summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2018-12-23 01:18:33 -0300
committerGravatar ReinUsesLisp2019-01-15 17:54:52 -0300
commit55e6786254d33e3501002bf7fbdd52552a0df32a (patch)
treec4d516419aff5dfa35c1de13efa77294afc50e16 /src
parentshader_decode: Update TLD4 reflecting #1862 changes (diff)
downloadyuzu-55e6786254d33e3501002bf7fbdd52552a0df32a.tar.gz
yuzu-55e6786254d33e3501002bf7fbdd52552a0df32a.tar.xz
yuzu-55e6786254d33e3501002bf7fbdd52552a0df32a.zip
shader_decode: Implement TLDS (untested)
Diffstat (limited to 'src')
-rw-r--r--src/video_core/shader/decode/memory.cpp69
-rw-r--r--src/video_core/shader/glsl_decompiler.cpp29
-rw-r--r--src/video_core/shader/shader_ir.h4
3 files changed, 92 insertions, 10 deletions
diff --git a/src/video_core/shader/decode/memory.cpp b/src/video_core/shader/decode/memory.cpp
index cfdb92807..ce3445512 100644
--- a/src/video_core/shader/decode/memory.cpp
+++ b/src/video_core/shader/decode/memory.cpp
@@ -204,7 +204,7 @@ u32 ShaderIR::DecodeMemory(BasicBlock& bb, u32 pc) {
204 break; 204 break;
205 } 205 }
206 case OpCode::Id::TEXS: { 206 case OpCode::Id::TEXS: {
207 Tegra::Shader::TextureType texture_type{instr.texs.GetTextureType()}; 207 const TextureType texture_type{instr.texs.GetTextureType()};
208 const bool is_array{instr.texs.IsArrayTexture()}; 208 const bool is_array{instr.texs.IsArrayTexture()};
209 const bool depth_compare = instr.texs.UsesMiscMode(TextureMiscMode::DC); 209 const bool depth_compare = instr.texs.UsesMiscMode(TextureMiscMode::DC);
210 const auto process_mode = instr.texs.GetTextureProcessMode(); 210 const auto process_mode = instr.texs.GetTextureProcessMode();
@@ -373,6 +373,22 @@ u32 ShaderIR::DecodeMemory(BasicBlock& bb, u32 pc) {
373 GetRegister(RZ), GetRegister(RZ))); 373 GetRegister(RZ), GetRegister(RZ)));
374 break; 374 break;
375 } 375 }
376 case OpCode::Id::TLDS: {
377 const Tegra::Shader::TextureType texture_type{instr.tlds.GetTextureType()};
378 const bool is_array{instr.tlds.IsArrayTexture()};
379
380 UNIMPLEMENTED_IF_MSG(instr.tlds.UsesMiscMode(TextureMiscMode::AOFFI),
381 "AOFFI is not implemented");
382 UNIMPLEMENTED_IF_MSG(instr.tlds.UsesMiscMode(TextureMiscMode::MZ), "MZ is not implemented");
383
384 if (instr.tlds.UsesMiscMode(TextureMiscMode::NODEP)) {
385 LOG_WARNING(HW_GPU, "TMML.NODEP implementation is incomplete");
386 }
387
388 const Node texture = GetTldsCode(instr, texture_type, is_array);
389 WriteTexsInstructionFloat(bb, instr, texture);
390 break;
391 }
376 default: 392 default:
377 UNIMPLEMENTED_MSG("Unhandled memory instruction: {}", opcode->get().GetName()); 393 UNIMPLEMENTED_MSG("Unhandled memory instruction: {}", opcode->get().GetName());
378 } 394 }
@@ -576,22 +592,59 @@ Node ShaderIR::GetTld4Code(Instruction instr, TextureType texture_type, bool dep
576 for (size_t i = 0; i < coord_count; ++i) { 592 for (size_t i = 0; i < coord_count; ++i) {
577 params.push_back(GetRegister(coord_register + i)); 593 params.push_back(GetRegister(coord_register + i));
578 } 594 }
579 std::size_t array_offset{}; 595 std::optional<u32> array_offset;
580 if (is_array) { 596 if (is_array) {
581 array_offset = params.size(); 597 array_offset = static_cast<u32>(params.size());
582 params.push_back(GetRegister(array_register)); 598 params.push_back(GetRegister(array_register));
583 } 599 }
584 600
585 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, depth_compare); 601 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, depth_compare);
586 602 MetaTexture meta{sampler, static_cast<u32>(params.size()), array_offset};
587 std::optional<u32> array_offset_value;
588 if (is_array)
589 array_offset_value = static_cast<u32>(array_offset);
590 MetaTexture meta{sampler, static_cast<u32>(params.size()), array_offset_value};
591 603
592 return Operation(OperationCode::F4TextureGather, std::move(meta), std::move(params)); 604 return Operation(OperationCode::F4TextureGather, std::move(meta), std::move(params));
593} 605}
594 606
607Node ShaderIR::GetTldsCode(Instruction instr, TextureType texture_type, bool is_array) {
608 const std::size_t type_coord_count = GetCoordCount(texture_type);
609 const std::size_t total_coord_count = type_coord_count + (is_array ? 1 : 0);
610 const bool lod_enabled = instr.tlds.GetTextureProcessMode() == TextureProcessMode::LL;
611
612 // If enabled arrays index is always stored in the gpr8 field
613 const u64 array_register = instr.gpr8.Value();
614 // if is array gpr20 is used
615 const u64 coord_register = is_array ? instr.gpr20.Value() : instr.gpr8.Value();
616
617 const u64 last_coord_register =
618 ((type_coord_count > 2) || (type_coord_count == 2 && !lod_enabled)) && !is_array
619 ? static_cast<u64>(instr.gpr20.Value())
620 : coord_register + 1;
621
622 std::vector<Node> params;
623
624 for (std::size_t i = 0; i < type_coord_count; ++i) {
625 const bool last = (i == (type_coord_count - 1)) && (type_coord_count > 1);
626 params.push_back(GetRegister(last ? last_coord_register : coord_register + i));
627 }
628 std::optional<u32> array_offset;
629 if (is_array) {
630 array_offset = static_cast<u32>(params.size());
631 params.push_back(GetRegister(array_register));
632 }
633 const auto coords_count = static_cast<u32>(params.size());
634
635 if (lod_enabled) {
636 // When lod is used always is in grp20
637 params.push_back(GetRegister(instr.gpr20));
638 } else {
639 params.push_back(Immediate(0));
640 }
641
642 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, false);
643 MetaTexture meta{sampler, coords_count, array_offset};
644
645 return Operation(OperationCode::F4TexelFetch, std::move(meta), std::move(params));
646}
647
595std::tuple<std::size_t, std::size_t> ShaderIR::ValidateAndGetCoordinateElement( 648std::tuple<std::size_t, std::size_t> ShaderIR::ValidateAndGetCoordinateElement(
596 TextureType texture_type, bool depth_compare, bool is_array, bool lod_bias_enabled, 649 TextureType texture_type, bool depth_compare, bool is_array, bool lod_bias_enabled,
597 std::size_t max_coords, std::size_t max_inputs) { 650 std::size_t max_coords, std::size_t max_inputs) {
diff --git a/src/video_core/shader/glsl_decompiler.cpp b/src/video_core/shader/glsl_decompiler.cpp
index a513c0c4b..b93ea9ec6 100644
--- a/src/video_core/shader/glsl_decompiler.cpp
+++ b/src/video_core/shader/glsl_decompiler.cpp
@@ -635,8 +635,6 @@ private:
635 result_type)); 635 result_type));
636 } 636 }
637 637
638#pragma optimize("", off)
639
640 std::string GenerateTexture(Operation operation, const std::string& func, 638 std::string GenerateTexture(Operation operation, const std::string& func,
641 std::string extra_cast(std::string) = nullptr) { 639 std::string extra_cast(std::string) = nullptr) {
642 constexpr std::array<const char*, 4> coord_constructors = {"float", "vec2", "vec3", "vec4"}; 640 constexpr std::array<const char*, 4> coord_constructors = {"float", "vec2", "vec3", "vec4"};
@@ -1100,6 +1098,32 @@ private:
1100 return "vec4(itof(int(" + tmp + ".y)), utof(uint(" + tmp + ".x)), 0, 0)"; 1098 return "vec4(itof(int(" + tmp + ".y)), utof(uint(" + tmp + ".x)), 0, 0)";
1101 } 1099 }
1102 1100
1101 std::string F4TexelFetch(Operation operation) {
1102 constexpr std::array<const char*, 4> constructors = {"int", "ivec2", "ivec3", "ivec4"};
1103 const auto& meta = std::get<MetaTexture>(operation.GetMeta());
1104 const auto count = static_cast<u32>(operation.GetOperandsCount());
1105
1106 std::string expr = "texelFetch(";
1107 expr += GetSampler(meta.sampler);
1108 expr += ", ";
1109
1110 expr += constructors[meta.coords_count - 1];
1111 expr += '(';
1112 for (u32 i = 0; i < count; ++i) {
1113 expr += VisitOperand(operation, i, Type::Int);
1114 expr += ", ";
1115
1116 if (i + 1 == meta.coords_count) {
1117 expr += ')';
1118 }
1119 if (i + 1 < count) {
1120 expr += ", ";
1121 }
1122 }
1123 expr += ')';
1124 return expr;
1125 }
1126
1103 std::string Ipa(Operation operation) { 1127 std::string Ipa(Operation operation) {
1104 const auto& attribute = operation[0]; 1128 const auto& attribute = operation[0];
1105 // TODO(Rodrigo): Special IPA attribute interactions 1129 // TODO(Rodrigo): Special IPA attribute interactions
@@ -1314,6 +1338,7 @@ private:
1314 &F4TextureGather, 1338 &F4TextureGather,
1315 &F4TextureQueryDimensions, 1339 &F4TextureQueryDimensions,
1316 &F4TextureQueryLod, 1340 &F4TextureQueryLod,
1341 &F4TexelFetch,
1317 1342
1318 &Ipa, 1343 &Ipa,
1319 1344
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h
index 691bd6d72..231f58f6a 100644
--- a/src/video_core/shader/shader_ir.h
+++ b/src/video_core/shader/shader_ir.h
@@ -154,6 +154,7 @@ enum class OperationCode {
154 F4TextureGather, /// (MetaTexture, float[N] coords, float[M] params) -> float4 154 F4TextureGather, /// (MetaTexture, float[N] coords, float[M] params) -> float4
155 F4TextureQueryDimensions, /// (MetaTexture, float a) -> float4 155 F4TextureQueryDimensions, /// (MetaTexture, float a) -> float4
156 F4TextureQueryLod, /// (MetaTexture, float[N] coords) -> float4 156 F4TextureQueryLod, /// (MetaTexture, float[N] coords) -> float4
157 F4TexelFetch, /// (MetaTexture, int[N], int) -> float4
157 158
158 Ipa, /// (abuf src) -> float 159 Ipa, /// (abuf src) -> float
159 160
@@ -694,6 +695,9 @@ private:
694 Node GetTld4Code(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type, 695 Node GetTld4Code(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
695 bool depth_compare, bool is_array); 696 bool depth_compare, bool is_array);
696 697
698 Node GetTldsCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
699 bool is_array);
700
697 std::tuple<std::size_t, std::size_t> ValidateAndGetCoordinateElement( 701 std::tuple<std::size_t, std::size_t> ValidateAndGetCoordinateElement(
698 Tegra::Shader::TextureType texture_type, bool depth_compare, bool is_array, 702 Tegra::Shader::TextureType texture_type, bool depth_compare, bool is_array,
699 bool lod_bias_enabled, std::size_t max_coords, std::size_t max_inputs); 703 bool lod_bias_enabled, std::size_t max_coords, std::size_t max_inputs);