start adding graphics pipeline
[kazan.git] / src / pipeline / pipeline.h
1 /*
2 * Copyright 2017 Jacob Lifshay
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 *
22 */
23 #ifndef PIPELINE_PIPELINE_H_
24 #define PIPELINE_PIPELINE_H_
25
26 #include <memory>
27 #include <cstdint>
28 #include "llvm_wrapper/llvm_wrapper.h"
29
30 namespace vulkan_cpu
31 {
32 namespace pipeline
33 {
34 class Pipeline
35 {
36 Pipeline(const Pipeline &) = delete;
37 Pipeline &operator=(const Pipeline &) = delete;
38
39 public:
40 typedef std::uintptr_t Handle;
41
42 public:
43 constexpr Pipeline() noexcept
44 {
45 }
46 virtual ~Pipeline() = default;
47 static std::unique_ptr<Pipeline> move_from_handle(Handle pipeline) noexcept
48 {
49 return std::unique_ptr<Pipeline>(from_handle(pipeline));
50 }
51 static Pipeline *from_handle(Handle pipeline) noexcept
52 {
53 return reinterpret_cast<Pipeline *>(pipeline);
54 }
55 };
56
57 inline Pipeline::Handle to_handle(Pipeline *pipeline) noexcept
58 {
59 return reinterpret_cast<Pipeline::Handle>(pipeline);
60 }
61
62 inline Pipeline::Handle move_to_handle(std::unique_ptr<Pipeline> pipeline) noexcept
63 {
64 return to_handle(pipeline.release());
65 }
66
67 class Graphics_pipeline final : public Pipeline
68 {
69 public:
70 #warning finish adding draw function parameters
71 typedef void (*Vertex_shader_function)(std::uint32_t vertex_start_index,
72 std::uint32_t vertex_count,
73 std::uint32_t instance_id,
74 void *output_buffer);
75
76 public:
77 const Vertex_shader_function get_vertex_shader_function() const noexcept
78 {
79 return vertex_shader_function;
80 }
81 #warning finish implementing Graphics_pipeline::make
82 static std::unique_ptr<Graphics_pipeline> make();
83 static std::unique_ptr<Graphics_pipeline> move_from_handle(Handle pipeline) noexcept
84 {
85 return std::unique_ptr<Graphics_pipeline>(from_handle(pipeline));
86 }
87 static Graphics_pipeline *from_handle(Handle pipeline) noexcept
88 {
89 auto *retval = reinterpret_cast<Pipeline *>(pipeline);
90 assert(!retval || dynamic_cast<Graphics_pipeline *>(retval));
91 return static_cast<Graphics_pipeline *>(retval);
92 }
93
94 private:
95 Graphics_pipeline(std::shared_ptr<void> state,
96 Vertex_shader_function vertex_shader_function) noexcept
97 : state(std::move(state)),
98 vertex_shader_function(vertex_shader_function)
99 {
100 }
101
102 private:
103 std::shared_ptr<void> state;
104 Vertex_shader_function vertex_shader_function;
105 };
106
107 inline Pipeline::Handle to_handle(Graphics_pipeline *pipeline) noexcept
108 {
109 return to_handle(static_cast<Pipeline *>(pipeline));
110 }
111
112 inline Pipeline::Handle move_to_handle(std::unique_ptr<Graphics_pipeline> pipeline) noexcept
113 {
114 return to_handle(pipeline.release());
115 }
116 }
117 }
118
119 #endif // PIPELINE_PIPELINE_H_