diff options
| author | 2021-03-27 02:56:09 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:24 -0400 | |
| commit | cb6039ccea77d35fb829c337fd61451f549e3453 (patch) | |
| tree | 7943d5f75c979c356c6e8d6e4ad21d47e0c2744f /src | |
| parent | shader: Implement front face (diff) | |
| download | yuzu-cb6039ccea77d35fb829c337fd61451f549e3453.tar.gz yuzu-cb6039ccea77d35fb829c337fd61451f549e3453.tar.xz yuzu-cb6039ccea77d35fb829c337fd61451f549e3453.zip | |
vk_pipeline_cache: Fix pipeline and shader caches
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | 26 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_pipeline_cache.h | 1 |
2 files changed, 21 insertions, 6 deletions
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 30d424346..51c155077 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -62,7 +62,7 @@ public: | |||
| 62 | ~GenericEnvironment() override = default; | 62 | ~GenericEnvironment() override = default; |
| 63 | 63 | ||
| 64 | std::optional<u128> Analyze() { | 64 | std::optional<u128> Analyze() { |
| 65 | const std::optional<u64> size{TryFindSize(start_address)}; | 65 | const std::optional<u64> size{TryFindSize()}; |
| 66 | if (!size) { | 66 | if (!size) { |
| 67 | return std::nullopt; | 67 | return std::nullopt; |
| 68 | } | 68 | } |
| @@ -71,6 +71,13 @@ public: | |||
| 71 | return Common::CityHash128(reinterpret_cast<const char*>(code.data()), code.size()); | 71 | return Common::CityHash128(reinterpret_cast<const char*>(code.data()), code.size()); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | void SetCachedSize(size_t size_bytes) { | ||
| 75 | cached_lowest = start_address; | ||
| 76 | cached_highest = start_address + static_cast<u32>(size_bytes); | ||
| 77 | code.resize(CachedSize()); | ||
| 78 | gpu_memory->ReadBlock(program_base + cached_lowest, code.data(), code.size() * sizeof(u64)); | ||
| 79 | } | ||
| 80 | |||
| 74 | [[nodiscard]] size_t CachedSize() const noexcept { | 81 | [[nodiscard]] size_t CachedSize() const noexcept { |
| 75 | return cached_highest - cached_lowest + INST_SIZE; | 82 | return cached_highest - cached_lowest + INST_SIZE; |
| 76 | } | 83 | } |
| @@ -80,7 +87,7 @@ public: | |||
| 80 | } | 87 | } |
| 81 | 88 | ||
| 82 | [[nodiscard]] bool CanBeSerialized() const noexcept { | 89 | [[nodiscard]] bool CanBeSerialized() const noexcept { |
| 83 | return has_unbound_instructions; | 90 | return !has_unbound_instructions; |
| 84 | } | 91 | } |
| 85 | 92 | ||
| 86 | [[nodiscard]] u128 CalculateHash() const { | 93 | [[nodiscard]] u128 CalculateHash() const { |
| @@ -95,7 +102,7 @@ public: | |||
| 95 | read_highest = std::max(read_highest, address); | 102 | read_highest = std::max(read_highest, address); |
| 96 | 103 | ||
| 97 | if (address >= cached_lowest && address < cached_highest) { | 104 | if (address >= cached_lowest && address < cached_highest) { |
| 98 | return code[address / INST_SIZE]; | 105 | return code[(address - cached_lowest) / INST_SIZE]; |
| 99 | } | 106 | } |
| 100 | has_unbound_instructions = true; | 107 | has_unbound_instructions = true; |
| 101 | return gpu_memory->Read<u64>(program_base + address); | 108 | return gpu_memory->Read<u64>(program_base + address); |
| @@ -117,30 +124,34 @@ public: | |||
| 117 | .write(reinterpret_cast<const char*>(&read_highest), sizeof(read_highest)) | 124 | .write(reinterpret_cast<const char*>(&read_highest), sizeof(read_highest)) |
| 118 | .write(reinterpret_cast<const char*>(&stage), sizeof(stage)) | 125 | .write(reinterpret_cast<const char*>(&stage), sizeof(stage)) |
| 119 | .write(data.get(), code_size); | 126 | .write(data.get(), code_size); |
| 127 | file.flush(); | ||
| 120 | for (const auto [key, type] : texture_types) { | 128 | for (const auto [key, type] : texture_types) { |
| 121 | file.write(reinterpret_cast<const char*>(&key), sizeof(key)) | 129 | file.write(reinterpret_cast<const char*>(&key), sizeof(key)) |
| 122 | .write(reinterpret_cast<const char*>(&type), sizeof(type)); | 130 | .write(reinterpret_cast<const char*>(&type), sizeof(type)); |
| 123 | } | 131 | } |
| 132 | file.flush(); | ||
| 124 | if (stage == Shader::Stage::Compute) { | 133 | if (stage == Shader::Stage::Compute) { |
| 125 | const std::array<u32, 3> workgroup_size{WorkgroupSize()}; | 134 | const std::array<u32, 3> workgroup_size{WorkgroupSize()}; |
| 126 | file.write(reinterpret_cast<const char*>(&workgroup_size), sizeof(workgroup_size)); | 135 | file.write(reinterpret_cast<const char*>(&workgroup_size), sizeof(workgroup_size)); |
| 127 | } else { | 136 | } else { |
| 128 | file.write(reinterpret_cast<const char*>(&sph), sizeof(sph)); | 137 | file.write(reinterpret_cast<const char*>(&sph), sizeof(sph)); |
| 129 | } | 138 | } |
| 139 | file.flush(); | ||
| 130 | } | 140 | } |
| 131 | 141 | ||
| 132 | protected: | 142 | protected: |
| 133 | static constexpr size_t INST_SIZE = sizeof(u64); | 143 | static constexpr size_t INST_SIZE = sizeof(u64); |
| 134 | 144 | ||
| 135 | std::optional<u64> TryFindSize(GPUVAddr guest_addr) { | 145 | std::optional<u64> TryFindSize() { |
| 136 | constexpr size_t BLOCK_SIZE = 0x1000; | 146 | constexpr size_t BLOCK_SIZE = 0x1000; |
| 137 | constexpr size_t MAXIMUM_SIZE = 0x100000; | 147 | constexpr size_t MAXIMUM_SIZE = 0x100000; |
| 138 | 148 | ||
| 139 | constexpr u64 SELF_BRANCH_A = 0xE2400FFFFF87000FULL; | 149 | constexpr u64 SELF_BRANCH_A = 0xE2400FFFFF87000FULL; |
| 140 | constexpr u64 SELF_BRANCH_B = 0xE2400FFFFF07000FULL; | 150 | constexpr u64 SELF_BRANCH_B = 0xE2400FFFFF07000FULL; |
| 141 | 151 | ||
| 142 | size_t offset = 0; | 152 | GPUVAddr guest_addr{program_base + start_address}; |
| 143 | size_t size = BLOCK_SIZE; | 153 | size_t offset{0}; |
| 154 | size_t size{BLOCK_SIZE}; | ||
| 144 | while (size <= MAXIMUM_SIZE) { | 155 | while (size <= MAXIMUM_SIZE) { |
| 145 | code.resize(size / INST_SIZE); | 156 | code.resize(size / INST_SIZE); |
| 146 | u64* const data = code.data() + offset / INST_SIZE; | 157 | u64* const data = code.data() + offset / INST_SIZE; |
| @@ -623,6 +634,7 @@ bool PipelineCache::RefreshStages() { | |||
| 623 | GraphicsEnvironment env{maxwell3d, gpu_memory, program, base_addr, start_address}; | 634 | GraphicsEnvironment env{maxwell3d, gpu_memory, program, base_addr, start_address}; |
| 624 | shader_info = MakeShaderInfo(env, *cpu_shader_addr); | 635 | shader_info = MakeShaderInfo(env, *cpu_shader_addr); |
| 625 | } | 636 | } |
| 637 | shader_infos[index] = shader_info; | ||
| 626 | graphics_key.unique_hashes[index] = shader_info->unique_hash; | 638 | graphics_key.unique_hashes[index] = shader_info->unique_hash; |
| 627 | } | 639 | } |
| 628 | return true; | 640 | return true; |
| @@ -707,6 +719,8 @@ GraphicsPipeline PipelineCache::CreateGraphicsPipeline() { | |||
| 707 | GraphicsEnvironment& env{graphics_envs[index]}; | 719 | GraphicsEnvironment& env{graphics_envs[index]}; |
| 708 | const u32 start_address{maxwell3d.regs.shader_config[index].offset}; | 720 | const u32 start_address{maxwell3d.regs.shader_config[index].offset}; |
| 709 | env = GraphicsEnvironment{maxwell3d, gpu_memory, program, base_addr, start_address}; | 721 | env = GraphicsEnvironment{maxwell3d, gpu_memory, program, base_addr, start_address}; |
| 722 | env.SetCachedSize(shader_infos[index]->size_bytes); | ||
| 723 | |||
| 710 | generic_envs.push_back(&env); | 724 | generic_envs.push_back(&env); |
| 711 | envs.push_back(&env); | 725 | envs.push_back(&env); |
| 712 | } | 726 | } |
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.h b/src/video_core/renderer_vulkan/vk_pipeline_cache.h index e09d78063..b55e14189 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.h +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.h | |||
| @@ -172,6 +172,7 @@ private: | |||
| 172 | TextureCache& texture_cache; | 172 | TextureCache& texture_cache; |
| 173 | 173 | ||
| 174 | GraphicsPipelineCacheKey graphics_key{}; | 174 | GraphicsPipelineCacheKey graphics_key{}; |
| 175 | std::array<const ShaderInfo*, 6> shader_infos{}; | ||
| 175 | 176 | ||
| 176 | std::unordered_map<ComputePipelineCacheKey, ComputePipeline> compute_cache; | 177 | std::unordered_map<ComputePipelineCacheKey, ComputePipeline> compute_cache; |
| 177 | std::unordered_map<GraphicsPipelineCacheKey, GraphicsPipeline> graphics_cache; | 178 | std::unordered_map<GraphicsPipelineCacheKey, GraphicsPipeline> graphics_cache; |