diff options
| author | 2023-01-04 21:20:00 -0500 | |
|---|---|---|
| committer | 2023-01-04 21:20:00 -0500 | |
| commit | b78328f19a54964ef6874281d1a4d6b6ad1c34d9 (patch) | |
| tree | 239947ad53a4a06c3641d58c5d6b8daf5b3dc16a /src/video_core/shader_environment.cpp | |
| parent | Merge pull request #9518 from gidoly/revert-9504-pg2 (diff) | |
| parent | yuzu-ui: Add setting for disabling macro HLE (diff) | |
| download | yuzu-b78328f19a54964ef6874281d1a4d6b6ad1c34d9.tar.gz yuzu-b78328f19a54964ef6874281d1a4d6b6ad1c34d9.tar.xz yuzu-b78328f19a54964ef6874281d1a4d6b6ad1c34d9.zip | |
Merge pull request #9501 from FernandoS27/yfc-rel-2
Yuzu Fried Chicken Part 1.5: MacroHLE Rework and Dynamic State
Diffstat (limited to 'src/video_core/shader_environment.cpp')
| -rw-r--r-- | src/video_core/shader_environment.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/video_core/shader_environment.cpp b/src/video_core/shader_environment.cpp index 958810747..574760f80 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,9 @@ 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 | is_propietary_driver = texture_bound == 2; | ||
| 329 | has_hle_engine_state = | ||
| 330 | maxwell3d->engine_state == Tegra::Engines::Maxwell3D::EngineHint::OnHLEMacro; | ||
| 321 | } | 331 | } |
| 322 | 332 | ||
| 323 | u32 GraphicsEnvironment::ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) { | 333 | u32 GraphicsEnvironment::ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) { |
| @@ -331,6 +341,32 @@ u32 GraphicsEnvironment::ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) { | |||
| 331 | return value; | 341 | return value; |
| 332 | } | 342 | } |
| 333 | 343 | ||
| 344 | std::optional<Shader::ReplaceConstant> GraphicsEnvironment::GetReplaceConstBuffer(u32 bank, | ||
| 345 | u32 offset) { | ||
| 346 | if (!has_hle_engine_state) { | ||
| 347 | return std::nullopt; | ||
| 348 | } | ||
| 349 | const u64 key = (static_cast<u64>(bank) << 32) | static_cast<u64>(offset); | ||
| 350 | auto it = maxwell3d->replace_table.find(key); | ||
| 351 | if (it == maxwell3d->replace_table.end()) { | ||
| 352 | return std::nullopt; | ||
| 353 | } | ||
| 354 | const auto converted_value = [](Tegra::Engines::Maxwell3D::HLEReplacementAttributeType name) { | ||
| 355 | switch (name) { | ||
| 356 | case Tegra::Engines::Maxwell3D::HLEReplacementAttributeType::BaseVertex: | ||
| 357 | return Shader::ReplaceConstant::BaseVertex; | ||
| 358 | case Tegra::Engines::Maxwell3D::HLEReplacementAttributeType::BaseInstance: | ||
| 359 | return Shader::ReplaceConstant::BaseInstance; | ||
| 360 | case Tegra::Engines::Maxwell3D::HLEReplacementAttributeType::DrawID: | ||
| 361 | return Shader::ReplaceConstant::DrawID; | ||
| 362 | default: | ||
| 363 | UNREACHABLE(); | ||
| 364 | } | ||
| 365 | }(it->second); | ||
| 366 | cbuf_replacements.emplace(key, converted_value); | ||
| 367 | return converted_value; | ||
| 368 | } | ||
| 369 | |||
| 334 | Shader::TextureType GraphicsEnvironment::ReadTextureType(u32 handle) { | 370 | Shader::TextureType GraphicsEnvironment::ReadTextureType(u32 handle) { |
| 335 | const auto& regs{maxwell3d->regs}; | 371 | const auto& regs{maxwell3d->regs}; |
| 336 | const bool via_header_index{regs.sampler_binding == Maxwell::SamplerBinding::ViaHeaderBinding}; | 372 | const bool via_header_index{regs.sampler_binding == Maxwell::SamplerBinding::ViaHeaderBinding}; |
| @@ -366,6 +402,7 @@ ComputeEnvironment::ComputeEnvironment(Tegra::Engines::KeplerCompute& kepler_com | |||
| 366 | stage = Shader::Stage::Compute; | 402 | stage = Shader::Stage::Compute; |
| 367 | local_memory_size = qmd.local_pos_alloc + qmd.local_crs_alloc; | 403 | local_memory_size = qmd.local_pos_alloc + qmd.local_crs_alloc; |
| 368 | texture_bound = kepler_compute->regs.tex_cb_index; | 404 | texture_bound = kepler_compute->regs.tex_cb_index; |
| 405 | is_propietary_driver = texture_bound == 2; | ||
| 369 | shared_memory_size = qmd.shared_alloc; | 406 | shared_memory_size = qmd.shared_alloc; |
| 370 | workgroup_size = {qmd.block_dim_x, qmd.block_dim_y, qmd.block_dim_z}; | 407 | workgroup_size = {qmd.block_dim_x, qmd.block_dim_y, qmd.block_dim_z}; |
| 371 | } | 408 | } |
| @@ -409,11 +446,14 @@ void FileEnvironment::Deserialize(std::ifstream& file) { | |||
| 409 | u64 num_texture_types{}; | 446 | u64 num_texture_types{}; |
| 410 | u64 num_texture_pixel_formats{}; | 447 | u64 num_texture_pixel_formats{}; |
| 411 | u64 num_cbuf_values{}; | 448 | u64 num_cbuf_values{}; |
| 449 | u64 num_cbuf_replacement_values{}; | ||
| 412 | file.read(reinterpret_cast<char*>(&code_size), sizeof(code_size)) | 450 | file.read(reinterpret_cast<char*>(&code_size), sizeof(code_size)) |
| 413 | .read(reinterpret_cast<char*>(&num_texture_types), sizeof(num_texture_types)) | 451 | .read(reinterpret_cast<char*>(&num_texture_types), sizeof(num_texture_types)) |
| 414 | .read(reinterpret_cast<char*>(&num_texture_pixel_formats), | 452 | .read(reinterpret_cast<char*>(&num_texture_pixel_formats), |
| 415 | sizeof(num_texture_pixel_formats)) | 453 | sizeof(num_texture_pixel_formats)) |
| 416 | .read(reinterpret_cast<char*>(&num_cbuf_values), sizeof(num_cbuf_values)) | 454 | .read(reinterpret_cast<char*>(&num_cbuf_values), sizeof(num_cbuf_values)) |
| 455 | .read(reinterpret_cast<char*>(&num_cbuf_replacement_values), | ||
| 456 | sizeof(num_cbuf_replacement_values)) | ||
| 417 | .read(reinterpret_cast<char*>(&local_memory_size), sizeof(local_memory_size)) | 457 | .read(reinterpret_cast<char*>(&local_memory_size), sizeof(local_memory_size)) |
| 418 | .read(reinterpret_cast<char*>(&texture_bound), sizeof(texture_bound)) | 458 | .read(reinterpret_cast<char*>(&texture_bound), sizeof(texture_bound)) |
| 419 | .read(reinterpret_cast<char*>(&start_address), sizeof(start_address)) | 459 | .read(reinterpret_cast<char*>(&start_address), sizeof(start_address)) |
| @@ -444,6 +484,13 @@ void FileEnvironment::Deserialize(std::ifstream& file) { | |||
| 444 | .read(reinterpret_cast<char*>(&value), sizeof(value)); | 484 | .read(reinterpret_cast<char*>(&value), sizeof(value)); |
| 445 | cbuf_values.emplace(key, value); | 485 | cbuf_values.emplace(key, value); |
| 446 | } | 486 | } |
| 487 | for (size_t i = 0; i < num_cbuf_replacement_values; ++i) { | ||
| 488 | u64 key; | ||
| 489 | Shader::ReplaceConstant value; | ||
| 490 | file.read(reinterpret_cast<char*>(&key), sizeof(key)) | ||
| 491 | .read(reinterpret_cast<char*>(&value), sizeof(value)); | ||
| 492 | cbuf_replacements.emplace(key, value); | ||
| 493 | } | ||
| 447 | if (stage == Shader::Stage::Compute) { | 494 | if (stage == Shader::Stage::Compute) { |
| 448 | file.read(reinterpret_cast<char*>(&workgroup_size), sizeof(workgroup_size)) | 495 | file.read(reinterpret_cast<char*>(&workgroup_size), sizeof(workgroup_size)) |
| 449 | .read(reinterpret_cast<char*>(&shared_memory_size), sizeof(shared_memory_size)); | 496 | .read(reinterpret_cast<char*>(&shared_memory_size), sizeof(shared_memory_size)); |
| @@ -455,6 +502,7 @@ void FileEnvironment::Deserialize(std::ifstream& file) { | |||
| 455 | file.read(reinterpret_cast<char*>(&gp_passthrough_mask), sizeof(gp_passthrough_mask)); | 502 | file.read(reinterpret_cast<char*>(&gp_passthrough_mask), sizeof(gp_passthrough_mask)); |
| 456 | } | 503 | } |
| 457 | } | 504 | } |
| 505 | is_propietary_driver = texture_bound == 2; | ||
| 458 | } | 506 | } |
| 459 | 507 | ||
| 460 | void FileEnvironment::Dump(u64 hash) { | 508 | void FileEnvironment::Dump(u64 hash) { |
| @@ -512,6 +560,16 @@ std::array<u32, 3> FileEnvironment::WorkgroupSize() const { | |||
| 512 | return workgroup_size; | 560 | return workgroup_size; |
| 513 | } | 561 | } |
| 514 | 562 | ||
| 563 | std::optional<Shader::ReplaceConstant> FileEnvironment::GetReplaceConstBuffer(u32 bank, | ||
| 564 | u32 offset) { | ||
| 565 | const u64 key = (static_cast<u64>(bank) << 32) | static_cast<u64>(offset); | ||
| 566 | auto it = cbuf_replacements.find(key); | ||
| 567 | if (it == cbuf_replacements.end()) { | ||
| 568 | return std::nullopt; | ||
| 569 | } | ||
| 570 | return it->second; | ||
| 571 | } | ||
| 572 | |||
| 515 | void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, | 573 | void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, |
| 516 | const std::filesystem::path& filename, u32 cache_version) try { | 574 | const std::filesystem::path& filename, u32 cache_version) try { |
| 517 | std::ofstream file(filename, std::ios::binary | std::ios::ate | std::ios::app); | 575 | std::ofstream file(filename, std::ios::binary | std::ios::ate | std::ios::app); |