mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
VideoCommon: Add a separate constants buffer for the geometry shader.
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#include "VideoCommon/BPFunctions.h"
|
||||
#include "VideoCommon/BPStructs.h"
|
||||
#include "VideoCommon/Fifo.h"
|
||||
#include "VideoCommon/GeometryShaderManager.h"
|
||||
#include "VideoCommon/PerfQueryBase.h"
|
||||
#include "VideoCommon/PixelEngine.h"
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
@ -125,6 +126,7 @@ static void BPWritten(const BPCmd& bp)
|
||||
case BPMEM_SCISSOROFFSET: // Scissor Offset
|
||||
SetScissor();
|
||||
VertexShaderManager::SetViewportChanged();
|
||||
GeometryShaderManager::SetViewportChanged();
|
||||
return;
|
||||
case BPMEM_LINEPTWIDTH: // Line Width
|
||||
SetLineWidth();
|
||||
|
@ -10,6 +10,7 @@ set(SRCS BoundingBox.cpp
|
||||
FPSCounter.cpp
|
||||
FramebufferManagerBase.cpp
|
||||
GeometryShaderGen.cpp
|
||||
GeometryShaderManager.cpp
|
||||
HiresTextures.cpp
|
||||
ImageWrite.cpp
|
||||
IndexGenerator.cpp
|
||||
|
@ -43,6 +43,9 @@ struct VertexShaderConstants
|
||||
float4 normalmatrices[32];
|
||||
float4 posttransformmatrices[64];
|
||||
float4 pixelcentercorrection;
|
||||
float4 stereoparams;
|
||||
};
|
||||
|
||||
struct GeometryShaderConstants
|
||||
{
|
||||
float4 stereoparams;
|
||||
};
|
||||
|
@ -43,11 +43,12 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy
|
||||
|
||||
// uniforms
|
||||
if (ApiType == API_OPENGL)
|
||||
out.Write("layout(std140%s) uniform VSBlock {\n", g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 2" : "");
|
||||
out.Write("layout(std140%s) uniform GSBlock {\n", g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 3" : "");
|
||||
else
|
||||
out.Write("cbuffer VSBlock {\n");
|
||||
out.Write(s_shader_uniforms);
|
||||
out.Write("};\n");
|
||||
out.Write("cbuffer GSBlock {\n");
|
||||
out.Write(
|
||||
"\tfloat4 " I_STEREOPARAMS";\n"
|
||||
"};\n");
|
||||
|
||||
uid_data->numTexGens = xfmem.numTexGen.numTexGens;
|
||||
uid_data->pixel_lighting = g_ActiveConfig.bEnablePixelLighting;
|
||||
|
82
Source/Core/VideoCommon/GeometryShaderManager.cpp
Normal file
82
Source/Core/VideoCommon/GeometryShaderManager.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright 2013 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
|
||||
#include "VideoCommon/GeometryShaderGen.h"
|
||||
#include "VideoCommon/GeometryShaderManager.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
#include "VideoCommon/XFMemory.h"
|
||||
|
||||
// track changes
|
||||
static bool s_projection_changed, s_viewport_changed;
|
||||
|
||||
GeometryShaderConstants GeometryShaderManager::constants;
|
||||
bool GeometryShaderManager::dirty;
|
||||
|
||||
void GeometryShaderManager::Init()
|
||||
{
|
||||
memset(&constants, 0, sizeof(constants));
|
||||
|
||||
Dirty();
|
||||
}
|
||||
|
||||
void GeometryShaderManager::Shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
void GeometryShaderManager::Dirty()
|
||||
{
|
||||
s_projection_changed = true;
|
||||
s_viewport_changed = true;
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
// Syncs the shader constant buffers with xfmem
|
||||
void GeometryShaderManager::SetConstants()
|
||||
{
|
||||
if (s_projection_changed)
|
||||
{
|
||||
s_projection_changed = false;
|
||||
|
||||
if (g_ActiveConfig.iStereoMode > 0 && xfmem.projection.type == GX_PERSPECTIVE)
|
||||
{
|
||||
float offset = (g_ActiveConfig.iStereoSeparation / 1000.0f) * (g_ActiveConfig.iStereoSeparationPercent / 100.0f);
|
||||
constants.stereoparams[0] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset;
|
||||
constants.stereoparams[1] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset;
|
||||
constants.stereoparams[2] = (g_ActiveConfig.iStereoConvergence / 10.0f) * (g_ActiveConfig.iStereoConvergencePercent / 100.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
constants.stereoparams[0] = constants.stereoparams[1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void GeometryShaderManager::SetViewportChanged()
|
||||
{
|
||||
s_viewport_changed = true;
|
||||
}
|
||||
|
||||
void GeometryShaderManager::SetProjectionChanged()
|
||||
{
|
||||
s_projection_changed = true;
|
||||
}
|
||||
|
||||
void GeometryShaderManager::DoState(PointerWrap &p)
|
||||
{
|
||||
p.Do(dirty);
|
||||
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
{
|
||||
// Reload current state from global GPU state
|
||||
// NOTE: This requires that all GPU memory has been loaded already.
|
||||
Dirty();
|
||||
}
|
||||
}
|
29
Source/Core/VideoCommon/GeometryShaderManager.h
Normal file
29
Source/Core/VideoCommon/GeometryShaderManager.h
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2013 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "VideoCommon/ConstantManager.h"
|
||||
#include "VideoCommon/GeometryShaderGen.h"
|
||||
|
||||
class PointerWrap;
|
||||
|
||||
// The non-API dependent parts.
|
||||
class GeometryShaderManager
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Dirty();
|
||||
static void Shutdown();
|
||||
static void DoState(PointerWrap &p);
|
||||
|
||||
// constant management
|
||||
static void SetConstants();
|
||||
|
||||
static void SetViewportChanged();
|
||||
static void SetProjectionChanged();
|
||||
|
||||
static GeometryShaderConstants constants;
|
||||
static bool dirty;
|
||||
};
|
@ -279,7 +279,8 @@ static inline void GenerateVSOutputStruct(T& object, API_TYPE api_type)
|
||||
#define I_NORMALMATRICES "cnmtx"
|
||||
#define I_POSTTRANSFORMMATRICES "cpostmtx"
|
||||
#define I_PIXELCENTERCORRECTION "cpixelcenter"
|
||||
#define I_STEREOPARAMS "cstereo"
|
||||
|
||||
#define I_STEREOPARAMS "cstereo"
|
||||
|
||||
static const char s_shader_uniforms[] =
|
||||
"\tfloat4 " I_POSNORMALMATRIX"[6];\n"
|
||||
@ -290,5 +291,4 @@ static const char s_shader_uniforms[] =
|
||||
"\tfloat4 " I_TRANSFORMMATRICES"[64];\n"
|
||||
"\tfloat4 " I_NORMALMATRICES"[32];\n"
|
||||
"\tfloat4 " I_POSTTRANSFORMMATRICES"[64];\n"
|
||||
"\tfloat4 " I_PIXELCENTERCORRECTION";\n"
|
||||
"\tfloat4 " I_STEREOPARAMS";\n";
|
||||
"\tfloat4 " I_PIXELCENTERCORRECTION";\n";
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "VideoCommon/BPStructs.h"
|
||||
#include "VideoCommon/Debugger.h"
|
||||
#include "VideoCommon/GeometryShaderManager.h"
|
||||
#include "VideoCommon/IndexGenerator.h"
|
||||
#include "VideoCommon/MainBase.h"
|
||||
#include "VideoCommon/NativeVertexFormat.h"
|
||||
@ -223,6 +224,7 @@ void VertexManager::Flush()
|
||||
// set global constants
|
||||
VertexShaderManager::SetConstants();
|
||||
PixelShaderManager::SetConstants();
|
||||
GeometryShaderManager::SetConstants();
|
||||
|
||||
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass &&
|
||||
bpmem.dstalpha.enable &&
|
||||
|
@ -512,18 +512,6 @@ void VertexShaderManager::SetConstants()
|
||||
memcpy(constants.projection, correctedMtx.data, 4*16);
|
||||
}
|
||||
|
||||
if (g_ActiveConfig.iStereoMode > 0 && xfmem.projection.type == GX_PERSPECTIVE)
|
||||
{
|
||||
float offset = (g_ActiveConfig.iStereoSeparation / 1000.0f) * (g_ActiveConfig.iStereoSeparationPercent / 100.0f);
|
||||
constants.stereoparams[0] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset;
|
||||
constants.stereoparams[1] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset;
|
||||
constants.stereoparams[2] = (g_ActiveConfig.iStereoConvergence / 10.0f) * (g_ActiveConfig.iStereoConvergencePercent / 100.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
constants.stereoparams[0] = constants.stereoparams[1] = 0;
|
||||
}
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,7 @@
|
||||
<ClCompile Include="RenderBase.cpp" />
|
||||
<ClCompile Include="Statistics.cpp" />
|
||||
<ClCompile Include="GeometryShaderGen.cpp" />
|
||||
<ClCompile Include="GeometryShaderManager.cpp" />
|
||||
<ClCompile Include="TextureCacheBase.cpp" />
|
||||
<ClCompile Include="TextureConversionShader.cpp" />
|
||||
<ClCompile Include="VertexLoader.cpp" />
|
||||
@ -112,6 +113,7 @@
|
||||
<ClInclude Include="ShaderGenCommon.h" />
|
||||
<ClInclude Include="Statistics.h" />
|
||||
<ClInclude Include="GeometryShaderGen.h" />
|
||||
<ClInclude Include="GeometryShaderManager.h" />
|
||||
<ClInclude Include="TextureCacheBase.h" />
|
||||
<ClInclude Include="TextureConversionShader.h" />
|
||||
<ClInclude Include="TextureDecoder.h" />
|
||||
|
@ -146,6 +146,9 @@
|
||||
<ClCompile Include="GeometryShaderGen.cpp">
|
||||
<Filter>Shader Generators</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeometryShaderManager.cpp">
|
||||
<Filter>Shader Managers</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CommandProcessor.h" />
|
||||
@ -284,6 +287,9 @@
|
||||
<ClInclude Include="GeometryShaderGen.h">
|
||||
<Filter>Shader Generators</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GeometryShaderManager.h">
|
||||
<Filter>Shader Managers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "VideoCommon/CommandProcessor.h"
|
||||
#include "VideoCommon/CPMemory.h"
|
||||
#include "VideoCommon/Fifo.h"
|
||||
#include "VideoCommon/GeometryShaderManager.h"
|
||||
#include "VideoCommon/PixelEngine.h"
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
#include "VideoCommon/TextureDecoder.h"
|
||||
@ -50,6 +51,9 @@ static void DoState(PointerWrap &p)
|
||||
VertexShaderManager::DoState(p);
|
||||
p.DoMarker("VertexShaderManager");
|
||||
|
||||
GeometryShaderManager::DoState(p);
|
||||
p.DoMarker("GeometryShaderManager");
|
||||
|
||||
VertexManager::DoState(p);
|
||||
p.DoMarker("VertexManager");
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "VideoCommon/CPMemory.h"
|
||||
#include "VideoCommon/DataReader.h"
|
||||
#include "VideoCommon/Fifo.h"
|
||||
#include "VideoCommon/GeometryShaderManager.h"
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
#include "VideoCommon/VertexManagerBase.h"
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
@ -110,6 +111,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||
VertexManager::Flush();
|
||||
VertexShaderManager::SetViewportChanged();
|
||||
PixelShaderManager::SetViewportChanged();
|
||||
GeometryShaderManager::SetViewportChanged();
|
||||
|
||||
nextAddress = XFMEM_SETVIEWPORT + 6;
|
||||
break;
|
||||
@ -123,6 +125,7 @@ static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
||||
case XFMEM_SETPROJECTION+6:
|
||||
VertexManager::Flush();
|
||||
VertexShaderManager::SetProjectionChanged();
|
||||
GeometryShaderManager::SetProjectionChanged();
|
||||
|
||||
nextAddress = XFMEM_SETPROJECTION + 7;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user