From: Mikko Rasa Date: Sun, 7 Nov 2021 17:09:42 +0000 (+0200) Subject: Build the list of glUniform* calls even for SPIR-V modules X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2e6e6fd559010aad6ae0d44c433e32acb387e8b9;p=libs%2Fgl.git Build the list of glUniform* calls even for SPIR-V modules This is relevant since SPIR-V supports default block uniforms when targeting OpenGL. --- diff --git a/source/backends/opengl/program_backend.cpp b/source/backends/opengl/program_backend.cpp index d78a5b42..911ce34e 100644 --- a/source/backends/opengl/program_backend.cpp +++ b/source/backends/opengl/program_backend.cpp @@ -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; - else if(u.type==FLOAT_VEC2) - func = &uniform_wrapper; - else if(u.type==FLOAT_VEC3) - func = &uniform_wrapper; - else if(u.type==FLOAT_VEC4) - func = &uniform_wrapper; - else if(u.type==INT) - func = &uniform_wrapper; - else if(u.type==INT_VEC2) - func = &uniform_wrapper; - else if(u.type==INT_VEC3) - func = &uniform_wrapper; - else if(u.type==INT_VEC4) - func = &uniform_wrapper; - else if(u.type==UNSIGNED_INT) - func = &uniform_wrapper; - else if(u.type==UINT_VEC2) - func = &uniform_wrapper; - else if(u.type==UINT_VEC3) - func = &uniform_wrapper; - else if(u.type==UINT_VEC4) - func = &uniform_wrapper; - else if(u.type==FLOAT_MAT2) - func = &uniform_matrix_wrapper; - else if(u.type==FLOAT_MAT3) - func = &uniform_matrix_wrapper; - else if(u.type==FLOAT_MAT4) - func = &uniform_matrix_wrapper; - else if(u.type==FLOAT_MAT2x3) - func = &uniform_matrix_wrapper; - else if(u.type==FLOAT_MAT3x2) - func = &uniform_matrix_wrapper; - else if(u.type==FLOAT_MAT2x4) - func = &uniform_matrix_wrapper; - else if(u.type==FLOAT_MAT4x2) - func = &uniform_matrix_wrapper; - else if(u.type==FLOAT_MAT3x4) - func = &uniform_matrix_wrapper; - else if(u.type==FLOAT_MAT4x3) - func = &uniform_matrix_wrapper; - - 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(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; + else if(u->type==FLOAT_VEC2) + func = &uniform_wrapper; + else if(u->type==FLOAT_VEC3) + func = &uniform_wrapper; + else if(u->type==FLOAT_VEC4) + func = &uniform_wrapper; + else if(u->type==INT) + func = &uniform_wrapper; + else if(u->type==INT_VEC2) + func = &uniform_wrapper; + else if(u->type==INT_VEC3) + func = &uniform_wrapper; + else if(u->type==INT_VEC4) + func = &uniform_wrapper; + else if(u->type==UNSIGNED_INT) + func = &uniform_wrapper; + else if(u->type==UINT_VEC2) + func = &uniform_wrapper; + else if(u->type==UINT_VEC3) + func = &uniform_wrapper; + else if(u->type==UINT_VEC4) + func = &uniform_wrapper; + else if(u->type==FLOAT_MAT2) + func = &uniform_matrix_wrapper; + else if(u->type==FLOAT_MAT3) + func = &uniform_matrix_wrapper; + else if(u->type==FLOAT_MAT4) + func = &uniform_matrix_wrapper; + else if(u->type==FLOAT_MAT2x3) + func = &uniform_matrix_wrapper; + else if(u->type==FLOAT_MAT3x2) + func = &uniform_matrix_wrapper; + else if(u->type==FLOAT_MAT2x4) + func = &uniform_matrix_wrapper; + else if(u->type==FLOAT_MAT4x2) + func = &uniform_matrix_wrapper; + else if(u->type==FLOAT_MAT3x4) + func = &uniform_matrix_wrapper; + else if(u->type==FLOAT_MAT4x3) + func = &uniform_matrix_wrapper; + + if(func) + uniform_calls.push_back(UniformCall(u->location, u->array_size, func)); + } + } +} + void OpenGLProgram::set_debug_name(const string &name) { #ifdef DEBUG diff --git a/source/backends/opengl/program_backend.h b/source/backends/opengl/program_backend.h index 8fa68102..dbf043e9 100644 --- a/source/backends/opengl/program_backend.h +++ b/source/backends/opengl/program_backend.h @@ -60,6 +60,7 @@ protected: void query_uniform_blocks(const std::vector &); 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); diff --git a/source/core/program.cpp b/source/core/program.cpp index 6013e7e8..9193cd7b 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -40,6 +40,8 @@ void Program::add_stages(const Module &mod, const map &spec_values) collect_attributes(static_cast(mod)); } + finalize_uniforms(); + for(ReflectData::UniformBlockInfo &b: reflect_data.uniform_blocks) if(!b.data_size && !b.uniforms.empty()) {