]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/opengl/program_backend.cpp
Move backend information into Device
[libs/gl.git] / source / backends / opengl / program_backend.cpp
index d78a5b4206505ee51c9b3ecce1a201579bfe18ee..132ad1c05e823e5fd0da09887a9d54af82044638 100644 (file)
@@ -12,6 +12,7 @@
 #include <msp/gl/extensions/khr_debug.h>
 #include <msp/gl/extensions/nv_non_square_matrices.h>
 #include <msp/io/print.h>
+#include "device.h"
 #include "error.h"
 #include "program.h"
 #include "program_backend.h"
@@ -89,7 +90,7 @@ unsigned OpenGLProgram::add_stage(Stage type)
 
 void OpenGLProgram::add_glsl_stages(const GlslModule &mod, const map<string, int> &spec_values, TransientData &transient)
 {
-       SL::Compiler compiler;
+       SL::Compiler compiler(Device::get_current().get_info().glsl_features);
        compiler.set_source(mod.get_prepared_source(), "<module>");
        compiler.specialize(spec_values);
        compiler.compile(SL::Compiler::PROGRAM);
@@ -162,7 +163,7 @@ void OpenGLProgram::compile_glsl_stage(const GlslModule &mod, unsigned stage_id)
 #endif
 }
 
-void OpenGLProgram::add_spirv_stages(const SpirVModule &mod, const map<string, int> &spec_values, TransientData &transient)
+void OpenGLProgram::add_spirv_stages(const SpirVModule &mod, const map<string, int> &spec_values)
 {
        static Require _req(ARB_gl_spirv);
        static Require _req2(ARB_ES2_compatibility);
@@ -201,7 +202,6 @@ void OpenGLProgram::add_spirv_stages(const SpirVModule &mod, const map<string, i
                {
                        spec_id_array.push_back(c.constant_id);
                        spec_value_array.push_back(i->second);
-                       transient.spec_values[c.constant_id] = i->second;
                }
        }
 
@@ -298,57 +298,8 @@ void OpenGLProgram::query_uniforms()
                                u.matrix_stride = get_type_size(get_matrix_column_type(u.type));
                        default_block.uniforms.push_back(&u);
 
-                       if(u.location>=0)
-                       {
-                               UniformCall::FuncPtr func = 0;
-                               if(is_image(u.type))
-                                       glGetUniformiv(id, u.location, &u.binding);
-                               else if(u.type==FLOAT)
-                                       func = &uniform_wrapper<float, glUniform1fv>;
-                               else if(u.type==FLOAT_VEC2)
-                                       func = &uniform_wrapper<float, glUniform2fv>;
-                               else if(u.type==FLOAT_VEC3)
-                                       func = &uniform_wrapper<float, glUniform3fv>;
-                               else if(u.type==FLOAT_VEC4)
-                                       func = &uniform_wrapper<float, glUniform4fv>;
-                               else if(u.type==INT)
-                                       func = &uniform_wrapper<int, glUniform1iv>;
-                               else if(u.type==INT_VEC2)
-                                       func = &uniform_wrapper<int, glUniform2iv>;
-                               else if(u.type==INT_VEC3)
-                                       func = &uniform_wrapper<int, glUniform3iv>;
-                               else if(u.type==INT_VEC4)
-                                       func = &uniform_wrapper<int, glUniform4iv>;
-                               else if(u.type==UNSIGNED_INT)
-                                       func = &uniform_wrapper<unsigned, glUniform1uiv>;
-                               else if(u.type==UINT_VEC2)
-                                       func = &uniform_wrapper<unsigned, glUniform2uiv>;
-                               else if(u.type==UINT_VEC3)
-                                       func = &uniform_wrapper<unsigned, glUniform3uiv>;
-                               else if(u.type==UINT_VEC4)
-                                       func = &uniform_wrapper<unsigned, glUniform4uiv>;
-                               else if(u.type==FLOAT_MAT2)
-                                       func = &uniform_matrix_wrapper<float, glUniformMatrix2fv>;
-                               else if(u.type==FLOAT_MAT3)
-                                       func = &uniform_matrix_wrapper<float, glUniformMatrix3fv>;
-                               else if(u.type==FLOAT_MAT4)
-                                       func = &uniform_matrix_wrapper<float, glUniformMatrix4fv>;
-                               else if(u.type==FLOAT_MAT2x3)
-                                       func = &uniform_matrix_wrapper<float, glUniformMatrix2x3fv>;
-                               else if(u.type==FLOAT_MAT3x2)
-                                       func = &uniform_matrix_wrapper<float, glUniformMatrix3x2fv>;
-                               else if(u.type==FLOAT_MAT2x4)
-                                       func = &uniform_matrix_wrapper<float, glUniformMatrix2x4fv>;
-                               else if(u.type==FLOAT_MAT4x2)
-                                       func = &uniform_matrix_wrapper<float, glUniformMatrix4x2fv>;
-                               else if(u.type==FLOAT_MAT3x4)
-                                       func = &uniform_matrix_wrapper<float, glUniformMatrix3x4fv>;
-                               else if(u.type==FLOAT_MAT4x3)
-                                       func = &uniform_matrix_wrapper<float, glUniformMatrix4x3fv>;
-
-                               if(func)
-                                       uniform_calls.push_back(UniformCall(u.location, u.array_size, func));
-                       }
+                       if(is_image(u.type) && u.location>=0)
+                               glGetUniformiv(id, u.location, &u.binding);
                }
 
        default_block.sort_uniforms();
@@ -485,6 +436,72 @@ void OpenGLProgram::apply_bindings(const TransientData &transient)
        }
 }
 
+void OpenGLProgram::finalize_uniforms()
+{
+       ReflectData &rd = static_cast<Program *>(this)->reflect_data;
+
+       auto i = find_if(rd.uniform_blocks, [](const ReflectData::UniformBlockInfo &b){ return b.bind_point<0; });
+       if(i!=rd.uniform_blocks.end() && !i->uniforms.empty())
+       {
+               for(const ReflectData::UniformInfo *u: i->uniforms)
+                       if(u->location>=0)
+                       {
+                               UniformCall::FuncPtr func = 0;
+                               if(u->type==FLOAT)
+                                       func = &uniform_wrapper<float, glUniform1fv>;
+                               else if(u->type==FLOAT_VEC2)
+                                       func = &uniform_wrapper<float, glUniform2fv>;
+                               else if(u->type==FLOAT_VEC3)
+                                       func = &uniform_wrapper<float, glUniform3fv>;
+                               else if(u->type==FLOAT_VEC4)
+                                       func = &uniform_wrapper<float, glUniform4fv>;
+                               else if(u->type==INT)
+                                       func = &uniform_wrapper<int, glUniform1iv>;
+                               else if(u->type==INT_VEC2)
+                                       func = &uniform_wrapper<int, glUniform2iv>;
+                               else if(u->type==INT_VEC3)
+                                       func = &uniform_wrapper<int, glUniform3iv>;
+                               else if(u->type==INT_VEC4)
+                                       func = &uniform_wrapper<int, glUniform4iv>;
+                               else if(u->type==UNSIGNED_INT)
+                                       func = &uniform_wrapper<unsigned, glUniform1uiv>;
+                               else if(u->type==UINT_VEC2)
+                                       func = &uniform_wrapper<unsigned, glUniform2uiv>;
+                               else if(u->type==UINT_VEC3)
+                                       func = &uniform_wrapper<unsigned, glUniform3uiv>;
+                               else if(u->type==UINT_VEC4)
+                                       func = &uniform_wrapper<unsigned, glUniform4uiv>;
+                               else if(u->type==FLOAT_MAT2)
+                                       func = &uniform_matrix_wrapper<float, glUniformMatrix2fv>;
+                               else if(u->type==FLOAT_MAT3)
+                                       func = &uniform_matrix_wrapper<float, glUniformMatrix3fv>;
+                               else if(u->type==FLOAT_MAT4)
+                                       func = &uniform_matrix_wrapper<float, glUniformMatrix4fv>;
+                               else if(u->type==FLOAT_MAT2x3)
+                                       func = &uniform_matrix_wrapper<float, glUniformMatrix2x3fv>;
+                               else if(u->type==FLOAT_MAT3x2)
+                                       func = &uniform_matrix_wrapper<float, glUniformMatrix3x2fv>;
+                               else if(u->type==FLOAT_MAT2x4)
+                                       func = &uniform_matrix_wrapper<float, glUniformMatrix2x4fv>;
+                               else if(u->type==FLOAT_MAT4x2)
+                                       func = &uniform_matrix_wrapper<float, glUniformMatrix4x2fv>;
+                               else if(u->type==FLOAT_MAT3x4)
+                                       func = &uniform_matrix_wrapper<float, glUniformMatrix3x4fv>;
+                               else if(u->type==FLOAT_MAT4x3)
+                                       func = &uniform_matrix_wrapper<float, glUniformMatrix4x3fv>;
+
+                               if(func)
+                                       uniform_calls.push_back(UniformCall(u->location, u->array_size, func));
+                       }
+
+               if(i->data_size<=0)
+               {
+                       const ReflectData::UniformInfo &last = *i->uniforms.back();
+                       i->data_size = last.location*16+last.array_size*get_type_size(last.type);
+               }
+       }
+}
+
 void OpenGLProgram::set_debug_name(const string &name)
 {
 #ifdef DEBUG