diff options
| author | 2019-07-05 13:39:13 -0400 | |
|---|---|---|
| committer | 2019-07-05 13:39:13 -0400 | |
| commit | 772c86a260eb446b0fe4232b0a50666511bef25c (patch) | |
| tree | 013d92268c06454c93565c83eff2b79b56a00839 /src/video_core/shader/decode | |
| parent | Merge pull request #2669 from FearlessTobi/move-cpujit-setting (diff) | |
| parent | texture_cache: Address Feedback (diff) | |
| download | yuzu-772c86a260eb446b0fe4232b0a50666511bef25c.tar.gz yuzu-772c86a260eb446b0fe4232b0a50666511bef25c.tar.xz yuzu-772c86a260eb446b0fe4232b0a50666511bef25c.zip | |
Merge pull request #2601 from FernandoS27/texture_cache
Implement a new Texture Cache
Diffstat (limited to 'src/video_core/shader/decode')
| -rw-r--r-- | src/video_core/shader/decode/image.cpp | 120 | ||||
| -rw-r--r-- | src/video_core/shader/decode/texture.cpp | 45 |
2 files changed, 165 insertions, 0 deletions
diff --git a/src/video_core/shader/decode/image.cpp b/src/video_core/shader/decode/image.cpp new file mode 100644 index 000000000..24f022cc0 --- /dev/null +++ b/src/video_core/shader/decode/image.cpp | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <vector> | ||
| 7 | #include <fmt/format.h> | ||
| 8 | |||
| 9 | #include "common/assert.h" | ||
| 10 | #include "common/bit_field.h" | ||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "common/logging/log.h" | ||
| 13 | #include "video_core/engines/shader_bytecode.h" | ||
| 14 | #include "video_core/shader/node_helper.h" | ||
| 15 | #include "video_core/shader/shader_ir.h" | ||
| 16 | |||
| 17 | namespace VideoCommon::Shader { | ||
| 18 | |||
| 19 | using Tegra::Shader::Instruction; | ||
| 20 | using Tegra::Shader::OpCode; | ||
| 21 | |||
| 22 | namespace { | ||
| 23 | std::size_t GetImageTypeNumCoordinates(Tegra::Shader::ImageType image_type) { | ||
| 24 | switch (image_type) { | ||
| 25 | case Tegra::Shader::ImageType::Texture1D: | ||
| 26 | case Tegra::Shader::ImageType::TextureBuffer: | ||
| 27 | return 1; | ||
| 28 | case Tegra::Shader::ImageType::Texture1DArray: | ||
| 29 | case Tegra::Shader::ImageType::Texture2D: | ||
| 30 | return 2; | ||
| 31 | case Tegra::Shader::ImageType::Texture2DArray: | ||
| 32 | case Tegra::Shader::ImageType::Texture3D: | ||
| 33 | return 3; | ||
| 34 | } | ||
| 35 | UNREACHABLE(); | ||
| 36 | return 1; | ||
| 37 | } | ||
| 38 | } // Anonymous namespace | ||
| 39 | |||
| 40 | u32 ShaderIR::DecodeImage(NodeBlock& bb, u32 pc) { | ||
| 41 | const Instruction instr = {program_code[pc]}; | ||
| 42 | const auto opcode = OpCode::Decode(instr); | ||
| 43 | |||
| 44 | switch (opcode->get().GetId()) { | ||
| 45 | case OpCode::Id::SUST: { | ||
| 46 | UNIMPLEMENTED_IF(instr.sust.mode != Tegra::Shader::SurfaceDataMode::P); | ||
| 47 | UNIMPLEMENTED_IF(instr.sust.image_type == Tegra::Shader::ImageType::TextureBuffer); | ||
| 48 | UNIMPLEMENTED_IF(instr.sust.out_of_bounds_store != Tegra::Shader::OutOfBoundsStore::Ignore); | ||
| 49 | UNIMPLEMENTED_IF(instr.sust.component_mask_selector != 0xf); // Ensure we have an RGBA store | ||
| 50 | |||
| 51 | std::vector<Node> values; | ||
| 52 | constexpr std::size_t hardcoded_size{4}; | ||
| 53 | for (std::size_t i = 0; i < hardcoded_size; ++i) { | ||
| 54 | values.push_back(GetRegister(instr.gpr0.Value() + i)); | ||
| 55 | } | ||
| 56 | |||
| 57 | std::vector<Node> coords; | ||
| 58 | const std::size_t num_coords{GetImageTypeNumCoordinates(instr.sust.image_type)}; | ||
| 59 | for (std::size_t i = 0; i < num_coords; ++i) { | ||
| 60 | coords.push_back(GetRegister(instr.gpr8.Value() + i)); | ||
| 61 | } | ||
| 62 | |||
| 63 | const auto type{instr.sust.image_type}; | ||
| 64 | const auto& image{instr.sust.is_immediate ? GetImage(instr.image, type) | ||
| 65 | : GetBindlessImage(instr.gpr39, type)}; | ||
| 66 | MetaImage meta{image, values}; | ||
| 67 | const Node store{Operation(OperationCode::ImageStore, meta, std::move(coords))}; | ||
| 68 | bb.push_back(store); | ||
| 69 | break; | ||
| 70 | } | ||
| 71 | default: | ||
| 72 | UNIMPLEMENTED_MSG("Unhandled conversion instruction: {}", opcode->get().GetName()); | ||
| 73 | } | ||
| 74 | |||
| 75 | return pc; | ||
| 76 | } | ||
| 77 | |||
| 78 | const Image& ShaderIR::GetImage(Tegra::Shader::Image image, Tegra::Shader::ImageType type) { | ||
| 79 | const auto offset{static_cast<std::size_t>(image.index.Value())}; | ||
| 80 | |||
| 81 | // If this image has already been used, return the existing mapping. | ||
| 82 | const auto itr{std::find_if(used_images.begin(), used_images.end(), | ||
| 83 | [=](const Image& entry) { return entry.GetOffset() == offset; })}; | ||
| 84 | if (itr != used_images.end()) { | ||
| 85 | ASSERT(itr->GetType() == type); | ||
| 86 | return *itr; | ||
| 87 | } | ||
| 88 | |||
| 89 | // Otherwise create a new mapping for this image. | ||
| 90 | const std::size_t next_index{used_images.size()}; | ||
| 91 | const Image entry{offset, next_index, type}; | ||
| 92 | return *used_images.emplace(entry).first; | ||
| 93 | } | ||
| 94 | |||
| 95 | const Image& ShaderIR::GetBindlessImage(Tegra::Shader::Register reg, | ||
| 96 | Tegra::Shader::ImageType type) { | ||
| 97 | const Node image_register{GetRegister(reg)}; | ||
| 98 | const Node base_image{ | ||
| 99 | TrackCbuf(image_register, global_code, static_cast<s64>(global_code.size()))}; | ||
| 100 | const auto cbuf{std::get_if<CbufNode>(&*base_image)}; | ||
| 101 | const auto cbuf_offset_imm{std::get_if<ImmediateNode>(&*cbuf->GetOffset())}; | ||
| 102 | const auto cbuf_offset{cbuf_offset_imm->GetValue()}; | ||
| 103 | const auto cbuf_index{cbuf->GetIndex()}; | ||
| 104 | const auto cbuf_key{(static_cast<u64>(cbuf_index) << 32) | static_cast<u64>(cbuf_offset)}; | ||
| 105 | |||
| 106 | // If this image has already been used, return the existing mapping. | ||
| 107 | const auto itr{std::find_if(used_images.begin(), used_images.end(), | ||
| 108 | [=](const Image& entry) { return entry.GetOffset() == cbuf_key; })}; | ||
| 109 | if (itr != used_images.end()) { | ||
| 110 | ASSERT(itr->GetType() == type); | ||
| 111 | return *itr; | ||
| 112 | } | ||
| 113 | |||
| 114 | // Otherwise create a new mapping for this image. | ||
| 115 | const std::size_t next_index{used_images.size()}; | ||
| 116 | const Image entry{cbuf_index, cbuf_offset, next_index, type}; | ||
| 117 | return *used_images.emplace(entry).first; | ||
| 118 | } | ||
| 119 | |||
| 120 | } // namespace VideoCommon::Shader | ||
diff --git a/src/video_core/shader/decode/texture.cpp b/src/video_core/shader/decode/texture.cpp index 4a356dbd4..cb480be9b 100644 --- a/src/video_core/shader/decode/texture.cpp +++ b/src/video_core/shader/decode/texture.cpp | |||
| @@ -245,6 +245,18 @@ u32 ShaderIR::DecodeTexture(NodeBlock& bb, u32 pc) { | |||
| 245 | } | 245 | } |
| 246 | break; | 246 | break; |
| 247 | } | 247 | } |
| 248 | case OpCode::Id::TLD: { | ||
| 249 | UNIMPLEMENTED_IF_MSG(instr.tld.aoffi, "AOFFI is not implemented"); | ||
| 250 | UNIMPLEMENTED_IF_MSG(instr.tld.ms, "MS is not implemented"); | ||
| 251 | UNIMPLEMENTED_IF_MSG(instr.tld.cl, "CL is not implemented"); | ||
| 252 | |||
| 253 | if (instr.tld.nodep_flag) { | ||
| 254 | LOG_WARNING(HW_GPU, "TLD.NODEP implementation is incomplete"); | ||
| 255 | } | ||
| 256 | |||
| 257 | WriteTexInstructionFloat(bb, instr, GetTldCode(instr)); | ||
| 258 | break; | ||
| 259 | } | ||
| 248 | case OpCode::Id::TLDS: { | 260 | case OpCode::Id::TLDS: { |
| 249 | const Tegra::Shader::TextureType texture_type{instr.tlds.GetTextureType()}; | 261 | const Tegra::Shader::TextureType texture_type{instr.tlds.GetTextureType()}; |
| 250 | const bool is_array{instr.tlds.IsArrayTexture()}; | 262 | const bool is_array{instr.tlds.IsArrayTexture()}; |
| @@ -575,6 +587,39 @@ Node4 ShaderIR::GetTld4Code(Instruction instr, TextureType texture_type, bool de | |||
| 575 | return values; | 587 | return values; |
| 576 | } | 588 | } |
| 577 | 589 | ||
| 590 | Node4 ShaderIR::GetTldCode(Tegra::Shader::Instruction instr) { | ||
| 591 | const auto texture_type{instr.tld.texture_type}; | ||
| 592 | const bool is_array{instr.tld.is_array}; | ||
| 593 | const bool lod_enabled{instr.tld.GetTextureProcessMode() == TextureProcessMode::LL}; | ||
| 594 | const std::size_t coord_count{GetCoordCount(texture_type)}; | ||
| 595 | |||
| 596 | u64 gpr8_cursor{instr.gpr8.Value()}; | ||
| 597 | const Node array_register{is_array ? GetRegister(gpr8_cursor++) : nullptr}; | ||
| 598 | |||
| 599 | std::vector<Node> coords; | ||
| 600 | coords.reserve(coord_count); | ||
| 601 | for (std::size_t i = 0; i < coord_count; ++i) { | ||
| 602 | coords.push_back(GetRegister(gpr8_cursor++)); | ||
| 603 | } | ||
| 604 | |||
| 605 | u64 gpr20_cursor{instr.gpr20.Value()}; | ||
| 606 | // const Node bindless_register{is_bindless ? GetRegister(gpr20_cursor++) : nullptr}; | ||
| 607 | const Node lod{lod_enabled ? GetRegister(gpr20_cursor++) : Immediate(0u)}; | ||
| 608 | // const Node aoffi_register{is_aoffi ? GetRegister(gpr20_cursor++) : nullptr}; | ||
| 609 | // const Node multisample{is_multisample ? GetRegister(gpr20_cursor++) : nullptr}; | ||
| 610 | |||
| 611 | const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, false); | ||
| 612 | |||
| 613 | Node4 values; | ||
| 614 | for (u32 element = 0; element < values.size(); ++element) { | ||
| 615 | auto coords_copy = coords; | ||
| 616 | MetaTexture meta{sampler, array_register, {}, {}, {}, lod, {}, element}; | ||
| 617 | values[element] = Operation(OperationCode::TexelFetch, meta, std::move(coords_copy)); | ||
| 618 | } | ||
| 619 | |||
| 620 | return values; | ||
| 621 | } | ||
| 622 | |||
| 578 | Node4 ShaderIR::GetTldsCode(Instruction instr, TextureType texture_type, bool is_array) { | 623 | Node4 ShaderIR::GetTldsCode(Instruction instr, TextureType texture_type, bool is_array) { |
| 579 | const std::size_t type_coord_count = GetCoordCount(texture_type); | 624 | const std::size_t type_coord_count = GetCoordCount(texture_type); |
| 580 | const bool lod_enabled = instr.tlds.GetTextureProcessMode() == TextureProcessMode::LL; | 625 | const bool lod_enabled = instr.tlds.GetTextureProcessMode() == TextureProcessMode::LL; |