working on implementing Graphics_pipeline::make
authorJacob Lifshay <programmerjake@gmail.com>
Wed, 16 Aug 2017 08:19:06 +0000 (01:19 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Wed, 16 Aug 2017 08:19:06 +0000 (01:19 -0700)
src/pipeline/CMakeLists.txt
src/pipeline/pipeline.cpp
src/pipeline/pipeline.h

index e4dc438597123265ab336068c465bb22879ad30a..65fdb9416992f64c28a49c97b4e6f8d259455113 100644 (file)
@@ -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)
index fccfeb3c5512b5e94f9fbc35045558c57e0f3506..11d7ce5412d64634d5199d44ce86569f16ad777f 100644 (file)
  *
  */
 #include "pipeline.h"
+#include <stdexcept>
+
+namespace vulkan_cpu
+{
+namespace pipeline
+{
+std::unique_ptr<Graphics_pipeline> 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");
+}
+}
+}
index c50bc0815b0b5998ed6557b57bcdf8d413ebf7c5..54b4e57745661f641d43b3854f1354f22cf84bfb 100644 (file)
 
 #include <memory>
 #include <cstdint>
+#include <utility>
+#include <cassert>
 #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 *>(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<VkPipelineCache>(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<Pipeline> move_from_handle(Handle pipeline) noexcept
+    static std::unique_ptr<Pipeline> move_from_handle(VkPipeline pipeline) noexcept
     {
         return std::unique_ptr<Pipeline>(from_handle(pipeline));
     }
-    static Pipeline *from_handle(Handle pipeline) noexcept
+    static Pipeline *from_handle(VkPipeline pipeline) noexcept
     {
         return reinterpret_cast<Pipeline *>(pipeline);
     }
 };
 
-inline Pipeline::Handle to_handle(Pipeline *pipeline) noexcept
+inline VkPipeline to_handle(Pipeline *pipeline) noexcept
 {
-    return reinterpret_cast<Pipeline::Handle>(pipeline);
+    return reinterpret_cast<VkPipeline>(pipeline);
 }
 
-inline Pipeline::Handle move_to_handle(std::unique_ptr<Pipeline> pipeline) noexcept
+inline VkPipeline move_to_handle(std::unique_ptr<Pipeline> 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<Graphics_pipeline> make();
-    static std::unique_ptr<Graphics_pipeline> move_from_handle(Handle pipeline) noexcept
+    static std::unique_ptr<Graphics_pipeline> make(Pipeline_cache *pipeline_cache,
+                                                   const VkGraphicsPipelineCreateInfo &create_info);
+    static std::unique_ptr<Graphics_pipeline> move_from_handle(VkPipeline pipeline) noexcept
     {
         return std::unique_ptr<Graphics_pipeline>(from_handle(pipeline));
     }
-    static Graphics_pipeline *from_handle(Handle pipeline) noexcept
+    static Graphics_pipeline *from_handle(VkPipeline pipeline) noexcept
     {
-        auto *retval = reinterpret_cast<Pipeline *>(pipeline);
+        auto *retval = Pipeline::from_handle(pipeline);
         assert(!retval || dynamic_cast<Graphics_pipeline *>(retval));
         return static_cast<Graphics_pipeline *>(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 *>(pipeline));
 }
 
-inline Pipeline::Handle move_to_handle(std::unique_ptr<Graphics_pipeline> pipeline) noexcept
+inline VkPipeline move_to_handle(std::unique_ptr<Graphics_pipeline> pipeline) noexcept
 {
     return to_handle(pipeline.release());
 }