summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
diff options
context:
space:
mode:
authorGravatar ameerj2021-05-30 19:13:22 -0400
committerGravatar ameerj2021-07-22 21:51:37 -0400
commit9f3ffb996b0d02ca64b492d22ff158e8f3659257 (patch)
tree48993eaf320484cf042071a81a1a6b1dcc829eb9 /src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
parentglsl: Rework variable allocator to allow for variable reuse (diff)
downloadyuzu-9f3ffb996b0d02ca64b492d22ff158e8f3659257.tar.gz
yuzu-9f3ffb996b0d02ca64b492d22ff158e8f3659257.tar.xz
yuzu-9f3ffb996b0d02ca64b492d22ff158e8f3659257.zip
glsl: Rework var alloc to not assign unused results
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
index 0fd667c8f..44a719fc3 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
@@ -9,8 +9,14 @@
9#include "shader_recompiler/frontend/ir/value.h" 9#include "shader_recompiler/frontend/ir/value.h"
10 10
11namespace Shader::Backend::GLSL { 11namespace Shader::Backend::GLSL {
12namespace {
12static constexpr std::string_view SWIZZLE{"xyzw"}; 13static constexpr std::string_view SWIZZLE{"xyzw"};
13 14void CompositeInsert(EmitContext& ctx, std::string_view result, std::string_view composite,
15 std::string_view object, u32 index) {
16 ctx.Add("{}={};", result, composite);
17 ctx.Add("{}.{}={};", result, SWIZZLE[index], object);
18}
19} // namespace
14void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, 20void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
15 std::string_view e2) { 21 std::string_view e2) {
16 ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2); 22 ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2);
@@ -41,19 +47,22 @@ void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_vie
41 ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]); 47 ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
42} 48}
43 49
44void EmitCompositeInsertU32x2(EmitContext& ctx, std::string_view composite, std::string_view object, 50void EmitCompositeInsertU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
45 u32 index) { 51 std::string_view object, u32 index) {
46 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); 52 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)};
53 CompositeInsert(ctx, ret, composite, object, index);
47} 54}
48 55
49void EmitCompositeInsertU32x3(EmitContext& ctx, std::string_view composite, std::string_view object, 56void EmitCompositeInsertU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
50 u32 index) { 57 std::string_view object, u32 index) {
51 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); 58 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x3)};
59 CompositeInsert(ctx, ret, composite, object, index);
52} 60}
53 61
54void EmitCompositeInsertU32x4(EmitContext& ctx, std::string_view composite, std::string_view object, 62void EmitCompositeInsertU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
55 u32 index) { 63 std::string_view object, u32 index) {
56 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); 64 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x4)};
65 CompositeInsert(ctx, ret, composite, object, index);
57} 66}
58 67
59void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx, 68void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
@@ -146,19 +155,22 @@ void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_vie
146 ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]); 155 ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
147} 156}
148 157
149void EmitCompositeInsertF32x2(EmitContext& ctx, std::string_view composite, std::string_view object, 158void EmitCompositeInsertF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
150 u32 index) { 159 std::string_view object, u32 index) {
151 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); 160 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x2)};
161 CompositeInsert(ctx, ret, composite, object, index);
152} 162}
153 163
154void EmitCompositeInsertF32x3(EmitContext& ctx, std::string_view composite, std::string_view object, 164void EmitCompositeInsertF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
155 u32 index) { 165 std::string_view object, u32 index) {
156 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); 166 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x3)};
167 CompositeInsert(ctx, ret, composite, object, index);
157} 168}
158 169
159void EmitCompositeInsertF32x4(EmitContext& ctx, std::string_view composite, std::string_view object, 170void EmitCompositeInsertF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
160 u32 index) { 171 std::string_view object, u32 index) {
161 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object); 172 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
173 CompositeInsert(ctx, ret, composite, object, index);
162} 174}
163 175
164void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) { 176void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {