summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-04-07 10:51:42 +0200
committerbunnei <bunneidev@gmail.com>2018-04-14 05:48:23 +0200
commit10953495c1b7de412312b64370d99a2294dfe6a2 (patch)
treefb576ffbb201e6e2f88a4f91d7974bb307010d16 /src
parentgl_shader_util: Add missing includes. (diff)
downloadyuzu-10953495c1b7de412312b64370d99a2294dfe6a2.tar
yuzu-10953495c1b7de412312b64370d99a2294dfe6a2.tar.gz
yuzu-10953495c1b7de412312b64370d99a2294dfe6a2.tar.bz2
yuzu-10953495c1b7de412312b64370d99a2294dfe6a2.tar.lz
yuzu-10953495c1b7de412312b64370d99a2294dfe6a2.tar.xz
yuzu-10953495c1b7de412312b64370d99a2294dfe6a2.tar.zst
yuzu-10953495c1b7de412312b64370d99a2294dfe6a2.zip
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp4
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.h75
2 files changed, 50 insertions, 29 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 8f3c98800..524c2cfb5 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -7,12 +7,12 @@
namespace GLShader {
-std::string GenerateVertexShader(const MaxwellVSConfig& config) {
+std::string GenerateVertexShader(const ShaderSetup& setup, const MaxwellVSConfig& config) {
UNREACHABLE();
return {};
}
-std::string GenerateFragmentShader(const MaxwellFSConfig& config) {
+std::string GenerateFragmentShader(const ShaderSetup& setup, const MaxwellFSConfig& config) {
UNREACHABLE();
return {};
}
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h
index 5101e7d30..925e66ee4 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.h
+++ b/src/video_core/renderer_opengl/gl_shader_gen.h
@@ -4,46 +4,67 @@
#pragma once
-#include <cstring>
+#include <array>
#include <string>
#include <type_traits>
+#include "common/common_types.h"
#include "common/hash.h"
namespace GLShader {
-enum Attributes {
- ATTRIBUTE_POSITION,
- ATTRIBUTE_COLOR,
- ATTRIBUTE_TEXCOORD0,
- ATTRIBUTE_TEXCOORD1,
- ATTRIBUTE_TEXCOORD2,
- ATTRIBUTE_TEXCOORD0_W,
- ATTRIBUTE_NORMQUAT,
- ATTRIBUTE_VIEW,
-};
+constexpr size_t MAX_PROGRAM_CODE_LENGTH{0x1000};
-struct MaxwellShaderConfigCommon {
- explicit MaxwellShaderConfigCommon(){};
+using ProgramCode = std::array<u64, MAX_PROGRAM_CODE_LENGTH>;
+
+struct ShaderSetup {
+ ShaderSetup(ProgramCode&& program_code) : program_code(std::move(program_code)) {}
+
+ ProgramCode program_code;
+ bool program_code_hash_dirty = true;
+
+ u64 GetProgramCodeHash() {
+ if (program_code_hash_dirty) {
+ program_code_hash = Common::ComputeHash64(&program_code, sizeof(program_code));
+ program_code_hash_dirty = false;
+ }
+ return program_code_hash;
+ }
+
+private:
+ u64 program_code_hash{};
};
-struct MaxwellVSConfig : MaxwellShaderConfigCommon {
- explicit MaxwellVSConfig() : MaxwellShaderConfigCommon() {}
+struct MaxwellShaderConfigCommon {
+ void Init(ShaderSetup& setup) {
+ program_hash = setup.GetProgramCodeHash();
+ }
- bool operator==(const MaxwellVSConfig& o) const {
- return std::memcmp(this, &o, sizeof(MaxwellVSConfig)) == 0;
- };
+ u64 program_hash;
};
-struct MaxwellFSConfig : MaxwellShaderConfigCommon {
- explicit MaxwellFSConfig() : MaxwellShaderConfigCommon() {}
+struct MaxwellVSConfig : Common::HashableStruct<MaxwellShaderConfigCommon> {
+ explicit MaxwellVSConfig(ShaderSetup& setup) {
+ state.Init(setup);
+ }
+};
- bool operator==(const MaxwellFSConfig& o) const {
- return std::memcmp(this, &o, sizeof(MaxwellFSConfig)) == 0;
- };
+struct MaxwellFSConfig : Common::HashableStruct<MaxwellShaderConfigCommon> {
+ explicit MaxwellFSConfig(ShaderSetup& setup) {
+ state.Init(setup);
+ }
};
-std::string GenerateVertexShader(const MaxwellVSConfig& config);
-std::string GenerateFragmentShader(const MaxwellFSConfig& config);
+/**
+ * Generates the GLSL vertex shader program source code for the given VS program
+ * @returns String of the shader source code
+ */
+std::string GenerateVertexShader(const ShaderSetup& setup, const MaxwellVSConfig& config);
+
+/**
+ * Generates the GLSL fragment shader program source code for the given FS program
+ * @returns String of the shader source code
+ */
+std::string GenerateFragmentShader(const ShaderSetup& setup, const MaxwellFSConfig& config);
} // namespace GLShader
@@ -52,14 +73,14 @@ namespace std {
template <>
struct hash<GLShader::MaxwellVSConfig> {
size_t operator()(const GLShader::MaxwellVSConfig& k) const {
- return Common::ComputeHash64(&k, sizeof(GLShader::MaxwellVSConfig));
+ return k.Hash();
}
};
template <>
struct hash<GLShader::MaxwellFSConfig> {
size_t operator()(const GLShader::MaxwellFSConfig& k) const {
- return Common::ComputeHash64(&k, sizeof(GLShader::MaxwellFSConfig));
+ return k.Hash();
}
};