summaryrefslogtreecommitdiff
path: root/src/shader_recompiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/backend/glasm/emit_context.cpp13
-rw-r--r--src/shader_recompiler/backend/glasm/emit_context.h1
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm_image.cpp33
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm_instructions.h4
4 files changed, 38 insertions, 13 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_context.cpp b/src/shader_recompiler/backend/glasm/emit_context.cpp
index d1fe84a5f..e2182400c 100644
--- a/src/shader_recompiler/backend/glasm/emit_context.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_context.cpp
@@ -80,11 +80,14 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings) : info{progra
80 Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index); 80 Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index);
81 } 81 }
82 } 82 }
83 const size_t num_textures{program.info.texture_descriptors.size()}; 83 texture_buffer_bindings.reserve(program.info.texture_buffer_descriptors.size());
84 texture_bindings.resize(num_textures); 84 for (const auto& desc : program.info.texture_buffer_descriptors) {
85 for (size_t index = 0; index < num_textures; ++index) { 85 texture_buffer_bindings.push_back(bindings.texture);
86 const auto& desc{program.info.texture_descriptors[index]}; 86 bindings.texture += desc.count;
87 texture_bindings[index] = bindings.texture; 87 }
88 texture_bindings.reserve(program.info.texture_descriptors.size());
89 for (const auto& desc : program.info.texture_descriptors) {
90 texture_bindings.push_back(bindings.texture);
88 bindings.texture += desc.count; 91 bindings.texture += desc.count;
89 } 92 }
90} 93}
diff --git a/src/shader_recompiler/backend/glasm/emit_context.h b/src/shader_recompiler/backend/glasm/emit_context.h
index 084635c77..d6b0bf73c 100644
--- a/src/shader_recompiler/backend/glasm/emit_context.h
+++ b/src/shader_recompiler/backend/glasm/emit_context.h
@@ -56,6 +56,7 @@ public:
56 RegAlloc reg_alloc{*this}; 56 RegAlloc reg_alloc{*this};
57 const Info& info; 57 const Info& info;
58 58
59 std::vector<u32> texture_buffer_bindings;
59 std::vector<u32> texture_bindings; 60 std::vector<u32> texture_bindings;
60 61
61 std::string_view stage_name = "invalid"; 62 std::string_view stage_name = "invalid";
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp
index 7b95505e2..333a003c9 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp
@@ -43,7 +43,11 @@ struct ScopedRegister {
43std::string Texture(EmitContext& ctx, IR::TextureInstInfo info, 43std::string Texture(EmitContext& ctx, IR::TextureInstInfo info,
44 [[maybe_unused]] const IR::Value& index) { 44 [[maybe_unused]] const IR::Value& index) {
45 // FIXME: indexed reads 45 // FIXME: indexed reads
46 return fmt::format("texture[{}]", ctx.texture_bindings.at(info.descriptor_index)); 46 if (info.type == TextureType::Buffer) {
47 return fmt::format("texture[{}]", ctx.texture_buffer_bindings.at(info.descriptor_index));
48 } else {
49 return fmt::format("texture[{}]", ctx.texture_bindings.at(info.descriptor_index));
50 }
47} 51}
48 52
49std::string_view TextureType(IR::TextureInstInfo info) { 53std::string_view TextureType(IR::TextureInstInfo info) {
@@ -421,11 +425,28 @@ void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& inde
421 StoreSparse(ctx, sparse_inst); 425 StoreSparse(ctx, sparse_inst);
422} 426}
423 427
424void EmitImageFetch([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 428void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
425 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord, 429 const IR::Value& coord, const IR::Value& offset, ScalarS32 lod, ScalarS32 ms) {
426 [[maybe_unused]] Register offset, [[maybe_unused]] Register lod, 430 const auto info{inst.Flags<IR::TextureInstInfo>()};
427 [[maybe_unused]] Register ms) { 431 const auto sparse_inst{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSparseFromOp)};
428 throw NotImplementedException("GLASM instruction"); 432 const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""};
433 const std::string_view type{TextureType(info)};
434 const std::string texture{Texture(ctx, info, index)};
435 const std::string offset_vec{Offset(ctx, offset)};
436 const auto [coord_vec, coord_alloc]{Coord(ctx, coord)};
437 const Register ret{ctx.reg_alloc.Define(inst)};
438 if (info.type == TextureType::Buffer) {
439 ctx.Add("TXF.F{} {},{},{},{}{};", sparse_mod, ret, coord_vec, texture, type, offset_vec);
440 } else if (ms.type != Type::Void) {
441 ctx.Add("MOV.S {}.w,{};"
442 "TXFMS.F{} {},{},{},{}{};",
443 coord_vec, ms, sparse_mod, ret, coord_vec, texture, type, offset_vec);
444 } else {
445 ctx.Add("MOV.S {}.w,{};"
446 "TXF.F{} {},{},{},{}{};",
447 coord_vec, lod, sparse_mod, ret, coord_vec, texture, type, offset_vec);
448 }
449 StoreSparse(ctx, sparse_inst);
429} 450}
430 451
431void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 452void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h
index 8a707d924..119b166af 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h
+++ b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h
@@ -541,8 +541,8 @@ void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
541void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 541void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
542 const IR::Value& coord, const IR::Value& offset, const IR::Value& offset2, 542 const IR::Value& coord, const IR::Value& offset, const IR::Value& offset2,
543 const IR::Value& dref); 543 const IR::Value& dref);
544void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord, 544void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
545 Register offset, Register lod, Register ms); 545 const IR::Value& coord, const IR::Value& offset, ScalarS32 lod, ScalarS32 ms);
546void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 546void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
547 ScalarF32 lod); 547 ScalarF32 lod);
548void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord); 548void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord);