added VkDescriptorSetLayout
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 22 Sep 2017 00:17:07 +0000 (17:17 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 22 Sep 2017 00:17:07 +0000 (17:17 -0700)
src/vulkan/api_objects.cpp
src/vulkan/api_objects.h
src/vulkan_icd/vulkan_icd.cpp

index 61277d2af50c590873b3f3c700101bfd3ae34ff2..11f02d8017636a0e77a0d8632b8c5bbdb7b0be99 100644 (file)
@@ -559,6 +559,20 @@ std::unique_ptr<Vulkan_image_view> Vulkan_image_view::create(
                                                subresource_range);
 }
 
+std::unique_ptr<Vulkan_descriptor_set_layout> 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<Binding> bindings;
+    bindings.reserve(create_info.bindingCount);
+    for(std::uint32_t i = 0; i<create_info.bindingCount;i++)
+        bindings.emplace_back(create_info.pBindings[i]);
+    return std::make_unique<Vulkan_descriptor_set_layout>(std::move(bindings));
+}
+
 std::unique_ptr<Vulkan_render_pass> Vulkan_render_pass::create(
     Vulkan_device &device, const VkRenderPassCreateInfo &create_info)
 {
index 5f94703f4788ed26dce28d1154db0c4d3c5edd51..2b697e472523dcd3bfa8fd52ef56f71374da33e6 100644 (file)
@@ -2441,6 +2441,51 @@ struct Vulkan_image_view : public Vulkan_nondispatchable_object<Vulkan_image_vie
                                                      const VkImageViewCreateInfo &create_info);
 };
 
+struct Vulkan_sampler : public Vulkan_nondispatchable_object<Vulkan_sampler, VkSampler>
+{
+#warning finish implementing Vulkan_sampler
+};
+
+struct Vulkan_descriptor_set_layout
+    : public Vulkan_nondispatchable_object<Vulkan_descriptor_set_layout, VkDescriptorSetLayout>
+{
+    struct Binding
+    {
+        std::uint32_t binding;
+        VkDescriptorType descriptor_type;
+        std::uint32_t descriptor_count;
+        std::unique_ptr<Vulkan_sampler *[]> 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<Binding> bindings;
+    explicit Vulkan_descriptor_set_layout(std::vector<Binding> bindings) noexcept
+        : bindings(std::move(bindings))
+    {
+    }
+    static std::unique_ptr<Vulkan_descriptor_set_layout> create(
+        Vulkan_device &device, const VkDescriptorSetLayoutCreateInfo &create_info);
+};
+
 struct Vulkan_render_pass : public Vulkan_nondispatchable_object<Vulkan_render_pass, VkRenderPass>
 {
 #warning finish implementing Vulkan_render_pass
index cb7e894d99bfc956b8e919d9cdfaeae72b5a5661..4d9d616fe2df092b4570bc01cafad0b0a6e43b90 100644 (file)
@@ -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