From ec98e4d842d5ba04b329c866f5c9b1e7314069f2 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sun, 23 Dec 2018 00:38:01 -0300 Subject: [PATCH] shader_decode: Update TLD4 reflecting #1862 changes --- src/video_core/shader/decode/memory.cpp | 101 ++++++++++++------------ src/video_core/shader/shader_ir.h | 3 + 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/video_core/shader/decode/memory.cpp b/src/video_core/shader/decode/memory.cpp index 500a32af5..cfdb92807 100644 --- a/src/video_core/shader/decode/memory.cpp +++ b/src/video_core/shader/decode/memory.cpp @@ -225,7 +225,6 @@ u32 ShaderIR::DecodeMemory(BasicBlock& bb, u32 pc) { break; } case OpCode::Id::TLD4: { - ASSERT(instr.tld4.texture_type == Tegra::Shader::TextureType::Texture2D); ASSERT(instr.tld4.array == 0); UNIMPLEMENTED_IF_MSG(instr.tld4.UsesMiscMode(TextureMiscMode::AOFFI), "AOFFI is not implemented"); @@ -238,63 +237,29 @@ u32 ShaderIR::DecodeMemory(BasicBlock& bb, u32 pc) { LOG_WARNING(HW_GPU, "TLD4.NODEP implementation is incomplete"); } + const auto texture_type = instr.tld4.texture_type.Value(); const bool depth_compare = instr.tld4.UsesMiscMode(TextureMiscMode::DC); - auto texture_type = instr.tld4.texture_type.Value(); - u32 num_coordinates = static_cast(GetCoordCount(texture_type)); - if (depth_compare) - num_coordinates += 1; + const bool is_array = instr.tld4.array != 0; + const Node texture = GetTld4Code(instr, texture_type, depth_compare, is_array); - std::vector params; + MetaComponents meta_components; + std::array dest; - switch (num_coordinates) { - case 2: { - params.push_back(GetRegister(instr.gpr8)); - params.push_back(GetRegister(instr.gpr8.Value() + 1)); - break; - } - case 3: { - params.push_back(GetRegister(instr.gpr8)); - params.push_back(GetRegister(instr.gpr8.Value() + 1)); - params.push_back(GetRegister(instr.gpr8.Value() + 2)); - break; - } - default: - UNIMPLEMENTED_MSG("Unhandled coordinates number {}", static_cast(num_coordinates)); - params.push_back(GetRegister(instr.gpr8)); - params.push_back(GetRegister(instr.gpr8.Value() + 1)); - num_coordinates = 2; - texture_type = Tegra::Shader::TextureType::Texture2D; - } - params.push_back(Immediate(static_cast(instr.tld4.component))); - - const auto& sampler = GetSampler(instr.sampler, texture_type, false, depth_compare); - MetaTexture meta{sampler, num_coordinates}; - - const Node texture = - Operation(OperationCode::F4TextureGather, std::move(meta), std::move(params)); - - if (depth_compare) { - SetRegister(bb, instr.gpr0, texture); - } else { - MetaComponents meta; - std::array dest; - - std::size_t dest_elem = 0; - for (std::size_t elem = 0; elem < 4; ++elem) { - if (!instr.tex.IsComponentEnabled(elem)) { - // Skip disabled components - continue; - } - meta.components_map[dest_elem] = static_cast(elem); - dest[dest_elem] = GetRegister(instr.gpr0.Value() + dest_elem); - - ++dest_elem; + std::size_t dest_elem = 0; + for (std::size_t elem = 0; elem < 4; ++elem) { + if (!instr.tex.IsComponentEnabled(elem)) { + // Skip disabled components + continue; } - std::generate(dest.begin() + dest_elem, dest.end(), [&]() { return GetRegister(RZ); }); + meta_components.components_map[dest_elem] = static_cast(elem); + dest[dest_elem] = GetRegister(instr.gpr0.Value() + dest_elem); - bb.push_back(Operation(OperationCode::AssignComposite, std::move(meta), texture, - dest[0], dest[1], dest[2], dest[3])); + ++dest_elem; } + std::generate(dest.begin() + dest_elem, dest.end(), [&]() { return GetRegister(RZ); }); + + bb.push_back(Operation(OperationCode::AssignComposite, std::move(meta_components), texture, + dest[0], dest[1], dest[2], dest[3])); break; } case OpCode::Id::TLD4S: { @@ -595,6 +560,38 @@ Node ShaderIR::GetTexsCode(Instruction instr, TextureType texture_type, (coord_count > 2 ? 1 : 0), std::move(coords)); } +Node ShaderIR::GetTld4Code(Instruction instr, TextureType texture_type, bool depth_compare, + bool is_array) { + const std::size_t coord_count = GetCoordCount(texture_type); + const std::size_t total_coord_count = coord_count + (is_array ? 1 : 0); + const std::size_t total_reg_count = total_coord_count + (depth_compare ? 1 : 0); + + // If enabled arrays index is always stored in the gpr8 field + const u64 array_register = instr.gpr8.Value(); + // First coordinate index is the gpr8 or gpr8 + 1 when arrays are used + const u64 coord_register = array_register + (is_array ? 1 : 0); + + std::vector params; + + for (size_t i = 0; i < coord_count; ++i) { + params.push_back(GetRegister(coord_register + i)); + } + std::size_t array_offset{}; + if (is_array) { + array_offset = params.size(); + params.push_back(GetRegister(array_register)); + } + + const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, depth_compare); + + std::optional array_offset_value; + if (is_array) + array_offset_value = static_cast(array_offset); + MetaTexture meta{sampler, static_cast(params.size()), array_offset_value}; + + return Operation(OperationCode::F4TextureGather, std::move(meta), std::move(params)); +} + std::tuple ShaderIR::ValidateAndGetCoordinateElement( TextureType texture_type, bool depth_compare, bool is_array, bool lod_bias_enabled, std::size_t max_coords, std::size_t max_inputs) { diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 5939318c1..691bd6d72 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h @@ -691,6 +691,9 @@ private: Tegra::Shader::TextureProcessMode process_mode, bool depth_compare, bool is_array); + Node GetTld4Code(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type, + bool depth_compare, bool is_array); + std::tuple ValidateAndGetCoordinateElement( Tegra::Shader::TextureType texture_type, bool depth_compare, bool is_array, bool lod_bias_enabled, std::size_t max_coords, std::size_t max_inputs);