diff options
| author | 2023-08-18 18:30:31 +0200 | |
|---|---|---|
| committer | 2023-08-18 22:17:02 -0400 | |
| commit | c03f0b3c893f2bc2ae4f1e1825c5ac1453c36710 (patch) | |
| tree | 3f7f14fad6574878a7c0f94fbe16d574b61cb95a /src/shader_recompiler/backend | |
| parent | Merge pull request #11278 from Kelebek1/dma_sync (diff) | |
| download | yuzu-c03f0b3c893f2bc2ae4f1e1825c5ac1453c36710.tar.gz yuzu-c03f0b3c893f2bc2ae4f1e1825c5ac1453c36710.tar.xz yuzu-c03f0b3c893f2bc2ae4f1e1825c5ac1453c36710.zip | |
Shader Recomnpiler: implement textuzreGrad 3D emulation constant propagation
Diffstat (limited to 'src/shader_recompiler/backend')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm_image.cpp | 23 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_image.cpp | 8 |
2 files changed, 26 insertions, 5 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp index 85ee27333..d0e308124 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp | |||
| @@ -558,12 +558,15 @@ void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 558 | const IR::Value& coord, const IR::Value& derivatives, | 558 | const IR::Value& coord, const IR::Value& derivatives, |
| 559 | const IR::Value& offset, const IR::Value& lod_clamp) { | 559 | const IR::Value& offset, const IR::Value& lod_clamp) { |
| 560 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | 560 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 561 | ScopedRegister dpdx, dpdy; | 561 | ScopedRegister dpdx, dpdy, coords; |
| 562 | const bool multi_component{info.num_derivates > 1 || info.has_lod_clamp}; | 562 | const bool multi_component{info.num_derivates > 1 || info.has_lod_clamp}; |
| 563 | if (multi_component) { | 563 | if (multi_component) { |
| 564 | // Allocate this early to avoid aliasing other registers | 564 | // Allocate this early to avoid aliasing other registers |
| 565 | dpdx = ScopedRegister{ctx.reg_alloc}; | 565 | dpdx = ScopedRegister{ctx.reg_alloc}; |
| 566 | dpdy = ScopedRegister{ctx.reg_alloc}; | 566 | dpdy = ScopedRegister{ctx.reg_alloc}; |
| 567 | if (info.num_derivates >= 3) { | ||
| 568 | coords = ScopedRegister{ctx.reg_alloc}; | ||
| 569 | } | ||
| 567 | } | 570 | } |
| 568 | const auto sparse_inst{PrepareSparse(inst)}; | 571 | const auto sparse_inst{PrepareSparse(inst)}; |
| 569 | const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""}; | 572 | const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""}; |
| @@ -580,15 +583,27 @@ void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 580 | "MOV.F {}.y,{}.w;", | 583 | "MOV.F {}.y,{}.w;", |
| 581 | dpdx.reg, derivatives_vec, dpdx.reg, derivatives_vec, dpdy.reg, derivatives_vec, | 584 | dpdx.reg, derivatives_vec, dpdx.reg, derivatives_vec, dpdy.reg, derivatives_vec, |
| 582 | dpdy.reg, derivatives_vec); | 585 | dpdy.reg, derivatives_vec); |
| 586 | Register final_coord; | ||
| 587 | if (info.num_derivates >= 3) { | ||
| 588 | ctx.Add("MOV.F {}.z,{}.x;" | ||
| 589 | "MOV.F {}.z,{}.y;", | ||
| 590 | dpdx.reg, coord_vec, dpdy.reg, coord_vec); | ||
| 591 | ctx.Add("MOV.F {}.x,0;" | ||
| 592 | "MOV.F {}.y,0;", | ||
| 593 | "MOV.F {}.z,0;", coords.reg, coords.reg, coords.reg); | ||
| 594 | final_coord = coords.reg; | ||
| 595 | } else { | ||
| 596 | final_coord = coord_vec; | ||
| 597 | } | ||
| 583 | if (info.has_lod_clamp) { | 598 | if (info.has_lod_clamp) { |
| 584 | const ScalarF32 lod_clamp_value{ctx.reg_alloc.Consume(lod_clamp)}; | 599 | const ScalarF32 lod_clamp_value{ctx.reg_alloc.Consume(lod_clamp)}; |
| 585 | ctx.Add("MOV.F {}.w,{};" | 600 | ctx.Add("MOV.F {}.w,{};" |
| 586 | "TXD.F.LODCLAMP{} {},{},{},{},{},{}{};", | 601 | "TXD.F.LODCLAMP{} {},{},{},{},{},{}{};", |
| 587 | dpdy.reg, lod_clamp_value, sparse_mod, ret, coord_vec, dpdx.reg, dpdy.reg, | 602 | dpdy.reg, lod_clamp_value, sparse_mod, ret, final_coord, dpdx.reg, dpdy.reg, |
| 588 | texture, type, offset_vec); | 603 | texture, type, offset_vec); |
| 589 | } else { | 604 | } else { |
| 590 | ctx.Add("TXD.F{} {},{},{},{},{},{}{};", sparse_mod, ret, coord_vec, dpdx.reg, dpdy.reg, | 605 | ctx.Add("TXD.F{} {},{},{},{},{},{}{};", sparse_mod, ret, final_coord, dpdx.reg, |
| 591 | texture, type, offset_vec); | 606 | dpdy.reg, texture, type, offset_vec); |
| 592 | } | 607 | } |
| 593 | } else { | 608 | } else { |
| 594 | ctx.Add("TXD.F{} {},{},{}.x,{}.y,{},{}{};", sparse_mod, ret, coord_vec, derivatives_vec, | 609 | ctx.Add("TXD.F{} {},{},{}.x,{}.y,{},{}{};", sparse_mod, ret, coord_vec, derivatives_vec, |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp index 418505475..3ad668a47 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp | |||
| @@ -548,7 +548,7 @@ void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 548 | if (sparse_inst) { | 548 | if (sparse_inst) { |
| 549 | throw NotImplementedException("EmitImageGradient Sparse"); | 549 | throw NotImplementedException("EmitImageGradient Sparse"); |
| 550 | } | 550 | } |
| 551 | if (!offset.IsEmpty()) { | 551 | if (!offset.IsEmpty() && info.num_derivates <= 2) { |
| 552 | throw NotImplementedException("EmitImageGradient offset"); | 552 | throw NotImplementedException("EmitImageGradient offset"); |
| 553 | } | 553 | } |
| 554 | const auto texture{Texture(ctx, info, index)}; | 554 | const auto texture{Texture(ctx, info, index)}; |
| @@ -556,6 +556,12 @@ void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 556 | const bool multi_component{info.num_derivates > 1 || info.has_lod_clamp}; | 556 | const bool multi_component{info.num_derivates > 1 || info.has_lod_clamp}; |
| 557 | const auto derivatives_vec{ctx.var_alloc.Consume(derivatives)}; | 557 | const auto derivatives_vec{ctx.var_alloc.Consume(derivatives)}; |
| 558 | if (multi_component) { | 558 | if (multi_component) { |
| 559 | if (info.num_derivates >= 3) { | ||
| 560 | const auto offset_vec{ctx.var_alloc.Consume(offset)}; | ||
| 561 | ctx.Add("{}=textureGrad({},{},vec3({}.xz, {}.x),vec3({}.yz, {}.y));", texel, texture, | ||
| 562 | coords, derivatives_vec, offset_vec, derivatives_vec, offset_vec); | ||
| 563 | return; | ||
| 564 | } | ||
| 559 | ctx.Add("{}=textureGrad({},{},vec2({}.xz),vec2({}.yz));", texel, texture, coords, | 565 | ctx.Add("{}=textureGrad({},{},vec2({}.xz),vec2({}.yz));", texel, texture, coords, |
| 560 | derivatives_vec, derivatives_vec); | 566 | derivatives_vec, derivatives_vec); |
| 561 | } else { | 567 | } else { |