mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
VideoCommon: keep a copy of the const buffer in VideoCommon
The upload in the backend isn't done, it's just pushed by the mostly removed SetMulti*SConstant4fv. Also no optimizations was done on VideoCommon side, but I can start now :-) Sorry for the hacky way, but I think this is a nice (working) snapshot for a much bigger change.
This commit is contained in:
46
Source/Core/VideoCommon/Src/ConstantManager.h
Normal file
46
Source/Core/VideoCommon/Src/ConstantManager.h
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright 2013 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#ifndef _CONSTANTMANAGER_H
|
||||
#define _CONSTANTMANAGER_H
|
||||
|
||||
// all constant buffer attributes must be 16 bytes aligned, so this are the only allowed components:
|
||||
typedef float float4[4];
|
||||
typedef u8 uchar16[16];
|
||||
typedef s8 schar16[16];
|
||||
typedef u16 ushort8[8];
|
||||
typedef s16 sshort8[8];
|
||||
typedef u32 uint4[4];
|
||||
typedef s32 sint4[4];
|
||||
|
||||
struct PixelShaderConstants
|
||||
{
|
||||
float4 colors[4];
|
||||
float4 kcolors[4];
|
||||
float4 alpha;
|
||||
float4 texdims[8];
|
||||
float4 zbias[2];
|
||||
float4 indtexscale[2];
|
||||
float4 indtexmts[6];
|
||||
float4 fog[3];
|
||||
|
||||
// For pixel lighting
|
||||
float4 plights[40];
|
||||
float4 pmaterials[4];
|
||||
};
|
||||
|
||||
struct VertexShaderConstants
|
||||
{
|
||||
float4 posnormalmatrix[6];
|
||||
float4 projection[4];
|
||||
float4 materials[4];
|
||||
float4 lights[40];
|
||||
float4 texmatrices[24];
|
||||
float4 transformmatrices[64];
|
||||
float4 normalmatrices[32];
|
||||
float4 posttransformmatrices[64];
|
||||
float4 depthparams;
|
||||
};
|
||||
|
||||
#endif
|
@ -44,16 +44,16 @@ enum DSTALPHA_MODE
|
||||
};
|
||||
|
||||
// Annoying sure, can be removed once we get up to GLSL ~1.3
|
||||
const s_svar PSVar_Loc[] = { {I_COLORS, C_COLORS, 4 },
|
||||
{I_KCOLORS, C_KCOLORS, 4 },
|
||||
{I_ALPHA, C_ALPHA, 1 },
|
||||
{I_TEXDIMS, C_TEXDIMS, 8 },
|
||||
{I_ZBIAS , C_ZBIAS, 2 },
|
||||
{I_INDTEXSCALE , C_INDTEXSCALE, 2 },
|
||||
{I_INDTEXMTX, C_INDTEXMTX, 6 },
|
||||
{I_FOG, C_FOG, 3 },
|
||||
{I_PLIGHTS, C_PLIGHTS, 40 },
|
||||
{I_PMATERIALS, C_PMATERIALS, 4 },
|
||||
const s_svar PSVar_Loc[] = { {C_COLORS, 4 },
|
||||
{C_KCOLORS, 4 },
|
||||
{C_ALPHA, 1 },
|
||||
{C_TEXDIMS, 8 },
|
||||
{C_ZBIAS, 2 },
|
||||
{C_INDTEXSCALE, 2 },
|
||||
{C_INDTEXMTX, 6 },
|
||||
{C_FOG, 3 },
|
||||
{C_PLIGHTS, 40 },
|
||||
{C_PMATERIALS, 4 },
|
||||
};
|
||||
|
||||
#pragma pack(1)
|
||||
|
@ -29,19 +29,40 @@ static u32 lastTexDims[8]; // width | height << 16 | wrap_s << 28 | wrap_t << 30
|
||||
static u32 lastZBias;
|
||||
static int nMaterialsChanged;
|
||||
|
||||
PixelShaderConstants PixelShaderManager::constants;
|
||||
bool PixelShaderManager::dirty;
|
||||
|
||||
inline void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||
{
|
||||
g_renderer->SetPSConstant4f(const_number, f1, f2, f3, f4);
|
||||
float4* c = (float4*) &PixelShaderManager::constants;
|
||||
c[const_number][0] = f1;
|
||||
c[const_number][1] = f2;
|
||||
c[const_number][2] = f3;
|
||||
c[const_number][3] = f4;
|
||||
PixelShaderManager::dirty = true;
|
||||
}
|
||||
|
||||
inline void SetPSConstant4fv(unsigned int const_number, const float *f)
|
||||
{
|
||||
g_renderer->SetPSConstant4fv(const_number, f);
|
||||
float4* c = (float4*) &PixelShaderManager::constants;
|
||||
c[const_number][0] = f[0];
|
||||
c[const_number][1] = f[1];
|
||||
c[const_number][2] = f[2];
|
||||
c[const_number][3] = f[3];
|
||||
PixelShaderManager::dirty = true;
|
||||
}
|
||||
|
||||
inline void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||
{
|
||||
g_renderer->SetMultiPSConstant4fv(const_number, count, f);
|
||||
float4* c = (float4*) &PixelShaderManager::constants;
|
||||
for(u32 i=0; i<count; i++)
|
||||
{
|
||||
c[const_number+i][0] = f[0 + 4*i];
|
||||
c[const_number+i][1] = f[1 + 4*i];
|
||||
c[const_number+i][2] = f[2 + 4*i];
|
||||
c[const_number+i][3] = f[3 + 4*i];
|
||||
}
|
||||
PixelShaderManager::dirty = true;
|
||||
}
|
||||
|
||||
void PixelShaderManager::Init()
|
||||
@ -50,6 +71,7 @@ void PixelShaderManager::Init()
|
||||
memset(lastTexDims, 0, sizeof(lastTexDims));
|
||||
lastZBias = 0;
|
||||
memset(lastRGBAfull, 0, sizeof(lastRGBAfull));
|
||||
memset(&constants, 0, sizeof(constants));
|
||||
Dirty();
|
||||
}
|
||||
|
||||
@ -63,6 +85,7 @@ void PixelShaderManager::Dirty()
|
||||
s_bFogRangeAdjustChanged = s_bFogColorChanged = s_bFogParamChanged = true;
|
||||
nLightsChanged[0] = 0; nLightsChanged[1] = 0x80;
|
||||
nMaterialsChanged = 15;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void PixelShaderManager::Shutdown()
|
||||
@ -73,8 +96,8 @@ void PixelShaderManager::Shutdown()
|
||||
void PixelShaderManager::SetConstants(u32 components)
|
||||
{
|
||||
if (g_ActiveConfig.backend_info.APIType == API_OPENGL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
Dirty();
|
||||
|
||||
dirty = true;
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (s_nColorsChanged[i])
|
||||
@ -335,6 +358,12 @@ void PixelShaderManager::SetConstants(u32 components)
|
||||
nMaterialsChanged = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(dirty)
|
||||
{
|
||||
g_renderer->SetMultiPSConstant4fv(0, sizeof(constants)/16, (float*) &constants);
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void PixelShaderManager::SetPSTextureDims(int texid)
|
||||
@ -495,7 +524,9 @@ void PixelShaderManager::DoState(PointerWrap &p)
|
||||
p.Do(lastAlpha);
|
||||
p.Do(lastTexDims);
|
||||
p.Do(lastZBias);
|
||||
|
||||
p.Do(constants);
|
||||
p.Do(dirty);
|
||||
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
{
|
||||
Dirty();
|
||||
|
@ -8,9 +8,12 @@
|
||||
#include "BPMemory.h"
|
||||
#include "XFMemory.h"
|
||||
#include "PixelShaderGen.h"
|
||||
#include "ConstantManager.h"
|
||||
|
||||
class PointerWrap;
|
||||
|
||||
|
||||
|
||||
// The non-API dependent parts.
|
||||
class PixelShaderManager
|
||||
{
|
||||
@ -41,6 +44,9 @@ public:
|
||||
static void SetColorMatrix(const float* pmatrix);
|
||||
static void InvalidateXFRange(int start, int end);
|
||||
static void SetMaterialColorChanged(int index);
|
||||
|
||||
static PixelShaderConstants constants;
|
||||
static bool dirty;
|
||||
};
|
||||
|
||||
|
||||
|
@ -116,14 +116,7 @@ public:
|
||||
static void StorePixelFormat(unsigned int new_format) { prev_efb_format = new_format; }
|
||||
|
||||
// TODO: doesn't belong here
|
||||
virtual void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) = 0;
|
||||
virtual void SetPSConstant4fv(unsigned int const_number, const float *f) = 0;
|
||||
virtual void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) = 0;
|
||||
|
||||
// TODO: doesn't belong here
|
||||
virtual void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) = 0;
|
||||
virtual void SetVSConstant4fv(unsigned int const_number, const float *f) = 0;
|
||||
virtual void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f) = 0;
|
||||
virtual void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f) = 0;
|
||||
|
||||
protected:
|
||||
|
@ -867,10 +867,4 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
|
||||
return text;
|
||||
}
|
||||
|
||||
void SetShaderParameters(float width, float height, float offsetX, float offsetY, float widthStride, float heightStride,float buffW,float buffH)
|
||||
{
|
||||
g_renderer->SetPSConstant4f(C_COLORMATRIX, widthStride, heightStride, buffW, buffH);
|
||||
g_renderer->SetPSConstant4f(C_COLORMATRIX + 1, width, (height - 1), offsetX, offsetY);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -15,8 +15,6 @@ u16 GetEncodedSampleCount(u32 format);
|
||||
|
||||
const char *GenerateEncodingShader(u32 format, API_TYPE ApiType = API_OPENGL);
|
||||
|
||||
void SetShaderParameters(float width, float height, float offsetX, float offsetY, float widthStride, float heightStride,float buffW = 0.0f,float buffH = 0.0f);
|
||||
|
||||
}
|
||||
|
||||
#endif // _TEXTURECONVERSIONSHADER_H_
|
||||
|
@ -53,15 +53,15 @@
|
||||
#define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64)
|
||||
#define C_VENVCONST_END (C_DEPTHPARAMS + 1)
|
||||
|
||||
const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
|
||||
{I_PROJECTION , C_PROJECTION, 4 },
|
||||
{I_MATERIALS, C_MATERIALS, 4 },
|
||||
{I_LIGHTS, C_LIGHTS, 40 },
|
||||
{I_TEXMATRICES, C_TEXMATRICES, 24 },
|
||||
{I_TRANSFORMMATRICES , C_TRANSFORMMATRICES, 64 },
|
||||
{I_NORMALMATRICES , C_NORMALMATRICES, 32 },
|
||||
{I_POSTTRANSFORMMATRICES, C_POSTTRANSFORMMATRICES, 64 },
|
||||
{I_DEPTHPARAMS, C_DEPTHPARAMS, 1 },
|
||||
const s_svar VSVar_Loc[] = { {C_POSNORMALMATRIX, 6 },
|
||||
{C_PROJECTION, 4 },
|
||||
{C_MATERIALS, 4 },
|
||||
{C_LIGHTS, 40 },
|
||||
{C_TEXMATRICES, 24 },
|
||||
{C_TRANSFORMMATRICES, 64 },
|
||||
{C_NORMALMATRICES, 32 },
|
||||
{C_POSTTRANSFORMMATRICES, 64 },
|
||||
{C_DEPTHPARAMS, 1 },
|
||||
};
|
||||
|
||||
#pragma pack(1)
|
||||
|
@ -36,6 +36,9 @@ static Matrix33 s_viewInvRotationMatrix;
|
||||
static float s_fViewTranslationVector[3];
|
||||
static float s_fViewRotation[2];
|
||||
|
||||
VertexShaderConstants VertexShaderManager::constants;
|
||||
bool VertexShaderManager::dirty;
|
||||
|
||||
void UpdateViewport(Matrix44& vpCorrection);
|
||||
|
||||
void UpdateViewportWithCorrection()
|
||||
@ -45,22 +48,48 @@ void UpdateViewportWithCorrection()
|
||||
|
||||
inline void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
||||
{
|
||||
g_renderer->SetVSConstant4f(const_number, f1, f2, f3, f4);
|
||||
float4* c = (float4*) &VertexShaderManager::constants;
|
||||
c[const_number][0] = f1;
|
||||
c[const_number][1] = f2;
|
||||
c[const_number][2] = f3;
|
||||
c[const_number][3] = f4;
|
||||
VertexShaderManager::dirty = true;
|
||||
}
|
||||
|
||||
inline void SetVSConstant4fv(unsigned int const_number, const float *f)
|
||||
{
|
||||
g_renderer->SetVSConstant4fv(const_number, f);
|
||||
float4* c = (float4*) &VertexShaderManager::constants;
|
||||
c[const_number][0] = f[0];
|
||||
c[const_number][1] = f[1];
|
||||
c[const_number][2] = f[2];
|
||||
c[const_number][3] = f[3];
|
||||
VertexShaderManager::dirty = true;
|
||||
}
|
||||
|
||||
inline void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
|
||||
{
|
||||
g_renderer->SetMultiVSConstant3fv(const_number, count, f);
|
||||
float4* c = (float4*) &VertexShaderManager::constants;
|
||||
for(u32 i=0; i<count; i++)
|
||||
{
|
||||
c[const_number+i][0] = f[0 + 3*i];
|
||||
c[const_number+i][1] = f[1 + 3*i];
|
||||
c[const_number+i][2] = f[2 + 3*i];
|
||||
c[const_number+i][3] = 0.0f;
|
||||
}
|
||||
VertexShaderManager::dirty = true;
|
||||
}
|
||||
|
||||
inline void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||
{
|
||||
g_renderer->SetMultiVSConstant4fv(const_number, count, f);
|
||||
float4* c = (float4*) &VertexShaderManager::constants;
|
||||
for(u32 i=0; i<count; i++)
|
||||
{
|
||||
c[const_number+i][0] = f[0 + 4*i];
|
||||
c[const_number+i][1] = f[1 + 4*i];
|
||||
c[const_number+i][2] = f[2 + 4*i];
|
||||
c[const_number+i][3] = f[3 + 4*i];
|
||||
}
|
||||
VertexShaderManager::dirty = true;
|
||||
}
|
||||
|
||||
struct ProjectionHack
|
||||
@ -153,6 +182,7 @@ void VertexShaderManager::Init()
|
||||
|
||||
memset(&xfregs, 0, sizeof(xfregs));
|
||||
memset(xfmem, 0, sizeof(xfmem));
|
||||
memset(&constants, 0 , sizeof(constants));
|
||||
ResetView();
|
||||
|
||||
// TODO: should these go inside ResetView()?
|
||||
@ -187,6 +217,8 @@ void VertexShaderManager::Dirty()
|
||||
bProjectionChanged = true;
|
||||
|
||||
nMaterialsChanged = 15;
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
// Syncs the shader constant buffers with xfmem
|
||||
@ -194,7 +226,7 @@ void VertexShaderManager::Dirty()
|
||||
void VertexShaderManager::SetConstants()
|
||||
{
|
||||
if (g_ActiveConfig.backend_info.APIType == API_OPENGL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
Dirty();
|
||||
dirty = true;
|
||||
|
||||
if (nTransformMatricesChanged[0] >= 0)
|
||||
{
|
||||
@ -488,6 +520,12 @@ void VertexShaderManager::SetConstants()
|
||||
SetMultiVSConstant4fv(C_PROJECTION, 4, correctedMtx.data);
|
||||
}
|
||||
}
|
||||
|
||||
if(dirty)
|
||||
{
|
||||
dirty = false;
|
||||
g_renderer->SetMultiVSConstant4fv(0, sizeof(constants)/16, (float*) &constants);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexShaderManager::InvalidateXFRange(int start, int end)
|
||||
@ -669,6 +707,8 @@ void VertexShaderManager::DoState(PointerWrap &p)
|
||||
p.Do(s_viewInvRotationMatrix);
|
||||
p.Do(s_fViewTranslationVector);
|
||||
p.Do(s_fViewRotation);
|
||||
p.Do(constants);
|
||||
p.Do(dirty);
|
||||
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
{
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define _VERTEXSHADERMANAGER_H
|
||||
|
||||
#include "VertexShaderGen.h"
|
||||
#include "ConstantManager.h"
|
||||
|
||||
class PointerWrap;
|
||||
|
||||
@ -35,6 +36,9 @@ public:
|
||||
static void TranslateView(float x, float y, float z = 0.0f);
|
||||
static void RotateView(float x, float y);
|
||||
static void ResetView();
|
||||
|
||||
static VertexShaderConstants constants;
|
||||
static bool dirty;
|
||||
};
|
||||
|
||||
#endif // _VERTEXSHADERMANAGER_H
|
||||
|
@ -134,7 +134,6 @@ inline unsigned int GetPow2(unsigned int val)
|
||||
}
|
||||
struct s_svar
|
||||
{
|
||||
const char *name;
|
||||
const unsigned int reg;
|
||||
const unsigned int size;
|
||||
};
|
||||
|
Reference in New Issue
Block a user