summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2019-01-15 06:42:25 +0100
committerReinUsesLisp <reinuseslisp@airmail.cc>2019-02-07 02:23:40 +0100
commit750abcc23d0b9584b716ab93110383209b0971f8 (patch)
treef8299f57d6354c8e2020f3b34e3a50c5c9883fea /src/video_core/renderer_opengl
parentgl_shader_disk_cache: Pass return values returning instead of by parameters (diff)
downloadyuzu-750abcc23d0b9584b716ab93110383209b0971f8.tar
yuzu-750abcc23d0b9584b716ab93110383209b0971f8.tar.gz
yuzu-750abcc23d0b9584b716ab93110383209b0971f8.tar.bz2
yuzu-750abcc23d0b9584b716ab93110383209b0971f8.tar.lz
yuzu-750abcc23d0b9584b716ab93110383209b0971f8.tar.xz
yuzu-750abcc23d0b9584b716ab93110383209b0971f8.tar.zst
yuzu-750abcc23d0b9584b716ab93110383209b0971f8.zip
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp6
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.h6
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.h8
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp26
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.h54
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 49b872c44..6acfd1649 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<u64, UnspecializedShader> ShaderCacheOpenGL::GenerateUnspecializedShaders(
const std::vector<ShaderDiskCacheRaw>& raws,
const std::map<u64, ShaderDiskCacheDecompiled>& decompiled) {
-
std::map<u64, UnspecializedShader> 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 3b5a82f8a..c6a621ae3 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 0031cb614..72aca4938 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<std::string, ShaderEntries>;
+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, ShaderEntries>;
-
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 7783e3c01..5157e319a 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<char, ShaderHashSize> hash{};
std::strncpy(hash.data(), Common::g_shader_cache_version, ShaderHashSize);
- return std::string(hash.data());
+ return std::string(hash.data(), hash.size());
}
template <typename T>
@@ -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<u32>(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 c44a776d9..4bffe4307 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<u64>;
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<u32, u32, u32> 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<u64, BaseBindings, GLenum> 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<u8> 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);