From 81a5e2355ac8a5a36b0b7908774f0002feb76bf3 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Mon, 28 Aug 2023 13:23:59 -0700 Subject: [PATCH] shader: Fix address register offset behavior in GLSL. (#6920) --- .../renderer_opengl/gl_shader_decompiler.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 73a7bb27c..06f6a1cd4 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -334,7 +334,7 @@ private: return fmt::format("reg_tmp{}", index); case RegisterType::FloatUniform: if (address_register_index != 0) { - return fmt::format("uniforms.f[{} + address_registers.{}]", index, + return fmt::format("get_offset_register({}, address_registers.{})", index, "xyz"[address_register_index - 1]); } return fmt::format("uniforms.f[{}]", index); @@ -835,6 +835,14 @@ private: #endif } + shader.AddLine("vec4 get_offset_register(int base_index, int offset) {{"); + ++shader.scope; + shader.AddLine("int fixed_offset = offset >= -128 && offset <= 127 ? offset : 0;"); + shader.AddLine("uint index = uint((base_index + fixed_offset) & 0x7F);"); + shader.AddLine("return index < 96u ? uniforms.f[index] : vec4(1.0);"); + --shader.scope; + shader.AddLine("}}\n"); + // Add declarations for registers shader.AddLine("bvec2 conditional_code = bvec2(false);"); shader.AddLine("ivec3 address_registers = ivec3(0);");