Pass VS_OUTPUT structs between shaders.

This commit is contained in:
Jules Blok 2014-10-25 02:05:49 +02:00
parent b005f61a2e
commit 2d8ec62beb
3 changed files with 34 additions and 46 deletions

View File

@ -73,12 +73,12 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy
GenerateVSOutputStructForGS(code, ApiType);
out.Write(code.GetBuffer());
out.Write("in VS_OUTPUT vertices[];\n");
out.Write("out VS_OUTPUT frag;\n");
out.Write("centroid in VS_OUTPUT v[];\n");
out.Write("centroid out VS_OUTPUT o;\n");
out.Write("void main()\n{\n");
out.Write("\tfor (int i = 0; i < gl_in.length(); ++i) {\n");
out.Write("\t\tfrag = vertices[i];\n");
out.Write("\t\to = v[i];\n");
out.Write("\t\tgl_Position = gl_in[i].gl_Position;\n");
out.Write("\t\tgl_Layer = gl_InvocationID;\n");
out.Write("\t\tEmitVertex();\n");

View File

@ -16,6 +16,7 @@
#include "VideoCommon/LightingShaderGen.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/PixelShaderGen.h"
#include "VideoCommon/VertexShaderGen.h"
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.h" // for texture projection mode
@ -275,6 +276,12 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
);
}
ShaderCode code;
char buf[16384];
code.SetBuffer(buf);
GenerateVSOutputStructForGS(code, ApiType);
out.Write(code.GetBuffer());
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);
@ -325,22 +332,27 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
// As a workaround, we interpolate at the centroid of the coveraged pixel, which
// is always inside the primitive.
// Without MSAA, this flag is defined to have no effect.
out.Write("centroid in float4 colors_02;\n");
out.Write("centroid in float4 colors_12;\n");
out.Write("centroid in VS_OUTPUT o;\n");
out.Write("void main()\n{\n");
// compute window position if needed because binding semantic WPOS is not widely supported
// Let's set up attributes
for (unsigned int i = 0; i < numTexgen; ++i)
{
out.Write("centroid in float3 uv%d;\n", i);
out.Write("\tfloat3 uv%d = o.tex%d;\n", i, i);
}
out.Write("centroid in float4 clipPos;\n");
out.Write("\tfloat4 clipPos = o.clipPos;\n");
if (g_ActiveConfig.bEnablePixelLighting)
{
out.Write("centroid in float4 Normal;\n");
out.Write("\tfloat4 Normal = o.Normal;\n");
}
out.Write("void main()\n{\n");
// On Mali, global variables must be initialized as constants.
// This is why we initialize these variables locally instead.
out.Write("\tfloat4 colors_0 = o.colors_0;\n");
out.Write("\tfloat4 colors_1 = o.colors_1;\n");
out.Write("\tfloat4 rawpos = gl_FragCoord;\n");
}
else // D3D
@ -370,14 +382,6 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
"\tint2 wrappedcoord=int2(0,0), tempcoord=int2(0,0);\n"
"\tint4 tevin_a=int4(0,0,0,0),tevin_b=int4(0,0,0,0),tevin_c=int4(0,0,0,0),tevin_d=int4(0,0,0,0);\n\n"); // tev combiner inputs
if (ApiType == API_OPENGL)
{
// On Mali, global variables must be initialized as constants.
// This is why we initialize these variables locally instead.
out.Write("\tfloat4 colors_0 = colors_02;\n");
out.Write("\tfloat4 colors_1 = colors_12;\n");
}
if (g_ActiveConfig.bEnablePixelLighting)
{
out.Write("\tfloat3 _norm0 = normalize(Normal.xyz);\n\n");

View File

@ -131,22 +131,16 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
out.Write("in float%d tex%d; // ATTR%d,\n", hastexmtx ? 3 : 2, i, SHADER_TEXTURE0_ATTRIB + i);
}
// Let's set up attributes
for (size_t i = 0; i < 8; ++i)
{
if (i < xfmem.numTexGen.numTexGens)
{
out.Write("centroid out float3 uv%d;\n", i);
}
}
out.Write("centroid out float4 clipPos;\n");
if (g_ActiveConfig.bEnablePixelLighting)
out.Write("centroid out float4 Normal;\n");
out.Write("centroid out float4 colors_02;\n");
out.Write("centroid out float4 colors_12;\n");
if (g_ActiveConfig.bStereo)
out.Write("centroid out VS_OUTPUT v;\n");
else
out.Write("centroid out VS_OUTPUT o;\n");
out.Write("void main()\n{\n");
if (g_ActiveConfig.bStereo)
out.Write("VS_OUTPUT o;\n");
}
else // D3D
{
@ -172,8 +166,9 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
if (components & VB_HAS_POSMTXIDX)
out.Write(" int posmtx : BLENDINDICES,\n");
out.Write(" float4 rawpos : POSITION) {\n");
out.Write("VS_OUTPUT o;\n");
}
out.Write("VS_OUTPUT o;\n");
// transforms
if (components & VB_HAS_POSMTXIDX)
@ -431,27 +426,16 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
if (api_type == API_OPENGL)
{
// Bit ugly here
// TODO: Make pretty
// Will look better when we bind uniforms in GLSL 1.3
// clipPos/w needs to be done in pixel shader, not here
if (g_ActiveConfig.bStereo)
out.Write("v = o;\n");
for (unsigned int i = 0; i < xfmem.numTexGen.numTexGens; ++i)
out.Write(" uv%d.xyz = o.tex%d;\n", i, i);
out.Write(" clipPos = o.clipPos;\n");
if (g_ActiveConfig.bEnablePixelLighting)
out.Write(" Normal = o.Normal;\n");
out.Write("colors_02 = o.colors_0;\n");
out.Write("colors_12 = o.colors_1;\n");
out.Write("gl_Position = o.pos;\n");
out.Write("}\n");
}
else // D3D
{
out.Write("return o;\n}\n");
out.Write("return o;\n");
}
out.Write("}\n");
if (is_writing_shadercode)
{