forked from ShuriZma/suyu
1
0
Fork 0

Merge pull request #2534 from ReinUsesLisp/shader-cleanup

gl_shader_cache: Minor style changes
This commit is contained in:
Zach Hilman 2019-06-05 15:28:34 -04:00 committed by GitHub
commit dd4fe0dab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 32 deletions

View File

@ -35,8 +35,8 @@ struct UnspecializedShader {
namespace { namespace {
/// Gets the address for the specified shader stage program /// Gets the address for the specified shader stage program
GPUVAddr GetShaderAddress(Maxwell::ShaderProgram program) { GPUVAddr GetShaderAddress(Core::System& system, Maxwell::ShaderProgram program) {
const auto& gpu{Core::System::GetInstance().GPU().Maxwell3D()}; const auto& gpu{system.GPU().Maxwell3D()};
const auto& shader_config{gpu.regs.shader_config[static_cast<std::size_t>(program)]}; const auto& shader_config{gpu.regs.shader_config[static_cast<std::size_t>(program)]};
return gpu.regs.code_address.CodeAddress() + shader_config.offset; return gpu.regs.code_address.CodeAddress() + shader_config.offset;
} }
@ -350,7 +350,8 @@ ShaderDiskCacheUsage CachedShader::GetUsage(GLenum primitive_mode,
ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer, Core::System& system, ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer, Core::System& system,
Core::Frontend::EmuWindow& emu_window, const Device& device) Core::Frontend::EmuWindow& emu_window, const Device& device)
: RasterizerCache{rasterizer}, emu_window{emu_window}, device{device}, disk_cache{system} {} : RasterizerCache{rasterizer}, system{system}, emu_window{emu_window}, device{device},
disk_cache{system} {}
void ShaderCacheOpenGL::LoadDiskCache(const std::atomic_bool& stop_loading, void ShaderCacheOpenGL::LoadDiskCache(const std::atomic_bool& stop_loading,
const VideoCore::DiskResourceLoadCallback& callback) { const VideoCore::DiskResourceLoadCallback& callback) {
@ -546,42 +547,45 @@ std::unordered_map<u64, UnspecializedShader> ShaderCacheOpenGL::GenerateUnspecia
} }
Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) {
if (!Core::System::GetInstance().GPU().Maxwell3D().dirty_flags.shaders) { if (!system.GPU().Maxwell3D().dirty_flags.shaders) {
return last_shaders[static_cast<u32>(program)]; return last_shaders[static_cast<std::size_t>(program)];
} }
auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()}; auto& memory_manager{system.GPU().MemoryManager()};
const GPUVAddr program_addr{GetShaderAddress(program)}; const GPUVAddr program_addr{GetShaderAddress(system, program)};
// Look up shader in the cache based on address // Look up shader in the cache based on address
const auto& host_ptr{memory_manager.GetPointer(program_addr)}; const auto host_ptr{memory_manager.GetPointer(program_addr)};
Shader shader{TryGet(host_ptr)}; Shader shader{TryGet(host_ptr)};
if (shader) {
return last_shaders[static_cast<std::size_t>(program)] = shader;
}
if (!shader) {
// No shader found - create a new one // No shader found - create a new one
ProgramCode program_code{GetShaderCode(memory_manager, program_addr, host_ptr)}; ProgramCode program_code{GetShaderCode(memory_manager, program_addr, host_ptr)};
ProgramCode program_code_b; ProgramCode program_code_b;
if (program == Maxwell::ShaderProgram::VertexA) { if (program == Maxwell::ShaderProgram::VertexA) {
const GPUVAddr program_addr_b{GetShaderAddress(Maxwell::ShaderProgram::VertexB)}; const GPUVAddr program_addr_b{GetShaderAddress(system, Maxwell::ShaderProgram::VertexB)};
program_code_b = GetShaderCode(memory_manager, program_addr_b, program_code_b = GetShaderCode(memory_manager, program_addr_b,
memory_manager.GetPointer(program_addr_b)); memory_manager.GetPointer(program_addr_b));
} }
const u64 unique_identifier = GetUniqueIdentifier(program, program_code, program_code_b); const u64 unique_identifier = GetUniqueIdentifier(program, program_code, program_code_b);
const VAddr cpu_addr{*memory_manager.GpuToCpuAddress(program_addr)}; const VAddr cpu_addr{*memory_manager.GpuToCpuAddress(program_addr)};
const auto found = precompiled_shaders.find(unique_identifier); const auto found = precompiled_shaders.find(unique_identifier);
if (found != precompiled_shaders.end()) { if (found != precompiled_shaders.end()) {
shader = // Create a shader from the cache
std::make_shared<CachedShader>(cpu_addr, unique_identifier, program, disk_cache, shader = std::make_shared<CachedShader>(cpu_addr, unique_identifier, program, disk_cache,
precompiled_programs, found->second, host_ptr); precompiled_programs, found->second, host_ptr);
} else { } else {
// Create a shader from guest memory
shader = std::make_shared<CachedShader>( shader = std::make_shared<CachedShader>(
device, cpu_addr, unique_identifier, program, disk_cache, precompiled_programs, device, cpu_addr, unique_identifier, program, disk_cache, precompiled_programs,
std::move(program_code), std::move(program_code_b), host_ptr); std::move(program_code), std::move(program_code_b), host_ptr);
} }
Register(shader); Register(shader);
}
return last_shaders[static_cast<u32>(program)] = shader; return last_shaders[static_cast<std::size_t>(program)] = shader;
} }
} // namespace OpenGL } // namespace OpenGL

View File

@ -137,6 +137,7 @@ private:
CachedProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump, CachedProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump,
const std::set<GLenum>& supported_formats); const std::set<GLenum>& supported_formats);
Core::System& system;
Core::Frontend::EmuWindow& emu_window; Core::Frontend::EmuWindow& emu_window;
const Device& device; const Device& device;
ShaderDiskCacheOpenGL disk_cache; ShaderDiskCacheOpenGL disk_cache;