From 3e08acd6a9d4ffa8357fc27c85bfa54f5b5679ab Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Wed, 16 Aug 2017 01:19:06 -0700 Subject: [PATCH] working on implementing Graphics_pipeline::make --- src/pipeline/CMakeLists.txt | 2 +- src/pipeline/pipeline.cpp | 14 +++++ src/pipeline/pipeline.h | 105 ++++++++++++++++++++++++++++++------ 3 files changed, 105 insertions(+), 16 deletions(-) diff --git a/src/pipeline/CMakeLists.txt b/src/pipeline/CMakeLists.txt index e4dc438..65fdb94 100644 --- a/src/pipeline/CMakeLists.txt +++ b/src/pipeline/CMakeLists.txt @@ -22,4 +22,4 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR) set(sources pipeline.cpp) add_library(vulkan_cpu_pipeline STATIC ${sources}) -target_link_libraries(vulkan_cpu_pipeline vulkan_cpu_spirv_to_llvm vulkan_cpu_util vulkan_cpu_spirv vulkan_cpu_llvm_wrapper) +target_link_libraries(vulkan_cpu_pipeline vulkan_cpu_spirv_to_llvm vulkan_cpu_util vulkan_cpu_spirv vulkan_cpu_llvm_wrapper vulkan_cpu_vulkan) diff --git a/src/pipeline/pipeline.cpp b/src/pipeline/pipeline.cpp index fccfeb3..11d7ce5 100644 --- a/src/pipeline/pipeline.cpp +++ b/src/pipeline/pipeline.cpp @@ -21,3 +21,17 @@ * */ #include "pipeline.h" +#include + +namespace vulkan_cpu +{ +namespace pipeline +{ +std::unique_ptr Graphics_pipeline::make( + Pipeline_cache *pipeline_cache, const VkGraphicsPipelineCreateInfo &create_info) +{ +#warning finish implementing Graphics_pipeline::make + throw std::runtime_error("Graphics_pipeline::make is not implemented"); +} +} +} diff --git a/src/pipeline/pipeline.h b/src/pipeline/pipeline.h index c50bc08..54b4e57 100644 --- a/src/pipeline/pipeline.h +++ b/src/pipeline/pipeline.h @@ -25,41 +25,116 @@ #include #include +#include +#include #include "llvm_wrapper/llvm_wrapper.h" +#include "vulkan/vulkan.h" namespace vulkan_cpu { namespace pipeline { +class Pipeline_cache; + +class Pipeline_cache_handle +{ +private: + static void destroy(Pipeline_cache *value) noexcept; + +public: + explicit Pipeline_cache_handle(Pipeline_cache *value) noexcept : value(value) + { + } + constexpr Pipeline_cache_handle() noexcept : value(nullptr) + { + } + Pipeline_cache_handle(Pipeline_cache_handle &&rt) noexcept : value(rt.value) + { + rt.value = nullptr; + } + Pipeline_cache_handle &operator=(Pipeline_cache_handle rt) noexcept + { + swap(rt); + return *this; + } + ~Pipeline_cache_handle() noexcept + { + if(value) + destroy(value); + } + void swap(Pipeline_cache_handle &rt) noexcept + { + using std::swap; + swap(value, rt.value); + } + static Pipeline_cache *from_handle(VkPipelineCache pipeline_cache) noexcept + { + return reinterpret_cast(pipeline_cache); + } + static Pipeline_cache_handle move_from_handle(VkPipelineCache pipeline_cache) noexcept + { + return Pipeline_cache_handle(from_handle(pipeline_cache)); + } + Pipeline_cache *get() const noexcept + { + return value; + } + Pipeline_cache *release() noexcept + { + auto retval = value; + value = nullptr; + return retval; + } + Pipeline_cache *operator->() const noexcept + { + assert(value); + return value; + } + Pipeline_cache &operator*() const noexcept + { + return *operator->(); + } + +private: + Pipeline_cache *value; +}; + +inline VkPipelineCache to_handle(Pipeline_cache *pipeline_cache) noexcept +{ + return reinterpret_cast(pipeline_cache); +} + +inline VkPipelineCache move_to_handle(Pipeline_cache_handle pipeline_cache) noexcept +{ + return to_handle(pipeline_cache.release()); +} + class Pipeline { Pipeline(const Pipeline &) = delete; Pipeline &operator=(const Pipeline &) = delete; -public: - typedef std::uintptr_t Handle; - public: constexpr Pipeline() noexcept { } virtual ~Pipeline() = default; - static std::unique_ptr move_from_handle(Handle pipeline) noexcept + static std::unique_ptr move_from_handle(VkPipeline pipeline) noexcept { return std::unique_ptr(from_handle(pipeline)); } - static Pipeline *from_handle(Handle pipeline) noexcept + static Pipeline *from_handle(VkPipeline pipeline) noexcept { return reinterpret_cast(pipeline); } }; -inline Pipeline::Handle to_handle(Pipeline *pipeline) noexcept +inline VkPipeline to_handle(Pipeline *pipeline) noexcept { - return reinterpret_cast(pipeline); + return reinterpret_cast(pipeline); } -inline Pipeline::Handle move_to_handle(std::unique_ptr pipeline) noexcept +inline VkPipeline move_to_handle(std::unique_ptr pipeline) noexcept { return to_handle(pipeline.release()); } @@ -78,15 +153,15 @@ public: { return vertex_shader_function; } -#warning finish implementing Graphics_pipeline::make - static std::unique_ptr make(); - static std::unique_ptr move_from_handle(Handle pipeline) noexcept + static std::unique_ptr make(Pipeline_cache *pipeline_cache, + const VkGraphicsPipelineCreateInfo &create_info); + static std::unique_ptr move_from_handle(VkPipeline pipeline) noexcept { return std::unique_ptr(from_handle(pipeline)); } - static Graphics_pipeline *from_handle(Handle pipeline) noexcept + static Graphics_pipeline *from_handle(VkPipeline pipeline) noexcept { - auto *retval = reinterpret_cast(pipeline); + auto *retval = Pipeline::from_handle(pipeline); assert(!retval || dynamic_cast(retval)); return static_cast(retval); } @@ -104,12 +179,12 @@ private: Vertex_shader_function vertex_shader_function; }; -inline Pipeline::Handle to_handle(Graphics_pipeline *pipeline) noexcept +inline VkPipeline to_handle(Graphics_pipeline *pipeline) noexcept { return to_handle(static_cast(pipeline)); } -inline Pipeline::Handle move_to_handle(std::unique_ptr pipeline) noexcept +inline VkPipeline move_to_handle(std::unique_ptr pipeline) noexcept { return to_handle(pipeline.release()); } -- 2.30.2