From: Mikko Rasa Date: Wed, 17 Nov 2021 13:19:39 +0000 (+0200) Subject: Add a backend for SpirVModule and make it non-copyable X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=5cbd8664a7300d0c0076862572adeda9955b1c97 Add a backend for SpirVModule and make it non-copyable In Vulkan shader modules are objects of their own. --- diff --git a/source/backends/opengl/module_backend.h b/source/backends/opengl/module_backend.h new file mode 100644 index 00000000..9c91ae1e --- /dev/null +++ b/source/backends/opengl/module_backend.h @@ -0,0 +1,22 @@ +#ifndef MSP_GL_MODULE_BACKEND_H_ +#define MSP_GL_MODULE_BACKEND_H_ + +#include + +namespace Msp { +namespace GL { + +class OpenGLSpirVModule: public NonCopyable +{ +protected: + OpenGLSpirVModule() = default; + OpenGLSpirVModule(OpenGLSpirVModule &&) { }; + ~OpenGLSpirVModule() = default; +}; + +using SpirVModuleBackend = OpenGLSpirVModule; + +} // namespace GL +} // namespace Msp + +#endif diff --git a/source/core/module.cpp b/source/core/module.cpp index 15bd750c..4eefc034 100644 --- a/source/core/module.cpp +++ b/source/core/module.cpp @@ -96,41 +96,6 @@ void GlslModule::compile(SL::Compiler &compiler) } -SpirVModule::SpirVModule(const SpirVModule &other): - code(other.code), - entry_points(other.entry_points), - structs(other.structs), - variables(other.variables) -{ - remap_pointers_from(other); -} - -SpirVModule &SpirVModule::operator=(const SpirVModule &other) -{ - code = other.code; - entry_points = other.entry_points; - structs = other.structs; - variables = other.variables; - remap_pointers_from(other); - return *this; -} - -void SpirVModule::remap_pointers_from(const SpirVModule &other) -{ - for(EntryPoint &e: entry_points) - for(const Variable *&v: e.globals) - v = &variables[v-&other.variables.front()]; - - for(Variable &v: variables) - if(v.struct_type) - v.struct_type = &structs[v.struct_type-&other.structs.front()]; - - for(Structure &s: structs) - for(StructMember &m: s.members) - if(m.struct_type) - m.struct_type = &structs[m.struct_type-&other.structs.front()]; -} - void SpirVModule::load_code(IO::Base &io) { uint32_t buffer[1024]; diff --git a/source/core/module.h b/source/core/module.h index ad11f00b..c669af05 100644 --- a/source/core/module.h +++ b/source/core/module.h @@ -6,6 +6,7 @@ #include #include #include "datatype.h" +#include "module_backend.h" #include "glsl/compiler.h" #include "glsl/sourcemap.h" @@ -91,7 +92,7 @@ compiled to SPIR-V. Pre-compiled SPIR-V modules can also be loaded. Afterwards reflection data is available, providing information about variables forming the module's interface. */ -class SpirVModule: public Module +class SpirVModule: public Module, public SpirVModuleBackend { public: enum Stage @@ -228,13 +229,6 @@ private: std::vector variables; std::vector spec_constants; -public: - SpirVModule() = default; - SpirVModule(const SpirVModule &); - SpirVModule &operator=(const SpirVModule &); -private: - void remap_pointers_from(const SpirVModule &); - public: virtual Format get_format() const { return SPIR_V; }