Skip to content

Commit 28b6b81

Browse files
Merge pull request #1573 from vsg-dev/Shader_clone
Added copyop support to ShaderStage, ShaderModule and ShaderCompileSettings.
2 parents 01a5afd + fc2fd4a commit 28b6b81

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

include/vsg/state/ShaderModule.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ namespace vsg
2727
class VSG_DECLSPEC ShaderCompileSettings : public Inherit<Object, ShaderCompileSettings>
2828
{
2929
public:
30+
31+
ShaderCompileSettings();
32+
ShaderCompileSettings(const ShaderCompileSettings& rhs, const CopyOp& copyop = {});
33+
3034
enum Language
3135
{
3236
GLSL,
@@ -55,6 +59,7 @@ namespace vsg
5559
std::set<std::string> defines;
5660

5761
public:
62+
ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return ShaderCompileSettings::create(*this, copyop); }
5863
int compare(const Object& rhs_object) const override;
5964

6065
void read(Input& input) override;
@@ -70,6 +75,7 @@ namespace vsg
7075
using SPIRV = std::vector<uint32_t>;
7176

7277
ShaderModule();
78+
ShaderModule(const ShaderModule& rhs, const CopyOp& copyop = {});
7379
explicit ShaderModule(const std::string& in_source, ref_ptr<ShaderCompileSettings> in_hints = {});
7480
explicit ShaderModule(const SPIRV& in_code);
7581
ShaderModule(const std::string& source, const SPIRV& in_code);
@@ -91,6 +97,7 @@ namespace vsg
9197
void release() { _implementation.clear(); }
9298

9399
public:
100+
ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return ShaderModule::create(*this, copyop); }
94101
int compare(const Object& rhs_object) const override;
95102

96103
void read(Input& input) override;

include/vsg/state/ShaderStage.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace vsg
2424
{
2525
public:
2626
ShaderStage();
27+
ShaderStage(const ShaderStage& rhs, const CopyOp& copyop = {});
2728
ShaderStage(VkShaderStageFlagBits stage, const std::string& entryPointName, ref_ptr<ShaderModule> shaderModule);
2829
ShaderStage(VkShaderStageFlagBits stage, const std::string& entryPointName, const std::string& source, ref_ptr<ShaderCompileSettings> hints = {});
2930
ShaderStage(VkShaderStageFlagBits stage, const std::string& entryPointName, const ShaderModule::SPIRV& spirv);
@@ -44,16 +45,18 @@ namespace vsg
4445
static ref_ptr<ShaderStage> read(VkShaderStageFlagBits stage, const std::string& entryPointName, const Path& filename, ref_ptr<const Options> options = {});
4546
static ref_ptr<ShaderStage> read(VkShaderStageFlagBits stage, const std::string& entryPointName, std::istream& fin, ref_ptr<const Options> options = {});
4647

47-
int compare(const Object& rhs_object) const override;
48-
49-
void read(Input& input) override;
50-
void write(Output& output) const override;
51-
5248
void apply(Context& context, VkPipelineShaderStageCreateInfo& stageInfo) const;
5349

5450
// compile the Vulkan object, context parameter used for Device
5551
void compile(Context& context);
5652

53+
public:
54+
ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return ShaderStage::create(*this, copyop); }
55+
int compare(const Object& rhs_object) const override;
56+
57+
void read(Input& input) override;
58+
void write(Output& output) const override;
59+
5760
protected:
5861
virtual ~ShaderStage();
5962
};

src/vsg/state/ShaderModule.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ using namespace vsg;
2222
//
2323
// ShaderCompileSettings
2424
//
25+
ShaderCompileSettings::ShaderCompileSettings()
26+
{
27+
}
28+
29+
ShaderCompileSettings::ShaderCompileSettings(const ShaderCompileSettings& rhs, const CopyOp& copyop):
30+
Inherit(rhs, copyop),
31+
vulkanVersion(rhs.vulkanVersion),
32+
clientInputVersion(rhs.clientInputVersion),
33+
language(rhs.language),
34+
defaultVersion(rhs.defaultVersion),
35+
target(rhs.target),
36+
forwardCompatible(rhs.forwardCompatible),
37+
generateDebugInfo(rhs.generateDebugInfo),
38+
optimize(rhs.optimize),
39+
defines(rhs.defines)
40+
{
41+
vsg::info("ShaderCompileSettings::ShaderCompileSettings(", &rhs, ", copyop)");
42+
}
43+
2544
int ShaderCompileSettings::compare(const Object& rhs_object) const
2645
{
2746
int result = Object::compare(rhs_object);
@@ -92,6 +111,15 @@ ShaderModule::ShaderModule()
92111
{
93112
}
94113

114+
ShaderModule::ShaderModule(const ShaderModule& rhs, const CopyOp& copyop):
115+
Inherit(rhs, copyop),
116+
source(rhs.source),
117+
hints(copyop(rhs.hints)),
118+
code(rhs.code)
119+
{
120+
vsg::info("ShaderModule::ShaderModule(", &rhs, ", copyop) ");
121+
}
122+
95123
ShaderModule::ShaderModule(const std::string& in_source, ref_ptr<ShaderCompileSettings> in_hints) :
96124
source(in_source),
97125
hints(in_hints)

src/vsg/state/ShaderStage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ ShaderStage::ShaderStage()
2121
{
2222
}
2323

24+
ShaderStage::ShaderStage(const ShaderStage& rhs, const CopyOp& copyop):
25+
Inherit(rhs, copyop),
26+
mask(rhs.mask),
27+
flags(rhs.flags),
28+
stage(rhs.stage),
29+
module(copyop(rhs.module)),
30+
entryPointName(rhs.entryPointName),
31+
specializationConstants(rhs.specializationConstants)
32+
{
33+
}
34+
2435
ShaderStage::ShaderStage(VkShaderStageFlagBits in_stage, const std::string& in_entryPointName, ref_ptr<ShaderModule> shaderModule) :
2536
stage(in_stage),
2637
module(shaderModule),

0 commit comments

Comments
 (0)