summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fernando S2023-12-22 17:41:13 +0100
committerGravatar GitHub2023-12-22 17:41:13 +0100
commit820f113d9ee0d76d0f5575eec20283a3041b8d5b (patch)
tree778049e5d7d58d8980f190d8a81b254328f27be0
parentMerge pull request #12410 from liamwhite/more-mali-null (diff)
parentshader_recompiler: ensure derivatives for textureGrad are f32 (diff)
downloadyuzu-820f113d9ee0d76d0f5575eec20283a3041b8d5b.tar.gz
yuzu-820f113d9ee0d76d0f5575eec20283a3041b8d5b.tar.xz
yuzu-820f113d9ee0d76d0f5575eec20283a3041b8d5b.zip
Merge pull request #12435 from liamwhite/type-check
shader_recompiler: ensure derivatives for textureGrad are f32
-rw-r--r--src/shader_recompiler/ir_opt/constant_propagation_pass.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp
index ec12c843a..e4a73a360 100644
--- a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp
+++ b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp
@@ -815,6 +815,15 @@ bool FindGradient3DDerivatives(std::array<IR::Value, 3>& results, IR::Value coor
815 return true; 815 return true;
816} 816}
817 817
818void ConvertDerivatives(std::array<IR::Value, 3>& results, IR::IREmitter& ir) {
819 for (size_t i = 0; i < 3; i++) {
820 if (results[i].Type() == IR::Type::U32) {
821 results[i] = results[i].IsImmediate() ? ir.Imm32(Common::BitCast<f32>(results[i].U32()))
822 : ir.BitCast<IR::F32>(IR::U32(results[i]));
823 }
824 }
825}
826
818void FoldImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) { 827void FoldImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) {
819 IR::TextureInstInfo info = inst.Flags<IR::TextureInstInfo>(); 828 IR::TextureInstInfo info = inst.Flags<IR::TextureInstInfo>();
820 auto orig_opcode = inst.GetOpcode(); 829 auto orig_opcode = inst.GetOpcode();
@@ -831,12 +840,14 @@ void FoldImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) {
831 if (!offset.IsImmediate()) { 840 if (!offset.IsImmediate()) {
832 return; 841 return;
833 } 842 }
843 IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
834 IR::Inst* const inst2 = coords.InstRecursive(); 844 IR::Inst* const inst2 = coords.InstRecursive();
835 std::array<std::array<IR::Value, 3>, 3> results_matrix; 845 std::array<std::array<IR::Value, 3>, 3> results_matrix;
836 for (size_t i = 0; i < 3; i++) { 846 for (size_t i = 0; i < 3; i++) {
837 if (!FindGradient3DDerivatives(results_matrix[i], inst2->Arg(i).Resolve())) { 847 if (!FindGradient3DDerivatives(results_matrix[i], inst2->Arg(i).Resolve())) {
838 return; 848 return;
839 } 849 }
850 ConvertDerivatives(results_matrix[i], ir);
840 } 851 }
841 IR::F32 lod_clamp{}; 852 IR::F32 lod_clamp{};
842 if (info.has_lod_clamp != 0) { 853 if (info.has_lod_clamp != 0) {
@@ -846,7 +857,6 @@ void FoldImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) {
846 lod_clamp = IR::F32{bias_lc}; 857 lod_clamp = IR::F32{bias_lc};
847 } 858 }
848 } 859 }
849 IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
850 IR::Value new_coords = 860 IR::Value new_coords =
851 ir.CompositeConstruct(results_matrix[0][0], results_matrix[1][0], results_matrix[2][0]); 861 ir.CompositeConstruct(results_matrix[0][0], results_matrix[1][0], results_matrix[2][0]);
852 IR::Value derivatives_1 = ir.CompositeConstruct(results_matrix[0][1], results_matrix[0][2], 862 IR::Value derivatives_1 = ir.CompositeConstruct(results_matrix[0][1], results_matrix[0][2],