GeometryShaderManager: Upload Line/Point width constants.

This commit is contained in:
Jules Blok 2014-12-14 21:44:33 +01:00
parent aa4242fd9c
commit 332ba4b210
6 changed files with 59 additions and 3 deletions

View File

@ -130,6 +130,7 @@ static void BPWritten(const BPCmd& bp)
return;
case BPMEM_LINEPTWIDTH: // Line Width
SetLineWidth();
GeometryShaderManager::SetLinePtWidthChanged();
return;
case BPMEM_ZMODE: // Depth Control
PRIM_LOG("zmode: test=%d, func=%d, upd=%d", (int)bpmem.zmode.testenable,
@ -572,7 +573,10 @@ static void BPWritten(const BPCmd& bp)
case BPMEM_SU_SSIZE+14:
case BPMEM_SU_TSIZE+14:
if (bp.changes)
{
PixelShaderManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
GeometryShaderManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
}
return;
// ------------------------
// BPMEM_TX_SETMODE0 - (Texture lookup and filtering mode) LOD/BIAS Clamp, MaxAnsio, LODBIAS, DiagLoad, Min Filter, Mag Filter, Wrap T, S

View File

@ -48,4 +48,7 @@ struct VertexShaderConstants
struct GeometryShaderConstants
{
float4 stereoparams;
float4 lineptwidth;
float4 viewport;
u32 texoffsetflags[8];
};

View File

@ -47,9 +47,12 @@ 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"
"\tuint " I_TEXOFFSETFLAGS"[8];\n"
"};\n");
uid_data->numTexGens = xfmem.numTexGen.numTexGens;
uid_data->numTexGens = bpmem.genMode.numtexgens;
uid_data->pixel_lighting = g_ActiveConfig.bEnablePixelLighting;
GenerateVSOutputStruct<T>(out, ApiType);

View File

@ -5,6 +5,7 @@
#include <cfloat>
#include <cmath>
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/GeometryShaderGen.h"
#include "VideoCommon/GeometryShaderManager.h"
#include "VideoCommon/VideoCommon.h"
@ -12,7 +13,11 @@
#include "VideoCommon/XFMemory.h"
// track changes
static bool s_projection_changed, s_viewport_changed;
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
};
GeometryShaderConstants GeometryShaderManager::constants;
bool GeometryShaderManager::dirty;
@ -32,6 +37,16 @@ void GeometryShaderManager::Dirty()
{
s_projection_changed = true;
s_viewport_changed = true;
s_lineptwidth_changed = true;
SetTexCoordChanged(0);
SetTexCoordChanged(1);
SetTexCoordChanged(2);
SetTexCoordChanged(3);
SetTexCoordChanged(4);
SetTexCoordChanged(5);
SetTexCoordChanged(6);
SetTexCoordChanged(7);
dirty = true;
}
@ -39,6 +54,20 @@ void GeometryShaderManager::Dirty()
// Syncs the shader constant buffers with xfmem
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];
}
if (s_viewport_changed)
{
constants.viewport[0] = 2.0f * xfmem.viewport.wd;
constants.viewport[1] = -2.0f * xfmem.viewport.ht;
}
if (s_projection_changed)
{
s_projection_changed = false;
@ -69,6 +98,18 @@ void GeometryShaderManager::SetProjectionChanged()
s_projection_changed = true;
}
void GeometryShaderManager::SetLinePtWidthChanged()
{
s_lineptwidth_changed = true;
}
void GeometryShaderManager::SetTexCoordChanged(u8 texmapid)
{
TCoordInfo& tc = bpmem.texcoords[texmapid];
constants.texoffsetflags[texmapid] = tc.s.line_offset + tc.s.point_offset * 2;
dirty = true;
}
void GeometryShaderManager::DoState(PointerWrap &p)
{
p.Do(dirty);

View File

@ -23,6 +23,8 @@ public:
static void SetViewportChanged();
static void SetProjectionChanged();
static void SetLinePtWidthChanged();
static void SetTexCoordChanged(u8 texmapid);
static GeometryShaderConstants constants;
static bool dirty;

View File

@ -280,7 +280,10 @@ static inline void GenerateVSOutputStruct(T& object, API_TYPE api_type)
#define I_POSTTRANSFORMMATRICES "cpostmtx"
#define I_PIXELCENTERCORRECTION "cpixelcenter"
#define I_STEREOPARAMS "cstereo"
#define I_STEREOPARAMS "cstereo"
#define I_LINEPTWIDTH "clinept"
#define I_VIEWPORT "cviewport"
#define I_TEXOFFSETFLAGS "ctexoffset"
static const char s_shader_uniforms[] =
"\tfloat4 " I_POSNORMALMATRIX"[6];\n"