diff options
| -rw-r--r-- | src/video_core/shader_cache.cpp | 4 | ||||
| -rw-r--r-- | src/video_core/shader_environment.cpp | 16 | ||||
| -rw-r--r-- | src/video_core/shader_environment.h | 6 |
3 files changed, 16 insertions, 10 deletions
diff --git a/src/video_core/shader_cache.cpp b/src/video_core/shader_cache.cpp index d9482371b..c5213875b 100644 --- a/src/video_core/shader_cache.cpp +++ b/src/video_core/shader_cache.cpp | |||
| @@ -228,14 +228,14 @@ const ShaderInfo* ShaderCache::MakeShaderInfo(GenericEnvironment& env, VAddr cpu | |||
| 228 | auto info = std::make_unique<ShaderInfo>(); | 228 | auto info = std::make_unique<ShaderInfo>(); |
| 229 | if (const std::optional<u64> cached_hash{env.Analyze()}) { | 229 | if (const std::optional<u64> cached_hash{env.Analyze()}) { |
| 230 | info->unique_hash = *cached_hash; | 230 | info->unique_hash = *cached_hash; |
| 231 | info->size_bytes = env.CachedSize(); | 231 | info->size_bytes = env.CachedSizeBytes(); |
| 232 | } else { | 232 | } else { |
| 233 | // Slow path, not really hit on commercial games | 233 | // Slow path, not really hit on commercial games |
| 234 | // Build a control flow graph to get the real shader size | 234 | // Build a control flow graph to get the real shader size |
| 235 | Shader::ObjectPool<Shader::Maxwell::Flow::Block> flow_block; | 235 | Shader::ObjectPool<Shader::Maxwell::Flow::Block> flow_block; |
| 236 | Shader::Maxwell::Flow::CFG cfg{env, flow_block, env.StartAddress()}; | 236 | Shader::Maxwell::Flow::CFG cfg{env, flow_block, env.StartAddress()}; |
| 237 | info->unique_hash = env.CalculateHash(); | 237 | info->unique_hash = env.CalculateHash(); |
| 238 | info->size_bytes = env.ReadSize(); | 238 | info->size_bytes = env.ReadSizeBytes(); |
| 239 | } | 239 | } |
| 240 | const size_t size_bytes{info->size_bytes}; | 240 | const size_t size_bytes{info->size_bytes}; |
| 241 | const ShaderInfo* const result{info.get()}; | 241 | const ShaderInfo* const result{info.get()}; |
diff --git a/src/video_core/shader_environment.cpp b/src/video_core/shader_environment.cpp index 574760f80..c7cb56243 100644 --- a/src/video_core/shader_environment.cpp +++ b/src/video_core/shader_environment.cpp | |||
| @@ -170,15 +170,19 @@ std::optional<u64> GenericEnvironment::Analyze() { | |||
| 170 | void GenericEnvironment::SetCachedSize(size_t size_bytes) { | 170 | void GenericEnvironment::SetCachedSize(size_t size_bytes) { |
| 171 | cached_lowest = start_address; | 171 | cached_lowest = start_address; |
| 172 | cached_highest = start_address + static_cast<u32>(size_bytes); | 172 | cached_highest = start_address + static_cast<u32>(size_bytes); |
| 173 | code.resize(CachedSize()); | 173 | code.resize(CachedSizeWords()); |
| 174 | gpu_memory->ReadBlock(program_base + cached_lowest, code.data(), code.size() * sizeof(u64)); | 174 | gpu_memory->ReadBlock(program_base + cached_lowest, code.data(), code.size() * sizeof(u64)); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | size_t GenericEnvironment::CachedSize() const noexcept { | 177 | size_t GenericEnvironment::CachedSizeWords() const noexcept { |
| 178 | return cached_highest - cached_lowest + INST_SIZE; | 178 | return CachedSizeBytes() / INST_SIZE; |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | size_t GenericEnvironment::ReadSize() const noexcept { | 181 | size_t GenericEnvironment::CachedSizeBytes() const noexcept { |
| 182 | return static_cast<size_t>(cached_highest) - cached_lowest + INST_SIZE; | ||
| 183 | } | ||
| 184 | |||
| 185 | size_t GenericEnvironment::ReadSizeBytes() const noexcept { | ||
| 182 | return read_highest - read_lowest + INST_SIZE; | 186 | return read_highest - read_lowest + INST_SIZE; |
| 183 | } | 187 | } |
| 184 | 188 | ||
| @@ -187,7 +191,7 @@ bool GenericEnvironment::CanBeSerialized() const noexcept { | |||
| 187 | } | 191 | } |
| 188 | 192 | ||
| 189 | u64 GenericEnvironment::CalculateHash() const { | 193 | u64 GenericEnvironment::CalculateHash() const { |
| 190 | const size_t size{ReadSize()}; | 194 | const size_t size{ReadSizeBytes()}; |
| 191 | const auto data{std::make_unique<char[]>(size)}; | 195 | const auto data{std::make_unique<char[]>(size)}; |
| 192 | gpu_memory->ReadBlock(program_base + read_lowest, data.get(), size); | 196 | gpu_memory->ReadBlock(program_base + read_lowest, data.get(), size); |
| 193 | return Common::CityHash64(data.get(), size); | 197 | return Common::CityHash64(data.get(), size); |
| @@ -198,7 +202,7 @@ void GenericEnvironment::Dump(u64 hash) { | |||
| 198 | } | 202 | } |
| 199 | 203 | ||
| 200 | void GenericEnvironment::Serialize(std::ofstream& file) const { | 204 | void GenericEnvironment::Serialize(std::ofstream& file) const { |
| 201 | const u64 code_size{static_cast<u64>(CachedSize())}; | 205 | const u64 code_size{static_cast<u64>(CachedSizeBytes())}; |
| 202 | const u64 num_texture_types{static_cast<u64>(texture_types.size())}; | 206 | const u64 num_texture_types{static_cast<u64>(texture_types.size())}; |
| 203 | const u64 num_texture_pixel_formats{static_cast<u64>(texture_pixel_formats.size())}; | 207 | const u64 num_texture_pixel_formats{static_cast<u64>(texture_pixel_formats.size())}; |
| 204 | const u64 num_cbuf_values{static_cast<u64>(cbuf_values.size())}; | 208 | const u64 num_cbuf_values{static_cast<u64>(cbuf_values.size())}; |
diff --git a/src/video_core/shader_environment.h b/src/video_core/shader_environment.h index d75987a52..a0f61cbda 100644 --- a/src/video_core/shader_environment.h +++ b/src/video_core/shader_environment.h | |||
| @@ -48,9 +48,11 @@ public: | |||
| 48 | 48 | ||
| 49 | void SetCachedSize(size_t size_bytes); | 49 | void SetCachedSize(size_t size_bytes); |
| 50 | 50 | ||
| 51 | [[nodiscard]] size_t CachedSize() const noexcept; | 51 | [[nodiscard]] size_t CachedSizeWords() const noexcept; |
| 52 | 52 | ||
| 53 | [[nodiscard]] size_t ReadSize() const noexcept; | 53 | [[nodiscard]] size_t CachedSizeBytes() const noexcept; |
| 54 | |||
| 55 | [[nodiscard]] size_t ReadSizeBytes() const noexcept; | ||
| 54 | 56 | ||
| 55 | [[nodiscard]] bool CanBeSerialized() const noexcept; | 57 | [[nodiscard]] bool CanBeSerialized() const noexcept; |
| 56 | 58 | ||