Check for visibility in external_memory_host test
authorMichael Chock <mchock@nvidia.com>
Wed, 2 Mar 2022 17:16:34 +0000 (09:16 -0800)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Thu, 24 Mar 2022 19:48:59 +0000 (19:48 +0000)
The external_memory_host synchronization test uses mapMemory when
validating the contents of the external memory, but does not ensure that
the memory is host-visible. When choosing a memory type for the
host-visible memory, additionally check the HOST_VISIBLE flag.

Affects:

dEQP-VK.memory.external_memory_host.synchronization.synchronization

Components: Vulkan

VK-GL-CTS issue: 3547

Change-Id: I0cff8f42debedd01db1760881a6f5f9481ea39bf

external/vulkancts/modules/vulkan/memory/vktMemoryExternalMemoryHostTests.cpp

index 6888aed..90eba04 100644 (file)
@@ -93,7 +93,7 @@ protected:
        deUint32                                                getHostPointerMemoryTypeBits                            (void* hostPointer);
        Move<VkDeviceMemory>                    allocateMemoryFromHostPointer                           (deUint32 memoryTypeIndex);
        void                                                    logMemoryTypeIndexPropertyFlags                         (deUint32 index);
-       bool                                                    findCompatibleMemoryTypeIndexToTest                     (deUint32 resourceMemoryTypeBits, deUint32 hostPointerMemoryTypeBits, deUint32* outMemoryTypeIndexToTest);
+       bool                                                    findCompatibleMemoryTypeIndexToTest                     (deUint32 resourceMemoryTypeBits, deUint32 hostPointerMemoryTypeBits, deUint32 memoryPropertyFlagBits, deUint32* outMemoryTypeIndexToTest);
        bool                                                    findMemoryTypeIndexToTest                                       (deUint32 hostPointerMemoryTypeBits, deUint32* outMemoryTypeIndexToTest);
 
        const InstanceInterface&                                                m_vki;
@@ -260,11 +260,12 @@ void ExternalMemoryHostBaseTestInstance::logMemoryTypeIndexPropertyFlags (deUint
        m_log << tcu::TestLog::Message << getMemoryPropertyFlagsStr(m_memoryProps.memoryTypes[index].propertyFlags) << tcu::TestLog::EndMessage;
 }
 
-bool ExternalMemoryHostBaseTestInstance::findCompatibleMemoryTypeIndexToTest (deUint32 resourceMemoryTypeBits, deUint32 hostPointerMemoryTypeBits, deUint32* outMemoryTypeIndexToTest)
+bool ExternalMemoryHostBaseTestInstance::findCompatibleMemoryTypeIndexToTest (deUint32 resourceMemoryTypeBits, deUint32 hostPointerMemoryTypeBits, deUint32 memoryPropertyFlagBits, deUint32* outMemoryTypeIndexToTest)
 {
        for (deUint32 bitMaskPosition = 0; bitMaskPosition < VK_MAX_MEMORY_TYPES; bitMaskPosition++)
        {
-               if (isBitSet(resourceMemoryTypeBits & hostPointerMemoryTypeBits, bitMaskPosition))
+               if (isBitSet(resourceMemoryTypeBits & hostPointerMemoryTypeBits, bitMaskPosition) &&
+                       (m_memoryProps.memoryTypes[bitMaskPosition].propertyFlags & memoryPropertyFlagBits) == memoryPropertyFlagBits)
                {
                        logMemoryTypeIndexPropertyFlags(bitMaskPosition);
                        *outMemoryTypeIndexToTest = bitMaskPosition;
@@ -276,7 +277,7 @@ bool ExternalMemoryHostBaseTestInstance::findCompatibleMemoryTypeIndexToTest (de
 
 bool ExternalMemoryHostBaseTestInstance::findMemoryTypeIndexToTest (deUint32 hostPointerMemoryTypeBits, deUint32* outMemoryTypeIndexToTest)
 {
-       return findCompatibleMemoryTypeIndexToTest(~0u, hostPointerMemoryTypeBits, outMemoryTypeIndexToTest);
+       return findCompatibleMemoryTypeIndexToTest(~0u, hostPointerMemoryTypeBits, 0u, outMemoryTypeIndexToTest);
 }
 
 tcu::TestStatus ExternalMemoryHostBaseTestInstance::iterate (void)
@@ -352,7 +353,7 @@ tcu::TestStatus ExternalMemoryHostRenderImageTestInstance::iterate ()
        // Find the usable memory type index.
        const auto hostPointerMemoryTypeBits = getHostPointerMemoryTypeBits(m_hostMemoryAlloc);
 
-       if (findCompatibleMemoryTypeIndexToTest(imageMemoryRequirements.memoryTypeBits, hostPointerMemoryTypeBits, &memoryTypeIndexToTest))
+       if (findCompatibleMemoryTypeIndexToTest(imageMemoryRequirements.memoryTypeBits, hostPointerMemoryTypeBits, 0u, &memoryTypeIndexToTest))
                m_deviceMemoryAllocatedFromHostPointer = allocateMemoryFromHostPointer(memoryTypeIndexToTest);
        else
                TCU_THROW(NotSupportedError, "Compatible memory type not found");
@@ -817,8 +818,11 @@ tcu::TestStatus ExternalMemoryHostSynchronizationTestInstance::iterate ()
 
        //find the usable memory type index
        hostPointerMemoryTypeBits                               = getHostPointerMemoryTypeBits(m_hostMemoryAlloc);
-       if (findCompatibleMemoryTypeIndexToTest(bufferMemoryRequirements.memoryTypeBits, hostPointerMemoryTypeBits, &memoryTypeIndexToTest))
+       if (findCompatibleMemoryTypeIndexToTest(bufferMemoryRequirements.memoryTypeBits, hostPointerMemoryTypeBits,
+               VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &memoryTypeIndexToTest))
+       {
                m_deviceMemoryAllocatedFromHostPointer = allocateMemoryFromHostPointer(memoryTypeIndexToTest);
+       }
        else
                TCU_THROW(NotSupportedError, "Compatible memory type not found");