From d23ffe9b42a29b64d729ad91979c122025168b32 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 30 Apr 2020 22:03:36 -0400 Subject: [PATCH 1/2] gl_shader_gen: Mark PicaVSConfig reference parameter as const This isn't mutated whatsoever, so this can be marked const. --- src/video_core/renderer_opengl/gl_shader_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h index ebf54fe9f9..1374d532f8 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.h +++ b/src/video_core/renderer_opengl/gl_shader_gen.h @@ -170,7 +170,7 @@ struct PicaVSConfig : Common::HashableStruct { explicit PicaVSConfig(const Pica::ShaderRegs& regs, Pica::Shader::ShaderSetup& setup) { state.Init(regs, setup); } - explicit PicaVSConfig(PicaShaderConfigCommon& conf) { + explicit PicaVSConfig(const PicaShaderConfigCommon& conf) { state = conf; } }; From f20120e5a73bde9c4ca416d3ded16cde687377a9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 30 Apr 2020 22:05:46 -0400 Subject: [PATCH 2/2] gl_shader_gen: Mark hash implementations as noexcept These shouldn't throw at all, so we can mark the interface as such. --- src/common/hash.h | 12 ++++++------ src/video_core/renderer_opengl/gl_shader_gen.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/common/hash.h b/src/common/hash.h index 40194d1ee4..bcdcc4c5f5 100644 --- a/src/common/hash.h +++ b/src/common/hash.h @@ -17,7 +17,7 @@ namespace Common { * @param len Length of data (in bytes) to compute hash over * @returns 64-bit hash value that was computed over the data block */ -static inline u64 ComputeHash64(const void* data, std::size_t len) { +static inline u64 ComputeHash64(const void* data, std::size_t len) noexcept { return CityHash64(static_cast(data), len); } @@ -27,7 +27,7 @@ static inline u64 ComputeHash64(const void* data, std::size_t len) { * by memsetting the struct to 0 before filling it in. */ template -static inline u64 ComputeStructHash64(const T& data) { +static inline u64 ComputeStructHash64(const T& data) noexcept { static_assert(std::is_trivially_copyable_v, "Type passed to ComputeStructHash64 must be trivially copyable"); return ComputeHash64(&data, sizeof(data)); @@ -50,20 +50,20 @@ struct HashableStruct { T state; }; - HashableStruct() { + HashableStruct() noexcept { // Memset structure to zero padding bits, so that they will be deterministic when hashing std::memset(&state, 0, sizeof(T)); } - bool operator==(const HashableStruct& o) const { + bool operator==(const HashableStruct& o) const noexcept { return std::memcmp(&state, &o.state, sizeof(T)) == 0; }; - bool operator!=(const HashableStruct& o) const { + bool operator!=(const HashableStruct& o) const noexcept { return !(*this == o); }; - std::size_t Hash() const { + std::size_t Hash() const noexcept { return Common::ComputeStructHash64(state); } }; diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h index 1374d532f8..3b11fa88ce 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.h +++ b/src/video_core/renderer_opengl/gl_shader_gen.h @@ -237,21 +237,21 @@ ShaderDecompiler::ProgramResult GenerateFragmentShader(const PicaFSConfig& confi namespace std { template <> struct hash { - std::size_t operator()(const OpenGL::PicaFSConfig& k) const { + std::size_t operator()(const OpenGL::PicaFSConfig& k) const noexcept { return k.Hash(); } }; template <> struct hash { - std::size_t operator()(const OpenGL::PicaVSConfig& k) const { + std::size_t operator()(const OpenGL::PicaVSConfig& k) const noexcept { return k.Hash(); } }; template <> struct hash { - std::size_t operator()(const OpenGL::PicaFixedGSConfig& k) const { + std::size_t operator()(const OpenGL::PicaFixedGSConfig& k) const noexcept { return k.Hash(); } };