From 71d1eb3c313535b5003884bb862635d4d2f8aae9 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Tue, 3 Nov 2015 03:47:05 +0100 Subject: [PATCH] VideoCommon: return code/uid from shader gens rather than passing in non-const references --- .../VideoBackends/D3D/GeometryShaderCache.cpp | 9 +++----- .../VideoBackends/D3D/PixelShaderCache.cpp | 9 +++----- .../VideoBackends/D3D/VertexShaderCache.cpp | 9 +++----- .../VideoBackends/OGL/ProgramShaderCache.cpp | 23 ++++++++----------- Source/Core/VideoCommon/GeometryShaderGen.cpp | 13 +++++++---- Source/Core/VideoCommon/GeometryShaderGen.h | 4 ++-- Source/Core/VideoCommon/PixelShaderGen.cpp | 18 +++++++-------- Source/Core/VideoCommon/PixelShaderGen.h | 6 ++--- Source/Core/VideoCommon/VertexShaderGen.cpp | 13 +++++++---- Source/Core/VideoCommon/VertexShaderGen.h | 4 ++-- 10 files changed, 48 insertions(+), 60 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp b/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp index 97db9f912a..53a74c758f 100644 --- a/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp @@ -190,12 +190,10 @@ void GeometryShaderCache::Shutdown() bool GeometryShaderCache::SetShader(u32 primitive_type) { - GeometryShaderUid uid; - GetGeometryShaderUid(uid, primitive_type, API_D3D); + GeometryShaderUid uid = GetGeometryShaderUid(primitive_type, API_D3D); if (g_ActiveConfig.bEnableShaderDebugging) { - ShaderCode code; - GenerateGeometryShaderCode(code, primitive_type, API_D3D); + ShaderCode code = GenerateGeometryShaderCode(primitive_type, API_D3D); geometry_uid_checker.AddToIndexAndCheck(code, uid, "Geometry", "g"); } @@ -231,8 +229,7 @@ bool GeometryShaderCache::SetShader(u32 primitive_type) } // Need to compile a new shader - ShaderCode code; - GenerateGeometryShaderCode(code, primitive_type, API_D3D); + ShaderCode code = GenerateGeometryShaderCode(primitive_type, API_D3D); D3DBlob* pbytecode; if (!D3D::CompileGeometryShader(code.GetBuffer(), &pbytecode)) diff --git a/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp b/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp index c361a25835..d1013c5539 100644 --- a/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp @@ -527,12 +527,10 @@ void PixelShaderCache::Shutdown() bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode) { - PixelShaderUid uid; - GetPixelShaderUid(uid, dstAlphaMode, API_D3D); + PixelShaderUid uid = GetPixelShaderUid(dstAlphaMode, API_D3D); if (g_ActiveConfig.bEnableShaderDebugging) { - ShaderCode code; - GeneratePixelShaderCode(code, dstAlphaMode, API_D3D); + ShaderCode code = GeneratePixelShaderCode(dstAlphaMode, API_D3D); pixel_uid_checker.AddToIndexAndCheck(code, uid, "Pixel", "p"); } @@ -561,8 +559,7 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode) } // Need to compile a new shader - ShaderCode code; - GeneratePixelShaderCode(code, dstAlphaMode, API_D3D); + ShaderCode code = GeneratePixelShaderCode(dstAlphaMode, API_D3D); D3DBlob* pbytecode; if (!D3D::CompilePixelShader(code.GetBuffer(), &pbytecode)) diff --git a/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp b/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp index 38445422b1..a518cdd4e5 100644 --- a/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp @@ -186,12 +186,10 @@ void VertexShaderCache::Shutdown() bool VertexShaderCache::SetShader() { - VertexShaderUid uid; - GetVertexShaderUid(uid, API_D3D); + VertexShaderUid uid = GetVertexShaderUid(API_D3D); if (g_ActiveConfig.bEnableShaderDebugging) { - ShaderCode code; - GenerateVertexShaderCode(code, API_D3D); + ShaderCode code = GenerateVertexShaderCode(API_D3D); vertex_uid_checker.AddToIndexAndCheck(code, uid, "Vertex", "v"); } @@ -216,8 +214,7 @@ bool VertexShaderCache::SetShader() return (entry.shader != nullptr); } - ShaderCode code; - GenerateVertexShaderCode(code, API_D3D); + ShaderCode code = GenerateVertexShaderCode(API_D3D); D3DBlob* pbytecode = nullptr; D3D::CompileVertexShader(code.GetBuffer(), &pbytecode); diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 52baa54523..351bbe8c72 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -211,13 +211,11 @@ SHADER* ProgramShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 primitive_ last_entry = &newentry; newentry.in_cache = 0; - ShaderCode vcode; - ShaderCode pcode; + ShaderCode vcode = GenerateVertexShaderCode(API_OPENGL); + ShaderCode pcode = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL); ShaderCode gcode; - GenerateVertexShaderCode(vcode, API_OPENGL); - GeneratePixelShaderCode(pcode, dstAlphaMode, API_OPENGL); if (g_ActiveConfig.backend_info.bSupportsGeometryShaders && !uid.guid.GetUidData()->IsPassthrough()) - GenerateGeometryShaderCode(gcode, primitive_type, API_OPENGL); + gcode = GenerateGeometryShaderCode(primitive_type, API_OPENGL); if (g_ActiveConfig.bEnableShaderDebugging) { @@ -398,22 +396,19 @@ GLuint ProgramShaderCache::CompileSingleShader(GLuint type, const char* code) void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 primitive_type) { - GetPixelShaderUid(uid->puid, dstAlphaMode, API_OPENGL); - GetVertexShaderUid(uid->vuid, API_OPENGL); - GetGeometryShaderUid(uid->guid, primitive_type, API_OPENGL); + uid->puid = GetPixelShaderUid(dstAlphaMode, API_OPENGL); + uid->vuid = GetVertexShaderUid(API_OPENGL); + uid->guid = GetGeometryShaderUid(primitive_type, API_OPENGL); if (g_ActiveConfig.bEnableShaderDebugging) { - ShaderCode pcode; - GeneratePixelShaderCode(pcode, dstAlphaMode, API_OPENGL); + ShaderCode pcode = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL); pixel_uid_checker.AddToIndexAndCheck(pcode, uid->puid, "Pixel", "p"); - ShaderCode vcode; - GenerateVertexShaderCode(vcode, API_OPENGL); + ShaderCode vcode = GenerateVertexShaderCode(API_OPENGL); vertex_uid_checker.AddToIndexAndCheck(vcode, uid->vuid, "Vertex", "v"); - ShaderCode gcode; - GenerateGeometryShaderCode(gcode, primitive_type, API_OPENGL); + ShaderCode gcode = GenerateGeometryShaderCode(primitive_type, API_OPENGL); geometry_uid_checker.AddToIndexAndCheck(gcode, uid->guid, "Geometry", "g"); } } diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp index f36aa94a9a..bf054464c2 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.cpp +++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp @@ -30,8 +30,9 @@ template static inline void EmitVertex(T& out, const char* vertex, API_ template static inline void EndPrimitive(T& out, API_TYPE ApiType); template -static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE ApiType) +static inline T GenerateGeometryShader(u32 primitive_type, API_TYPE ApiType) { + T out; // Non-uid template parameters will write to the dummy data (=> gets optimized out) geometry_shader_uid_data dummy_data; geometry_shader_uid_data* uid_data = out.template GetUidData(); @@ -292,6 +293,8 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A if (text[sizeof(text) - 1] != 0x7C) PanicAlert("GeometryShader generator - buffer too small, canary has been eaten!"); } + + return out; } template @@ -327,12 +330,12 @@ static inline void EndPrimitive(T& out, API_TYPE ApiType) out.Write("\toutput.RestartStrip();\n"); } -void GetGeometryShaderUid(GeometryShaderUid& object, u32 primitive_type, API_TYPE ApiType) +GeometryShaderUid GetGeometryShaderUid(u32 primitive_type, API_TYPE ApiType) { - GenerateGeometryShader(object, primitive_type, ApiType); + return GenerateGeometryShader(primitive_type, ApiType); } -void GenerateGeometryShaderCode(ShaderCode& object, u32 primitive_type, API_TYPE ApiType) +ShaderCode GenerateGeometryShaderCode(u32 primitive_type, API_TYPE ApiType) { - GenerateGeometryShader(object, primitive_type, ApiType); + return GenerateGeometryShader(primitive_type, ApiType); } diff --git a/Source/Core/VideoCommon/GeometryShaderGen.h b/Source/Core/VideoCommon/GeometryShaderGen.h index fc4653f380..5277e78774 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.h +++ b/Source/Core/VideoCommon/GeometryShaderGen.h @@ -26,5 +26,5 @@ struct geometry_shader_uid_data typedef ShaderUid GeometryShaderUid; -void GenerateGeometryShaderCode(ShaderCode& object, u32 primitive_type, API_TYPE ApiType); -void GetGeometryShaderUid(GeometryShaderUid& object, u32 primitive_type, API_TYPE ApiType); +ShaderCode GenerateGeometryShaderCode(u32 primitive_type, API_TYPE ApiType); +GeometryShaderUid GetGeometryShaderUid(u32 primitive_type, API_TYPE ApiType); diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index e3d2ea87e9..a1cfcc4611 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -166,8 +166,9 @@ template static inline void WriteAlphaTest(T& out, pixel_shader_uid_dat template static inline void WriteFog(T& out, pixel_shader_uid_data* uid_data); template -static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType) +static inline T GeneratePixelShader(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType) { + T out; const u32 components = VertexLoaderManager::g_current_components; // Non-uid template parameters will write to the dummy data (=> gets optimized out) pixel_shader_uid_data dummy_data; @@ -667,6 +668,8 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T if (text[sizeof(text) - 1] != 0x7C) PanicAlert("PixelShader generator - buffer too small, canary has been eaten!"); } + + return out; } @@ -1170,17 +1173,12 @@ static inline void WriteFog(T& out, pixel_shader_uid_data* uid_data) out.Write("\tprev.rgb = (prev.rgb * (256 - ifog) + " I_FOGCOLOR".rgb * ifog) >> 8;\n"); } -void GetPixelShaderUid(PixelShaderUid& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType) +PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType) { - GeneratePixelShader(object, dstAlphaMode, ApiType); + return GeneratePixelShader(dstAlphaMode, ApiType); } -void GeneratePixelShaderCode(ShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType) +ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType) { - GeneratePixelShader(object, dstAlphaMode, ApiType); -} - -void GetPixelShaderConstantProfile(PixelShaderConstantProfile& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType) -{ - GeneratePixelShader(object, dstAlphaMode, ApiType); + return GeneratePixelShader(dstAlphaMode, ApiType); } diff --git a/Source/Core/VideoCommon/PixelShaderGen.h b/Source/Core/VideoCommon/PixelShaderGen.h index 638ff9b2bc..70f75958ca 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.h +++ b/Source/Core/VideoCommon/PixelShaderGen.h @@ -114,8 +114,6 @@ struct pixel_shader_uid_data #pragma pack() typedef ShaderUid PixelShaderUid; -typedef ShaderConstantProfile PixelShaderConstantProfile; // TODO: Obsolete -void GeneratePixelShaderCode(ShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType); -void GetPixelShaderUid(PixelShaderUid& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType); -void GetPixelShaderConstantProfile(PixelShaderConstantProfile& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType); +ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType); +PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType); diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index f00a6d760c..4f6331cfde 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -16,8 +16,9 @@ static char text[16768]; template -static inline void GenerateVertexShader(T& out, API_TYPE api_type) +static inline T GenerateVertexShader(API_TYPE api_type) { + T out; const u32 components = VertexLoaderManager::g_current_components; // Non-uid template parameters will write to the dummy data (=> gets optimized out) vertex_shader_uid_data dummy_data; @@ -394,14 +395,16 @@ static inline void GenerateVertexShader(T& out, API_TYPE api_type) if (text[sizeof(text) - 1] != 0x7C) PanicAlert("VertexShader generator - buffer too small, canary has been eaten!"); } + + return out; } -void GetVertexShaderUid(VertexShaderUid& object, API_TYPE api_type) +VertexShaderUid GetVertexShaderUid(API_TYPE api_type) { - GenerateVertexShader(object, api_type); + return GenerateVertexShader(api_type); } -void GenerateVertexShaderCode(ShaderCode& object, API_TYPE api_type) +ShaderCode GenerateVertexShaderCode(API_TYPE api_type) { - GenerateVertexShader(object, api_type); + return GenerateVertexShader(api_type); } diff --git a/Source/Core/VideoCommon/VertexShaderGen.h b/Source/Core/VideoCommon/VertexShaderGen.h index 45cc9bbac3..df79751df3 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.h +++ b/Source/Core/VideoCommon/VertexShaderGen.h @@ -60,5 +60,5 @@ struct vertex_shader_uid_data typedef ShaderUid VertexShaderUid; -void GetVertexShaderUid(VertexShaderUid& object, API_TYPE api_type); -void GenerateVertexShaderCode(ShaderCode& object, API_TYPE api_type); +VertexShaderUid GetVertexShaderUid(API_TYPE api_type); +ShaderCode GenerateVertexShaderCode(API_TYPE api_type);