diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index a1a1101e9e8..471399ec30a 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -405,7 +405,7 @@ static void print_resource(std::ostream &os, array_offset = res.uniformbuf.name.find_first_of("["); name_no_array = (array_offset == -1) ? res.uniformbuf.name : StringRef(res.uniformbuf.name.c_str(), array_offset); - os << "uniform _" << name_no_array << " { " << res.uniformbuf.type_name << " " + os << "uniform " << name_no_array << " { " << res.uniformbuf.type_name << " _" << res.uniformbuf.name << "; };\n"; break; case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER: @@ -413,13 +413,36 @@ static void print_resource(std::ostream &os, name_no_array = (array_offset == -1) ? res.storagebuf.name : StringRef(res.storagebuf.name.c_str(), array_offset); print_qualifier(os, res.storagebuf.qualifiers); - os << "buffer _"; - os << name_no_array << " { " << res.storagebuf.type_name << " " << res.storagebuf.name + os << "buffer "; + os << name_no_array << " { " << res.storagebuf.type_name << " _" << res.storagebuf.name << "; };\n"; break; } } +static void print_resource_alias(std::ostream &os, const ShaderCreateInfo::Resource &res) +{ + int64_t array_offset; + StringRef name_no_array; + + switch (res.bind_type) { + case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER: + array_offset = res.uniformbuf.name.find_first_of("["); + name_no_array = (array_offset == -1) ? res.uniformbuf.name : + StringRef(res.uniformbuf.name.c_str(), array_offset); + os << "#define " << name_no_array << " (_" << name_no_array << ")\n"; + break; + case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER: + array_offset = res.storagebuf.name.find_first_of("["); + name_no_array = (array_offset == -1) ? res.storagebuf.name : + StringRef(res.storagebuf.name.c_str(), array_offset); + os << "#define " << name_no_array << " (_" << name_no_array << ")\n"; + break; + default: + break; + } +} + static void print_interface(std::ostream &os, const StringRefNull &prefix, const StageInterfaceInfo &iface, @@ -452,10 +475,16 @@ std::string GLShader::resources_declare(const ShaderCreateInfo &info) const for (const ShaderCreateInfo::Resource &res : info.pass_resources_) { print_resource(ss, res, info.auto_resource_location_); } + for (const ShaderCreateInfo::Resource &res : info.pass_resources_) { + print_resource_alias(ss, res); + } ss << "\n/* Batch Resources. */\n"; for (const ShaderCreateInfo::Resource &res : info.batch_resources_) { print_resource(ss, res, info.auto_resource_location_); } + for (const ShaderCreateInfo::Resource &res : info.batch_resources_) { + print_resource_alias(ss, res); + } ss << "\n/* Push Constants. */\n"; for (const ShaderCreateInfo::PushConst &uniform : info.push_constants_) { ss << "uniform " << to_string(uniform.type) << " " << uniform.name; diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc index 99eabce794e..0b0bd2c1ea8 100644 --- a/source/blender/gpu/opengl/gl_shader_interface.cc +++ b/source/blender/gpu/opengl/gl_shader_interface.cc @@ -469,8 +469,7 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI if (res.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER) { copy_input_name(input, res.uniformbuf.name, name_buffer_, name_buffer_offset); if (true || !GLContext::explicit_location_support) { - std::string prefixed_name = "_" + res.uniformbuf.name; - input->location = glGetUniformBlockIndex(program, prefixed_name.c_str()); + input->location = glGetUniformBlockIndex(program, name_buffer_ + input->name_offset); glUniformBlockBinding(program, input->location, res.slot); } input->binding = res.slot;