mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 13:27:45 -07:00
GeometryShaderGen: Pack uniforms more tightly.
This commit is contained in:
parent
d115048615
commit
0ac7103391
@ -48,7 +48,6 @@ struct VertexShaderConstants
|
||||
struct GeometryShaderConstants
|
||||
{
|
||||
float4 stereoparams;
|
||||
float4 lineptwidth;
|
||||
float4 viewport;
|
||||
s32 texoffsetflags[8];
|
||||
float4 lineptparams;
|
||||
int4 texoffset;
|
||||
};
|
||||
|
@ -73,9 +73,8 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
|
||||
out.Write("cbuffer GSBlock {\n");
|
||||
out.Write(
|
||||
"\tfloat4 " I_STEREOPARAMS";\n"
|
||||
"\tfloat4 " I_LINEPTWIDTH";\n"
|
||||
"\tfloat4 " I_VIEWPORT";\n"
|
||||
"\tint " I_TEXOFFSETFLAGS"[8];\n"
|
||||
"\tfloat4 " I_LINEPTPARAMS";\n"
|
||||
"\tint4 " I_TEXOFFSET";\n"
|
||||
"};\n");
|
||||
|
||||
uid_data->numTexGens = bpmem.genMode.numtexgens;
|
||||
@ -130,21 +129,21 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
|
||||
out.Write("\tfloat2 to = abs(o[1].pos.xy - o[0].pos.xy);\n");
|
||||
// FIXME: What does real hardware do when line is at a 45-degree angle?
|
||||
// FIXME: Lines aren't drawn at the correct width. See Twilight Princess map.
|
||||
out.Write("\tif (" I_VIEWPORT".y * to.y > " I_VIEWPORT".x * to.x) {\n");
|
||||
out.Write("\tif (" I_LINEPTPARAMS".y * to.y > " I_LINEPTPARAMS".x * to.x) {\n");
|
||||
// Line is more tall. Extend geometry left and right.
|
||||
// Lerp LineWidth/2 from [0..VpWidth] to [-1..1]
|
||||
out.Write("\t\toffset = float2(" I_LINEPTWIDTH"[0] / " I_VIEWPORT".x, 0);\n");
|
||||
out.Write("\t\toffset = float2(" I_LINEPTPARAMS".z / " I_LINEPTPARAMS".x, 0);\n");
|
||||
out.Write("\t} else {\n");
|
||||
// Line is more wide. Extend geometry up and down.
|
||||
// Lerp LineWidth/2 from [0..VpHeight] to [1..-1]
|
||||
out.Write("\t\toffset = float2(0, -" I_LINEPTWIDTH"[0] / " I_VIEWPORT".y);\n");
|
||||
out.Write("\t\toffset = float2(0, -" I_LINEPTPARAMS".z / " I_LINEPTPARAMS".y);\n");
|
||||
out.Write("\t}\n");
|
||||
}
|
||||
else if (primitive_type == PRIMITIVE_POINTS)
|
||||
{
|
||||
// Offset from center to upper right vertex
|
||||
// Lerp PointSize/2 from [0,0..VpWidth,VpHeight] to [-1,1..1,-1]
|
||||
out.Write("float2 offset = float2(" I_LINEPTWIDTH"[1] / " I_VIEWPORT".x, -" I_LINEPTWIDTH"[1] / " I_VIEWPORT".y) * o[0].pos.w;\n");
|
||||
out.Write("float2 offset = float2(" I_LINEPTPARAMS".w / " I_LINEPTPARAMS".x, -" I_LINEPTPARAMS".w / " I_LINEPTPARAMS".y) * o[0].pos.w;\n");
|
||||
}
|
||||
|
||||
if (g_ActiveConfig.iStereoMode > 0)
|
||||
@ -190,34 +189,43 @@ static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE A
|
||||
out.Write("\tl.pos.xy -= offset * l.pos.w;\n");
|
||||
out.Write("\tr.pos.xy += offset * r.pos.w;\n");
|
||||
|
||||
out.Write("\tif (" I_TEXOFFSET"[2] != 0) {\n");
|
||||
out.Write("\tfloat texOffset = 1.0 / float(" I_TEXOFFSET"[2]);\n");
|
||||
|
||||
for (unsigned int i = 0; i < bpmem.genMode.numtexgens; ++i)
|
||||
{
|
||||
out.Write("\tr.tex%d.x += " I_LINEPTWIDTH"[2] * (" I_TEXOFFSETFLAGS"[%d] & 0x01);\n", i, i);
|
||||
out.Write("\tif (((" I_TEXOFFSET"[0] >> %d) & 0x1) != 0)\n", i);
|
||||
out.Write("\t\tr.tex%d.x += texOffset;\n", i);
|
||||
}
|
||||
out.Write("\t}\n");
|
||||
|
||||
EmitVertex<T>(out, "l", ApiType);
|
||||
EmitVertex<T>(out, "r", ApiType);
|
||||
}
|
||||
else if (primitive_type == PRIMITIVE_POINTS)
|
||||
{
|
||||
out.Write("VS_OUTPUT ll = f;\n");
|
||||
out.Write("VS_OUTPUT lr = f;\n");
|
||||
out.Write("VS_OUTPUT ul = f;\n");
|
||||
out.Write("VS_OUTPUT ur = f;\n");
|
||||
out.Write("\tVS_OUTPUT ll = f;\n");
|
||||
out.Write("\tVS_OUTPUT lr = f;\n");
|
||||
out.Write("\tVS_OUTPUT ul = f;\n");
|
||||
out.Write("\tVS_OUTPUT ur = f;\n");
|
||||
|
||||
out.Write("ll.pos.xy += float2(-1,-1) * offset;\n");
|
||||
out.Write("lr.pos.xy += float2(1,-1) * offset;\n");
|
||||
out.Write("ul.pos.xy += float2(-1,1) * offset;\n");
|
||||
out.Write("ur.pos.xy += offset;\n");
|
||||
out.Write("\tll.pos.xy += float2(-1,-1) * offset;\n");
|
||||
out.Write("\tlr.pos.xy += float2(1,-1) * offset;\n");
|
||||
out.Write("\tul.pos.xy += float2(-1,1) * offset;\n");
|
||||
out.Write("\tur.pos.xy += offset;\n");
|
||||
|
||||
out.Write("float2 texOffset = float2(" I_LINEPTWIDTH"[3], " I_LINEPTWIDTH"[3]);\n");
|
||||
out.Write("\tif (" I_TEXOFFSET"[3] != 0) {\n");
|
||||
out.Write("\tfloat2 texOffset = float2(1.0 / float(" I_TEXOFFSET"[3]), 1.0 / float(" I_TEXOFFSET"[3]));\n");
|
||||
|
||||
for (unsigned int i = 0; i < bpmem.genMode.numtexgens; ++i)
|
||||
{
|
||||
out.Write("ll.tex%d.xy += float2(0,1) * texOffset * (" I_TEXOFFSETFLAGS"[%d] & 0x10);\n", i, i);
|
||||
out.Write("lr.tex%d.xy += texOffset * (" I_TEXOFFSETFLAGS"[%d] & 0x10);\n", i, i);
|
||||
out.Write("ur.tex%d.xy += float2(1,0) * texOffset * (" I_TEXOFFSETFLAGS"[%d] & 0x10);\n", i, i);
|
||||
out.Write("\tif (((" I_TEXOFFSET"[1] >> %d) & 0x1) != 0) {\n", i);
|
||||
out.Write("\t\tll.tex%d.xy += float2(0,1) * texOffset;\n", i);
|
||||
out.Write("\t\tlr.tex%d.xy += texOffset;\n", i);
|
||||
out.Write("\t\tur.tex%d.xy += float2(1,0) * texOffset;\n", i);
|
||||
out.Write("\t}\n");
|
||||
}
|
||||
out.Write("\t}\n");
|
||||
|
||||
EmitVertex<T>(out, "ll", ApiType);
|
||||
EmitVertex<T>(out, "lr", ApiType);
|
||||
|
@ -15,8 +15,8 @@
|
||||
// track changes
|
||||
static bool s_projection_changed, s_viewport_changed, s_lineptwidth_changed;
|
||||
|
||||
static const float LINE_PT_TEX_OFFSETS[8] = {
|
||||
0.f, 0.0625f, 0.125f, 0.25f, 0.5f, 1.f, 1.f, 1.f
|
||||
static const int LINE_PT_TEX_OFFSETS[8] = {
|
||||
0, 16, 8, 4, 2, 1, 1, 1
|
||||
};
|
||||
|
||||
GeometryShaderConstants GeometryShaderManager::constants;
|
||||
@ -56,16 +56,16 @@ void GeometryShaderManager::SetConstants()
|
||||
{
|
||||
if (s_lineptwidth_changed)
|
||||
{
|
||||
constants.lineptwidth[0] = bpmem.lineptwidth.linesize / 6.f;
|
||||
constants.lineptwidth[1] = bpmem.lineptwidth.pointsize / 6.f;
|
||||
constants.lineptwidth[2] = LINE_PT_TEX_OFFSETS[bpmem.lineptwidth.lineoff];
|
||||
constants.lineptwidth[3] = LINE_PT_TEX_OFFSETS[bpmem.lineptwidth.pointoff];
|
||||
constants.lineptparams[2] = bpmem.lineptwidth.linesize / 6.f;
|
||||
constants.lineptparams[3] = bpmem.lineptwidth.pointsize / 6.f;
|
||||
constants.texoffset[2] = LINE_PT_TEX_OFFSETS[bpmem.lineptwidth.lineoff];
|
||||
constants.texoffset[3] = LINE_PT_TEX_OFFSETS[bpmem.lineptwidth.pointoff];
|
||||
}
|
||||
|
||||
if (s_viewport_changed)
|
||||
{
|
||||
constants.viewport[0] = 2.0f * xfmem.viewport.wd;
|
||||
constants.viewport[1] = -2.0f * xfmem.viewport.ht;
|
||||
constants.lineptparams[0] = 2.0f * xfmem.viewport.wd;
|
||||
constants.lineptparams[1] = -2.0f * xfmem.viewport.ht;
|
||||
}
|
||||
|
||||
if (s_projection_changed)
|
||||
@ -106,7 +106,11 @@ void GeometryShaderManager::SetLinePtWidthChanged()
|
||||
void GeometryShaderManager::SetTexCoordChanged(u8 texmapid)
|
||||
{
|
||||
TCoordInfo& tc = bpmem.texcoords[texmapid];
|
||||
constants.texoffsetflags[texmapid] = tc.s.line_offset + tc.s.point_offset * 2;
|
||||
int bitmask = 1 << texmapid;
|
||||
constants.texoffset[0] &= ~bitmask;
|
||||
constants.texoffset[0] |= tc.s.line_offset << texmapid;
|
||||
constants.texoffset[1] &= ~bitmask;
|
||||
constants.texoffset[1] |= tc.s.point_offset << texmapid;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
|
@ -280,10 +280,9 @@ static inline void GenerateVSOutputStruct(T& object, API_TYPE api_type)
|
||||
#define I_POSTTRANSFORMMATRICES "cpostmtx"
|
||||
#define I_PIXELCENTERCORRECTION "cpixelcenter"
|
||||
|
||||
#define I_STEREOPARAMS "cstereo"
|
||||
#define I_LINEPTWIDTH "clinept"
|
||||
#define I_VIEWPORT "cviewport"
|
||||
#define I_TEXOFFSETFLAGS "ctexoffset"
|
||||
#define I_STEREOPARAMS "cstereo"
|
||||
#define I_LINEPTPARAMS "clinept"
|
||||
#define I_TEXOFFSET "ctexoffset"
|
||||
|
||||
static const char s_shader_uniforms[] =
|
||||
"\tfloat4 " I_POSNORMALMATRIX"[6];\n"
|
||||
|
Loading…
Reference in New Issue
Block a user