ShaderGen: Use consistent variable names for texture coordinates

This commit is contained in:
Stenzek 2017-07-27 01:01:25 +10:00
parent 25338c53e0
commit e17efb1d8d
5 changed files with 49 additions and 52 deletions

View File

@ -143,8 +143,8 @@ void SHADER::SetProgramBindings(bool is_compute)
glBindAttribLocation(glprogid, SHADER_POSMTX_ATTRIB, "posmtx");
glBindAttribLocation(glprogid, SHADER_COLOR0_ATTRIB, "color0");
glBindAttribLocation(glprogid, SHADER_COLOR1_ATTRIB, "color1");
glBindAttribLocation(glprogid, SHADER_COLOR0_ATTRIB, "rawcolor0");
glBindAttribLocation(glprogid, SHADER_COLOR1_ATTRIB, "rawcolor1");
glBindAttribLocation(glprogid, SHADER_NORM0_ATTRIB, "rawnorm0");
glBindAttribLocation(glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
@ -153,7 +153,7 @@ void SHADER::SetProgramBindings(bool is_compute)
for (int i = 0; i < 8; i++)
{
std::string attrib_name = StringFromFormat("tex%d", i);
std::string attrib_name = StringFromFormat("rawtex%d", i);
glBindAttribLocation(glprogid, SHADER_TEXTURE0_ATTRIB + i, attrib_name.c_str());
}
}

View File

@ -119,11 +119,11 @@ static const u8 rasters[CHARACTER_COUNT][CHARACTER_HEIGHT] = {
static const char* s_vertexShaderSrc = "uniform vec2 charSize;\n"
"uniform vec2 offset;"
"in vec2 rawpos;\n"
"in vec2 tex0;\n"
"in vec2 rawtex0;\n"
"out vec2 uv0;\n"
"void main(void) {\n"
" gl_Position = vec4(rawpos + offset,0,1);\n"
" uv0 = tex0 * charSize;\n"
" uv0 = rawtex0 * charSize;\n"
"}\n";
static const char* s_fragmentShaderSrc = "SAMPLER_BINDING(8) uniform sampler2D samp8;\n"

View File

@ -562,7 +562,7 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const ShaderHostConfig& host
// Let's set up attributes
for (unsigned int i = 0; i < uid_data->genMode_numtexgens; ++i)
{
out.Write("%s in float3 uv%d;\n", GetInterpolationQualifier(msaa, ssaa), i);
out.Write("%s in float3 tex%d;\n", GetInterpolationQualifier(msaa, ssaa), i);
}
out.Write("%s in float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa));
if (per_pixel_lighting)
@ -573,13 +573,6 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const ShaderHostConfig& host
}
out.Write("void main()\n{\n");
if (host_config.backend_geometry_shaders || ApiType == APIType::Vulkan)
{
for (unsigned int i = 0; i < uid_data->genMode_numtexgens; ++i)
out.Write("\tfloat3 uv%d = tex%d;\n", i, i);
}
out.Write("\tfloat4 rawpos = gl_FragCoord;\n");
}
else // D3D
@ -595,7 +588,8 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const ShaderHostConfig& host
// compute window position if needed because binding semantic WPOS is not widely supported
for (unsigned int i = 0; i < uid_data->genMode_numtexgens; ++i)
out.Write(",\n in %s float3 uv%d : TEXCOORD%d", GetInterpolationQualifier(msaa, ssaa), i, i);
out.Write(",\n in %s float3 tex%d : TEXCOORD%d", GetInterpolationQualifier(msaa, ssaa), i,
i);
out.Write(",\n in %s float4 clipPos : TEXCOORD%d", GetInterpolationQualifier(msaa, ssaa),
uid_data->genMode_numtexgens);
if (per_pixel_lighting)
@ -658,7 +652,7 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const ShaderHostConfig& host
for (unsigned int i = 0; i < uid_data->genMode_numtexgens; ++i)
{
out.Write("\tint2 fixpoint_uv%d = int2(", i);
out.Write("(uv%d.z == 0.0 ? uv%d.xy : uv%d.xy / uv%d.z)", i, i, i, i);
out.Write("(tex%d.z == 0.0 ? tex%d.xy : tex%d.xy / tex%d.z)", i, i, i, i);
out.Write(" * " I_TEXDIMS "[%d].zw);\n", i);
// TODO: S24 overflows here?
}

View File

@ -113,10 +113,10 @@ ShaderCode GenVertexShader(APIType ApiType, const ShaderHostConfig& host_config,
out.Write("ATTRIBUTE_LOCATION(%d) in float3 rawnorm0;\n", SHADER_NORM0_ATTRIB);
out.Write("ATTRIBUTE_LOCATION(%d) in float3 rawnorm1;\n", SHADER_NORM1_ATTRIB);
out.Write("ATTRIBUTE_LOCATION(%d) in float3 rawnorm2;\n", SHADER_NORM2_ATTRIB);
out.Write("ATTRIBUTE_LOCATION(%d) in float4 color0;\n", SHADER_COLOR0_ATTRIB);
out.Write("ATTRIBUTE_LOCATION(%d) in float4 color1;\n", SHADER_COLOR1_ATTRIB);
out.Write("ATTRIBUTE_LOCATION(%d) in float4 rawcolor0;\n", SHADER_COLOR0_ATTRIB);
out.Write("ATTRIBUTE_LOCATION(%d) in float4 rawcolor1;\n", SHADER_COLOR1_ATTRIB);
for (int i = 0; i < 8; ++i)
out.Write("ATTRIBUTE_LOCATION(%d) in float3 tex%d;\n", SHADER_TEXTURE0_ATTRIB + i, i);
out.Write("ATTRIBUTE_LOCATION(%d) in float3 rawtex%d;\n", SHADER_TEXTURE0_ATTRIB + i, i);
// We need to always use output blocks for Vulkan, but geometry shaders are also optional.
if (host_config.backend_geometry_shaders || ApiType == APIType::Vulkan)
@ -130,7 +130,7 @@ ShaderCode GenVertexShader(APIType ApiType, const ShaderHostConfig& host_config,
{
// Let's set up attributes
for (u32 i = 0; i < numTexgen; ++i)
out.Write("%s out float3 uv%u;\n", GetInterpolationQualifier(msaa, ssaa), i);
out.Write("%s out float3 tex%u;\n", GetInterpolationQualifier(msaa, ssaa), i);
out.Write("%s out float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa));
if (per_pixel_lighting)
@ -152,10 +152,10 @@ ShaderCode GenVertexShader(APIType ApiType, const ShaderHostConfig& host_config,
out.Write(" float3 rawnorm0 : NORMAL0,\n");
out.Write(" float3 rawnorm1 : NORMAL1,\n");
out.Write(" float3 rawnorm2 : NORMAL2,\n");
out.Write(" float4 color0 : COLOR0,\n");
out.Write(" float4 color1 : COLOR1,\n");
out.Write(" float4 rawcolor0 : COLOR0,\n");
out.Write(" float4 rawcolor1 : COLOR1,\n");
for (int i = 0; i < 8; ++i)
out.Write(" float3 tex%d : TEXCOORD%d,\n", i, i);
out.Write(" float3 rawtex%d : TEXCOORD%d,\n", i, i);
out.Write(" uint posmtx : BLENDINDICES,\n");
out.Write(" float4 rawpos : POSITION) {\n");
}
@ -307,7 +307,7 @@ ShaderCode GenVertexShader(APIType ApiType, const ShaderHostConfig& host_config,
// TODO: Pass interface blocks between shader stages even if geometry shaders
// are not supported, however that will require at least OpenGL 3.2 support.
for (u32 i = 0; i < numTexgen; ++i)
out.Write("uv%d.xyz = o.tex%d;\n", i, i);
out.Write("tex%d.xyz = o.tex%d;\n", i, i);
out.Write("clipPos = o.clipPos;\n");
out.Write("colors_0 = o.colors_0;\n");
out.Write("colors_1 = o.colors_1;\n");
@ -337,12 +337,12 @@ ShaderCode GenVertexShader(APIType ApiType, const ShaderHostConfig& host_config,
void GenVertexShaderLighting(APIType ApiType, ShaderCode& out)
{
out.Write("if ((components & %uu) != 0u) // VB_HAS_COL0\n", VB_HAS_COL0);
out.Write(" o.colors_0 = color0;\n"
out.Write(" o.colors_0 = rawcolor0;\n"
"else\n"
" o.colors_0 = float4(1.0, 1.0, 1.0, 1.0);\n"
"\n");
out.Write("if ((components & %uu) != 0u) // VB_HAS_COL1\n", VB_HAS_COL1);
out.Write(" o.colors_1 = color1;\n"
out.Write(" o.colors_1 = rawcolor1;\n"
"else\n"
" o.colors_1 = float4(1.0, 1.0, 1.0, 1.0);\n"
"\n");
@ -358,9 +358,10 @@ void GenVertexShaderLighting(APIType ApiType, ShaderCode& out)
out.Write(" if (%s != 0u) {\n", BitfieldExtract("colorreg", LitChannel().matsource).c_str());
out.Write(" if ((components & (%uu << chan)) != 0u) // VB_HAS_COL0\n", VB_HAS_COL0);
out.Write(" mat.xyz = int3(round(((chan == 0u) ? color0.xyz : color1.xyz) * 255.0));\n");
out.Write(
" mat.xyz = int3(round(((chan == 0u) ? rawcolor0.xyz : rawcolor1.xyz) * 255.0));\n");
out.Write(" else if ((components & %uu) != 0u) // VB_HAS_COLO0\n", VB_HAS_COL0);
out.Write(" mat.xyz = int3(round(color0.xyz * 255.0));\n"
out.Write(" mat.xyz = int3(round(rawcolor0.xyz * 255.0));\n"
" else\n"
" mat.xyz = int3(255, 255, 255);\n"
" }\n"
@ -368,9 +369,9 @@ void GenVertexShaderLighting(APIType ApiType, ShaderCode& out)
out.Write(" if (%s != 0u) {\n", BitfieldExtract("alphareg", LitChannel().matsource).c_str());
out.Write(" if ((components & (%uu << chan)) != 0u) // VB_HAS_COL0\n", VB_HAS_COL0);
out.Write(" mat.w = int(round(((chan == 0u) ? color0.w : color1.w) * 255.0));\n");
out.Write(" mat.w = int(round(((chan == 0u) ? rawcolor0.w : rawcolor1.w) * 255.0));\n");
out.Write(" else if ((components & %uu) != 0u) // VB_HAS_COLO0\n", VB_HAS_COL0);
out.Write(" mat.w = int(round(color0.w * 255.0));\n"
out.Write(" mat.w = int(round(rawcolor0.w * 255.0));\n"
" else\n"
" mat.w = 255;\n"
" } else {\n"
@ -382,9 +383,10 @@ void GenVertexShaderLighting(APIType ApiType, ShaderCode& out)
BitfieldExtract("colorreg", LitChannel().enablelighting).c_str());
out.Write(" if (%s != 0u) {\n", BitfieldExtract("colorreg", LitChannel().ambsource).c_str());
out.Write(" if ((components & (%uu << chan)) != 0u) // VB_HAS_COL0\n", VB_HAS_COL0);
out.Write(" lacc.xyz = int3(round(((chan == 0u) ? color0.xyz : color1.xyz) * 255.0));\n");
out.Write(
" lacc.xyz = int3(round(((chan == 0u) ? rawcolor0.xyz : rawcolor1.xyz) * 255.0));\n");
out.Write(" else if ((components & %uu) != 0u) // VB_HAS_COLO0\n", VB_HAS_COL0);
out.Write(" lacc.xyz = int3(round(color0.xyz * 255.0));\n"
out.Write(" lacc.xyz = int3(round(rawcolor0.xyz * 255.0));\n"
" else\n"
" lacc.xyz = int3(255, 255, 255);\n"
" } else {\n"
@ -410,9 +412,9 @@ void GenVertexShaderLighting(APIType ApiType, ShaderCode& out)
BitfieldExtract("alphareg", LitChannel().enablelighting).c_str());
out.Write(" if (%s != 0u) {\n", BitfieldExtract("alphareg", LitChannel().ambsource).c_str());
out.Write(" if ((components & (%uu << chan)) != 0u) // VB_HAS_COL0\n", VB_HAS_COL0);
out.Write(" lacc.w = int(round(((chan == 0u) ? color0.w : color1.w) * 255.0));\n");
out.Write(" lacc.w = int(round(((chan == 0u) ? rawcolor0.w : rawcolor1.w) * 255.0));\n");
out.Write(" else if ((components & %uu) != 0u) // VB_HAS_COLO0\n", VB_HAS_COL0);
out.Write(" lacc.w = int(round(color0.w * 255.0));\n"
out.Write(" lacc.w = int(round(rawcolor0.w * 255.0));\n"
" else\n"
" lacc.w = 255;\n"
" } else {\n"
@ -488,9 +490,10 @@ void GenVertexShaderTexGens(APIType ApiType, u32 numTexgen, ShaderCode& out)
for (u32 i = 0; i < 8; i++)
{
out.Write(" case %uu: // XF_SRCTEX%u_INROW\n", XF_SRCTEX0_INROW + i, i);
out.Write(" coord = ((components & %uu /* VB_HAS_UV%u */) != 0u) ? float4(tex%u.x, tex%u.y, "
"1.0, 1.0) : coord;\n",
VB_HAS_UV0 << i, i, i, i);
out.Write(
" coord = ((components & %uu /* VB_HAS_UV%u */) != 0u) ? float4(rawtex%u.x, rawtex%u.y, "
"1.0, 1.0) : coord;\n",
VB_HAS_UV0 << i, i, i, i);
out.Write(" break;\n\n");
}
out.Write(" }\n");
@ -541,7 +544,7 @@ void GenVertexShaderTexGens(APIType ApiType, u32 numTexgen, ShaderCode& out)
" int tmp = 0;\n"
" switch (texgen) {\n");
for (u32 i = 0; i < numTexgen; i++)
out.Write(" case %uu: tmp = int(tex%u.z); break;\n", i, i);
out.Write(" case %uu: tmp = int(rawtex%u.z); break;\n", i, i);
out.Write(" }\n"
"\n");
out.Write(" if (%s == %uu) {\n",

View File

@ -114,16 +114,16 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
out.Write("ATTRIBUTE_LOCATION(%d) in float3 rawnorm2;\n", SHADER_NORM2_ATTRIB);
if (uid_data->components & VB_HAS_COL0)
out.Write("ATTRIBUTE_LOCATION(%d) in float4 color0;\n", SHADER_COLOR0_ATTRIB);
out.Write("ATTRIBUTE_LOCATION(%d) in float4 rawcolor0;\n", SHADER_COLOR0_ATTRIB);
if (uid_data->components & VB_HAS_COL1)
out.Write("ATTRIBUTE_LOCATION(%d) in float4 color1;\n", SHADER_COLOR1_ATTRIB);
out.Write("ATTRIBUTE_LOCATION(%d) in float4 rawcolor1;\n", SHADER_COLOR1_ATTRIB);
for (int i = 0; i < 8; ++i)
{
u32 hastexmtx = (uid_data->components & (VB_HAS_TEXMTXIDX0 << i));
if ((uid_data->components & (VB_HAS_UV0 << i)) || hastexmtx)
{
out.Write("ATTRIBUTE_LOCATION(%d) in float%d tex%d;\n", SHADER_TEXTURE0_ATTRIB + i,
out.Write("ATTRIBUTE_LOCATION(%d) in float%d rawtex%d;\n", SHADER_TEXTURE0_ATTRIB + i,
hastexmtx ? 3 : 2, i);
}
}
@ -143,7 +143,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
{
if (i < uid_data->numTexGens)
{
out.Write("%s out float3 uv%u;\n", GetInterpolationQualifier(msaa, ssaa), i);
out.Write("%s out float3 tex%u;\n", GetInterpolationQualifier(msaa, ssaa), i);
}
}
out.Write("%s out float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa));
@ -170,14 +170,14 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
if (uid_data->components & VB_HAS_NRM2)
out.Write(" float3 rawnorm2 : NORMAL2,\n");
if (uid_data->components & VB_HAS_COL0)
out.Write(" float4 color0 : COLOR0,\n");
out.Write(" float4 rawcolor0 : COLOR0,\n");
if (uid_data->components & VB_HAS_COL1)
out.Write(" float4 color1 : COLOR1,\n");
out.Write(" float4 rawcolor1 : COLOR1,\n");
for (int i = 0; i < 8; ++i)
{
u32 hastexmtx = (uid_data->components & (VB_HAS_TEXMTXIDX0 << i));
if ((uid_data->components & (VB_HAS_UV0 << i)) || hastexmtx)
out.Write(" float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i, i);
out.Write(" float%d rawtex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i, i);
}
if (uid_data->components & VB_HAS_POSMTXIDX)
out.Write(" uint4 posmtx : BLENDINDICES,\n");
@ -242,18 +242,18 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
if (uid_data->numColorChans == 0)
{
if (uid_data->components & VB_HAS_COL0)
out.Write("o.colors_0 = color0;\n");
out.Write("o.colors_0 = rawcolor0;\n");
else
out.Write("o.colors_0 = float4(1.0, 1.0, 1.0, 1.0);\n");
}
GenerateLightingShaderCode(out, uid_data->lighting, uid_data->components, uid_data->numColorChans,
"color", "o.colors_");
"rawcolor", "o.colors_");
if (uid_data->numColorChans < 2)
{
if (uid_data->components & VB_HAS_COL1)
out.Write("o.colors_1 = color1;\n");
out.Write("o.colors_1 = rawcolor1;\n");
else
out.Write("o.colors_1 = o.colors_0;\n");
}
@ -296,7 +296,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
default:
_assert_(texinfo.sourcerow <= XF_SRCTEX7_INROW);
if (uid_data->components & (VB_HAS_UV0 << (texinfo.sourcerow - XF_SRCTEX0_INROW)))
out.Write("coord = float4(tex%d.x, tex%d.y, 1.0, 1.0);\n",
out.Write("coord = float4(rawtex%d.x, rawtex%d.y, 1.0, 1.0);\n",
texinfo.sourcerow - XF_SRCTEX0_INROW, texinfo.sourcerow - XF_SRCTEX0_INROW);
break;
}
@ -338,7 +338,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
default:
if (uid_data->components & (VB_HAS_TEXMTXIDX0 << i))
{
out.Write("int tmp = int(tex%d.z);\n", i);
out.Write("int tmp = int(rawtex%d.z);\n", i);
if (((uid_data->texMtxInfo_n_projection >> i) & 1) == XF_TEXPROJ_STQ)
out.Write("o.tex%d.xyz = float3(dot(coord, " I_TRANSFORMMATRICES
"[tmp]), dot(coord, " I_TRANSFORMMATRICES
@ -407,10 +407,10 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
out.Write("o.WorldPos = pos.xyz;\n");
if (uid_data->components & VB_HAS_COL0)
out.Write("o.colors_0 = color0;\n");
out.Write("o.colors_0 = rawcolor0;\n");
if (uid_data->components & VB_HAS_COL1)
out.Write("o.colors_1 = color1;\n");
out.Write("o.colors_1 = rawcolor1;\n");
}
// If we can disable the incorrect depth clipping planes using depth clamping, then we can do
@ -495,7 +495,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
// TODO: Pass interface blocks between shader stages even if geometry shaders
// are not supported, however that will require at least OpenGL 3.2 support.
for (unsigned int i = 0; i < uid_data->numTexGens; ++i)
out.Write("uv%d.xyz = o.tex%d;\n", i, i);
out.Write("tex%d.xyz = o.tex%d;\n", i, i);
out.Write("clipPos = o.clipPos;\n");
if (per_pixel_lighting)
{