swr: [rasterizer core] viewport array support

Change viewport matrix storage from AOS to SOA to support viewport arrays.

Signed-off-by: Tim Rowley <timothy.o.rowley@intel.com>
This commit is contained in:
Tim Rowley
2016-08-05 16:42:24 -06:00
parent d86e2487a0
commit ad153189ec
8 changed files with 49 additions and 34 deletions
+16 -14
View File
@@ -663,7 +663,7 @@ void SwrSetViewports(
HANDLE hContext,
uint32_t numViewports,
const SWR_VIEWPORT* pViewports,
const SWR_VIEWPORT_MATRIX* pMatrices)
const SWR_VIEWPORT_MATRICES* pMatrices)
{
SWR_ASSERT(numViewports <= KNOB_NUM_VIEWPORTS_SCISSORS,
"Invalid number of viewports.");
@@ -675,7 +675,9 @@ void SwrSetViewports(
if (pMatrices != nullptr)
{
memcpy(&pState->vpMatrix[0], pMatrices, sizeof(SWR_VIEWPORT_MATRIX) * numViewports);
//memcpy(&pState->vpMatrix[0], pMatrices, sizeof(SWR_VIEWPORT_MATRIX) * numViewports);
// @todo Faster to copy portions of the SOA or just copy all of it?
memcpy(&pState->vpMatrices, pMatrices, sizeof(SWR_VIEWPORT_MATRICES));
}
else
{
@@ -684,22 +686,22 @@ void SwrSetViewports(
{
if (pContext->driverType == DX)
{
pState->vpMatrix[i].m00 = pState->vp[i].width / 2.0f;
pState->vpMatrix[i].m11 = -pState->vp[i].height / 2.0f;
pState->vpMatrix[i].m22 = pState->vp[i].maxZ - pState->vp[i].minZ;
pState->vpMatrix[i].m30 = pState->vp[i].x + pState->vpMatrix[i].m00;
pState->vpMatrix[i].m31 = pState->vp[i].y - pState->vpMatrix[i].m11;
pState->vpMatrix[i].m32 = pState->vp[i].minZ;
pState->vpMatrices.m00[i] = pState->vp[i].width / 2.0f;
pState->vpMatrices.m11[i] = -pState->vp[i].height / 2.0f;
pState->vpMatrices.m22[i] = pState->vp[i].maxZ - pState->vp[i].minZ;
pState->vpMatrices.m30[i] = pState->vp[i].x + pState->vpMatrices.m00[i];
pState->vpMatrices.m31[i] = pState->vp[i].y - pState->vpMatrices.m11[i];
pState->vpMatrices.m32[i] = pState->vp[i].minZ;
}
else
{
// Standard, with the exception that Y is inverted.
pState->vpMatrix[i].m00 = (pState->vp[i].width - pState->vp[i].x) / 2.0f;
pState->vpMatrix[i].m11 = (pState->vp[i].y - pState->vp[i].height) / 2.0f;
pState->vpMatrix[i].m22 = (pState->vp[i].maxZ - pState->vp[i].minZ) / 2.0f;
pState->vpMatrix[i].m30 = pState->vp[i].x + pState->vpMatrix[i].m00;
pState->vpMatrix[i].m31 = pState->vp[i].height + pState->vpMatrix[i].m11;
pState->vpMatrix[i].m32 = pState->vp[i].minZ + pState->vpMatrix[i].m22;
pState->vpMatrices.m00[i] = (pState->vp[i].width - pState->vp[i].x) / 2.0f;
pState->vpMatrices.m11[i] = (pState->vp[i].y - pState->vp[i].height) / 2.0f;
pState->vpMatrices.m22[i] = (pState->vp[i].maxZ - pState->vp[i].minZ) / 2.0f;
pState->vpMatrices.m30[i] = pState->vp[i].x + pState->vpMatrices.m00[i];
pState->vpMatrices.m31[i] = pState->vp[i].height + pState->vpMatrices.m11[i];
pState->vpMatrices.m32[i] = pState->vp[i].minZ + pState->vpMatrices.m22[i];
// Now that the matrix is calculated, clip the view coords to screen size.
// OpenGL allows for -ve x,y in the viewport.
@@ -495,7 +495,7 @@ void SWR_API SwrSetViewports(
HANDLE hContext,
uint32_t numViewports,
const SWR_VIEWPORT* pViewports,
const SWR_VIEWPORT_MATRIX* pMatrices);
const SWR_VIEWPORT_MATRICES* pMatrices);
//////////////////////////////////////////////////////////////////////////
/// @brief SwrSetScissorRects
@@ -277,7 +277,7 @@ OSALIGNLINE(struct) API_STATE
GUARDBAND gbState;
SWR_VIEWPORT vp[KNOB_NUM_VIEWPORTS_SCISSORS];
SWR_VIEWPORT_MATRIX vpMatrix[KNOB_NUM_VIEWPORTS_SCISSORS];
SWR_VIEWPORT_MATRICES vpMatrices;
BBOX scissorRects[KNOB_NUM_VIEWPORTS_SCISSORS];
BBOX scissorInFixedPoint;
@@ -1793,7 +1793,7 @@ void BinTriangles(
tri[2].v[2] = _simd_mul_ps(tri[2].v[2], vRecipW2);
// viewport transform to screen coords
viewportTransform<3>(tri, state.vpMatrix[0]);
viewportTransform<3>(tri, state.vpMatrices);
}
// adjust for pixel center location
@@ -2166,7 +2166,7 @@ void BinPoints(
primVerts.z = _simd_mul_ps(primVerts.z, vRecipW0);
// viewport transform to screen coords
viewportTransform<1>(&primVerts, state.vpMatrix[0]);
viewportTransform<1>(&primVerts, state.vpMatrices);
}
// adjust for pixel center location
@@ -2484,7 +2484,7 @@ void BinLines(
prim[1].v[2] = _simd_mul_ps(prim[1].v[2], vRecipW1);
// viewport transform to screen coords
viewportTransform<2>(prim, state.vpMatrix[0]);
viewportTransform<2>(prim, state.vpMatrices);
}
// adjust for pixel center location
@@ -202,14 +202,14 @@ void viewportTransform(__m128 &vX, __m128 &vY, __m128 &vZ, const SWR_VIEWPORT_MA
template<uint32_t NumVerts>
INLINE
void viewportTransform(simdvector *v, const SWR_VIEWPORT_MATRIX & vpMatrix)
void viewportTransform(simdvector *v, const SWR_VIEWPORT_MATRICES & vpMatrices)
{
simdscalar m00 = _simd_load1_ps(&vpMatrix.m00);
simdscalar m30 = _simd_load1_ps(&vpMatrix.m30);
simdscalar m11 = _simd_load1_ps(&vpMatrix.m11);
simdscalar m31 = _simd_load1_ps(&vpMatrix.m31);
simdscalar m22 = _simd_load1_ps(&vpMatrix.m22);
simdscalar m32 = _simd_load1_ps(&vpMatrix.m32);
simdscalar m00 = _simd_load1_ps(&vpMatrices.m00[0]);
simdscalar m30 = _simd_load1_ps(&vpMatrices.m30[0]);
simdscalar m11 = _simd_load1_ps(&vpMatrices.m11[0]);
simdscalar m31 = _simd_load1_ps(&vpMatrices.m31[0]);
simdscalar m22 = _simd_load1_ps(&vpMatrices.m22[0]);
simdscalar m32 = _simd_load1_ps(&vpMatrices.m32[0]);
for (uint32_t i = 0; i < NumVerts; ++i)
{
@@ -833,6 +833,19 @@ struct SWR_VIEWPORT_MATRIX
float m32;
};
//////////////////////////////////////////////////////////////////////////
/// VIEWPORT_MATRIXES
/////////////////////////////////////////////////////////////////////////
struct SWR_VIEWPORT_MATRICES
{
float m00[KNOB_NUM_VIEWPORTS_SCISSORS];
float m11[KNOB_NUM_VIEWPORTS_SCISSORS];
float m22[KNOB_NUM_VIEWPORTS_SCISSORS];
float m30[KNOB_NUM_VIEWPORTS_SCISSORS];
float m31[KNOB_NUM_VIEWPORTS_SCISSORS];
float m32[KNOB_NUM_VIEWPORTS_SCISSORS];
};
//////////////////////////////////////////////////////////////////////////
/// SWR_VIEWPORT
/////////////////////////////////////////////////////////////////////////
+7 -7
View File
@@ -944,7 +944,7 @@ swr_update_derived(struct pipe_context *pipe,
pipe_rasterizer_state *rasterizer = ctx->rasterizer;
SWR_VIEWPORT *vp = &ctx->derived.vp;
SWR_VIEWPORT_MATRIX *vpm = &ctx->derived.vpm;
SWR_VIEWPORT_MATRICES *vpm = &ctx->derived.vpm;
vp->x = state->translate[0] - state->scale[0];
vp->width = state->translate[0] + state->scale[0];
@@ -958,12 +958,12 @@ swr_update_derived(struct pipe_context *pipe,
vp->maxZ = state->translate[2] + state->scale[2];
}
vpm->m00 = state->scale[0];
vpm->m11 = state->scale[1];
vpm->m22 = state->scale[2];
vpm->m30 = state->translate[0];
vpm->m31 = state->translate[1];
vpm->m32 = state->translate[2];
vpm->m00[0] = state->scale[0];
vpm->m11[0] = state->scale[1];
vpm->m22[0] = state->scale[2];
vpm->m30[0] = state->translate[0];
vpm->m31[0] = state->translate[1];
vpm->m32[0] = state->translate[2];
/* Now that the matrix is calculated, clip the view coords to screen
* size. OpenGL allows for -ve x,y in the viewport. */
+1 -1
View File
@@ -87,7 +87,7 @@ struct swr_blend_state {
struct swr_derived_state {
SWR_RASTSTATE rastState;
SWR_VIEWPORT vp;
SWR_VIEWPORT_MATRIX vpm;
SWR_VIEWPORT_MATRICES vpm;
};
void swr_update_derived(struct pipe_context *,