diff options
author | bunnei <bunneidev@gmail.com> | 2019-03-17 02:59:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-17 02:59:45 +0100 |
commit | 2392e146b09c2a4b3bb557bb3a20c4afc7f75957 (patch) | |
tree | 1eafa50be7af78d74b4781fbe858277ac8ab1d35 /src/video_core/renderer_opengl/gl_shader_cache.cpp | |
parent | Merge pull request #2243 from bunnei/mem-simplify-cache (diff) | |
parent | video_core: Refactor to use MemoryManager interface for all memory access. (diff) | |
download | yuzu-2392e146b09c2a4b3bb557bb3a20c4afc7f75957.tar yuzu-2392e146b09c2a4b3bb557bb3a20c4afc7f75957.tar.gz yuzu-2392e146b09c2a4b3bb557bb3a20c4afc7f75957.tar.bz2 yuzu-2392e146b09c2a4b3bb557bb3a20c4afc7f75957.tar.lz yuzu-2392e146b09c2a4b3bb557bb3a20c4afc7f75957.tar.xz yuzu-2392e146b09c2a4b3bb557bb3a20c4afc7f75957.tar.zst yuzu-2392e146b09c2a4b3bb557bb3a20c4afc7f75957.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 60a04e146..1ed740877 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp @@ -32,13 +32,10 @@ struct UnspecializedShader { namespace { /// Gets the address for the specified shader stage program -VAddr GetShaderAddress(Maxwell::ShaderProgram program) { - const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D(); - const auto& shader_config = gpu.regs.shader_config[static_cast<std::size_t>(program)]; - const auto address = gpu.memory_manager.GpuToCpuAddress(gpu.regs.code_address.CodeAddress() + - shader_config.offset); - ASSERT_MSG(address, "Invalid GPU address"); - return *address; +Tegra::GPUVAddr GetShaderAddress(Maxwell::ShaderProgram program) { + const auto& gpu{Core::System::GetInstance().GPU().Maxwell3D()}; + const auto& shader_config{gpu.regs.shader_config[static_cast<std::size_t>(program)]}; + return gpu.regs.code_address.CodeAddress() + shader_config.offset; } /// Gets the shader program code from memory for the specified address @@ -214,11 +211,11 @@ std::set<GLenum> GetSupportedFormats() { } // namespace -CachedShader::CachedShader(VAddr guest_addr, u64 unique_identifier, +CachedShader::CachedShader(VAddr cpu_addr, u64 unique_identifier, Maxwell::ShaderProgram program_type, ShaderDiskCacheOpenGL& disk_cache, const PrecompiledPrograms& precompiled_programs, ProgramCode&& program_code, ProgramCode&& program_code_b, u8* host_ptr) - : host_ptr{host_ptr}, guest_addr{guest_addr}, unique_identifier{unique_identifier}, + : host_ptr{host_ptr}, cpu_addr{cpu_addr}, unique_identifier{unique_identifier}, program_type{program_type}, disk_cache{disk_cache}, precompiled_programs{precompiled_programs}, RasterizerCacheObject{host_ptr} { @@ -244,11 +241,11 @@ CachedShader::CachedShader(VAddr guest_addr, u64 unique_identifier, disk_cache.SaveRaw(raw); } -CachedShader::CachedShader(VAddr guest_addr, u64 unique_identifier, +CachedShader::CachedShader(VAddr cpu_addr, u64 unique_identifier, Maxwell::ShaderProgram program_type, ShaderDiskCacheOpenGL& disk_cache, const PrecompiledPrograms& precompiled_programs, GLShader::ProgramResult result, u8* host_ptr) - : guest_addr{guest_addr}, unique_identifier{unique_identifier}, program_type{program_type}, + : cpu_addr{cpu_addr}, unique_identifier{unique_identifier}, program_type{program_type}, disk_cache{disk_cache}, precompiled_programs{precompiled_programs}, RasterizerCacheObject{ host_ptr} { @@ -273,7 +270,7 @@ std::tuple<GLuint, BaseBindings> CachedShader::GetProgramHandle(GLenum primitive disk_cache.SaveUsage(GetUsage(primitive_mode, base_bindings)); } - LabelGLObject(GL_PROGRAM, program->handle, guest_addr); + LabelGLObject(GL_PROGRAM, program->handle, cpu_addr); } handle = program->handle; @@ -325,7 +322,7 @@ GLuint CachedShader::LazyGeometryProgram(CachedProgram& target_program, BaseBind disk_cache.SaveUsage(GetUsage(primitive_mode, base_bindings)); } - LabelGLObject(GL_PROGRAM, target_program->handle, guest_addr, debug_name); + LabelGLObject(GL_PROGRAM, target_program->handle, cpu_addr, debug_name); return target_program->handle; }; @@ -488,31 +485,31 @@ Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { return last_shaders[static_cast<u32>(program)]; } - const VAddr program_addr{GetShaderAddress(program)}; + auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()}; + const Tegra::GPUVAddr program_addr{GetShaderAddress(program)}; // Look up shader in the cache based on address - const auto& host_ptr{Memory::GetPointer(program_addr)}; + const auto& host_ptr{memory_manager.GetPointer(program_addr)}; Shader shader{TryGet(host_ptr)}; if (!shader) { // No shader found - create a new one - const auto& host_ptr{Memory::GetPointer(program_addr)}; ProgramCode program_code{GetShaderCode(host_ptr)}; ProgramCode program_code_b; if (program == Maxwell::ShaderProgram::VertexA) { program_code_b = GetShaderCode( - Memory::GetPointer(GetShaderAddress(Maxwell::ShaderProgram::VertexB))); + memory_manager.GetPointer(GetShaderAddress(Maxwell::ShaderProgram::VertexB))); } const u64 unique_identifier = GetUniqueIdentifier(program, program_code, program_code_b); - + const VAddr cpu_addr{*memory_manager.GpuToCpuAddress(program_addr)}; const auto found = precompiled_shaders.find(unique_identifier); if (found != precompiled_shaders.end()) { shader = - std::make_shared<CachedShader>(program_addr, unique_identifier, program, disk_cache, + std::make_shared<CachedShader>(cpu_addr, unique_identifier, program, disk_cache, precompiled_programs, found->second, host_ptr); } else { shader = std::make_shared<CachedShader>( - program_addr, unique_identifier, program, disk_cache, precompiled_programs, + cpu_addr, unique_identifier, program, disk_cache, precompiled_programs, std::move(program_code), std::move(program_code_b), host_ptr); } Register(shader); |