Add DescriptorSet{Pool, Layout, Update} builders.
authorJarkko Pöyry <jpoyry@google.com>
Thu, 30 Jul 2015 18:03:32 +0000 (11:03 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Thu, 30 Jul 2015 22:49:45 +0000 (15:49 -0700)
Change-Id: I949b4b127cb4401ac96173ca25a09e70cd2de827

external/vulkancts/framework/vulkan/CMakeLists.txt
external/vulkancts/framework/vulkan/vkBuilderUtil.cpp [new file with mode: 0644]
external/vulkancts/framework/vulkan/vkBuilderUtil.hpp [new file with mode: 0644]
external/vulkancts/framework/vulkan/vkRefUtil.cpp
external/vulkancts/framework/vulkan/vkRefUtil.hpp

index 048c5f6..c39a07f 100644 (file)
@@ -3,6 +3,8 @@
 set(VKUTIL_SRCS
        vkApiVersion.cpp
        vkApiVersion.hpp
+       vkBuilderUtil.cpp
+       vkBuilderUtil.hpp
        vkDefs.cpp
        vkDefs.hpp
        vkRef.cpp
diff --git a/external/vulkancts/framework/vulkan/vkBuilderUtil.cpp b/external/vulkancts/framework/vulkan/vkBuilderUtil.cpp
new file mode 100644 (file)
index 0000000..13aec2d
--- /dev/null
@@ -0,0 +1,191 @@
+/*-------------------------------------------------------------------------
+ * Vulkan CTS Framework
+ * --------------------
+ *
+ * Copyright (c) 2015 Google Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and/or associated documentation files (the
+ * "Materials"), to deal in the Materials without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Materials, and to
+ * permit persons to whom the Materials are furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice(s) and this permission notice shall be
+ * included in all copies or substantial portions of the Materials.
+ *
+ * The Materials are Confidential Information as defined by the
+ * Khronos Membership Agreement until designated non-confidential by
+ * Khronos, at which point this condition clause shall be removed.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//*!
+ * \file
+ * \brief Vulkan object builder utilities.
+ *//*--------------------------------------------------------------------*/
+
+#include "vkBuilderUtil.hpp"
+
+#include "vkRefUtil.hpp"
+
+namespace vk
+{
+
+// DescriptorSetLayoutBuilder
+
+DescriptorSetLayoutBuilder::DescriptorSetLayoutBuilder (void)
+{
+}
+
+DescriptorSetLayoutBuilder& DescriptorSetLayoutBuilder::addBinding (VkDescriptorType   descriptorType,
+                                                                                                                                       deUint32                        arraySize,
+                                                                                                                                       VkShaderStageFlags      stageFlags,
+                                                                                                                                       const VkSampler*        pImmutableSamplers)
+{
+       const VkDescriptorSetLayoutBinding binding =
+       {
+               descriptorType,                 //!< descriptorType
+               arraySize,                              //!< arraySize
+               stageFlags,                             //!< stageFlags
+               pImmutableSamplers,             //!< pImmutableSamplers
+       };
+       m_bindings.push_back(binding);
+       return *this;
+}
+
+Move<VkDescriptorSetLayout> DescriptorSetLayoutBuilder::build (const DeviceInterface& vk, VkDevice device) const
+{
+       const VkDescriptorSetLayoutBinding* const       bindingPtr      = (m_bindings.empty()) ? (DE_NULL) : (&m_bindings[0]);
+       const VkDescriptorSetLayoutCreateInfo           createInfo      =
+       {
+               VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
+               DE_NULL,
+               (deUint32)m_bindings.size(),            //!< count
+               bindingPtr,                                                     //!< pBinding
+       };
+
+       return createDescriptorSetLayout(vk, device, &createInfo);
+}
+
+// DescriptorPoolBuilder
+
+DescriptorPoolBuilder::DescriptorPoolBuilder (void)
+{
+}
+
+DescriptorPoolBuilder& DescriptorPoolBuilder::addType (VkDescriptorType type, deUint32 numDescriptors)
+{
+       if (numDescriptors == 0u)
+       {
+               // nothing to do
+               return *this;
+       }
+       else
+       {
+               for (size_t ndx = 0; ndx < m_counts.size(); ++ndx)
+               {
+                       if (m_counts[ndx].type == type)
+                       {
+                               // augment existing requirement
+                               m_counts[ndx].count += numDescriptors;
+                               return *this;
+                       }
+               }
+
+               {
+                       // new requirement
+                       const VkDescriptorTypeCount typeCount =
+                       {
+                               type,                   //!< type
+                               numDescriptors, //!< count
+                       };
+
+                       m_counts.push_back(typeCount);
+                       return *this;
+               }
+       }
+}
+
+Move<VkDescriptorPool> DescriptorPoolBuilder::build (const DeviceInterface& vk, VkDevice device, VkDescriptorPoolUsage poolUsage, deUint32 maxSets) const
+{
+       const VkDescriptorTypeCount* const      typeCountPtr    = (m_counts.empty()) ? (DE_NULL) : (&m_counts[0]);
+       const VkDescriptorPoolCreateInfo        createInfo              =
+       {
+               VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
+               DE_NULL,
+               (deUint32)m_counts.size(),              //!< count
+               typeCountPtr,                                   //!< pTypeCount
+       };
+
+       return createDescriptorPool(vk, device, poolUsage, maxSets, &createInfo);
+}
+
+// DescriptorSetUpdateBuilder
+
+DescriptorSetUpdateBuilder::DescriptorSetUpdateBuilder (void)
+{
+}
+
+DescriptorSetUpdateBuilder& DescriptorSetUpdateBuilder::write (VkDescriptorSet                 destSet,
+                                                                                                                          deUint32                                     destBinding,
+                                                                                                                          deUint32                                     destArrayElement,
+                                                                                                                          deUint32                                     count,
+                                                                                                                          VkDescriptorType                     descriptorType,
+                                                                                                                          const VkDescriptorInfo*      pDescriptors)
+{
+       const VkWriteDescriptorSet write =
+       {
+               VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
+               DE_NULL,
+               destSet,                        //!< destSet
+               destBinding,            //!< destBinding
+               destArrayElement,       //!< destArrayElement
+               count,                          //!< count
+               descriptorType,         //!< descriptorType
+               pDescriptors,           //!< pDescriptors
+       };
+       m_writes.push_back(write);
+       return *this;
+}
+
+DescriptorSetUpdateBuilder& DescriptorSetUpdateBuilder::copy (VkDescriptorSet  srcSet,
+                                                                                                                         deUint32                      srcBinding,
+                                                                                                                         deUint32                      srcArrayElement,
+                                                                                                                         VkDescriptorSet       destSet,
+                                                                                                                         deUint32                      destBinding,
+                                                                                                                         deUint32                      destArrayElement,
+                                                                                                                         deUint32                      count)
+{
+       const VkCopyDescriptorSet copy =
+       {
+               VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET,
+               DE_NULL,
+               srcSet,                         //!< srcSet
+               srcBinding,                     //!< srcBinding
+               srcArrayElement,        //!< srcArrayElement
+               destSet,                        //!< destSet
+               destBinding,            //!< destBinding
+               destArrayElement,       //!< destArrayElement
+               count,                          //!< count
+       };
+       m_copies.push_back(copy);
+       return *this;
+}
+
+void DescriptorSetUpdateBuilder::update (const DeviceInterface& vk, VkDevice device) const
+{
+       const VkWriteDescriptorSet* const       writePtr        = (m_writes.empty()) ? (DE_NULL) : (&m_writes[0]);
+       const VkCopyDescriptorSet* const        copyPtr         = (m_copies.empty()) ? (DE_NULL) : (&m_copies[0]);
+
+       VK_CHECK(vk.updateDescriptorSets(device, (deUint32)m_writes.size(), writePtr, (deUint32)m_copies.size(), copyPtr));
+}
+
+} // vk
diff --git a/external/vulkancts/framework/vulkan/vkBuilderUtil.hpp b/external/vulkancts/framework/vulkan/vkBuilderUtil.hpp
new file mode 100644 (file)
index 0000000..be1bcd5
--- /dev/null
@@ -0,0 +1,202 @@
+#ifndef _VKBUILDERUTIL_HPP
+#define _VKBUILDERUTIL_HPP
+/*-------------------------------------------------------------------------
+ * Vulkan CTS Framework
+ * --------------------
+ *
+ * Copyright (c) 2015 Google Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and/or associated documentation files (the
+ * "Materials"), to deal in the Materials without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Materials, and to
+ * permit persons to whom the Materials are furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice(s) and this permission notice shall be
+ * included in all copies or substantial portions of the Materials.
+ *
+ * The Materials are Confidential Information as defined by the
+ * Khronos Membership Agreement until designated non-confidential by
+ * Khronos, at which point this condition clause shall be removed.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//*!
+ * \file
+ * \brief Vulkan object builder utilities.
+ *//*--------------------------------------------------------------------*/
+
+#include "vkDefs.hpp"
+#include "vkRef.hpp"
+
+#include <vector>
+
+namespace vk
+{
+
+class DescriptorSetLayoutBuilder
+{
+public:
+                                                                                               DescriptorSetLayoutBuilder      (void);
+
+       DescriptorSetLayoutBuilder&                                     addBinding                                      (VkDescriptorType       descriptorType,
+                                                                                                                                                        deUint32                       arraySize,
+                                                                                                                                                        VkShaderStageFlags     stageFlags,
+                                                                                                                                                        const VkSampler*       pImmutableSamplers);
+
+       Move<VkDescriptorSetLayout>                                     build                                           (const DeviceInterface& vk, VkDevice device) const;
+
+       // helpers
+
+       inline DescriptorSetLayoutBuilder&                      addSingleBinding                        (VkDescriptorType       descriptorType,
+                                                                                                                                                        VkShaderStageFlags     stageFlags)
+       {
+               return addBinding(descriptorType, 1u, stageFlags, (VkSampler*)DE_NULL);
+       }
+       inline DescriptorSetLayoutBuilder&                      addArrayBinding                         (VkDescriptorType       descriptorType,
+                                                                                                                                                        deUint32                       arraySize,
+                                                                                                                                                        VkShaderStageFlags     stageFlags)
+       {
+               return addBinding(descriptorType, arraySize, stageFlags, (VkSampler*)DE_NULL);
+       }
+       inline DescriptorSetLayoutBuilder&                      addSingleSamplerBinding         (VkDescriptorType       descriptorType,
+                                                                                                                                                        VkShaderStageFlags     stageFlags,
+                                                                                                                                                        const VkSampler*       immutableSampler)       //!< \note: Using pointer to sampler to clarify that handle is not
+                                                                                                                                                                                                                                       //!<        copied and argument lifetime is expected to cover build()
+                                                                                                                                                                                                                                       //!<        call.
+       {
+               return addBinding(descriptorType, 1u, stageFlags, immutableSampler);
+       }
+       inline DescriptorSetLayoutBuilder&                      addArraySamplerBinding          (VkDescriptorType       descriptorType,
+                                                                                                                                                        deUint32                       arraySize,
+                                                                                                                                                        VkShaderStageFlags     stageFlags,
+                                                                                                                                                        const VkSampler*       pImmutableSamplers)
+       {
+               return addBinding(descriptorType, arraySize, stageFlags, pImmutableSamplers);
+       }
+
+private:
+                                                                                               DescriptorSetLayoutBuilder      (const DescriptorSetLayoutBuilder&); // delete
+       DescriptorSetLayoutBuilder&                                     operator=                                       (const DescriptorSetLayoutBuilder&); // delete
+
+       std::vector<VkDescriptorSetLayoutBinding>       m_bindings;
+};
+
+class DescriptorPoolBuilder
+{
+public:
+                                                                               DescriptorPoolBuilder   (void);
+
+       DescriptorPoolBuilder&                          addType                                 (VkDescriptorType type, deUint32 numDescriptors = 1u);
+       Move<VkDescriptorPool>                          build                                   (const DeviceInterface& vk, VkDevice device, VkDescriptorPoolUsage poolUsage, deUint32 maxSets) const;
+
+private:
+                                                                               DescriptorPoolBuilder   (const DescriptorPoolBuilder&); // delete
+       DescriptorPoolBuilder&                          operator=                               (const DescriptorPoolBuilder&); // delete
+
+       std::vector<VkDescriptorTypeCount>      m_counts;
+};
+
+class DescriptorSetUpdateBuilder
+{
+public:
+       class Location
+       {
+       public:
+               static inline Location  binding                         (deUint32 binding)
+               {
+                       return Location(binding, 0u);
+               }
+               static inline Location  bindingArrayElement     (deUint32 binding, deUint32 arrayElement)
+               {
+                       return Location(binding, arrayElement);
+               }
+
+       private:
+               // \note private to force use of factory methods that have more descriptive names
+               inline                                  Location                        (deUint32 binding, deUint32 arrayElement)
+                       : m_binding                     (binding)
+                       , m_arrayElement        (arrayElement)
+               {
+               }
+
+               friend class DescriptorSetUpdateBuilder;
+
+               const deUint32                  m_binding;
+               const deUint32                  m_arrayElement;
+       };
+
+                                                                               DescriptorSetUpdateBuilder      (void);
+
+       DescriptorSetUpdateBuilder&                     write                                           (VkDescriptorSet                        destSet,
+                                                                                                                                        deUint32                                       destBinding,
+                                                                                                                                        deUint32                                       destArrayElement,
+                                                                                                                                        deUint32                                       count,
+                                                                                                                                        VkDescriptorType                       descriptorType,
+                                                                                                                                        const VkDescriptorInfo*        pDescriptors);
+
+       DescriptorSetUpdateBuilder&                     copy                                            (VkDescriptorSet        srcSet,
+                                                                                                                                        deUint32                       srcBinding,
+                                                                                                                                        deUint32                       srcArrayElement,
+                                                                                                                                        VkDescriptorSet        destSet,
+                                                                                                                                        deUint32                       destBinding,
+                                                                                                                                        deUint32                       destArrayElement,
+                                                                                                                                        deUint32                       count);
+
+       void                                                            update                                          (const DeviceInterface& vk, VkDevice device) const;
+
+       // helpers
+
+       inline DescriptorSetUpdateBuilder&      writeSingle                                     (VkDescriptorSet                        destSet,
+                                                                                                                                        const Location&                        destLocation,
+                                                                                                                                        VkDescriptorType                       descriptorType,
+                                                                                                                                        const VkDescriptorInfo*        descriptor)
+       {
+               return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, descriptor);
+       }
+
+       inline DescriptorSetUpdateBuilder&      writeArray                                      (VkDescriptorSet                        destSet,
+                                                                                                                                        const Location&                        destLocation,
+                                                                                                                                        VkDescriptorType                       descriptorType,
+                                                                                                                                        deUint32                                       numDescriptors,
+                                                                                                                                        const VkDescriptorInfo*        descriptors)
+       {
+               return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, descriptors);
+       }
+
+       inline DescriptorSetUpdateBuilder&      copySingle                                      (VkDescriptorSet        srcSet,
+                                                                                                                                        const Location&        srcLocation,
+                                                                                                                                        VkDescriptorSet        destSet,
+                                                                                                                                        const Location&        destLocation)
+       {
+               return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u);
+       }
+
+       inline DescriptorSetUpdateBuilder&      copyArray                                       (VkDescriptorSet        srcSet,
+                                                                                                                                        const Location&        srcLocation,
+                                                                                                                                        VkDescriptorSet        destSet,
+                                                                                                                                        const Location&        destLocation,
+                                                                                                                                        deUint32                       count)
+       {
+               return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, count);
+       }
+
+private:
+                                                                               DescriptorSetUpdateBuilder      (const DescriptorSetUpdateBuilder&); // delete
+       DescriptorSetUpdateBuilder&                     operator=                                       (const DescriptorSetUpdateBuilder&); // delete
+
+       std::vector<VkWriteDescriptorSet>       m_writes;
+       std::vector<VkCopyDescriptorSet>        m_copies;
+};
+
+} // vk
+
+#endif // _VKBUILDERUTIL_HPP
index bde4453..75c0f73 100644 (file)
@@ -53,7 +53,7 @@ Move<VkPipeline> createComputePipeline (const DeviceInterface& vk, VkDevice devi
        return Move<VkPipeline>(check<VkPipeline>(object), Deleter<VkPipeline>(vk, device));
 }
 
-Move<VkDescriptorSet> allocDescriptorSet (const DeviceInterface& vk, vk::VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, VkDescriptorSetLayout layout)
+Move<VkDescriptorSet> allocDescriptorSet (const DeviceInterface& vk, VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, VkDescriptorSetLayout layout)
 {
        VkDescriptorSet descriptorSet   = 0u;
        deUint32                numCreated              = 0;
index 46b134b..7dedbd7 100644 (file)
@@ -44,7 +44,7 @@ namespace vk
 
 Move<VkPipeline>               createGraphicsPipeline  (const DeviceInterface& vk, VkDevice device, VkPipelineCache pipelineCache, const VkGraphicsPipelineCreateInfo* pCreateInfo);
 Move<VkPipeline>               createComputePipeline   (const DeviceInterface& vk, VkDevice device, VkPipelineCache pipelineCache, const VkComputePipelineCreateInfo* pCreateInfo);
-Move<VkDescriptorSet>  allocDescriptorSet              (const DeviceInterface& vk, vk::VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, VkDescriptorSetLayout layout);
+Move<VkDescriptorSet>  allocDescriptorSet              (const DeviceInterface& vk, VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, VkDescriptorSetLayout layout);
 
 } // vk