diff options
| author | 2018-12-26 01:33:56 -0300 | |
|---|---|---|
| committer | 2019-01-15 17:54:53 -0300 | |
| commit | 5af82a8ed4e2e0b7abc9c7da9f7bb5fa1c83de29 (patch) | |
| tree | 2982046f3f11a2177905e731bd264d21635e3010 /src | |
| parent | shader_decode: Fixup R2P (diff) | |
| download | yuzu-5af82a8ed4e2e0b7abc9c7da9f7bb5fa1c83de29.tar.gz yuzu-5af82a8ed4e2e0b7abc9c7da9f7bb5fa1c83de29.tar.xz yuzu-5af82a8ed4e2e0b7abc9c7da9f7bb5fa1c83de29.zip | |
shader_decode: Implement TEXS.F16
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/shader/decode/memory.cpp | 38 | ||||
| -rw-r--r-- | src/video_core/shader/glsl_decompiler.cpp | 26 | ||||
| -rw-r--r-- | src/video_core/shader/shader_ir.h | 8 |
3 files changed, 57 insertions, 15 deletions
diff --git a/src/video_core/shader/decode/memory.cpp b/src/video_core/shader/decode/memory.cpp index ce3445512..679e7f01b 100644 --- a/src/video_core/shader/decode/memory.cpp +++ b/src/video_core/shader/decode/memory.cpp | |||
| @@ -219,8 +219,7 @@ u32 ShaderIR::DecodeMemory(BasicBlock& bb, u32 pc) { | |||
| 219 | if (instr.texs.fp32_flag) { | 219 | if (instr.texs.fp32_flag) { |
| 220 | WriteTexsInstructionFloat(bb, instr, texture); | 220 | WriteTexsInstructionFloat(bb, instr, texture); |
| 221 | } else { | 221 | } else { |
| 222 | UNIMPLEMENTED(); | 222 | WriteTexsInstructionHalfFloat(bb, instr, texture); |
| 223 | // WriteTexsInstructionHalfFloat(bb, instr, texture); | ||
| 224 | } | 223 | } |
| 225 | break; | 224 | break; |
| 226 | } | 225 | } |
| @@ -416,39 +415,52 @@ const Sampler& ShaderIR::GetSampler(const Tegra::Shader::Sampler& sampler, Textu | |||
| 416 | return *used_samplers.emplace(entry).first; | 415 | return *used_samplers.emplace(entry).first; |
| 417 | } | 416 | } |
| 418 | 417 | ||
| 419 | void ShaderIR::WriteTexsInstructionFloat(BasicBlock& bb, Tegra::Shader::Instruction instr, | 418 | void ShaderIR::WriteTexsInstructionFloat(BasicBlock& bb, Instruction instr, Node texture) { |
| 420 | Node texture) { | ||
| 421 | // TEXS has two destination registers and a swizzle. The first two elements in the swizzle | 419 | // TEXS has two destination registers and a swizzle. The first two elements in the swizzle |
| 422 | // go into gpr0+0 and gpr0+1, and the rest goes into gpr28+0 and gpr28+1 | 420 | // go into gpr0+0 and gpr0+1, and the rest goes into gpr28+0 and gpr28+1 |
| 423 | 421 | ||
| 424 | MetaComponents meta; | 422 | MetaComponents meta; |
| 425 | std::array<Node, 4> dest; | 423 | std::array<Node, 4> dest; |
| 426 | |||
| 427 | std::size_t written_components = 0; | ||
| 428 | for (u32 component = 0; component < 4; ++component) { | 424 | for (u32 component = 0; component < 4; ++component) { |
| 429 | if (!instr.texs.IsComponentEnabled(component)) { | 425 | if (!instr.texs.IsComponentEnabled(component)) { |
| 430 | continue; | 426 | continue; |
| 431 | } | 427 | } |
| 432 | meta.components_map[written_components] = static_cast<u32>(component); | 428 | meta.components_map[meta.count] = component; |
| 433 | 429 | ||
| 434 | if (written_components < 2) { | 430 | if (meta.count < 2) { |
| 435 | // Write the first two swizzle components to gpr0 and gpr0+1 | 431 | // Write the first two swizzle components to gpr0 and gpr0+1 |
| 436 | dest[written_components] = GetRegister(instr.gpr0.Value() + written_components % 2); | 432 | dest[meta.count] = GetRegister(instr.gpr0.Value() + meta.count % 2); |
| 437 | } else { | 433 | } else { |
| 438 | ASSERT(instr.texs.HasTwoDestinations()); | 434 | ASSERT(instr.texs.HasTwoDestinations()); |
| 439 | // Write the rest of the swizzle components to gpr28 and gpr28+1 | 435 | // Write the rest of the swizzle components to gpr28 and gpr28+1 |
| 440 | dest[written_components] = GetRegister(instr.gpr28.Value() + written_components % 2); | 436 | dest[meta.count] = GetRegister(instr.gpr28.Value() + meta.count % 2); |
| 441 | } | 437 | } |
| 442 | 438 | ++meta.count; | |
| 443 | ++written_components; | ||
| 444 | } | 439 | } |
| 445 | 440 | ||
| 446 | std::generate(dest.begin() + written_components, dest.end(), [&]() { return GetRegister(RZ); }); | 441 | std::generate(dest.begin() + meta.count, dest.end(), [&]() { return GetRegister(RZ); }); |
| 447 | 442 | ||
| 448 | bb.push_back(Operation(OperationCode::AssignComposite, meta, texture, dest[0], dest[1], dest[2], | 443 | bb.push_back(Operation(OperationCode::AssignComposite, meta, texture, dest[0], dest[1], dest[2], |
| 449 | dest[3])); | 444 | dest[3])); |
| 450 | } | 445 | } |
| 451 | 446 | ||
| 447 | void ShaderIR::WriteTexsInstructionHalfFloat(BasicBlock& bb, Instruction instr, Node texture) { | ||
| 448 | // TEXS.F16 destionation registers are packed in two registers in pairs (just like any half | ||
| 449 | // float instruction). | ||
| 450 | |||
| 451 | MetaComponents meta; | ||
| 452 | for (u32 component = 0; component < 4; ++component) { | ||
| 453 | if (!instr.texs.IsComponentEnabled(component)) | ||
| 454 | continue; | ||
| 455 | meta.components_map[meta.count++] = component; | ||
| 456 | } | ||
| 457 | if (meta.count == 0) | ||
| 458 | return; | ||
| 459 | |||
| 460 | bb.push_back(Operation(OperationCode::AssignCompositeHalf, meta, texture, | ||
| 461 | GetRegister(instr.gpr0), GetRegister(instr.gpr28))); | ||
| 462 | } | ||
| 463 | |||
| 452 | Node ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type, | 464 | Node ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type, |
| 453 | TextureProcessMode process_mode, bool depth_compare, bool is_array, | 465 | TextureProcessMode process_mode, bool depth_compare, bool is_array, |
| 454 | std::size_t array_offset, std::size_t bias_offset, | 466 | std::size_t array_offset, std::size_t bias_offset, |
diff --git a/src/video_core/shader/glsl_decompiler.cpp b/src/video_core/shader/glsl_decompiler.cpp index d27d38178..5aa7966b9 100644 --- a/src/video_core/shader/glsl_decompiler.cpp +++ b/src/video_core/shader/glsl_decompiler.cpp | |||
| @@ -785,6 +785,31 @@ private: | |||
| 785 | return {}; | 785 | return {}; |
| 786 | } | 786 | } |
| 787 | 787 | ||
| 788 | std::string AssignCompositeHalf(Operation operation) { | ||
| 789 | const auto& meta = std::get<MetaComponents>(operation.GetMeta()); | ||
| 790 | |||
| 791 | const std::string composite = code.GenerateTemporal(); | ||
| 792 | code.AddLine("vec4 " + composite + " = " + Visit(operation[0]) + ';'); | ||
| 793 | |||
| 794 | const auto ReadComponent = [&](u32 component) { | ||
| 795 | if (component < meta.count) { | ||
| 796 | return composite + '[' + std::to_string(meta.GetSourceComponent(component)) + ']'; | ||
| 797 | } | ||
| 798 | return std::string("0"); | ||
| 799 | }; | ||
| 800 | |||
| 801 | const auto dst1 = std::get<GprNode>(*operation[1]).GetIndex(); | ||
| 802 | const std::string src1 = "vec2(" + ReadComponent(0) + ", " + ReadComponent(1) + ')'; | ||
| 803 | code.AddLine(GetRegister(dst1) + " = utof(packHalf2x16(" + src1 + "))"); | ||
| 804 | |||
| 805 | if (meta.count > 2) { | ||
| 806 | const auto dst2 = std::get<GprNode>(*operation[2]).GetIndex(); | ||
| 807 | const std::string src2 = "vec2(" + ReadComponent(2) + ", " + ReadComponent(3) + ')'; | ||
| 808 | code.AddLine(GetRegister(dst2) + " = utof(packHalf2x16(" + src2 + "))"); | ||
| 809 | } | ||
| 810 | return {}; | ||
| 811 | } | ||
| 812 | |||
| 788 | std::string Composite(Operation operation) { | 813 | std::string Composite(Operation operation) { |
| 789 | std::string value = "vec4("; | 814 | std::string value = "vec4("; |
| 790 | for (std::size_t i = 0; i < 4; ++i) { | 815 | for (std::size_t i = 0; i < 4; ++i) { |
| @@ -1302,6 +1327,7 @@ private: | |||
| 1302 | static constexpr OperationDecompilersArray operation_decompilers = { | 1327 | static constexpr OperationDecompilersArray operation_decompilers = { |
| 1303 | &GLSLDecompiler::Assign, | 1328 | &GLSLDecompiler::Assign, |
| 1304 | &GLSLDecompiler::AssignComposite, | 1329 | &GLSLDecompiler::AssignComposite, |
| 1330 | &GLSLDecompiler::AssignCompositeHalf, | ||
| 1305 | 1331 | ||
| 1306 | &GLSLDecompiler::Composite, | 1332 | &GLSLDecompiler::Composite, |
| 1307 | &GLSLDecompiler::Select, | 1333 | &GLSLDecompiler::Select, |
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 5676d32a9..7f11599bf 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h | |||
| @@ -44,8 +44,9 @@ constexpr u32 MAX_PROGRAM_LENGTH = 0x1000; | |||
| 44 | constexpr u32 RZ = 0xff; | 44 | constexpr u32 RZ = 0xff; |
| 45 | 45 | ||
| 46 | enum class OperationCode { | 46 | enum class OperationCode { |
| 47 | Assign, /// (float& dest, float src) -> void | 47 | Assign, /// (float& dest, float src) -> void |
| 48 | AssignComposite, /// (MetaComponents, float4 src, float&[4] dst) -> void | 48 | AssignComposite, /// (MetaComponents, float4 src, float&[4] dst) -> void |
| 49 | AssignCompositeHalf, /// (MetaComponents, float4 src, float&[2] dst) -> void | ||
| 49 | 50 | ||
| 50 | Composite, /// (float[4] values) -> float4 | 51 | Composite, /// (float[4] values) -> float4 |
| 51 | Select, /// (MetaArithmetic, bool pred, float a, float b) -> float | 52 | Select, /// (MetaArithmetic, bool pred, float a, float b) -> float |
| @@ -279,6 +280,7 @@ struct MetaTexture { | |||
| 279 | 280 | ||
| 280 | struct MetaComponents { | 281 | struct MetaComponents { |
| 281 | std::array<u32, 4> components_map{}; | 282 | std::array<u32, 4> components_map{}; |
| 283 | u32 count{}; | ||
| 282 | 284 | ||
| 283 | u32 GetSourceComponent(u32 dest_index) const { | 285 | u32 GetSourceComponent(u32 dest_index) const { |
| 284 | return components_map[dest_index]; | 286 | return components_map[dest_index]; |
| @@ -692,6 +694,8 @@ private: | |||
| 692 | Tegra::Shader::TextureType type, bool is_array, bool is_shadow); | 694 | Tegra::Shader::TextureType type, bool is_array, bool is_shadow); |
| 693 | 695 | ||
| 694 | void WriteTexsInstructionFloat(BasicBlock& bb, Tegra::Shader::Instruction instr, Node texture); | 696 | void WriteTexsInstructionFloat(BasicBlock& bb, Tegra::Shader::Instruction instr, Node texture); |
| 697 | void WriteTexsInstructionHalfFloat(BasicBlock& bb, Tegra::Shader::Instruction instr, | ||
| 698 | Node texture); | ||
| 695 | 699 | ||
| 696 | Node GetTexCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type, | 700 | Node GetTexCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type, |
| 697 | Tegra::Shader::TextureProcessMode process_mode, bool depth_compare, | 701 | Tegra::Shader::TextureProcessMode process_mode, bool depth_compare, |