diff --git a/Source/Core/VideoBackends/D3D/DXPipeline.cpp b/Source/Core/VideoBackends/D3D/DXPipeline.cpp index c8d3622aaa..67450b11da 100644 --- a/Source/Core/VideoBackends/D3D/DXPipeline.cpp +++ b/Source/Core/VideoBackends/D3D/DXPipeline.cpp @@ -2,9 +2,6 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include -#include - #include "Common/Assert.h" #include "Common/Logging/Log.h" @@ -15,6 +12,7 @@ #include "VideoBackends/D3D/DXTexture.h" #include "VideoBackends/D3D/Render.h" #include "VideoBackends/D3D/VertexManager.h" +#include "VideoCommon/VideoConfig.h" namespace DX11 { diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 52523e59c5..a738a98fa2 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -33,6 +33,7 @@ #include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexShaderManager.h" #include "VideoCommon/VideoBackendBase.h" +#include "VideoCommon/VideoConfig.h" namespace OGL { diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index ee813fbbda..85f5d75610 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -10,10 +10,7 @@ #include #include #include -#include -#include -#include "Common/Assert.h" #include "Common/Atomic.h" #include "Common/CommonTypes.h" #include "Common/GL/GLContext.h" @@ -24,7 +21,6 @@ #include "Common/StringUtil.h" #include "Core/Config/GraphicsSettings.h" -#include "Core/Core.h" #include "VideoBackends/OGL/BoundingBox.h" #include "VideoBackends/OGL/OGLPipeline.h" @@ -32,22 +28,16 @@ #include "VideoBackends/OGL/OGLTexture.h" #include "VideoBackends/OGL/ProgramShaderCache.h" #include "VideoBackends/OGL/SamplerCache.h" -#include "VideoBackends/OGL/StreamBuffer.h" #include "VideoBackends/OGL/VertexManager.h" #include "VideoCommon/BPFunctions.h" #include "VideoCommon/DriverDetails.h" #include "VideoCommon/FramebufferManager.h" -#include "VideoCommon/IndexGenerator.h" #include "VideoCommon/OnScreenDisplay.h" -#include "VideoCommon/PixelEngine.h" #include "VideoCommon/PostProcessing.h" #include "VideoCommon/RenderState.h" -#include "VideoCommon/ShaderGenCommon.h" -#include "VideoCommon/VertexShaderManager.h" -#include "VideoCommon/VideoBackendBase.h" +#include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" -#include "VideoCommon/XFMemory.h" namespace OGL { diff --git a/Source/Core/VideoBackends/OGL/main.cpp b/Source/Core/VideoBackends/OGL/main.cpp index d9d27c2b84..bfd2b25d6f 100644 --- a/Source/Core/VideoBackends/OGL/main.cpp +++ b/Source/Core/VideoBackends/OGL/main.cpp @@ -55,6 +55,7 @@ Make AA apply instantly during gameplay if possible #include "VideoCommon/FramebufferManager.h" #include "VideoCommon/TextureCacheBase.h" +#include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" namespace OGL diff --git a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp index 1db168e9e9..85609ec48e 100644 --- a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp +++ b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp @@ -21,7 +21,7 @@ #include "VideoBackends/Vulkan/VKTexture.h" #include "VideoBackends/Vulkan/VertexFormat.h" #include "VideoBackends/Vulkan/VulkanContext.h" -#include "VideoCommon/Statistics.h" +#include "VideoCommon/VideoCommon.h" namespace Vulkan { diff --git a/Source/Core/VideoCommon/FramebufferManager.cpp b/Source/Core/VideoCommon/FramebufferManager.cpp index 0aeb691362..344a6e2b64 100644 --- a/Source/Core/VideoCommon/FramebufferManager.cpp +++ b/Source/Core/VideoCommon/FramebufferManager.cpp @@ -3,9 +3,8 @@ // Refer to the license.txt file included. #include "VideoCommon/FramebufferManager.h" + #include -#include "VideoCommon/FramebufferShaderGen.h" -#include "VideoCommon/VertexManagerBase.h" #include "Common/ChunkFile.h" #include "Common/Logging/Log.h" @@ -17,7 +16,10 @@ #include "VideoCommon/AbstractStagingTexture.h" #include "VideoCommon/AbstractTexture.h" #include "VideoCommon/DriverDetails.h" +#include "VideoCommon/FramebufferShaderGen.h" #include "VideoCommon/RenderBase.h" +#include "VideoCommon/VertexManagerBase.h" +#include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" // Maximum number of pixels poked in one batch * 6 diff --git a/Source/Core/VideoCommon/FramebufferShaderGen.cpp b/Source/Core/VideoCommon/FramebufferShaderGen.cpp index 58d37dc8c9..49c2ba3b16 100644 --- a/Source/Core/VideoCommon/FramebufferShaderGen.cpp +++ b/Source/Core/VideoCommon/FramebufferShaderGen.cpp @@ -12,6 +12,8 @@ #include "VideoCommon/FramebufferManager.h" #include "VideoCommon/TextureDecoder.h" #include "VideoCommon/VertexShaderGen.h" +#include "VideoCommon/VideoCommon.h" +#include "VideoCommon/VideoConfig.h" namespace FramebufferShaderGen { diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp index 90446ca40d..fe7927dc4f 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.cpp +++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp @@ -91,7 +91,7 @@ ShaderCode GenerateGeometryShaderCode(APIType ApiType, const ShaderHostConfig& h "};\n"); out.Write("struct VS_OUTPUT {\n"); - GenerateVSOutputMembers(out, ApiType, uid_data->numTexGens, host_config, ""); + GenerateVSOutputMembers(out, ApiType, uid_data->numTexGens, host_config, ""); out.Write("};\n"); if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan) @@ -100,13 +100,13 @@ ShaderCode GenerateGeometryShaderCode(APIType ApiType, const ShaderHostConfig& h out.Write("#define InstanceID gl_InvocationID\n"); out.Write("VARYING_LOCATION(0) in VertexData {\n"); - GenerateVSOutputMembers(out, ApiType, uid_data->numTexGens, host_config, - GetInterpolationQualifier(msaa, ssaa, true, true)); + GenerateVSOutputMembers(out, ApiType, uid_data->numTexGens, host_config, + GetInterpolationQualifier(msaa, ssaa, true, true)); out.Write("} vs[%d];\n", vertex_in); out.Write("VARYING_LOCATION(0) out VertexData {\n"); - GenerateVSOutputMembers(out, ApiType, uid_data->numTexGens, host_config, - GetInterpolationQualifier(msaa, ssaa, true, false)); + GenerateVSOutputMembers(out, ApiType, uid_data->numTexGens, host_config, + GetInterpolationQualifier(msaa, ssaa, true, false)); if (stereo) out.Write("\tflat int layer;\n"); diff --git a/Source/Core/VideoCommon/PostProcessing.cpp b/Source/Core/VideoCommon/PostProcessing.cpp index 03f913eaaa..44667a4096 100644 --- a/Source/Core/VideoCommon/PostProcessing.cpp +++ b/Source/Core/VideoCommon/PostProcessing.cpp @@ -28,6 +28,7 @@ #include "VideoCommon/RenderBase.h" #include "VideoCommon/ShaderCache.h" #include "VideoCommon/VertexManagerBase.h" +#include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" namespace VideoCommon diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index 53866a3bfa..e148918ddb 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -15,14 +15,19 @@ #include "VideoCommon/Statistics.h" #include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexManagerBase.h" +#include "VideoCommon/VideoCommon.h" +#include "VideoCommon/VideoConfig.h" -#include "imgui.h" +#include std::unique_ptr g_shader_cache; namespace VideoCommon { -ShaderCache::ShaderCache() = default; +ShaderCache::ShaderCache() : m_api_type{APIType::Nothing} +{ +} + ShaderCache::~ShaderCache() { ClearCaches(); diff --git a/Source/Core/VideoCommon/ShaderCache.h b/Source/Core/VideoCommon/ShaderCache.h index ffea19ee60..d97d1c5014 100644 --- a/Source/Core/VideoCommon/ShaderCache.h +++ b/Source/Core/VideoCommon/ShaderCache.h @@ -34,6 +34,7 @@ class NativeVertexFormat; enum class AbstractTextureFormat : u32; +enum class APIType; enum class TextureFormat; enum class TLUTFormat; @@ -191,7 +192,7 @@ private: }; // Configuration bits. - APIType m_api_type = APIType::Nothing; + APIType m_api_type; ShaderHostConfig m_host_config = {}; std::unique_ptr m_async_shader_compiler; diff --git a/Source/Core/VideoCommon/ShaderGenCommon.cpp b/Source/Core/VideoCommon/ShaderGenCommon.cpp index 28bacc9942..75d77db687 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.cpp +++ b/Source/Core/VideoCommon/ShaderGenCommon.cpp @@ -8,6 +8,8 @@ #include "Common/FileUtil.h" #include "Core/ConfigManager.h" +#include "VideoCommon/VideoCommon.h" +#include "VideoCommon/VideoConfig.h" ShaderHostConfig ShaderHostConfig::GetCurrent() { @@ -84,3 +86,100 @@ std::string GetDiskShaderCacheFileName(APIType api_type, const char* type, bool filename += ".cache"; return filename; } + +static void DefineOutputMember(ShaderCode& object, APIType api_type, std::string_view qualifier, + std::string_view type, std::string_view name, int var_index, + std::string_view semantic = {}, int semantic_index = -1) +{ + object.WriteFmt("\t{} {} {}", qualifier, type, name); + + if (var_index != -1) + object.WriteFmt("{}", var_index); + + if (api_type == APIType::D3D && !semantic.empty()) + { + if (semantic_index != -1) + object.WriteFmt(" : {}{}", semantic, semantic_index); + else + object.WriteFmt(" : {}", semantic); + } + + object.WriteFmt(";\n"); +} + +void GenerateVSOutputMembers(ShaderCode& object, APIType api_type, u32 texgens, + const ShaderHostConfig& host_config, std::string_view qualifier) +{ + DefineOutputMember(object, api_type, qualifier, "float4", "pos", -1, "SV_Position"); + DefineOutputMember(object, api_type, qualifier, "float4", "colors_", 0, "COLOR", 0); + DefineOutputMember(object, api_type, qualifier, "float4", "colors_", 1, "COLOR", 1); + + for (unsigned int i = 0; i < texgens; ++i) + DefineOutputMember(object, api_type, qualifier, "float3", "tex", i, "TEXCOORD", i); + + if (!host_config.fast_depth_calc) + DefineOutputMember(object, api_type, qualifier, "float4", "clipPos", -1, "TEXCOORD", texgens); + + if (host_config.per_pixel_lighting) + { + DefineOutputMember(object, api_type, qualifier, "float3", "Normal", -1, "TEXCOORD", + texgens + 1); + DefineOutputMember(object, api_type, qualifier, "float3", "WorldPos", -1, "TEXCOORD", + texgens + 2); + } + + if (host_config.backend_geometry_shaders) + { + DefineOutputMember(object, api_type, qualifier, "float", "clipDist", 0, "SV_ClipDistance", 0); + DefineOutputMember(object, api_type, qualifier, "float", "clipDist", 1, "SV_ClipDistance", 1); + } +} + +void AssignVSOutputMembers(ShaderCode& object, std::string_view a, std::string_view b, u32 texgens, + const ShaderHostConfig& host_config) +{ + object.WriteFmt("\t{}.pos = {}.pos;\n", a, b); + object.WriteFmt("\t{}.colors_0 = {}.colors_0;\n", a, b); + object.WriteFmt("\t{}.colors_1 = {}.colors_1;\n", a, b); + + for (unsigned int i = 0; i < texgens; ++i) + object.WriteFmt("\t{}.tex{} = {}.tex{};\n", a, i, b, i); + + if (!host_config.fast_depth_calc) + object.WriteFmt("\t{}.clipPos = {}.clipPos;\n", a, b); + + if (host_config.per_pixel_lighting) + { + object.WriteFmt("\t{}.Normal = {}.Normal;\n", a, b); + object.WriteFmt("\t{}.WorldPos = {}.WorldPos;\n", a, b); + } + + if (host_config.backend_geometry_shaders) + { + object.WriteFmt("\t{}.clipDist0 = {}.clipDist0;\n", a, b); + object.WriteFmt("\t{}.clipDist1 = {}.clipDist1;\n", a, b); + } +} + +const char* GetInterpolationQualifier(bool msaa, bool ssaa, bool in_glsl_interface_block, bool in) +{ + if (!msaa) + return ""; + + // Without GL_ARB_shading_language_420pack support, the interpolation qualifier must be + // "centroid in" and not "centroid", even within an interface block. + if (in_glsl_interface_block && !g_ActiveConfig.backend_info.bSupportsBindingLayout) + { + if (!ssaa) + return in ? "centroid in" : "centroid out"; + else + return in ? "sample in" : "sample out"; + } + else + { + if (!ssaa) + return "centroid"; + else + return "sample"; + } +} diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index 5e7fa49f3d..d816d46fae 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -16,8 +15,8 @@ #include "Common/CommonTypes.h" #include "Common/StringUtil.h" -#include "VideoCommon/VideoCommon.h" -#include "VideoCommon/VideoConfig.h" + +enum class APIType; /** * Common interface for classes that need to go through the shader generation path @@ -193,82 +192,11 @@ union ShaderHostConfig std::string GetDiskShaderCacheFileName(APIType api_type, const char* type, bool include_gameid, bool include_host_config, bool include_api = true); -template -void DefineOutputMember(T& object, APIType api_type, std::string_view qualifier, - std::string_view type, std::string_view name, int var_index, - std::string_view semantic = {}, int semantic_index = -1) -{ - object.WriteFmt("\t{} {} {}", qualifier, type, name); +void GenerateVSOutputMembers(ShaderCode& object, APIType api_type, u32 texgens, + const ShaderHostConfig& host_config, std::string_view qualifier); - if (var_index != -1) - object.WriteFmt("{}", var_index); - - if (api_type == APIType::D3D && !semantic.empty()) - { - if (semantic_index != -1) - object.WriteFmt(" : {}{}", semantic, semantic_index); - else - object.WriteFmt(" : {}", semantic); - } - - object.WriteFmt(";\n"); -} - -template -void GenerateVSOutputMembers(T& object, APIType api_type, u32 texgens, - const ShaderHostConfig& host_config, std::string_view qualifier) -{ - DefineOutputMember(object, api_type, qualifier, "float4", "pos", -1, "SV_Position"); - DefineOutputMember(object, api_type, qualifier, "float4", "colors_", 0, "COLOR", 0); - DefineOutputMember(object, api_type, qualifier, "float4", "colors_", 1, "COLOR", 1); - - for (unsigned int i = 0; i < texgens; ++i) - DefineOutputMember(object, api_type, qualifier, "float3", "tex", i, "TEXCOORD", i); - - if (!host_config.fast_depth_calc) - DefineOutputMember(object, api_type, qualifier, "float4", "clipPos", -1, "TEXCOORD", texgens); - - if (host_config.per_pixel_lighting) - { - DefineOutputMember(object, api_type, qualifier, "float3", "Normal", -1, "TEXCOORD", - texgens + 1); - DefineOutputMember(object, api_type, qualifier, "float3", "WorldPos", -1, "TEXCOORD", - texgens + 2); - } - - if (host_config.backend_geometry_shaders) - { - DefineOutputMember(object, api_type, qualifier, "float", "clipDist", 0, "SV_ClipDistance", 0); - DefineOutputMember(object, api_type, qualifier, "float", "clipDist", 1, "SV_ClipDistance", 1); - } -} - -template -void AssignVSOutputMembers(T& object, std::string_view a, std::string_view b, u32 texgens, - const ShaderHostConfig& host_config) -{ - object.WriteFmt("\t{}.pos = {}.pos;\n", a, b); - object.WriteFmt("\t{}.colors_0 = {}.colors_0;\n", a, b); - object.WriteFmt("\t{}.colors_1 = {}.colors_1;\n", a, b); - - for (unsigned int i = 0; i < texgens; ++i) - object.WriteFmt("\t{}.tex{} = {}.tex{};\n", a, i, b, i); - - if (!host_config.fast_depth_calc) - object.WriteFmt("\t{}.clipPos = {}.clipPos;\n", a, b); - - if (host_config.per_pixel_lighting) - { - object.WriteFmt("\t{}.Normal = {}.Normal;\n", a, b); - object.WriteFmt("\t{}.WorldPos = {}.WorldPos;\n", a, b); - } - - if (host_config.backend_geometry_shaders) - { - object.WriteFmt("\t{}.clipDist0 = {}.clipDist0;\n", a, b); - object.WriteFmt("\t{}.clipDist1 = {}.clipDist1;\n", a, b); - } -} +void AssignVSOutputMembers(ShaderCode& object, std::string_view a, std::string_view b, u32 texgens, + const ShaderHostConfig& host_config); // We use the flag "centroid" to fix some MSAA rendering bugs. With MSAA, the // pixel shader will be executed for each pixel which has at least one passed sample. @@ -278,29 +206,8 @@ void AssignVSOutputMembers(T& object, std::string_view a, std::string_view b, u3 // As a workaround, we interpolate at the centroid of the coveraged pixel, which // is always inside the primitive. // Without MSAA, this flag is defined to have no effect. -inline const char* GetInterpolationQualifier(bool msaa, bool ssaa, - bool in_glsl_interface_block = false, bool in = false) -{ - if (!msaa) - return ""; - - // Without GL_ARB_shading_language_420pack support, the interpolation qualifier must be - // "centroid in" and not "centroid", even within an interface block. - if (in_glsl_interface_block && !g_ActiveConfig.backend_info.bSupportsBindingLayout) - { - if (!ssaa) - return in ? "centroid in" : "centroid out"; - else - return in ? "sample in" : "sample out"; - } - else - { - if (!ssaa) - return "centroid"; - else - return "sample"; - } -} +const char* GetInterpolationQualifier(bool msaa, bool ssaa, bool in_glsl_interface_block = false, + bool in = false); // Constant variable names #define I_COLORS "color" diff --git a/Source/Core/VideoCommon/UberShaderCommon.cpp b/Source/Core/VideoCommon/UberShaderCommon.cpp index b815e13c16..f34beba13f 100644 --- a/Source/Core/VideoCommon/UberShaderCommon.cpp +++ b/Source/Core/VideoCommon/UberShaderCommon.cpp @@ -4,7 +4,8 @@ #include "VideoCommon/UberShaderCommon.h" #include "VideoCommon/NativeVertexFormat.h" -#include "VideoCommon/VideoConfig.h" +#include "VideoCommon/ShaderGenCommon.h" +#include "VideoCommon/VideoCommon.h" #include "VideoCommon/XFMemory.h" namespace UberShader diff --git a/Source/Core/VideoCommon/UberShaderCommon.h b/Source/Core/VideoCommon/UberShaderCommon.h index 32e81ccadf..a94d0ac98b 100644 --- a/Source/Core/VideoCommon/UberShaderCommon.h +++ b/Source/Core/VideoCommon/UberShaderCommon.h @@ -9,8 +9,11 @@ #include -#include "VideoCommon/ShaderGenCommon.h" -#include "VideoCommon/VideoCommon.h" +#include "Common/CommonTypes.h" + +class ShaderCode; +enum class APIType; +union ShaderHostConfig; namespace UberShader { diff --git a/Source/Core/VideoCommon/UberShaderPixel.cpp b/Source/Core/VideoCommon/UberShaderPixel.cpp index 6d2886b256..26c8db3330 100644 --- a/Source/Core/VideoCommon/UberShaderPixel.cpp +++ b/Source/Core/VideoCommon/UberShaderPixel.cpp @@ -3,10 +3,15 @@ // Refer to the license.txt file included. #include "VideoCommon/UberShaderPixel.h" + #include "VideoCommon/BPMemory.h" #include "VideoCommon/DriverDetails.h" #include "VideoCommon/NativeVertexFormat.h" +#include "VideoCommon/PixelShaderGen.h" +#include "VideoCommon/ShaderGenCommon.h" #include "VideoCommon/UberShaderCommon.h" +#include "VideoCommon/VideoCommon.h" +#include "VideoCommon/VideoConfig.h" #include "VideoCommon/XFMemory.h" namespace UberShader diff --git a/Source/Core/VideoCommon/UberShaderPixel.h b/Source/Core/VideoCommon/UberShaderPixel.h index 3575526ed2..95f7745ed2 100644 --- a/Source/Core/VideoCommon/UberShaderPixel.h +++ b/Source/Core/VideoCommon/UberShaderPixel.h @@ -5,7 +5,10 @@ #pragma once #include -#include "VideoCommon/PixelShaderGen.h" +#include "Common/CommonTypes.h" +#include "VideoCommon/ShaderGenCommon.h" + +enum class APIType; namespace UberShader { diff --git a/Source/Core/VideoCommon/UberShaderVertex.cpp b/Source/Core/VideoCommon/UberShaderVertex.cpp index 5fb30aaf03..9b85b4d1c2 100644 --- a/Source/Core/VideoCommon/UberShaderVertex.cpp +++ b/Source/Core/VideoCommon/UberShaderVertex.cpp @@ -3,11 +3,12 @@ // Refer to the license.txt file included. #include "VideoCommon/UberShaderVertex.h" + #include "VideoCommon/DriverDetails.h" #include "VideoCommon/NativeVertexFormat.h" #include "VideoCommon/UberShaderCommon.h" #include "VideoCommon/VertexShaderGen.h" -#include "VideoCommon/VideoConfig.h" +#include "VideoCommon/VideoCommon.h" #include "VideoCommon/XFMemory.h" namespace UberShader diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index f18e3d1d67..5588c1e717 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -34,6 +34,7 @@ #include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexShaderManager.h" #include "VideoCommon/VideoBackendBase.h" +#include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" #include "VideoCommon/XFMemory.h"