gl_shader_disk_cache: Address miscellaneous feedback

master
ReinUsesLisp 2019-01-15 02:42:25 +07:00
parent 8ee3666a3c
commit 750abcc23d
5 changed files with 57 additions and 43 deletions

@ -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) {

@ -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;

@ -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,

@ -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) {

@ -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);