[Mesa-dev] [PATCH 3/8] mesa: Pass number of samples as a program state variable

Ian Romanick idr at freedesktop.org
Tue Oct 15 18:53:23 CEST 2013


On 10/14/2013 10:12 AM, Anuj Phogat wrote:
> Number of samples will be required in fragment shader program by new
> GLSL builtin uniform "gl_NumSamples".
> 
> Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
> ---
>  src/mesa/program/prog_statevars.c | 11 +++++++++++
>  src/mesa/program/prog_statevars.h |  2 ++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
> index 145c07c..8f798da 100644
> --- a/src/mesa/program/prog_statevars.c
> +++ b/src/mesa/program/prog_statevars.c
> @@ -349,6 +349,9 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
>           }
>        }
>        return;
> +   case STATE_NUM_SAMPLES:
> +      ((int *)value)[0] = ctx->DrawBuffer->Visual.samples;
> +      return;
>     case STATE_DEPTH_RANGE:
>        value[0] = ctx->Viewport.Near;                     /* near       */
>        value[1] = ctx->Viewport.Far;                      /* far        */
> @@ -665,6 +668,9 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
>     case STATE_PROGRAM_MATRIX:
>        return _NEW_TRACK_MATRIX;
>  
> +   case STATE_NUM_SAMPLES:
> +      return _NEW_MULTISAMPLE;
> +
>     case STATE_DEPTH_RANGE:
>        return _NEW_VIEWPORT;
>  
> @@ -852,6 +858,9 @@ append_token(char *dst, gl_state_index k)
>     case STATE_TEXENV_COLOR:
>        append(dst, "texenv");
>        break;
> +   case STATE_NUM_SAMPLES:
> +      append(dst, "num.samples");
> +      break;

There is some really broken code in append_token and
_mesa_program_state_string... and, of course, none of it is ever
exercised. :(

Here's how this works... In ARB_vertex_program and ARB_fragment_program
(the ARB assembly shader extensions), there was a big structure-like
thing called "state".  This is where all of the built-in variables that
represented things like gl_DepthRange.near or
gl_ModelViewProjectionMatrix lived.  They were accessed as
state.depth.range (and the x, y, z, and w fields had the data) or
state.matrix.modelview.

The state[] tokens passed to _mesa_program_state_string represents a
dereference of the assembly program state structure.  Each element
(usually) represents one level of the dereference.  So, gl_DepthRange is
state.depth.range is { STATE_DEPTH_RANGE, 0, 0 } and
gl_ModelViewProjectionMatrix[1] is state.matrix.modelview[1] is {
STATE_MVP_MATRIX, 1, 0 }.

_mesa_program_state_string converts the list of tokens back into an
assembly-style string.  When it gets { STATE_DEPTH_RANGE, 0, 0 }, it
should return "state.depth.range".  When it gets { STATE_NUM_SAMPLES, 0,
0 }, it should return "state.numsamples" (or similar).  Right now each
of these queries returns... nothing.

The "append(dst, ...)" should go in _mesa_program_state_string.

>     case STATE_DEPTH_RANGE:
>        append(dst, "depth.range");
>        break;
> @@ -1027,6 +1036,8 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
>        break;
>     case STATE_FOG_COLOR:
>        break;
> +   case STATE_NUM_SAMPLES:
> +      break;
>     case STATE_DEPTH_RANGE:
>        break;
>     case STATE_FRAGMENT_PROGRAM:
> diff --git a/src/mesa/program/prog_statevars.h b/src/mesa/program/prog_statevars.h
> index ec22b73..c3081c4 100644
> --- a/src/mesa/program/prog_statevars.h
> +++ b/src/mesa/program/prog_statevars.h
> @@ -103,6 +103,8 @@ typedef enum gl_state_index_ {
>  
>     STATE_TEXENV_COLOR,
>  
> +   STATE_NUM_SAMPLES,
> +
>     STATE_DEPTH_RANGE,
>  
>     STATE_VERTEX_PROGRAM,
> 



More information about the mesa-dev mailing list