};
#if (DE_OS == DE_OS_WIN32)
-deUint32 chooseMemoryType (deUint32 bits)
+deUint32 chooseWin32MemoryType(deUint32 bits)
{
if (bits == 0)
TCU_THROW(NotSupportedError, "No compatible memory type found");
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
// \note Buffer is only allocated to get memory requirements
- deUint32 exportedMemoryTypeIndex = ~0U;
const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
const vk::VkExportMemoryWin32HandleInfoKHR win32Info =
(vk::VkExternalMemoryHandleTypeFlags)config.externalType
};
- exportedMemoryTypeIndex = chooseMemoryType(requirements.memoryTypeBits & compatibleMemTypes);
- const vk::VkMemoryAllocateInfo info =
+ const deUint32 exportedMemoryTypeIndex = chooseWin32MemoryType(requirements.memoryTypeBits & compatibleMemTypes);
+ const vk::VkMemoryAllocateInfo info =
{
vk::VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
&exportInfo,
requirements.size,
exportedMemoryTypeIndex
};
- const vk::Unique<vk::VkDeviceMemory> memory (vk::allocateMemory(vkd, *device, &info));
+ const vk::Unique<vk::VkDeviceMemory> memory (vk::allocateMemory(vkd, *device, &info));
NativeHandle handleA;
if (config.hostVisible)
#endif
}
+deUint32 getExportedMemoryTypeIndex(const vk::InstanceDriver& vki, const vk::VkPhysicalDevice physicalDevice, bool hostVisible, deUint32 memoryBits)
+{
+ if (hostVisible)
+ {
+ const vk::VkPhysicalDeviceMemoryProperties properties(vk::getPhysicalDeviceMemoryProperties(vki, physicalDevice));
+ return chooseHostVisibleMemoryType(memoryBits, properties);
+ }
+
+ return chooseMemoryType(memoryBits);
+}
+
tcu::TestStatus testMemoryImportTwice (Context& context, MemoryTestConfig config)
{
const vk::PlatformInterface& vkp (context.getPlatformInterface());
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
- const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
- const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vki, physicalDevice, vkd, *device, requirements, config.externalType, config.hostVisible, config.dedicated ? *buffer : (vk::VkBuffer)0, exportedMemoryTypeIndex));
- NativeHandle handleA;
+ const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
+ const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
+ const deUint32 exportedMemoryTypeIndex (getExportedMemoryTypeIndex(vki, physicalDevice, config.hostVisible, requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *buffer : (vk::VkBuffer)0));
+ NativeHandle handleA;
if (config.hostVisible)
writeHostMemory(vkd, *device, *memory, testData.size(), &testData[0]);
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vki, physicalDevice, vkd, *device, requirements, config.externalType, config.hostVisible, config.dedicated ? *buffer : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (getExportedMemoryTypeIndex(vki, physicalDevice, config.hostVisible, requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *buffer : (vk::VkBuffer)0));
NativeHandle handleA;
getMemoryNative(vkd, *device, *memory, config.externalType, handleA);
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vki, physicalDevice, vkd, *device, requirements, config.externalType, config.hostVisible, config.dedicated ? *buffer : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (getExportedMemoryTypeIndex(vki, physicalDevice, config.hostVisible, requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *buffer : (vk::VkBuffer)0));
for (size_t ndx = 0; ndx < count; ndx++)
{
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vki, physicalDevice, vkd, *device, requirements, config.externalType, config.hostVisible, config.dedicated ? *buffer : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (getExportedMemoryTypeIndex(vki, physicalDevice, config.hostVisible, requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *buffer : (vk::VkBuffer)0));
vk::VkMemoryFdPropertiesKHR properties;
NativeHandle handle;
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vki, physicalDevice, vkd, *device, requirements, config.externalType, config.hostVisible, config.dedicated ? *buffer : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (getExportedMemoryTypeIndex(vki, physicalDevice, config.hostVisible, requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *buffer : (vk::VkBuffer)0));
if (config.hostVisible)
writeHostMemory(vkd, *device, *memory, testData.size(), &testData[0]);
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vki, physicalDevice, vkd, *device, requirements, config.externalType, config.hostVisible, config.dedicated ? *buffer : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (getExportedMemoryTypeIndex(vki, physicalDevice, config.hostVisible, requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *buffer : (vk::VkBuffer)0));
if (config.hostVisible)
writeHostMemory(vkd, *device, *memory, testData.size(), &testData[0]);
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vki, physicalDevice, vkd, *device, requirements, config.externalType, config.hostVisible, config.dedicated ? *buffer : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (getExportedMemoryTypeIndex(vki, physicalDevice, config.hostVisible, requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *buffer : (vk::VkBuffer)0));
if (config.hostVisible)
writeHostMemory(vkd, *device, *memory, testData.size(), &testData[0]);
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> buffer (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *buffer));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vki, physicalDevice, vkd, *device, requirements, config.externalType, config.hostVisible, config.dedicated ? *buffer : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (getExportedMemoryTypeIndex(vki, physicalDevice, config.hostVisible, requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *buffer : (vk::VkBuffer)0));
if (config.hostVisible)
writeHostMemory(vkd, *device, *memory, testData.size(), &testData[0]);
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> bufferA (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *bufferA));
- const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements, config.externalType, config.dedicated ? *bufferA : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (chooseMemoryType(requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *bufferA : (vk::VkBuffer)0));
NativeHandle handle;
VK_CHECK(vkd.bindBufferMemory(*device, *bufferA, *memoryA, 0u));
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> bufferA (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *bufferA));
- const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements, config.externalType, config.dedicated ? *bufferA : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (chooseMemoryType(requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *bufferA : (vk::VkBuffer)0));
NativeHandle handle;
getMemoryNative(vkd, *device, *memoryA, config.externalType, handle);
checkBufferSupport(vki, physicalDevice, config.externalType, 0u, usage, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Buffer is only allocated to get memory requirements
const vk::Unique<vk::VkBuffer> bufferA (createExternalBuffer(vkd, *device, queueFamilyIndex, config.externalType, bufferSize, 0u, usage));
const vk::VkMemoryRequirements requirements (getBufferMemoryRequirements(vkd, *device, *bufferA));
- const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements, config.externalType, config.dedicated ? *bufferA : (vk::VkBuffer)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (chooseMemoryType(requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *bufferA : (vk::VkBuffer)0));
NativeHandle handle;
getMemoryNative(vkd, *device, *memoryA, config.externalType, handle);
checkImageSupport(vki, physicalDevice, config.externalType, 0u, usage, format, tiling, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
const vk::Unique<vk::VkImage> imageA (createExternalImage(vkd, *device, queueFamilyIndex, config.externalType, format, width, height, tiling, 0u, usage));
const vk::VkMemoryRequirements requirements (getImageMemoryRequirements(vkd, *device, *imageA));
- const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements, config.externalType, config.dedicated ? *imageA : (vk::VkImage)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (chooseMemoryType(requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *imageA : (vk::VkImage)0));
NativeHandle handle;
VK_CHECK(vkd.bindImageMemory(*device, *imageA, *memoryA, 0u));
checkImageSupport(vki, physicalDevice, config.externalType, 0u, usage, format, tiling, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
const vk::Unique<vk::VkImage> imageA (createExternalImage(vkd, *device, queueFamilyIndex, config.externalType, format, width, height, tiling, 0u, usage));
const vk::VkMemoryRequirements requirements (getImageMemoryRequirements(vkd, *device, *imageA));
- const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements, config.externalType, config.dedicated ? *imageA : (vk::VkImage)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (chooseMemoryType(requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *imageA : (vk::VkImage)0));
NativeHandle handle;
getMemoryNative(vkd, *device, *memoryA, config.externalType, handle);
checkImageSupport(vki, physicalDevice, config.externalType, 0u, usage, format, tiling, config.dedicated);
- deUint32 exportedMemoryTypeIndex = ~0U;
// \note Image is only allocated to get memory requirements
const vk::Unique<vk::VkImage> imageA (createExternalImage(vkd, *device, queueFamilyIndex, config.externalType, format, width, height, tiling, 0u, usage));
const vk::VkMemoryRequirements requirements (getImageMemoryRequirements(vkd, *device, *imageA));
- const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements, config.externalType, config.dedicated ? *imageA : (vk::VkImage)0, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (chooseMemoryType(requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memoryA (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, config.externalType, config.dedicated ? *imageA : (vk::VkImage)0));
NativeHandle handle;
getMemoryNative(vkd, *device, *memoryA, config.externalType, handle);
};
for (size_t i = 0; i < DE_LENGTH_OF_ARRAY(sizes); i++)
{
- deUint32 exportedMemoryTypeIndex = ~0U;
const vk::Unique<vk::VkImage> image (createExternalImage(vkd, *device, queueFamilyIndex, externalMemoryType, format, sizes[i].width, sizes[i].height, tiling, createFlag, usage));
const vk::VkMemoryRequirements requirements (getImageMemoryRequirements(vkd, *device, *image));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements, externalMemoryType, *image, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (chooseMemoryType(requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, externalMemoryType, *image));
NativeHandle handle;
VK_CHECK(vkd.bindImageMemory(*device, *image, *memory, 0u));
if (properties.imageFormatProperties.maxMipLevels > 1u)
{
- deUint32 exportedMemoryTypeIndex = ~0U;
const vk::Unique<vk::VkImage> image (createExternalImage(vkd, *device, queueFamilyIndex, externalMemoryType, format, 64u, 64u, tiling, createFlag, usage, properties.imageFormatProperties.maxMipLevels));
const vk::VkMemoryRequirements requirements (getImageMemoryRequirements(vkd, *device, *image));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements, externalMemoryType, *image, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (chooseMemoryType(requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, externalMemoryType, *image));
NativeHandle handle;
VK_CHECK(vkd.bindImageMemory(*device, *image, *memory, 0u));
if ((properties.imageFormatProperties.maxArrayLayers > 1u) && enableMaxLayerTest)
{
- deUint32 exportedMemoryTypeIndex = ~0U;
const vk::Unique<vk::VkImage> image (createExternalImage(vkd, *device, queueFamilyIndex, externalMemoryType, format, 64u, 64u, tiling, createFlag, usage, 1u, properties.imageFormatProperties.maxArrayLayers));
const vk::VkMemoryRequirements requirements (getImageMemoryRequirements(vkd, *device, *image));
- const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements, externalMemoryType, *image, exportedMemoryTypeIndex));
+ const deUint32 exportedMemoryTypeIndex (chooseMemoryType(requirements.memoryTypeBits));
+ const vk::Unique<vk::VkDeviceMemory> memory (allocateExportableMemory(vkd, *device, requirements.size, exportedMemoryTypeIndex, externalMemoryType, *image));
NativeHandle handle;
VK_CHECK(vkd.bindImageMemory(*device, *image, *memory, 0u));
return vk::allocateCommandBuffer(vkd, device, &allocateInfo);
}
-de::MovePtr<vk::Allocation> allocateAndBindMemory (const vk::DeviceInterface& vkd,
- vk::VkDevice device,
- vk::VkBuffer buffer,
- vk::VkExternalMemoryHandleTypeFlagBits externalType,
- deUint32& exportedMemoryTypeIndex,
- bool dedicated,
- bool getMemReq2Supported)
+vk::VkMemoryRequirements getMemoryRequirements(const vk::DeviceInterface& vkd,
+ vk::VkDevice device,
+ vk::VkImage image,
+ bool dedicated,
+ bool getMemReq2Supported)
{
vk::VkMemoryRequirements memoryRequirements = { 0u, 0u, 0u, };
if (getMemReq2Supported)
{
- const vk::VkBufferMemoryRequirementsInfo2 requirementInfo =
+ const vk::VkImageMemoryRequirementsInfo2 requirementInfo =
{
- vk::VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
+ vk::VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
DE_NULL,
- buffer
+ image
};
vk::VkMemoryDedicatedRequirements dedicatedRequirements =
{
&dedicatedRequirements,
{ 0u, 0u, 0u, }
};
- vkd.getBufferMemoryRequirements2(device, &requirementInfo, &requirements);
+ vkd.getImageMemoryRequirements2(device, &requirementInfo, &requirements);
if (!dedicated && dedicatedRequirements.requiresDedicatedAllocation)
TCU_THROW(NotSupportedError, "Memory requires dedicated allocation");
}
else
{
- vkd.getBufferMemoryRequirements(device, buffer, &memoryRequirements);
+ vkd.getImageMemoryRequirements(device, image, &memoryRequirements);
}
-
- vk::Move<vk::VkDeviceMemory> memory = allocateExportableMemory(vkd, device, memoryRequirements, externalType, dedicated ? buffer : (vk::VkBuffer)0, exportedMemoryTypeIndex);
- VK_CHECK(vkd.bindBufferMemory(device, buffer, *memory, 0u));
-
- return de::MovePtr<vk::Allocation>(new SimpleAllocation(vkd, device, memory.disown()));
+ return memoryRequirements;
}
-de::MovePtr<vk::Allocation> allocateAndBindMemory (const vk::DeviceInterface& vkd,
- vk::VkDevice device,
- vk::VkImage image,
- vk::VkExternalMemoryHandleTypeFlagBits externalType,
- deUint32& exportedMemoryTypeIndex,
- bool dedicated,
- bool getMemReq2Supported)
+vk::VkMemoryRequirements getMemoryRequirements(const vk::DeviceInterface& vkd,
+ vk::VkDevice device,
+ vk::VkBuffer buffer,
+ bool dedicated,
+ bool getMemReq2Supported)
{
vk::VkMemoryRequirements memoryRequirements = { 0u, 0u, 0u, };
if (getMemReq2Supported)
{
- const vk::VkImageMemoryRequirementsInfo2 requirementInfo =
+ const vk::VkBufferMemoryRequirementsInfo2 requirementInfo =
{
- vk::VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
+ vk::VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
DE_NULL,
- image
+ buffer
};
vk::VkMemoryDedicatedRequirements dedicatedRequirements =
{
&dedicatedRequirements,
{ 0u, 0u, 0u, }
};
- vkd.getImageMemoryRequirements2(device, &requirementInfo, &requirements);
+ vkd.getBufferMemoryRequirements2(device, &requirementInfo, &requirements);
if (!dedicated && dedicatedRequirements.requiresDedicatedAllocation)
TCU_THROW(NotSupportedError, "Memory requires dedicated allocation");
}
else
{
- vkd.getImageMemoryRequirements(device, image, &memoryRequirements);
+ vkd.getBufferMemoryRequirements(device, buffer, &memoryRequirements);
}
- vk::Move<vk::VkDeviceMemory> memory = allocateExportableMemory(vkd, device, memoryRequirements, externalType, dedicated ? image : (vk::VkImage)0, exportedMemoryTypeIndex);
- VK_CHECK(vkd.bindImageMemory(device, image, *memory, 0u));
-
- return de::MovePtr<vk::Allocation>(new SimpleAllocation(vkd, device, memory.disown()));
+ return memoryRequirements;
}
-de::MovePtr<Resource> createResource (const vk::DeviceInterface& vkd,
- vk::VkDevice device,
- const ResourceDescription& resourceDesc,
- const std::vector<deUint32>& queueFamilyIndices,
- const OperationSupport& readOp,
- const OperationSupport& writeOp,
- vk::VkExternalMemoryHandleTypeFlagBits externalType,
- deUint32& exportedMemoryTypeIndex,
- bool dedicated,
- bool getMemReq2Supported)
+Move<VkImage> createImage(const vk::DeviceInterface& vkd,
+ vk::VkDevice device,
+ const ResourceDescription& resourceDesc,
+ const vk::VkExtent3D extent,
+ const std::vector<deUint32>& queueFamilyIndices,
+ const OperationSupport& readOp,
+ const OperationSupport& writeOp,
+ vk::VkExternalMemoryHandleTypeFlagBits externalType)
{
- if (resourceDesc.type == RESOURCE_TYPE_IMAGE)
+ const vk::VkExternalMemoryImageCreateInfo externalInfo =
{
- const vk::VkExtent3D extent =
- {
- (deUint32)resourceDesc.size.x(),
- de::max(1u, (deUint32)resourceDesc.size.y()),
- de::max(1u, (deUint32)resourceDesc.size.z())
- };
- const vk::VkImageSubresourceRange subresourceRange =
- {
- resourceDesc.imageAspect,
- 0u,
- 1u,
- 0u,
- 1u
- };
- const vk::VkImageSubresourceLayers subresourceLayers =
- {
- resourceDesc.imageAspect,
- 0u,
- 0u,
- 1u
- };
- const vk::VkExternalMemoryImageCreateInfo externalInfo =
- {
- vk::VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
- DE_NULL,
- (vk::VkExternalMemoryHandleTypeFlags)externalType
- };
- const vk::VkImageCreateInfo createInfo =
- {
- vk::VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
- &externalInfo,
- 0u,
-
- resourceDesc.imageType,
- resourceDesc.imageFormat,
- extent,
- 1u,
- 1u,
- vk::VK_SAMPLE_COUNT_1_BIT,
- vk::VK_IMAGE_TILING_OPTIMAL,
- readOp.getInResourceUsageFlags() | writeOp.getOutResourceUsageFlags(),
- vk::VK_SHARING_MODE_EXCLUSIVE,
+ vk::VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
+ DE_NULL,
+ (vk::VkExternalMemoryHandleTypeFlags)externalType
+ };
+ const vk::VkImageCreateInfo createInfo =
+ {
+ vk::VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+ &externalInfo,
+ 0u,
- (deUint32)queueFamilyIndices.size(),
- &queueFamilyIndices[0],
- vk::VK_IMAGE_LAYOUT_UNDEFINED
- };
+ resourceDesc.imageType,
+ resourceDesc.imageFormat,
+ extent,
+ 1u,
+ 1u,
+ vk::VK_SAMPLE_COUNT_1_BIT,
+ vk::VK_IMAGE_TILING_OPTIMAL,
+ readOp.getInResourceUsageFlags() | writeOp.getOutResourceUsageFlags(),
+ vk::VK_SHARING_MODE_EXCLUSIVE,
+
+ (deUint32)queueFamilyIndices.size(),
+ &queueFamilyIndices[0],
+ vk::VK_IMAGE_LAYOUT_UNDEFINED
+ };
- vk::Move<vk::VkImage> image = vk::createImage(vkd, device, &createInfo);
- de::MovePtr<vk::Allocation> allocation = allocateAndBindMemory(vkd, device, *image, externalType, exportedMemoryTypeIndex, dedicated, getMemReq2Supported);
+ return vk::createImage(vkd, device, &createInfo);
+}
- return de::MovePtr<Resource>(new Resource(image, allocation, extent, resourceDesc.imageType, resourceDesc.imageFormat, subresourceRange, subresourceLayers));
- }
- else
+Move<VkBuffer> createBuffer(const vk::DeviceInterface& vkd,
+ vk::VkDevice device,
+ const vk::VkDeviceSize size,
+ const vk::VkBufferUsageFlags usage,
+ const vk::VkExternalMemoryHandleTypeFlagBits memoryHandleType,
+ const std::vector<deUint32>& queueFamilyIndices)
+{
+ const vk::VkExternalMemoryBufferCreateInfo externalInfo =
{
- const vk::VkDeviceSize offset = 0u;
- const vk::VkDeviceSize size = static_cast<vk::VkDeviceSize>(resourceDesc.size.x());
- const vk::VkBufferUsageFlags usage = readOp.getInResourceUsageFlags() | writeOp.getOutResourceUsageFlags();
- const vk:: VkExternalMemoryBufferCreateInfo externalInfo =
- {
- vk::VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
- DE_NULL,
- (vk::VkExternalMemoryHandleTypeFlags)externalType
- };
- const vk::VkBufferCreateInfo createInfo =
- {
- vk::VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
- &externalInfo,
- 0u,
-
- size,
- usage,
- vk::VK_SHARING_MODE_EXCLUSIVE,
- (deUint32)queueFamilyIndices.size(),
- &queueFamilyIndices[0]
- };
- vk::Move<vk::VkBuffer> buffer = vk::createBuffer(vkd, device, &createInfo);
- de::MovePtr<vk::Allocation> allocation = allocateAndBindMemory(vkd, device, *buffer, externalType, exportedMemoryTypeIndex, dedicated, getMemReq2Supported);
+ vk::VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
+ DE_NULL,
+ (vk::VkExternalMemoryHandleTypeFlags)memoryHandleType
+ };
+ const vk::VkBufferCreateInfo createInfo =
+ {
+ vk::VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
+ &externalInfo,
+ 0u,
- return de::MovePtr<Resource>(new Resource(resourceDesc.type, buffer, allocation, offset, size));
- }
+ size,
+ usage,
+ vk::VK_SHARING_MODE_EXCLUSIVE,
+ (deUint32)queueFamilyIndices.size(),
+ &queueFamilyIndices[0]
+ };
+ return vk::createBuffer(vkd, device, &createInfo);
}
de::MovePtr<vk::Allocation> importAndBindMemory (const vk::DeviceInterface& vkd,
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphoreType(m_vkdA, *m_deviceA, m_config.semaphoreType, m_semaphoreHandleType));
const vk::Unique<vk::VkSemaphore> semaphoreB (createSemaphoreType(m_vkdB, *m_deviceB, m_config.semaphoreType));
- deUint32 exportedMemoryTypeIndex = ~0U;
- const de::UniquePtr<Resource> resourceA (createResource(m_vkdA, *m_deviceA, m_config.resource, m_queueFamilyIndicesA, *m_supportReadOp, *m_supportWriteOp, m_memoryHandleType, exportedMemoryTypeIndex, m_config.dedicated, m_getMemReq2Supported));
+ const ResourceDescription& resourceDesc = m_config.resource;
+ de::MovePtr<Resource> resourceA;
+
+ deUint32 exportedMemoryTypeIndex = ~0U;
+ if (resourceDesc.type == RESOURCE_TYPE_IMAGE)
+ {
+ const vk::VkExtent3D extent =
+ {
+ (deUint32)resourceDesc.size.x(),
+ de::max(1u, (deUint32)resourceDesc.size.y()),
+ de::max(1u, (deUint32)resourceDesc.size.z())
+ };
+ const vk::VkImageSubresourceRange subresourceRange =
+ {
+ resourceDesc.imageAspect,
+ 0u,
+ 1u,
+ 0u,
+ 1u
+ };
+ const vk::VkImageSubresourceLayers subresourceLayers =
+ {
+ resourceDesc.imageAspect,
+ 0u,
+ 0u,
+ 1u
+ };
+
+ vk::Move<vk::VkImage> image = createImage(m_vkdA, *m_deviceA, resourceDesc, extent, m_queueFamilyIndicesA,
+ *m_supportReadOp, *m_supportWriteOp, m_memoryHandleType);
+ const vk::VkMemoryRequirements requirements = getMemoryRequirements(m_vkdA, *m_deviceA, *image, m_config.dedicated, m_getMemReq2Supported);
+ exportedMemoryTypeIndex = chooseMemoryType(requirements.memoryTypeBits);
+ vk::Move<vk::VkDeviceMemory> memory = allocateExportableMemory(m_vkdA, *m_deviceA, requirements.size, exportedMemoryTypeIndex, m_memoryHandleType, m_config.dedicated ? *image : (vk::VkImage)0);
+
+ VK_CHECK(m_vkdA.bindImageMemory(*m_deviceA, *image, *memory, 0u));
+
+ de::MovePtr<vk::Allocation> allocation = de::MovePtr<vk::Allocation>(new SimpleAllocation(m_vkdA, *m_deviceA, memory.disown()));
+ resourceA = de::MovePtr<Resource>(new Resource(image, allocation, extent, resourceDesc.imageType, resourceDesc.imageFormat, subresourceRange, subresourceLayers));
+ }
+ else
+ {
+ const vk::VkDeviceSize offset = 0u;
+ const vk::VkDeviceSize size = static_cast<vk::VkDeviceSize>(resourceDesc.size.x());
+ const vk::VkBufferUsageFlags usage = m_supportReadOp->getInResourceUsageFlags() | m_supportWriteOp->getOutResourceUsageFlags();
+ vk::Move<vk::VkBuffer> buffer = createBuffer(m_vkdA, *m_deviceA, size, usage, m_memoryHandleType, m_queueFamilyIndicesA);
+ const vk::VkMemoryRequirements requirements = getMemoryRequirements(m_vkdA, *m_deviceA, *buffer, m_config.dedicated, m_getMemReq2Supported);
+ exportedMemoryTypeIndex = chooseMemoryType(requirements.memoryTypeBits);
+ vk::Move<vk::VkDeviceMemory> memory = allocateExportableMemory(m_vkdA, *m_deviceA, requirements.size, exportedMemoryTypeIndex, m_memoryHandleType, m_config.dedicated ? *buffer : (vk::VkBuffer)0);
+
+ VK_CHECK(m_vkdA.bindBufferMemory(*m_deviceA, *buffer, *memory, 0u));
+
+ de::MovePtr<vk::Allocation> allocation = de::MovePtr<vk::Allocation>(new SimpleAllocation(m_vkdA, *m_deviceA, memory.disown()));
+ resourceA = de::MovePtr<Resource>(new Resource(resourceDesc.type, buffer, allocation, offset, size));
+ }
NativeHandle nativeMemoryHandle;
getMemoryNative(m_vkdA, *m_deviceA, resourceA->getMemory(), m_memoryHandleType, nativeMemoryHandle);
- const de::UniquePtr<Resource> resourceB (importResource(m_vkdB, *m_deviceB, m_config.resource, m_queueFamilyIndicesB, *m_supportReadOp, *m_supportWriteOp, nativeMemoryHandle, m_memoryHandleType, exportedMemoryTypeIndex, m_config.dedicated));
+ const de::UniquePtr<Resource> resourceB (importResource(m_vkdB, *m_deviceB, resourceDesc, m_queueFamilyIndicesB, *m_supportReadOp, *m_supportWriteOp, nativeMemoryHandle, m_memoryHandleType, exportedMemoryTypeIndex, m_config.dedicated));
const vk::VkQueue queueA (getQueue(m_vkdA, *m_deviceA, queueFamilyA));
m_vkd.freeMemory(m_device, getMemory(), DE_NULL);
}
-MovePtr<Allocation> allocateAndBindMemory (const DeviceInterface& vkd,
- VkDevice device,
- VkBuffer buffer,
- VkExternalMemoryHandleTypeFlagBits externalType,
- deUint32& memoryIndex)
+vk::VkMemoryRequirements getMemoryRequirements (const DeviceInterface& vkd,
+ VkDevice device,
+ VkBuffer buffer)
{
const VkBufferMemoryRequirementsInfo2 requirementInfo =
{
{ 0u, 0u, 0u, }
};
vkd.getBufferMemoryRequirements2(device, &requirementInfo, &requirements);
-
- Move<VkDeviceMemory> memory = allocateExportableMemory(vkd, device, requirements.memoryRequirements, externalType, buffer, memoryIndex);
- VK_CHECK(vkd.bindBufferMemory(device, buffer, *memory, 0u));
-
- return MovePtr<Allocation>(new SimpleAllocation(vkd, device, memory.disown()));
+ return requirements.memoryRequirements;
}
-MovePtr<Allocation> allocateAndBindMemory (const DeviceInterface& vkd,
- VkDevice device,
- VkImage image,
- VkExternalMemoryHandleTypeFlagBits externalType,
- deUint32& exportedMemoryTypeIndex)
+vk::VkMemoryRequirements getMemoryRequirements(const DeviceInterface& vkd,
+ VkDevice device,
+ VkImage image)
{
- VkMemoryRequirements memoryRequirements = { 0u, 0u, 0u, };
const VkImageMemoryRequirementsInfo2 requirementInfo =
{
VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
};
vkd.getImageMemoryRequirements2(device, &requirementInfo, &requirements);
- memoryRequirements = requirements.memoryRequirements;
-
- Move<VkDeviceMemory> memory = allocateExportableMemory(vkd, device, memoryRequirements, externalType, image, exportedMemoryTypeIndex);
- VK_CHECK(vkd.bindImageMemory(device, image, *memory, 0u));
-
- return MovePtr<Allocation>(new SimpleAllocation(vkd, device, memory.disown()));
+ return requirements.memoryRequirements;
}
-
MovePtr<Allocation> importAndBindMemory (const DeviceInterface& vkd,
VkDevice device,
VkBuffer buffer,
SharedPtr<Operation> op;
};
-de::MovePtr<Resource> createResource (const DeviceInterface& vkd,
- VkDevice device,
- const ResourceDescription& resourceDesc,
- const deUint32 queueFamilyIndex,
- const OperationSupport& readOp,
- const OperationSupport& writeOp,
- VkExternalMemoryHandleTypeFlagBits externalType,
- deUint32& exportedMemoryTypeIndex)
-{
- if (resourceDesc.type == RESOURCE_TYPE_IMAGE)
- {
- const VkExtent3D extent =
- {
- (deUint32)resourceDesc.size.x(),
- de::max(1u, (deUint32)resourceDesc.size.y()),
- de::max(1u, (deUint32)resourceDesc.size.z())
- };
- const VkImageSubresourceRange subresourceRange =
- {
- resourceDesc.imageAspect,
- 0u,
- 1u,
- 0u,
- 1u
- };
- const VkImageSubresourceLayers subresourceLayers =
- {
- resourceDesc.imageAspect,
- 0u,
- 0u,
- 1u
- };
- const VkExternalMemoryImageCreateInfo externalInfo =
- {
- VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
- DE_NULL,
- (VkExternalMemoryHandleTypeFlags)externalType
- };
- const VkImageCreateInfo createInfo =
- {
- VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
- &externalInfo,
- 0u,
-
- resourceDesc.imageType,
- resourceDesc.imageFormat,
- extent,
- 1u,
- 1u,
- VK_SAMPLE_COUNT_1_BIT,
- VK_IMAGE_TILING_OPTIMAL,
- readOp.getInResourceUsageFlags() | writeOp.getOutResourceUsageFlags(),
- VK_SHARING_MODE_EXCLUSIVE,
-
- 1u,
- &queueFamilyIndex,
- VK_IMAGE_LAYOUT_UNDEFINED
- };
-
- Move<VkImage> image = createImage(vkd, device, &createInfo);
- MovePtr<Allocation> allocation = allocateAndBindMemory(vkd, device, *image, externalType, exportedMemoryTypeIndex);
-
- return MovePtr<Resource>(new Resource(image, allocation, extent, resourceDesc.imageType, resourceDesc.imageFormat, subresourceRange, subresourceLayers));
- }
- else
- {
- const VkDeviceSize offset = 0u;
- const VkDeviceSize size = static_cast<VkDeviceSize>(resourceDesc.size.x());
- const VkBufferUsageFlags usage = readOp.getInResourceUsageFlags() | writeOp.getOutResourceUsageFlags();
- const VkExternalMemoryBufferCreateInfo externalInfo =
- {
- VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
- DE_NULL,
- (VkExternalMemoryHandleTypeFlags)externalType
- };
- const VkBufferCreateInfo createInfo =
- {
- VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
- &externalInfo,
- 0u,
-
- size,
- usage,
- VK_SHARING_MODE_EXCLUSIVE,
- 1u,
- &queueFamilyIndex
- };
- Move<VkBuffer> buffer = createBuffer(vkd, device, &createInfo);
- MovePtr<Allocation> allocation = allocateAndBindMemory(vkd, device, *buffer, externalType, exportedMemoryTypeIndex);
-
- return MovePtr<Resource>(new Resource(resourceDesc.type, buffer, allocation, offset, size));
- }
-}
-
de::MovePtr<Resource> importResource (const DeviceInterface& vkd,
VkDevice device,
const ResourceDescription& resourceDesc,
}
+ Move<VkImage> createImage (const vk::DeviceInterface& vkd,
+ vk::VkDevice device,
+ const vk::VkExtent3D& extent,
+ deUint32 queueFamilyIndex)
+ {
+ const VkExternalMemoryImageCreateInfo externalInfo =
+ {
+ VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
+ DE_NULL,
+ (VkExternalMemoryHandleTypeFlags)m_memoryHandleType
+ };
+ const VkImageCreateInfo createInfo =
+ {
+ VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+ &externalInfo,
+ 0u,
+
+ m_resourceDesc.imageType,
+ m_resourceDesc.imageFormat,
+ extent,
+ 1u,
+ 1u,
+ VK_SAMPLE_COUNT_1_BIT,
+ VK_IMAGE_TILING_OPTIMAL,
+ m_readOpSupport->getInResourceUsageFlags() | m_writeOpSupport->getOutResourceUsageFlags(),
+ VK_SHARING_MODE_EXCLUSIVE,
+
+ 1u,
+ &queueFamilyIndex,
+ VK_IMAGE_LAYOUT_UNDEFINED
+ };
+
+ return vk::createImage(vkd, device, &createInfo);
+ }
+
+ Move<VkBuffer> createBuffer (const vk::DeviceInterface& vkd,
+ vk::VkDevice device,
+ const vk::VkDeviceSize& size,
+ deUint32 queueFamilyIndex)
+ {
+ const VkExternalMemoryBufferCreateInfo externalInfo =
+ {
+ VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
+ DE_NULL,
+ (VkExternalMemoryHandleTypeFlags)m_memoryHandleType
+ };
+ const VkBufferCreateInfo createInfo =
+ {
+ VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
+ &externalInfo,
+ 0u,
+
+ size,
+ m_readOpSupport->getInResourceUsageFlags() | m_writeOpSupport->getOutResourceUsageFlags(),
+ VK_SHARING_MODE_EXCLUSIVE,
+ 1u,
+ &queueFamilyIndex
+ };
+ return vk::createBuffer(vkd, device, &createInfo);
+ }
+
tcu::TestStatus iterate (void)
{
// We're using 2 devices to make sure we have 2 queues even on
std::vector<VkSemaphore> semaphoreHandlesB;
std::vector<deUint64> timelineValuesA;
std::vector<deUint64> timelineValuesB;
- std::vector<QueueSubmitOrderSharedIteration> iterations;
+ std::vector<QueueSubmitOrderSharedIteration> iterations(12);
std::vector<VkPipelineStageFlags> stageBits;
// Create a dozen of set of write/read operations.
- iterations.resize(12);
for (deUint32 iterIdx = 0; iterIdx < iterations.size(); iterIdx++)
{
QueueSubmitOrderSharedIteration& iter = iterations[iterIdx];
deUint32 memoryTypeIndex;
NativeHandle nativeMemoryHandle;
- iter.resourceA = makeSharedPtr(createResource(vkA, deviceA,
- m_resourceDesc,
- universalQueueFamilyIndex,
- *m_readOpSupport,
- *m_writeOpSupport,
- m_memoryHandleType,
- memoryTypeIndex));
+ if (m_resourceDesc.type == RESOURCE_TYPE_IMAGE)
+ {
+ const VkExtent3D extent =
+ {
+ (deUint32)m_resourceDesc.size.x(),
+ de::max(1u, (deUint32)m_resourceDesc.size.y()),
+ de::max(1u, (deUint32)m_resourceDesc.size.z())
+ };
+ const VkImageSubresourceRange subresourceRange =
+ {
+ m_resourceDesc.imageAspect,
+ 0u,
+ 1u,
+ 0u,
+ 1u
+ };
+ const VkImageSubresourceLayers subresourceLayers =
+ {
+ m_resourceDesc.imageAspect,
+ 0u,
+ 0u,
+ 1u
+ };
+
+ Move<VkImage> image = createImage(vkA, deviceA, extent, universalQueueFamilyIndex);
+ const vk::VkMemoryRequirements requirements = getMemoryRequirements(vkA, deviceA, *image);
+ memoryTypeIndex = chooseMemoryType(requirements.memoryTypeBits);
+ vk::Move<vk::VkDeviceMemory> memory = allocateExportableMemory(vkA, deviceA, requirements.size, memoryTypeIndex, m_memoryHandleType, *image);
+
+ VK_CHECK(vkA.bindImageMemory(deviceA, *image, *memory, 0u));
+
+ MovePtr<Allocation> allocation(new SimpleAllocation(vkA, deviceA, memory.disown()));
+ iter.resourceA = makeSharedPtr(new Resource(image, allocation, extent, m_resourceDesc.imageType, m_resourceDesc.imageFormat, subresourceRange, subresourceLayers));
+ }
+ else
+ {
+ const VkDeviceSize offset = 0u;
+ const VkDeviceSize size = static_cast<VkDeviceSize>(m_resourceDesc.size.x());
+ Move<VkBuffer> buffer = createBuffer(vkA, deviceA, size, universalQueueFamilyIndex);
+ const vk::VkMemoryRequirements requirements = getMemoryRequirements(vkA, deviceA, *buffer);
+ memoryTypeIndex = chooseMemoryType(requirements.memoryTypeBits);
+ vk::Move<vk::VkDeviceMemory> memory = allocateExportableMemory(vkA, deviceA, requirements.size, memoryTypeIndex, m_memoryHandleType, *buffer);
+
+ VK_CHECK(vkA.bindBufferMemory(deviceA, *buffer, *memory, 0u));
+
+ MovePtr<Allocation> allocation(new SimpleAllocation(vkA, deviceA, memory.disown()));
+ iter.resourceA = makeSharedPtr(new Resource(m_resourceDesc.type, buffer, allocation, offset, size));
+ }
+
getMemoryNative(vkA, deviceA, iter.resourceA->getMemory(), m_memoryHandleType, nativeMemoryHandle);
iter.resourceB = makeSharedPtr(importResource(vkB, *deviceB,
m_resourceDesc,
{
namespace
{
-deUint32 chooseMemoryType (deUint32 bits)
-{
- DE_ASSERT(bits != 0);
-
- for (deUint32 memoryTypeIndex = 0; (1u << memoryTypeIndex) <= bits; memoryTypeIndex++)
- {
- if ((bits & (1u << memoryTypeIndex)) != 0)
- return memoryTypeIndex;
- }
-
- DE_FATAL("No supported memory types");
- return -1;
-}
} // anonymous
return semaphore;
}
+deUint32 chooseMemoryType(deUint32 bits)
+{
+ DE_ASSERT(bits != 0);
+
+ for (deUint32 memoryTypeIndex = 0; (1u << memoryTypeIndex) <= bits; memoryTypeIndex++)
+ {
+ if ((bits & (1u << memoryTypeIndex)) != 0)
+ return memoryTypeIndex;
+ }
+
+ DE_FATAL("No supported memory types");
+ return -1;
+}
+
+deUint32 chooseHostVisibleMemoryType (deUint32 bits, const vk::VkPhysicalDeviceMemoryProperties properties)
+{
+ DE_ASSERT(bits != 0);
+
+ for (deUint32 memoryTypeIndex = 0; (1u << memoryTypeIndex) <= bits; memoryTypeIndex++)
+ {
+ if (((bits & (1u << memoryTypeIndex)) != 0) &&
+ ((properties.memoryTypes[memoryTypeIndex].propertyFlags & vk::VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0))
+ return memoryTypeIndex;
+ }
+
+ TCU_THROW(NotSupportedError, "No supported memory type found");
+ return -1;
+}
+
vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::DeviceInterface& vkd,
vk::VkDevice device,
- const vk::VkMemoryRequirements& requirements,
+ vk::VkDeviceSize allocationSize,
+ deUint32 memoryTypeIndex,
vk::VkExternalMemoryHandleTypeFlagBits externalType,
- vk::VkBuffer buffer,
- deUint32& exportedMemoryTypeIndex)
+ vk::VkBuffer buffer)
{
- exportedMemoryTypeIndex = chooseMemoryType(requirements.memoryTypeBits);
const vk::VkMemoryDedicatedAllocateInfo dedicatedInfo =
{
vk::VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
{
vk::VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
&exportInfo,
- requirements.size,
- exportedMemoryTypeIndex
+ allocationSize,
+ memoryTypeIndex
};
return vk::allocateMemory(vkd, device, &info);
}
vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::DeviceInterface& vkd,
vk::VkDevice device,
- const vk::VkMemoryRequirements& requirements,
+ vk::VkDeviceSize allocationSize,
+ deUint32 memoryTypeIndex,
vk::VkExternalMemoryHandleTypeFlagBits externalType,
- vk::VkImage image,
- deUint32& exportedMemoryTypeIndex)
+ vk::VkImage image)
{
- exportedMemoryTypeIndex = chooseMemoryType(requirements.memoryTypeBits);
const vk::VkMemoryDedicatedAllocateInfo dedicatedInfo =
{
vk::VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
{
vk::VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
&exportInfo,
- requirements.size,
- exportedMemoryTypeIndex
+ allocationSize,
+ memoryTypeIndex
};
return vk::allocateMemory(vkd, device, &info);
}
-vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::InstanceInterface& vki,
- vk::VkPhysicalDevice physicalDevice,
- const vk::DeviceInterface& vkd,
- vk::VkDevice device,
- const vk::VkMemoryRequirements& requirements,
- vk::VkExternalMemoryHandleTypeFlagBits externalType,
- bool hostVisible,
- vk::VkBuffer buffer,
- deUint32& exportedMemoryTypeIndex)
-{
- const vk::VkPhysicalDeviceMemoryProperties properties = vk::getPhysicalDeviceMemoryProperties(vki, physicalDevice);
-
- for (deUint32 memoryTypeIndex = 0; (1u << memoryTypeIndex) <= requirements.memoryTypeBits; memoryTypeIndex++)
- {
- if (((requirements.memoryTypeBits & (1u << memoryTypeIndex)) != 0)
- && (((properties.memoryTypes[memoryTypeIndex].propertyFlags & vk::VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) == hostVisible))
- {
- const vk::VkMemoryDedicatedAllocateInfo dedicatedInfo =
- {
- vk::VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
- DE_NULL,
-
- (vk::VkImage)0,
- buffer
- };
- const vk::VkExportMemoryAllocateInfo exportInfo =
- {
- vk::VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO,
- !!buffer ? &dedicatedInfo : DE_NULL,
- (vk::VkExternalMemoryHandleTypeFlags)externalType
- };
- const vk::VkMemoryAllocateInfo info =
- {
- vk::VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
- &exportInfo,
- requirements.size,
- memoryTypeIndex
- };
-
- exportedMemoryTypeIndex = memoryTypeIndex;
- return vk::allocateMemory(vkd, device, &info);
- }
- }
-
- TCU_THROW(NotSupportedError, "No supported memory type found");
-}
-
static vk::Move<vk::VkDeviceMemory> importMemory (const vk::DeviceInterface& vkd,
vk::VkDevice device,
vk::VkBuffer buffer,
vk::VkFence fence,
vk::VkExternalFenceHandleTypeFlagBits externalType,
NativeHandle& nativeHandle,
- bool expectFenceUnsignaled = true);
+ bool expectFenceUnsignaled = true);
void importFence (const vk::DeviceInterface& vkd,
const vk::VkDevice device,
NativeHandle& handle,
vk::VkFenceImportFlags flags);
-vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::DeviceInterface& vkd,
- vk::VkDevice device,
- const vk::VkMemoryRequirements& requirements,
- vk::VkExternalMemoryHandleTypeFlagBits externalType,
- deUint32& exportedMemoryTypeIndex);
+deUint32 chooseMemoryType (deUint32 bits);
+
+deUint32 chooseHostVisibleMemoryType (deUint32 bits,
+ const vk::VkPhysicalDeviceMemoryProperties properties);
// If buffer is not null use dedicated allocation
vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::DeviceInterface& vkd,
vk::VkDevice device,
- const vk::VkMemoryRequirements& requirements,
+ vk::VkDeviceSize allocationSize,
+ deUint32 memoryTypeIndex,
vk::VkExternalMemoryHandleTypeFlagBits externalType,
- vk::VkBuffer buffer,
- deUint32& exportedMemoryTypeIndex);
+ vk::VkBuffer buffer);
// If image is not null use dedicated allocation
vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::DeviceInterface& vkd,
vk::VkDevice device,
- const vk::VkMemoryRequirements& requirements,
+ vk::VkDeviceSize allocationSize,
+ deUint32 memoryTypeIndex,
vk::VkExternalMemoryHandleTypeFlagBits externalType,
- vk::VkImage image,
- deUint32& exportedMemoryTypeIndex);
+ vk::VkImage image);
+/*
// \note hostVisible argument is strict. Setting it to false will cause NotSupportedError to be thrown if non-host visible memory doesn't exist.
// If buffer is not null use dedicated allocation
vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::InstanceInterface& vki,
bool hostVisible,
vk::VkBuffer buffer,
deUint32& exportedMemoryTypeIndex);
+*/
vk::Move<vk::VkDeviceMemory> importMemory (const vk::DeviceInterface& vkd,
vk::VkDevice device,