diff options
| author | 2022-11-09 17:58:10 +0100 | |
|---|---|---|
| committer | 2023-01-01 16:43:57 -0500 | |
| commit | aad0cbf024fb8077a9b375a093c60a7e2ab1db3d (patch) | |
| tree | 8c6a86c92ed8cedbafb5f34dd9f72283eaaf4342 /src/video_core/shader_environment.cpp | |
| parent | MacroHLE: Add Index Buffer size estimation. (diff) | |
| download | yuzu-aad0cbf024fb8077a9b375a093c60a7e2ab1db3d.tar.gz yuzu-aad0cbf024fb8077a9b375a093c60a7e2ab1db3d.tar.xz yuzu-aad0cbf024fb8077a9b375a093c60a7e2ab1db3d.zip | |
MacroHLE: Add HLE replacement for base vertex and base instance.
Diffstat (limited to 'src/video_core/shader_environment.cpp')
| -rw-r--r-- | src/video_core/shader_environment.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/video_core/shader_environment.cpp b/src/video_core/shader_environment.cpp index 958810747..99d85bfb3 100644 --- a/src/video_core/shader_environment.cpp +++ b/src/video_core/shader_environment.cpp | |||
| @@ -202,12 +202,15 @@ void GenericEnvironment::Serialize(std::ofstream& file) const { | |||
| 202 | const u64 num_texture_types{static_cast<u64>(texture_types.size())}; | 202 | 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())}; | 203 | 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())}; | 204 | const u64 num_cbuf_values{static_cast<u64>(cbuf_values.size())}; |
| 205 | const u64 num_cbuf_replacement_values{static_cast<u64>(cbuf_replacements.size())}; | ||
| 205 | 206 | ||
| 206 | file.write(reinterpret_cast<const char*>(&code_size), sizeof(code_size)) | 207 | file.write(reinterpret_cast<const char*>(&code_size), sizeof(code_size)) |
| 207 | .write(reinterpret_cast<const char*>(&num_texture_types), sizeof(num_texture_types)) | 208 | .write(reinterpret_cast<const char*>(&num_texture_types), sizeof(num_texture_types)) |
| 208 | .write(reinterpret_cast<const char*>(&num_texture_pixel_formats), | 209 | .write(reinterpret_cast<const char*>(&num_texture_pixel_formats), |
| 209 | sizeof(num_texture_pixel_formats)) | 210 | sizeof(num_texture_pixel_formats)) |
| 210 | .write(reinterpret_cast<const char*>(&num_cbuf_values), sizeof(num_cbuf_values)) | 211 | .write(reinterpret_cast<const char*>(&num_cbuf_values), sizeof(num_cbuf_values)) |
| 212 | .write(reinterpret_cast<const char*>(&num_cbuf_replacement_values), | ||
| 213 | sizeof(num_cbuf_replacement_values)) | ||
| 211 | .write(reinterpret_cast<const char*>(&local_memory_size), sizeof(local_memory_size)) | 214 | .write(reinterpret_cast<const char*>(&local_memory_size), sizeof(local_memory_size)) |
| 212 | .write(reinterpret_cast<const char*>(&texture_bound), sizeof(texture_bound)) | 215 | .write(reinterpret_cast<const char*>(&texture_bound), sizeof(texture_bound)) |
| 213 | .write(reinterpret_cast<const char*>(&start_address), sizeof(start_address)) | 216 | .write(reinterpret_cast<const char*>(&start_address), sizeof(start_address)) |
| @@ -229,6 +232,10 @@ void GenericEnvironment::Serialize(std::ofstream& file) const { | |||
| 229 | file.write(reinterpret_cast<const char*>(&key), sizeof(key)) | 232 | file.write(reinterpret_cast<const char*>(&key), sizeof(key)) |
| 230 | .write(reinterpret_cast<const char*>(&type), sizeof(type)); | 233 | .write(reinterpret_cast<const char*>(&type), sizeof(type)); |
| 231 | } | 234 | } |
| 235 | for (const auto& [key, type] : cbuf_replacements) { | ||
| 236 | file.write(reinterpret_cast<const char*>(&key), sizeof(key)) | ||
| 237 | .write(reinterpret_cast<const char*>(&type), sizeof(type)); | ||
| 238 | } | ||
| 232 | if (stage == Shader::Stage::Compute) { | 239 | if (stage == Shader::Stage::Compute) { |
| 233 | file.write(reinterpret_cast<const char*>(&workgroup_size), sizeof(workgroup_size)) | 240 | file.write(reinterpret_cast<const char*>(&workgroup_size), sizeof(workgroup_size)) |
| 234 | .write(reinterpret_cast<const char*>(&shared_memory_size), sizeof(shared_memory_size)); | 241 | .write(reinterpret_cast<const char*>(&shared_memory_size), sizeof(shared_memory_size)); |
| @@ -318,6 +325,8 @@ GraphicsEnvironment::GraphicsEnvironment(Tegra::Engines::Maxwell3D& maxwell3d_, | |||
| 318 | ASSERT(local_size <= std::numeric_limits<u32>::max()); | 325 | ASSERT(local_size <= std::numeric_limits<u32>::max()); |
| 319 | local_memory_size = static_cast<u32>(local_size) + sph.common3.shader_local_memory_crs_size; | 326 | local_memory_size = static_cast<u32>(local_size) + sph.common3.shader_local_memory_crs_size; |
| 320 | texture_bound = maxwell3d->regs.bindless_texture_const_buffer_slot; | 327 | texture_bound = maxwell3d->regs.bindless_texture_const_buffer_slot; |
| 328 | has_hle_engine_state = | ||
| 329 | maxwell3d->engine_state == Tegra::Engines::Maxwell3D::EngineHint::OnHLEMacro; | ||
| 321 | } | 330 | } |
| 322 | 331 | ||
| 323 | u32 GraphicsEnvironment::ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) { | 332 | u32 GraphicsEnvironment::ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) { |
| @@ -331,6 +340,30 @@ u32 GraphicsEnvironment::ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) { | |||
| 331 | return value; | 340 | return value; |
| 332 | } | 341 | } |
| 333 | 342 | ||
| 343 | std::optional<Shader::ReplaceConstant> GraphicsEnvironment::GetReplaceConstBuffer(u32 bank, | ||
| 344 | u32 offset) { | ||
| 345 | if (!has_hle_engine_state) { | ||
| 346 | return std::nullopt; | ||
| 347 | } | ||
| 348 | const u64 key = (static_cast<u64>(bank) << 32) | static_cast<u64>(offset); | ||
| 349 | auto it = maxwell3d->replace_table.find(key); | ||
| 350 | if (it == maxwell3d->replace_table.end()) { | ||
| 351 | return std::nullopt; | ||
| 352 | } | ||
| 353 | const auto converted_value = [](Tegra::Engines::Maxwell3D::HLEReplaceName name) { | ||
| 354 | switch (name) { | ||
| 355 | case Tegra::Engines::Maxwell3D::HLEReplaceName::BaseVertex: | ||
| 356 | return Shader::ReplaceConstant::BaseVertex; | ||
| 357 | case Tegra::Engines::Maxwell3D::HLEReplaceName::BaseInstance: | ||
| 358 | return Shader::ReplaceConstant::BaseInstance; | ||
| 359 | default: | ||
| 360 | UNREACHABLE(); | ||
| 361 | } | ||
| 362 | }(it->second); | ||
| 363 | cbuf_replacements.emplace(key, converted_value); | ||
| 364 | return converted_value; | ||
| 365 | } | ||
| 366 | |||
| 334 | Shader::TextureType GraphicsEnvironment::ReadTextureType(u32 handle) { | 367 | Shader::TextureType GraphicsEnvironment::ReadTextureType(u32 handle) { |
| 335 | const auto& regs{maxwell3d->regs}; | 368 | const auto& regs{maxwell3d->regs}; |
| 336 | const bool via_header_index{regs.sampler_binding == Maxwell::SamplerBinding::ViaHeaderBinding}; | 369 | const bool via_header_index{regs.sampler_binding == Maxwell::SamplerBinding::ViaHeaderBinding}; |
| @@ -409,11 +442,14 @@ void FileEnvironment::Deserialize(std::ifstream& file) { | |||
| 409 | u64 num_texture_types{}; | 442 | u64 num_texture_types{}; |
| 410 | u64 num_texture_pixel_formats{}; | 443 | u64 num_texture_pixel_formats{}; |
| 411 | u64 num_cbuf_values{}; | 444 | u64 num_cbuf_values{}; |
| 445 | u64 num_cbuf_replacement_values{}; | ||
| 412 | file.read(reinterpret_cast<char*>(&code_size), sizeof(code_size)) | 446 | file.read(reinterpret_cast<char*>(&code_size), sizeof(code_size)) |
| 413 | .read(reinterpret_cast<char*>(&num_texture_types), sizeof(num_texture_types)) | 447 | .read(reinterpret_cast<char*>(&num_texture_types), sizeof(num_texture_types)) |
| 414 | .read(reinterpret_cast<char*>(&num_texture_pixel_formats), | 448 | .read(reinterpret_cast<char*>(&num_texture_pixel_formats), |
| 415 | sizeof(num_texture_pixel_formats)) | 449 | sizeof(num_texture_pixel_formats)) |
| 416 | .read(reinterpret_cast<char*>(&num_cbuf_values), sizeof(num_cbuf_values)) | 450 | .read(reinterpret_cast<char*>(&num_cbuf_values), sizeof(num_cbuf_values)) |
| 451 | .read(reinterpret_cast<char*>(&num_cbuf_replacement_values), | ||
| 452 | sizeof(num_cbuf_replacement_values)) | ||
| 417 | .read(reinterpret_cast<char*>(&local_memory_size), sizeof(local_memory_size)) | 453 | .read(reinterpret_cast<char*>(&local_memory_size), sizeof(local_memory_size)) |
| 418 | .read(reinterpret_cast<char*>(&texture_bound), sizeof(texture_bound)) | 454 | .read(reinterpret_cast<char*>(&texture_bound), sizeof(texture_bound)) |
| 419 | .read(reinterpret_cast<char*>(&start_address), sizeof(start_address)) | 455 | .read(reinterpret_cast<char*>(&start_address), sizeof(start_address)) |
| @@ -444,6 +480,13 @@ void FileEnvironment::Deserialize(std::ifstream& file) { | |||
| 444 | .read(reinterpret_cast<char*>(&value), sizeof(value)); | 480 | .read(reinterpret_cast<char*>(&value), sizeof(value)); |
| 445 | cbuf_values.emplace(key, value); | 481 | cbuf_values.emplace(key, value); |
| 446 | } | 482 | } |
| 483 | for (size_t i = 0; i < num_cbuf_replacement_values; ++i) { | ||
| 484 | u64 key; | ||
| 485 | Shader::ReplaceConstant value; | ||
| 486 | file.read(reinterpret_cast<char*>(&key), sizeof(key)) | ||
| 487 | .read(reinterpret_cast<char*>(&value), sizeof(value)); | ||
| 488 | cbuf_replacements.emplace(key, value); | ||
| 489 | } | ||
| 447 | if (stage == Shader::Stage::Compute) { | 490 | if (stage == Shader::Stage::Compute) { |
| 448 | file.read(reinterpret_cast<char*>(&workgroup_size), sizeof(workgroup_size)) | 491 | file.read(reinterpret_cast<char*>(&workgroup_size), sizeof(workgroup_size)) |
| 449 | .read(reinterpret_cast<char*>(&shared_memory_size), sizeof(shared_memory_size)); | 492 | .read(reinterpret_cast<char*>(&shared_memory_size), sizeof(shared_memory_size)); |
| @@ -512,6 +555,16 @@ std::array<u32, 3> FileEnvironment::WorkgroupSize() const { | |||
| 512 | return workgroup_size; | 555 | return workgroup_size; |
| 513 | } | 556 | } |
| 514 | 557 | ||
| 558 | std::optional<Shader::ReplaceConstant> FileEnvironment::GetReplaceConstBuffer(u32 bank, | ||
| 559 | u32 offset) { | ||
| 560 | const u64 key = (static_cast<u64>(bank) << 32) | static_cast<u64>(offset); | ||
| 561 | auto it = cbuf_replacements.find(key); | ||
| 562 | if (it == cbuf_replacements.end()) { | ||
| 563 | return std::nullopt; | ||
| 564 | } | ||
| 565 | return it->second; | ||
| 566 | } | ||
| 567 | |||
| 515 | void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, | 568 | void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, |
| 516 | const std::filesystem::path& filename, u32 cache_version) try { | 569 | const std::filesystem::path& filename, u32 cache_version) try { |
| 517 | std::ofstream file(filename, std::ios::binary | std::ios::ate | std::ios::app); | 570 | std::ofstream file(filename, std::ios::binary | std::ios::ate | std::ios::app); |