[Mesa-dev] [PATCH 1/8] gallium: Add a cap for offset_units_unscaled

Roland Scheidegger sroland at vmware.com
Tue Jun 14 22:21:02 UTC 2016


Am 14.06.2016 um 23:33 schrieb Axel Davy:
> D3D9 has a different behaviour for depth bias.
> 
> For OGL/D3D1X, the depth bias unit is the
> minimal resolvable value for the depth buffer,
> which depends on the format (and has different
> behaviour for float depth buffers).
> 
> For D3D9, the depth bias unit is 1.0f.
> 
> Signed-off-by: Axel Davy <axel.davy at ens.fr>
> ---
>  src/gallium/docs/source/cso/rasterizer.rst       | 6 ++++++
>  src/gallium/docs/source/screen.rst               | 2 ++
>  src/gallium/drivers/freedreno/freedreno_screen.c | 1 +
>  src/gallium/drivers/i915/i915_screen.c           | 1 +
>  src/gallium/drivers/ilo/ilo_screen.c             | 1 +
>  src/gallium/drivers/llvmpipe/lp_screen.c         | 1 +
>  src/gallium/drivers/nouveau/nv30/nv30_screen.c   | 1 +
>  src/gallium/drivers/nouveau/nv50/nv50_screen.c   | 1 +
>  src/gallium/drivers/nouveau/nvc0/nvc0_screen.c   | 1 +
>  src/gallium/drivers/r300/r300_screen.c           | 1 +
>  src/gallium/drivers/r600/r600_pipe.c             | 1 +
>  src/gallium/drivers/radeonsi/si_pipe.c           | 1 +
>  src/gallium/drivers/softpipe/sp_screen.c         | 1 +
>  src/gallium/drivers/svga/svga_screen.c           | 1 +
>  src/gallium/drivers/swr/swr_screen.cpp           | 1 +
>  src/gallium/drivers/vc4/vc4_screen.c             | 1 +
>  src/gallium/drivers/virgl/virgl_screen.c         | 1 +
>  src/gallium/include/pipe/p_defines.h             | 1 +
>  src/gallium/include/pipe/p_state.h               | 7 +++++++
>  19 files changed, 31 insertions(+)
> 
> diff --git a/src/gallium/docs/source/cso/rasterizer.rst b/src/gallium/docs/source/cso/rasterizer.rst
> index 8d473b8..616e451 100644
> --- a/src/gallium/docs/source/cso/rasterizer.rst
> +++ b/src/gallium/docs/source/cso/rasterizer.rst
> @@ -127,6 +127,12 @@ offset_tri
>  
>  offset_units
>      Specifies the polygon offset bias
> +offset_units_unscaled
> +    Specifies the unit of the polygon offset bias. If false, use the
> +    GL/D3D1X behaviour. If true, offset_units is a floating point offset
> +    which isn't scaled (D3D9). Note that GL/D3D1X behaviour has different
> +    formula whether the depth buffer is unorm or float, which is not
> +    the case for D3D9.
>  offset_scale
>      Specifies the polygon offset scale
>  offset_clamp
> diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst
> index 920da42..9c26604 100644
> --- a/src/gallium/docs/source/screen.rst
> +++ b/src/gallium/docs/source/screen.rst
> @@ -340,6 +340,8 @@ The integer capabilities:
>    extension and thus implements proper support for culling planes.
>  * ``PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES``: Whether primitive restart is
>    supported for patch primitives.
> +* ``PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED``: If true, the driver implements support
> +  for ``pipe_rasterizer_state::offset_units_unscaled``.
>  
>  
>  .. _pipe_capf:
> diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c
> index ad15aab..ed61456 100644
> --- a/src/gallium/drivers/freedreno/freedreno_screen.c
> +++ b/src/gallium/drivers/freedreno/freedreno_screen.c
> @@ -262,6 +262,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
>  	case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>  	case PIPE_CAP_CULL_DISTANCE:
>  	case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +	case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>  		return 0;
>  
>  	case PIPE_CAP_MAX_VIEWPORTS:
> diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c
> index c0e06e5..ea451e6 100644
> --- a/src/gallium/drivers/i915/i915_screen.c
> +++ b/src/gallium/drivers/i915/i915_screen.c
> @@ -273,6 +273,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
>     case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>     case PIPE_CAP_CULL_DISTANCE:
>     case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>  
>     case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
> diff --git a/src/gallium/drivers/ilo/ilo_screen.c b/src/gallium/drivers/ilo/ilo_screen.c
> index c847a90..c9b8d81 100644
> --- a/src/gallium/drivers/ilo/ilo_screen.c
> +++ b/src/gallium/drivers/ilo/ilo_screen.c
> @@ -502,6 +502,7 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap param)
>     case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>     case PIPE_CAP_CULL_DISTANCE:
>     case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>  
>     case PIPE_CAP_VENDOR_ID:
> diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c
> index 5fc4427..f9217d6 100644
> --- a/src/gallium/drivers/llvmpipe/lp_screen.c
> +++ b/src/gallium/drivers/llvmpipe/lp_screen.c
> @@ -329,6 +329,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
>     case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
>     case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>     case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>     }
>     /* should only get here on unhandled cases */
> diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
> index 9832211..031f9ba 100644
> --- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
> +++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
> @@ -196,6 +196,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
>     case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>     case PIPE_CAP_CULL_DISTANCE:
>     case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>  
>     case PIPE_CAP_VENDOR_ID:
> diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
> index 8456d7e..34ac36c 100644
> --- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
> +++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
> @@ -249,6 +249,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
>     case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
>     case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>     case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>  
>     case PIPE_CAP_VENDOR_ID:
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
> index 6541241..726634d 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
> @@ -261,6 +261,7 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
>     case PIPE_CAP_PCI_BUS:
>     case PIPE_CAP_PCI_DEVICE:
>     case PIPE_CAP_PCI_FUNCTION:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>  
>     case PIPE_CAP_VENDOR_ID:
> diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c
> index c4a8db3..49977d9 100644
> --- a/src/gallium/drivers/r300/r300_screen.c
> +++ b/src/gallium/drivers/r300/r300_screen.c
> @@ -218,6 +218,7 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
>  	case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>          case PIPE_CAP_CULL_DISTANCE:
>          case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +        case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>              return 0;
>  
>          /* SWTCL-only features. */
> diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
> index ddf880e..db4fd1b 100644
> --- a/src/gallium/drivers/r600/r600_pipe.c
> +++ b/src/gallium/drivers/r600/r600_pipe.c
> @@ -368,6 +368,7 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
>  	case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>  	case PIPE_CAP_CULL_DISTANCE:
>  	case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +	case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>  		return 0;
>  
>  	case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
> diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
> index 7bb3dc2..99c0349 100644
> --- a/src/gallium/drivers/radeonsi/si_pipe.c
> +++ b/src/gallium/drivers/radeonsi/si_pipe.c
> @@ -400,6 +400,7 @@ static int si_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
>  	case PIPE_CAP_QUERY_BUFFER_OBJECT:
>  	case PIPE_CAP_CULL_DISTANCE:
>  	case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +	case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>  		return 0;
>  
>  	case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
> diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
> index 3a40ef7..49c8884 100644
> --- a/src/gallium/drivers/softpipe/sp_screen.c
> +++ b/src/gallium/drivers/softpipe/sp_screen.c
> @@ -274,6 +274,7 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
>     case PIPE_CAP_PCI_FUNCTION:
>     case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>     case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>     case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
>        return 4;
> diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
> index 173873f..621ecff 100644
> --- a/src/gallium/drivers/svga/svga_screen.c
> +++ b/src/gallium/drivers/svga/svga_screen.c
> @@ -408,6 +408,7 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
>     case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
>     case PIPE_CAP_CULL_DISTANCE:
>     case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>     }
>  
> diff --git a/src/gallium/drivers/swr/swr_screen.cpp b/src/gallium/drivers/swr/swr_screen.cpp
> index 0772274..6b8c25d 100644
> --- a/src/gallium/drivers/swr/swr_screen.cpp
> +++ b/src/gallium/drivers/swr/swr_screen.cpp
> @@ -360,6 +360,7 @@ swr_get_param(struct pipe_screen *screen, enum pipe_cap param)
>     case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
>     case PIPE_CAP_CULL_DISTANCE:
>     case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>     }
>  
> diff --git a/src/gallium/drivers/vc4/vc4_screen.c b/src/gallium/drivers/vc4/vc4_screen.c
> index 733275a..a4eb306 100644
> --- a/src/gallium/drivers/vc4/vc4_screen.c
> +++ b/src/gallium/drivers/vc4/vc4_screen.c
> @@ -211,6 +211,7 @@ vc4_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
>          case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>          case PIPE_CAP_CULL_DISTANCE:
>          case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +        case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>                  return 0;
>  
>                  /* Stream output. */
> diff --git a/src/gallium/drivers/virgl/virgl_screen.c b/src/gallium/drivers/virgl/virgl_screen.c
> index 73f9f8d..fda72c9 100644
> --- a/src/gallium/drivers/virgl/virgl_screen.c
> +++ b/src/gallium/drivers/virgl/virgl_screen.c
> @@ -243,6 +243,7 @@ virgl_get_param(struct pipe_screen *screen, enum pipe_cap param)
>     case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
>     case PIPE_CAP_CULL_DISTANCE:
>     case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
> +   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
>        return 0;
>     case PIPE_CAP_VENDOR_ID:
>        return 0x1af4;
> diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
> index 278d100..7cf3568 100644
> --- a/src/gallium/include/pipe/p_defines.h
> +++ b/src/gallium/include/pipe/p_defines.h
> @@ -729,6 +729,7 @@ enum pipe_cap
>     PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR,
>     PIPE_CAP_CULL_DISTANCE,
>     PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES,
> +   PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED,
>  };
>  
>  #define PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 (1 << 0)
> diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
> index 396f563..7dce80a 100644
> --- a/src/gallium/include/pipe/p_state.h
> +++ b/src/gallium/include/pipe/p_state.h
> @@ -139,6 +139,13 @@ struct pipe_rasterizer_state
>     unsigned clip_halfz:1;
>  
>     /**
> +    * When true do not scale offset_units and use same rules for unorm and
> +    * float depth buffers (D3D9). When false use GL/D3D1X behaviour.
> +    * This depends on PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED.
> +    */
> +   unsigned offset_units_unscaled;
> +
> +   /**
>      * Enable bits for clipping half-spaces.
>      * This applies to both user clip planes and shader clip distances.
>      * Note that if the bound shader exports any clip distances, these
> 

I don't like this. Generally, for unorm formats, you can easily enough
translate this from d3d9 to gl (or d3d10) rules (but yes, obviously it's
going to be format dependent). (With one big caveat, in general not all
gl drivers think the minimum resolvable difference is the same, that
might range from 2^-22 to 2^-24 for 24bit unorm depth for instance, and
I don't think it's quite consistent with gallium drivers neither).

You are right though for float depth the formula is different, and you
can't translate it. But do you really need float depth buffer support?
AFAIK no d3d9 app really depends on it, everything can fall back to d24.

Roland



More information about the mesa-dev mailing list