]> git.tdb.fi Git - libs/gl.git/commitdiff
Build the list of glUniform* calls even for SPIR-V modules
authorMikko Rasa <tdb@tdb.fi>
Sun, 7 Nov 2021 17:09:42 +0000 (19:09 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 7 Nov 2021 17:11:50 +0000 (19:11 +0200)
This is relevant since SPIR-V supports default block uniforms when
targeting OpenGL.

source/backends/opengl/program_backend.cpp
source/backends/opengl/program_backend.h
source/core/program.cpp

index d78a5b4206505ee51c9b3ecce1a201579bfe18ee..911ce34e69fbf591ccd1950adea30ed91d6fda83 100644 (file)
@@ -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,66 @@ 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));
+                       }
+       }
+}
+
 void OpenGLProgram::set_debug_name(const string &name)
 {
 #ifdef DEBUG
index 8fa68102c2ddd0f714ec8d4dfb062e3133183a70..dbf043e9c89ba39a808432f80a001c2e933d68cb 100644 (file)
@@ -60,6 +60,7 @@ protected:
        void query_uniform_blocks(const std::vector<ReflectData::UniformInfo *> &);
        void query_attributes();
        void apply_bindings(const TransientData &);
+       void finalize_uniforms();
 
        void set_debug_name(const std::string &);
        void set_stage_debug_name(unsigned, Stage);
index 6013e7e82e9f35656f6741bb3743ea25a0237f5b..9193cd7be155b54a4f8b1fc8a87de974cc3d72b4 100644 (file)
@@ -40,6 +40,8 @@ void Program::add_stages(const Module &mod, const map<string, int> &spec_values)
                collect_attributes(static_cast<const SpirVModule &>(mod));
        }
 
+       finalize_uniforms();
+
        for(ReflectData::UniformBlockInfo &b: reflect_data.uniform_blocks)
                if(!b.data_size && !b.uniforms.empty())
                {