From cf9f11dbcc2c6f6f26ee62850789c2dbc2d5365d Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 21 Sep 2017 20:58:49 -0700 Subject: [PATCH] implement creating graphics pipelines through vulkan api --- src/pipeline/pipeline.h | 3 ++ src/vulkan/api_objects.cpp | 26 ++++++++++- src/vulkan/api_objects.h | 27 +++++++++--- src/vulkan_icd/vulkan_icd.cpp | 83 +++++++++++++++++++++++++---------- 4 files changed, 107 insertions(+), 32 deletions(-) diff --git a/src/pipeline/pipeline.h b/src/pipeline/pipeline.h index 04a37a9..637f363 100644 --- a/src/pipeline/pipeline.h +++ b/src/pipeline/pipeline.h @@ -196,6 +196,9 @@ private: VkViewport viewport; VkRect2D scissor_rect; }; + +using vulkan::move_to_handle; +using vulkan::to_handle; } } diff --git a/src/vulkan/api_objects.cpp b/src/vulkan/api_objects.cpp index 11f02d8..693a754 100644 --- a/src/vulkan/api_objects.cpp +++ b/src/vulkan/api_objects.cpp @@ -568,11 +568,33 @@ std::unique_ptr Vulkan_descriptor_set_layout::crea 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_pipeline_layout::create( + Vulkan_device &device, const VkPipelineLayoutCreateInfo &create_info) +{ + assert(create_info.sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO); + assert(create_info.setLayoutCount == 0 || create_info.pSetLayouts); + assert(create_info.pushConstantRangeCount == 0 || create_info.pPushConstantRanges); + std::vector descriptor_set_layouts; + descriptor_set_layouts.reserve(create_info.setLayoutCount); + for(std::uint32_t i = 0; i < create_info.setLayoutCount; i++) + { + auto *descriptor_set_layout = + Vulkan_descriptor_set_layout::from_handle(create_info.pSetLayouts[i]); + assert(descriptor_set_layout); + descriptor_set_layouts.push_back(descriptor_set_layout); + } + std::vector push_constant_ranges( + create_info.pPushConstantRanges, + create_info.pPushConstantRanges + create_info.pushConstantRangeCount); + return std::make_unique(std::move(descriptor_set_layouts), + std::move(push_constant_ranges)); +} + std::unique_ptr Vulkan_render_pass::create( Vulkan_device &device, const VkRenderPassCreateInfo &create_info) { @@ -680,7 +702,7 @@ std::unique_ptr Vulkan_render_pass::create( { static std::atomic_bool wrote_warning{false}; if(!wrote_warning.exchange(true, std::memory_order::memory_order_relaxed)) - std::cerr << "depth stencil attachments not supported" << std::endl; + std::cerr << "depth stencil attachments not implemented" << std::endl; } return std::make_unique( std::move(attachments), *color_attachment_index, depth_stencil_attachment_index); diff --git a/src/vulkan/api_objects.h b/src/vulkan/api_objects.h index 2b697e4..df8b6a5 100644 --- a/src/vulkan/api_objects.h +++ b/src/vulkan/api_objects.h @@ -1490,15 +1490,15 @@ struct Vulkan_nondispatchable_object template typename std:: - enable_if, Object_type>::value, typename Object_type::Vulkan_handle>::type to_handle(Object_type *object) noexcept { return reinterpret_cast( - static_cast *>( - object)); + static_cast *>(object)); } template @@ -1510,15 +1510,15 @@ decltype(to_handle(static_cast(nullptr))) move_to_handle( template typename std:: - enable_if, Object_type>::value, typename Object_type::Vulkan_handle>::type to_handle(Object_type *object) noexcept { return reinterpret_cast( - static_cast - *>(object)); + static_cast *>(object)); } struct Vulkan_device; @@ -2486,6 +2486,21 @@ struct Vulkan_descriptor_set_layout Vulkan_device &device, const VkDescriptorSetLayoutCreateInfo &create_info); }; +struct Vulkan_pipeline_layout + : public Vulkan_nondispatchable_object +{ + std::vector descriptor_set_layouts; + std::vector push_constant_ranges; + Vulkan_pipeline_layout(std::vector descriptor_set_layouts, + std::vector push_constant_ranges) noexcept + : descriptor_set_layouts(std::move(descriptor_set_layouts)), + push_constant_ranges(std::move(push_constant_ranges)) + { + } + static std::unique_ptr create( + Vulkan_device &device, const VkPipelineLayoutCreateInfo &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 4d9d616..17bcc61 100644 --- a/src/vulkan_icd/vulkan_icd.cpp +++ b/src/vulkan_icd/vulkan_icd.cpp @@ -798,22 +798,31 @@ extern "C" VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, extern "C" VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(VkDevice device, - const VkShaderModuleCreateInfo *pCreateInfo, + const VkShaderModuleCreateInfo *create_info, const VkAllocationCallbacks *allocator, - VkShaderModule *pShaderModule) + VkShaderModule *shader_module) { validate_allocator(allocator); -#warning finish implementing vkCreateShaderModule - assert(!"vkCreateShaderModule is not implemented"); + assert(device); + assert(create_info); + assert(shader_module); + return vulkan_icd::catch_exceptions_and_return_result( + [&]() + { + auto create_result = pipeline::Shader_module::create( + *vulkan::Vulkan_device::from_handle(device), *create_info); + *shader_module = move_to_handle(std::move(create_result)); + return VK_SUCCESS; + }); } extern "C" VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, - VkShaderModule shaderModule, + VkShaderModule shader_module, const VkAllocationCallbacks *allocator) { validate_allocator(allocator); -#warning finish implementing vkDestroyShaderModule - assert(!"vkDestroyShaderModule is not implemented"); + assert(device); + pipeline::Shader_module::move_from_handle(shader_module).reset(); } extern "C" VKAPI_ATTR VkResult VKAPI_CALL @@ -865,15 +874,32 @@ extern "C" VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(VkDevice device, extern "C" VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(VkDevice device, - VkPipelineCache pipelineCache, - uint32_t createInfoCount, - const VkGraphicsPipelineCreateInfo *pCreateInfos, + VkPipelineCache pipeline_cache, + uint32_t create_info_count, + const VkGraphicsPipelineCreateInfo *create_infos, const VkAllocationCallbacks *allocator, - VkPipeline *pPipelines) + VkPipeline *pipelines) { validate_allocator(allocator); -#warning finish implementing vkCreateGraphicsPipelines - assert(!"vkCreateGraphicsPipelines is not implemented"); + assert(device); + assert(create_info_count != 0); + assert(create_infos); + assert(pipelines); + return vulkan_icd::catch_exceptions_and_return_result( + [&]() + { + std::vector> pipeline_vector; + pipeline_vector.resize(create_info_count); + for(std::uint32_t i = 0; i < create_info_count; i++) + pipeline_vector[i] = pipeline::Graphics_pipeline::create( + *vulkan::Vulkan_device::from_handle(device), + pipeline::Pipeline_cache::from_handle(pipeline_cache), + create_infos[i]); + // only copy to pipelines after we're sure nothing will throw + for(std::uint32_t i = 0; i < create_info_count; i++) + pipelines[i] = move_to_handle(std::move(pipeline_vector[i])); + return VK_SUCCESS; + }); } extern "C" VKAPI_ATTR VkResult VKAPI_CALL @@ -894,27 +920,36 @@ extern "C" VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, const VkAllocationCallbacks *allocator) { validate_allocator(allocator); -#warning finish implementing vkDestroyPipeline - assert(!"vkDestroyPipeline is not implemented"); + assert(device); + pipeline::Pipeline::move_from_handle(pipeline).reset(); } extern "C" VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, - const VkPipelineLayoutCreateInfo *pCreateInfo, + const VkPipelineLayoutCreateInfo *create_info, const VkAllocationCallbacks *allocator, - VkPipelineLayout *pPipelineLayout) + VkPipelineLayout *pipeline_layout) { validate_allocator(allocator); -#warning finish implementing vkCreatePipelineLayout - assert(!"vkCreatePipelineLayout is not implemented"); + assert(device); + assert(create_info); + assert(pipeline_layout); + return vulkan_icd::catch_exceptions_and_return_result( + [&]() + { + auto create_result = vulkan::Vulkan_pipeline_layout::create( + *vulkan::Vulkan_device::from_handle(device), *create_info); + *pipeline_layout = move_to_handle(std::move(create_result)); + return VK_SUCCESS; + }); } extern "C" VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout( - VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks *allocator) + VkDevice device, VkPipelineLayout pipeline_layout, const VkAllocationCallbacks *allocator) { validate_allocator(allocator); -#warning finish implementing vkDestroyPipelineLayout - assert(!"vkDestroyPipelineLayout is not implemented"); + assert(device); + vulkan::Vulkan_pipeline_layout::move_from_handle(pipeline_layout).reset(); } extern "C" VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, @@ -932,8 +967,8 @@ extern "C" VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, const VkAllocationCallbacks *allocator) { validate_allocator(allocator); -#warning finish implementing vkDestroySampler - assert(!"vkDestroySampler is not implemented"); + assert(device); + vulkan::Vulkan_sampler::move_from_handle(sampler).reset(); } extern "C" VKAPI_ATTR VkResult VKAPI_CALL -- 2.30.2