Merge pull request #5989 from lioncash/constantmgr
ConstantManager: Use std::array where applicable
This commit is contained in:
commit
edf4bfaf5f
|
@ -4,42 +4,44 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
// all constant buffer attributes must be 16 bytes aligned, so this are the only allowed components:
|
// all constant buffer attributes must be 16 bytes aligned, so this are the only allowed components:
|
||||||
typedef float float4[4];
|
using float4 = std::array<float, 4>;
|
||||||
typedef u32 uint4[4];
|
using uint4 = std::array<u32, 4>;
|
||||||
typedef s32 int4[4];
|
using int4 = std::array<s32, 4>;
|
||||||
|
|
||||||
struct PixelShaderConstants
|
struct PixelShaderConstants
|
||||||
{
|
{
|
||||||
int4 colors[4];
|
std::array<int4, 4> colors;
|
||||||
int4 kcolors[4];
|
std::array<int4, 4> kcolors;
|
||||||
int4 alpha;
|
int4 alpha;
|
||||||
float4 texdims[8];
|
std::array<float4, 8> texdims;
|
||||||
int4 zbias[2];
|
std::array<int4, 2> zbias;
|
||||||
int4 indtexscale[2];
|
std::array<int4, 2> indtexscale;
|
||||||
int4 indtexmtx[6];
|
std::array<int4, 6> indtexmtx;
|
||||||
int4 fogcolor;
|
int4 fogcolor;
|
||||||
int4 fogi;
|
int4 fogi;
|
||||||
float4 fogf[2];
|
std::array<float4, 2> fogf;
|
||||||
float4 zslope;
|
float4 zslope;
|
||||||
float efbscale[2];
|
std::array<float, 2> efbscale;
|
||||||
|
|
||||||
// Constants from here onwards are only used in ubershaders.
|
// Constants from here onwards are only used in ubershaders.
|
||||||
u32 genmode; // .z
|
u32 genmode; // .z
|
||||||
u32 alphaTest; // .w
|
u32 alphaTest; // .w
|
||||||
u32 fogParam3; // .x
|
u32 fogParam3; // .x
|
||||||
u32 fogRangeBase; // .y
|
u32 fogRangeBase; // .y
|
||||||
u32 dstalpha; // .z
|
u32 dstalpha; // .z
|
||||||
u32 ztex_op; // .w
|
u32 ztex_op; // .w
|
||||||
u32 late_ztest; // .x (bool)
|
u32 late_ztest; // .x (bool)
|
||||||
u32 rgba6_format; // .y (bool)
|
u32 rgba6_format; // .y (bool)
|
||||||
u32 dither; // .z (bool)
|
u32 dither; // .z (bool)
|
||||||
u32 bounding_box; // .w (bool)
|
u32 bounding_box; // .w (bool)
|
||||||
uint4 pack1[16]; // .xy - combiners, .z - tevind, .w - iref
|
std::array<uint4, 16> pack1; // .xy - combiners, .z - tevind, .w - iref
|
||||||
uint4 pack2[8]; // .x - tevorder, .y - tevksel
|
std::array<uint4, 8> pack2; // .x - tevorder, .y - tevksel
|
||||||
int4 konst[32]; // .rgba
|
std::array<int4, 32> konst; // .rgba
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexShaderConstants
|
struct VertexShaderConstants
|
||||||
|
@ -49,9 +51,9 @@ struct VertexShaderConstants
|
||||||
u32 xfmem_numColorChans; // .z
|
u32 xfmem_numColorChans; // .z
|
||||||
u32 pad1; // .w
|
u32 pad1; // .w
|
||||||
|
|
||||||
float4 posnormalmatrix[6];
|
std::array<float4, 6> posnormalmatrix;
|
||||||
float4 projection[4];
|
std::array<float4, 4> projection;
|
||||||
int4 materials[4];
|
std::array<int4, 4> materials;
|
||||||
struct Light
|
struct Light
|
||||||
{
|
{
|
||||||
int4 color;
|
int4 color;
|
||||||
|
@ -59,16 +61,18 @@ struct VertexShaderConstants
|
||||||
float4 distatt;
|
float4 distatt;
|
||||||
float4 pos;
|
float4 pos;
|
||||||
float4 dir;
|
float4 dir;
|
||||||
} lights[8];
|
};
|
||||||
float4 texmatrices[24];
|
std::array<Light, 8> lights;
|
||||||
float4 transformmatrices[64];
|
std::array<float4, 24> texmatrices;
|
||||||
float4 normalmatrices[32];
|
std::array<float4, 64> transformmatrices;
|
||||||
float4 posttransformmatrices[64];
|
std::array<float4, 32> normalmatrices;
|
||||||
|
std::array<float4, 64> posttransformmatrices;
|
||||||
float4 pixelcentercorrection;
|
float4 pixelcentercorrection;
|
||||||
float viewport[2]; // .xy
|
std::array<float, 2> viewport; // .xy
|
||||||
float pad2[2]; // .zw
|
std::array<float, 2> pad2; // .zw
|
||||||
|
|
||||||
uint4 xfmem_pack1[8]; // .x - texMtxInfo, .y - postMtxInfo, [0..1].z = color, [0..1].w = alpha
|
// .x - texMtxInfo, .y - postMtxInfo, [0..1].z = color, [0..1].w = alpha
|
||||||
|
std::array<uint4, 8> xfmem_pack1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GeometryShaderConstants
|
struct GeometryShaderConstants
|
||||||
|
|
|
@ -227,7 +227,7 @@ void VertexShaderManager::SetConstants()
|
||||||
{
|
{
|
||||||
int startn = nTransformMatricesChanged[0] / 4;
|
int startn = nTransformMatricesChanged[0] / 4;
|
||||||
int endn = (nTransformMatricesChanged[1] + 3) / 4;
|
int endn = (nTransformMatricesChanged[1] + 3) / 4;
|
||||||
memcpy(constants.transformmatrices[startn], &xfmem.posMatrices[startn * 4],
|
memcpy(constants.transformmatrices[startn].data(), &xfmem.posMatrices[startn * 4],
|
||||||
(endn - startn) * sizeof(float4));
|
(endn - startn) * sizeof(float4));
|
||||||
dirty = true;
|
dirty = true;
|
||||||
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
|
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
|
||||||
|
@ -239,7 +239,7 @@ void VertexShaderManager::SetConstants()
|
||||||
int endn = (nNormalMatricesChanged[1] + 2) / 3;
|
int endn = (nNormalMatricesChanged[1] + 2) / 3;
|
||||||
for (int i = startn; i < endn; i++)
|
for (int i = startn; i < endn; i++)
|
||||||
{
|
{
|
||||||
memcpy(constants.normalmatrices[i], &xfmem.normalMatrices[3 * i], 12);
|
memcpy(constants.normalmatrices[i].data(), &xfmem.normalMatrices[3 * i], 12);
|
||||||
}
|
}
|
||||||
dirty = true;
|
dirty = true;
|
||||||
nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
|
nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
|
||||||
|
@ -249,7 +249,7 @@ void VertexShaderManager::SetConstants()
|
||||||
{
|
{
|
||||||
int startn = nPostTransformMatricesChanged[0] / 4;
|
int startn = nPostTransformMatricesChanged[0] / 4;
|
||||||
int endn = (nPostTransformMatricesChanged[1] + 3) / 4;
|
int endn = (nPostTransformMatricesChanged[1] + 3) / 4;
|
||||||
memcpy(constants.posttransformmatrices[startn], &xfmem.postMatrices[startn * 4],
|
memcpy(constants.posttransformmatrices[startn].data(), &xfmem.postMatrices[startn * 4],
|
||||||
(endn - startn) * sizeof(float4));
|
(endn - startn) * sizeof(float4));
|
||||||
dirty = true;
|
dirty = true;
|
||||||
nPostTransformMatricesChanged[0] = nPostTransformMatricesChanged[1] = -1;
|
nPostTransformMatricesChanged[0] = nPostTransformMatricesChanged[1] = -1;
|
||||||
|
@ -327,10 +327,10 @@ void VertexShaderManager::SetConstants()
|
||||||
const float* norm =
|
const float* norm =
|
||||||
&xfmem.normalMatrices[3 * (g_main_cp_state.matrix_index_a.PosNormalMtxIdx & 31)];
|
&xfmem.normalMatrices[3 * (g_main_cp_state.matrix_index_a.PosNormalMtxIdx & 31)];
|
||||||
|
|
||||||
memcpy(constants.posnormalmatrix, pos, 3 * sizeof(float4));
|
memcpy(constants.posnormalmatrix.data(), pos, 3 * sizeof(float4));
|
||||||
memcpy(constants.posnormalmatrix[3], norm, 3 * sizeof(float));
|
memcpy(constants.posnormalmatrix[3].data(), norm, 3 * sizeof(float));
|
||||||
memcpy(constants.posnormalmatrix[4], norm + 3, 3 * sizeof(float));
|
memcpy(constants.posnormalmatrix[4].data(), norm + 3, 3 * sizeof(float));
|
||||||
memcpy(constants.posnormalmatrix[5], norm + 6, 3 * sizeof(float));
|
memcpy(constants.posnormalmatrix[5].data(), norm + 6, 3 * sizeof(float));
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,7 +345,7 @@ void VertexShaderManager::SetConstants()
|
||||||
|
|
||||||
for (size_t i = 0; i < ArraySize(pos_matrix_ptrs); ++i)
|
for (size_t i = 0; i < ArraySize(pos_matrix_ptrs); ++i)
|
||||||
{
|
{
|
||||||
memcpy(constants.texmatrices[3 * i], pos_matrix_ptrs[i], 3 * sizeof(float4));
|
memcpy(constants.texmatrices[3 * i].data(), pos_matrix_ptrs[i], 3 * sizeof(float4));
|
||||||
}
|
}
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ void VertexShaderManager::SetConstants()
|
||||||
|
|
||||||
for (size_t i = 0; i < ArraySize(pos_matrix_ptrs); ++i)
|
for (size_t i = 0; i < ArraySize(pos_matrix_ptrs); ++i)
|
||||||
{
|
{
|
||||||
memcpy(constants.texmatrices[3 * i + 12], pos_matrix_ptrs[i], 3 * sizeof(float4));
|
memcpy(constants.texmatrices[3 * i + 12].data(), pos_matrix_ptrs[i], 3 * sizeof(float4));
|
||||||
}
|
}
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -549,7 +549,7 @@ void VertexShaderManager::SetConstants()
|
||||||
Matrix44::Set(mtxB, g_fProjectionMatrix);
|
Matrix44::Set(mtxB, g_fProjectionMatrix);
|
||||||
Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view
|
Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view
|
||||||
Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA
|
Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA
|
||||||
memcpy(constants.projection, mtxB.data, 4 * sizeof(float4));
|
memcpy(constants.projection.data(), mtxB.data, 4 * sizeof(float4));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -558,7 +558,7 @@ void VertexShaderManager::SetConstants()
|
||||||
|
|
||||||
Matrix44 correctedMtx;
|
Matrix44 correctedMtx;
|
||||||
Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx);
|
Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx);
|
||||||
memcpy(constants.projection, correctedMtx.data, 4 * sizeof(float4));
|
memcpy(constants.projection.data(), correctedMtx.data, 4 * sizeof(float4));
|
||||||
}
|
}
|
||||||
|
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
|
Loading…
Reference in New Issue