summaryrefslogtreecommitdiff
path: root/src/video_core/shader/decode
diff options
context:
space:
mode:
authorGravatar bunnei2019-02-12 10:20:15 -0500
committerGravatar GitHub2019-02-12 10:20:15 -0500
commit27e5efd265397c2902828ab77303088412ec3a72 (patch)
tree968dd99f5384435a2fee12b2cdc0c77451902ebb /src/video_core/shader/decode
parentMerge pull request #1904 from bunnei/better-fermi-copy (diff)
parentshader_ir: Remove F4 prefix to texture operations (diff)
downloadyuzu-27e5efd265397c2902828ab77303088412ec3a72.tar.gz
yuzu-27e5efd265397c2902828ab77303088412ec3a72.tar.xz
yuzu-27e5efd265397c2902828ab77303088412ec3a72.zip
Merge pull request #2068 from ReinUsesLisp/shader-cleanup-textures
shader_ir: Clean texture management code
Diffstat (limited to 'src/video_core/shader/decode')
-rw-r--r--src/video_core/shader/decode/memory.cpp157
1 files changed, 59 insertions, 98 deletions
diff --git a/src/video_core/shader/decode/memory.cpp b/src/video_core/shader/decode/memory.cpp
index e006f8138..523421794 100644
--- a/src/video_core/shader/decode/memory.cpp
+++ b/src/video_core/shader/decode/memory.cpp
@@ -306,7 +306,6 @@ u32 ShaderIR::DecodeMemory(NodeBlock& bb, u32 pc) {
306 case OpCode::Id::TLD4S: { 306 case OpCode::Id::TLD4S: {
307 UNIMPLEMENTED_IF_MSG(instr.tld4s.UsesMiscMode(TextureMiscMode::AOFFI), 307 UNIMPLEMENTED_IF_MSG(instr.tld4s.UsesMiscMode(TextureMiscMode::AOFFI),
308 "AOFFI is not implemented"); 308 "AOFFI is not implemented");
309
310 if (instr.tld4s.UsesMiscMode(TextureMiscMode::NODEP)) { 309 if (instr.tld4s.UsesMiscMode(TextureMiscMode::NODEP)) {
311 LOG_WARNING(HW_GPU, "TLD4S.NODEP implementation is incomplete"); 310 LOG_WARNING(HW_GPU, "TLD4S.NODEP implementation is incomplete");
312 } 311 }
@@ -315,9 +314,8 @@ u32 ShaderIR::DecodeMemory(NodeBlock& bb, u32 pc) {
315 const Node op_a = GetRegister(instr.gpr8); 314 const Node op_a = GetRegister(instr.gpr8);
316 const Node op_b = GetRegister(instr.gpr20); 315 const Node op_b = GetRegister(instr.gpr20);
317 316
318 std::vector<Node> coords;
319
320 // TODO(Subv): Figure out how the sampler type is encoded in the TLD4S instruction. 317 // TODO(Subv): Figure out how the sampler type is encoded in the TLD4S instruction.
318 std::vector<Node> coords;
321 if (depth_compare) { 319 if (depth_compare) {
322 // Note: TLD4S coordinate encoding works just like TEXS's 320 // Note: TLD4S coordinate encoding works just like TEXS's
323 const Node op_y = GetRegister(instr.gpr8.Value() + 1); 321 const Node op_y = GetRegister(instr.gpr8.Value() + 1);
@@ -328,18 +326,17 @@ u32 ShaderIR::DecodeMemory(NodeBlock& bb, u32 pc) {
328 coords.push_back(op_a); 326 coords.push_back(op_a);
329 coords.push_back(op_b); 327 coords.push_back(op_b);
330 } 328 }
331 const auto num_coords = static_cast<u32>(coords.size()); 329 std::vector<Node> extras;
332 coords.push_back(Immediate(static_cast<u32>(instr.tld4s.component))); 330 extras.push_back(Immediate(static_cast<u32>(instr.tld4s.component)));
333 331
334 const auto& sampler = 332 const auto& sampler =
335 GetSampler(instr.sampler, TextureType::Texture2D, false, depth_compare); 333 GetSampler(instr.sampler, TextureType::Texture2D, false, depth_compare);
336 334
337 Node4 values; 335 Node4 values;
338 for (u32 element = 0; element < values.size(); ++element) { 336 for (u32 element = 0; element < values.size(); ++element) {
339 auto params = coords; 337 auto coords_copy = coords;
340 MetaTexture meta{sampler, element, num_coords}; 338 MetaTexture meta{sampler, {}, {}, extras, element};
341 values[element] = 339 values[element] = Operation(OperationCode::TextureGather, meta, std::move(coords_copy));
342 Operation(OperationCode::F4TextureGather, std::move(meta), std::move(params));
343 } 340 }
344 341
345 WriteTexsInstructionFloat(bb, instr, values); 342 WriteTexsInstructionFloat(bb, instr, values);
@@ -360,12 +357,13 @@ u32 ShaderIR::DecodeMemory(NodeBlock& bb, u32 pc) {
360 switch (instr.txq.query_type) { 357 switch (instr.txq.query_type) {
361 case Tegra::Shader::TextureQueryType::Dimension: { 358 case Tegra::Shader::TextureQueryType::Dimension: {
362 for (u32 element = 0; element < 4; ++element) { 359 for (u32 element = 0; element < 4; ++element) {
363 if (instr.txq.IsComponentEnabled(element)) { 360 if (!instr.txq.IsComponentEnabled(element)) {
364 MetaTexture meta{sampler, element}; 361 continue;
365 const Node value = Operation(OperationCode::F4TextureQueryDimensions,
366 std::move(meta), GetRegister(instr.gpr8));
367 SetTemporal(bb, indexer++, value);
368 } 362 }
363 MetaTexture meta{sampler, {}, {}, {}, element};
364 const Node value =
365 Operation(OperationCode::TextureQueryDimensions, meta, GetRegister(instr.gpr8));
366 SetTemporal(bb, indexer++, value);
369 } 367 }
370 for (u32 i = 0; i < indexer; ++i) { 368 for (u32 i = 0; i < indexer; ++i) {
371 SetRegister(bb, instr.gpr0.Value() + i, GetTemporal(i)); 369 SetRegister(bb, instr.gpr0.Value() + i, GetTemporal(i));
@@ -412,9 +410,8 @@ u32 ShaderIR::DecodeMemory(NodeBlock& bb, u32 pc) {
412 410
413 for (u32 element = 0; element < 2; ++element) { 411 for (u32 element = 0; element < 2; ++element) {
414 auto params = coords; 412 auto params = coords;
415 MetaTexture meta_texture{sampler, element, static_cast<u32>(coords.size())}; 413 MetaTexture meta{sampler, {}, {}, {}, element};
416 const Node value = 414 const Node value = Operation(OperationCode::TextureQueryLod, meta, std::move(params));
417 Operation(OperationCode::F4TextureQueryLod, meta_texture, std::move(params));
418 SetTemporal(bb, element, value); 415 SetTemporal(bb, element, value);
419 } 416 }
420 for (u32 element = 0; element < 2; ++element) { 417 for (u32 element = 0; element < 2; ++element) {
@@ -535,15 +532,16 @@ void ShaderIR::WriteTexsInstructionHalfFloat(NodeBlock& bb, Instruction instr,
535} 532}
536 533
537Node4 ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type, 534Node4 ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type,
538 TextureProcessMode process_mode, bool depth_compare, bool is_array, 535 TextureProcessMode process_mode, std::vector<Node> coords,
539 std::size_t array_offset, std::size_t bias_offset, 536 Node array, Node depth_compare, u32 bias_offset) {
540 std::vector<Node>&& coords) { 537 const bool is_array = array;
541 UNIMPLEMENTED_IF_MSG( 538 const bool is_shadow = depth_compare;
542 (texture_type == TextureType::Texture3D && (is_array || depth_compare)) ||
543 (texture_type == TextureType::TextureCube && is_array && depth_compare),
544 "This method is not supported.");
545 539
546 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, depth_compare); 540 UNIMPLEMENTED_IF_MSG((texture_type == TextureType::Texture3D && (is_array || is_shadow)) ||
541 (texture_type == TextureType::TextureCube && is_array && is_shadow),
542 "This method is not supported.");
543
544 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, is_shadow);
547 545
548 const bool lod_needed = process_mode == TextureProcessMode::LZ || 546 const bool lod_needed = process_mode == TextureProcessMode::LZ ||
549 process_mode == TextureProcessMode::LL || 547 process_mode == TextureProcessMode::LL ||
@@ -552,35 +550,30 @@ Node4 ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type,
552 // LOD selection (either via bias or explicit textureLod) not supported in GL for 550 // LOD selection (either via bias or explicit textureLod) not supported in GL for
553 // sampler2DArrayShadow and samplerCubeArrayShadow. 551 // sampler2DArrayShadow and samplerCubeArrayShadow.
554 const bool gl_lod_supported = 552 const bool gl_lod_supported =
555 !((texture_type == Tegra::Shader::TextureType::Texture2D && is_array && depth_compare) || 553 !((texture_type == Tegra::Shader::TextureType::Texture2D && is_array && is_shadow) ||
556 (texture_type == Tegra::Shader::TextureType::TextureCube && is_array && depth_compare)); 554 (texture_type == Tegra::Shader::TextureType::TextureCube && is_array && is_shadow));
557 555
558 const OperationCode read_method = 556 const OperationCode read_method =
559 lod_needed && gl_lod_supported ? OperationCode::F4TextureLod : OperationCode::F4Texture; 557 lod_needed && gl_lod_supported ? OperationCode::TextureLod : OperationCode::Texture;
560 558
561 UNIMPLEMENTED_IF(process_mode != TextureProcessMode::None && !gl_lod_supported); 559 UNIMPLEMENTED_IF(process_mode != TextureProcessMode::None && !gl_lod_supported);
562 560
563 std::optional<u32> array_offset_value; 561 std::vector<Node> extras;
564 if (is_array)
565 array_offset_value = static_cast<u32>(array_offset);
566
567 const auto coords_count = static_cast<u32>(coords.size());
568
569 if (process_mode != TextureProcessMode::None && gl_lod_supported) { 562 if (process_mode != TextureProcessMode::None && gl_lod_supported) {
570 if (process_mode == TextureProcessMode::LZ) { 563 if (process_mode == TextureProcessMode::LZ) {
571 coords.push_back(Immediate(0.0f)); 564 extras.push_back(Immediate(0.0f));
572 } else { 565 } else {
573 // If present, lod or bias are always stored in the register indexed by the gpr20 566 // If present, lod or bias are always stored in the register indexed by the gpr20
574 // field with an offset depending on the usage of the other registers 567 // field with an offset depending on the usage of the other registers
575 coords.push_back(GetRegister(instr.gpr20.Value() + bias_offset)); 568 extras.push_back(GetRegister(instr.gpr20.Value() + bias_offset));
576 } 569 }
577 } 570 }
578 571
579 Node4 values; 572 Node4 values;
580 for (u32 element = 0; element < values.size(); ++element) { 573 for (u32 element = 0; element < values.size(); ++element) {
581 auto params = coords; 574 auto copy_coords = coords;
582 MetaTexture meta{sampler, element, coords_count, array_offset_value}; 575 MetaTexture meta{sampler, array, depth_compare, extras, element};
583 values[element] = Operation(read_method, std::move(meta), std::move(params)); 576 values[element] = Operation(read_method, meta, std::move(copy_coords));
584 } 577 }
585 578
586 return values; 579 return values;
@@ -602,28 +595,22 @@ Node4 ShaderIR::GetTexCode(Instruction instr, TextureType texture_type,
602 for (std::size_t i = 0; i < coord_count; ++i) { 595 for (std::size_t i = 0; i < coord_count; ++i) {
603 coords.push_back(GetRegister(coord_register + i)); 596 coords.push_back(GetRegister(coord_register + i));
604 } 597 }
605 // 1D.DC in opengl the 2nd component is ignored. 598 // 1D.DC in OpenGL the 2nd component is ignored.
606 if (depth_compare && !is_array && texture_type == TextureType::Texture1D) { 599 if (depth_compare && !is_array && texture_type == TextureType::Texture1D) {
607 coords.push_back(Immediate(0.0f)); 600 coords.push_back(Immediate(0.0f));
608 } 601 }
609 std::size_t array_offset{}; 602
610 if (is_array) { 603 const Node array = is_array ? GetRegister(array_register) : nullptr;
611 array_offset = coords.size(); 604
612 coords.push_back(GetRegister(array_register)); 605 Node dc{};
613 }
614 if (depth_compare) { 606 if (depth_compare) {
615 // Depth is always stored in the register signaled by gpr20 607 // Depth is always stored in the register signaled by gpr20 or in the next register if lod
616 // or in the next register if lod or bias are used 608 // or bias are used
617 const u64 depth_register = instr.gpr20.Value() + (lod_bias_enabled ? 1 : 0); 609 const u64 depth_register = instr.gpr20.Value() + (lod_bias_enabled ? 1 : 0);
618 coords.push_back(GetRegister(depth_register)); 610 dc = GetRegister(depth_register);
619 }
620 // Fill ignored coordinates
621 while (coords.size() < total_coord_count) {
622 coords.push_back(Immediate(0));
623 } 611 }
624 612
625 return GetTextureCode(instr, texture_type, process_mode, depth_compare, is_array, array_offset, 613 return GetTextureCode(instr, texture_type, process_mode, coords, array, dc, 0);
626 0, std::move(coords));
627} 614}
628 615
629Node4 ShaderIR::GetTexsCode(Instruction instr, TextureType texture_type, 616Node4 ShaderIR::GetTexsCode(Instruction instr, TextureType texture_type,
@@ -641,6 +628,7 @@ Node4 ShaderIR::GetTexsCode(Instruction instr, TextureType texture_type,
641 (is_array || !(lod_bias_enabled || depth_compare) || (coord_count > 2)) 628 (is_array || !(lod_bias_enabled || depth_compare) || (coord_count > 2))
642 ? static_cast<u64>(instr.gpr20.Value()) 629 ? static_cast<u64>(instr.gpr20.Value())
643 : coord_register + 1; 630 : coord_register + 1;
631 const u32 bias_offset = coord_count > 2 ? 1 : 0;
644 632
645 std::vector<Node> coords; 633 std::vector<Node> coords;
646 for (std::size_t i = 0; i < coord_count; ++i) { 634 for (std::size_t i = 0; i < coord_count; ++i) {
@@ -648,24 +636,17 @@ Node4 ShaderIR::GetTexsCode(Instruction instr, TextureType texture_type,
648 coords.push_back(GetRegister(last ? last_coord_register : coord_register + i)); 636 coords.push_back(GetRegister(last ? last_coord_register : coord_register + i));
649 } 637 }
650 638
651 std::size_t array_offset{}; 639 const Node array = is_array ? GetRegister(array_register) : nullptr;
652 if (is_array) { 640
653 array_offset = coords.size(); 641 Node dc{};
654 coords.push_back(GetRegister(array_register));
655 }
656 if (depth_compare) { 642 if (depth_compare) {
657 // Depth is always stored in the register signaled by gpr20 643 // Depth is always stored in the register signaled by gpr20 or in the next register if lod
658 // or in the next register if lod or bias are used 644 // or bias are used
659 const u64 depth_register = instr.gpr20.Value() + (lod_bias_enabled ? 1 : 0); 645 const u64 depth_register = instr.gpr20.Value() + (lod_bias_enabled ? 1 : 0);
660 coords.push_back(GetRegister(depth_register)); 646 dc = GetRegister(depth_register);
661 }
662 // Fill ignored coordinates
663 while (coords.size() < total_coord_count) {
664 coords.push_back(Immediate(0));
665 } 647 }
666 648
667 return GetTextureCode(instr, texture_type, process_mode, depth_compare, is_array, array_offset, 649 return GetTextureCode(instr, texture_type, process_mode, coords, array, dc, bias_offset);
668 (coord_count > 2 ? 1 : 0), std::move(coords));
669} 650}
670 651
671Node4 ShaderIR::GetTld4Code(Instruction instr, TextureType texture_type, bool depth_compare, 652Node4 ShaderIR::GetTld4Code(Instruction instr, TextureType texture_type, bool depth_compare,
@@ -680,24 +661,16 @@ Node4 ShaderIR::GetTld4Code(Instruction instr, TextureType texture_type, bool de
680 const u64 coord_register = array_register + (is_array ? 1 : 0); 661 const u64 coord_register = array_register + (is_array ? 1 : 0);
681 662
682 std::vector<Node> coords; 663 std::vector<Node> coords;
683 664 for (size_t i = 0; i < coord_count; ++i)
684 for (size_t i = 0; i < coord_count; ++i) {
685 coords.push_back(GetRegister(coord_register + i)); 665 coords.push_back(GetRegister(coord_register + i));
686 }
687 std::optional<u32> array_offset;
688 if (is_array) {
689 array_offset = static_cast<u32>(coords.size());
690 coords.push_back(GetRegister(array_register));
691 }
692 666
693 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, depth_compare); 667 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, depth_compare);
694 668
695 Node4 values; 669 Node4 values;
696 for (u32 element = 0; element < values.size(); ++element) { 670 for (u32 element = 0; element < values.size(); ++element) {
697 auto params = coords; 671 auto coords_copy = coords;
698 MetaTexture meta{sampler, element, static_cast<u32>(coords.size()), array_offset}; 672 MetaTexture meta{sampler, GetRegister(array_register), {}, {}, element};
699 values[element] = 673 values[element] = Operation(OperationCode::TextureGather, meta, std::move(coords_copy));
700 Operation(OperationCode::F4TextureGather, std::move(meta), std::move(params));
701 } 674 }
702 675
703 return values; 676 return values;
@@ -705,7 +678,6 @@ Node4 ShaderIR::GetTld4Code(Instruction instr, TextureType texture_type, bool de
705 678
706Node4 ShaderIR::GetTldsCode(Instruction instr, TextureType texture_type, bool is_array) { 679Node4 ShaderIR::GetTldsCode(Instruction instr, TextureType texture_type, bool is_array) {
707 const std::size_t type_coord_count = GetCoordCount(texture_type); 680 const std::size_t type_coord_count = GetCoordCount(texture_type);
708 const std::size_t total_coord_count = type_coord_count + (is_array ? 1 : 0);
709 const bool lod_enabled = instr.tlds.GetTextureProcessMode() == TextureProcessMode::LL; 681 const bool lod_enabled = instr.tlds.GetTextureProcessMode() == TextureProcessMode::LL;
710 682
711 // If enabled arrays index is always stored in the gpr8 field 683 // If enabled arrays index is always stored in the gpr8 field
@@ -719,33 +691,22 @@ Node4 ShaderIR::GetTldsCode(Instruction instr, TextureType texture_type, bool is
719 : coord_register + 1; 691 : coord_register + 1;
720 692
721 std::vector<Node> coords; 693 std::vector<Node> coords;
722
723 for (std::size_t i = 0; i < type_coord_count; ++i) { 694 for (std::size_t i = 0; i < type_coord_count; ++i) {
724 const bool last = (i == (type_coord_count - 1)) && (type_coord_count > 1); 695 const bool last = (i == (type_coord_count - 1)) && (type_coord_count > 1);
725 coords.push_back(GetRegister(last ? last_coord_register : coord_register + i)); 696 coords.push_back(GetRegister(last ? last_coord_register : coord_register + i));
726 } 697 }
727 std::optional<u32> array_offset;
728 if (is_array) {
729 array_offset = static_cast<u32>(coords.size());
730 coords.push_back(GetRegister(array_register));
731 }
732 const auto coords_count = static_cast<u32>(coords.size());
733 698
734 if (lod_enabled) { 699 const Node array = is_array ? GetRegister(array_register) : nullptr;
735 // When lod is used always is in grp20 700 // When lod is used always is in gpr20
736 coords.push_back(GetRegister(instr.gpr20)); 701 const Node lod = lod_enabled ? GetRegister(instr.gpr20) : Immediate(0);
737 } else {
738 coords.push_back(Immediate(0));
739 }
740 702
741 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, false); 703 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, false);
742 704
743 Node4 values; 705 Node4 values;
744 for (u32 element = 0; element < values.size(); ++element) { 706 for (u32 element = 0; element < values.size(); ++element) {
745 auto params = coords; 707 auto coords_copy = coords;
746 MetaTexture meta{sampler, element, coords_count, array_offset}; 708 MetaTexture meta{sampler, array, {}, {lod}, element};
747 values[element] = 709 values[element] = Operation(OperationCode::TexelFetch, meta, std::move(coords_copy));
748 Operation(OperationCode::F4TexelFetch, std::move(meta), std::move(params));
749 } 710 }
750 return values; 711 return values;
751} 712}