diff options
| author | 2021-05-09 03:11:34 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:30 -0400 | |
| commit | 1c9307969c4e3f6206947f1360acae33f95a4a86 (patch) | |
| tree | 86ccd9c88333327d7659a396f66301955a088f45 /src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp | |
| parent | glasm: Use CMP.S for Select32 (diff) | |
| download | yuzu-1c9307969c4e3f6206947f1360acae33f95a4a86.tar.gz yuzu-1c9307969c4e3f6206947f1360acae33f95a4a86.tar.xz yuzu-1c9307969c4e3f6206947f1360acae33f95a4a86.zip | |
glasm: Make GLASM aware of types
Diffstat (limited to 'src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp index e69de29bb..063dcaf13 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_composite.cpp | |||
| @@ -0,0 +1,225 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "shader_recompiler/backend/glasm/emit_context.h" | ||
| 6 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" | ||
| 7 | #include "shader_recompiler/frontend/ir/value.h" | ||
| 8 | |||
| 9 | namespace Shader::Backend::GLASM { | ||
| 10 | namespace { | ||
| 11 | template <typename... Values> | ||
| 12 | void CompositeConstructU32(EmitContext& ctx, IR::Inst& inst, Values&&... elements) { | ||
| 13 | const Register ret{ctx.reg_alloc.Define(inst)}; | ||
| 14 | if (std::ranges::any_of(std::array{elements...}, | ||
| 15 | [](const IR::Value& value) { return value.IsImmediate(); })) { | ||
| 16 | const std::array<u32, 4> values{(elements.IsImmediate() ? elements.U32() : 0)...}; | ||
| 17 | ctx.Add("MOV.U {},{{{},{},{},{}}};", ret, fmt::to_string(values[0]), | ||
| 18 | fmt::to_string(values[1]), fmt::to_string(values[2]), fmt::to_string(values[3])); | ||
| 19 | } | ||
| 20 | size_t index{}; | ||
| 21 | for (const IR::Value& element : {elements...}) { | ||
| 22 | if (!element.IsImmediate()) { | ||
| 23 | const ScalarU32 value{ctx.reg_alloc.Consume(element)}; | ||
| 24 | ctx.Add("MOV.U {}.{},{};", ret, "xyzw"[index], value); | ||
| 25 | } | ||
| 26 | ++index; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | void CompositeExtractU32(EmitContext& ctx, IR::Inst& inst, Register composite, u32 index) { | ||
| 31 | const Register ret{ctx.reg_alloc.Define(inst)}; | ||
| 32 | if (ret == composite && index == 0) { | ||
| 33 | // No need to do anything here, the source and destination are the same register | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | ctx.Add("MOV.U {}.x,{}.{};", ret, composite, "xyzw"[index]); | ||
| 37 | } | ||
| 38 | } // Anonymous namespace | ||
| 39 | |||
| 40 | void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& e1, | ||
| 41 | const IR::Value& e2) { | ||
| 42 | CompositeConstructU32(ctx, inst, e1, e2); | ||
| 43 | } | ||
| 44 | |||
| 45 | void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, const IR::Value& e1, | ||
| 46 | const IR::Value& e2, const IR::Value& e3) { | ||
| 47 | CompositeConstructU32(ctx, inst, e1, e2, e3); | ||
| 48 | } | ||
| 49 | |||
| 50 | void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, const IR::Value& e1, | ||
| 51 | const IR::Value& e2, const IR::Value& e3, const IR::Value& e4) { | ||
| 52 | CompositeConstructU32(ctx, inst, e1, e2, e3, e4); | ||
| 53 | } | ||
| 54 | |||
| 55 | void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, Register composite, u32 index) { | ||
| 56 | CompositeExtractU32(ctx, inst, composite, index); | ||
| 57 | } | ||
| 58 | |||
| 59 | void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, Register composite, u32 index) { | ||
| 60 | CompositeExtractU32(ctx, inst, composite, index); | ||
| 61 | } | ||
| 62 | |||
| 63 | void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, Register composite, u32 index) { | ||
| 64 | CompositeExtractU32(ctx, inst, composite, index); | ||
| 65 | } | ||
| 66 | |||
| 67 | void EmitCompositeInsertU32x2([[maybe_unused]] EmitContext& ctx, | ||
| 68 | [[maybe_unused]] Register composite, | ||
| 69 | [[maybe_unused]] ScalarU32 object, [[maybe_unused]] u32 index) { | ||
| 70 | throw NotImplementedException("GLASM instruction"); | ||
| 71 | } | ||
| 72 | |||
| 73 | void EmitCompositeInsertU32x3([[maybe_unused]] EmitContext& ctx, | ||
| 74 | [[maybe_unused]] Register composite, | ||
| 75 | [[maybe_unused]] ScalarU32 object, [[maybe_unused]] u32 index) { | ||
| 76 | throw NotImplementedException("GLASM instruction"); | ||
| 77 | } | ||
| 78 | |||
| 79 | void EmitCompositeInsertU32x4([[maybe_unused]] EmitContext& ctx, | ||
| 80 | [[maybe_unused]] Register composite, | ||
| 81 | [[maybe_unused]] ScalarU32 object, [[maybe_unused]] u32 index) { | ||
| 82 | throw NotImplementedException("GLASM instruction"); | ||
| 83 | } | ||
| 84 | |||
| 85 | void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register e1, | ||
| 86 | [[maybe_unused]] Register e2) { | ||
| 87 | throw NotImplementedException("GLASM instruction"); | ||
| 88 | } | ||
| 89 | |||
| 90 | void EmitCompositeConstructF16x3([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register e1, | ||
| 91 | [[maybe_unused]] Register e2, [[maybe_unused]] Register e3) { | ||
| 92 | throw NotImplementedException("GLASM instruction"); | ||
| 93 | } | ||
| 94 | |||
| 95 | void EmitCompositeConstructF16x4([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register e1, | ||
| 96 | [[maybe_unused]] Register e2, [[maybe_unused]] Register e3, | ||
| 97 | [[maybe_unused]] Register e4) { | ||
| 98 | throw NotImplementedException("GLASM instruction"); | ||
| 99 | } | ||
| 100 | |||
| 101 | void EmitCompositeExtractF16x2([[maybe_unused]] EmitContext& ctx, | ||
| 102 | [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) { | ||
| 103 | throw NotImplementedException("GLASM instruction"); | ||
| 104 | } | ||
| 105 | |||
| 106 | void EmitCompositeExtractF16x3([[maybe_unused]] EmitContext& ctx, | ||
| 107 | [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) { | ||
| 108 | throw NotImplementedException("GLASM instruction"); | ||
| 109 | } | ||
| 110 | |||
| 111 | void EmitCompositeExtractF16x4([[maybe_unused]] EmitContext& ctx, | ||
| 112 | [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) { | ||
| 113 | throw NotImplementedException("GLASM instruction"); | ||
| 114 | } | ||
| 115 | |||
| 116 | void EmitCompositeInsertF16x2([[maybe_unused]] EmitContext& ctx, | ||
| 117 | [[maybe_unused]] Register composite, [[maybe_unused]] Register object, | ||
| 118 | [[maybe_unused]] u32 index) { | ||
| 119 | throw NotImplementedException("GLASM instruction"); | ||
| 120 | } | ||
| 121 | |||
| 122 | void EmitCompositeInsertF16x3([[maybe_unused]] EmitContext& ctx, | ||
| 123 | [[maybe_unused]] Register composite, [[maybe_unused]] Register object, | ||
| 124 | [[maybe_unused]] u32 index) { | ||
| 125 | throw NotImplementedException("GLASM instruction"); | ||
| 126 | } | ||
| 127 | |||
| 128 | void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx, | ||
| 129 | [[maybe_unused]] Register composite, [[maybe_unused]] Register object, | ||
| 130 | [[maybe_unused]] u32 index) { | ||
| 131 | throw NotImplementedException("GLASM instruction"); | ||
| 132 | } | ||
| 133 | |||
| 134 | void EmitCompositeConstructF32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarF32 e1, | ||
| 135 | [[maybe_unused]] ScalarF32 e2) { | ||
| 136 | throw NotImplementedException("GLASM instruction"); | ||
| 137 | } | ||
| 138 | |||
| 139 | void EmitCompositeConstructF32x3([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarF32 e1, | ||
| 140 | [[maybe_unused]] ScalarF32 e2, [[maybe_unused]] ScalarF32 e3) { | ||
| 141 | throw NotImplementedException("GLASM instruction"); | ||
| 142 | } | ||
| 143 | |||
| 144 | void EmitCompositeConstructF32x4([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarF32 e1, | ||
| 145 | [[maybe_unused]] ScalarF32 e2, [[maybe_unused]] ScalarF32 e3, | ||
| 146 | [[maybe_unused]] ScalarF32 e4) { | ||
| 147 | throw NotImplementedException("GLASM instruction"); | ||
| 148 | } | ||
| 149 | |||
| 150 | void EmitCompositeExtractF32x2([[maybe_unused]] EmitContext& ctx, | ||
| 151 | [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) { | ||
| 152 | throw NotImplementedException("GLASM instruction"); | ||
| 153 | } | ||
| 154 | |||
| 155 | void EmitCompositeExtractF32x3([[maybe_unused]] EmitContext& ctx, | ||
| 156 | [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) { | ||
| 157 | throw NotImplementedException("GLASM instruction"); | ||
| 158 | } | ||
| 159 | |||
| 160 | void EmitCompositeExtractF32x4([[maybe_unused]] EmitContext& ctx, | ||
| 161 | [[maybe_unused]] Register composite, [[maybe_unused]] u32 index) { | ||
| 162 | throw NotImplementedException("GLASM instruction"); | ||
| 163 | } | ||
| 164 | |||
| 165 | void EmitCompositeInsertF32x2([[maybe_unused]] EmitContext& ctx, | ||
| 166 | [[maybe_unused]] Register composite, | ||
| 167 | [[maybe_unused]] ScalarF32 object, [[maybe_unused]] u32 index) { | ||
| 168 | throw NotImplementedException("GLASM instruction"); | ||
| 169 | } | ||
| 170 | |||
| 171 | void EmitCompositeInsertF32x3([[maybe_unused]] EmitContext& ctx, | ||
| 172 | [[maybe_unused]] Register composite, | ||
| 173 | [[maybe_unused]] ScalarF32 object, [[maybe_unused]] u32 index) { | ||
| 174 | throw NotImplementedException("GLASM instruction"); | ||
| 175 | } | ||
| 176 | |||
| 177 | void EmitCompositeInsertF32x4([[maybe_unused]] EmitContext& ctx, | ||
| 178 | [[maybe_unused]] Register composite, | ||
| 179 | [[maybe_unused]] ScalarF32 object, [[maybe_unused]] u32 index) { | ||
| 180 | throw NotImplementedException("GLASM instruction"); | ||
| 181 | } | ||
| 182 | |||
| 183 | void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) { | ||
| 184 | throw NotImplementedException("GLASM instruction"); | ||
| 185 | } | ||
| 186 | |||
| 187 | void EmitCompositeConstructF64x3([[maybe_unused]] EmitContext& ctx) { | ||
| 188 | throw NotImplementedException("GLASM instruction"); | ||
| 189 | } | ||
| 190 | |||
| 191 | void EmitCompositeConstructF64x4([[maybe_unused]] EmitContext& ctx) { | ||
| 192 | throw NotImplementedException("GLASM instruction"); | ||
| 193 | } | ||
| 194 | |||
| 195 | void EmitCompositeExtractF64x2([[maybe_unused]] EmitContext& ctx) { | ||
| 196 | throw NotImplementedException("GLASM instruction"); | ||
| 197 | } | ||
| 198 | |||
| 199 | void EmitCompositeExtractF64x3([[maybe_unused]] EmitContext& ctx) { | ||
| 200 | throw NotImplementedException("GLASM instruction"); | ||
| 201 | } | ||
| 202 | |||
| 203 | void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) { | ||
| 204 | throw NotImplementedException("GLASM instruction"); | ||
| 205 | } | ||
| 206 | |||
| 207 | void EmitCompositeInsertF64x2([[maybe_unused]] EmitContext& ctx, | ||
| 208 | [[maybe_unused]] Register composite, [[maybe_unused]] Register object, | ||
| 209 | [[maybe_unused]] u32 index) { | ||
| 210 | throw NotImplementedException("GLASM instruction"); | ||
| 211 | } | ||
| 212 | |||
| 213 | void EmitCompositeInsertF64x3([[maybe_unused]] EmitContext& ctx, | ||
| 214 | [[maybe_unused]] Register composite, [[maybe_unused]] Register object, | ||
| 215 | [[maybe_unused]] u32 index) { | ||
| 216 | throw NotImplementedException("GLASM instruction"); | ||
| 217 | } | ||
| 218 | |||
| 219 | void EmitCompositeInsertF64x4([[maybe_unused]] EmitContext& ctx, | ||
| 220 | [[maybe_unused]] Register composite, [[maybe_unused]] Register object, | ||
| 221 | [[maybe_unused]] u32 index) { | ||
| 222 | throw NotImplementedException("GLASM instruction"); | ||
| 223 | } | ||
| 224 | |||
| 225 | } // namespace Shader::Backend::GLASM | ||