[Mesa-dev] [PATCH 1/2] swr: [rasterizer core] allow an OpenGL driver to specify halfz clipping

Rowley, Timothy O timothy.o.rowley at intel.com
Wed Nov 9 16:12:26 UTC 2016


Yes, that was about to be my suggestion too - remove the drivertype use in the clipper and use the “clipHalfZ” flag instead.

driverType is still used in the SwrSetViewports setup, so can’t be completely removed right now.

-Tim

> On Nov 9, 2016, at 10:04 AM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> 
> On Wed, Nov 9, 2016 at 1:21 AM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
>> With ARB_clip_control, GL may also do 0..1 depth clipping, not just
>> -1..1. For backwards compatibility, preserve the existing driver type
>> check for DX as well.
> 
> Oh. An even better idea would be to update SwrSetRasterizer to
> magically flip that bit on when driverType == DX at the API level. And
> drop all that driver type stuff from the core otherwise. IMHO that's
> much cleaner. Let me know if you think this will cause problems.
> 
> At least in gallium, we've avoided making any GL vs DX distinctions.
> It seems like a good thing to do in swr core as well.
> 
> Cheers,
> 
>  -ilia
> 
>> 
>> Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
>> ---
>> src/gallium/drivers/swr/rasterizer/core/clip.h  | 6 +++---
>> src/gallium/drivers/swr/rasterizer/core/state.h | 1 +
>> 2 files changed, 4 insertions(+), 3 deletions(-)
>> 
>> diff --git a/src/gallium/drivers/swr/rasterizer/core/clip.h b/src/gallium/drivers/swr/rasterizer/core/clip.h
>> index 43bc522..78dbcf0 100644
>> --- a/src/gallium/drivers/swr/rasterizer/core/clip.h
>> +++ b/src/gallium/drivers/swr/rasterizer/core/clip.h
>> @@ -90,7 +90,7 @@ void ComputeClipCodes(DRIVER_TYPE type, const API_STATE& state, const simdvector
>>     {
>>         // FRUSTUM_NEAR
>>         // DX clips depth [0..w], GL clips [-w..w]
>> -        if (type == DX)
>> +        if (type == DX || state.rastState.clipHalfZ)
>>         {
>>             vRes = _simd_cmplt_ps(vertex.z, _simd_setzero_ps());
>>         }
>> @@ -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_NEAR:
>>             // DX Znear plane is 0, GL is -w
>> -            if (this->driverType == DX)
>> +            if (this->driverType == DX || this->state.rastState.clipHalfZ)
>>             {
>>                 t = ComputeInterpFactor(v1[2], v2[2]);
>>             }
>> @@ -708,7 +708,7 @@ private:
>>         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_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->driverType == DX || 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]);
>>         default:
>>             SWR_ASSERT(false, "invalid clipping plane: %d", ClippingPlane);
>> diff --git a/src/gallium/drivers/swr/rasterizer/core/state.h b/src/gallium/drivers/swr/rasterizer/core/state.h
>> index 93e4565..5ee12e8 100644
>> --- a/src/gallium/drivers/swr/rasterizer/core/state.h
>> +++ b/src/gallium/drivers/swr/rasterizer/core/state.h
>> @@ -932,6 +932,7 @@ struct SWR_RASTSTATE
>>     uint32_t frontWinding           : 1;
>>     uint32_t scissorEnable          : 1;
>>     uint32_t depthClipEnable        : 1;
>> +    uint32_t clipHalfZ              : 1;
>>     uint32_t pointParam             : 1;
>>     uint32_t pointSpriteEnable      : 1;
>>     uint32_t pointSpriteTopOrigin   : 1;
>> --
>> 2.7.3
>> 



More information about the mesa-dev mailing list