summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/UberShaderVertex.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2022-07-08 15:29:58 -0400
committerGitHub <noreply@github.com>2022-07-08 15:29:58 -0400
commit828afc67356c2299c6056d618eb6b7afe4c843b9 (patch)
treecb7809cf9aad689968ec209e8d886b5457ca68dc /Source/Core/VideoCommon/UberShaderVertex.cpp
parent7cc89f5642cab3b91aef1c8255af857a1607ddf6 (diff)
parenta8b52663479effc0f404f7c0f8b52bc0ee37b742 (diff)
Merge pull request #10673 from iwubcode/spirv-backends
D3D: Generate HLSL from SPIRV*
Diffstat (limited to 'Source/Core/VideoCommon/UberShaderVertex.cpp')
-rw-r--r--Source/Core/VideoCommon/UberShaderVertex.cpp162
1 files changed, 67 insertions, 95 deletions
diff --git a/Source/Core/VideoCommon/UberShaderVertex.cpp b/Source/Core/VideoCommon/UberShaderVertex.cpp
index 3f05400a46..67dd84bb7f 100644
--- a/Source/Core/VideoCommon/UberShaderVertex.cpp
+++ b/Source/Core/VideoCommon/UberShaderVertex.cpp
@@ -38,85 +38,65 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
out.Write("{}", s_lighting_struct);
// uniforms
- if (api_type == APIType::OpenGL || api_type == APIType::Vulkan)
- out.Write("UBO_BINDING(std140, 2) uniform VSBlock {{\n");
- else
- out.Write("cbuffer VSBlock {{\n");
+ out.Write("UBO_BINDING(std140, 2) uniform VSBlock {{\n");
out.Write("{}", s_shader_uniforms);
out.Write("}};\n");
out.Write("struct VS_OUTPUT {{\n");
- GenerateVSOutputMembers(out, api_type, num_texgen, host_config, "");
+ GenerateVSOutputMembers(out, api_type, num_texgen, host_config, "", ShaderStage::Vertex);
out.Write("}};\n\n");
WriteIsNanHeader(out, api_type);
WriteBitfieldExtractHeader(out, api_type, host_config);
WriteLightingFunction(out);
- if (api_type == APIType::OpenGL || api_type == APIType::Vulkan)
+ out.Write("ATTRIBUTE_LOCATION({}) in float4 rawpos;\n", SHADER_POSITION_ATTRIB);
+ out.Write("ATTRIBUTE_LOCATION({}) in uint4 posmtx;\n", SHADER_POSMTX_ATTRIB);
+ out.Write("ATTRIBUTE_LOCATION({}) in float3 rawnormal;\n", SHADER_NORMAL_ATTRIB);
+ out.Write("ATTRIBUTE_LOCATION({}) in float3 rawtangent;\n", SHADER_TANGENT_ATTRIB);
+ out.Write("ATTRIBUTE_LOCATION({}) in float3 rawbinormal;\n", SHADER_BINORMAL_ATTRIB);
+ out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor0;\n", SHADER_COLOR0_ATTRIB);
+ out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor1;\n", SHADER_COLOR1_ATTRIB);
+ for (int i = 0; i < 8; ++i)
+ out.Write("ATTRIBUTE_LOCATION({}) in float3 rawtex{};\n", SHADER_TEXTURE0_ATTRIB + i, i);
+
+ if (host_config.backend_geometry_shaders)
{
- out.Write("ATTRIBUTE_LOCATION({}) in float4 rawpos;\n", SHADER_POSITION_ATTRIB);
- out.Write("ATTRIBUTE_LOCATION({}) in uint4 posmtx;\n", SHADER_POSMTX_ATTRIB);
- out.Write("ATTRIBUTE_LOCATION({}) in float3 rawnormal;\n", SHADER_NORMAL_ATTRIB);
- out.Write("ATTRIBUTE_LOCATION({}) in float3 rawtangent;\n", SHADER_TANGENT_ATTRIB);
- out.Write("ATTRIBUTE_LOCATION({}) in float3 rawbinormal;\n", SHADER_BINORMAL_ATTRIB);
- out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor0;\n", SHADER_COLOR0_ATTRIB);
- out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor1;\n", SHADER_COLOR1_ATTRIB);
- for (int i = 0; i < 8; ++i)
- out.Write("ATTRIBUTE_LOCATION({}) in float3 rawtex{};\n", SHADER_TEXTURE0_ATTRIB + i, i);
-
- if (host_config.backend_geometry_shaders)
+ out.Write("VARYING_LOCATION(0) out VertexData {{\n");
+ GenerateVSOutputMembers(out, api_type, num_texgen, host_config,
+ GetInterpolationQualifier(msaa, ssaa, true, false),
+ ShaderStage::Vertex);
+ out.Write("}} vs;\n");
+ }
+ else
+ {
+ // Let's set up attributes
+ u32 counter = 0;
+ out.Write("VARYING_LOCATION({}) {} out float4 colors_0;\n", counter++,
+ GetInterpolationQualifier(msaa, ssaa));
+ out.Write("VARYING_LOCATION({}) {} out float4 colors_1;\n", counter++,
+ GetInterpolationQualifier(msaa, ssaa));
+ for (u32 i = 0; i < num_texgen; ++i)
+ {
+ out.Write("VARYING_LOCATION({}) {} out float3 tex{};\n", counter++,
+ GetInterpolationQualifier(msaa, ssaa), i);
+ }
+ if (!host_config.fast_depth_calc)
{
- out.Write("VARYING_LOCATION(0) out VertexData {{\n");
- GenerateVSOutputMembers(out, api_type, num_texgen, host_config,
- GetInterpolationQualifier(msaa, ssaa, true, false));
- out.Write("}} vs;\n");
+ out.Write("VARYING_LOCATION({}) {} out float4 clipPos;\n", counter++,
+ GetInterpolationQualifier(msaa, ssaa));
}
- else
+ if (per_pixel_lighting)
{
- // Let's set up attributes
- u32 counter = 0;
- out.Write("VARYING_LOCATION({}) {} out float4 colors_0;\n", counter++,
+ out.Write("VARYING_LOCATION({}) {} out float3 Normal;\n", counter++,
GetInterpolationQualifier(msaa, ssaa));
- out.Write("VARYING_LOCATION({}) {} out float4 colors_1;\n", counter++,
+ out.Write("VARYING_LOCATION({}) {} out float3 WorldPos;\n", counter++,
GetInterpolationQualifier(msaa, ssaa));
- for (u32 i = 0; i < num_texgen; ++i)
- {
- out.Write("VARYING_LOCATION({}) {} out float3 tex{};\n", counter++,
- GetInterpolationQualifier(msaa, ssaa), i);
- }
- if (!host_config.fast_depth_calc)
- {
- out.Write("VARYING_LOCATION({}) {} out float4 clipPos;\n", counter++,
- GetInterpolationQualifier(msaa, ssaa));
- }
- if (per_pixel_lighting)
- {
- out.Write("VARYING_LOCATION({}) {} out float3 Normal;\n", counter++,
- GetInterpolationQualifier(msaa, ssaa));
- out.Write("VARYING_LOCATION({}) {} out float3 WorldPos;\n", counter++,
- GetInterpolationQualifier(msaa, ssaa));
- }
}
-
- out.Write("void main()\n{{\n");
- }
- else // D3D
- {
- out.Write("VS_OUTPUT main(\n");
-
- // inputs
- out.Write(" float3 rawnormal : NORMAL,\n"
- " float3 rawtangent : TANGENT,\n"
- " float3 rawbinormal : BINORMAL,\n"
- " float4 rawcolor0 : COLOR0,\n"
- " float4 rawcolor1 : COLOR1,\n");
- for (int i = 0; i < 8; ++i)
- out.Write(" float3 rawtex{} : TEXCOORD{},\n", i, i);
- out.Write(" uint posmtx : BLENDINDICES,\n");
- out.Write(" float4 rawpos : POSITION) {{\n");
}
+ out.Write("void main()\n{{\n");
+
out.Write("VS_OUTPUT o;\n"
"\n");
@@ -335,45 +315,38 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
"}}\n");
}
- if (api_type == APIType::OpenGL || api_type == APIType::Vulkan)
+ if (host_config.backend_geometry_shaders)
{
- if (host_config.backend_geometry_shaders)
- {
- AssignVSOutputMembers(out, "vs", "o", num_texgen, host_config);
- }
- else
- {
- // 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 < num_texgen; ++i)
- out.Write("tex{}.xyz = o.tex{};\n", i, i);
- if (!host_config.fast_depth_calc)
- out.Write("clipPos = o.clipPos;\n");
- if (per_pixel_lighting)
- {
- out.Write("Normal = o.Normal;\n"
- "WorldPos = o.WorldPos;\n");
- }
- out.Write("colors_0 = o.colors_0;\n"
- "colors_1 = o.colors_1;\n");
- }
-
- if (host_config.backend_depth_clamp)
+ AssignVSOutputMembers(out, "vs", "o", num_texgen, host_config);
+ }
+ else
+ {
+ // 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 < num_texgen; ++i)
+ out.Write("tex{}.xyz = o.tex{};\n", i, i);
+ if (!host_config.fast_depth_calc)
+ out.Write("clipPos = o.clipPos;\n");
+ if (per_pixel_lighting)
{
- out.Write("gl_ClipDistance[0] = clipDist0;\n"
- "gl_ClipDistance[1] = clipDist1;\n");
+ out.Write("Normal = o.Normal;\n"
+ "WorldPos = o.WorldPos;\n");
}
-
- // Vulkan NDC space has Y pointing down (right-handed NDC space).
- if (api_type == APIType::Vulkan)
- out.Write("gl_Position = float4(o.pos.x, -o.pos.y, o.pos.z, o.pos.w);\n");
- else
- out.Write("gl_Position = o.pos;\n");
+ out.Write("colors_0 = o.colors_0;\n"
+ "colors_1 = o.colors_1;\n");
}
- else // D3D
+
+ if (host_config.backend_depth_clamp)
{
- out.Write("return o;\n");
+ out.Write("gl_ClipDistance[0] = clipDist0;\n"
+ "gl_ClipDistance[1] = clipDist1;\n");
}
+
+ // Vulkan NDC space has Y pointing down (right-handed NDC space).
+ if (api_type == APIType::Vulkan)
+ out.Write("gl_Position = float4(o.pos.x, -o.pos.y, o.pos.z, o.pos.w);\n");
+ else
+ out.Write("gl_Position = o.pos;\n");
out.Write("}}\n");
return out;
@@ -393,8 +366,7 @@ static void GenVertexShaderTexGens(APIType api_type, u32 num_texgen, ShaderCode&
}
else
{
- out.Write("{}for (uint texgen = 0u; texgen < {}u; texgen++) {{\n",
- api_type == APIType::D3D ? "[loop] " : "", num_texgen);
+ out.Write("for (uint texgen = 0u; texgen < {}u; texgen++) {{\n", num_texgen);
}
out.Write(" // Texcoord transforms\n");