diff options
| author | 2021-06-11 22:43:43 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:38 -0400 | |
| commit | 427a2596a1de1875fd2c4d483cea482b80c986b2 (patch) | |
| tree | 2ba9fabe45ab8abfdb5d64489a0af8daea58639c /src/shader_recompiler/backend | |
| parent | glsl: Add immediate index oob checking for Cbuf getters (diff) | |
| download | yuzu-427a2596a1de1875fd2c4d483cea482b80c986b2.tar.gz yuzu-427a2596a1de1875fd2c4d483cea482b80c986b2.tar.xz yuzu-427a2596a1de1875fd2c4d483cea482b80c986b2.zip | |
glsl: Fix Cbuf getters for F32 type
Diffstat (limited to 'src/shader_recompiler/backend')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp index 8223ad862..96296ad28 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp | |||
| @@ -34,16 +34,16 @@ std::string OutputVertexIndex(EmitContext& ctx) { | |||
| 34 | return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : ""; | 34 | return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : ""; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | void GetCbuf(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const IR::Value& offset, | 37 | void GetCbuf(EmitContext& ctx, std::string_view ret, const IR::Value& binding, |
| 38 | u32 num_bits, std::string_view cast = {}, bool component_indexing_bug = false, | 38 | const IR::Value& offset, u32 num_bits, std::string_view cast = {}, |
| 39 | std::string_view bit_offset = {}) { | 39 | bool component_indexing_bug = false, std::string_view bit_offset = {}) { |
| 40 | const bool is_immediate{offset.IsImmediate()}; | 40 | const bool is_immediate{offset.IsImmediate()}; |
| 41 | if (is_immediate) { | 41 | if (is_immediate) { |
| 42 | const s32 signed_offset{static_cast<s32>(offset.U32())}; | 42 | const s32 signed_offset{static_cast<s32>(offset.U32())}; |
| 43 | static constexpr u32 cbuf_size{4096 * 16}; | 43 | static constexpr u32 cbuf_size{4096 * 16}; |
| 44 | if (signed_offset < 0 || offset.U32() > cbuf_size) { | 44 | if (signed_offset < 0 || offset.U32() > cbuf_size) { |
| 45 | // LOG_WARNING(..., "Immediate constant buffer offset is out of bounds"); | 45 | // LOG_WARNING(..., "Immediate constant buffer offset is out of bounds"); |
| 46 | ctx.AddU32("{}=0u;", inst); | 46 | ctx.Add("{}=0u;", ret); |
| 47 | return; | 47 | return; |
| 48 | } | 48 | } |
| 49 | } | 49 | } |
| @@ -60,10 +60,9 @@ void GetCbuf(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const I | |||
| 60 | bit_offset, num_bits)}; | 60 | bit_offset, num_bits)}; |
| 61 | if (!component_indexing_bug) { | 61 | if (!component_indexing_bug) { |
| 62 | const auto result{fmt::format(extraction, swizzle)}; | 62 | const auto result{fmt::format(extraction, swizzle)}; |
| 63 | ctx.AddU32("{}={};", inst, result); | 63 | ctx.Add("{}={};", ret, result); |
| 64 | return; | 64 | return; |
| 65 | } | 65 | } |
| 66 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; | ||
| 67 | const auto cbuf_offset{fmt::format("{}>>2", offset_var)}; | 66 | const auto cbuf_offset{fmt::format("{}>>2", offset_var)}; |
| 68 | for (u32 i = 0; i < 4; ++i) { | 67 | for (u32 i = 0; i < 4; ++i) { |
| 69 | const auto swizzle_string{fmt::format(".{}", "xyzw"[i])}; | 68 | const auto swizzle_string{fmt::format(".{}", "xyzw"[i])}; |
| @@ -74,26 +73,28 @@ void GetCbuf(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const I | |||
| 74 | 73 | ||
| 75 | void GetCbuf8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const IR::Value& offset, | 74 | void GetCbuf8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const IR::Value& offset, |
| 76 | std::string_view cast) { | 75 | std::string_view cast) { |
| 76 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; | ||
| 77 | if (offset.IsImmediate()) { | 77 | if (offset.IsImmediate()) { |
| 78 | const auto bit_offset{fmt::format("{}", (offset.U32() % 4) * 8)}; | 78 | const auto bit_offset{fmt::format("{}", (offset.U32() % 4) * 8)}; |
| 79 | GetCbuf(ctx, inst, binding, offset, 8, cast, false, bit_offset); | 79 | GetCbuf(ctx, ret, binding, offset, 8, cast, false, bit_offset); |
| 80 | } else { | 80 | } else { |
| 81 | const auto offset_var{ctx.var_alloc.Consume(offset)}; | 81 | const auto offset_var{ctx.var_alloc.Consume(offset)}; |
| 82 | const auto bit_offset{fmt::format("({}%4)*8", offset_var)}; | 82 | const auto bit_offset{fmt::format("({}%4)*8", offset_var)}; |
| 83 | GetCbuf(ctx, inst, binding, offset, 8, cast, ctx.profile.has_gl_component_indexing_bug, | 83 | GetCbuf(ctx, ret, binding, offset, 8, cast, ctx.profile.has_gl_component_indexing_bug, |
| 84 | bit_offset); | 84 | bit_offset); |
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | void GetCbuf16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const IR::Value& offset, | 88 | void GetCbuf16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const IR::Value& offset, |
| 89 | std::string_view cast) { | 89 | std::string_view cast) { |
| 90 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; | ||
| 90 | if (offset.IsImmediate()) { | 91 | if (offset.IsImmediate()) { |
| 91 | const auto bit_offset{fmt::format("{}", ((offset.U32() / 2) % 2) * 16)}; | 92 | const auto bit_offset{fmt::format("{}", ((offset.U32() / 2) % 2) * 16)}; |
| 92 | GetCbuf(ctx, inst, binding, offset, 16, cast, false, bit_offset); | 93 | GetCbuf(ctx, ret, binding, offset, 16, cast, false, bit_offset); |
| 93 | } else { | 94 | } else { |
| 94 | const auto offset_var{ctx.var_alloc.Consume(offset)}; | 95 | const auto offset_var{ctx.var_alloc.Consume(offset)}; |
| 95 | const auto bit_offset{fmt::format("(({}>>1)%2)*16", offset_var)}; | 96 | const auto bit_offset{fmt::format("(({}>>1)%2)*16", offset_var)}; |
| 96 | GetCbuf(ctx, inst, binding, offset, 16, cast, ctx.profile.has_gl_component_indexing_bug, | 97 | GetCbuf(ctx, ret, binding, offset, 16, cast, ctx.profile.has_gl_component_indexing_bug, |
| 97 | bit_offset); | 98 | bit_offset); |
| 98 | } | 99 | } |
| 99 | } | 100 | } |
| @@ -121,12 +122,14 @@ void EmitGetCbufS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | |||
| 121 | 122 | ||
| 122 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 123 | void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 123 | const IR::Value& offset) { | 124 | const IR::Value& offset) { |
| 124 | GetCbuf(ctx, inst, binding, offset, 32, "ftou"); | 125 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; |
| 126 | GetCbuf(ctx, ret, binding, offset, 32, "ftou"); | ||
| 125 | } | 127 | } |
| 126 | 128 | ||
| 127 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 129 | void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |
| 128 | const IR::Value& offset) { | 130 | const IR::Value& offset) { |
| 129 | GetCbuf(ctx, inst, binding, offset, 32); | 131 | const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32)}; |
| 132 | GetCbuf(ctx, ret, binding, offset, 32); | ||
| 130 | } | 133 | } |
| 131 | 134 | ||
| 132 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, | 135 | void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, |