shader: Fix address register offset behavior in GLSL. (#6920)

This commit is contained in:
Steveice10 2023-08-28 13:23:59 -07:00 committed by GitHub
parent d2260bafef
commit 81a5e2355a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);");