1
0
Fork 0
forked from suyu/suyu

gl_shader_gen: Add hashable setup/config structs.

This commit is contained in:
bunnei 2018-04-07 04:51:42 -04:00
parent 2fcbb35ad2
commit 10953495c1
2 changed files with 50 additions and 29 deletions

View file

@ -7,12 +7,12 @@
namespace GLShader { namespace GLShader {
std::string GenerateVertexShader(const MaxwellVSConfig& config) { std::string GenerateVertexShader(const ShaderSetup& setup, const MaxwellVSConfig& config) {
UNREACHABLE(); UNREACHABLE();
return {}; return {};
} }
std::string GenerateFragmentShader(const MaxwellFSConfig& config) { std::string GenerateFragmentShader(const ShaderSetup& setup, const MaxwellFSConfig& config) {
UNREACHABLE(); UNREACHABLE();
return {}; return {};
} }

View file

@ -4,46 +4,67 @@
#pragma once #pragma once
#include <cstring> #include <array>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include "common/common_types.h"
#include "common/hash.h" #include "common/hash.h"
namespace GLShader { namespace GLShader {
enum Attributes { constexpr size_t MAX_PROGRAM_CODE_LENGTH{0x1000};
ATTRIBUTE_POSITION,
ATTRIBUTE_COLOR, using ProgramCode = std::array<u64, MAX_PROGRAM_CODE_LENGTH>;
ATTRIBUTE_TEXCOORD0,
ATTRIBUTE_TEXCOORD1, struct ShaderSetup {
ATTRIBUTE_TEXCOORD2, ShaderSetup(ProgramCode&& program_code) : program_code(std::move(program_code)) {}
ATTRIBUTE_TEXCOORD0_W,
ATTRIBUTE_NORMQUAT, ProgramCode program_code;
ATTRIBUTE_VIEW, 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 MaxwellShaderConfigCommon { struct MaxwellShaderConfigCommon {
explicit MaxwellShaderConfigCommon(){}; void Init(ShaderSetup& setup) {
program_hash = setup.GetProgramCodeHash();
}
u64 program_hash;
}; };
struct MaxwellVSConfig : MaxwellShaderConfigCommon { struct MaxwellVSConfig : Common::HashableStruct<MaxwellShaderConfigCommon> {
explicit MaxwellVSConfig() : MaxwellShaderConfigCommon() {} explicit MaxwellVSConfig(ShaderSetup& setup) {
state.Init(setup);
bool operator==(const MaxwellVSConfig& o) const { }
return std::memcmp(this, &o, sizeof(MaxwellVSConfig)) == 0;
};
}; };
struct MaxwellFSConfig : MaxwellShaderConfigCommon { struct MaxwellFSConfig : Common::HashableStruct<MaxwellShaderConfigCommon> {
explicit MaxwellFSConfig() : MaxwellShaderConfigCommon() {} explicit MaxwellFSConfig(ShaderSetup& setup) {
state.Init(setup);
bool operator==(const MaxwellFSConfig& o) const { }
return std::memcmp(this, &o, sizeof(MaxwellFSConfig)) == 0;
};
}; };
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 } // namespace GLShader
@ -52,14 +73,14 @@ namespace std {
template <> template <>
struct hash<GLShader::MaxwellVSConfig> { struct hash<GLShader::MaxwellVSConfig> {
size_t operator()(const GLShader::MaxwellVSConfig& k) const { size_t operator()(const GLShader::MaxwellVSConfig& k) const {
return Common::ComputeHash64(&k, sizeof(GLShader::MaxwellVSConfig)); return k.Hash();
} }
}; };
template <> template <>
struct hash<GLShader::MaxwellFSConfig> { struct hash<GLShader::MaxwellFSConfig> {
size_t operator()(const GLShader::MaxwellFSConfig& k) const { size_t operator()(const GLShader::MaxwellFSConfig& k) const {
return Common::ComputeHash64(&k, sizeof(GLShader::MaxwellFSConfig)); return k.Hash();
} }
}; };