vsg 1.1.13
VulkanSceneGraph library
Loading...
Searching...
No Matches
ShaderModule.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <fstream>
16
17#include <vsg/vk/Device.h>
18#include <vsg/vk/vk_buffer.h>
19
20namespace vsg
21{
22 // forward declare
23 class Context;
24
27 class VSG_DECLSPEC ShaderCompileSettings : public Inherit<Object, ShaderCompileSettings>
28 {
29 public:
30 ShaderCompileSettings();
31 ShaderCompileSettings(const ShaderCompileSettings& rhs, const CopyOp& copyop = {});
32
33 enum Language
34 {
35 GLSL,
36 HLSL
37 };
38
39 enum SpirvTarget
40 {
41 SPIRV_1_0 = (1 << 16),
42 SPIRV_1_1 = (1 << 16) | (1 << 8),
43 SPIRV_1_2 = (1 << 16) | (2 << 8),
44 SPIRV_1_3 = (1 << 16) | (3 << 8),
45 SPIRV_1_4 = (1 << 16) | (4 << 8),
46 SPIRV_1_5 = (1 << 16) | (5 << 8)
47 };
48
49 uint32_t vulkanVersion = VK_API_VERSION_1_0;
50 int clientInputVersion = 100;
51 Language language = GLSL;
52 int defaultVersion = 450;
53 SpirvTarget target = SPIRV_1_0;
54 bool forwardCompatible = false;
55 bool generateDebugInfo = false; // maps to SpvOptions::generateDebugInfo
56 bool optimize = false;
57
58 std::set<std::string> defines;
59
60 public:
61 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return ShaderCompileSettings::create(*this, copyop); }
62 int compare(const Object& rhs_object) const override;
63
64 void read(Input& input) override;
65 void write(Output& output) const override;
66 };
67 VSG_type_name(vsg::ShaderCompileSettings);
68
71 class VSG_DECLSPEC ShaderModule : public Inherit<Object, ShaderModule>
72 {
73 public:
74 using SPIRV = std::vector<uint32_t>;
75
76 ShaderModule();
77 ShaderModule(const ShaderModule& rhs, const CopyOp& copyop = {});
78 explicit ShaderModule(const std::string& in_source, ref_ptr<ShaderCompileSettings> in_hints = {});
79 explicit ShaderModule(const SPIRV& in_code);
80 ShaderModule(const std::string& source, const SPIRV& in_code);
81
82 std::string source;
84
86 SPIRV code;
87
89 VkShaderModule vk(uint32_t deviceID) const { return _implementation[deviceID]->_shaderModule; }
90
91 // compile the Vulkan object, context parameter used for Device
92 void compile(Context& context);
93
94 // remove the local reference to the Vulkan implementation
95 void release(uint32_t deviceID) { _implementation[deviceID] = {}; }
96 void release() { _implementation.clear(); }
97
98 public:
99 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return ShaderModule::create(*this, copyop); }
100 int compare(const Object& rhs_object) const override;
101
102 void read(Input& input) override;
103 void write(Output& output) const override;
104
105 protected:
106 virtual ~ShaderModule();
107
108 struct Implementation : public Inherit<Object, Implementation>
109 {
110 Implementation(Device* device, ShaderModule* shader);
111
112 virtual ~Implementation();
113
114 VkShaderModule _shaderModule;
115 ref_ptr<Device> _device;
116 };
117
118 vk_buffer<ref_ptr<Implementation>> _implementation;
119 };
120 VSG_type_name(vsg::ShaderModule);
121
123 extern VSG_DECLSPEC std::string insertIncludes(const std::string& source, ref_ptr<const Options> options);
124
125} // namespace vsg
Definition Context.h:67
Definition Object.h:42
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition Device.h:39
Definition Input.h:44
Definition Object.h:60
Definition Output.h:41
Definition ShaderModule.h:28
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition ShaderModule.h:61
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition ShaderModule.h:72
VkShaderModule vk(uint32_t deviceID) const
Vulkan VkShaderModule handle.
Definition ShaderModule.h:89
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition ShaderModule.h:99
SPIRV code
VkShaderModuleCreateInfo settings.
Definition ShaderModule.h:86
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition ref_ptr.h:22
vk_buffer that manages a single logical device supported.
Definition vk_buffer.h:29