summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/GeometryShaderGen.cpp
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2020-11-09 02:23:32 -0500
committerLioncash <mathew1800@gmail.com>2020-11-09 02:31:49 -0500
commita5b28f1f07b0f310f407462ebb86eafbf4d63f20 (patch)
tree191784de45d42f3d608a2f2fabde4b0d5993deb0 /Source/Core/VideoCommon/GeometryShaderGen.cpp
parenta9ef7e0e436795d1ef842aae7433c6173f623f90 (diff)
ShaderGenCommon: Rename WriteFmt() to Write()
Now that we've converted all of the shader generators over to using fmt, we can drop the old Write() member function and perform a rename operation on the WriteFmt() to turn it into the new Write() function. All changes within this are the removal of a <cstdarg> header, since the previous printf-based Write() required it, and renaming. No functional changes are made at all.
Diffstat (limited to 'Source/Core/VideoCommon/GeometryShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/GeometryShaderGen.cpp216
1 files changed, 107 insertions, 109 deletions
diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp
index dd8dc6df38..718bc6d4cb 100644
--- a/Source/Core/VideoCommon/GeometryShaderGen.cpp
+++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp
@@ -73,133 +73,131 @@ ShaderCode GenerateGeometryShaderCode(APIType ApiType, const ShaderHostConfig& h
// Insert layout parameters
if (host_config.backend_gs_instancing)
{
- out.WriteFmt("layout({}, invocations = {}) in;\n", primitives_ogl[primitive_type_index],
- stereo ? 2 : 1);
- out.WriteFmt("layout({}_strip, max_vertices = {}) out;\n", wireframe ? "line" : "triangle",
- vertex_out);
+ out.Write("layout({}, invocations = {}) in;\n", primitives_ogl[primitive_type_index],
+ stereo ? 2 : 1);
+ out.Write("layout({}_strip, max_vertices = {}) out;\n", wireframe ? "line" : "triangle",
+ vertex_out);
}
else
{
- out.WriteFmt("layout({}) in;\n", primitives_ogl[primitive_type_index]);
- out.WriteFmt("layout({}_strip, max_vertices = {}) out;\n", wireframe ? "line" : "triangle",
- stereo ? vertex_out * 2 : vertex_out);
+ out.Write("layout({}) in;\n", primitives_ogl[primitive_type_index]);
+ out.Write("layout({}_strip, max_vertices = {}) out;\n", wireframe ? "line" : "triangle",
+ stereo ? vertex_out * 2 : vertex_out);
}
}
- out.WriteFmt("{}", s_lighting_struct);
+ out.Write("{}", s_lighting_struct);
// uniforms
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
- out.WriteFmt("UBO_BINDING(std140, 3) uniform GSBlock {{\n");
+ out.Write("UBO_BINDING(std140, 3) uniform GSBlock {{\n");
else
- out.WriteFmt("cbuffer GSBlock {{\n");
+ out.Write("cbuffer GSBlock {{\n");
- out.WriteFmt("\tfloat4 " I_STEREOPARAMS ";\n"
- "\tfloat4 " I_LINEPTPARAMS ";\n"
- "\tint4 " I_TEXOFFSET ";\n"
- "}};\n");
+ out.Write("\tfloat4 " I_STEREOPARAMS ";\n"
+ "\tfloat4 " I_LINEPTPARAMS ";\n"
+ "\tint4 " I_TEXOFFSET ";\n"
+ "}};\n");
- out.WriteFmt("struct VS_OUTPUT {{\n");
+ out.Write("struct VS_OUTPUT {{\n");
GenerateVSOutputMembers(out, ApiType, uid_data->numTexGens, host_config, "");
- out.WriteFmt("}};\n");
+ out.Write("}};\n");
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
{
if (host_config.backend_gs_instancing)
- out.WriteFmt("#define InstanceID gl_InvocationID\n");
+ out.Write("#define InstanceID gl_InvocationID\n");
- out.WriteFmt("VARYING_LOCATION(0) in VertexData {{\n");
+ out.Write("VARYING_LOCATION(0) in VertexData {{\n");
GenerateVSOutputMembers(out, ApiType, uid_data->numTexGens, host_config,
GetInterpolationQualifier(msaa, ssaa, true, true));
- out.WriteFmt("}} vs[{}];\n", vertex_in);
+ out.Write("}} vs[{}];\n", vertex_in);
- out.WriteFmt("VARYING_LOCATION(0) out VertexData {{\n");
+ out.Write("VARYING_LOCATION(0) out VertexData {{\n");
GenerateVSOutputMembers(out, ApiType, uid_data->numTexGens, host_config,
GetInterpolationQualifier(msaa, ssaa, true, false));
if (stereo)
- out.WriteFmt("\tflat int layer;\n");
+ out.Write("\tflat int layer;\n");
- out.WriteFmt("}} ps;\n");
+ out.Write("}} ps;\n");
- out.WriteFmt("void main()\n{{\n");
+ out.Write("void main()\n{{\n");
}
else // D3D
{
- out.WriteFmt("struct VertexData {{\n");
- out.WriteFmt("\tVS_OUTPUT o;\n");
+ out.Write("struct VertexData {{\n");
+ out.Write("\tVS_OUTPUT o;\n");
if (stereo)
- out.WriteFmt("\tuint layer : SV_RenderTargetArrayIndex;\n");
+ out.Write("\tuint layer : SV_RenderTargetArrayIndex;\n");
- out.WriteFmt("}};\n");
+ out.Write("}};\n");
if (host_config.backend_gs_instancing)
{
- out.WriteFmt("[maxvertexcount({})]\n[instance({})]\n", vertex_out, stereo ? 2 : 1);
- out.WriteFmt("void main({} VS_OUTPUT o[{}], inout {}Stream<VertexData> output, in uint "
- "InstanceID : SV_GSInstanceID)\n{{\n",
- primitives_d3d[primitive_type_index], vertex_in,
- wireframe ? "Line" : "Triangle");
+ out.Write("[maxvertexcount({})]\n[instance({})]\n", vertex_out, stereo ? 2 : 1);
+ out.Write("void main({} VS_OUTPUT o[{}], inout {}Stream<VertexData> output, in uint "
+ "InstanceID : SV_GSInstanceID)\n{{\n",
+ primitives_d3d[primitive_type_index], vertex_in, wireframe ? "Line" : "Triangle");
}
else
{
- out.WriteFmt("[maxvertexcount({})]\n", stereo ? vertex_out * 2 : vertex_out);
- out.WriteFmt("void main({} VS_OUTPUT o[{}], inout {}Stream<VertexData> output)\n{{\n",
- primitives_d3d[primitive_type_index], vertex_in,
- wireframe ? "Line" : "Triangle");
+ out.Write("[maxvertexcount({})]\n", stereo ? vertex_out * 2 : vertex_out);
+ out.Write("void main({} VS_OUTPUT o[{}], inout {}Stream<VertexData> output)\n{{\n",
+ primitives_d3d[primitive_type_index], vertex_in, wireframe ? "Line" : "Triangle");
}
- out.WriteFmt("\tVertexData ps;\n");
+ out.Write("\tVertexData ps;\n");
}
if (primitive_type == PrimitiveType::Lines)
{
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
{
- out.WriteFmt("\tVS_OUTPUT start, end;\n");
+ out.Write("\tVS_OUTPUT start, end;\n");
AssignVSOutputMembers(out, "start", "vs[0]", uid_data->numTexGens, host_config);
AssignVSOutputMembers(out, "end", "vs[1]", uid_data->numTexGens, host_config);
}
else
{
- out.WriteFmt("\tVS_OUTPUT start = o[0];\n"
- "\tVS_OUTPUT end = o[1];\n");
+ out.Write("\tVS_OUTPUT start = o[0];\n"
+ "\tVS_OUTPUT end = o[1];\n");
}
// GameCube/Wii's line drawing algorithm is a little quirky. It does not
// use the correct line caps. Instead, the line caps are vertical or
// horizontal depending the slope of the line.
- out.WriteFmt("\tfloat2 offset;\n"
- "\tfloat2 to = abs(end.pos.xy / end.pos.w - start.pos.xy / start.pos.w);\n"
- // FIXME: What does real hardware do when line is at a 45-degree angle?
- // FIXME: Lines aren't drawn at the correct width. See Twilight Princess map.
- "\tif (" I_LINEPTPARAMS ".y * to.y > " I_LINEPTPARAMS ".x * to.x) {{\n"
- // Line is more tall. Extend geometry left and right.
- // Lerp LineWidth/2 from [0..VpWidth] to [-1..1]
- "\t\toffset = float2(" I_LINEPTPARAMS ".z / " I_LINEPTPARAMS ".x, 0);\n"
- "\t}} else {{\n"
- // Line is more wide. Extend geometry up and down.
- // Lerp LineWidth/2 from [0..VpHeight] to [1..-1]
- "\t\toffset = float2(0, -" I_LINEPTPARAMS ".z / " I_LINEPTPARAMS ".y);\n"
- "\t}}\n");
+ out.Write("\tfloat2 offset;\n"
+ "\tfloat2 to = abs(end.pos.xy / end.pos.w - start.pos.xy / start.pos.w);\n"
+ // FIXME: What does real hardware do when line is at a 45-degree angle?
+ // FIXME: Lines aren't drawn at the correct width. See Twilight Princess map.
+ "\tif (" I_LINEPTPARAMS ".y * to.y > " I_LINEPTPARAMS ".x * to.x) {{\n"
+ // Line is more tall. Extend geometry left and right.
+ // Lerp LineWidth/2 from [0..VpWidth] to [-1..1]
+ "\t\toffset = float2(" I_LINEPTPARAMS ".z / " I_LINEPTPARAMS ".x, 0);\n"
+ "\t}} else {{\n"
+ // Line is more wide. Extend geometry up and down.
+ // Lerp LineWidth/2 from [0..VpHeight] to [1..-1]
+ "\t\toffset = float2(0, -" I_LINEPTPARAMS ".z / " I_LINEPTPARAMS ".y);\n"
+ "\t}}\n");
}
else if (primitive_type == PrimitiveType::Points)
{
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
{
- out.WriteFmt("\tVS_OUTPUT center;\n");
+ out.Write("\tVS_OUTPUT center;\n");
AssignVSOutputMembers(out, "center", "vs[0]", uid_data->numTexGens, host_config);
}
else
{
- out.WriteFmt("\tVS_OUTPUT center = o[0];\n");
+ out.Write("\tVS_OUTPUT center = o[0];\n");
}
// Offset from center to upper right vertex
// Lerp PointSize/2 from [0,0..VpWidth,VpHeight] to [-1,1..1,-1]
- out.WriteFmt("\tfloat2 offset = float2(" I_LINEPTPARAMS ".w / " I_LINEPTPARAMS
- ".x, -" I_LINEPTPARAMS ".w / " I_LINEPTPARAMS ".y) * center.pos.w;\n");
+ out.Write("\tfloat2 offset = float2(" I_LINEPTPARAMS ".w / " I_LINEPTPARAMS
+ ".x, -" I_LINEPTPARAMS ".w / " I_LINEPTPARAMS ".y) * center.pos.w;\n");
}
if (stereo)
@@ -207,19 +205,19 @@ ShaderCode GenerateGeometryShaderCode(APIType ApiType, const ShaderHostConfig& h
// If the GPU supports invocation we don't need a for loop and can simply use the
// invocation identifier to determine which layer we're rendering.
if (host_config.backend_gs_instancing)
- out.WriteFmt("\tint eye = InstanceID;\n");
+ out.Write("\tint eye = InstanceID;\n");
else
- out.WriteFmt("\tfor (int eye = 0; eye < 2; ++eye) {{\n");
+ out.Write("\tfor (int eye = 0; eye < 2; ++eye) {{\n");
}
if (wireframe)
- out.WriteFmt("\tVS_OUTPUT first;\n");
+ out.Write("\tVS_OUTPUT first;\n");
- out.WriteFmt("\tfor (int i = 0; i < {}; ++i) {{\n", vertex_in);
+ out.Write("\tfor (int i = 0; i < {}; ++i) {{\n", vertex_in);
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
{
- out.WriteFmt("\tVS_OUTPUT f;\n");
+ out.Write("\tVS_OUTPUT f;\n");
AssignVSOutputMembers(out, "f", "vs[i]", uid_data->numTexGens, host_config);
if (host_config.backend_depth_clamp &&
@@ -227,21 +225,21 @@ ShaderCode GenerateGeometryShaderCode(APIType ApiType, const ShaderHostConfig& h
{
// On certain GPUs we have to consume the clip distance from the vertex shader
// or else the other vertex shader outputs will get corrupted.
- out.WriteFmt("\tf.clipDist0 = gl_in[i].gl_ClipDistance[0];\n"
- "\tf.clipDist1 = gl_in[i].gl_ClipDistance[1];\n");
+ out.Write("\tf.clipDist0 = gl_in[i].gl_ClipDistance[0];\n"
+ "\tf.clipDist1 = gl_in[i].gl_ClipDistance[1];\n");
}
}
else
{
- out.WriteFmt("\tVS_OUTPUT f = o[i];\n");
+ out.Write("\tVS_OUTPUT f = o[i];\n");
}
if (stereo)
{
// Select the output layer
- out.WriteFmt("\tps.layer = eye;\n");
+ out.Write("\tps.layer = eye;\n");
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
- out.WriteFmt("\tgl_Layer = eye;\n");
+ out.Write("\tgl_Layer = eye;\n");
// For stereoscopy add a small horizontal offset in Normalized Device Coordinates proportional
// to the depth of the vertex. We retrieve the depth value from the w-component of the projected
@@ -250,56 +248,56 @@ ShaderCode GenerateGeometryShaderCode(APIType ApiType, const ShaderHostConfig& h
// 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.WriteFmt("\tfloat hoffset = (eye == 0) ? " I_STEREOPARAMS ".x : " I_STEREOPARAMS ".y;\n");
- out.WriteFmt("\tf.pos.x += hoffset * (f.pos.w - " I_STEREOPARAMS ".z);\n");
+ out.Write("\tfloat hoffset = (eye == 0) ? " I_STEREOPARAMS ".x : " I_STEREOPARAMS ".y;\n");
+ out.Write("\tf.pos.x += hoffset * (f.pos.w - " I_STEREOPARAMS ".z);\n");
}
if (primitive_type == PrimitiveType::Lines)
{
- out.WriteFmt("\tVS_OUTPUT l = f;\n"
- "\tVS_OUTPUT r = f;\n");
+ out.Write("\tVS_OUTPUT l = f;\n"
+ "\tVS_OUTPUT r = f;\n");
- out.WriteFmt("\tl.pos.xy -= offset * l.pos.w;\n"
- "\tr.pos.xy += offset * r.pos.w;\n");
+ out.Write("\tl.pos.xy -= offset * l.pos.w;\n"
+ "\tr.pos.xy += offset * r.pos.w;\n");
- out.WriteFmt("\tif (" I_TEXOFFSET "[2] != 0) {{\n");
- out.WriteFmt("\tfloat texOffset = 1.0 / float(" I_TEXOFFSET "[2]);\n");
+ out.Write("\tif (" I_TEXOFFSET "[2] != 0) {{\n");
+ out.Write("\tfloat texOffset = 1.0 / float(" I_TEXOFFSET "[2]);\n");
for (u32 i = 0; i < uid_data->numTexGens; ++i)
{
- out.WriteFmt("\tif (((" I_TEXOFFSET "[0] >> {}) & 0x1) != 0)\n", i);
- out.WriteFmt("\t\tr.tex{}.x += texOffset;\n", i);
+ out.Write("\tif (((" I_TEXOFFSET "[0] >> {}) & 0x1) != 0)\n", i);
+ out.Write("\t\tr.tex{}.x += texOffset;\n", i);
}
- out.WriteFmt("\t}}\n");
+ out.Write("\t}}\n");
EmitVertex(out, host_config, uid_data, "l", ApiType, wireframe, true);
EmitVertex(out, host_config, uid_data, "r", ApiType, wireframe);
}
else if (primitive_type == PrimitiveType::Points)
{
- out.WriteFmt("\tVS_OUTPUT ll = f;\n"
- "\tVS_OUTPUT lr = f;\n"
- "\tVS_OUTPUT ul = f;\n"
- "\tVS_OUTPUT ur = f;\n");
+ out.Write("\tVS_OUTPUT ll = f;\n"
+ "\tVS_OUTPUT lr = f;\n"
+ "\tVS_OUTPUT ul = f;\n"
+ "\tVS_OUTPUT ur = f;\n");
- out.WriteFmt("\tll.pos.xy += float2(-1,-1) * offset;\n"
- "\tlr.pos.xy += float2(1,-1) * offset;\n"
- "\tul.pos.xy += float2(-1,1) * offset;\n"
- "\tur.pos.xy += offset;\n");
+ out.Write("\tll.pos.xy += float2(-1,-1) * offset;\n"
+ "\tlr.pos.xy += float2(1,-1) * offset;\n"
+ "\tul.pos.xy += float2(-1,1) * offset;\n"
+ "\tur.pos.xy += offset;\n");
- out.WriteFmt("\tif (" I_TEXOFFSET "[3] != 0) {{\n");
- out.WriteFmt("\tfloat2 texOffset = float2(1.0 / float(" I_TEXOFFSET
- "[3]), 1.0 / float(" I_TEXOFFSET "[3]));\n");
+ out.Write("\tif (" I_TEXOFFSET "[3] != 0) {{\n");
+ out.Write("\tfloat2 texOffset = float2(1.0 / float(" I_TEXOFFSET
+ "[3]), 1.0 / float(" I_TEXOFFSET "[3]));\n");
for (u32 i = 0; i < uid_data->numTexGens; ++i)
{
- out.WriteFmt("\tif (((" I_TEXOFFSET "[1] >> {}) & 0x1) != 0) {{\n", i);
- out.WriteFmt("\t\tul.tex{}.xy += float2(0,1) * texOffset;\n", i);
- out.WriteFmt("\t\tur.tex{}.xy += texOffset;\n", i);
- out.WriteFmt("\t\tlr.tex{}.xy += float2(1,0) * texOffset;\n", i);
- out.WriteFmt("\t}}\n");
+ out.Write("\tif (((" I_TEXOFFSET "[1] >> {}) & 0x1) != 0) {{\n", i);
+ out.Write("\t\tul.tex{}.xy += float2(0,1) * texOffset;\n", i);
+ out.Write("\t\tur.tex{}.xy += texOffset;\n", i);
+ out.Write("\t\tlr.tex{}.xy += float2(1,0) * texOffset;\n", i);
+ out.Write("\t}}\n");
}
- out.WriteFmt("\t}}\n");
+ out.Write("\t}}\n");
EmitVertex(out, host_config, uid_data, "ll", ApiType, wireframe, true);
EmitVertex(out, host_config, uid_data, "lr", ApiType, wireframe);
@@ -311,14 +309,14 @@ ShaderCode GenerateGeometryShaderCode(APIType ApiType, const ShaderHostConfig& h
EmitVertex(out, host_config, uid_data, "f", ApiType, wireframe, true);
}
- out.WriteFmt("\t}}\n");
+ out.Write("\t}}\n");
EndPrimitive(out, host_config, uid_data, ApiType, wireframe);
if (stereo && !host_config.backend_gs_instancing)
- out.WriteFmt("\t}}\n");
+ out.Write("\t}}\n");
- out.WriteFmt("}}\n");
+ out.Write("}}\n");
return out;
}
@@ -328,34 +326,34 @@ static void EmitVertex(ShaderCode& out, const ShaderHostConfig& host_config,
APIType ApiType, bool wireframe, bool first_vertex)
{
if (wireframe && first_vertex)
- out.WriteFmt("\tif (i == 0) first = {};\n", vertex);
+ out.Write("\tif (i == 0) first = {};\n", vertex);
if (ApiType == APIType::OpenGL)
{
- out.WriteFmt("\tgl_Position = {}.pos;\n", vertex);
+ out.Write("\tgl_Position = {}.pos;\n", vertex);
if (host_config.backend_depth_clamp)
{
- out.WriteFmt("\tgl_ClipDistance[0] = {}.clipDist0;\n", vertex);
- out.WriteFmt("\tgl_ClipDistance[1] = {}.clipDist1;\n", vertex);
+ out.Write("\tgl_ClipDistance[0] = {}.clipDist0;\n", vertex);
+ out.Write("\tgl_ClipDistance[1] = {}.clipDist1;\n", vertex);
}
AssignVSOutputMembers(out, "ps", vertex, uid_data->numTexGens, host_config);
}
else if (ApiType == APIType::Vulkan)
{
// Vulkan NDC space has Y pointing down (right-handed NDC space).
- out.WriteFmt("\tgl_Position = {}.pos;\n", vertex);
- out.WriteFmt("\tgl_Position.y = -gl_Position.y;\n");
+ out.Write("\tgl_Position = {}.pos;\n", vertex);
+ out.Write("\tgl_Position.y = -gl_Position.y;\n");
AssignVSOutputMembers(out, "ps", vertex, uid_data->numTexGens, host_config);
}
else
{
- out.WriteFmt("\tps.o = {};\n", vertex);
+ out.Write("\tps.o = {};\n", vertex);
}
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
- out.WriteFmt("\tEmitVertex();\n");
+ out.Write("\tEmitVertex();\n");
else
- out.WriteFmt("\toutput.Append(ps);\n");
+ out.Write("\toutput.Append(ps);\n");
}
static void EndPrimitive(ShaderCode& out, const ShaderHostConfig& host_config,
@@ -365,9 +363,9 @@ static void EndPrimitive(ShaderCode& out, const ShaderHostConfig& host_config,
EmitVertex(out, host_config, uid_data, "first", ApiType, wireframe);
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
- out.WriteFmt("\tEndPrimitive();\n");
+ out.Write("\tEndPrimitive();\n");
else
- out.WriteFmt("\toutput.RestartStrip();\n");
+ out.Write("\toutput.RestartStrip();\n");
}
void EnumerateGeometryShaderUids(const std::function<void(const GeometryShaderUid&)>& callback)