diff options
| author | 2019-07-03 20:20:05 -0400 | |
|---|---|---|
| committer | 2019-07-03 20:20:05 -0400 | |
| commit | da5a537029a374053066a74186228f63b8344943 (patch) | |
| tree | 39abdf8a0a5077b87d87b1402027fa8e010c1971 /src | |
| parent | Merge pull request #2604 from ogniK5377/INotificationService (diff) | |
| parent | gl_shader_cache: Use static constructors for CachedShader initialization (diff) | |
| download | yuzu-da5a537029a374053066a74186228f63b8344943.tar.gz yuzu-da5a537029a374053066a74186228f63b8344943.tar.xz yuzu-da5a537029a374053066a74186228f63b8344943.zip | |
Merge pull request #2563 from ReinUsesLisp/shader-initializers
gl_shader_cache: Use static constructors for CachedShader initialization
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 76 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.h | 29 |
2 files changed, 53 insertions, 52 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index ac8a9e6b7..2d78e2b60 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -221,44 +221,37 @@ std::set<GLenum> GetSupportedFormats() { | |||
| 221 | 221 | ||
| 222 | } // Anonymous namespace | 222 | } // Anonymous namespace |
| 223 | 223 | ||
| 224 | CachedShader::CachedShader(const Device& device, VAddr cpu_addr, u64 unique_identifier, | 224 | CachedShader::CachedShader(const ShaderParameters& params, Maxwell::ShaderProgram program_type, |
| 225 | Maxwell::ShaderProgram program_type, ShaderDiskCacheOpenGL& disk_cache, | 225 | GLShader::ProgramResult result) |
| 226 | const PrecompiledPrograms& precompiled_programs, | 226 | : RasterizerCacheObject{params.host_ptr}, host_ptr{params.host_ptr}, cpu_addr{params.cpu_addr}, |
| 227 | ProgramCode&& program_code, ProgramCode&& program_code_b, u8* host_ptr) | 227 | unique_identifier{params.unique_identifier}, program_type{program_type}, |
| 228 | : RasterizerCacheObject{host_ptr}, host_ptr{host_ptr}, cpu_addr{cpu_addr}, | 228 | disk_cache{params.disk_cache}, precompiled_programs{params.precompiled_programs}, |
| 229 | unique_identifier{unique_identifier}, program_type{program_type}, disk_cache{disk_cache}, | 229 | entries{result.second}, code{std::move(result.first)}, shader_length{entries.shader_length} {} |
| 230 | precompiled_programs{precompiled_programs} { | 230 | |
| 231 | const std::size_t code_size{CalculateProgramSize(program_code)}; | 231 | Shader CachedShader::CreateStageFromMemory(const ShaderParameters& params, |
| 232 | const std::size_t code_size_b{program_code_b.empty() ? 0 | 232 | Maxwell::ShaderProgram program_type, |
| 233 | : CalculateProgramSize(program_code_b)}; | 233 | ProgramCode&& program_code, |
| 234 | GLShader::ProgramResult program_result{ | 234 | ProgramCode&& program_code_b) { |
| 235 | CreateProgram(device, program_type, program_code, program_code_b)}; | 235 | const auto code_size{CalculateProgramSize(program_code)}; |
| 236 | if (program_result.first.empty()) { | 236 | const auto code_size_b{CalculateProgramSize(program_code_b)}; |
| 237 | auto result{CreateProgram(params.device, program_type, program_code, program_code_b)}; | ||
| 238 | if (result.first.empty()) { | ||
| 237 | // TODO(Rodrigo): Unimplemented shader stages hit here, avoid using these for now | 239 | // TODO(Rodrigo): Unimplemented shader stages hit here, avoid using these for now |
| 238 | return; | 240 | return {}; |
| 239 | } | 241 | } |
| 240 | 242 | ||
| 241 | code = program_result.first; | 243 | params.disk_cache.SaveRaw(ShaderDiskCacheRaw( |
| 242 | entries = program_result.second; | 244 | params.unique_identifier, program_type, static_cast<u32>(code_size / sizeof(u64)), |
| 243 | shader_length = entries.shader_length; | 245 | static_cast<u32>(code_size_b / sizeof(u64)), std::move(program_code), |
| 246 | std::move(program_code_b))); | ||
| 244 | 247 | ||
| 245 | const ShaderDiskCacheRaw raw(unique_identifier, program_type, | 248 | return std::make_shared<CachedShader>(params, program_type, std::move(result)); |
| 246 | static_cast<u32>(code_size / sizeof(u64)), | ||
| 247 | static_cast<u32>(code_size_b / sizeof(u64)), | ||
| 248 | std::move(program_code), std::move(program_code_b)); | ||
| 249 | disk_cache.SaveRaw(raw); | ||
| 250 | } | 249 | } |
| 251 | 250 | ||
| 252 | CachedShader::CachedShader(VAddr cpu_addr, u64 unique_identifier, | 251 | Shader CachedShader::CreateStageFromCache(const ShaderParameters& params, |
| 253 | Maxwell::ShaderProgram program_type, ShaderDiskCacheOpenGL& disk_cache, | 252 | Maxwell::ShaderProgram program_type, |
| 254 | const PrecompiledPrograms& precompiled_programs, | 253 | GLShader::ProgramResult result) { |
| 255 | GLShader::ProgramResult result, u8* host_ptr) | 254 | return std::make_shared<CachedShader>(params, program_type, std::move(result)); |
| 256 | : RasterizerCacheObject{host_ptr}, cpu_addr{cpu_addr}, unique_identifier{unique_identifier}, | ||
| 257 | program_type{program_type}, disk_cache{disk_cache}, precompiled_programs{ | ||
| 258 | precompiled_programs} { | ||
| 259 | code = std::move(result.first); | ||
| 260 | entries = result.second; | ||
| 261 | shader_length = entries.shader_length; | ||
| 262 | } | 255 | } |
| 263 | 256 | ||
| 264 | std::tuple<GLuint, BaseBindings> CachedShader::GetProgramHandle(GLenum primitive_mode, | 257 | std::tuple<GLuint, BaseBindings> CachedShader::GetProgramHandle(GLenum primitive_mode, |
| @@ -570,18 +563,17 @@ Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { | |||
| 570 | memory_manager.GetPointer(program_addr_b)); | 563 | memory_manager.GetPointer(program_addr_b)); |
| 571 | } | 564 | } |
| 572 | 565 | ||
| 573 | const u64 unique_identifier = GetUniqueIdentifier(program, program_code, program_code_b); | 566 | const auto unique_identifier = GetUniqueIdentifier(program, program_code, program_code_b); |
| 574 | const VAddr cpu_addr{*memory_manager.GpuToCpuAddress(program_addr)}; | 567 | const auto cpu_addr{*memory_manager.GpuToCpuAddress(program_addr)}; |
| 568 | const ShaderParameters params{disk_cache, precompiled_programs, device, cpu_addr, | ||
| 569 | host_ptr, unique_identifier}; | ||
| 570 | |||
| 575 | const auto found = precompiled_shaders.find(unique_identifier); | 571 | const auto found = precompiled_shaders.find(unique_identifier); |
| 576 | if (found != precompiled_shaders.end()) { | 572 | if (found == precompiled_shaders.end()) { |
| 577 | // Create a shader from the cache | 573 | shader = CachedShader::CreateStageFromMemory(params, program, std::move(program_code), |
| 578 | shader = std::make_shared<CachedShader>(cpu_addr, unique_identifier, program, disk_cache, | 574 | std::move(program_code_b)); |
| 579 | precompiled_programs, found->second, host_ptr); | ||
| 580 | } else { | 575 | } else { |
| 581 | // Create a shader from guest memory | 576 | shader = CachedShader::CreateStageFromCache(params, program, found->second); |
| 582 | shader = std::make_shared<CachedShader>( | ||
| 583 | device, cpu_addr, unique_identifier, program, disk_cache, precompiled_programs, | ||
| 584 | std::move(program_code), std::move(program_code_b), host_ptr); | ||
| 585 | } | 577 | } |
| 586 | Register(shader); | 578 | Register(shader); |
| 587 | 579 | ||
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h index 09bd0761d..964f680bc 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_cache.h | |||
| @@ -41,17 +41,27 @@ using Maxwell = Tegra::Engines::Maxwell3D::Regs; | |||
| 41 | using PrecompiledPrograms = std::unordered_map<ShaderDiskCacheUsage, CachedProgram>; | 41 | using PrecompiledPrograms = std::unordered_map<ShaderDiskCacheUsage, CachedProgram>; |
| 42 | using PrecompiledShaders = std::unordered_map<u64, GLShader::ProgramResult>; | 42 | using PrecompiledShaders = std::unordered_map<u64, GLShader::ProgramResult>; |
| 43 | 43 | ||
| 44 | struct ShaderParameters { | ||
| 45 | ShaderDiskCacheOpenGL& disk_cache; | ||
| 46 | const PrecompiledPrograms& precompiled_programs; | ||
| 47 | const Device& device; | ||
| 48 | VAddr cpu_addr; | ||
| 49 | u8* host_ptr; | ||
| 50 | u64 unique_identifier; | ||
| 51 | }; | ||
| 52 | |||
| 44 | class CachedShader final : public RasterizerCacheObject { | 53 | class CachedShader final : public RasterizerCacheObject { |
| 45 | public: | 54 | public: |
| 46 | explicit CachedShader(const Device& device, VAddr cpu_addr, u64 unique_identifier, | 55 | explicit CachedShader(const ShaderParameters& params, Maxwell::ShaderProgram program_type, |
| 47 | Maxwell::ShaderProgram program_type, ShaderDiskCacheOpenGL& disk_cache, | 56 | GLShader::ProgramResult result); |
| 48 | const PrecompiledPrograms& precompiled_programs, | ||
| 49 | ProgramCode&& program_code, ProgramCode&& program_code_b, u8* host_ptr); | ||
| 50 | 57 | ||
| 51 | explicit CachedShader(VAddr cpu_addr, u64 unique_identifier, | 58 | static Shader CreateStageFromMemory(const ShaderParameters& params, |
| 52 | Maxwell::ShaderProgram program_type, ShaderDiskCacheOpenGL& disk_cache, | 59 | Maxwell::ShaderProgram program_type, |
| 53 | const PrecompiledPrograms& precompiled_programs, | 60 | ProgramCode&& program_code, ProgramCode&& program_code_b); |
| 54 | GLShader::ProgramResult result, u8* host_ptr); | 61 | |
| 62 | static Shader CreateStageFromCache(const ShaderParameters& params, | ||
| 63 | Maxwell::ShaderProgram program_type, | ||
| 64 | GLShader::ProgramResult result); | ||
| 55 | 65 | ||
| 56 | VAddr GetCpuAddr() const override { | 66 | VAddr GetCpuAddr() const override { |
| 57 | return cpu_addr; | 67 | return cpu_addr; |
| @@ -99,10 +109,9 @@ private: | |||
| 99 | ShaderDiskCacheOpenGL& disk_cache; | 109 | ShaderDiskCacheOpenGL& disk_cache; |
| 100 | const PrecompiledPrograms& precompiled_programs; | 110 | const PrecompiledPrograms& precompiled_programs; |
| 101 | 111 | ||
| 102 | std::size_t shader_length{}; | ||
| 103 | GLShader::ShaderEntries entries; | 112 | GLShader::ShaderEntries entries; |
| 104 | |||
| 105 | std::string code; | 113 | std::string code; |
| 114 | std::size_t shader_length{}; | ||
| 106 | 115 | ||
| 107 | std::unordered_map<BaseBindings, CachedProgram> programs; | 116 | std::unordered_map<BaseBindings, CachedProgram> programs; |
| 108 | std::unordered_map<BaseBindings, GeometryPrograms> geometry_programs; | 117 | std::unordered_map<BaseBindings, GeometryPrograms> geometry_programs; |