[Mesa-dev] [PATCH 4/6] gallium: allow choosing which colorbuffers to clear

Roland Scheidegger sroland at vmware.com
Thu Dec 5 13:47:24 PST 2013


Am 05.12.2013 22:42, schrieb Roland Scheidegger:
> Am 05.12.2013 18:53, schrieb Marek Olšák:
>> From: Marek Olšák <marek.olsak at amd.com>
>>
>> Required for glClearBuffer, which only clears one colorbuffer attachment.
>>
>> Example:
>>    If the first colorbuffer is float and the second one is int:
>>       pipe->clear(pipe, PIPE_CLEAR_COLOR0, float_clear_color, ...);
>>       pipe->clear(pipe, PIPE_CLEAR_COLOR1, int_clear_color, ...);
>>
>> This doesn't need any driver changes yet, because all drivers just use:
>>   if (flags & PIPE_CLEAR_COLOR) ..
>>
>> The drivers which support GL 3.0 will have to implement it properly though.
>> ---
>>  src/gallium/auxiliary/postprocess/pp_mlaa.c |  2 +-
>>  src/gallium/auxiliary/postprocess/pp_run.c  |  2 +-
>>  src/gallium/auxiliary/util/u_clear.h        |  7 ++++---
>>  src/gallium/drivers/r300/r300_blit.c        |  2 +-
>>  src/gallium/include/pipe/p_defines.h        | 19 +++++++++++++++----
>>  src/gallium/state_trackers/vega/api_masks.c |  2 +-
>>  6 files changed, 23 insertions(+), 11 deletions(-)
>>
>> diff --git a/src/gallium/auxiliary/postprocess/pp_mlaa.c b/src/gallium/auxiliary/postprocess/pp_mlaa.c
>> index 92bd11c..4f0c156 100644
>> --- a/src/gallium/auxiliary/postprocess/pp_mlaa.c
>> +++ b/src/gallium/auxiliary/postprocess/pp_mlaa.c
>> @@ -138,7 +138,7 @@ pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
>>     pp_filter_set_fb(p);
>>     pp_filter_misc_state(p);
>>     cso_set_depth_stencil_alpha(p->cso, &mstencil);
>> -   p->pipe->clear(p->pipe, PIPE_CLEAR_STENCIL | PIPE_CLEAR_COLOR,
>> +   p->pipe->clear(p->pipe, PIPE_CLEAR_STENCIL | PIPE_CLEAR_COLOR0,
>>                    &p->clear_color, 0, 0);
>>  
>>     cso_single_sampler(p->cso, PIPE_SHADER_FRAGMENT, 0, &p->sampler_point);
>> diff --git a/src/gallium/auxiliary/postprocess/pp_run.c b/src/gallium/auxiliary/postprocess/pp_run.c
>> index 5c6dfa1..a4dc75d 100644
>> --- a/src/gallium/auxiliary/postprocess/pp_run.c
>> +++ b/src/gallium/auxiliary/postprocess/pp_run.c
>> @@ -309,5 +309,5 @@ void
>>  pp_filter_set_clear_fb(struct pp_program *p)
>>  {
>>     cso_set_framebuffer(p->cso, &p->framebuffer);
>> -   p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, &p->clear_color, 0, 0);
>> +   p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR0, &p->clear_color, 0, 0);
>>  }
> These changes here in postprocess (plus the one in the vega state
> tracker) don't look like they'd still work with unaltered drivers as
> claimed in the commit message.
> 
Argh actually you're right this should still work, so forget that.

Roland


> 
> 
>> diff --git a/src/gallium/auxiliary/util/u_clear.h b/src/gallium/auxiliary/util/u_clear.h
>> index e9fd874..75047c1 100644
>> --- a/src/gallium/auxiliary/util/u_clear.h
>> +++ b/src/gallium/auxiliary/util/u_clear.h
>> @@ -42,9 +42,10 @@ util_clear(struct pipe_context *pipe,
>>             struct pipe_framebuffer_state *framebuffer, unsigned buffers,
>>             const union pipe_color_union *color, double depth, unsigned stencil)
>>  {
>> -   if (buffers & PIPE_CLEAR_COLOR) {
>> -      unsigned i;
>> -      for (i = 0; i < framebuffer->nr_cbufs; i++) {
>> +   unsigned i;
>> +
>> +   for (i = 0; i < framebuffer->nr_cbufs; i++) {
>> +      if (buffers & (PIPE_CLEAR_COLOR0 << i)) {
>>           struct pipe_surface *ps = framebuffer->cbufs[i];
>>           pipe->clear_render_target(pipe, ps, color, 0, 0, ps->width, ps->height);
>>        }
>> diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c
>> index 42410fe..a0b4573 100644
>> --- a/src/gallium/drivers/r300/r300_blit.c
>> +++ b/src/gallium/drivers/r300/r300_blit.c
>> @@ -130,7 +130,7 @@ static boolean r300_cbzb_clear_allowed(struct r300_context *r300,
>>          (struct pipe_framebuffer_state*)r300->fb_state.state;
>>  
>>      /* Only color clear allowed, and only one colorbuffer. */
>> -    if (clear_buffers != PIPE_CLEAR_COLOR || fb->nr_cbufs != 1)
>> +    if ((clear_buffers & ~PIPE_CLEAR_COLOR) != 0 || fb->nr_cbufs != 1)
>>          return FALSE;
>>  
>>      return r300_surface(fb->cbufs[0])->cbzb_allowed;
>> diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
>> index 06a9edd..982f529 100644
>> --- a/src/gallium/include/pipe/p_defines.h
>> +++ b/src/gallium/include/pipe/p_defines.h
>> @@ -188,11 +188,22 @@ enum pipe_texture_target {
>>  /**
>>   * Clear buffer bits
>>   */
>> +#define PIPE_CLEAR_DEPTH        (1 << 0)
>> +#define PIPE_CLEAR_STENCIL      (1 << 1)
>> +#define PIPE_CLEAR_COLOR0       (1 << 2)
>> +#define PIPE_CLEAR_COLOR1       (1 << 3)
>> +#define PIPE_CLEAR_COLOR2       (1 << 4)
>> +#define PIPE_CLEAR_COLOR3       (1 << 5)
>> +#define PIPE_CLEAR_COLOR4       (1 << 6)
>> +#define PIPE_CLEAR_COLOR5       (1 << 7)
>> +#define PIPE_CLEAR_COLOR6       (1 << 8)
>> +#define PIPE_CLEAR_COLOR7       (1 << 9)
>> +/** Combined flags */
>>  /** All color buffers currently bound */
>> -#define PIPE_CLEAR_COLOR        (1 << 0)
>> -#define PIPE_CLEAR_DEPTH        (1 << 1)
>> -#define PIPE_CLEAR_STENCIL      (1 << 2)
>> -/** Depth/stencil combined */
>> +#define PIPE_CLEAR_COLOR        (PIPE_CLEAR_COLOR0 | PIPE_CLEAR_COLOR1 | \
>> +                                 PIPE_CLEAR_COLOR2 | PIPE_CLEAR_COLOR3 | \
>> +                                 PIPE_CLEAR_COLOR4 | PIPE_CLEAR_COLOR5 | \
>> +                                 PIPE_CLEAR_COLOR6 | PIPE_CLEAR_COLOR7)
>>  #define PIPE_CLEAR_DEPTHSTENCIL (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)
>>  
>>  /**
>> diff --git a/src/gallium/state_trackers/vega/api_masks.c b/src/gallium/state_trackers/vega/api_masks.c
>> index 0ddcdfb..48dc844 100644
>> --- a/src/gallium/state_trackers/vega/api_masks.c
>> +++ b/src/gallium/state_trackers/vega/api_masks.c
>> @@ -97,7 +97,7 @@ void vegaClear(VGint x, VGint y,
>>        clear_color.f[1] = ctx->state.vg.clear_color[1];
>>        clear_color.f[2] = ctx->state.vg.clear_color[2];
>>        clear_color.f[3] = ctx->state.vg.clear_color[3];
>> -      ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
>> +      ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_COLOR0 | PIPE_CLEAR_DEPTHSTENCIL,
>>                         &clear_color, 1., 0);
>>     } else if (renderer_clear_begin(ctx->renderer)) {
>>        /* XXX verify coord round-off */
>>
> 


More information about the mesa-dev mailing list