[Mesa-dev] [PATCH 1/4] mesa: mesa: add fallback texture for SampleMapATI if there is nothing

Ian Romanick idr at freedesktop.org
Tue Nov 21 00:27:19 UTC 2017


Only need one mesa: in the subject. :)

On 11/20/2017 04:07 PM, Miklós Máté wrote:
> This fixes crash in the state tracker.
> Piglit: spec/ati_fragment_shader/render-notexture
> 
> Signed-off-by: Miklós Máté <mtmkls at gmail.com>
> ---
>  src/mesa/main/texstate.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
> index 2146723d08..a0717a542f 100644
> --- a/src/mesa/main/texstate.c
> +++ b/src/mesa/main/texstate.c
> @@ -819,6 +819,35 @@ update_ff_texture_state(struct gl_context *ctx,
>     }
>  }
>  
> +static void
> +fix_missing_textures_for_atifs(struct gl_context *ctx,
> +                               struct gl_program *prog,
> +                               BITSET_WORD *enabled_texture_units)

I'm fairly sure there's already a function like this somewhere in Mesa.
Perhaps that code could be refactored slightly so that it can be re-used
here?

> +{
> +   GLbitfield mask;
> +   GLuint s;
> +   int unit;
> +   gl_texture_index target_index;
> +   struct gl_texture_object *texObj;

All of these declarations except mask can be moved inside the loop.
Then they could all be made const.

> +
> +   mask = prog->SamplersUsed;
> +   while (mask) {
> +      s = u_bit_scan(&mask);
> +      unit = prog->SamplerUnits[s];
> +
> +      target_index = ffs(prog->TexturesUsed[unit]) - 1;
> +
> +      if (!ctx->Texture.Unit[unit]._Current) {
> +         texObj = _mesa_get_fallback_texture(ctx, target_index);
> +
> +         _mesa_reference_texobj(&ctx->Texture.Unit[unit]._Current, texObj);
> +         BITSET_SET(enabled_texture_units, unit);
> +         ctx->Texture._MaxEnabledTexImageUnit =
> +            MAX2(ctx->Texture._MaxEnabledTexImageUnit, (int)unit);
> +      }
> +   }
> +}
> +
>  /**
>   * \note This routine refers to derived texture matrix values to
>   * compute the ENABLE_TEXMAT flags, but is only called on
> @@ -866,6 +895,12 @@ _mesa_update_texture_state(struct gl_context *ctx)
>     if (!prog[MESA_SHADER_FRAGMENT])
>        update_ff_texture_state(ctx, enabled_texture_units);
>  
> +   /* add fallback texture for SampleMapATI if there is nothing */
> +   if (_mesa_ati_fragment_shader_enabled(ctx) &&
> +         ctx->ATIFragmentShader.Current->Program)

This should line up with the (.

> +      fix_missing_textures_for_atifs(ctx,
> +            ctx->ATIFragmentShader.Current->Program, enabled_texture_units);

Same here.

> +
>     /* Now, clear out the _Current of any disabled texture units. */
>     for (i = 0; i <= ctx->Texture._MaxEnabledTexImageUnit; i++) {
>        if (!BITSET_TEST(enabled_texture_units, i))
> 



More information about the mesa-dev mailing list