diff options
| author | 2019-06-05 15:28:34 -0400 | |
|---|---|---|
| committer | 2019-06-05 15:28:34 -0400 | |
| commit | dd4fe0dab1c6a5559e416833a89ca4520b69a74c (patch) | |
| tree | 92558e8e0bd4439af14dbc26fb664a1230172b98 /src | |
| parent | Merge pull request #2531 from ReinUsesLisp/qt-warnings (diff) | |
| parent | gl_shader_cache: Store a system class and drop global accessors (diff) | |
| download | yuzu-dd4fe0dab1c6a5559e416833a89ca4520b69a74c.tar.gz yuzu-dd4fe0dab1c6a5559e416833a89ca4520b69a74c.tar.xz yuzu-dd4fe0dab1c6a5559e416833a89ca4520b69a74c.zip | |
Merge pull request #2534 from ReinUsesLisp/shader-cleanup
gl_shader_cache: Minor style changes
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 66 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.h | 1 |
2 files changed, 36 insertions, 31 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index d66252224..ac8a9e6b7 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -35,8 +35,8 @@ struct UnspecializedShader { | |||
| 35 | namespace { | 35 | namespace { |
| 36 | 36 | ||
| 37 | /// Gets the address for the specified shader stage program | 37 | /// Gets the address for the specified shader stage program |
| 38 | GPUVAddr GetShaderAddress(Maxwell::ShaderProgram program) { | 38 | GPUVAddr GetShaderAddress(Core::System& system, Maxwell::ShaderProgram program) { |
| 39 | const auto& gpu{Core::System::GetInstance().GPU().Maxwell3D()}; | 39 | const auto& gpu{system.GPU().Maxwell3D()}; |
| 40 | const auto& shader_config{gpu.regs.shader_config[static_cast<std::size_t>(program)]}; | 40 | const auto& shader_config{gpu.regs.shader_config[static_cast<std::size_t>(program)]}; |
| 41 | return gpu.regs.code_address.CodeAddress() + shader_config.offset; | 41 | return gpu.regs.code_address.CodeAddress() + shader_config.offset; |
| 42 | } | 42 | } |
| @@ -350,7 +350,8 @@ ShaderDiskCacheUsage CachedShader::GetUsage(GLenum primitive_mode, | |||
| 350 | 350 | ||
| 351 | ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer, Core::System& system, | 351 | ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer, Core::System& system, |
| 352 | Core::Frontend::EmuWindow& emu_window, const Device& device) | 352 | Core::Frontend::EmuWindow& emu_window, const Device& device) |
| 353 | : RasterizerCache{rasterizer}, emu_window{emu_window}, device{device}, disk_cache{system} {} | 353 | : RasterizerCache{rasterizer}, system{system}, emu_window{emu_window}, device{device}, |
| 354 | disk_cache{system} {} | ||
| 354 | 355 | ||
| 355 | void ShaderCacheOpenGL::LoadDiskCache(const std::atomic_bool& stop_loading, | 356 | void ShaderCacheOpenGL::LoadDiskCache(const std::atomic_bool& stop_loading, |
| 356 | const VideoCore::DiskResourceLoadCallback& callback) { | 357 | const VideoCore::DiskResourceLoadCallback& callback) { |
| @@ -546,42 +547,45 @@ std::unordered_map<u64, UnspecializedShader> ShaderCacheOpenGL::GenerateUnspecia | |||
| 546 | } | 547 | } |
| 547 | 548 | ||
| 548 | Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { | 549 | Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { |
| 549 | if (!Core::System::GetInstance().GPU().Maxwell3D().dirty_flags.shaders) { | 550 | if (!system.GPU().Maxwell3D().dirty_flags.shaders) { |
| 550 | return last_shaders[static_cast<u32>(program)]; | 551 | return last_shaders[static_cast<std::size_t>(program)]; |
| 551 | } | 552 | } |
| 552 | 553 | ||
| 553 | auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()}; | 554 | auto& memory_manager{system.GPU().MemoryManager()}; |
| 554 | const GPUVAddr program_addr{GetShaderAddress(program)}; | 555 | const GPUVAddr program_addr{GetShaderAddress(system, program)}; |
| 555 | 556 | ||
| 556 | // Look up shader in the cache based on address | 557 | // Look up shader in the cache based on address |
| 557 | const auto& host_ptr{memory_manager.GetPointer(program_addr)}; | 558 | const auto host_ptr{memory_manager.GetPointer(program_addr)}; |
| 558 | Shader shader{TryGet(host_ptr)}; | 559 | Shader shader{TryGet(host_ptr)}; |
| 560 | if (shader) { | ||
| 561 | return last_shaders[static_cast<std::size_t>(program)] = shader; | ||
| 562 | } | ||
| 559 | 563 | ||
| 560 | if (!shader) { | 564 | // No shader found - create a new one |
| 561 | // No shader found - create a new one | 565 | ProgramCode program_code{GetShaderCode(memory_manager, program_addr, host_ptr)}; |
| 562 | ProgramCode program_code{GetShaderCode(memory_manager, program_addr, host_ptr)}; | 566 | ProgramCode program_code_b; |
| 563 | ProgramCode program_code_b; | 567 | if (program == Maxwell::ShaderProgram::VertexA) { |
| 564 | if (program == Maxwell::ShaderProgram::VertexA) { | 568 | const GPUVAddr program_addr_b{GetShaderAddress(system, Maxwell::ShaderProgram::VertexB)}; |
| 565 | const GPUVAddr program_addr_b{GetShaderAddress(Maxwell::ShaderProgram::VertexB)}; | 569 | program_code_b = GetShaderCode(memory_manager, program_addr_b, |
| 566 | program_code_b = GetShaderCode(memory_manager, program_addr_b, | 570 | memory_manager.GetPointer(program_addr_b)); |
| 567 | memory_manager.GetPointer(program_addr_b)); | 571 | } |
| 568 | } | 572 | |
| 569 | const u64 unique_identifier = GetUniqueIdentifier(program, program_code, program_code_b); | 573 | const u64 unique_identifier = GetUniqueIdentifier(program, program_code, program_code_b); |
| 570 | const VAddr cpu_addr{*memory_manager.GpuToCpuAddress(program_addr)}; | 574 | const VAddr cpu_addr{*memory_manager.GpuToCpuAddress(program_addr)}; |
| 571 | const auto found = precompiled_shaders.find(unique_identifier); | 575 | const auto found = precompiled_shaders.find(unique_identifier); |
| 572 | if (found != precompiled_shaders.end()) { | 576 | if (found != precompiled_shaders.end()) { |
| 573 | shader = | 577 | // Create a shader from the cache |
| 574 | std::make_shared<CachedShader>(cpu_addr, unique_identifier, program, disk_cache, | 578 | shader = std::make_shared<CachedShader>(cpu_addr, unique_identifier, program, disk_cache, |
| 575 | precompiled_programs, found->second, host_ptr); | 579 | precompiled_programs, found->second, host_ptr); |
| 576 | } else { | 580 | } else { |
| 577 | shader = std::make_shared<CachedShader>( | 581 | // Create a shader from guest memory |
| 578 | device, cpu_addr, unique_identifier, program, disk_cache, precompiled_programs, | 582 | shader = std::make_shared<CachedShader>( |
| 579 | std::move(program_code), std::move(program_code_b), host_ptr); | 583 | device, cpu_addr, unique_identifier, program, disk_cache, precompiled_programs, |
| 580 | } | 584 | std::move(program_code), std::move(program_code_b), host_ptr); |
| 581 | Register(shader); | ||
| 582 | } | 585 | } |
| 586 | Register(shader); | ||
| 583 | 587 | ||
| 584 | return last_shaders[static_cast<u32>(program)] = shader; | 588 | return last_shaders[static_cast<std::size_t>(program)] = shader; |
| 585 | } | 589 | } |
| 586 | 590 | ||
| 587 | } // namespace OpenGL | 591 | } // namespace OpenGL |
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h index 64e5a5594..09bd0761d 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_cache.h | |||
| @@ -137,6 +137,7 @@ private: | |||
| 137 | CachedProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump, | 137 | CachedProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump, |
| 138 | const std::set<GLenum>& supported_formats); | 138 | const std::set<GLenum>& supported_formats); |
| 139 | 139 | ||
| 140 | Core::System& system; | ||
| 140 | Core::Frontend::EmuWindow& emu_window; | 141 | Core::Frontend::EmuWindow& emu_window; |
| 141 | const Device& device; | 142 | const Device& device; |
| 142 | ShaderDiskCacheOpenGL disk_cache; | 143 | ShaderDiskCacheOpenGL disk_cache; |