From 332ba4b2100ec4dcda4b2e83eb5b0e2d21e6abc4 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sun, 14 Dec 2014 21:44:33 +0100 Subject: [PATCH] GeometryShaderManager: Upload Line/Point width constants. --- Source/Core/VideoCommon/BPStructs.cpp | 4 ++ Source/Core/VideoCommon/ConstantManager.h | 3 ++ Source/Core/VideoCommon/GeometryShaderGen.cpp | 5 ++- .../VideoCommon/GeometryShaderManager.cpp | 43 ++++++++++++++++++- .../Core/VideoCommon/GeometryShaderManager.h | 2 + Source/Core/VideoCommon/ShaderGenCommon.h | 5 ++- 6 files changed, 59 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index 8996784760..fdf3e15ff2 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -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 diff --git a/Source/Core/VideoCommon/ConstantManager.h b/Source/Core/VideoCommon/ConstantManager.h index 9039a1b220..00f82d681e 100644 --- a/Source/Core/VideoCommon/ConstantManager.h +++ b/Source/Core/VideoCommon/ConstantManager.h @@ -48,4 +48,7 @@ struct VertexShaderConstants struct GeometryShaderConstants { float4 stereoparams; + float4 lineptwidth; + float4 viewport; + u32 texoffsetflags[8]; }; diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp index 3a2282521e..814ad9c075 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.cpp +++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp @@ -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(out, ApiType); diff --git a/Source/Core/VideoCommon/GeometryShaderManager.cpp b/Source/Core/VideoCommon/GeometryShaderManager.cpp index f754961cbc..70bb151666 100644 --- a/Source/Core/VideoCommon/GeometryShaderManager.cpp +++ b/Source/Core/VideoCommon/GeometryShaderManager.cpp @@ -5,6 +5,7 @@ #include #include +#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); diff --git a/Source/Core/VideoCommon/GeometryShaderManager.h b/Source/Core/VideoCommon/GeometryShaderManager.h index d9d8af959f..86cd3ee2ea 100644 --- a/Source/Core/VideoCommon/GeometryShaderManager.h +++ b/Source/Core/VideoCommon/GeometryShaderManager.h @@ -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; diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index a73290fa44..d5a2438316 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -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"