summaryrefslogtreecommitdiff
path: root/src/video_core/shader/decode
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/video_core/shader/decode
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/video_core/shader/decode')
-rw-r--r--src/video_core/shader/decode/memory.cpp69
1 files changed, 61 insertions, 8 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) {