tests: Add unit tests for dedicated memory binding
authorJohn Zulauf <jzulauf@lunarg.com>
Fri, 2 Mar 2018 16:24:43 +0000 (09:24 -0700)
committerjzulauf-lunarg <32470354+jzulauf-lunarg@users.noreply.github.com>
Mon, 5 Mar 2018 18:48:31 +0000 (11:48 -0700)
Added unit tests for the following valid usage checks w.r.t. binding
dedicated allocations to buffers and images.

VALIDATION_ERROR_17000bc8 VUID-vkBindBufferMemory-memory-01508
VALIDATION_ERROR_17400bca VUID-vkBindImageMemory-memory-01509

As same code path checks the BindImage2/BufferMemory2, but has no
matching valid usage, no tests are added for those cases.

Change-Id: Id8845d3cdb85731142ca0dca381a5e9157118a25

layers/vk_validation_error_database.txt
tests/layer_validation_tests.cpp

index 4e1a8e0..791a489 100644 (file)
@@ -1688,7 +1688,7 @@ VALIDATION_ERROR_1700081a~^~Y~^~BindInvalidMemory~^~vkBindBufferMemory~^~VUID-vk
 VALIDATION_ERROR_1700081c~^~N~^~Unknown~^~vkBindBufferMemory~^~VUID-vkBindBufferMemory-buffer-01038~^~(VK_NV_dedicated_allocation)~^~The spec valid usage text states 'If buffer was created with VkDedicatedAllocationBufferCreateInfoNV::dedicatedAllocation equal to VK_TRUE, memory must have been created with VkDedicatedAllocationMemoryAllocateInfoNV::buffer equal to a buffer handle created with identical creation parameters to buffer and memoryOffset must be zero' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-vkBindBufferMemory-buffer-01038)~^~
 VALIDATION_ERROR_1700081e~^~N~^~Unknown~^~vkBindBufferMemory~^~VUID-vkBindBufferMemory-buffer-01039~^~(VK_NV_dedicated_allocation)+!(VK_KHR_dedicated_allocation)~^~The spec valid usage text states 'If buffer was not created with VkDedicatedAllocationBufferCreateInfoNV::dedicatedAllocation equal to VK_TRUE, memory must not have been allocated dedicated for a specific buffer or image' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkBindBufferMemory-buffer-01039)~^~
 VALIDATION_ERROR_17000b48~^~N~^~None~^~vkBindBufferMemory~^~VUID-vkBindBufferMemory-buffer-01444~^~(VK_KHR_dedicated_allocation)~^~The spec valid usage text states 'If buffer requires a dedicated allocation(as reported by vkGetBufferMemoryRequirements2KHR in VkMemoryDedicatedRequirementsKHR::requiresDedicatedAllocation for image), memory must have been created with VkMemoryDedicatedAllocateInfoKHR::buffer equal to buffer' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-vkBindBufferMemory-buffer-01444)~^~
-VALIDATION_ERROR_17000bc8~^~Y~^~None~^~vkBindBufferMemory~^~VUID-vkBindBufferMemory-memory-01508~^~(VK_KHR_dedicated_allocation)~^~The spec valid usage text states 'If the VkmemoryAllocateInfo provided when memory was allocated included an instance of VkMemoryDedicatedAllocateInfoKHR in its pNext chain, and VkMemoryDedicatedAllocateInfoKHR::buffer was not VK_NULL_HANDLE, then buffer must equal VkMemoryDedicatedAllocateInfoKHR::buffer and memoryOffset must be zero.' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-vkBindBufferMemory-memory-01508)~^~
+VALIDATION_ERROR_17000bc8~^~Y~^~DedicatedAllocation~^~vkBindBufferMemory~^~VUID-vkBindBufferMemory-memory-01508~^~(VK_KHR_dedicated_allocation)~^~The spec valid usage text states 'If the VkmemoryAllocateInfo provided when memory was allocated included an instance of VkMemoryDedicatedAllocateInfoKHR in its pNext chain, and VkMemoryDedicatedAllocateInfoKHR::buffer was not VK_NULL_HANDLE, then buffer must equal VkMemoryDedicatedAllocateInfoKHR::buffer and memoryOffset must be zero.' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-vkBindBufferMemory-memory-01508)~^~
 VALIDATION_ERROR_17001a01~^~Y~^~VertexBufferInvalid~^~vkBindBufferMemory~^~VUID-vkBindBufferMemory-buffer-parameter~^~core~^~The spec valid usage text states 'buffer must be a valid VkBuffer handle' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkBindBufferMemory-buffer-parameter)~^~implicit
 VALIDATION_ERROR_17001a07~^~Y~^~Unknown~^~vkBindBufferMemory~^~VUID-vkBindBufferMemory-buffer-parent~^~core~^~The spec valid usage text states 'buffer must have been created, allocated, or retrieved from device' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkBindBufferMemory-buffer-parent)~^~implicit
 VALIDATION_ERROR_17005601~^~Y~^~None~^~vkBindBufferMemory~^~VUID-vkBindBufferMemory-device-parameter~^~core~^~The spec valid usage text states 'device must be a valid VkDevice handle' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkBindBufferMemory-device-parameter)~^~implicit
@@ -1706,7 +1706,7 @@ VALIDATION_ERROR_17400832~^~Y~^~BindInvalidMemory~^~vkBindImageMemory~^~VUID-vkB
 VALIDATION_ERROR_17400834~^~N~^~Unknown~^~vkBindImageMemory~^~VUID-vkBindImageMemory-image-01050~^~(VK_NV_dedicated_allocation)~^~The spec valid usage text states 'If image was created with VkDedicatedAllocationImageCreateInfoNV::dedicatedAllocation equal to VK_TRUE, memory must have been created with VkDedicatedAllocationMemoryAllocateInfoNV::image equal to an image handle created with identical creation parameters to image and memoryOffset must be zero' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-vkBindImageMemory-image-01050)~^~
 VALIDATION_ERROR_17400836~^~N~^~Unknown~^~vkBindImageMemory~^~VUID-vkBindImageMemory-image-01051~^~(VK_NV_dedicated_allocation)+!(VK_KHR_dedicated_allocation)~^~The spec valid usage text states 'If image was not created with VkDedicatedAllocationImageCreateInfoNV::dedicatedAllocation equal to VK_TRUE, memory must not have been allocated dedicated for a specific buffer or image' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkBindImageMemory-image-01051)~^~
 VALIDATION_ERROR_17400b4a~^~N~^~None~^~vkBindImageMemory~^~VUID-vkBindImageMemory-image-01445~^~(VK_KHR_dedicated_allocation)~^~The spec valid usage text states 'If image requires a dedicated allocation (as reported by vkGetImageMemoryRequirements2KHR in VkMemoryDedicatedRequirementsKHR::requiresDedicatedAllocation for image), memory must have been created with VkMemoryDedicatedAllocateInfoKHR::image equal to image' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-vkBindImageMemory-image-01445)~^~
-VALIDATION_ERROR_17400bca~^~Y~^~None~^~vkBindImageMemory~^~VUID-vkBindImageMemory-memory-01509~^~(VK_KHR_dedicated_allocation)~^~The spec valid usage text states 'If the VkmemoryAllocateInfo provided when memory was allocated included an instance of VkMemoryDedicatedAllocateInfoKHR in its pNext chain, and VkMemoryDedicatedAllocateInfoKHR::image was not VK_NULL_HANDLE, then image must equal VkMemoryDedicatedAllocateInfoKHR::image and memoryOffset must be zero.' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-vkBindImageMemory-memory-01509)~^~
+VALIDATION_ERROR_17400bca~^~Y~^~DedicatedAllocation~^~vkBindImageMemory~^~VUID-vkBindImageMemory-memory-01509~^~(VK_KHR_dedicated_allocation)~^~The spec valid usage text states 'If the VkmemoryAllocateInfo provided when memory was allocated included an instance of VkMemoryDedicatedAllocateInfoKHR in its pNext chain, and VkMemoryDedicatedAllocateInfoKHR::image was not VK_NULL_HANDLE, then image must equal VkMemoryDedicatedAllocateInfoKHR::image and memoryOffset must be zero.' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-vkBindImageMemory-memory-01509)~^~
 VALIDATION_ERROR_17400c90~^~N~^~None~^~vkBindImageMemory~^~VUID-vkBindImageMemory-image-01608~^~(VK_KHR_sampler_ycbcr_conversion)~^~The spec valid usage text states 'image must not have been created with the VK_IMAGE_CREATE_DISJOINT_BIT_KHR set.' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-vkBindImageMemory-image-01608)~^~
 VALIDATION_ERROR_17405601~^~Y~^~None~^~vkBindImageMemory~^~VUID-vkBindImageMemory-device-parameter~^~core~^~The spec valid usage text states 'device must be a valid VkDevice handle' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkBindImageMemory-device-parameter)~^~implicit
 VALIDATION_ERROR_1740a001~^~Y~^~BindMemoryToDestroyedObject~^~vkBindImageMemory~^~VUID-vkBindImageMemory-image-parameter~^~core~^~The spec valid usage text states 'image must be a valid VkImage handle' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkBindImageMemory-image-parameter)~^~implicit
index 98d070f..402d7df 100644 (file)
@@ -25994,6 +25994,84 @@ TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
     m_errorMonitor->VerifyFound();
 }
 
+TEST_F(VkLayerTest, DedicatedAllocation) {
+    ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
+    if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME)) {
+        m_device_extension_names.push_back(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME);
+        m_device_extension_names.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
+    } else {
+        printf("             Dedicated allocation extension not supported, skipping test\n");
+        return;
+    }
+    ASSERT_NO_FATAL_FAILURE(InitState());
+
+    VkMemoryPropertyFlags mem_flags = 0;
+    const VkDeviceSize resource_size = 1024;
+    auto buffer_info = vk_testing::Buffer::create_info(resource_size, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
+    vk_testing::Buffer buffer;
+    buffer.init_no_mem(*m_device, buffer_info);
+    auto buffer_alloc_info = vk_testing::DeviceMemory::get_resource_alloc_info(*m_device, buffer.memory_requirements(), mem_flags);
+    auto buffer_dedicated_info = lvl_init_struct<VkMemoryDedicatedAllocateInfoKHR>();
+    buffer_dedicated_info.buffer = buffer.handle();
+    buffer_alloc_info.pNext = &buffer_dedicated_info;
+    vk_testing::DeviceMemory dedicated_buffer_memory;
+    dedicated_buffer_memory.init(*m_device, buffer_alloc_info);
+
+    vk_testing::Buffer wrong_buffer;
+    wrong_buffer.init_no_mem(*m_device, buffer_info);
+
+    // Bind with wrong buffer
+    m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_17000bc8);
+    vkBindBufferMemory(m_device->handle(), wrong_buffer.handle(), dedicated_buffer_memory.handle(), 0);
+    m_errorMonitor->VerifyFound();
+
+    // Bind with non-zero offset (same VUID)
+    m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_17000bc8);  // offset must be zero
+    m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_1700081a);  // offset pushes us past size
+    auto offset = buffer.memory_requirements().alignment;
+    vkBindBufferMemory(m_device->handle(), buffer.handle(), dedicated_buffer_memory.handle(), offset);
+    m_errorMonitor->VerifyFound();
+
+    // Bind correctly (depends on the "skip" above)
+    m_errorMonitor->ExpectSuccess();
+    vkBindBufferMemory(m_device->handle(), buffer.handle(), dedicated_buffer_memory.handle(), 0);
+    m_errorMonitor->VerifyNotFound();
+
+    // And for images...
+    vk_testing::Image image;
+    vk_testing::Image wrong_image;
+    auto image_info = vk_testing::Image::create_info();
+    image_info.extent.width = resource_size;
+    image_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
+    image_info.format = VK_FORMAT_R8G8B8A8_UNORM;
+    image.init_no_mem(*m_device, image_info);
+    wrong_image.init_no_mem(*m_device, image_info);
+
+    auto image_dedicated_info = lvl_init_struct<VkMemoryDedicatedAllocateInfoKHR>();
+    image_dedicated_info.image = image.handle();
+    auto image_alloc_info = vk_testing::DeviceMemory::get_resource_alloc_info(*m_device, image.memory_requirements(), mem_flags);
+    image_alloc_info.pNext = &image_dedicated_info;
+    vk_testing::DeviceMemory dedicated_image_memory;
+    dedicated_image_memory.init(*m_device, image_alloc_info);
+
+    // Bind with wrong image
+    m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_17400bca);
+    vkBindImageMemory(m_device->handle(), wrong_image.handle(), dedicated_image_memory.handle(), 0);
+    m_errorMonitor->VerifyFound();
+
+    // Bind with non-zero offset (same VUID)
+    m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_17400bca);  // offset must be zero
+    m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_17400832);  // offset pushes us past size
+    auto image_offset = image.memory_requirements().alignment;
+    vkBindImageMemory(m_device->handle(), image.handle(), dedicated_image_memory.handle(), image_offset);
+    m_errorMonitor->VerifyFound();
+
+    // Bind correctly (depends on the "skip" above)
+    m_errorMonitor->ExpectSuccess();
+    vkBindImageMemory(m_device->handle(), image.handle(), dedicated_image_memory.handle(), 0);
+    m_errorMonitor->VerifyNotFound();
+}
+
 TEST_F(VkPositiveLayerTest, ValidStructPNext) {
     TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");