Commit f705ceca by Alexis Hetu Committed by Alexis Hétu

Descriptor Update Template implementation

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/+/26568Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 13eba6ca
......@@ -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;
......
// 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) :
descriptorUpdateEntryCount(pCreateInfo->descriptorUpdateEntryCount),
descriptorUpdateEntries(reinterpret_cast<VkDescriptorUpdateTemplateEntry*>(mem)),
descriptorSetLayout(Cast(pCreateInfo->descriptorSetLayout))
{
for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++)
{
descriptorUpdateEntries[i] = pCreateInfo->pDescriptorUpdateEntries[i];
}
}
size_t DescriptorUpdateTemplate::ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo* info)
{
return info->descriptorUpdateEntryCount * sizeof(VkDescriptorUpdateTemplateEntry);
}
void DescriptorUpdateTemplate::updateDescriptorSet(VkDescriptorSet descriptorSet, const void* pData)
{
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);
}
}
}
}
\ No newline at end of file
// 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.
#ifndef VK_DESCRIPTOR_UPDATE_TEMPLATE_HPP_
#define VK_DESCRIPTOR_UPDATE_TEMPLATE_HPP_
#include "VkObject.hpp"
namespace vk
{
class DescriptorSetLayout;
class DescriptorUpdateTemplate : public Object<DescriptorUpdateTemplate, VkDescriptorUpdateTemplate>
{
public:
DescriptorUpdateTemplate(const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, void* mem);
~DescriptorUpdateTemplate() = delete;
static size_t ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo* info);
void updateDescriptorSet(VkDescriptorSet descriptorSet, const void* pData);
private:
uint32_t descriptorUpdateEntryCount = 0;
VkDescriptorUpdateTemplateEntry* descriptorUpdateEntries = nullptr;
DescriptorSetLayout* descriptorSetLayout = nullptr;
};
static inline DescriptorUpdateTemplate* Cast(VkDescriptorUpdateTemplate object)
{
return reinterpret_cast<DescriptorUpdateTemplate*>(object);
}
} // namespace vk
#endif // VK_DESCRIPTOR_UPDATE_TEMPLATE_HPP_
......@@ -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)
......
......@@ -106,6 +106,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClCompile Include="VkDebug.cpp" />
<ClCompile Include="VkDescriptorPool.cpp" />
<ClCompile Include="VkDescriptorSetLayout.cpp" />
<ClCompile Include="VkDescriptorUpdateTemplate.cpp" />
<ClCompile Include="VkDevice.cpp" />
<ClCompile Include="VkDeviceMemory.cpp" />
<ClCompile Include="VkFramebuffer.cpp" />
......@@ -202,6 +203,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClInclude Include="VkDebug.hpp" />
<ClInclude Include="VkDescriptorPool.hpp" />
<ClInclude Include="VkDescriptorSetLayout.hpp" />
<ClInclude Include="VkDescriptorUpdateTemplate.hpp" />
<ClInclude Include="VkDestroy.h" />
<ClInclude Include="VkDevice.hpp" />
<ClInclude Include="VkDeviceMemory.hpp" />
......
......@@ -210,6 +210,9 @@
<ClCompile Include="VkDescriptorSetLayout.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="VkDescriptorUpdateTemplate.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="VkDevice.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
......@@ -290,6 +293,9 @@
<ClInclude Include="VkDescriptorSetLayout.hpp">
<Filter>Header Files\Vulkan</Filter>
</ClInclude>
<ClInclude Include="VkDescriptorUpdateTemplate.hpp">
<Filter>Header Files\Vulkan</Filter>
</ClInclude>
<ClInclude Include="VkDevice.hpp">
<Filter>Header Files\Vulkan</Filter>
</ClInclude>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment