From 750abcc23d0b9584b716ab93110383209b0971f8 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Tue, 15 Jan 2019 02:42:25 -0300 Subject: [PATCH] gl_shader_disk_cache: Address miscellaneous feedback --- .../renderer_opengl/gl_shader_cache.cpp | 6 +-- .../renderer_opengl/gl_shader_cache.h | 6 +-- .../renderer_opengl/gl_shader_decompiler.h | 8 +-- .../renderer_opengl/gl_shader_disk_cache.cpp | 26 ++++++--- .../renderer_opengl/gl_shader_disk_cache.h | 54 ++++++++++--------- 5 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 49b872c44f..6acfd16496 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp @@ -181,7 +181,8 @@ CachedProgram SpecializeShader(const std::string& code, const GLShader::ShaderEn } if (program_type == Maxwell::ShaderProgram::Geometry) { - const auto [glsl_topology, _, max_vertices] = GetPrimitiveDescription(primitive_mode); + const auto [glsl_topology, debug_name, max_vertices] = + GetPrimitiveDescription(primitive_mode); source += "layout (" + std::string(glsl_topology) + ") in;\n"; source += "#define MAX_VERTEX_INPUT " + std::to_string(max_vertices) + '\n'; @@ -314,7 +315,7 @@ GLuint CachedShader::LazyGeometryProgram(CachedProgram& target_program, BaseBind if (target_program) { return target_program->handle; } - const auto [_, debug_name, __] = GetPrimitiveDescription(primitive_mode); + const auto [glsl_name, debug_name, vertices] = GetPrimitiveDescription(primitive_mode); target_program = TryLoadProgram(primitive_mode, base_bindings); if (!target_program) { target_program = @@ -419,7 +420,6 @@ CachedProgram ShaderCacheOpenGL::GeneratePrecompiledProgram( std::map ShaderCacheOpenGL::GenerateUnspecializedShaders( const std::vector& raws, const std::map& decompiled) { - std::map unspecialized; for (const auto& raw : raws) { diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h index 3b5a82f8ad..c6a621ae39 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_cache.h @@ -86,9 +86,9 @@ private: ShaderDiskCacheUsage GetUsage(GLenum primitive_mode, BaseBindings base_bindings) const; - const VAddr addr; - const u64 unique_identifier; - const Maxwell::ShaderProgram program_type; + VAddr addr{}; + u64 unique_identifier{}; + Maxwell::ShaderProgram program_type{}; ShaderDiskCacheOpenGL& disk_cache; const PrecompiledPrograms& precompiled_programs; diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.h b/src/video_core/renderer_opengl/gl_shader_decompiler.h index 0031cb6143..72aca49382 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.h +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.h @@ -19,7 +19,11 @@ class ShaderIR; namespace OpenGL::GLShader { +struct ShaderEntries; + using Maxwell = Tegra::Engines::Maxwell3D::Regs; +using ProgramResult = std::pair; +using SamplerEntry = VideoCommon::Shader::Sampler; class ConstBufferEntry : public VideoCommon::Shader::ConstBuffer { public: @@ -34,8 +38,6 @@ private: u32 index{}; }; -using SamplerEntry = VideoCommon::Shader::Sampler; - class GlobalMemoryEntry { public: explicit GlobalMemoryEntry(u32 cbuf_index, u32 cbuf_offset) @@ -62,8 +64,6 @@ struct ShaderEntries { std::size_t shader_length{}; }; -using ProgramResult = std::pair; - std::string GetCommonDeclarations(); ProgramResult Decompile(const VideoCommon::Shader::ShaderIR& ir, Maxwell::ShaderStage stage, diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index 7783e3c019..5157e319a8 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -49,7 +49,7 @@ std::string GetTitleID() { std::string GetShaderHash() { std::array hash{}; std::strncpy(hash.data(), Common::g_shader_cache_version, ShaderHashSize); - return std::string(hash.data()); + return std::string(hash.data(), hash.size()); } template @@ -86,7 +86,8 @@ ShaderDiskCacheRaw::ShaderDiskCacheRaw(FileUtil::IOFile& file) { file.ReadBytes(&unique_identifier, sizeof(u64)); file.ReadBytes(&program_type, sizeof(u32)); - u32 program_code_size{}, program_code_size_b{}; + u32 program_code_size{}; + u32 program_code_size_b{}; file.ReadBytes(&program_code_size, sizeof(u32)); file.ReadBytes(&program_code_size_b, sizeof(u32)); @@ -99,6 +100,15 @@ ShaderDiskCacheRaw::ShaderDiskCacheRaw(FileUtil::IOFile& file) { } } +ShaderDiskCacheRaw::ShaderDiskCacheRaw(u64 unique_identifier, Maxwell::ShaderProgram program_type, + u32 program_code_size, u32 program_code_size_b, + ProgramCode program_code, ProgramCode program_code_b) + : unique_identifier{unique_identifier}, program_type{program_type}, + program_code_size{program_code_size}, program_code_size_b{program_code_size_b}, + program_code{std::move(program_code)}, program_code_b{std::move(program_code_b)} {} + +ShaderDiskCacheRaw::~ShaderDiskCacheRaw() = default; + void ShaderDiskCacheRaw::Save(FileUtil::IOFile& file) const { file.WriteObject(unique_identifier); file.WriteObject(static_cast(program_type)); @@ -186,7 +196,7 @@ ShaderDiskCacheOpenGL::LoadPrecompiled() { char precompiled_hash[ShaderHashSize]; file.ReadBytes(&precompiled_hash, ShaderHashSize); - if (std::string(precompiled_hash) != GetShaderHash()) { + if (precompiled_hash != GetShaderHash()) { LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing"); file.Close(); InvalidatePrecompiled(); @@ -311,13 +321,13 @@ ShaderDiskCacheOpenGL::LoadPrecompiled() { return {decompiled, dumps}; } -void ShaderDiskCacheOpenGL::InvalidateTransferable() const { - FileUtil::Delete(GetTransferablePath()); - InvalidatePrecompiled(); +bool ShaderDiskCacheOpenGL::InvalidateTransferable() const { + const bool success = FileUtil::Delete(GetTransferablePath()); + return InvalidatePrecompiled() && success; } -void ShaderDiskCacheOpenGL::InvalidatePrecompiled() const { - FileUtil::Delete(GetPrecompiledPath()); +bool ShaderDiskCacheOpenGL::InvalidatePrecompiled() const { + return FileUtil::Delete(GetPrecompiledPath()); } void ShaderDiskCacheOpenGL::SaveRaw(const ShaderDiskCacheRaw& entry) { diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.h b/src/video_core/renderer_opengl/gl_shader_disk_cache.h index c44a776d92..4bffe4307d 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h @@ -15,22 +15,20 @@ #include "common/assert.h" #include "common/common_types.h" -#include "common/file_util.h" #include "video_core/engines/maxwell_3d.h" #include "video_core/renderer_opengl/gl_shader_gen.h" +namespace FileUtil { +class IOFile; +} // namespace FileUtil + namespace OpenGL { using ProgramCode = std::vector; using Maxwell = Tegra::Engines::Maxwell3D::Regs; +/// Allocated bindings used by an OpenGL shader program struct BaseBindings { -private: - auto Tie() const { - return std::tie(cbuf, gmem, sampler); - } - -public: u32 cbuf{}; u32 gmem{}; u32 sampler{}; @@ -44,20 +42,24 @@ public: } bool operator!=(const BaseBindings& rhs) const { - return !this->operator==(rhs); + return !operator==(rhs); + } + + std::tuple Tie() const { + return std::tie(cbuf, gmem, sampler); } }; +/// Describes a shader how it's used by the guest GPU class ShaderDiskCacheRaw { public: explicit ShaderDiskCacheRaw(FileUtil::IOFile& file); explicit ShaderDiskCacheRaw(u64 unique_identifier, Maxwell::ShaderProgram program_type, u32 program_code_size, u32 program_code_size_b, - ProgramCode program_code, ProgramCode program_code_b) - : unique_identifier{unique_identifier}, program_type{program_type}, - program_code_size{program_code_size}, program_code_size_b{program_code_size_b}, - program_code{std::move(program_code)}, program_code_b{std::move(program_code_b)} {} + ProgramCode program_code, ProgramCode program_code_b); + + ~ShaderDiskCacheRaw(); void Save(FileUtil::IOFile& file) const; @@ -108,17 +110,8 @@ private: ProgramCode program_code_b; }; +/// Describes how a shader is used struct ShaderDiskCacheUsage { -private: - auto Tie() const { - return std::tie(unique_identifier, bindings, primitive); - } - -public: - u64 unique_identifier{}; - BaseBindings bindings; - GLenum primitive{}; - bool operator<(const ShaderDiskCacheUsage& rhs) const { return Tie() < rhs.Tie(); } @@ -128,15 +121,26 @@ public: } bool operator!=(const ShaderDiskCacheUsage& rhs) const { - return !this->operator==(rhs); + return !operator==(rhs); + } + + u64 unique_identifier{}; + BaseBindings bindings; + GLenum primitive{}; + +private: + std::tuple Tie() const { + return std::tie(unique_identifier, bindings, primitive); } }; +/// Contains decompiled data from a shader struct ShaderDiskCacheDecompiled { std::string code; GLShader::ShaderEntries entries; }; +/// Contains an OpenGL dumped binary program struct ShaderDiskCacheDump { GLenum binary_format; std::vector binary; @@ -154,10 +158,10 @@ public: LoadPrecompiled(); /// Removes the transferable (and precompiled) cache file. - void InvalidateTransferable() const; + bool InvalidateTransferable() const; /// Removes the precompiled cache file. - void InvalidatePrecompiled() const; + bool InvalidatePrecompiled() const; /// Saves a raw dump to the transferable file. Checks for collisions. void SaveRaw(const ShaderDiskCacheRaw& entry);