summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-05-16 17:54:43 -0300
committerGravatar ameerj2021-07-22 21:51:31 -0400
commitbf2949df100d43f3d54ca74a028aa59678ba76c8 (patch)
treea7b43b8e7dd212c1e120468c7bcdf5638eba2566 /src/shader_recompiler/backend
parentemit_glasm: Enable ARB_draw_buffers when needed (diff)
downloadyuzu-bf2949df100d43f3d54ca74a028aa59678ba76c8.tar.gz
yuzu-bf2949df100d43f3d54ca74a028aa59678ba76c8.tar.xz
yuzu-bf2949df100d43f3d54ca74a028aa59678ba76c8.zip
glasm: Improve texture sampling instructions
Diffstat (limited to 'src/shader_recompiler/backend')
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm_image.cpp66
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm_instructions.h54
2 files changed, 70 insertions, 50 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp
index 4d146d34e..7f2cf052a 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp
@@ -112,24 +112,46 @@ static std::string Texture([[maybe_unused]] EmitContext& ctx, IR::TextureInstInf
112} 112}
113 113
114void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 114void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
115 Register coords, Register bias_lc, 115 const IR::Value& coord, Register bias_lc,
116 [[maybe_unused]] const IR::Value& offset) { 116 [[maybe_unused]] const IR::Value& offset) {
117 const auto info{inst.Flags<IR::TextureInstInfo>()}; 117 const auto info{inst.Flags<IR::TextureInstInfo>()};
118 const auto sparse_inst{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSparseFromOp)}; 118 const auto sparse_inst{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSparseFromOp)};
119 const std::string_view op{info.has_bias ? "TXB" : "TEX"};
120 const std::string_view lod_clamp{info.has_lod_clamp ? ".LODCLAMP" : ""};
121 const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""}; 119 const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""};
120 const std::string_view lod_clamp_mod{info.has_lod_clamp ? ".LODCLAMP" : ""};
121 const std::string_view type{"2D"}; // FIXME
122 const std::string texture{Texture(ctx, info, index)}; 122 const std::string texture{Texture(ctx, info, index)};
123
124 std::string coord_vec{fmt::to_string(Register{ctx.reg_alloc.Consume(coord)})};
125 if (coord.InstRecursive()->HasUses()) {
126 // Move non-dead coords to a separate register, although this should never happen because
127 // vectors are only assembled for immediate texture instructions
128 ctx.Add("MOV.F RC,{};", coord_vec);
129 coord_vec = "RC";
130 }
123 const Register ret{ctx.reg_alloc.Define(inst)}; 131 const Register ret{ctx.reg_alloc.Define(inst)};
124 // FIXME 132 if (info.has_bias) {
125 const bool separate{info.type == TextureType::ColorArrayCube}; 133 if (info.type == TextureType::ColorArrayCube) {
126 if (separate) { 134 ctx.Add("TXB.F{}{} {},{},{},{},ARRAYCUBE;", lod_clamp_mod, sparse_mod, ret, coord_vec,
127 ctx.Add("{}.F{}{} {},{},{},{},2D;", op, lod_clamp, sparse_mod, ret, coords, bias_lc, 135 bias_lc, texture);
128 texture); 136 } else {
137 if (info.has_lod_clamp) {
138 ctx.Add("MOV.F {}.w,{}.x;"
139 "TXB.F.LODCLAMP{} {},{},{}.y,{},{};",
140 coord_vec, bias_lc, sparse_mod, ret, coord_vec, bias_lc, texture, type);
141 } else {
142 ctx.Add("MOV.F {}.w,{}.x;"
143 "TXB.F{} {},{},{},{};",
144 coord_vec, bias_lc, sparse_mod, ret, coord_vec, texture, type);
145 }
146 }
129 } else { 147 } else {
130 ctx.Add("MOV.F {}.w,{}.x;" 148 if (info.has_lod_clamp && info.type == TextureType::ColorArrayCube) {
131 "{}.F{}{} {},{},{},2D;", 149 ctx.Add("TEX.F.LODCLAMP{} {},{},{},{},ARRAYCUBE;", sparse_mod, ret, coord_vec, bias_lc,
132 coords, bias_lc, op, lod_clamp, sparse_mod, ret, coords, texture); 150 texture);
151 } else {
152 ctx.Add("TEX.F{}{} {},{},{},{};", lod_clamp_mod, sparse_mod, ret, coord_vec, texture,
153 type);
154 }
133 } 155 }
134 if (sparse_inst) { 156 if (sparse_inst) {
135 const Register sparse_ret{ctx.reg_alloc.Define(*sparse_inst)}; 157 const Register sparse_ret{ctx.reg_alloc.Define(*sparse_inst)};
@@ -142,7 +164,7 @@ void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Valu
142 164
143void EmitImageSampleExplicitLod([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 165void EmitImageSampleExplicitLod([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
144 [[maybe_unused]] const IR::Value& index, 166 [[maybe_unused]] const IR::Value& index,
145 [[maybe_unused]] Register coords, [[maybe_unused]] Register lod_lc, 167 [[maybe_unused]] Register coord, [[maybe_unused]] Register lod_lc,
146 [[maybe_unused]] const IR::Value& offset) { 168 [[maybe_unused]] const IR::Value& offset) {
147 throw NotImplementedException("GLASM instruction"); 169 throw NotImplementedException("GLASM instruction");
148} 170}
@@ -150,8 +172,7 @@ void EmitImageSampleExplicitLod([[maybe_unused]] EmitContext& ctx, [[maybe_unuse
150void EmitImageSampleDrefImplicitLod([[maybe_unused]] EmitContext& ctx, 172void EmitImageSampleDrefImplicitLod([[maybe_unused]] EmitContext& ctx,
151 [[maybe_unused]] IR::Inst& inst, 173 [[maybe_unused]] IR::Inst& inst,
152 [[maybe_unused]] const IR::Value& index, 174 [[maybe_unused]] const IR::Value& index,
153 [[maybe_unused]] Register coords, 175 [[maybe_unused]] Register coord, [[maybe_unused]] Register dref,
154 [[maybe_unused]] Register dref,
155 [[maybe_unused]] Register bias_lc, 176 [[maybe_unused]] Register bias_lc,
156 [[maybe_unused]] const IR::Value& offset) { 177 [[maybe_unused]] const IR::Value& offset) {
157 throw NotImplementedException("GLASM instruction"); 178 throw NotImplementedException("GLASM instruction");
@@ -160,22 +181,21 @@ void EmitImageSampleDrefImplicitLod([[maybe_unused]] EmitContext& ctx,
160void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx, 181void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx,
161 [[maybe_unused]] IR::Inst& inst, 182 [[maybe_unused]] IR::Inst& inst,
162 [[maybe_unused]] const IR::Value& index, 183 [[maybe_unused]] const IR::Value& index,
163 [[maybe_unused]] Register coords, 184 [[maybe_unused]] Register coord, [[maybe_unused]] Register dref,
164 [[maybe_unused]] Register dref,
165 [[maybe_unused]] Register lod_lc, 185 [[maybe_unused]] Register lod_lc,
166 [[maybe_unused]] const IR::Value& offset) { 186 [[maybe_unused]] const IR::Value& offset) {
167 throw NotImplementedException("GLASM instruction"); 187 throw NotImplementedException("GLASM instruction");
168} 188}
169 189
170void EmitImageGather([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 190void EmitImageGather([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
171 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coords, 191 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord,
172 [[maybe_unused]] const IR::Value& offset, 192 [[maybe_unused]] const IR::Value& offset,
173 [[maybe_unused]] const IR::Value& offset2) { 193 [[maybe_unused]] const IR::Value& offset2) {
174 throw NotImplementedException("GLASM instruction"); 194 throw NotImplementedException("GLASM instruction");
175} 195}
176 196
177void EmitImageGatherDref([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 197void EmitImageGatherDref([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
178 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coords, 198 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord,
179 [[maybe_unused]] const IR::Value& offset, 199 [[maybe_unused]] const IR::Value& offset,
180 [[maybe_unused]] const IR::Value& offset2, 200 [[maybe_unused]] const IR::Value& offset2,
181 [[maybe_unused]] Register dref) { 201 [[maybe_unused]] Register dref) {
@@ -183,7 +203,7 @@ void EmitImageGatherDref([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR:
183} 203}
184 204
185void EmitImageFetch([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 205void EmitImageFetch([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
186 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coords, 206 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord,
187 [[maybe_unused]] Register offset, [[maybe_unused]] Register lod, 207 [[maybe_unused]] Register offset, [[maybe_unused]] Register lod,
188 [[maybe_unused]] Register ms) { 208 [[maybe_unused]] Register ms) {
189 throw NotImplementedException("GLASM instruction"); 209 throw NotImplementedException("GLASM instruction");
@@ -196,24 +216,24 @@ void EmitImageQueryDimensions([[maybe_unused]] EmitContext& ctx, [[maybe_unused]
196} 216}
197 217
198void EmitImageQueryLod([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 218void EmitImageQueryLod([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
199 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coords) { 219 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord) {
200 throw NotImplementedException("GLASM instruction"); 220 throw NotImplementedException("GLASM instruction");
201} 221}
202 222
203void EmitImageGradient([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 223void EmitImageGradient([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
204 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coords, 224 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord,
205 [[maybe_unused]] Register derivates, [[maybe_unused]] Register offset, 225 [[maybe_unused]] Register derivates, [[maybe_unused]] Register offset,
206 [[maybe_unused]] Register lod_clamp) { 226 [[maybe_unused]] Register lod_clamp) {
207 throw NotImplementedException("GLASM instruction"); 227 throw NotImplementedException("GLASM instruction");
208} 228}
209 229
210void EmitImageRead([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 230void EmitImageRead([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
211 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coords) { 231 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord) {
212 throw NotImplementedException("GLASM instruction"); 232 throw NotImplementedException("GLASM instruction");
213} 233}
214 234
215void EmitImageWrite([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 235void EmitImageWrite([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
216 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coords, 236 [[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord,
217 [[maybe_unused]] Register color) { 237 [[maybe_unused]] Register color) {
218 throw NotImplementedException("GLASM instruction"); 238 throw NotImplementedException("GLASM instruction");
219} 239}
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h
index ad640bcb9..a128f9ac4 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h
+++ b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h
@@ -525,28 +525,28 @@ void EmitBoundImageGradient(EmitContext&);
525void EmitBoundImageRead(EmitContext&); 525void EmitBoundImageRead(EmitContext&);
526void EmitBoundImageWrite(EmitContext&); 526void EmitBoundImageWrite(EmitContext&);
527void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 527void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
528 Register coords, Register bias_lc, const IR::Value& offset); 528 const IR::Value& coord, Register bias_lc, const IR::Value& offset);
529void EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 529void EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
530 Register coords, Register lod_lc, const IR::Value& offset); 530 Register coord, Register lod_lc, const IR::Value& offset);
531void EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 531void EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
532 Register coords, Register dref, Register bias_lc, 532 Register coord, Register dref, Register bias_lc,
533 const IR::Value& offset); 533 const IR::Value& offset);
534void EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 534void EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
535 Register coords, Register dref, Register lod_lc, 535 Register coord, Register dref, Register lod_lc,
536 const IR::Value& offset); 536 const IR::Value& offset);
537void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 537void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
538 const IR::Value& offset, const IR::Value& offset2); 538 const IR::Value& offset, const IR::Value& offset2);
539void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 539void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
540 const IR::Value& offset, const IR::Value& offset2, Register dref); 540 const IR::Value& offset, const IR::Value& offset2, Register dref);
541void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 541void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
542 Register offset, Register lod, Register ms); 542 Register offset, Register lod, Register ms);
543void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 543void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
544 Register lod); 544 Register lod);
545void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords); 545void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord);
546void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 546void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
547 Register derivates, Register offset, Register lod_clamp); 547 Register derivates, Register offset, Register lod_clamp);
548void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords); 548void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord);
549void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 549void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
550 Register color); 550 Register color);
551void EmitBindlessImageAtomicIAdd32(EmitContext&); 551void EmitBindlessImageAtomicIAdd32(EmitContext&);
552void EmitBindlessImageAtomicSMin32(EmitContext&); 552void EmitBindlessImageAtomicSMin32(EmitContext&);
@@ -570,28 +570,28 @@ void EmitBoundImageAtomicAnd32(EmitContext&);
570void EmitBoundImageAtomicOr32(EmitContext&); 570void EmitBoundImageAtomicOr32(EmitContext&);
571void EmitBoundImageAtomicXor32(EmitContext&); 571void EmitBoundImageAtomicXor32(EmitContext&);
572void EmitBoundImageAtomicExchange32(EmitContext&); 572void EmitBoundImageAtomicExchange32(EmitContext&);
573void EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 573void EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
574 Register coords, ScalarU32 value); 574 ScalarU32 value);
575void EmitImageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 575void EmitImageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
576 Register coords, ScalarS32 value); 576 ScalarS32 value);
577void EmitImageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 577void EmitImageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
578 Register coords, ScalarU32 value); 578 ScalarU32 value);
579void EmitImageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 579void EmitImageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
580 Register coords, ScalarS32 value); 580 ScalarS32 value);
581void EmitImageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 581void EmitImageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
582 Register coords, ScalarU32 value); 582 ScalarU32 value);
583void EmitImageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 583void EmitImageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
584 ScalarU32 value); 584 ScalarU32 value);
585void EmitImageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 585void EmitImageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
586 ScalarU32 value); 586 ScalarU32 value);
587void EmitImageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 587void EmitImageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
588 ScalarU32 value); 588 ScalarU32 value);
589void EmitImageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 589void EmitImageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
590 ScalarU32 value); 590 ScalarU32 value);
591void EmitImageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coords, 591void EmitImageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
592 ScalarU32 value); 592 ScalarU32 value);
593void EmitImageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, 593void EmitImageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
594 Register coords, ScalarU32 value); 594 Register coord, ScalarU32 value);
595void EmitLaneId(EmitContext& ctx, IR::Inst& inst); 595void EmitLaneId(EmitContext& ctx, IR::Inst& inst);
596void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, ScalarS32 pred); 596void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, ScalarS32 pred);
597void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, ScalarS32 pred); 597void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, ScalarS32 pred);