diff options
| author | 2018-04-07 04:51:42 -0400 | |
|---|---|---|
| committer | 2018-04-13 23:48:23 -0400 | |
| commit | 10953495c1b7de412312b64370d99a2294dfe6a2 (patch) | |
| tree | fb576ffbb201e6e2f88a4f91d7974bb307010d16 | |
| parent | gl_shader_util: Add missing includes. (diff) | |
| download | yuzu-10953495c1b7de412312b64370d99a2294dfe6a2.tar.gz yuzu-10953495c1b7de412312b64370d99a2294dfe6a2.tar.xz yuzu-10953495c1b7de412312b64370d99a2294dfe6a2.zip | |
gl_shader_gen: Add hashable setup/config structs.
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 4 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.h | 75 |
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 @@ | |||
| 7 | 7 | ||
| 8 | namespace GLShader { | 8 | namespace GLShader { |
| 9 | 9 | ||
| 10 | std::string GenerateVertexShader(const MaxwellVSConfig& config) { | 10 | std::string GenerateVertexShader(const ShaderSetup& setup, const MaxwellVSConfig& config) { |
| 11 | UNREACHABLE(); | 11 | UNREACHABLE(); |
| 12 | return {}; | 12 | return {}; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | std::string GenerateFragmentShader(const MaxwellFSConfig& config) { | 15 | std::string GenerateFragmentShader(const ShaderSetup& setup, const MaxwellFSConfig& config) { |
| 16 | UNREACHABLE(); | 16 | UNREACHABLE(); |
| 17 | return {}; | 17 | return {}; |
| 18 | } | 18 | } |
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 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstring> | 7 | #include <array> |
| 8 | #include <string> | 8 | #include <string> |
| 9 | #include <type_traits> | 9 | #include <type_traits> |
| 10 | #include "common/common_types.h" | ||
| 10 | #include "common/hash.h" | 11 | #include "common/hash.h" |
| 11 | 12 | ||
| 12 | namespace GLShader { | 13 | namespace GLShader { |
| 13 | 14 | ||
| 14 | enum Attributes { | 15 | constexpr size_t MAX_PROGRAM_CODE_LENGTH{0x1000}; |
| 15 | ATTRIBUTE_POSITION, | ||
| 16 | ATTRIBUTE_COLOR, | ||
| 17 | ATTRIBUTE_TEXCOORD0, | ||
| 18 | ATTRIBUTE_TEXCOORD1, | ||
| 19 | ATTRIBUTE_TEXCOORD2, | ||
| 20 | ATTRIBUTE_TEXCOORD0_W, | ||
| 21 | ATTRIBUTE_NORMQUAT, | ||
| 22 | ATTRIBUTE_VIEW, | ||
| 23 | }; | ||
| 24 | 16 | ||
| 25 | struct MaxwellShaderConfigCommon { | 17 | using ProgramCode = std::array<u64, MAX_PROGRAM_CODE_LENGTH>; |
| 26 | explicit MaxwellShaderConfigCommon(){}; | 18 | |
| 19 | struct ShaderSetup { | ||
| 20 | ShaderSetup(ProgramCode&& program_code) : program_code(std::move(program_code)) {} | ||
| 21 | |||
| 22 | ProgramCode program_code; | ||
| 23 | bool program_code_hash_dirty = true; | ||
| 24 | |||
| 25 | u64 GetProgramCodeHash() { | ||
| 26 | if (program_code_hash_dirty) { | ||
| 27 | program_code_hash = Common::ComputeHash64(&program_code, sizeof(program_code)); | ||
| 28 | program_code_hash_dirty = false; | ||
| 29 | } | ||
| 30 | return program_code_hash; | ||
| 31 | } | ||
| 32 | |||
| 33 | private: | ||
| 34 | u64 program_code_hash{}; | ||
| 27 | }; | 35 | }; |
| 28 | 36 | ||
| 29 | struct MaxwellVSConfig : MaxwellShaderConfigCommon { | 37 | struct MaxwellShaderConfigCommon { |
| 30 | explicit MaxwellVSConfig() : MaxwellShaderConfigCommon() {} | 38 | void Init(ShaderSetup& setup) { |
| 39 | program_hash = setup.GetProgramCodeHash(); | ||
| 40 | } | ||
| 31 | 41 | ||
| 32 | bool operator==(const MaxwellVSConfig& o) const { | 42 | u64 program_hash; |
| 33 | return std::memcmp(this, &o, sizeof(MaxwellVSConfig)) == 0; | ||
| 34 | }; | ||
| 35 | }; | 43 | }; |
| 36 | 44 | ||
| 37 | struct MaxwellFSConfig : MaxwellShaderConfigCommon { | 45 | struct MaxwellVSConfig : Common::HashableStruct<MaxwellShaderConfigCommon> { |
| 38 | explicit MaxwellFSConfig() : MaxwellShaderConfigCommon() {} | 46 | explicit MaxwellVSConfig(ShaderSetup& setup) { |
| 47 | state.Init(setup); | ||
| 48 | } | ||
| 49 | }; | ||
| 39 | 50 | ||
| 40 | bool operator==(const MaxwellFSConfig& o) const { | 51 | struct MaxwellFSConfig : Common::HashableStruct<MaxwellShaderConfigCommon> { |
| 41 | return std::memcmp(this, &o, sizeof(MaxwellFSConfig)) == 0; | 52 | explicit MaxwellFSConfig(ShaderSetup& setup) { |
| 42 | }; | 53 | state.Init(setup); |
| 54 | } | ||
| 43 | }; | 55 | }; |
| 44 | 56 | ||
| 45 | std::string GenerateVertexShader(const MaxwellVSConfig& config); | 57 | /** |
| 46 | std::string GenerateFragmentShader(const MaxwellFSConfig& config); | 58 | * Generates the GLSL vertex shader program source code for the given VS program |
| 59 | * @returns String of the shader source code | ||
| 60 | */ | ||
| 61 | std::string GenerateVertexShader(const ShaderSetup& setup, const MaxwellVSConfig& config); | ||
| 62 | |||
| 63 | /** | ||
| 64 | * Generates the GLSL fragment shader program source code for the given FS program | ||
| 65 | * @returns String of the shader source code | ||
| 66 | */ | ||
| 67 | std::string GenerateFragmentShader(const ShaderSetup& setup, const MaxwellFSConfig& config); | ||
| 47 | 68 | ||
| 48 | } // namespace GLShader | 69 | } // namespace GLShader |
| 49 | 70 | ||
| @@ -52,14 +73,14 @@ namespace std { | |||
| 52 | template <> | 73 | template <> |
| 53 | struct hash<GLShader::MaxwellVSConfig> { | 74 | struct hash<GLShader::MaxwellVSConfig> { |
| 54 | size_t operator()(const GLShader::MaxwellVSConfig& k) const { | 75 | size_t operator()(const GLShader::MaxwellVSConfig& k) const { |
| 55 | return Common::ComputeHash64(&k, sizeof(GLShader::MaxwellVSConfig)); | 76 | return k.Hash(); |
| 56 | } | 77 | } |
| 57 | }; | 78 | }; |
| 58 | 79 | ||
| 59 | template <> | 80 | template <> |
| 60 | struct hash<GLShader::MaxwellFSConfig> { | 81 | struct hash<GLShader::MaxwellFSConfig> { |
| 61 | size_t operator()(const GLShader::MaxwellFSConfig& k) const { | 82 | size_t operator()(const GLShader::MaxwellFSConfig& k) const { |
| 62 | return Common::ComputeHash64(&k, sizeof(GLShader::MaxwellFSConfig)); | 83 | return k.Hash(); |
| 63 | } | 84 | } |
| 64 | }; | 85 | }; |
| 65 | 86 | ||