From c82991df5ba360986f18cfee32c34405f65df09f Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 17 Mar 2014 10:29:32 +0100 Subject: [PATCH] ShaderGen: inline constant shaders --- Source/Core/VideoCommon/PixelShaderGen.cpp | 33 ++++++++++----------- Source/Core/VideoCommon/ShaderGenCommon.h | 7 ----- Source/Core/VideoCommon/VertexShaderGen.cpp | 25 ++++++++-------- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index ec58c606f1..3ce0403f6c 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -223,24 +223,23 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T out.Write("layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 1" : ""); else out.Write("cbuffer PSBlock {\n"); + out.Write( + "\tint4 " I_COLORS"[4];\n" + "\tint4 " I_KCOLORS"[4];\n" + "\tint4 " I_ALPHA";\n" + "\tfloat4 " I_TEXDIMS"[8];\n" + "\tint4 " I_ZBIAS"[2];\n" + "\tint4 " I_INDTEXSCALE"[2];\n" + "\tint4 " I_INDTEXMTX"[6];\n" + "\tint4 " I_FOGCOLOR";\n" + "\tint4 " I_FOGI";\n" + "\tfloat4 " I_FOGF"[2];\n" - DeclareUniform(out, ApiType, C_COLORS, "int4", I_COLORS"[4]"); - DeclareUniform(out, ApiType, C_KCOLORS, "int4", I_KCOLORS"[4]"); - DeclareUniform(out, ApiType, C_ALPHA, "int4", I_ALPHA); - DeclareUniform(out, ApiType, C_TEXDIMS, "float4", I_TEXDIMS"[8]"); - DeclareUniform(out, ApiType, C_ZBIAS, "int4", I_ZBIAS"[2]"); - DeclareUniform(out, ApiType, C_INDTEXSCALE, "int4", I_INDTEXSCALE"[2]"); - DeclareUniform(out, ApiType, C_INDTEXMTX, "int4", I_INDTEXMTX"[6]"); - DeclareUniform(out, ApiType, C_FOGCOLOR, "int4", I_FOGCOLOR); - DeclareUniform(out, ApiType, C_FOGI, "int4", I_FOGI); - DeclareUniform(out, ApiType, C_FOGF, "float4", I_FOGF"[2]"); - - // For pixel lighting - TODO: Should only be defined when per pixel lighting is enabled! - DeclareUniform(out, ApiType, C_PLIGHT_COLORS, "int4", I_PLIGHT_COLORS"[8]"); - DeclareUniform(out, ApiType, C_PLIGHTS, "float4", I_PLIGHTS"[32]"); - DeclareUniform(out, ApiType, C_PMATERIALS, "int4", I_PMATERIALS"[4]"); - - out.Write("};\n"); + // For pixel lighting - TODO: Should only be defined when per pixel lighting is enabled! + "\tint4 " I_PLIGHT_COLORS"[8];\n" + "\tfloat4 " I_PLIGHTS"[32];\n" + "\tint4 " I_PMATERIALS"[4];\n" + "};\n"); const bool forced_early_z = g_ActiveConfig.backend_info.bSupportsEarlyZ && bpmem.UseEarlyDepthTest() && (g_ActiveConfig.bFastDepthCalc || bpmem.alpha_test.TestResult() == AlphaTest::UNDETERMINED); const bool per_pixel_depth = (bpmem.ztex2.op != ZTEXTURE_DISABLE && bpmem.UseLateDepthTest()) || (!g_ActiveConfig.bFastDepthCalc && bpmem.zmode.testenable && !forced_early_z); diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index bf9b382633..5b79f30221 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -150,13 +150,6 @@ public: private: std::vector constant_usage; // TODO: Is vector appropriate here? }; - -template -static inline void DeclareUniform(T& object, API_TYPE api_type, const u32 num, const char* type, const char* name) -{ - object.Write("%s %s;\n", type, name); -} - /** * Checks if there has been */ diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 05d67ed8e5..32bd8ae9fb 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -86,19 +86,18 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ out.Write("layout(std140%s) uniform VSBlock {\n", g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 2" : ""); else out.Write("cbuffer VSBlock {\n"); - - DeclareUniform(out, api_type, C_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]"); - DeclareUniform(out, api_type, C_PROJECTION, "float4", I_PROJECTION"[4]"); - DeclareUniform(out, api_type, C_MATERIALS, "int4", I_MATERIALS"[4]"); - DeclareUniform(out, api_type, C_LIGHT_COLORS, "int4", I_LIGHT_COLORS"[8]"); - DeclareUniform(out, api_type, C_LIGHTS, "float4", I_LIGHTS"[32]"); - DeclareUniform(out, api_type, C_TEXMATRICES, "float4", I_TEXMATRICES"[24]"); - DeclareUniform(out, api_type, C_TRANSFORMMATRICES, "float4", I_TRANSFORMMATRICES"[64]"); - DeclareUniform(out, api_type, C_NORMALMATRICES, "float4", I_NORMALMATRICES"[32]"); - DeclareUniform(out, api_type, C_POSTTRANSFORMMATRICES, "float4", I_POSTTRANSFORMMATRICES"[64]"); - DeclareUniform(out, api_type, C_DEPTHPARAMS, "float4", I_DEPTHPARAMS); - - out.Write("};\n"); + out.Write( + "\tfloat4 " I_POSNORMALMATRIX"[6];\n" + "\tfloat4 " I_PROJECTION"[4];\n" + "\tint4 " I_MATERIALS"[4];\n" + "\tint4 " I_LIGHT_COLORS"[8];\n" + "\tfloat4 " I_LIGHTS"[32];\n" + "\tfloat4 " I_TEXMATRICES"[24];\n" + "\tfloat4 " I_TRANSFORMMATRICES"[64];\n" + "\tfloat4 " I_NORMALMATRICES"[32];\n" + "\tfloat4 " I_POSTTRANSFORMMATRICES"[64];\n" + "\tfloat4 " I_DEPTHPARAMS";\n" + "};\n"); GenerateVSOutputStruct(out, api_type);