OSDN Git Service

Descriptor Update Template implementation
authorAlexis Hetu <sugoi@google.com>
Tue, 29 Jan 2019 19:09:36 +0000 (14:09 -0500)
committerAlexis Hétu <sugoi@google.com>
Fri, 8 Mar 2019 19:51:36 +0000 (19:51 +0000)
Basic implementation of descriptor update template.
Only supports VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET template type.

Bug b/123244275

Change-Id: Iaf7c1e52bee6d2683a2f34bd2f780396aa953442
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26568
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
src/Vulkan/VkDescriptorSetLayout.hpp
src/Vulkan/VkDescriptorUpdateTemplate.cpp [new file with mode: 0644]
src/Vulkan/VkDescriptorUpdateTemplate.hpp [new file with mode: 0644]
src/Vulkan/libVulkan.cpp
src/Vulkan/vulkan.vcxproj
src/Vulkan/vulkan.vcxproj.filters

index d332c28..3905a16 100644 (file)
@@ -36,10 +36,10 @@ public:
        void initialize(VkDescriptorSet descriptorSet);
        size_t getSize() const;
        size_t getBindingOffset(uint32_t binding) const;
+       uint8_t* getOffsetPointer(VkDescriptorSet descriptorSet, uint32_t binding, uint32_t arrayElement, uint32_t count, size_t* typeSize) const;
 
 private:
        uint32_t getBindingIndex(uint32_t binding) const;
-       uint8_t* getOffsetPointer(VkDescriptorSet descriptorSet, uint32_t binding, uint32_t arrayElement, uint32_t count, size_t* typeSize) const;
        static const uint8_t* GetInputData(const VkWriteDescriptorSet& descriptorWrites);
 
        VkDescriptorSetLayoutCreateFlags flags;
diff --git a/src/Vulkan/VkDescriptorUpdateTemplate.cpp b/src/Vulkan/VkDescriptorUpdateTemplate.cpp
new file mode 100644 (file)
index 0000000..903f5f2
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright 2018 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "VkDescriptorUpdateTemplate.hpp"
+#include "VkDescriptorSetLayout.hpp"
+#include <cstring>
+
+namespace vk
+{
+       DescriptorUpdateTemplate::DescriptorUpdateTemplate(const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, void* mem) :\r
+               descriptorUpdateEntryCount(pCreateInfo->descriptorUpdateEntryCount),\r
+               descriptorUpdateEntries(reinterpret_cast<VkDescriptorUpdateTemplateEntry*>(mem)),\r
+               descriptorSetLayout(Cast(pCreateInfo->descriptorSetLayout))\r
+       {\r
+               for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++)\r
+               {\r
+                       descriptorUpdateEntries[i] = pCreateInfo->pDescriptorUpdateEntries[i];\r
+               }\r
+       }\r
+\r
+       size_t DescriptorUpdateTemplate::ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo* info)\r
+       {\r
+               return info->descriptorUpdateEntryCount * sizeof(VkDescriptorUpdateTemplateEntry);\r
+       }\r
+\r
+       void DescriptorUpdateTemplate::updateDescriptorSet(VkDescriptorSet descriptorSet, const void* pData)\r
+       {
+               for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++)
+               {
+                       for(uint32_t j = 0; j < descriptorUpdateEntries[i].descriptorCount; j++)
+                       {
+                               const char *memToRead = (const char *)pData + descriptorUpdateEntries[i].offset + j * descriptorUpdateEntries[i].stride;
+                               size_t typeSize = 0;
+                               uint8_t* memToWrite = descriptorSetLayout->getOffsetPointer(
+                                       descriptorSet, descriptorUpdateEntries[i].dstBinding, descriptorUpdateEntries[i].dstArrayElement, 1, &typeSize);
+                               memcpy(memToWrite, memToRead, typeSize);
+                       }
+               }\r
+       }
+}
\ No newline at end of file
diff --git a/src/Vulkan/VkDescriptorUpdateTemplate.hpp b/src/Vulkan/VkDescriptorUpdateTemplate.hpp
new file mode 100644 (file)
index 0000000..cb75f22
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright 2018 The SwiftShader Authors. All Rights Reserved.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//    http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+#ifndef VK_DESCRIPTOR_UPDATE_TEMPLATE_HPP_\r
+#define VK_DESCRIPTOR_UPDATE_TEMPLATE_HPP_\r
+\r
+#include "VkObject.hpp"\r
+\r
+namespace vk\r
+{\r
+       class DescriptorSetLayout;\r
+\r
+       class DescriptorUpdateTemplate : public Object<DescriptorUpdateTemplate, VkDescriptorUpdateTemplate>\r
+       {\r
+       public:\r
+               DescriptorUpdateTemplate(const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, void* mem);\r
+               ~DescriptorUpdateTemplate() = delete;\r
+\r
+               static size_t ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo* info);\r
+\r
+               void updateDescriptorSet(VkDescriptorSet descriptorSet, const void* pData);\r
+\r
+       private:\r
+               uint32_t                              descriptorUpdateEntryCount = 0;\r
+               VkDescriptorUpdateTemplateEntry*      descriptorUpdateEntries = nullptr;\r
+               DescriptorSetLayout*                  descriptorSetLayout = nullptr;\r
+       };\r
+\r
+       static inline DescriptorUpdateTemplate* Cast(VkDescriptorUpdateTemplate object)\r
+       {\r
+               return reinterpret_cast<DescriptorUpdateTemplate*>(object);\r
+       }\r
+\r
+} // namespace vk\r
+\r
+#endif // VK_DESCRIPTOR_UPDATE_TEMPLATE_HPP_\r
index 5b2f735..26ac1d8 100644 (file)
@@ -20,6 +20,7 @@
 #include "VkDebug.hpp"
 #include "VkDescriptorPool.hpp"
 #include "VkDescriptorSetLayout.hpp"
+#include "VkDescriptorUpdateTemplate.hpp"
 #include "VkDestroy.h"
 #include "VkDevice.hpp"
 #include "VkDeviceMemory.hpp"
@@ -2032,21 +2033,31 @@ VKAPI_ATTR void VKAPI_CALL vkDestroySamplerYcbcrConversion(VkDevice device, VkSa
 
 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorUpdateTemplate(VkDevice device, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate)
 {
-       TRACE("()");
-       UNIMPLEMENTED();
-       return VK_SUCCESS;
+       TRACE("(VkDevice device = 0x%X, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate = 0x%X)",
+             device, pCreateInfo, pAllocator, pDescriptorUpdateTemplate);
+
+       if(pCreateInfo->pNext || pCreateInfo->flags || (pCreateInfo->templateType != VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET))
+       {
+               UNIMPLEMENTED();
+       }
+
+       return vk::DescriptorUpdateTemplate::Create(pAllocator, pCreateInfo, pDescriptorUpdateTemplate);
 }
 
 VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorUpdateTemplate(VkDevice device, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const VkAllocationCallbacks* pAllocator)
 {
-       TRACE("()");
-       UNIMPLEMENTED();
+       TRACE("(VkDevice device = 0x%X, VkDescriptorUpdateTemplate descriptorUpdateTemplate = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
+             device, descriptorUpdateTemplate, pAllocator);
+
+       vk::destroy(descriptorUpdateTemplate, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const void* pData)
 {
-       TRACE("()");
-       UNIMPLEMENTED();
+       TRACE("(VkDevice device = 0x%X, VkDescriptorSet descriptorSet = 0x%X, VkDescriptorUpdateTemplate descriptorUpdateTemplate = 0x%X, const void* pData = 0x%X)",
+             device, descriptorSet, descriptorUpdateTemplate, pData);
+
+       vk::Cast(descriptorUpdateTemplate)->updateDescriptorSet(descriptorSet, pData);
 }
 
 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties)
index 65dad9e..0328234 100644 (file)
@@ -106,6 +106,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
     <ClCompile Include="VkDebug.cpp" />\r
     <ClCompile Include="VkDescriptorPool.cpp" />\r
     <ClCompile Include="VkDescriptorSetLayout.cpp" />\r
+    <ClCompile Include="VkDescriptorUpdateTemplate.cpp" />\r
     <ClCompile Include="VkDevice.cpp" />\r
     <ClCompile Include="VkDeviceMemory.cpp" />\r
     <ClCompile Include="VkFramebuffer.cpp" />\r
@@ -202,6 +203,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
     <ClInclude Include="VkDebug.hpp" />\r
     <ClInclude Include="VkDescriptorPool.hpp" />\r
     <ClInclude Include="VkDescriptorSetLayout.hpp" />\r
+    <ClInclude Include="VkDescriptorUpdateTemplate.hpp" />\r
     <ClInclude Include="VkDestroy.h" />\r
     <ClInclude Include="VkDevice.hpp" />\r
     <ClInclude Include="VkDeviceMemory.hpp" />\r
index 522de29..06eef79 100644 (file)
     <ClCompile Include="VkDescriptorSetLayout.cpp">\r
       <Filter>Source Files\Vulkan</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="VkDescriptorUpdateTemplate.cpp">\r
+      <Filter>Source Files\Vulkan</Filter>\r
+    </ClCompile>\r
     <ClCompile Include="VkDevice.cpp">\r
       <Filter>Source Files\Vulkan</Filter>\r
     </ClCompile>\r
     <ClInclude Include="VkDescriptorSetLayout.hpp">\r
       <Filter>Header Files\Vulkan</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="VkDescriptorUpdateTemplate.hpp">\r
+      <Filter>Header Files\Vulkan</Filter>\r
+    </ClInclude>\r
     <ClInclude Include="VkDevice.hpp">\r
       <Filter>Header Files\Vulkan</Filter>\r
     </ClInclude>\r