diff options
| author | JMC47 <JMC4789@gmail.com> | 2022-07-08 15:29:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-08 15:29:58 -0400 |
| commit | 828afc67356c2299c6056d618eb6b7afe4c843b9 (patch) | |
| tree | cb7809cf9aad689968ec209e8d886b5457ca68dc /Source/Core/VideoCommon/VertexShaderGen.cpp | |
| parent | 7cc89f5642cab3b91aef1c8255af857a1607ddf6 (diff) | |
| parent | a8b52663479effc0f404f7c0f8b52bc0ee37b742 (diff) | |
Merge pull request #10673 from iwubcode/spirv-backends
D3D: Generate HLSL from SPIRV*
Diffstat (limited to 'Source/Core/VideoCommon/VertexShaderGen.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VertexShaderGen.cpp | 195 |
1 files changed, 79 insertions, 116 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 9fa2d6cd0e..2eb5a53a97 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -86,111 +86,81 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho 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, uid_data->numTexGens, host_config, ""); + GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, host_config, "", + ShaderStage::Vertex); out.Write("}};\n\n"); WriteIsNanHeader(out, api_type); - if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) + out.Write("ATTRIBUTE_LOCATION({}) in float4 rawpos;\n", SHADER_POSITION_ATTRIB); + if ((uid_data->components & VB_HAS_POSMTXIDX) != 0) + out.Write("ATTRIBUTE_LOCATION({}) in uint4 posmtx;\n", SHADER_POSMTX_ATTRIB); + if ((uid_data->components & VB_HAS_NORMAL) != 0) + out.Write("ATTRIBUTE_LOCATION({}) in float3 rawnormal;\n", SHADER_NORMAL_ATTRIB); + if ((uid_data->components & VB_HAS_TANGENT) != 0) + out.Write("ATTRIBUTE_LOCATION({}) in float3 rawtangent;\n", SHADER_TANGENT_ATTRIB); + if ((uid_data->components & VB_HAS_BINORMAL) != 0) + out.Write("ATTRIBUTE_LOCATION({}) in float3 rawbinormal;\n", SHADER_BINORMAL_ATTRIB); + + if ((uid_data->components & VB_HAS_COL0) != 0) + out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor0;\n", SHADER_COLOR0_ATTRIB); + if ((uid_data->components & VB_HAS_COL1) != 0) + out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor1;\n", SHADER_COLOR1_ATTRIB); + + for (u32 i = 0; i < 8; ++i) { - out.Write("ATTRIBUTE_LOCATION({}) in float4 rawpos;\n", SHADER_POSITION_ATTRIB); - if ((uid_data->components & VB_HAS_POSMTXIDX) != 0) - out.Write("ATTRIBUTE_LOCATION({}) in uint4 posmtx;\n", SHADER_POSMTX_ATTRIB); - if ((uid_data->components & VB_HAS_NORMAL) != 0) - out.Write("ATTRIBUTE_LOCATION({}) in float3 rawnormal;\n", SHADER_NORMAL_ATTRIB); - if ((uid_data->components & VB_HAS_TANGENT) != 0) - out.Write("ATTRIBUTE_LOCATION({}) in float3 rawtangent;\n", SHADER_TANGENT_ATTRIB); - if ((uid_data->components & VB_HAS_BINORMAL) != 0) - out.Write("ATTRIBUTE_LOCATION({}) in float3 rawbinormal;\n", SHADER_BINORMAL_ATTRIB); - - if ((uid_data->components & VB_HAS_COL0) != 0) - out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor0;\n", SHADER_COLOR0_ATTRIB); - if ((uid_data->components & VB_HAS_COL1) != 0) - out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor1;\n", SHADER_COLOR1_ATTRIB); - - for (u32 i = 0; i < 8; ++i) - { - const u32 has_texmtx = (uid_data->components & (VB_HAS_TEXMTXIDX0 << i)); + const u32 has_texmtx = (uid_data->components & (VB_HAS_TEXMTXIDX0 << i)); - if ((uid_data->components & (VB_HAS_UV0 << i)) != 0 || has_texmtx != 0) - { - out.Write("ATTRIBUTE_LOCATION({}) in float{} rawtex{};\n", SHADER_TEXTURE0_ATTRIB + i, - has_texmtx != 0 ? 3 : 2, i); - } + if ((uid_data->components & (VB_HAS_UV0 << i)) != 0 || has_texmtx != 0) + { + out.Write("ATTRIBUTE_LOCATION({}) in float{} rawtex{};\n", SHADER_TEXTURE0_ATTRIB + i, + has_texmtx != 0 ? 3 : 2, i); } + } - if (host_config.backend_geometry_shaders) + if (host_config.backend_geometry_shaders) + { + out.Write("VARYING_LOCATION(0) out VertexData {{\n"); + GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, 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 < uid_data->numTexGens; ++i) { - out.Write("VARYING_LOCATION(0) out VertexData {{\n"); - GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, host_config, - GetInterpolationQualifier(msaa, ssaa, true, false)); - out.Write("}} vs;\n"); + out.Write("VARYING_LOCATION({}) {} out float3 tex{};\n", counter++, + GetInterpolationQualifier(msaa, ssaa), i); } - else + if (!host_config.fast_depth_calc) { - // 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++, + out.Write("VARYING_LOCATION({}) {} out float4 clipPos;\n", counter++, GetInterpolationQualifier(msaa, ssaa)); - for (u32 i = 0; i < uid_data->numTexGens; ++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 - if ((uid_data->components & VB_HAS_NORMAL) != 0) - out.Write(" float3 rawnormal : NORMAL,\n"); - if ((uid_data->components & VB_HAS_TANGENT) != 0) - out.Write(" float3 rawtangent : TANGENT,\n"); - if ((uid_data->components & VB_HAS_BINORMAL) != 0) - out.Write(" float3 rawbinormal : BINORMAL,\n"); - if ((uid_data->components & VB_HAS_COL0) != 0) - out.Write(" float4 rawcolor0 : COLOR0,\n"); - if ((uid_data->components & VB_HAS_COL1) != 0) - out.Write(" float4 rawcolor1 : COLOR1,\n"); - for (u32 i = 0; i < 8; ++i) + if (per_pixel_lighting) { - const u32 has_texmtx = (uid_data->components & (VB_HAS_TEXMTXIDX0 << i)); - - if ((uid_data->components & (VB_HAS_UV0 << i)) != 0 || has_texmtx != 0) - out.Write(" float{} rawtex{} : TEXCOORD{},\n", has_texmtx ? 3 : 2, i, i); + out.Write("VARYING_LOCATION({}) {} out float3 Normal;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION({}) {} out float3 WorldPos;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); } - if ((uid_data->components & VB_HAS_POSMTXIDX) != 0) - out.Write(" uint4 posmtx : BLENDINDICES,\n"); - out.Write(" float4 rawpos : POSITION) {{\n"); } + out.Write("void main()\n{{\n"); + out.Write("VS_OUTPUT o;\n"); // xfmem.numColorChans controls the number of color channels available to TEV, but we still need @@ -548,45 +518,38 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho "}}\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", uid_data->numTexGens, 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 < uid_data->numTexGens; ++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", uid_data->numTexGens, 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 < uid_data->numTexGens; ++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; |
