]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a backend for SpirVModule and make it non-copyable
authorMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 13:19:39 +0000 (15:19 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 13:28:10 +0000 (15:28 +0200)
In Vulkan shader modules are objects of their own.

source/backends/opengl/module_backend.h [new file with mode: 0644]
source/core/module.cpp
source/core/module.h

diff --git a/source/backends/opengl/module_backend.h b/source/backends/opengl/module_backend.h
new file mode 100644 (file)
index 0000000..9c91ae1
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef MSP_GL_MODULE_BACKEND_H_
+#define MSP_GL_MODULE_BACKEND_H_
+
+#include <msp/core/noncopyable.h>
+
+namespace Msp {
+namespace GL {
+
+class OpenGLSpirVModule: public NonCopyable
+{
+protected:
+       OpenGLSpirVModule() = default;
+       OpenGLSpirVModule(OpenGLSpirVModule &&) { };
+       ~OpenGLSpirVModule() = default;
+};
+
+using SpirVModuleBackend = OpenGLSpirVModule;
+
+} // namespace GL
+} // namespace Msp
+
+#endif
index 15bd750cf0b299bd7ea8440ed6d0be5adc3788d1..4eefc0347494ecadb077e8b0bc8a984688b08464 100644 (file)
@@ -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];
index ad11f00ba4e3470966b12f883490aa1baf1a9665..c669af0506ab64d26b25bf504ec28533e7e1cf92 100644 (file)
@@ -6,6 +6,7 @@
 #include <vector>
 #include <msp/io/base.h>
 #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<Variable> variables;
        std::vector<Constant> 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; }