summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/GeometryShaderGen.cpp
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2014-12-14 22:27:09 +0100
committerJules Blok <jules.blok@gmail.com>2014-12-15 22:47:41 +0100
commit382e1c22db91d863b55d6223d4893cb629dab810 (patch)
tree858007f14d0c4833ebb9a5ad437a950684335e06 /Source/Core/VideoCommon/GeometryShaderGen.cpp
parent887c669c288a8aeb432e9b6e9cd0c781bd14faf5 (diff)
GeometryShaderGen: Support multiple primitive types.
And make more stereoscopy code optional.
Diffstat (limited to 'Source/Core/VideoCommon/GeometryShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/GeometryShaderGen.cpp79
1 files changed, 52 insertions, 27 deletions
diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp
index d0e9eb7144..ca4ef96a43 100644
--- a/Source/Core/VideoCommon/GeometryShaderGen.cpp
+++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp
@@ -6,11 +6,26 @@
#include "VideoCommon/GeometryShaderGen.h"
#include "VideoCommon/LightingShaderGen.h"
+#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VertexShaderGen.h"
#include "VideoCommon/VideoConfig.h"
static char text[16384];
+static const char* primitives_ogl[] =
+{
+ "points",
+ "lines",
+ "triangles"
+};
+
+static const char* primitives_d3d[] =
+{
+ "point",
+ "line",
+ "triangle"
+};
+
template<class T>
static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE ApiType)
{
@@ -27,15 +42,18 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
text[sizeof(text) - 1] = 0x7C; // canary
uid_data->primitive_type = primitive_type;
+ const unsigned int vertex_in = primitive_type + 1;
uid_data->stereo = g_ActiveConfig.iStereoMode > 0;
+ const unsigned int vertex_out = primitive_type == PRIMITIVE_TRIANGLES ? 3 : 4;
+
if (ApiType == API_OPENGL)
{
// Insert layout parameters
if (g_ActiveConfig.backend_info.bSupportsGSInstancing)
- out.Write("layout(triangles, invocations = %d) in;\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1);
+ out.Write("layout(%s, invocations = %d) in;\n", primitives_ogl[primitive_type], g_ActiveConfig.iStereoMode > 0 ? 2 : 1);
else
- out.Write("layout(triangles) in;\n");
- out.Write("layout(triangle_strip, max_vertices = %d) out;\n", g_ActiveConfig.backend_info.bSupportsGSInstancing ? 3 : 6);
+ out.Write("layout(%s) in;\n", primitives_ogl[primitive_type]);
+ out.Write("layout(triangle_strip, max_vertices = %d) out;\n", g_ActiveConfig.backend_info.bSupportsGSInstancing ? vertex_out : vertex_out * 2);
}
out.Write("%s", s_lighting_struct);
@@ -62,9 +80,11 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
if (g_ActiveConfig.backend_info.bSupportsGSInstancing)
out.Write("#define InstanceID gl_InvocationID\n");
- out.Write("centroid in VS_OUTPUT o[3];\n");
+ out.Write("centroid in VS_OUTPUT o[%d];\n", vertex_in);
out.Write("centroid out VS_OUTPUT vs;\n");
- out.Write("flat out int layer;\n");
+
+ if (g_ActiveConfig.iStereoMode > 0)
+ out.Write("flat out int layer;\n");
out.Write("void main()\n{\n");
}
@@ -72,18 +92,21 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
{
out.Write("struct GS_OUTPUT {\n");
out.Write("\tVS_OUTPUT vs;\n");
- out.Write("\tuint layer : SV_RenderTargetArrayIndex;\n");
+
+ if (g_ActiveConfig.iStereoMode > 0)
+ out.Write("\tuint layer : SV_RenderTargetArrayIndex;\n");
+
out.Write("};\n");
+ out.Write("[maxvertexcount(%d)]\n", vertex_out);
if (g_ActiveConfig.backend_info.bSupportsGSInstancing)
{
- out.Write("[maxvertexcount(3)]\n[instance(%d)]\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1);
- out.Write("void main(triangle VS_OUTPUT o[3], inout TriangleStream<GS_OUTPUT> Output, in uint InstanceID : SV_GSInstanceID)\n{\n");
+ out.Write("[instance(%d)]\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1);
+ out.Write("void main(%s VS_OUTPUT o[%d], inout TriangleStream<GS_OUTPUT> Output, in uint InstanceID : SV_GSInstanceID)\n{\n", primitives_d3d[primitive_type], vertex_in);
}
else
{
- out.Write("[maxvertexcount(6)]\n");
- out.Write("void main(triangle VS_OUTPUT o[3], inout TriangleStream<GS_OUTPUT> Output)\n{\n");
+ out.Write("void main(%s VS_OUTPUT o[%d], inout TriangleStream<GS_OUTPUT> Output)\n{\n", primitives_d3d[primitive_type], vertex_in);
}
out.Write("\tGS_OUTPUT gs;\n");
@@ -91,29 +114,32 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
out.Write("\tVS_OUTPUT f;\n");
- // If the GPU supports invocation we don't need a for loop and can simply use the
- // invocation identifier to determine which layer we're rendering.
- if (g_ActiveConfig.backend_info.bSupportsGSInstancing)
- out.Write("\tint eye = InstanceID;\n");
- else
- out.Write("\tfor (int eye = 0; eye < %d; ++eye) {\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1);
-
- out.Write("\tfor (int i = 0; i < 3; ++i) {\n");
-
- // Select the output layer
- if (ApiType == API_OPENGL)
+ if (g_ActiveConfig.iStereoMode > 0)
{
- out.Write("\t\tgl_Layer = eye;\n");
- out.Write("\t\tlayer = eye;\n");
+ // If the GPU supports invocation we don't need a for loop and can simply use the
+ // invocation identifier to determine which layer we're rendering.
+ if (g_ActiveConfig.backend_info.bSupportsGSInstancing)
+ out.Write("\tint eye = InstanceID;\n");
+ else
+ out.Write("\tfor (int eye = 0; eye < %d; ++eye) {\n", g_ActiveConfig.iStereoMode > 0 ? 2 : 1);
}
- else
- out.Write("\t\tgs.layer = eye;\n");
+
+ out.Write("\tfor (int i = 0; i < %d; ++i) {\n", vertex_in);
out.Write("\t\tf = o[i];\n");
out.Write("\t\tfloat4 pos = o[i].pos;\n");
if (g_ActiveConfig.iStereoMode > 0)
{
+ // Select the output layer
+ if (ApiType == API_OPENGL)
+ {
+ out.Write("\t\tgl_Layer = eye;\n");
+ out.Write("\t\tlayer = eye;\n");
+ }
+ else
+ out.Write("\t\tgs.layer = eye;\n");
+
// For stereoscopy add a small horizontal offset in Normalized Device Coordinates proportional
// to the depth of the vertex. We retrieve the depth value from the w-component of the projected
// vertex which contains the negated z-component of the original vertex.
@@ -123,10 +149,9 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
// This formula is based on page 13 of the "Nvidia 3D Vision Automatic, Best Practices Guide"
out.Write("\t\tf.clipPos.x = o[i].clipPos.x + " I_STEREOPARAMS"[eye] * (o[i].clipPos.w - " I_STEREOPARAMS"[2]);\n");
out.Write("\t\tpos.x = o[i].pos.x + " I_STEREOPARAMS"[eye] * (o[i].pos.w - " I_STEREOPARAMS"[2]);\n");
+ out.Write("\t\tf.pos.x = pos.x;\n");
}
- out.Write("\t\tf.pos.x = pos.x;\n");
-
if (ApiType == API_OPENGL)
out.Write("\t\tgl_Position = pos;\n");