From 82c27182a8a15903a0082890e6b188435ec957b4 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 24 Jun 2017 18:18:53 +1000 Subject: ShaderGen: Remove host state from shader uids --- Source/Core/VideoCommon/VertexShaderGen.cpp | 46 +++++++++++++---------------- 1 file changed, 20 insertions(+), 26 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderGen.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 9fe4bfcada..a69245bda7 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -26,11 +26,6 @@ VertexShaderUid GetVertexShaderUid() uid_data->numTexGens = xfmem.numTexGen.numTexGens; uid_data->components = VertexLoaderManager::g_current_components; - uid_data->pixel_lighting = g_ActiveConfig.bEnablePixelLighting; - uid_data->vertex_rounding = - g_ActiveConfig.bVertexRounding && g_ActiveConfig.iEFBScale != SCALE_1X; - uid_data->msaa = g_ActiveConfig.iMultisamples > 1; - uid_data->ssaa = g_ActiveConfig.iMultisamples > 1 && g_ActiveConfig.bSSAA; uid_data->numColorChans = xfmem.numChan.numColorChans; GetLightingShaderUid(uid_data->lighting); @@ -84,6 +79,12 @@ VertexShaderUid GetVertexShaderUid() ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_data* uid_data) { ShaderCode out; + + const bool per_pixel_lighting = g_ActiveConfig.bEnablePixelLighting; + const bool msaa = g_ActiveConfig.IsMSAAEnabled(); + const bool ssaa = g_ActiveConfig.IsSSAAEnabled(); + const bool vertex_rounding = g_ActiveConfig.UseVertexRounding(); + out.Write("%s", s_lighting_struct); // uniforms @@ -96,7 +97,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da out.Write("};\n"); out.Write("struct VS_OUTPUT {\n"); - GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, uid_data->pixel_lighting, ""); + GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, per_pixel_lighting, ""); out.Write("};\n"); if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) @@ -130,9 +131,8 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da if (g_ActiveConfig.backend_info.bSupportsGeometryShaders || api_type == APIType::Vulkan) { out.Write("VARYING_LOCATION(0) out VertexData {\n"); - GenerateVSOutputMembers( - out, api_type, uid_data->numTexGens, uid_data->pixel_lighting, - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa, true, false)); + GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, per_pixel_lighting, + GetInterpolationQualifier(msaa, ssaa, true, false)); out.Write("} vs;\n"); } else @@ -142,23 +142,17 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da { if (i < uid_data->numTexGens) { - out.Write("%s out float3 uv%u;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa), i); + out.Write("%s out float3 uv%u;\n", GetInterpolationQualifier(msaa, ssaa), i); } } - out.Write("%s out float4 clipPos;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); - if (uid_data->pixel_lighting) + out.Write("%s out float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa)); + if (per_pixel_lighting) { - out.Write("%s out float3 Normal;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); - out.Write("%s out float3 WorldPos;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); + out.Write("%s out float3 Normal;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("%s out float3 WorldPos;\n", GetInterpolationQualifier(msaa, ssaa)); } - out.Write("%s out float4 colors_0;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); - out.Write("%s out float4 colors_1;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); + out.Write("%s out float4 colors_0;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("%s out float4 colors_1;\n", GetInterpolationQualifier(msaa, ssaa)); } out.Write("void main()\n{\n"); @@ -406,7 +400,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da // clipPos/w needs to be done in pixel shader, not here out.Write("o.clipPos = o.pos;\n"); - if (uid_data->pixel_lighting) + if (per_pixel_lighting) { out.Write("o.Normal = _norm0;\n"); out.Write("o.WorldPos = pos.xyz;\n"); @@ -466,7 +460,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da // get rasterized correctly. out.Write("o.pos.xy = o.pos.xy - o.pos.w * " I_PIXELCENTERCORRECTION ".xy;\n"); - if (uid_data->vertex_rounding) + if (vertex_rounding) { // By now our position is in clip space // however, higher resolutions than the Wii outputs @@ -493,7 +487,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da { if (g_ActiveConfig.backend_info.bSupportsGeometryShaders || api_type == APIType::Vulkan) { - AssignVSOutputMembers(out, "vs", "o", uid_data->numTexGens, uid_data->pixel_lighting); + AssignVSOutputMembers(out, "vs", "o", uid_data->numTexGens, per_pixel_lighting); } else { @@ -502,7 +496,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da for (unsigned int i = 0; i < uid_data->numTexGens; ++i) out.Write("uv%d.xyz = o.tex%d;\n", i, i); out.Write("clipPos = o.clipPos;\n"); - if (uid_data->pixel_lighting) + if (per_pixel_lighting) { out.Write("Normal = o.Normal;\n"); out.Write("WorldPos = o.WorldPos;\n"); -- cgit v1.2.3 From 3ea9d86faa2544b8c1c235db9456f271baf42fec Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 20 Jul 2017 17:10:02 +1000 Subject: ShaderGen: Pass host config to shader generation functions Also moves the host config checks to common. --- Source/Core/VideoCommon/VertexShaderGen.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderGen.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index a69245bda7..2ee9532254 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -76,14 +76,15 @@ VertexShaderUid GetVertexShaderUid() return out; } -ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_data* uid_data) +ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& host_config, + const vertex_shader_uid_data* uid_data) { ShaderCode out; const bool per_pixel_lighting = g_ActiveConfig.bEnablePixelLighting; - const bool msaa = g_ActiveConfig.IsMSAAEnabled(); - const bool ssaa = g_ActiveConfig.IsSSAAEnabled(); - const bool vertex_rounding = g_ActiveConfig.UseVertexRounding(); + const bool msaa = host_config.msaa; + const bool ssaa = host_config.ssaa; + const bool vertex_rounding = host_config.vertex_rounding; out.Write("%s", s_lighting_struct); @@ -128,7 +129,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da } // We need to always use output blocks for Vulkan, but geometry shaders are also optional. - if (g_ActiveConfig.backend_info.bSupportsGeometryShaders || api_type == APIType::Vulkan) + if (host_config.backend_geometry_shaders || api_type == APIType::Vulkan) { out.Write("VARYING_LOCATION(0) out VertexData {\n"); GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, per_pixel_lighting, @@ -415,7 +416,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da // If we can disable the incorrect depth clipping planes using depth clamping, then we can do // our own depth clipping and calculate the depth range before the perspective divide if // necessary. - if (g_ActiveConfig.backend_info.bSupportsDepthClamp) + if (host_config.backend_depth_clamp) { // Since we're adjusting z for the depth range before the perspective divide, we have to do our // own clipping. We want to clip so that -w <= z <= 0, which matches the console -1..0 range. @@ -440,7 +441,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION ".w - " "o.pos.z * " I_PIXELCENTERCORRECTION ".z;\n"); - if (!g_ActiveConfig.backend_info.bSupportsClipControl) + if (!host_config.backend_clip_control) { // If the graphics API doesn't support a depth range of 0..1, then we need to map z to // the -1..1 range. Unfortunately we have to use a substraction, which is a lossy floating-point @@ -485,7 +486,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) { - if (g_ActiveConfig.backend_info.bSupportsGeometryShaders || api_type == APIType::Vulkan) + if (host_config.backend_geometry_shaders || api_type == APIType::Vulkan) { AssignVSOutputMembers(out, "vs", "o", uid_data->numTexGens, per_pixel_lighting); } @@ -505,7 +506,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da out.Write("colors_1 = o.colors_1;\n"); } - if (g_ActiveConfig.backend_info.bSupportsDepthClamp) + if (host_config.backend_depth_clamp) { out.Write("gl_ClipDistance[0] = o.clipDist0;\n"); out.Write("gl_ClipDistance[1] = o.clipDist1;\n"); -- cgit v1.2.3