summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/ir_opt/texture_pass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/ir_opt/texture_pass.cpp')
-rw-r--r--src/shader_recompiler/ir_opt/texture_pass.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/shader_recompiler/ir_opt/texture_pass.cpp b/src/shader_recompiler/ir_opt/texture_pass.cpp
index ca3e306e8..5cead5135 100644
--- a/src/shader_recompiler/ir_opt/texture_pass.cpp
+++ b/src/shader_recompiler/ir_opt/texture_pass.cpp
@@ -362,6 +362,21 @@ private:
362 TextureDescriptors& texture_descriptors; 362 TextureDescriptors& texture_descriptors;
363 ImageDescriptors& image_descriptors; 363 ImageDescriptors& image_descriptors;
364}; 364};
365
366void PatchImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) {
367 IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
368 const auto info{inst.Flags<IR::TextureInstInfo>()};
369 const IR::Value coord(inst.Arg(1));
370 const IR::Value handle(ir.Imm32(0));
371 const IR::U32 lod{ir.Imm32(0)};
372 const IR::Value texture_size = ir.ImageQueryDimension(handle, lod, info);
373 inst.SetArg(
374 1, ir.CompositeConstruct(
375 ir.FPMul(IR::F32(ir.CompositeExtract(coord, 0)),
376 ir.FPRecip(ir.ConvertUToF(32, 32, ir.CompositeExtract(texture_size, 0)))),
377 ir.FPMul(IR::F32(ir.CompositeExtract(coord, 1)),
378 ir.FPRecip(ir.ConvertUToF(32, 32, ir.CompositeExtract(texture_size, 1))))));
379}
365} // Anonymous namespace 380} // Anonymous namespace
366 381
367void TexturePass(Environment& env, IR::Program& program) { 382void TexturePass(Environment& env, IR::Program& program) {
@@ -399,6 +414,14 @@ void TexturePass(Environment& env, IR::Program& program) {
399 flags.type.Assign(ReadTextureType(env, cbuf)); 414 flags.type.Assign(ReadTextureType(env, cbuf));
400 inst->SetFlags(flags); 415 inst->SetFlags(flags);
401 break; 416 break;
417 case IR::Opcode::ImageSampleImplicitLod:
418 if (flags.type == TextureType::Color2D) {
419 auto texture_type = ReadTextureType(env, cbuf);
420 if (texture_type == TextureType::Color2DRect) {
421 PatchImageSampleImplicitLod(*texture_inst.block, *texture_inst.inst);
422 }
423 }
424 break;
402 case IR::Opcode::ImageFetch: 425 case IR::Opcode::ImageFetch:
403 if (flags.type != TextureType::Color1D) { 426 if (flags.type != TextureType::Color1D) {
404 break; 427 break;