mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-21 19:47:32 +01: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:
parent
0753ce5bda
commit
4377618438
@ -538,47 +538,9 @@ bool PixelShaderCache::InsertByteCode(const PixelShaderUid &uid, const void* byt
|
|||||||
|
|
||||||
// These are "callbacks" from VideoCommon and thus must be outside namespace DX11.
|
// These are "callbacks" from VideoCommon and thus must be outside namespace DX11.
|
||||||
// This will have to be changed when we merge.
|
// This will have to be changed when we merge.
|
||||||
|
|
||||||
// HACK to avoid some invasive VideoCommon changes
|
|
||||||
// these values are hardcoded, they depend on internal D3DCompile behavior; TODO: Solve this with D3DReflect or something
|
|
||||||
// offset given in floats, table index is float4
|
|
||||||
static const unsigned int ps_constant_offset_table[] = {
|
|
||||||
0, 4, 8, 12, // C_COLORS, 16
|
|
||||||
16, 20, 24, 28, // C_KCOLORS, 16
|
|
||||||
32, // C_ALPHA, 4
|
|
||||||
36, 40, 44, 48, 52, 56, 60, 64, // C_TEXDIMS, 32
|
|
||||||
68, 72, // C_ZBIAS, 8
|
|
||||||
76, 80, // C_INDTEXSCALE, 8
|
|
||||||
84, 88, 92, 96, 100, 104, // C_INDTEXMTX, 24
|
|
||||||
108, 112, 116, // C_FOG, 12
|
|
||||||
120, 124, 128, 132, 136, // C_PLIGHTS0, 20
|
|
||||||
140, 144, 148, 152, 156, // C_PLIGHTS1, 20
|
|
||||||
160, 164, 168, 172, 176, // C_PLIGHTS2, 20
|
|
||||||
180, 184, 188, 192, 196, // C_PLIGHTS3, 20
|
|
||||||
200, 204, 208, 212, 216, // C_PLIGHTS4, 20
|
|
||||||
220, 224, 228, 232, 236, // C_PLIGHTS5, 20
|
|
||||||
240, 244, 248, 252, 256, // C_PLIGHTS6, 20
|
|
||||||
260, 264, 268, 272, 276, // C_PLIGHTS7, 20
|
|
||||||
280, 284, 288, 292 // C_PMATERIALS, 16
|
|
||||||
};
|
|
||||||
void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
|
||||||
{
|
|
||||||
psconstants[ps_constant_offset_table[const_number] ] = f1;
|
|
||||||
psconstants[ps_constant_offset_table[const_number]+1] = f2;
|
|
||||||
psconstants[ps_constant_offset_table[const_number]+2] = f3;
|
|
||||||
psconstants[ps_constant_offset_table[const_number]+3] = f4;
|
|
||||||
pscbufchanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetPSConstant4fv(unsigned int const_number, const float* f)
|
|
||||||
{
|
|
||||||
memcpy(&psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4);
|
|
||||||
pscbufchanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float* f)
|
void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float* f)
|
||||||
{
|
{
|
||||||
memcpy(&psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4*count);
|
memcpy(psconstants, f, sizeof(float)*4*count);
|
||||||
pscbufchanged = true;
|
pscbufchanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,13 +52,7 @@ public:
|
|||||||
|
|
||||||
static bool CheckForResize();
|
static bool CheckForResize();
|
||||||
|
|
||||||
void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
|
|
||||||
void SetPSConstant4fv(unsigned int const_number, const float *f);
|
|
||||||
void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
|
|
||||||
void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
|
|
||||||
void SetVSConstant4fv(unsigned int const_number, const float *f);
|
|
||||||
void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f);
|
|
||||||
void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -280,32 +280,7 @@ bool VertexShaderCache::InsertByteCode(const VertexShaderUid &uid, D3DBlob* bcod
|
|||||||
// These are "callbacks" from VideoCommon and thus must be outside namespace DX11.
|
// These are "callbacks" from VideoCommon and thus must be outside namespace DX11.
|
||||||
// This will have to be changed when we merge.
|
// This will have to be changed when we merge.
|
||||||
|
|
||||||
// maps the constant numbers to float indices in the constant buffer
|
// TODO: fetch directly from VideoCommon
|
||||||
void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
|
||||||
{
|
|
||||||
vsconstants[vs_constant_offset_table[const_number] ] = f1;
|
|
||||||
vsconstants[vs_constant_offset_table[const_number]+1] = f2;
|
|
||||||
vsconstants[vs_constant_offset_table[const_number]+2] = f3;
|
|
||||||
vsconstants[vs_constant_offset_table[const_number]+3] = f4;
|
|
||||||
vscbufchanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetVSConstant4fv(unsigned int const_number, const float* f)
|
|
||||||
{
|
|
||||||
memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4);
|
|
||||||
vscbufchanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float* f)
|
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
memcpy(&vsconstants[vs_constant_offset_table[const_number+i]], f+3*i, sizeof(float)*3);
|
|
||||||
vsconstants[vs_constant_offset_table[const_number+i]+3] = 0.f;
|
|
||||||
}
|
|
||||||
vscbufchanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float* f)
|
void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float* f)
|
||||||
{
|
{
|
||||||
memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4*count);
|
memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4*count);
|
||||||
|
@ -24,66 +24,7 @@
|
|||||||
namespace OGL
|
namespace OGL
|
||||||
{
|
{
|
||||||
|
|
||||||
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
|
||||||
{
|
|
||||||
ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram();
|
|
||||||
for (int a = 0; a < NUM_UNIFORMS; ++a)
|
|
||||||
{
|
|
||||||
if (!strcmp(name, UniformNames[a]))
|
|
||||||
{
|
|
||||||
if (tmp.shader.UniformLocations[a] == -1)
|
|
||||||
return;
|
|
||||||
else if (tmp.shader.UniformSize[a] <= offset)
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unsigned int maxcount= tmp.shader.UniformSize[a]-offset;
|
|
||||||
glUniform4fv(tmp.shader.UniformLocations[a] + offset, std::min(count, maxcount), f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renderer functions
|
// Renderer functions
|
||||||
void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
|
||||||
{
|
|
||||||
float const f[4] = {f1, f2, f3, f4};
|
|
||||||
|
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
|
||||||
{
|
|
||||||
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (unsigned int a = 0; a < 10; ++a)
|
|
||||||
{
|
|
||||||
if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
|
||||||
{
|
|
||||||
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
|
||||||
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetPSConstant4fv(unsigned int const_number, const float *f)
|
|
||||||
{
|
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
|
||||||
{
|
|
||||||
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (unsigned int a = 0; a < 10; ++a)
|
|
||||||
{
|
|
||||||
if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
|
||||||
{
|
|
||||||
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
|
||||||
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
{
|
{
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
@ -91,14 +32,15 @@ void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int cou
|
|||||||
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, count);
|
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
for (unsigned int a = 0; a < 10; ++a)
|
for (unsigned int a = 0; a < 10; ++a)
|
||||||
{
|
{
|
||||||
if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
u32 offset = PSVar_Loc[a].reg - const_number;
|
||||||
{
|
if(offset >= count) return;
|
||||||
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
u32 size = std::min(tmp.shader.UniformSize[a], count-offset);
|
||||||
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count);
|
if(size > 0)
|
||||||
return;
|
glUniform4fv(tmp.shader.UniformLocations[a], size, f + 4*offset);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace OGL
|
} // namespace OGL
|
||||||
|
@ -81,13 +81,7 @@ public:
|
|||||||
|
|
||||||
bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc);
|
bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc);
|
||||||
|
|
||||||
void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
|
|
||||||
void SetPSConstant4fv(unsigned int const_number, const float *f);
|
|
||||||
void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
|
|
||||||
void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
|
|
||||||
void SetVSConstant4fv(unsigned int const_number, const float *f);
|
|
||||||
void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f);
|
|
||||||
void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -24,65 +24,6 @@
|
|||||||
namespace OGL
|
namespace OGL
|
||||||
{
|
{
|
||||||
|
|
||||||
void SetVSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
|
||||||
{
|
|
||||||
ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram();
|
|
||||||
for (int a = 0; a < NUM_UNIFORMS; ++a)
|
|
||||||
{
|
|
||||||
if (!strcmp(name, UniformNames[a]))
|
|
||||||
{
|
|
||||||
if (tmp.shader.UniformLocations[a] == -1)
|
|
||||||
return;
|
|
||||||
else if (tmp.shader.UniformSize[a] <= offset)
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unsigned int maxcount= tmp.shader.UniformSize[a]-offset;
|
|
||||||
glUniform4fv(tmp.shader.UniformLocations[a] + offset, std::min(count, maxcount), f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
|
||||||
{
|
|
||||||
float const buf[4] = {f1, f2, f3, f4};
|
|
||||||
|
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
|
||||||
{
|
|
||||||
ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (unsigned int a = 0; a < 9; ++a)
|
|
||||||
{
|
|
||||||
if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
|
||||||
{
|
|
||||||
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
|
||||||
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetVSConstant4fv(unsigned int const_number, const float *f)
|
|
||||||
{
|
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
|
||||||
{
|
|
||||||
ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (unsigned int a = 0; a < 9; ++a)
|
|
||||||
{
|
|
||||||
if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
|
||||||
{
|
|
||||||
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
|
||||||
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
{
|
{
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
@ -90,40 +31,14 @@ void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int cou
|
|||||||
ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, count);
|
ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ProgramShaderCache::PCacheEntry tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
for (unsigned int a = 0; a < 9; ++a)
|
for (unsigned int a = 0; a < 9; ++a)
|
||||||
{
|
{
|
||||||
if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
u32 offset = VSVar_Loc[a].reg - const_number;
|
||||||
{
|
if(offset >= count) return;
|
||||||
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
u32 size = std::min(tmp.shader.UniformSize[a+10], count-offset);
|
||||||
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count);
|
if(size > 0)
|
||||||
return;
|
glUniform4fv(tmp.shader.UniformLocations[a+10], size, f + 4*offset);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
|
|
||||||
{
|
|
||||||
float buf[4 * C_VENVCONST_END];
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
buf[4*i ] = *f++;
|
|
||||||
buf[4*i+1] = *f++;
|
|
||||||
buf[4*i+2] = *f++;
|
|
||||||
buf[4*i+3] = 0.f;
|
|
||||||
}
|
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
|
||||||
{
|
|
||||||
ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, count);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (unsigned int a = 0; a < 9; ++a)
|
|
||||||
{
|
|
||||||
if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
|
||||||
{
|
|
||||||
unsigned int offset = const_number - VSVar_Loc[a].reg;
|
|
||||||
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// Annoying sure, can be removed once we get up to GLSL ~1.3
|
||||||
const s_svar PSVar_Loc[] = { {I_COLORS, C_COLORS, 4 },
|
const s_svar PSVar_Loc[] = { {C_COLORS, 4 },
|
||||||
{I_KCOLORS, C_KCOLORS, 4 },
|
{C_KCOLORS, 4 },
|
||||||
{I_ALPHA, C_ALPHA, 1 },
|
{C_ALPHA, 1 },
|
||||||
{I_TEXDIMS, C_TEXDIMS, 8 },
|
{C_TEXDIMS, 8 },
|
||||||
{I_ZBIAS , C_ZBIAS, 2 },
|
{C_ZBIAS, 2 },
|
||||||
{I_INDTEXSCALE , C_INDTEXSCALE, 2 },
|
{C_INDTEXSCALE, 2 },
|
||||||
{I_INDTEXMTX, C_INDTEXMTX, 6 },
|
{C_INDTEXMTX, 6 },
|
||||||
{I_FOG, C_FOG, 3 },
|
{C_FOG, 3 },
|
||||||
{I_PLIGHTS, C_PLIGHTS, 40 },
|
{C_PLIGHTS, 40 },
|
||||||
{I_PMATERIALS, C_PMATERIALS, 4 },
|
{C_PMATERIALS, 4 },
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
@ -29,19 +29,40 @@ static u32 lastTexDims[8]; // width | height << 16 | wrap_s << 28 | wrap_t << 30
|
|||||||
static u32 lastZBias;
|
static u32 lastZBias;
|
||||||
static int nMaterialsChanged;
|
static int nMaterialsChanged;
|
||||||
|
|
||||||
|
PixelShaderConstants PixelShaderManager::constants;
|
||||||
|
bool PixelShaderManager::dirty;
|
||||||
|
|
||||||
inline void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
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)
|
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)
|
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()
|
void PixelShaderManager::Init()
|
||||||
@ -50,6 +71,7 @@ void PixelShaderManager::Init()
|
|||||||
memset(lastTexDims, 0, sizeof(lastTexDims));
|
memset(lastTexDims, 0, sizeof(lastTexDims));
|
||||||
lastZBias = 0;
|
lastZBias = 0;
|
||||||
memset(lastRGBAfull, 0, sizeof(lastRGBAfull));
|
memset(lastRGBAfull, 0, sizeof(lastRGBAfull));
|
||||||
|
memset(&constants, 0, sizeof(constants));
|
||||||
Dirty();
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +85,7 @@ void PixelShaderManager::Dirty()
|
|||||||
s_bFogRangeAdjustChanged = s_bFogColorChanged = s_bFogParamChanged = true;
|
s_bFogRangeAdjustChanged = s_bFogColorChanged = s_bFogParamChanged = true;
|
||||||
nLightsChanged[0] = 0; nLightsChanged[1] = 0x80;
|
nLightsChanged[0] = 0; nLightsChanged[1] = 0x80;
|
||||||
nMaterialsChanged = 15;
|
nMaterialsChanged = 15;
|
||||||
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelShaderManager::Shutdown()
|
void PixelShaderManager::Shutdown()
|
||||||
@ -73,8 +96,8 @@ void PixelShaderManager::Shutdown()
|
|||||||
void PixelShaderManager::SetConstants(u32 components)
|
void PixelShaderManager::SetConstants(u32 components)
|
||||||
{
|
{
|
||||||
if (g_ActiveConfig.backend_info.APIType == API_OPENGL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
if (g_ActiveConfig.backend_info.APIType == API_OPENGL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
Dirty();
|
dirty = true;
|
||||||
|
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
if (s_nColorsChanged[i])
|
if (s_nColorsChanged[i])
|
||||||
@ -335,6 +358,12 @@ void PixelShaderManager::SetConstants(u32 components)
|
|||||||
nMaterialsChanged = 0;
|
nMaterialsChanged = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(dirty)
|
||||||
|
{
|
||||||
|
g_renderer->SetMultiPSConstant4fv(0, sizeof(constants)/16, (float*) &constants);
|
||||||
|
dirty = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelShaderManager::SetPSTextureDims(int texid)
|
void PixelShaderManager::SetPSTextureDims(int texid)
|
||||||
@ -495,7 +524,9 @@ void PixelShaderManager::DoState(PointerWrap &p)
|
|||||||
p.Do(lastAlpha);
|
p.Do(lastAlpha);
|
||||||
p.Do(lastTexDims);
|
p.Do(lastTexDims);
|
||||||
p.Do(lastZBias);
|
p.Do(lastZBias);
|
||||||
|
p.Do(constants);
|
||||||
|
p.Do(dirty);
|
||||||
|
|
||||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||||
{
|
{
|
||||||
Dirty();
|
Dirty();
|
||||||
|
@ -8,9 +8,12 @@
|
|||||||
#include "BPMemory.h"
|
#include "BPMemory.h"
|
||||||
#include "XFMemory.h"
|
#include "XFMemory.h"
|
||||||
#include "PixelShaderGen.h"
|
#include "PixelShaderGen.h"
|
||||||
|
#include "ConstantManager.h"
|
||||||
|
|
||||||
class PointerWrap;
|
class PointerWrap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The non-API dependent parts.
|
// The non-API dependent parts.
|
||||||
class PixelShaderManager
|
class PixelShaderManager
|
||||||
{
|
{
|
||||||
@ -41,6 +44,9 @@ public:
|
|||||||
static void SetColorMatrix(const float* pmatrix);
|
static void SetColorMatrix(const float* pmatrix);
|
||||||
static void InvalidateXFRange(int start, int end);
|
static void InvalidateXFRange(int start, int end);
|
||||||
static void SetMaterialColorChanged(int index);
|
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; }
|
static void StorePixelFormat(unsigned int new_format) { prev_efb_format = new_format; }
|
||||||
|
|
||||||
// TODO: doesn't belong here
|
// 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;
|
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;
|
virtual void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -867,10 +867,4 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
|
|||||||
return text;
|
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
|
} // namespace
|
||||||
|
@ -15,8 +15,6 @@ u16 GetEncodedSampleCount(u32 format);
|
|||||||
|
|
||||||
const char *GenerateEncodingShader(u32 format, API_TYPE ApiType = API_OPENGL);
|
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_
|
#endif // _TEXTURECONVERSIONSHADER_H_
|
||||||
|
@ -53,15 +53,15 @@
|
|||||||
#define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64)
|
#define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64)
|
||||||
#define C_VENVCONST_END (C_DEPTHPARAMS + 1)
|
#define C_VENVCONST_END (C_DEPTHPARAMS + 1)
|
||||||
|
|
||||||
const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
|
const s_svar VSVar_Loc[] = { {C_POSNORMALMATRIX, 6 },
|
||||||
{I_PROJECTION , C_PROJECTION, 4 },
|
{C_PROJECTION, 4 },
|
||||||
{I_MATERIALS, C_MATERIALS, 4 },
|
{C_MATERIALS, 4 },
|
||||||
{I_LIGHTS, C_LIGHTS, 40 },
|
{C_LIGHTS, 40 },
|
||||||
{I_TEXMATRICES, C_TEXMATRICES, 24 },
|
{C_TEXMATRICES, 24 },
|
||||||
{I_TRANSFORMMATRICES , C_TRANSFORMMATRICES, 64 },
|
{C_TRANSFORMMATRICES, 64 },
|
||||||
{I_NORMALMATRICES , C_NORMALMATRICES, 32 },
|
{C_NORMALMATRICES, 32 },
|
||||||
{I_POSTTRANSFORMMATRICES, C_POSTTRANSFORMMATRICES, 64 },
|
{C_POSTTRANSFORMMATRICES, 64 },
|
||||||
{I_DEPTHPARAMS, C_DEPTHPARAMS, 1 },
|
{C_DEPTHPARAMS, 1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
@ -36,6 +36,9 @@ static Matrix33 s_viewInvRotationMatrix;
|
|||||||
static float s_fViewTranslationVector[3];
|
static float s_fViewTranslationVector[3];
|
||||||
static float s_fViewRotation[2];
|
static float s_fViewRotation[2];
|
||||||
|
|
||||||
|
VertexShaderConstants VertexShaderManager::constants;
|
||||||
|
bool VertexShaderManager::dirty;
|
||||||
|
|
||||||
void UpdateViewport(Matrix44& vpCorrection);
|
void UpdateViewport(Matrix44& vpCorrection);
|
||||||
|
|
||||||
void UpdateViewportWithCorrection()
|
void UpdateViewportWithCorrection()
|
||||||
@ -45,22 +48,48 @@ void UpdateViewportWithCorrection()
|
|||||||
|
|
||||||
inline void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
|
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)
|
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)
|
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)
|
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
|
struct ProjectionHack
|
||||||
@ -153,6 +182,7 @@ void VertexShaderManager::Init()
|
|||||||
|
|
||||||
memset(&xfregs, 0, sizeof(xfregs));
|
memset(&xfregs, 0, sizeof(xfregs));
|
||||||
memset(xfmem, 0, sizeof(xfmem));
|
memset(xfmem, 0, sizeof(xfmem));
|
||||||
|
memset(&constants, 0 , sizeof(constants));
|
||||||
ResetView();
|
ResetView();
|
||||||
|
|
||||||
// TODO: should these go inside ResetView()?
|
// TODO: should these go inside ResetView()?
|
||||||
@ -187,6 +217,8 @@ void VertexShaderManager::Dirty()
|
|||||||
bProjectionChanged = true;
|
bProjectionChanged = true;
|
||||||
|
|
||||||
nMaterialsChanged = 15;
|
nMaterialsChanged = 15;
|
||||||
|
|
||||||
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Syncs the shader constant buffers with xfmem
|
// Syncs the shader constant buffers with xfmem
|
||||||
@ -194,7 +226,7 @@ void VertexShaderManager::Dirty()
|
|||||||
void VertexShaderManager::SetConstants()
|
void VertexShaderManager::SetConstants()
|
||||||
{
|
{
|
||||||
if (g_ActiveConfig.backend_info.APIType == API_OPENGL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
if (g_ActiveConfig.backend_info.APIType == API_OPENGL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
Dirty();
|
dirty = true;
|
||||||
|
|
||||||
if (nTransformMatricesChanged[0] >= 0)
|
if (nTransformMatricesChanged[0] >= 0)
|
||||||
{
|
{
|
||||||
@ -488,6 +520,12 @@ void VertexShaderManager::SetConstants()
|
|||||||
SetMultiVSConstant4fv(C_PROJECTION, 4, correctedMtx.data);
|
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)
|
void VertexShaderManager::InvalidateXFRange(int start, int end)
|
||||||
@ -669,6 +707,8 @@ void VertexShaderManager::DoState(PointerWrap &p)
|
|||||||
p.Do(s_viewInvRotationMatrix);
|
p.Do(s_viewInvRotationMatrix);
|
||||||
p.Do(s_fViewTranslationVector);
|
p.Do(s_fViewTranslationVector);
|
||||||
p.Do(s_fViewRotation);
|
p.Do(s_fViewRotation);
|
||||||
|
p.Do(constants);
|
||||||
|
p.Do(dirty);
|
||||||
|
|
||||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#define _VERTEXSHADERMANAGER_H
|
#define _VERTEXSHADERMANAGER_H
|
||||||
|
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
|
#include "ConstantManager.h"
|
||||||
|
|
||||||
class PointerWrap;
|
class PointerWrap;
|
||||||
|
|
||||||
@ -35,6 +36,9 @@ public:
|
|||||||
static void TranslateView(float x, float y, float z = 0.0f);
|
static void TranslateView(float x, float y, float z = 0.0f);
|
||||||
static void RotateView(float x, float y);
|
static void RotateView(float x, float y);
|
||||||
static void ResetView();
|
static void ResetView();
|
||||||
|
|
||||||
|
static VertexShaderConstants constants;
|
||||||
|
static bool dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _VERTEXSHADERMANAGER_H
|
#endif // _VERTEXSHADERMANAGER_H
|
||||||
|
@ -134,7 +134,6 @@ inline unsigned int GetPow2(unsigned int val)
|
|||||||
}
|
}
|
||||||
struct s_svar
|
struct s_svar
|
||||||
{
|
{
|
||||||
const char *name;
|
|
||||||
const unsigned int reg;
|
const unsigned int reg;
|
||||||
const unsigned int size;
|
const unsigned int size;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user