diff options
| author | 2022-12-27 21:39:46 -0500 | |
|---|---|---|
| committer | 2023-01-03 16:29:25 -0500 | |
| commit | a045e860dd63a46c1f44d343007d772e6da6b037 (patch) | |
| tree | 7c910d74f74aa48858a1d4012d543946516cc554 /src | |
| parent | Vulkan: rework stencil tracking. (diff) | |
| download | yuzu-a045e860dd63a46c1f44d343007d772e6da6b037.tar.gz yuzu-a045e860dd63a46c1f44d343007d772e6da6b037.tar.xz yuzu-a045e860dd63a46c1f44d343007d772e6da6b037.zip | |
ShaderCompiler: Inline driver specific constants.
Diffstat (limited to 'src')
| -rw-r--r-- | src/shader_recompiler/environment.h | 5 | ||||
| -rw-r--r-- | src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | 30 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/shader_environment.cpp | 3 |
5 files changed, 39 insertions, 3 deletions
diff --git a/src/shader_recompiler/environment.h b/src/shader_recompiler/environment.h index 8fc359126..26e8307c1 100644 --- a/src/shader_recompiler/environment.h +++ b/src/shader_recompiler/environment.h | |||
| @@ -57,11 +57,16 @@ public: | |||
| 57 | return start_address; | 57 | return start_address; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | [[nodiscard]] bool IsPropietaryDriver() const noexcept { | ||
| 61 | return is_propietary_driver; | ||
| 62 | } | ||
| 63 | |||
| 60 | protected: | 64 | protected: |
| 61 | ProgramHeader sph{}; | 65 | ProgramHeader sph{}; |
| 62 | std::array<u32, 8> gp_passthrough_mask{}; | 66 | std::array<u32, 8> gp_passthrough_mask{}; |
| 63 | Stage stage{}; | 67 | Stage stage{}; |
| 64 | u32 start_address{}; | 68 | u32 start_address{}; |
| 69 | bool is_propietary_driver{}; | ||
| 65 | }; | 70 | }; |
| 66 | 71 | ||
| 67 | } // namespace Shader | 72 | } // namespace Shader |
diff --git a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp index ac10405f3..5275b2c8b 100644 --- a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp +++ b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | |||
| @@ -677,6 +677,30 @@ void FoldConstBuffer(Environment& env, IR::Block& block, IR::Inst& inst) { | |||
| 677 | } | 677 | } |
| 678 | } | 678 | } |
| 679 | 679 | ||
| 680 | void FoldDriverConstBuffer(Environment& env, IR::Block& block, IR::Inst& inst, u32 which_bank, | ||
| 681 | u32 offset_start = 0, u32 offset_end = std::numeric_limits<u16>::max()) { | ||
| 682 | const IR::Value bank{inst.Arg(0)}; | ||
| 683 | const IR::Value offset{inst.Arg(1)}; | ||
| 684 | if (!bank.IsImmediate() || !offset.IsImmediate()) { | ||
| 685 | return; | ||
| 686 | } | ||
| 687 | const auto bank_value = bank.U32(); | ||
| 688 | if (bank_value != which_bank) { | ||
| 689 | return; | ||
| 690 | } | ||
| 691 | const auto offset_value = offset.U32(); | ||
| 692 | if (offset_value < offset_start || offset_value >= offset_end) { | ||
| 693 | return; | ||
| 694 | } | ||
| 695 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; | ||
| 696 | if (inst.GetOpcode() == IR::Opcode::GetCbufU32) { | ||
| 697 | inst.ReplaceUsesWith(IR::Value{env.ReadCbufValue(bank_value, offset_value)}); | ||
| 698 | } else { | ||
| 699 | inst.ReplaceUsesWith( | ||
| 700 | IR::Value{Common::BitCast<f32>(env.ReadCbufValue(bank_value, offset_value))}); | ||
| 701 | } | ||
| 702 | } | ||
| 703 | |||
| 680 | void ConstantPropagation(Environment& env, IR::Block& block, IR::Inst& inst) { | 704 | void ConstantPropagation(Environment& env, IR::Block& block, IR::Inst& inst) { |
| 681 | switch (inst.GetOpcode()) { | 705 | switch (inst.GetOpcode()) { |
| 682 | case IR::Opcode::GetRegister: | 706 | case IR::Opcode::GetRegister: |
| @@ -825,13 +849,17 @@ void ConstantPropagation(Environment& env, IR::Block& block, IR::Inst& inst) { | |||
| 825 | case IR::Opcode::GetCbufF32: | 849 | case IR::Opcode::GetCbufF32: |
| 826 | case IR::Opcode::GetCbufU32: | 850 | case IR::Opcode::GetCbufU32: |
| 827 | if (env.HasHLEMacroState()) { | 851 | if (env.HasHLEMacroState()) { |
| 828 | return FoldConstBuffer(env, block, inst); | 852 | FoldConstBuffer(env, block, inst); |
| 853 | } | ||
| 854 | if (env.IsPropietaryDriver()) { | ||
| 855 | FoldDriverConstBuffer(env, block, inst, 1); | ||
| 829 | } | 856 | } |
| 830 | break; | 857 | break; |
| 831 | default: | 858 | default: |
| 832 | break; | 859 | break; |
| 833 | } | 860 | } |
| 834 | } | 861 | } |
| 862 | |||
| 835 | } // Anonymous namespace | 863 | } // Anonymous namespace |
| 836 | 864 | ||
| 837 | void ConstantPropagationPass(Environment& env, IR::Program& program) { | 865 | void ConstantPropagationPass(Environment& env, IR::Program& program) { |
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index bf991afee..03b6314ff 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -51,7 +51,7 @@ using VideoCommon::LoadPipelines; | |||
| 51 | using VideoCommon::SerializePipeline; | 51 | using VideoCommon::SerializePipeline; |
| 52 | using Context = ShaderContext::Context; | 52 | using Context = ShaderContext::Context; |
| 53 | 53 | ||
| 54 | constexpr u32 CACHE_VERSION = 8; | 54 | constexpr u32 CACHE_VERSION = 9; |
| 55 | 55 | ||
| 56 | template <typename Container> | 56 | template <typename Container> |
| 57 | auto MakeSpan(Container& container) { | 57 | auto MakeSpan(Container& container) { |
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 6cd162422..3046b72ab 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -54,7 +54,7 @@ using VideoCommon::FileEnvironment; | |||
| 54 | using VideoCommon::GenericEnvironment; | 54 | using VideoCommon::GenericEnvironment; |
| 55 | using VideoCommon::GraphicsEnvironment; | 55 | using VideoCommon::GraphicsEnvironment; |
| 56 | 56 | ||
| 57 | constexpr u32 CACHE_VERSION = 9; | 57 | constexpr u32 CACHE_VERSION = 10; |
| 58 | 58 | ||
| 59 | template <typename Container> | 59 | template <typename Container> |
| 60 | auto MakeSpan(Container& container) { | 60 | auto MakeSpan(Container& container) { |
diff --git a/src/video_core/shader_environment.cpp b/src/video_core/shader_environment.cpp index 99d85bfb3..c34728245 100644 --- a/src/video_core/shader_environment.cpp +++ b/src/video_core/shader_environment.cpp | |||
| @@ -325,6 +325,7 @@ GraphicsEnvironment::GraphicsEnvironment(Tegra::Engines::Maxwell3D& maxwell3d_, | |||
| 325 | ASSERT(local_size <= std::numeric_limits<u32>::max()); | 325 | ASSERT(local_size <= std::numeric_limits<u32>::max()); |
| 326 | 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; |
| 327 | 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; | ||
| 328 | has_hle_engine_state = | 329 | has_hle_engine_state = |
| 329 | maxwell3d->engine_state == Tegra::Engines::Maxwell3D::EngineHint::OnHLEMacro; | 330 | maxwell3d->engine_state == Tegra::Engines::Maxwell3D::EngineHint::OnHLEMacro; |
| 330 | } | 331 | } |
| @@ -399,6 +400,7 @@ ComputeEnvironment::ComputeEnvironment(Tegra::Engines::KeplerCompute& kepler_com | |||
| 399 | stage = Shader::Stage::Compute; | 400 | stage = Shader::Stage::Compute; |
| 400 | local_memory_size = qmd.local_pos_alloc + qmd.local_crs_alloc; | 401 | local_memory_size = qmd.local_pos_alloc + qmd.local_crs_alloc; |
| 401 | texture_bound = kepler_compute->regs.tex_cb_index; | 402 | texture_bound = kepler_compute->regs.tex_cb_index; |
| 403 | is_propietary_driver = texture_bound == 2; | ||
| 402 | shared_memory_size = qmd.shared_alloc; | 404 | shared_memory_size = qmd.shared_alloc; |
| 403 | workgroup_size = {qmd.block_dim_x, qmd.block_dim_y, qmd.block_dim_z}; | 405 | workgroup_size = {qmd.block_dim_x, qmd.block_dim_y, qmd.block_dim_z}; |
| 404 | } | 406 | } |
| @@ -498,6 +500,7 @@ void FileEnvironment::Deserialize(std::ifstream& file) { | |||
| 498 | file.read(reinterpret_cast<char*>(&gp_passthrough_mask), sizeof(gp_passthrough_mask)); | 500 | file.read(reinterpret_cast<char*>(&gp_passthrough_mask), sizeof(gp_passthrough_mask)); |
| 499 | } | 501 | } |
| 500 | } | 502 | } |
| 503 | is_propietary_driver = texture_bound == 2; | ||
| 501 | } | 504 | } |
| 502 | 505 | ||
| 503 | void FileEnvironment::Dump(u64 hash) { | 506 | void FileEnvironment::Dump(u64 hash) { |