From 2afd892e466e656a2dc623bb5d6574d0d6c5533a Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 29 Mar 2013 22:24:49 +0100 Subject: [PATCH] ShaderGen: More interface cleanups. Less wtfs :) --- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 3 ++- Source/Core/VideoCommon/Src/PixelShaderGen.h | 4 ++-- Source/Core/VideoCommon/Src/ShaderGenCommon.h | 20 ++++++++----------- .../Core/VideoCommon/Src/VertexShaderGen.cpp | 7 ++++--- Source/Core/VideoCommon/Src/VertexShaderGen.h | 4 ++-- .../Src/LineGeometryShader.cpp | 2 +- .../Src/PointGeometryShader.cpp | 2 +- .../Src/ProgramShaderCache.cpp | 6 +++--- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index d9d45902fe..e534e2a6ca 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -274,7 +274,8 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u // Non-uid template parameters will write to the dummy data (=> gets optimized out) pixel_shader_uid_data dummy_data; - pixel_shader_uid_data& uid_data = (&out.GetUidData() != NULL) ? out.GetUidData() : dummy_data; + pixel_shader_uid_data& uid_data = (&out.template GetUidData() != NULL) + ? out.template GetUidData() : dummy_data; out.SetBuffer(text); if (out.GetBuffer() != NULL) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index 4f9cba0c37..4881999206 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -190,8 +190,8 @@ struct pixel_shader_uid_data }; typedef ShaderUid PixelShaderUid; -typedef ShaderCode PixelShaderCode; -typedef ShaderConstantProfile PixelShaderConstantProfile; +typedef ShaderCode PixelShaderCode; // TODO: Obsolete +typedef ShaderConstantProfile PixelShaderConstantProfile; // TODO: Obsolete void GeneratePixelShaderCode(PixelShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components); diff --git a/Source/Core/VideoCommon/Src/ShaderGenCommon.h b/Source/Core/VideoCommon/Src/ShaderGenCommon.h index a2616e0a6c..a904a8e635 100644 --- a/Source/Core/VideoCommon/Src/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/Src/ShaderGenCommon.h @@ -25,7 +25,6 @@ #include -template class ShaderGeneratorInterface { public: @@ -33,11 +32,13 @@ public: const char* GetBuffer() { return NULL; } void SetBuffer(char* buffer) { } inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index) {} - uid_data& GetUidData() { return *(uid_data*)NULL; } // TODO: can be moved out, just make this GetUidData instead + + template + uid_data& GetUidData() { return *(uid_data*)NULL; } }; template -class ShaderUid : public ShaderGeneratorInterface +class ShaderUid : public ShaderGeneratorInterface { public: ShaderUid() @@ -69,7 +70,8 @@ public: return false; } - inline uid_data& GetUidData() { return data; } + template + inline T& GetUidData() override { return data; } private: union @@ -79,9 +81,7 @@ private: }; }; -// Needs to be a template for hacks... -template -class ShaderCode : public ShaderGeneratorInterface +class ShaderCode : public ShaderGeneratorInterface { public: ShaderCode() : buf(NULL), write_ptr(NULL) @@ -105,15 +105,11 @@ private: char* write_ptr; }; -template -class ShaderConstantProfile : public ShaderGeneratorInterface +class ShaderConstantProfile : public ShaderGeneratorInterface { public: ShaderConstantProfile(int num_constants) { constant_usage.resize(num_constants); } - // has room for optimization (if it matters at all...) - void NumConstants() { return constant_usage.size(); } - inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index) { for (unsigned int i = first_index; i < last_index+1; ++i) diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 5ed1a73569..e27ced7b39 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -85,7 +85,8 @@ void GenerateVertexShader(T& out, u32 components, API_TYPE api_type) { // Non-uid template parameters will write to the dummy data (=> gets optimized out) vertex_shader_uid_data dummy_data; - vertex_shader_uid_data& uid_data = (&out.GetUidData() != NULL) ? out.GetUidData() : dummy_data; + vertex_shader_uid_data& uid_data = (&out.template GetUidData() != NULL) + ? out.template GetUidData() : dummy_data; out.SetBuffer(text); if (out.GetBuffer() != NULL) @@ -535,7 +536,7 @@ void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE GenerateVertexShader(object, components, api_type); } -void GenerateVSOutputStructForGS(ShaderCode& object, u32 components, API_TYPE api_type) +void GenerateVSOutputStructForGS(ShaderCode& object, u32 components, API_TYPE api_type) { - GenerateVSOutputStruct >(object, components, api_type); + GenerateVSOutputStruct(object, components, api_type); } diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h index b6b176c806..33d27ecdf0 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.h +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h @@ -110,10 +110,10 @@ struct vertex_shader_uid_data }; typedef ShaderUid VertexShaderUid; -typedef ShaderCode VertexShaderCode; +typedef ShaderCode VertexShaderCode; // TODO: Obsolete.. void GetVertexShaderUid(VertexShaderUid& object, u32 components, API_TYPE api_type); void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE api_type); -void GenerateVSOutputStructForGS(ShaderCode& object, u32 components, API_TYPE api_type); +void GenerateVSOutputStructForGS(ShaderCode& object, u32 components, API_TYPE api_type); #endif // GCOGL_VERTEXSHADER_H diff --git a/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp b/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp index f22ebef0df..5d6b8eb5b5 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp @@ -183,7 +183,7 @@ bool LineGeometryShader::SetShader(u32 components, float lineWidth, { // Generate new shader. Warning: not thread-safe. static char buffer[16384]; - ShaderCode code; + ShaderCode code; code.SetBuffer(buffer); GenerateVSOutputStructForGS(code, components, API_D3D11); code.Write("\n%s", LINE_GS_COMMON); diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp b/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp index 5976c09ab9..8f5300ff64 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp @@ -177,7 +177,7 @@ bool PointGeometryShader::SetShader(u32 components, float pointSize, { // Generate new shader. Warning: not thread-safe. static char buffer[16384]; - ShaderCode code; + ShaderCode code; code.SetBuffer(buffer); GenerateVSOutputStructForGS(code, components, API_D3D11); code.Write("\n%s", POINT_GS_COMMON); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index 188145ebcf..81621d2d38 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -360,9 +360,9 @@ template UidT GetPartialUid(const SHADERUID& uid); template<> PixelShaderUid GetPartialUid(const SHADERUID& uid) { return uid.puid; } template<> VertexShaderUid GetPartialUid(const SHADERUID& uid) { return uid.vuid; } -template const std::string& GetShaderCode(const SHADER& shader); -template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strpprog; } -template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strvprog; } +template const std::string& GetShaderCode(const SHADER& shader); +template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strpprog; } +template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strvprog; } template void CheckForUidMismatch(const ProgramShaderCache::PCache& cache, CodeT& new_code, const UidT& new_uid)