summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorRyan Houdek <Sonicadvance1@gmail.com>2015-09-06 13:31:49 -0500
committerRyan Houdek <Sonicadvance1@gmail.com>2015-09-06 13:31:49 -0500
commitd2ac382a146bfa64b0ce65a503c3651d0302a387 (patch)
tree15bf8911646a19fa68eebfafd11574869e6a75e0 /Source/Core/VideoCommon
parentc08a83a5aae41e7c8904295cfa62f932ea87ce02 (diff)
parent1c0366993a582e76333ed18421e92424261901f2 (diff)
Merge pull request #2986 from degasus/master
VideoBackends: Reimplement SSAA, now for D3D + OGL
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/GeometryShaderGen.cpp4
-rw-r--r--Source/Core/VideoCommon/PixelShaderGen.cpp36
-rw-r--r--Source/Core/VideoCommon/PixelShaderGen.h6
-rw-r--r--Source/Core/VideoCommon/ShaderGenCommon.h23
-rw-r--r--Source/Core/VideoCommon/VertexShaderGen.cpp14
5 files changed, 51 insertions, 32 deletions
diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp
index 5ec98b3813..f36aa94a9a 100644
--- a/Source/Core/VideoCommon/GeometryShaderGen.cpp
+++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp
@@ -94,11 +94,11 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
out.Write("#define InstanceID gl_InvocationID\n");
out.Write("in VertexData {\n");
- GenerateVSOutputMembers<T>(out, ApiType, g_ActiveConfig.backend_info.bSupportsBindingLayout ? "centroid" : "centroid in");
+ GenerateVSOutputMembers<T>(out, ApiType, GetInterpolationQualifier(ApiType, true, true));
out.Write("} vs[%d];\n", vertex_in);
out.Write("out VertexData {\n");
- GenerateVSOutputMembers<T>(out, ApiType, g_ActiveConfig.backend_info.bSupportsBindingLayout ? "centroid" : "centroid out");
+ GenerateVSOutputMembers<T>(out, ApiType, GetInterpolationQualifier(ApiType, false, true));
if (g_ActiveConfig.iStereoMode > 0)
out.Write("\tflat int layer;\n");
diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp
index 10947fe4a8..2a65a32836 100644
--- a/Source/Core/VideoCommon/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/PixelShaderGen.cpp
@@ -333,6 +333,8 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
warn_once = false;
}
+ uid_data->msaa = g_ActiveConfig.iMultisampleMode > 0;
+ uid_data->ssaa = g_ActiveConfig.iMultisampleMode > 0 && g_ActiveConfig.bSSAA;
if (ApiType == API_OPENGL)
{
out.Write("out vec4 ocol0;\n");
@@ -342,19 +344,11 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
if (per_pixel_depth)
out.Write("#define depth gl_FragDepth\n");
- // 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.
- // So there may be rendered pixels where the center of the pixel isn't in the primitive.
- // As the pixel shader usually renders at the center of the pixel, this position may be
- // outside the primitive. This will lead to sampling outside the texture, sign changes, ...
- // 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.
uid_data->stereo = g_ActiveConfig.iStereoMode > 0;
if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
{
out.Write("in VertexData {\n");
- GenerateVSOutputMembers<T>(out, ApiType, g_ActiveConfig.backend_info.bSupportsBindingLayout ? "centroid" : "centroid in");
+ GenerateVSOutputMembers<T>(out, ApiType, GetInterpolationQualifier(ApiType, true, true));
if (g_ActiveConfig.iStereoMode > 0)
out.Write("\tflat int layer;\n");
@@ -363,19 +357,19 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
}
else
{
- out.Write("centroid in float4 colors_0;\n");
- out.Write("centroid in float4 colors_1;\n");
+ out.Write("%s in float4 colors_0;\n", GetInterpolationQualifier(ApiType));
+ out.Write("%s in float4 colors_1;\n", GetInterpolationQualifier(ApiType));
// compute window position if needed because binding semantic WPOS is not widely supported
// Let's set up attributes
for (unsigned int i = 0; i < numTexgen; ++i)
{
- out.Write("centroid in float3 uv%d;\n", i);
+ out.Write("%s in float3 uv%d;\n", GetInterpolationQualifier(ApiType), i);
}
- out.Write("centroid in float4 clipPos;\n");
+ out.Write("%s in float4 clipPos;\n", GetInterpolationQualifier(ApiType));
if (g_ActiveConfig.bEnablePixelLighting)
{
- out.Write("centroid in float3 Normal;\n");
- out.Write("centroid in float3 WorldPos;\n");
+ out.Write("%s in float3 Normal;\n", GetInterpolationQualifier(ApiType));
+ out.Write("%s in float3 WorldPos;\n", GetInterpolationQualifier(ApiType));
}
}
@@ -396,17 +390,17 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : SV_Target1," : "",
per_pixel_depth ? "\n out float depth : SV_Depth," : "");
- out.Write(" in centroid float4 colors_0 : COLOR0,\n");
- out.Write(" in centroid float4 colors_1 : COLOR1\n");
+ out.Write(" in %s float4 colors_0 : COLOR0,\n", GetInterpolationQualifier(ApiType));
+ out.Write(" in %s float4 colors_1 : COLOR1\n", GetInterpolationQualifier(ApiType));
// compute window position if needed because binding semantic WPOS is not widely supported
for (unsigned int i = 0; i < numTexgen; ++i)
- out.Write(",\n in centroid float3 uv%d : TEXCOORD%d", i, i);
- out.Write(",\n in centroid float4 clipPos : TEXCOORD%d", numTexgen);
+ out.Write(",\n in %s float3 uv%d : TEXCOORD%d", GetInterpolationQualifier(ApiType), i, i);
+ out.Write(",\n in %s float4 clipPos : TEXCOORD%d", GetInterpolationQualifier(ApiType), numTexgen);
if (g_ActiveConfig.bEnablePixelLighting)
{
- out.Write(",\n in centroid float3 Normal : TEXCOORD%d", numTexgen + 1);
- out.Write(",\n in centroid float3 WorldPos : TEXCOORD%d", numTexgen + 2);
+ out.Write(",\n in %s float3 Normal : TEXCOORD%d", GetInterpolationQualifier(ApiType), numTexgen + 1);
+ out.Write(",\n in %s float3 WorldPos : TEXCOORD%d", GetInterpolationQualifier(ApiType), numTexgen + 2);
}
uid_data->stereo = g_ActiveConfig.iStereoMode > 0;
if (g_ActiveConfig.iStereoMode > 0)
diff --git a/Source/Core/VideoCommon/PixelShaderGen.h b/Source/Core/VideoCommon/PixelShaderGen.h
index 90241e867d..518207f7bc 100644
--- a/Source/Core/VideoCommon/PixelShaderGen.h
+++ b/Source/Core/VideoCommon/PixelShaderGen.h
@@ -48,9 +48,11 @@ struct pixel_shader_uid_data
u32 early_ztest : 1;
u32 bounding_box : 1;
- // TODO: 31 bits of padding is a waste. Can we free up some bits elseware?
+ // TODO: 29 bits of padding is a waste. Can we free up some bits elseware?
u32 zfreeze : 1;
- u32 pad : 31;
+ u32 msaa : 1;
+ u32 ssaa : 1;
+ u32 pad : 29;
u32 texMtxInfo_n_projection : 8; // 8x1 bit
u32 tevindref_bi0 : 3;
diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h
index 218d9b98b5..2fd6c51819 100644
--- a/Source/Core/VideoCommon/ShaderGenCommon.h
+++ b/Source/Core/VideoCommon/ShaderGenCommon.h
@@ -279,6 +279,29 @@ static inline void AssignVSOutputMembers(T& object, const char* a, const char* b
}
}
+// 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.
+// So there may be rendered pixels where the center of the pixel isn't in the primitive.
+// As the pixel shader usually renders at the center of the pixel, this position may be
+// outside the primitive. This will lead to sampling outside the texture, sign changes, ...
+// 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.
+static inline const char* GetInterpolationQualifier(API_TYPE api_type, bool in = true, bool in_out = false)
+{
+ if (!g_ActiveConfig.iMultisampleMode)
+ return "";
+
+ if (!g_ActiveConfig.bSSAA)
+ {
+ if (in_out && api_type == API_OPENGL && !g_ActiveConfig.backend_info.bSupportsBindingLayout)
+ return in ? "centroid in" : "centroid out";
+ return "centroid";
+ }
+
+ return "sample";
+}
+
// Constant variable names
#define I_COLORS "color"
#define I_KCOLORS "k"
diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp
index 6fe58bd422..63f80488e4 100644
--- a/Source/Core/VideoCommon/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/VertexShaderGen.cpp
@@ -77,7 +77,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
if (g_ActiveConfig.backend_info.bSupportsGeometryShaders)
{
out.Write("out VertexData {\n");
- GenerateVSOutputMembers<T>(out, api_type, g_ActiveConfig.backend_info.bSupportsBindingLayout ? "centroid" : "centroid out");
+ GenerateVSOutputMembers<T>(out, api_type, GetInterpolationQualifier(api_type, false, true));
out.Write("} vs;\n");
}
else
@@ -87,17 +87,17 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
{
if (i < xfmem.numTexGen.numTexGens)
{
- out.Write("centroid out float3 uv%d;\n", i);
+ out.Write("%s out float3 uv%d;\n", GetInterpolationQualifier(api_type), i);
}
}
- out.Write("centroid out float4 clipPos;\n");
+ out.Write("%s out float4 clipPos;\n", GetInterpolationQualifier(api_type));
if (g_ActiveConfig.bEnablePixelLighting)
{
- out.Write("centroid out float3 Normal;\n");
- out.Write("centroid out float3 WorldPos;\n");
+ out.Write("%s out float3 Normal;\n", GetInterpolationQualifier(api_type));
+ out.Write("%s out float3 WorldPos;\n", GetInterpolationQualifier(api_type));
}
- out.Write("centroid out float4 colors_0;\n");
- out.Write("centroid out float4 colors_1;\n");
+ out.Write("%s out float4 colors_0;\n", GetInterpolationQualifier(api_type));
+ out.Write("%s out float4 colors_1;\n", GetInterpolationQualifier(api_type));
}
out.Write("void main()\n{\n");