diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp index 187af8b088..57009aedaa 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.cpp +++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp @@ -53,17 +53,22 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy uid_data->pixel_lighting = g_ActiveConfig.bEnablePixelLighting; GenerateVSOutputStruct(out, ApiType); - GenerateGSOutputStruct(out, ApiType); if (ApiType == API_OPENGL) { out.Write("centroid in VS_OUTPUT o[3];\n"); - out.Write("centroid out GS_OUTPUT gs;\n"); + out.Write("centroid out VS_OUTPUT vs;\n"); + out.Write("flat out int layer;\n"); out.Write("void main()\n{\n"); } else // D3D { + out.Write("struct GS_OUTPUT {\n"); + out.Write("\tVS_OUTPUT vs;\n"); + out.Write("\tuint layer : SV_RenderTargetArrayIndex;\n"); + out.Write("};\n"); + if (g_ActiveConfig.backend_info.bSupportsGSInstancing) { out.Write("[maxvertexcount(3)]\n[instance(%d)]\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1); @@ -85,19 +90,23 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy if (g_ActiveConfig.backend_info.bSupportsGSInstancing) { if (ApiType == API_OPENGL) - out.Write("\tint layer = gl_InvocationID;\n"); + out.Write("\tint eye = gl_InvocationID;\n"); else - out.Write("\tint layer = InstanceID;\n"); + out.Write("\tint eye = InstanceID;\n"); } else - out.Write("\tfor (int layer = 0; layer < %d; ++layer) {\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1); + out.Write("\tfor (int eye = 0; eye < %d; ++eye) {\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1); out.Write("\tfor (int i = 0; i < 3; ++i) {\n"); // Select the output layer - out.Write("\t\tgs.layer = layer;\n"); if (ApiType == API_OPENGL) - out.Write("\t\tgl_Layer = layer;\n"); + { + out.Write("\t\tgl_Layer = eye;\n"); + out.Write("\t\tlayer = eye;\n"); + } + else + out.Write("\t\tgs.layer = eye;\n"); out.Write("\t\tf = o[i];\n"); out.Write("\t\tfloat4 pos = o[i].pos;\n"); @@ -111,8 +120,8 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy // the depth value. This results in objects at a distance smaller than the convergence // distance to seemingly appear in front of the screen. // This formula is based on page 13 of the "Nvidia 3D Vision Automatic, Best Practices Guide" - out.Write("\t\tf.clipPos.x = o[i].clipPos.x + " I_STEREOPARAMS"[layer] * (o[i].clipPos.w - " I_STEREOPARAMS"[2]);\n"); - out.Write("\t\tpos.x = o[i].pos.x + " I_STEREOPARAMS"[layer] * (o[i].pos.w - " I_STEREOPARAMS"[2]);\n"); + out.Write("\t\tf.clipPos.x = o[i].clipPos.x + " I_STEREOPARAMS"[eye] * (o[i].clipPos.w - " I_STEREOPARAMS"[2]);\n"); + out.Write("\t\tpos.x = o[i].pos.x + " I_STEREOPARAMS"[eye] * (o[i].pos.w - " I_STEREOPARAMS"[2]);\n"); } out.Write("\t\tf.pos.x = pos.x;\n"); @@ -120,7 +129,7 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy if (ApiType == API_OPENGL) out.Write("\t\tgl_Position = pos;\n"); - out.Write("\t\tgs.vs = f;\n"); + out.Write("\t\t%s = f;\n", (ApiType == API_OPENGL) ? "vs" : "gs.vs"); if (ApiType == API_OPENGL) out.Write("\t\tEmitVertex();\n"); diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index b925b826d3..48cd5b8fec 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -265,7 +265,6 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T } GenerateVSOutputStruct(out, ApiType); - GenerateGSOutputStruct(out, ApiType); 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); @@ -320,7 +319,8 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T uid_data->stereo = g_ActiveConfig.iStereoMode > 0; if (g_ActiveConfig.iStereoMode > 0) { - out.Write("centroid in GS_OUTPUT gs;\n"); + out.Write("centroid in VS_OUTPUT vs;\n"); + out.Write("flat in int layer;\n"); } else { @@ -348,19 +348,19 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T // Let's set up attributes for (unsigned int i = 0; i < numTexgen; ++i) { - out.Write("\tfloat3 uv%d = gs.vs.tex%d;\n", i, i); + out.Write("\tfloat3 uv%d = vs.tex%d;\n", i, i); } - out.Write("\tfloat4 clipPos = gs.vs.clipPos;\n"); + out.Write("\tfloat4 clipPos = vs.clipPos;\n"); if (g_ActiveConfig.bEnablePixelLighting) { - out.Write("\tfloat4 Normal = gs.vs.Normal;\n"); + out.Write("\tfloat4 Normal = vs.Normal;\n"); } } // On Mali, global variables must be initialized as constants. // This is why we initialize these variables locally instead. - out.Write("\tfloat4 colors_0 = %s;\n", (g_ActiveConfig.iStereoMode > 0) ? "gs.vs.colors_0" : "colors_02"); - out.Write("\tfloat4 colors_1 = %s;\n", (g_ActiveConfig.iStereoMode > 0) ? "gs.vs.colors_1" : "colors_12"); + out.Write("\tfloat4 colors_0 = %s;\n", (g_ActiveConfig.iStereoMode > 0) ? "vs.colors_0" : "colors_02"); + out.Write("\tfloat4 colors_1 = %s;\n", (g_ActiveConfig.iStereoMode > 0) ? "vs.colors_1" : "colors_12"); out.Write("\tfloat4 rawpos = gl_FragCoord;\n"); } @@ -943,7 +943,7 @@ static inline void SampleTexture(T& out, const char *texcoords, const char *texs if (ApiType == API_D3D) out.Write("iround(255.0 * Tex%d.Sample(samp%d, float3(%s.xy * " I_TEXDIMS"[%d].xy, %s))).%s;\n", texmap, texmap, texcoords, texmap, g_ActiveConfig.iStereoMode > 0 ? "layer" : "0.0", texswap); else - out.Write("iround(255.0 * texture(samp%d, float3(%s.xy * " I_TEXDIMS"[%d].xy, %s))).%s;\n", texmap, texcoords, texmap, g_ActiveConfig.iStereoMode > 0 ? "gs.layer" : "0.0", texswap); + out.Write("iround(255.0 * texture(samp%d, float3(%s.xy * " I_TEXDIMS"[%d].xy, %s))).%s;\n", texmap, texcoords, texmap, g_ActiveConfig.iStereoMode > 0 ? "layer" : "0.0", texswap); } static const char *tevAlphaFuncsTable[] = diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index ed9bab9fca..618d262374 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -258,17 +258,6 @@ static inline void GenerateVSOutputStruct(T& object, API_TYPE api_type) object.Write("};\n"); } -template -static inline void GenerateGSOutputStruct(T& object, API_TYPE api_type) -{ - object.Write("struct GS_OUTPUT {\n"); - - DefineOutputStructMember(object, api_type, "VS_OUTPUT", "vs", -1, ""); - DefineOutputStructMember(object, api_type, (api_type == API_OPENGL) ? "flat int" : "uint", "layer", -1, "SV_RenderTargetArrayIndex"); - - object.Write("};\n"); -} - // Constant variable names #define I_COLORS "color" #define I_KCOLORS "k"