From b9189ba2cd8b9e38fbf638ecc356914500211351 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 21 Sep 2017 17:17:07 -0700 Subject: [PATCH] added VkDescriptorSetLayout --- src/vulkan/api_objects.cpp | 14 +++++++++++ src/vulkan/api_objects.h | 45 +++++++++++++++++++++++++++++++++++ src/vulkan_icd/vulkan_icd.cpp | 23 ++++++++++++------ 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/vulkan/api_objects.cpp b/src/vulkan/api_objects.cpp index 61277d2..11f02d8 100644 --- a/src/vulkan/api_objects.cpp +++ b/src/vulkan/api_objects.cpp @@ -559,6 +559,20 @@ std::unique_ptr Vulkan_image_view::create( subresource_range); } +std::unique_ptr Vulkan_descriptor_set_layout::create( + Vulkan_device &device, const VkDescriptorSetLayoutCreateInfo &create_info) +{ + assert(create_info.sType == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO); + constexpr VkDescriptorSetLayoutCreateFlags supported_flags = 0; + assert((create_info.flags & ~supported_flags) == 0); + assert(create_info.bindingCount == 0 || create_info.pBindings); + std::vector bindings; + bindings.reserve(create_info.bindingCount); + for(std::uint32_t i = 0; i(std::move(bindings)); +} + std::unique_ptr Vulkan_render_pass::create( Vulkan_device &device, const VkRenderPassCreateInfo &create_info) { diff --git a/src/vulkan/api_objects.h b/src/vulkan/api_objects.h index 5f94703..2b697e4 100644 --- a/src/vulkan/api_objects.h +++ b/src/vulkan/api_objects.h @@ -2441,6 +2441,51 @@ struct Vulkan_image_view : public Vulkan_nondispatchable_object +{ +#warning finish implementing Vulkan_sampler +}; + +struct Vulkan_descriptor_set_layout + : public Vulkan_nondispatchable_object +{ + struct Binding + { + std::uint32_t binding; + VkDescriptorType descriptor_type; + std::uint32_t descriptor_count; + std::unique_ptr immutable_samplers; + explicit Binding(const VkDescriptorSetLayoutBinding &descriptor_set_layout_binding) + : binding(descriptor_set_layout_binding.binding), + descriptor_type(descriptor_set_layout_binding.descriptorType), + descriptor_count(descriptor_set_layout_binding.descriptorCount), + immutable_samplers() + { + if((descriptor_type == VK_DESCRIPTOR_TYPE_SAMPLER + || descriptor_type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) + && descriptor_count != 0 + && descriptor_set_layout_binding.pImmutableSamplers) + { + immutable_samplers.reset(new Vulkan_sampler *[descriptor_count]); + for(std::uint32_t i = 0; i < descriptor_count; i++) + { + auto *sampler = Vulkan_sampler::from_handle( + descriptor_set_layout_binding.pImmutableSamplers[i]); + assert(sampler); + immutable_samplers[i] = sampler; + } + } + } + }; + std::vector bindings; + explicit Vulkan_descriptor_set_layout(std::vector bindings) noexcept + : bindings(std::move(bindings)) + { + } + static std::unique_ptr create( + Vulkan_device &device, const VkDescriptorSetLayoutCreateInfo &create_info); +}; + struct Vulkan_render_pass : public Vulkan_nondispatchable_object { #warning finish implementing Vulkan_render_pass diff --git a/src/vulkan_icd/vulkan_icd.cpp b/src/vulkan_icd/vulkan_icd.cpp index cb7e894..4d9d616 100644 --- a/src/vulkan_icd/vulkan_icd.cpp +++ b/src/vulkan_icd/vulkan_icd.cpp @@ -938,23 +938,32 @@ extern "C" VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, extern "C" VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, - const VkDescriptorSetLayoutCreateInfo *pCreateInfo, + const VkDescriptorSetLayoutCreateInfo *create_info, const VkAllocationCallbacks *allocator, - VkDescriptorSetLayout *pSetLayout) + VkDescriptorSetLayout *set_layout) { validate_allocator(allocator); -#warning finish implementing vkCreateDescriptorSetLayout - assert(!"vkCreateDescriptorSetLayout is not implemented"); + assert(device); + assert(create_info); + assert(set_layout); + return vulkan_icd::catch_exceptions_and_return_result( + [&]() + { + auto create_result = vulkan::Vulkan_descriptor_set_layout::create( + *vulkan::Vulkan_device::from_handle(device), *create_info); + *set_layout = move_to_handle(std::move(create_result)); + return VK_SUCCESS; + }); } extern "C" VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, - VkDescriptorSetLayout descriptorSetLayout, + VkDescriptorSetLayout descriptor_set_layout, const VkAllocationCallbacks *allocator) { validate_allocator(allocator); -#warning finish implementing vkDestroyDescriptorSetLayout - assert(!"vkDestroyDescriptorSetLayout is not implemented"); + assert(device); + vulkan::Vulkan_descriptor_set_layout::move_from_handle(descriptor_set_layout).reset(); } extern "C" VKAPI_ATTR VkResult VKAPI_CALL -- 2.30.2