diff options
Diffstat (limited to 'src/shader_recompiler/backend/glasm/emit_glasm_image.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm_image.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp index ab5a694fd..beee9cf06 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp | |||
| @@ -50,6 +50,16 @@ std::string Texture(EmitContext& ctx, IR::TextureInstInfo info, | |||
| 50 | } | 50 | } |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | std::string Image(EmitContext& ctx, IR::TextureInstInfo info, | ||
| 54 | [[maybe_unused]] const IR::Value& index) { | ||
| 55 | // FIXME: indexed reads | ||
| 56 | if (info.type == TextureType::Buffer) { | ||
| 57 | return fmt::format("image[{}]", ctx.image_buffer_bindings.at(info.descriptor_index)); | ||
| 58 | } else { | ||
| 59 | return fmt::format("image[{}]", ctx.image_bindings.at(info.descriptor_index)); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 53 | std::string_view TextureType(IR::TextureInstInfo info) { | 63 | std::string_view TextureType(IR::TextureInstInfo info) { |
| 54 | if (info.is_depth) { | 64 | if (info.is_depth) { |
| 55 | switch (info.type) { | 65 | switch (info.type) { |
| @@ -173,6 +183,28 @@ void StoreSparse(EmitContext& ctx, IR::Inst* sparse_inst) { | |||
| 173 | sparse_ret, sparse_ret); | 183 | sparse_ret, sparse_ret); |
| 174 | sparse_inst->Invalidate(); | 184 | sparse_inst->Invalidate(); |
| 175 | } | 185 | } |
| 186 | |||
| 187 | std::string_view FormatStorage(ImageFormat format) { | ||
| 188 | switch (format) { | ||
| 189 | case ImageFormat::Typeless: | ||
| 190 | return "U"; | ||
| 191 | case ImageFormat::R8_UINT: | ||
| 192 | return "U8"; | ||
| 193 | case ImageFormat::R8_SINT: | ||
| 194 | return "S8"; | ||
| 195 | case ImageFormat::R16_UINT: | ||
| 196 | return "U16"; | ||
| 197 | case ImageFormat::R16_SINT: | ||
| 198 | return "S16"; | ||
| 199 | case ImageFormat::R32_UINT: | ||
| 200 | return "U32"; | ||
| 201 | case ImageFormat::R32G32_UINT: | ||
| 202 | return "U32X2"; | ||
| 203 | case ImageFormat::R32G32B32A32_UINT: | ||
| 204 | return "U32X4"; | ||
| 205 | } | ||
| 206 | throw InvalidArgument("Invalid image format {}", format); | ||
| 207 | } | ||
| 176 | } // Anonymous namespace | 208 | } // Anonymous namespace |
| 177 | 209 | ||
| 178 | void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 210 | void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
| @@ -528,9 +560,16 @@ void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 528 | StoreSparse(ctx, sparse_inst); | 560 | StoreSparse(ctx, sparse_inst); |
| 529 | } | 561 | } |
| 530 | 562 | ||
| 531 | void EmitImageRead([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 563 | void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord) { |
| 532 | [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord) { | 564 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 533 | throw NotImplementedException("GLASM instruction"); | 565 | const auto sparse_inst{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSparseFromOp)}; |
| 566 | const std::string_view format{FormatStorage(info.image_format)}; | ||
| 567 | const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""}; | ||
| 568 | const std::string_view type{TextureType(info)}; | ||
| 569 | const std::string image{Image(ctx, info, index)}; | ||
| 570 | const Register ret{ctx.reg_alloc.Define(inst)}; | ||
| 571 | ctx.Add("LOADIM.{}{} {},{},{},{};", format, sparse_mod, ret, coord, image, type); | ||
| 572 | StoreSparse(ctx, sparse_inst); | ||
| 534 | } | 573 | } |
| 535 | 574 | ||
| 536 | void EmitImageWrite([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 575 | void EmitImageWrite([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |