swr: [rasterizer core] allow an OpenGL driver to specify halfz clipping
With ARB_clip_control, GL may also do 0..1 depth clipping, not just -1..1. This removes clip's reliance on driver type. DX users will need to be updated to set the new clipHalfZ flag to get proper clipping functionality. Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu> Reviewed-by: Tim Rowley <timothy.o.rowley@intel.com>
This commit is contained in:
parent
4af25e7131
commit
4b5b87e7ab
|
@ -63,7 +63,7 @@ void Clip(const float *pTriangle, const float *pAttribs, int numAttribs, float *
|
||||||
int *numVerts, float *pOutAttribs);
|
int *numVerts, float *pOutAttribs);
|
||||||
|
|
||||||
INLINE
|
INLINE
|
||||||
void ComputeClipCodes(DRIVER_TYPE type, const API_STATE& state, const simdvector& vertex, simdscalar& clipCodes, simdscalari viewportIndexes)
|
void ComputeClipCodes(const API_STATE& state, const simdvector& vertex, simdscalar& clipCodes, simdscalari viewportIndexes)
|
||||||
{
|
{
|
||||||
clipCodes = _simd_setzero_ps();
|
clipCodes = _simd_setzero_ps();
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ void ComputeClipCodes(DRIVER_TYPE type, const API_STATE& state, const simdvector
|
||||||
{
|
{
|
||||||
// FRUSTUM_NEAR
|
// FRUSTUM_NEAR
|
||||||
// DX clips depth [0..w], GL clips [-w..w]
|
// DX clips depth [0..w], GL clips [-w..w]
|
||||||
if (type == DX)
|
if (state.rastState.clipHalfZ)
|
||||||
{
|
{
|
||||||
vRes = _simd_cmplt_ps(vertex.z, _simd_setzero_ps());
|
vRes = _simd_cmplt_ps(vertex.z, _simd_setzero_ps());
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ class Clipper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Clipper(uint32_t in_workerId, DRAW_CONTEXT* in_pDC) :
|
Clipper(uint32_t in_workerId, DRAW_CONTEXT* in_pDC) :
|
||||||
workerId(in_workerId), driverType(in_pDC->pContext->driverType), pDC(in_pDC), state(GetApiState(in_pDC))
|
workerId(in_workerId), pDC(in_pDC), state(GetApiState(in_pDC))
|
||||||
{
|
{
|
||||||
static_assert(NumVertsPerPrim >= 1 && NumVertsPerPrim <= 3, "Invalid NumVertsPerPrim");
|
static_assert(NumVertsPerPrim >= 1 && NumVertsPerPrim <= 3, "Invalid NumVertsPerPrim");
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ public:
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < NumVertsPerPrim; ++i)
|
for (uint32_t i = 0; i < NumVertsPerPrim; ++i)
|
||||||
{
|
{
|
||||||
::ComputeClipCodes(this->driverType, this->state, vertex[i], this->clipCodes[i], viewportIndexes);
|
::ComputeClipCodes(this->state, vertex[i], this->clipCodes[i], viewportIndexes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,7 +640,7 @@ private:
|
||||||
case FRUSTUM_BOTTOM: t = ComputeInterpFactor(_simd_sub_ps(v1[3], v1[1]), _simd_sub_ps(v2[3], v2[1])); break;
|
case FRUSTUM_BOTTOM: t = ComputeInterpFactor(_simd_sub_ps(v1[3], v1[1]), _simd_sub_ps(v2[3], v2[1])); break;
|
||||||
case FRUSTUM_NEAR:
|
case FRUSTUM_NEAR:
|
||||||
// DX Znear plane is 0, GL is -w
|
// DX Znear plane is 0, GL is -w
|
||||||
if (this->driverType == DX)
|
if (this->state.rastState.clipHalfZ)
|
||||||
{
|
{
|
||||||
t = ComputeInterpFactor(v1[2], v2[2]);
|
t = ComputeInterpFactor(v1[2], v2[2]);
|
||||||
}
|
}
|
||||||
|
@ -708,7 +708,7 @@ private:
|
||||||
case FRUSTUM_RIGHT: return _simd_cmple_ps(v[0], v[3]);
|
case FRUSTUM_RIGHT: return _simd_cmple_ps(v[0], v[3]);
|
||||||
case FRUSTUM_TOP: return _simd_cmpge_ps(v[1], _simd_mul_ps(v[3], _simd_set1_ps(-1.0f)));
|
case FRUSTUM_TOP: return _simd_cmpge_ps(v[1], _simd_mul_ps(v[3], _simd_set1_ps(-1.0f)));
|
||||||
case FRUSTUM_BOTTOM: return _simd_cmple_ps(v[1], v[3]);
|
case FRUSTUM_BOTTOM: return _simd_cmple_ps(v[1], v[3]);
|
||||||
case FRUSTUM_NEAR: return _simd_cmpge_ps(v[2], this->driverType == DX ? _simd_setzero_ps() : _simd_mul_ps(v[3], _simd_set1_ps(-1.0f)));
|
case FRUSTUM_NEAR: return _simd_cmpge_ps(v[2], this->state.rastState.clipHalfZ ? _simd_setzero_ps() : _simd_mul_ps(v[3], _simd_set1_ps(-1.0f)));
|
||||||
case FRUSTUM_FAR: return _simd_cmple_ps(v[2], v[3]);
|
case FRUSTUM_FAR: return _simd_cmple_ps(v[2], v[3]);
|
||||||
default:
|
default:
|
||||||
SWR_ASSERT(false, "invalid clipping plane: %d", ClippingPlane);
|
SWR_ASSERT(false, "invalid clipping plane: %d", ClippingPlane);
|
||||||
|
@ -942,7 +942,6 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t workerId{ 0 };
|
const uint32_t workerId{ 0 };
|
||||||
const DRIVER_TYPE driverType{ DX };
|
|
||||||
DRAW_CONTEXT* pDC{ nullptr };
|
DRAW_CONTEXT* pDC{ nullptr };
|
||||||
const API_STATE& state;
|
const API_STATE& state;
|
||||||
simdscalar clipCodes[NumVertsPerPrim];
|
simdscalar clipCodes[NumVertsPerPrim];
|
||||||
|
|
|
@ -932,6 +932,7 @@ struct SWR_RASTSTATE
|
||||||
uint32_t frontWinding : 1;
|
uint32_t frontWinding : 1;
|
||||||
uint32_t scissorEnable : 1;
|
uint32_t scissorEnable : 1;
|
||||||
uint32_t depthClipEnable : 1;
|
uint32_t depthClipEnable : 1;
|
||||||
|
uint32_t clipHalfZ : 1;
|
||||||
uint32_t pointParam : 1;
|
uint32_t pointParam : 1;
|
||||||
uint32_t pointSpriteEnable : 1;
|
uint32_t pointSpriteEnable : 1;
|
||||||
uint32_t pointSpriteTopOrigin : 1;
|
uint32_t pointSpriteTopOrigin : 1;
|
||||||
|
|
Loading…
Reference in New Issue