summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/FramebufferShaderGen.cpp
diff options
context:
space:
mode:
authorLC <mathew1800@gmail.com>2020-11-09 22:08:42 -0500
committerGitHub <noreply@github.com>2020-11-09 22:08:42 -0500
commit0a2564a89d1fc669acf07ded151229910ba7addd (patch)
tree3b26b51bfe5bcccb8c3bbe29da8507fda191eaa4 /Source/Core/VideoCommon/FramebufferShaderGen.cpp
parent43e2f0e88f80686c2b76dcba4241a7be64e7bf55 (diff)
parenta5b28f1f07b0f310f407462ebb86eafbf4d63f20 (diff)
Merge pull request #9234 from lioncash/rename-fmt
ShaderGenCommon: Rename WriteFmt() to Write()
Diffstat (limited to 'Source/Core/VideoCommon/FramebufferShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/FramebufferShaderGen.cpp474
1 files changed, 236 insertions, 238 deletions
diff --git a/Source/Core/VideoCommon/FramebufferShaderGen.cpp b/Source/Core/VideoCommon/FramebufferShaderGen.cpp
index 0b4022239e..3e4f27a1e0 100644
--- a/Source/Core/VideoCommon/FramebufferShaderGen.cpp
+++ b/Source/Core/VideoCommon/FramebufferShaderGen.cpp
@@ -27,9 +27,9 @@ APIType GetAPIType()
void EmitUniformBufferDeclaration(ShaderCode& code)
{
if (GetAPIType() == APIType::D3D)
- code.WriteFmt("cbuffer PSBlock : register(b0)\n");
+ code.Write("cbuffer PSBlock : register(b0)\n");
else
- code.WriteFmt("UBO_BINDING(std140, 1) uniform PSBlock\n");
+ code.Write("UBO_BINDING(std140, 1) uniform PSBlock\n");
}
void EmitSamplerDeclarations(ShaderCode& code, u32 start = 0, u32 end = 1,
@@ -43,8 +43,8 @@ void EmitSamplerDeclarations(ShaderCode& code, u32 start = 0, u32 end = 1,
for (u32 i = start; i < end; i++)
{
- code.WriteFmt("{} tex{} : register(t{});\n", array_type, i, i);
- code.WriteFmt("SamplerState samp{} : register(s{});\n", i, i);
+ code.Write("{} tex{} : register(t{});\n", array_type, i, i);
+ code.Write("SamplerState samp{} : register(s{});\n", i, i);
}
}
break;
@@ -56,7 +56,7 @@ void EmitSamplerDeclarations(ShaderCode& code, u32 start = 0, u32 end = 1,
for (u32 i = start; i < end; i++)
{
- code.WriteFmt("SAMPLER_BINDING({}) uniform {} samp{};\n", i, array_type, i);
+ code.Write("SAMPLER_BINDING({}) uniform {} samp{};\n", i, array_type, i);
}
}
break;
@@ -70,12 +70,12 @@ void EmitSampleTexture(ShaderCode& code, u32 n, std::string_view coords)
switch (GetAPIType())
{
case APIType::D3D:
- code.WriteFmt("tex{}.Sample(samp{}, {})", n, n, coords);
+ code.Write("tex{}.Sample(samp{}, {})", n, n, coords);
break;
case APIType::OpenGL:
case APIType::Vulkan:
- code.WriteFmt("texture(samp{}, {})", n, coords);
+ code.Write("texture(samp{}, {})", n, coords);
break;
default:
@@ -90,12 +90,12 @@ void EmitTextureLoad(ShaderCode& code, u32 n, std::string_view coords)
switch (GetAPIType())
{
case APIType::D3D:
- code.WriteFmt("tex{}.Load({})", n, coords);
+ code.Write("tex{}.Load({})", n, coords);
break;
case APIType::OpenGL:
case APIType::Vulkan:
- code.WriteFmt("texelFetch(samp{}, ({}).xyz, ({}).w)", n, coords, coords);
+ code.Write("texelFetch(samp{}, ({}).xyz, ({}).w)", n, coords, coords);
break;
default:
@@ -111,19 +111,19 @@ void EmitVertexMainDeclaration(ShaderCode& code, u32 num_tex_inputs, u32 num_col
{
case APIType::D3D:
{
- code.WriteFmt("void main(");
+ code.Write("void main(");
for (u32 i = 0; i < num_tex_inputs; i++)
- code.WriteFmt("in float3 rawtex{} : TEXCOORD{}, ", i, i);
+ code.Write("in float3 rawtex{} : TEXCOORD{}, ", i, i);
for (u32 i = 0; i < num_color_inputs; i++)
- code.WriteFmt("in float4 rawcolor{} : COLOR{}, ", i, i);
+ code.Write("in float4 rawcolor{} : COLOR{}, ", i, i);
if (position_input)
- code.WriteFmt("in float4 rawpos : POSITION, ");
- code.WriteFmt("{}", extra_inputs);
+ code.Write("in float4 rawpos : POSITION, ");
+ code.Write("{}", extra_inputs);
for (u32 i = 0; i < num_tex_outputs; i++)
- code.WriteFmt("out float3 v_tex{} : TEXCOORD{}, ", i, i);
+ code.Write("out float3 v_tex{} : TEXCOORD{}, ", i, i);
for (u32 i = 0; i < num_color_outputs; i++)
- code.WriteFmt("out float4 v_col{} : COLOR{}, ", i, i);
- code.WriteFmt("out float4 opos : SV_Position)\n");
+ code.Write("out float4 v_col{} : COLOR{}, ", i, i);
+ code.Write("out float4 opos : SV_Position)\n");
}
break;
@@ -133,35 +133,35 @@ void EmitVertexMainDeclaration(ShaderCode& code, u32 num_tex_inputs, u32 num_col
for (u32 i = 0; i < num_tex_inputs; i++)
{
const auto attribute = SHADER_TEXTURE0_ATTRIB + i;
- code.WriteFmt("ATTRIBUTE_LOCATION({}) in float3 rawtex{};\n", attribute, i);
+ code.Write("ATTRIBUTE_LOCATION({}) in float3 rawtex{};\n", attribute, i);
}
for (u32 i = 0; i < num_color_inputs; i++)
{
const auto attribute = SHADER_COLOR0_ATTRIB + i;
- code.WriteFmt("ATTRIBUTE_LOCATION({}) in float4 rawcolor{};\n", attribute, i);
+ code.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor{};\n", attribute, i);
}
if (position_input)
- code.WriteFmt("ATTRIBUTE_LOCATION({}) in float4 rawpos;\n", SHADER_POSITION_ATTRIB);
+ code.Write("ATTRIBUTE_LOCATION({}) in float4 rawpos;\n", SHADER_POSITION_ATTRIB);
if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
{
- code.WriteFmt("VARYING_LOCATION(0) out VertexData {{\n");
+ code.Write("VARYING_LOCATION(0) out VertexData {{\n");
for (u32 i = 0; i < num_tex_outputs; i++)
- code.WriteFmt(" float3 v_tex{};\n", i);
+ code.Write(" float3 v_tex{};\n", i);
for (u32 i = 0; i < num_color_outputs; i++)
- code.WriteFmt(" float4 v_col{};\n", i);
- code.WriteFmt("}};\n");
+ code.Write(" float4 v_col{};\n", i);
+ code.Write("}};\n");
}
else
{
for (u32 i = 0; i < num_tex_outputs; i++)
- code.WriteFmt("VARYING_LOCATION({}) out float3 v_tex{};\n", i, i);
+ code.Write("VARYING_LOCATION({}) out float3 v_tex{};\n", i, i);
for (u32 i = 0; i < num_color_outputs; i++)
- code.WriteFmt("VARYING_LOCATION({}) out float4 v_col{};\n", num_tex_inputs + i, i);
+ code.Write("VARYING_LOCATION({}) out float4 v_col{};\n", num_tex_inputs + i, i);
}
- code.WriteFmt("#define opos gl_Position\n");
- code.WriteFmt("{}\n", extra_inputs);
- code.WriteFmt("void main()\n");
+ code.Write("#define opos gl_Position\n");
+ code.Write("{}\n", extra_inputs);
+ code.Write("void main()\n");
}
break;
default:
@@ -177,14 +177,14 @@ void EmitPixelMainDeclaration(ShaderCode& code, u32 num_tex_inputs, u32 num_colo
{
case APIType::D3D:
{
- code.WriteFmt("void main(");
+ code.Write("void main(");
for (u32 i = 0; i < num_tex_inputs; i++)
- code.WriteFmt("in float3 v_tex{} : TEXCOORD{}, ", i, i);
+ code.Write("in float3 v_tex{} : TEXCOORD{}, ", i, i);
for (u32 i = 0; i < num_color_inputs; i++)
- code.WriteFmt("in float4 v_col{} : COLOR{}, ", i, i);
+ code.Write("in float4 v_col{} : COLOR{}, ", i, i);
if (emit_frag_coord)
- code.WriteFmt("in float4 frag_coord : SV_Position, ");
- code.WriteFmt("{}out {} ocol0 : SV_Target)\n", extra_vars, output_type);
+ code.Write("in float4 frag_coord : SV_Position, ");
+ code.Write("{}out {} ocol0 : SV_Target)\n", extra_vars, output_type);
}
break;
@@ -193,26 +193,26 @@ void EmitPixelMainDeclaration(ShaderCode& code, u32 num_tex_inputs, u32 num_colo
{
if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
{
- code.WriteFmt("VARYING_LOCATION(0) in VertexData {{\n");
+ code.Write("VARYING_LOCATION(0) in VertexData {{\n");
for (u32 i = 0; i < num_tex_inputs; i++)
- code.WriteFmt(" in float3 v_tex{};\n", i);
+ code.Write(" in float3 v_tex{};\n", i);
for (u32 i = 0; i < num_color_inputs; i++)
- code.WriteFmt(" in float4 v_col{};\n", i);
- code.WriteFmt("}};\n");
+ code.Write(" in float4 v_col{};\n", i);
+ code.Write("}};\n");
}
else
{
for (u32 i = 0; i < num_tex_inputs; i++)
- code.WriteFmt("VARYING_LOCATION({}) in float3 v_tex{};\n", i, i);
+ code.Write("VARYING_LOCATION({}) in float3 v_tex{};\n", i, i);
for (u32 i = 0; i < num_color_inputs; i++)
- code.WriteFmt("VARYING_LOCATION({}) in float4 v_col{};\n", num_tex_inputs + i, i);
+ code.Write("VARYING_LOCATION({}) in float4 v_col{};\n", num_tex_inputs + i, i);
}
- code.WriteFmt("FRAGMENT_OUTPUT_LOCATION(0) out {} ocol0;\n", output_type);
- code.WriteFmt("{}\n", extra_vars);
+ code.Write("FRAGMENT_OUTPUT_LOCATION(0) out {} ocol0;\n", output_type);
+ code.Write("{}\n", extra_vars);
if (emit_frag_coord)
- code.WriteFmt("#define frag_coord gl_FragCoord\n");
- code.WriteFmt("void main()\n");
+ code.Write("#define frag_coord gl_FragCoord\n");
+ code.Write("void main()\n");
}
break;
@@ -228,16 +228,16 @@ std::string GenerateScreenQuadVertexShader()
EmitVertexMainDeclaration(code, 0, 0, false, 1, 0,
GetAPIType() == APIType::D3D ? "in uint id : SV_VertexID, " :
"#define id gl_VertexID\n");
- code.WriteFmt(
+ code.Write(
"{{\n"
" v_tex0 = float3(float((id << 1) & 2), float(id & 2), 0.0f);\n"
" opos = float4(v_tex0.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);\n");
// NDC space is flipped in Vulkan. We also flip in GL so that (0,0) is in the lower-left.
if (GetAPIType() == APIType::Vulkan || GetAPIType() == APIType::OpenGL)
- code.WriteFmt(" opos.y = -opos.y;\n");
+ code.Write(" opos.y = -opos.y;\n");
- code.WriteFmt("}}\n");
+ code.Write("}}\n");
return code.GetBuffer();
}
@@ -247,88 +247,88 @@ std::string GeneratePassthroughGeometryShader(u32 num_tex, u32 num_colors)
ShaderCode code;
if (GetAPIType() == APIType::D3D)
{
- code.WriteFmt("struct VS_OUTPUT\n"
- "{{\n");
+ code.Write("struct VS_OUTPUT\n"
+ "{{\n");
for (u32 i = 0; i < num_tex; i++)
- code.WriteFmt(" float3 tex{} : TEXCOORD{};\n", i, i);
+ code.Write(" float3 tex{} : TEXCOORD{};\n", i, i);
for (u32 i = 0; i < num_colors; i++)
- code.WriteFmt(" float4 color{} : COLOR{};\n", i, i);
- code.WriteFmt(" float4 position : SV_Position;\n"
- "}};\n");
+ code.Write(" float4 color{} : COLOR{};\n", i, i);
+ code.Write(" float4 position : SV_Position;\n"
+ "}};\n");
- code.WriteFmt("struct GS_OUTPUT\n"
- "{{");
+ code.Write("struct GS_OUTPUT\n"
+ "{{");
for (u32 i = 0; i < num_tex; i++)
- code.WriteFmt(" float3 tex{} : TEXCOORD{};\n", i, i);
+ code.Write(" float3 tex{} : TEXCOORD{};\n", i, i);
for (u32 i = 0; i < num_colors; i++)
- code.WriteFmt(" float4 color{} : COLOR{};\n", i, i);
- code.WriteFmt(" float4 position : SV_Position;\n"
- " uint slice : SV_RenderTargetArrayIndex;\n"
- "}};\n\n");
-
- code.WriteFmt("[maxvertexcount(6)]\n"
- "void main(triangle VS_OUTPUT vso[3], inout TriangleStream<GS_OUTPUT> output)\n"
- "{{\n"
- " for (uint slice = 0; slice < 2u; slice++)\n"
- " {{\n"
- " for (int i = 0; i < 3; i++)\n"
- " {{\n"
- " GS_OUTPUT gso;\n"
- " gso.position = vso[i].position;\n");
+ code.Write(" float4 color{} : COLOR{};\n", i, i);
+ code.Write(" float4 position : SV_Position;\n"
+ " uint slice : SV_RenderTargetArrayIndex;\n"
+ "}};\n\n");
+
+ code.Write("[maxvertexcount(6)]\n"
+ "void main(triangle VS_OUTPUT vso[3], inout TriangleStream<GS_OUTPUT> output)\n"
+ "{{\n"
+ " for (uint slice = 0; slice < 2u; slice++)\n"
+ " {{\n"
+ " for (int i = 0; i < 3; i++)\n"
+ " {{\n"
+ " GS_OUTPUT gso;\n"
+ " gso.position = vso[i].position;\n");
for (u32 i = 0; i < num_tex; i++)
- code.WriteFmt(" gso.tex{} = float3(vso[i].tex{}.xy, float(slice));\n", i, i);
+ code.Write(" gso.tex{} = float3(vso[i].tex{}.xy, float(slice));\n", i, i);
for (u32 i = 0; i < num_colors; i++)
- code.WriteFmt(" gso.color{} = vso[i].color{};\n", i, i);
- code.WriteFmt(" gso.slice = slice;\n"
- " output.Append(gso);\n"
- " }}\n"
- " output.RestartStrip();\n"
- " }}\n"
- "}}\n");
+ code.Write(" gso.color{} = vso[i].color{};\n", i, i);
+ code.Write(" gso.slice = slice;\n"
+ " output.Append(gso);\n"
+ " }}\n"
+ " output.RestartStrip();\n"
+ " }}\n"
+ "}}\n");
}
else if (GetAPIType() == APIType::OpenGL || GetAPIType() == APIType::Vulkan)
{
- code.WriteFmt("layout(triangles) in;\n"
- "layout(triangle_strip, max_vertices = 6) out;\n");
+ code.Write("layout(triangles) in;\n"
+ "layout(triangle_strip, max_vertices = 6) out;\n");
if (num_tex > 0 || num_colors > 0)
{
- code.WriteFmt("VARYING_LOCATION(0) in VertexData {{\n");
+ code.Write("VARYING_LOCATION(0) in VertexData {{\n");
for (u32 i = 0; i < num_tex; i++)
- code.WriteFmt(" float3 v_tex{};\n", i);
+ code.Write(" float3 v_tex{};\n", i);
for (u32 i = 0; i < num_colors; i++)
- code.WriteFmt(" float4 v_col{};\n", i);
- code.WriteFmt("}} v_in[];\n");
+ code.Write(" float4 v_col{};\n", i);
+ code.Write("}} v_in[];\n");
- code.WriteFmt("VARYING_LOCATION(0) out VertexData {{\n");
+ code.Write("VARYING_LOCATION(0) out VertexData {{\n");
for (u32 i = 0; i < num_tex; i++)
- code.WriteFmt(" float3 v_tex{};\n", i);
+ code.Write(" float3 v_tex{};\n", i);
for (u32 i = 0; i < num_colors; i++)
- code.WriteFmt(" float4 v_col{};\n", i);
- code.WriteFmt("}} v_out;\n");
+ code.Write(" float4 v_col{};\n", i);
+ code.Write("}} v_out;\n");
}
- code.WriteFmt("\n"
- "void main()\n"
- "{{\n"
- " for (int j = 0; j < 2; j++)\n"
- " {{\n"
- " gl_Layer = j;\n");
+ code.Write("\n"
+ "void main()\n"
+ "{{\n"
+ " for (int j = 0; j < 2; j++)\n"
+ " {{\n"
+ " gl_Layer = j;\n");
// We have to explicitly unroll this loop otherwise the GL compiler gets cranky.
for (u32 v = 0; v < 3; v++)
{
- code.WriteFmt(" gl_Position = gl_in[{}].gl_Position;\n", v);
+ code.Write(" gl_Position = gl_in[{}].gl_Position;\n", v);
for (u32 i = 0; i < num_tex; i++)
{
- code.WriteFmt(" v_out.v_tex{} = float3(v_in[{}].v_tex{}.xy, float(j));\n", i, v, i);
+ code.Write(" v_out.v_tex{} = float3(v_in[{}].v_tex{}.xy, float(j));\n", i, v, i);
}
for (u32 i = 0; i < num_colors; i++)
- code.WriteFmt(" v_out.v_col{} = v_in[{}].v_col{};\n", i, v, i);
- code.WriteFmt(" EmitVertex();\n\n");
+ code.Write(" v_out.v_col{} = v_in[{}].v_col{};\n", i, v, i);
+ code.Write(" EmitVertex();\n\n");
}
- code.WriteFmt(" EndPrimitive();\n"
- " }}\n"
- "}}\n");
+ code.Write(" EndPrimitive();\n"
+ " }}\n"
+ "}}\n");
}
return code.GetBuffer();
@@ -338,25 +338,24 @@ std::string GenerateTextureCopyVertexShader()
{
ShaderCode code;
EmitUniformBufferDeclaration(code);
- code.WriteFmt("{{"
- " float2 src_offset;\n"
- " float2 src_size;\n"
- "}};\n\n");
+ code.Write("{{"
+ " float2 src_offset;\n"
+ " float2 src_size;\n"
+ "}};\n\n");
EmitVertexMainDeclaration(code, 0, 0, false, 1, 0,
GetAPIType() == APIType::D3D ? "in uint id : SV_VertexID, " :
"#define id gl_VertexID");
- code.WriteFmt(
- "{{\n"
- " v_tex0 = float3(float((id << 1) & 2), float(id & 2), 0.0f);\n"
- " opos = float4(v_tex0.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);\n"
- " v_tex0 = float3(src_offset + (src_size * v_tex0.xy), 0.0f);\n");
+ code.Write("{{\n"
+ " v_tex0 = float3(float((id << 1) & 2), float(id & 2), 0.0f);\n"
+ " opos = float4(v_tex0.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);\n"
+ " v_tex0 = float3(src_offset + (src_size * v_tex0.xy), 0.0f);\n");
// NDC space is flipped in Vulkan. We also flip in GL so that (0,0) is in the lower-left.
if (GetAPIType() == APIType::Vulkan || GetAPIType() == APIType::OpenGL)
- code.WriteFmt(" opos.y = -opos.y;\n");
+ code.Write(" opos.y = -opos.y;\n");
- code.WriteFmt("}}\n");
+ code.Write("}}\n");
return code.GetBuffer();
}
@@ -366,11 +365,11 @@ std::string GenerateTextureCopyPixelShader()
ShaderCode code;
EmitSamplerDeclarations(code, 0, 1, false);
EmitPixelMainDeclaration(code, 1, 0);
- code.WriteFmt("{{\n"
- " ocol0 = ");
+ code.Write("{{\n"
+ " ocol0 = ");
EmitSampleTexture(code, 0, "v_tex0");
- code.WriteFmt(";\n"
- "}}\n");
+ code.Write(";\n"
+ "}}\n");
return code.GetBuffer();
}
@@ -378,9 +377,9 @@ std::string GenerateColorPixelShader()
{
ShaderCode code;
EmitPixelMainDeclaration(code, 0, 1);
- code.WriteFmt("{{\n"
- " ocol0 = v_col0;\n"
- "}}\n");
+ code.Write("{{\n"
+ " ocol0 = v_col0;\n"
+ "}}\n");
return code.GetBuffer();
}
@@ -390,25 +389,25 @@ std::string GenerateResolveDepthPixelShader(u32 samples)
EmitSamplerDeclarations(code, 0, 1, true);
EmitPixelMainDeclaration(code, 1, 0, "float",
GetAPIType() == APIType::D3D ? "in float4 ipos : SV_Position, " : "");
- code.WriteFmt("{{\n"
- " int layer = int(v_tex0.z);\n");
+ code.Write("{{\n"
+ " int layer = int(v_tex0.z);\n");
if (GetAPIType() == APIType::D3D)
- code.WriteFmt(" int3 coords = int3(int2(ipos.xy), layer);\n");
+ code.Write(" int3 coords = int3(int2(ipos.xy), layer);\n");
else
- code.WriteFmt(" int3 coords = int3(int2(gl_FragCoord.xy), layer);\n");
+ code.Write(" int3 coords = int3(int2(gl_FragCoord.xy), layer);\n");
// Take the minimum of all depth samples.
if (GetAPIType() == APIType::D3D)
- code.WriteFmt(" ocol0 = tex0.Load(coords, 0).r;\n");
+ code.Write(" ocol0 = tex0.Load(coords, 0).r;\n");
else
- code.WriteFmt(" ocol0 = texelFetch(samp0, coords, 0).r;\n");
- code.WriteFmt(" for (int i = 1; i < {}; i++)\n", samples);
+ code.Write(" ocol0 = texelFetch(samp0, coords, 0).r;\n");
+ code.Write(" for (int i = 1; i < {}; i++)\n", samples);
if (GetAPIType() == APIType::D3D)
- code.WriteFmt(" ocol0 = min(ocol0, tex0.Load(coords, i).r);\n");
+ code.Write(" ocol0 = min(ocol0, tex0.Load(coords, i).r);\n");
else
- code.WriteFmt(" ocol0 = min(ocol0, texelFetch(samp0, coords, i).r);\n");
+ code.Write(" ocol0 = min(ocol0, texelFetch(samp0, coords, i).r);\n");
- code.WriteFmt("}}\n");
+ code.Write("}}\n");
return code.GetBuffer();
}
@@ -416,15 +415,15 @@ std::string GenerateClearVertexShader()
{
ShaderCode code;
EmitUniformBufferDeclaration(code);
- code.WriteFmt("{{\n"
- " float4 clear_color;\n"
- " float clear_depth;\n"
- "}};\n");
+ code.Write("{{\n"
+ " float4 clear_color;\n"
+ " float clear_depth;\n"
+ "}};\n");
EmitVertexMainDeclaration(code, 0, 0, false, 0, 1,
GetAPIType() == APIType::D3D ? "in uint id : SV_VertexID, " :
"#define id gl_VertexID\n");
- code.WriteFmt(
+ code.Write(
"{{\n"
" float2 coord = float2(float((id << 1) & 2), float(id & 2));\n"
" opos = float4(coord * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), clear_depth, 1.0f);\n"
@@ -432,9 +431,9 @@ std::string GenerateClearVertexShader()
// NDC space is flipped in Vulkan
if (GetAPIType() == APIType::Vulkan)
- code.WriteFmt(" opos.y = -opos.y;\n");
+ code.Write(" opos.y = -opos.y;\n");
- code.WriteFmt("}}\n");
+ code.Write("}}\n");
return code.GetBuffer();
}
@@ -443,17 +442,17 @@ std::string GenerateEFBPokeVertexShader()
{
ShaderCode code;
EmitVertexMainDeclaration(code, 0, 1, true, 0, 1);
- code.WriteFmt("{{\n"
- " v_col0 = rawcolor0;\n"
- " opos = float4(rawpos.xyz, 1.0f);\n");
+ code.Write("{{\n"
+ " v_col0 = rawcolor0;\n"
+ " opos = float4(rawpos.xyz, 1.0f);\n");
if (g_ActiveConfig.backend_info.bSupportsLargePoints)
- code.WriteFmt(" gl_PointSize = rawpos.w;\n");
+ code.Write(" gl_PointSize = rawpos.w;\n");
// NDC space is flipped in Vulkan.
if (GetAPIType() == APIType::Vulkan)
- code.WriteFmt(" opos.y = -opos.y;\n");
+ code.Write(" opos.y = -opos.y;\n");
- code.WriteFmt("}}\n");
+ code.Write("}}\n");
return code.GetBuffer();
}
@@ -468,82 +467,82 @@ std::string GenerateFormatConversionShader(EFBReinterpretType convtype, u32 samp
"in float4 ipos : SV_Position, in uint isample : SV_SampleIndex, " :
"in float4 ipos : SV_Position, ") :
"");
- code.WriteFmt("{{\n"
- " int layer = int(v_tex0.z);\n");
+ code.Write("{{\n"
+ " int layer = int(v_tex0.z);\n");
if (GetAPIType() == APIType::D3D)
- code.WriteFmt(" int3 coords = int3(int2(ipos.xy), layer);\n");
+ code.Write(" int3 coords = int3(int2(ipos.xy), layer);\n");
else
- code.WriteFmt(" int3 coords = int3(int2(gl_FragCoord.xy), layer);\n");
+ code.Write(" int3 coords = int3(int2(gl_FragCoord.xy), layer);\n");
if (samples == 1)
{
// No MSAA at all.
if (GetAPIType() == APIType::D3D)
- code.WriteFmt(" float4 val = tex0.Load(int4(coords, 0));\n");
+ code.Write(" float4 val = tex0.Load(int4(coords, 0));\n");
else
- code.WriteFmt(" float4 val = texelFetch(samp0, coords, 0);\n");
+ code.Write(" float4 val = texelFetch(samp0, coords, 0);\n");
}
else if (g_ActiveConfig.bSSAA)
{
// Sample shading, shader runs once per sample
if (GetAPIType() == APIType::D3D)
- code.WriteFmt(" float4 val = tex0.Load(coords, isample);");
+ code.Write(" float4 val = tex0.Load(coords, isample);");
else
- code.WriteFmt(" float4 val = texelFetch(samp0, coords, gl_SampleID);");
+ code.Write(" float4 val = texelFetch(samp0, coords, gl_SampleID);");
}
else
{
// MSAA without sample shading, average out all samples.
- code.WriteFmt(" float4 val = float4(0.0f, 0.0f, 0.0f, 0.0f);\n");
- code.WriteFmt(" for (int i = 0; i < {}; i++)\n", samples);
+ code.Write(" float4 val = float4(0.0f, 0.0f, 0.0f, 0.0f);\n");
+ code.Write(" for (int i = 0; i < {}; i++)\n", samples);
if (GetAPIType() == APIType::D3D)
- code.WriteFmt(" val += tex0.Load(coords, i);\n");
+ code.Write(" val += tex0.Load(coords, i);\n");
else
- code.WriteFmt(" val += texelFetch(samp0, coords, i);\n");
- code.WriteFmt(" val /= float({});\n", samples);
+ code.Write(" val += texelFetch(samp0, coords, i);\n");
+ code.Write(" val /= float({});\n", samples);
}
switch (convtype)
{
case EFBReinterpretType::RGB8ToRGBA6:
- code.WriteFmt(" int4 src8 = int4(round(val * 255.f));\n"
- " int4 dst6;\n"
- " dst6.r = src8.r >> 2;\n"
- " dst6.g = ((src8.r & 0x3) << 4) | (src8.g >> 4);\n"
- " dst6.b = ((src8.g & 0xF) << 2) | (src8.b >> 6);\n"
- " dst6.a = src8.b & 0x3F;\n"
- " ocol0 = float4(dst6) / 63.f;\n");
+ code.Write(" int4 src8 = int4(round(val * 255.f));\n"
+ " int4 dst6;\n"
+ " dst6.r = src8.r >> 2;\n"
+ " dst6.g = ((src8.r & 0x3) << 4) | (src8.g >> 4);\n"
+ " dst6.b = ((src8.g & 0xF) << 2) | (src8.b >> 6);\n"
+ " dst6.a = src8.b & 0x3F;\n"
+ " ocol0 = float4(dst6) / 63.f;\n");
break;
case EFBReinterpretType::RGB8ToRGB565:
- code.WriteFmt(" ocol0 = val;\n");
+ code.Write(" ocol0 = val;\n");
break;
case EFBReinterpretType::RGBA6ToRGB8:
- code.WriteFmt(" int4 src6 = int4(round(val * 63.f));\n"
- " int4 dst8;\n"
- " dst8.r = (src6.r << 2) | (src6.g >> 4);\n"
- " dst8.g = ((src6.g & 0xF) << 4) | (src6.b >> 2);\n"
- " dst8.b = ((src6.b & 0x3) << 6) | src6.a;\n"
- " dst8.a = 255;\n"
- " ocol0 = float4(dst8) / 255.f;\n");
+ code.Write(" int4 src6 = int4(round(val * 63.f));\n"
+ " int4 dst8;\n"
+ " dst8.r = (src6.r << 2) | (src6.g >> 4);\n"
+ " dst8.g = ((src6.g & 0xF) << 4) | (src6.b >> 2);\n"
+ " dst8.b = ((src6.b & 0x3) << 6) | src6.a;\n"
+ " dst8.a = 255;\n"
+ " ocol0 = float4(dst8) / 255.f;\n");
break;
case EFBReinterpretType::RGBA6ToRGB565:
- code.WriteFmt(" ocol0 = val;\n");
+ code.Write(" ocol0 = val;\n");
break;
case EFBReinterpretType::RGB565ToRGB8:
- code.WriteFmt(" ocol0 = val;\n");
+ code.Write(" ocol0 = val;\n");
break;
case EFBReinterpretType::RGB565ToRGBA6:
//
- code.WriteFmt(" ocol0 = val;\n");
+ code.Write(" ocol0 = val;\n");
break;
}
- code.WriteFmt("}}\n");
+ code.Write("}}\n");
return code.GetBuffer();
}
@@ -552,71 +551,70 @@ std::string GenerateTextureReinterpretShader(TextureFormat from_format, TextureF
ShaderCode code;
EmitSamplerDeclarations(code, 0, 1, false);
EmitPixelMainDeclaration(code, 1, 0, "float4", "", true);
- code.WriteFmt("{{\n"
- " int layer = int(v_tex0.z);\n"
- " int4 coords = int4(int2(frag_coord.xy), layer, 0);\n");
+ code.Write("{{\n"
+ " int layer = int(v_tex0.z);\n"
+ " int4 coords = int4(int2(frag_coord.xy), layer, 0);\n");
// Convert to a 32-bit value encompassing all channels, filling the most significant bits with
// zeroes.
- code.WriteFmt(" uint raw_value;\n");
+ code.Write(" uint raw_value;\n");
switch (from_format)
{
case TextureFormat::I8:
case TextureFormat::C8:
{
- code.WriteFmt(" float4 temp_value = ");
+ code.Write(" float4 temp_value = ");
EmitTextureLoad(code, 0, "coords");
- code.WriteFmt(";\n"
- " raw_value = uint(temp_value.r * 255.0);\n");
+ code.Write(";\n"
+ " raw_value = uint(temp_value.r * 255.0);\n");
}
break;
case TextureFormat::IA8:
{
- code.WriteFmt(" float4 temp_value = ");
+ code.Write(" float4 temp_value = ");
EmitTextureLoad(code, 0, "coords");
- code.WriteFmt(
- ";\n"
- " raw_value = uint(temp_value.r * 255.0) | (uint(temp_value.a * 255.0) << 8);\n");
+ code.Write(";\n"
+ " raw_value = uint(temp_value.r * 255.0) | (uint(temp_value.a * 255.0) << 8);\n");
}
break;
case TextureFormat::I4:
{
- code.WriteFmt(" float4 temp_value = ");
+ code.Write(" float4 temp_value = ");
EmitTextureLoad(code, 0, "coords");
- code.WriteFmt(";\n"
- " raw_value = uint(temp_value.r * 15.0);\n");
+ code.Write(";\n"
+ " raw_value = uint(temp_value.r * 15.0);\n");
}
break;
case TextureFormat::IA4:
{
- code.WriteFmt(" float4 temp_value = ");
+ code.Write(" float4 temp_value = ");
EmitTextureLoad(code, 0, "coords");
- code.WriteFmt(";\n"
- " raw_value = uint(temp_value.r * 15.0) | (uint(temp_value.a * 15.0) << 4);\n");
+ code.Write(";\n"
+ " raw_value = uint(temp_value.r * 15.0) | (uint(temp_value.a * 15.0) << 4);\n");
}
break;
case TextureFormat::RGB565:
{
- code.WriteFmt(" float4 temp_value = ");
+ code.Write(" float4 temp_value = ");
EmitTextureLoad(code, 0, "coords");
- code.WriteFmt(";\n"
- " raw_value = uint(temp_value.b * 31.0) | (uint(temp_value.g * 63.0) << 5) |\n"
- " (uint(temp_value.r * 31.0) << 11);\n");
+ code.Write(";\n"
+ " raw_value = uint(temp_value.b * 31.0) | (uint(temp_value.g * 63.0) << 5) |\n"
+ " (uint(temp_value.r * 31.0) << 11);\n");
}
break;
case TextureFormat::RGB5A3:
{
- code.WriteFmt(" float4 temp_value = ");
+ code.Write(" float4 temp_value = ");
EmitTextureLoad(code, 0, "coords");
- code.WriteFmt(";\n");
+ code.Write(";\n");
// 0.8784 = 224 / 255 which is the maximum alpha value that can be represented in 3 bits
- code.WriteFmt(
+ code.Write(
" if (temp_value.a > 0.878f) {{\n"
" raw_value = (uint(temp_value.b * 31.0)) | (uint(temp_value.g * 31.0) << 5) |\n"
" (uint(temp_value.r * 31.0) << 10) | 0x8000u;\n"
@@ -638,45 +636,45 @@ std::string GenerateTextureReinterpretShader(TextureFormat from_format, TextureF
case TextureFormat::I8:
case TextureFormat::C8:
{
- code.WriteFmt(" float orgba = float(raw_value & 0xFFu) / 255.0;\n"
- " ocol0 = float4(orgba, orgba, orgba, orgba);\n");
+ code.Write(" float orgba = float(raw_value & 0xFFu) / 255.0;\n"
+ " ocol0 = float4(orgba, orgba, orgba, orgba);\n");
}
break;
case TextureFormat::IA8:
{
- code.WriteFmt(" float orgb = float(raw_value & 0xFFu) / 255.0;\n"
- " ocol0 = float4(orgb, orgb, orgb, float((raw_value >> 8) & 0xFFu) / 255.0);\n");
+ code.Write(" float orgb = float(raw_value & 0xFFu) / 255.0;\n"
+ " ocol0 = float4(orgb, orgb, orgb, float((raw_value >> 8) & 0xFFu) / 255.0);\n");
}
break;
case TextureFormat::IA4:
{
- code.WriteFmt(" float orgb = float(raw_value & 0xFu) / 15.0;\n"
- " ocol0 = float4(orgb, orgb, orgb, float((raw_value >> 4) & 0xFu) / 15.0);\n");
+ code.Write(" float orgb = float(raw_value & 0xFu) / 15.0;\n"
+ " ocol0 = float4(orgb, orgb, orgb, float((raw_value >> 4) & 0xFu) / 15.0);\n");
}
break;
case TextureFormat::RGB565:
{
- code.WriteFmt(" ocol0 = float4(float((raw_value >> 10) & 0x1Fu) / 31.0,\n"
- " float((raw_value >> 5) & 0x1Fu) / 31.0,\n"
- " float(raw_value & 0x1Fu) / 31.0, 1.0);\n");
+ code.Write(" ocol0 = float4(float((raw_value >> 10) & 0x1Fu) / 31.0,\n"
+ " float((raw_value >> 5) & 0x1Fu) / 31.0,\n"
+ " float(raw_value & 0x1Fu) / 31.0, 1.0);\n");
}
break;
case TextureFormat::RGB5A3:
{
- code.WriteFmt(" if ((raw_value & 0x8000u) != 0u) {{\n"
- " ocol0 = float4(float((raw_value >> 10) & 0x1Fu) / 31.0,\n"
- " float((raw_value >> 5) & 0x1Fu) / 31.0,\n"
- " float(raw_value & 0x1Fu) / 31.0, 1.0);\n"
- " }} else {{\n"
- " ocol0 = float4(float((raw_value >> 8) & 0x0Fu) / 15.0,\n"
- " float((raw_value >> 4) & 0x0Fu) / 15.0,\n"
- " float(raw_value & 0x0Fu) / 15.0,\n"
- " float((raw_value >> 12) & 0x07u) / 7.0);\n"
- " }}\n");
+ code.Write(" if ((raw_value & 0x8000u) != 0u) {{\n"
+ " ocol0 = float4(float((raw_value >> 10) & 0x1Fu) / 31.0,\n"
+ " float((raw_value >> 5) & 0x1Fu) / 31.0,\n"
+ " float(raw_value & 0x1Fu) / 31.0, 1.0);\n"
+ " }} else {{\n"
+ " ocol0 = float4(float((raw_value >> 8) & 0x0Fu) / 15.0,\n"
+ " float((raw_value >> 4) & 0x0Fu) / 15.0,\n"
+ " float(raw_value & 0x0Fu) / 15.0,\n"
+ " float((raw_value >> 12) & 0x07u) / 7.0);\n"
+ " }}\n");
}
break;
default:
@@ -684,7 +682,7 @@ std::string GenerateTextureReinterpretShader(TextureFormat from_format, TextureF
return "{}\n";
}
- code.WriteFmt("}}\n");
+ code.Write("}}\n");
return code.GetBuffer();
}
@@ -694,14 +692,14 @@ std::string GenerateEFBRestorePixelShader()
EmitSamplerDeclarations(code, 0, 2, false);
EmitPixelMainDeclaration(code, 1, 0, "float4",
GetAPIType() == APIType::D3D ? "out float depth : SV_Depth, " : "");
- code.WriteFmt("{{\n"
- " ocol0 = ");
+ code.Write("{{\n"
+ " ocol0 = ");
EmitSampleTexture(code, 0, "v_tex0");
- code.WriteFmt(";\n");
- code.WriteFmt(" {} = ", GetAPIType() == APIType::D3D ? "depth" : "gl_FragDepth");
+ code.Write(";\n");
+ code.Write(" {} = ", GetAPIType() == APIType::D3D ? "depth" : "gl_FragDepth");
EmitSampleTexture(code, 1, "v_tex0");
- code.WriteFmt(".r;\n"
- "}}\n");
+ code.Write(".r;\n"
+ "}}\n");
return code.GetBuffer();
}
@@ -711,22 +709,22 @@ std::string GenerateImGuiVertexShader()
// Uniform buffer contains the viewport size, and we transform in the vertex shader.
EmitUniformBufferDeclaration(code);
- code.WriteFmt("{{\n"
- "float2 u_rcp_viewport_size_mul2;\n"
- "}};\n\n");
+ code.Write("{{\n"
+ "float2 u_rcp_viewport_size_mul2;\n"
+ "}};\n\n");
EmitVertexMainDeclaration(code, 1, 1, true, 1, 1);
- code.WriteFmt("{{\n"
- " v_tex0 = float3(rawtex0.xy, 0.0);\n"
- " v_col0 = rawcolor0;\n"
- " opos = float4(rawpos.x * u_rcp_viewport_size_mul2.x - 1.0,"
- " 1.0 - rawpos.y * u_rcp_viewport_size_mul2.y, 0.0, 1.0);\n");
+ code.Write("{{\n"
+ " v_tex0 = float3(rawtex0.xy, 0.0);\n"
+ " v_col0 = rawcolor0;\n"
+ " opos = float4(rawpos.x * u_rcp_viewport_size_mul2.x - 1.0,"
+ " 1.0 - rawpos.y * u_rcp_viewport_size_mul2.y, 0.0, 1.0);\n");
// NDC space is flipped in Vulkan.
if (GetAPIType() == APIType::Vulkan)
- code.WriteFmt(" opos.y = -opos.y;\n");
+ code.Write(" opos.y = -opos.y;\n");
- code.WriteFmt("}}\n");
+ code.Write("}}\n");
return code.GetBuffer();
}
@@ -735,11 +733,11 @@ std::string GenerateImGuiPixelShader()
ShaderCode code;
EmitSamplerDeclarations(code, 0, 1, false);
EmitPixelMainDeclaration(code, 1, 1);
- code.WriteFmt("{{\n"
- " ocol0 = ");
+ code.Write("{{\n"
+ " ocol0 = ");
EmitSampleTexture(code, 0, "float3(v_tex0.xy, 0.0)");
- code.WriteFmt(" * v_col0;\n"
- "}}\n");
+ code.Write(" * v_col0;\n"
+ "}}\n");
return code.GetBuffer();
}