Test texture gather with separate sparse binding queue
authorPaavo Pessi <paavo.pessi@siru.fi>
Fri, 3 Nov 2017 11:49:27 +0000 (13:49 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Wed, 31 Jan 2018 10:04:31 +0000 (05:04 -0500)
Existing texture gather tests assume the binding queue is part of
graphics queue. Tests were modified to support both combined and
separate sparse binding queues.

Affects:

dEQP-VK.glsl.texture_gather.*.sparse_*

Components: Vulkan

VK-GL-CTS issue: 361

Change-Id: I0c2160649e6d0fd3e45401a43ab6b3960312c5e0

external/vulkancts/modules/vulkan/shaderrender/vktShaderRender.cpp
external/vulkancts/modules/vulkan/shaderrender/vktShaderRender.hpp

index 1f81021..410594c 100644 (file)
@@ -535,7 +535,6 @@ ShaderRenderCaseInstance::ShaderRenderCaseInstance (Context& context)
        : vkt::TestInstance             (context)
        , m_imageBackingMode    (IMAGE_BACKING_MODE_REGULAR)
        , m_quadGridSize                (static_cast<deUint32>(GRID_SIZE_DEFAULT_FRAGMENT))
-       , m_sparseContext               (createSparseContext())
        , m_memAlloc                    (getAllocator())
        , m_clearColor                  (DEFAULT_CLEAR_COLOR)
        , m_isVertexCase                (false)
@@ -565,7 +564,6 @@ ShaderRenderCaseInstance::ShaderRenderCaseInstance (Context&                                        context,
                                                                ? static_cast<deUint32>(GRID_SIZE_DEFAULT_VERTEX)
                                                                : static_cast<deUint32>(GRID_SIZE_DEFAULT_FRAGMENT))
                                                         : gridSize)
-       , m_sparseContext               (createSparseContext())
        , m_memAlloc                    (getAllocator())
        , m_clearColor                  (DEFAULT_CLEAR_COLOR)
        , m_isVertexCase                (isVertexCase)
@@ -594,7 +592,6 @@ ShaderRenderCaseInstance::ShaderRenderCaseInstance (Context&                                        context,
                                                                ? static_cast<deUint32>(GRID_SIZE_DEFAULT_VERTEX)
                                                                : static_cast<deUint32>(GRID_SIZE_DEFAULT_FRAGMENT))
                                                         : gridSize)
-       , m_sparseContext               (createSparseContext())
        , m_memAlloc                    (getAllocator())
        , m_clearColor                  (DEFAULT_CLEAR_COLOR)
        , m_isVertexCase                (isVertexCase)
@@ -609,86 +606,8 @@ ShaderRenderCaseInstance::ShaderRenderCaseInstance (Context&                                       context,
 {
 }
 
-static deUint32 findQueueFamilyIndexWithCaps (const InstanceInterface& vkInstance, VkPhysicalDevice physicalDevice, VkQueueFlags requiredCaps)
-{
-       const std::vector<VkQueueFamilyProperties>      queueProps      = getPhysicalDeviceQueueFamilyProperties(vkInstance, physicalDevice);
-
-       for (size_t queueNdx = 0; queueNdx < queueProps.size(); queueNdx++)
-       {
-               if ((queueProps[queueNdx].queueFlags & requiredCaps) == requiredCaps)
-                       return (deUint32)queueNdx;
-       }
-
-       TCU_THROW(NotSupportedError, "No matching queue found");
-}
-
-
-ShaderRenderCaseInstance::SparseContext::SparseContext (vkt::Context& context)
-       : m_context                             (context)
-       , m_queueFamilyIndex    (findQueueFamilyIndexWithCaps(context.getInstanceInterface(), context.getPhysicalDevice(), VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_SPARSE_BINDING_BIT))
-       , m_device                              (createDevice())
-       , m_deviceInterface             (context.getInstanceInterface(), *m_device)
-       , m_queue                               (getDeviceQueue(m_deviceInterface, *m_device, m_queueFamilyIndex, 0))
-       , m_allocator                   (createAllocator())
-{
-}
-
-Move<VkDevice> ShaderRenderCaseInstance::SparseContext::createDevice () const
-{
-       const InstanceInterface&                                vk                                      = m_context.getInstanceInterface();
-       const VkPhysicalDevice                                  physicalDevice          = m_context.getPhysicalDevice();
-       const VkPhysicalDeviceFeatures                  deviceFeatures          = getPhysicalDeviceFeatures(vk, physicalDevice);
-
-       VkDeviceQueueCreateInfo                                 queueInfo;
-       VkDeviceCreateInfo                                              deviceInfo;
-       const float                                                             queuePriority           = 1.0f;
-
-       deMemset(&queueInfo,    0, sizeof(queueInfo));
-       deMemset(&deviceInfo,   0, sizeof(deviceInfo));
-
-       queueInfo.sType                                                 = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
-       queueInfo.pNext                                                 = DE_NULL;
-       queueInfo.flags                                                 = (VkDeviceQueueCreateFlags)0u;
-       queueInfo.queueFamilyIndex                              = m_queueFamilyIndex;
-       queueInfo.queueCount                                    = 1u;
-       queueInfo.pQueuePriorities                              = &queuePriority;
-
-       deviceInfo.sType                                                = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
-       deviceInfo.pNext                                                = DE_NULL;
-       deviceInfo.queueCreateInfoCount                 = 1u;
-       deviceInfo.pQueueCreateInfos                    = &queueInfo;
-       deviceInfo.enabledExtensionCount                = 0u;
-       deviceInfo.ppEnabledExtensionNames              = DE_NULL;
-       deviceInfo.enabledLayerCount                    = 0u;
-       deviceInfo.ppEnabledLayerNames                  = DE_NULL;
-       deviceInfo.pEnabledFeatures                             = &deviceFeatures;
-
-       return vk::createDevice(vk, physicalDevice, &deviceInfo);
-}
-
-vk::Allocator* ShaderRenderCaseInstance::SparseContext::createAllocator        () const
-{
-       const VkPhysicalDeviceMemoryProperties memoryProperties = getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice());
-       return new SimpleAllocator(m_deviceInterface, *m_device, memoryProperties);
-}
-
-ShaderRenderCaseInstance::SparseContext* ShaderRenderCaseInstance::createSparseContext (void) const
-{
-       if (m_imageBackingMode == IMAGE_BACKING_MODE_SPARSE)
-       {
-               return new SparseContext(m_context);
-       }
-
-       return DE_NULL;
-}
-
 vk::Allocator& ShaderRenderCaseInstance::getAllocator (void) const
 {
-       if (m_imageBackingMode == IMAGE_BACKING_MODE_SPARSE)
-       {
-               return *m_sparseContext->m_allocator;
-       }
-
        return m_context.getDefaultAllocator();
 }
 
@@ -698,45 +617,41 @@ ShaderRenderCaseInstance::~ShaderRenderCaseInstance (void)
 
 VkDevice ShaderRenderCaseInstance::getDevice (void) const
 {
-       if (m_imageBackingMode == IMAGE_BACKING_MODE_SPARSE)
-               return *m_sparseContext->m_device;
-
        return m_context.getDevice();
 }
 
 deUint32 ShaderRenderCaseInstance::getUniversalQueueFamilyIndex        (void) const
 {
-       if (m_imageBackingMode == IMAGE_BACKING_MODE_SPARSE)
-               return m_sparseContext->m_queueFamilyIndex;
-
        return m_context.getUniversalQueueFamilyIndex();
 }
 
-const DeviceInterface& ShaderRenderCaseInstance::getDeviceInterface (void) const
+deUint32 ShaderRenderCaseInstance::getSparseQueueFamilyIndex (void) const
 {
-       if (m_imageBackingMode == IMAGE_BACKING_MODE_SPARSE)
-               return m_sparseContext->m_deviceInterface;
+       return m_context.getSparseQueueFamilyIndex();
+}
 
+const DeviceInterface& ShaderRenderCaseInstance::getDeviceInterface (void) const
+{
        return m_context.getDeviceInterface();
 }
 
 VkQueue ShaderRenderCaseInstance::getUniversalQueue (void) const
 {
-       if (m_imageBackingMode == IMAGE_BACKING_MODE_SPARSE)
-               return m_sparseContext->m_queue;
-
        return m_context.getUniversalQueue();
 }
 
+VkQueue ShaderRenderCaseInstance::getSparseQueue (void) const
+{
+       return m_context.getSparseQueue();
+}
+
 VkPhysicalDevice ShaderRenderCaseInstance::getPhysicalDevice (void) const
 {
-       // Same in sparse and regular case
        return m_context.getPhysicalDevice();
 }
 
 const InstanceInterface& ShaderRenderCaseInstance::getInstanceInterface (void) const
 {
-       // Same in sparse and regular case
        return m_context.getInstanceInterface();
 }
 
@@ -1424,6 +1339,7 @@ void ShaderRenderCaseInstance::uploadSparseImage (const tcu::TextureFormat&               tex
        const DeviceInterface&                                  vk                                              = getDeviceInterface();
        const VkPhysicalDevice                                  physicalDevice                  = getPhysicalDevice();
        const VkQueue                                                   queue                                   = getUniversalQueue();
+       const VkQueue                                                   sparseQueue                             = getSparseQueue();
        const deUint32                                                  queueFamilyIndex                = getUniversalQueueFamilyIndex();
        const InstanceInterface&                                instance                                = getInstanceInterface();
        const VkPhysicalDeviceProperties                deviceProperties                = getPhysicalDeviceProperties(instance, physicalDevice);
@@ -1675,7 +1591,7 @@ void ShaderRenderCaseInstance::uploadSparseImage (const tcu::TextureFormat&               tex
                        bindSparseInfo.pImageOpaqueBinds = &imageMipTailBindInfo;
                }
 
-               VK_CHECK(vk.queueBindSparse(queue, 1u, &bindSparseInfo, DE_NULL));
+               VK_CHECK(vk.queueBindSparse(sparseQueue, 1u, &bindSparseInfo, DE_NULL));
        }
 
        Move<VkCommandPool>             cmdPool;
@@ -1838,6 +1754,7 @@ void ShaderRenderCaseInstance::uploadSparseImage (const tcu::TextureFormat&               tex
        {
                VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *fence));
                VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), true, ~(0ull) /* infinity */));
+               VK_CHECK(vk.queueWaitIdle(sparseQueue));
        }
        catch (...)
        {
@@ -2067,13 +1984,23 @@ void ShaderRenderCaseInstance::createSamplerUniform (deUint32                                           bindingLocati
        const VkDevice                                  vkDevice                        = getDevice();
        const DeviceInterface&                  vk                                      = getDeviceInterface();
        const deUint32                                  queueFamilyIndex        = getUniversalQueueFamilyIndex();
+       const deUint32                                  sparseFamilyIndex       = (m_imageBackingMode == IMAGE_BACKING_MODE_SPARSE) ? getSparseQueueFamilyIndex() : queueFamilyIndex;
 
        const bool                                              isShadowSampler         = refSampler.compare != tcu::Sampler::COMPAREMODE_NONE;
        const VkImageAspectFlags                aspectMask                      = isShadowSampler ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
        const VkImageViewType                   imageViewType           = textureTypeToImageViewType(textureType);
        const VkImageType                               imageType                       = viewTypeToImageType(imageViewType);
+       const VkSharingMode                             sharingMode                     = (queueFamilyIndex != sparseFamilyIndex) ? VK_SHARING_MODE_CONCURRENT : VK_SHARING_MODE_EXCLUSIVE;
        const VkFormat                                  format                          = mapTextureFormat(texFormat);
        const bool                                              isCube                          = imageViewType == VK_IMAGE_VIEW_TYPE_CUBE || imageViewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY;
+
+       const deUint32                                  queueIndexCount         = (queueFamilyIndex != sparseFamilyIndex) ? 2 : 1;
+       const deUint32                                  queueIndices[]          =
+       {
+               queueFamilyIndex,
+               sparseFamilyIndex
+       };
+
        VkImageCreateFlags                              imageCreateFlags        = isCube ? (VkImageCreateFlags)VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : (VkImageCreateFlags)0;
        VkImageUsageFlags                               imageUsageFlags         = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
        Move<VkImage>                                   vkTexture;
@@ -2102,9 +2029,9 @@ void ShaderRenderCaseInstance::createSamplerUniform (deUint32                                             bindingLocati
                textureParams.samples,                                                                                  // VkSampleCountFlagBits        samples;
                VK_IMAGE_TILING_OPTIMAL,                                                                                // VkImageTiling                        tiling;
                imageUsageFlags,                                                                                                // VkImageUsageFlags            usage;
-               VK_SHARING_MODE_EXCLUSIVE,                                                                              // VkSharingMode                        sharingMode;
-               1u,                                                                                                                             // deUint32                                     queueFamilyIndexCount;
-               &queueFamilyIndex,                                                                                              // const deUint32*                      pQueueFamilyIndices;
+               sharingMode,                                                                                                    // VkSharingMode                        sharingMode;
+               queueIndexCount,                                                                                                // deUint32                                     queueFamilyIndexCount;
+               queueIndices,                                                                                                   // const deUint32*                      pQueueFamilyIndices;
                VK_IMAGE_LAYOUT_UNDEFINED                                                                               // VkImageLayout                        initialLayout;
        };
 
index c53c299..5069665 100644 (file)
@@ -524,25 +524,7 @@ protected:
        ImageBackingMode                                                                        m_imageBackingMode;
 
        deUint32                                                                                        m_quadGridSize;
-private:
-
-       struct SparseContext
-       {
-                                                                                       SparseContext   (vkt::Context& context);
-
-               vkt::Context&                                           m_context;
-               const deUint32                                          m_queueFamilyIndex;
-               vk::Unique<vk::VkDevice>                        m_device;
-               vk::DeviceDriver                                        m_deviceInterface;
-               const vk::VkQueue                                       m_queue;
-               const de::UniquePtr<vk::Allocator>      m_allocator;
-       private:
-               vk::Move<vk::VkDevice>                          createDevice    (void) const;
-               vk::Allocator*                                          createAllocator (void) const;
-
-       };
 
-       de::UniquePtr<SparseContext>                                            m_sparseContext;
 protected:
        vk::Allocator&                                                                          m_memAlloc;
        const tcu::Vec4                                                                         m_clearColor;
@@ -674,14 +656,14 @@ private:
        vk::VkSampleCountFlagBits                                                       m_sampleCount;
        std::vector<vk::VkPushConstantRange>                            m_pushConstantRanges;
 
-       // Wrapper functions around m_context calls to support sparse cases.
        vk::VkDevice                                                                            getDevice                                               (void) const;
        deUint32                                                                                        getUniversalQueueFamilyIndex    (void) const;
+       deUint32                                                                                        getSparseQueueFamilyIndex               (void) const;
        const vk::DeviceInterface&                                                      getDeviceInterface                              (void) const;
        vk::VkQueue                                                                                     getUniversalQueue                               (void) const;
+       vk::VkQueue                                                                                     getSparseQueue                                  (void) const;
        vk::VkPhysicalDevice                                                            getPhysicalDevice                               (void) const;
        const vk::InstanceInterface&                                            getInstanceInterface                    (void) const;
-       SparseContext*                                                                          createSparseContext                             (void) const;
        vk::Allocator&                                                                          getAllocator                                    (void) const;
 };