[Mesa-dev] [PATCH 1/2] gallium/u_blitter: implement buffer clearing

Marek Olšák maraeo at gmail.com
Tue Apr 23 11:21:21 PDT 2013


On Mon, Apr 22, 2013 at 4:42 PM, Brian Paul <brianp at vmware.com> wrote:
> On 04/21/2013 05:25 PM, Marek Olšák wrote:
>>
>> Although this might be useful for ARB_clear_buffer_object,
>> I need it for initializating resources in r600g.
>> ---
>>   src/gallium/auxiliary/util/u_blitter.c |   81
>> +++++++++++++++++++++++++++++---
>>   src/gallium/auxiliary/util/u_blitter.h |   18 ++++++-
>>   2 files changed, 91 insertions(+), 8 deletions(-)
>>
>> diff --git a/src/gallium/auxiliary/util/u_blitter.c
>> b/src/gallium/auxiliary/util/u_blitter.c
>> index 2a4a13e..2f7a1a8 100644
>> --- a/src/gallium/auxiliary/util/u_blitter.c
>> +++ b/src/gallium/auxiliary/util/u_blitter.c
>> @@ -100,7 +100,7 @@ struct blitter_context_priv
>>      void *velem_state;
>>      void *velem_uint_state;
>>      void *velem_sint_state;
>> -   void *velem_state_readbuf;
>> +   void *velem_state_readbuf[4];
>
>
> It took me a minute to understand what '4' is all about.  Maybe add a
> comment like this:
>
> void *velem_state_readbuf[4];  /**< X, XY, XYZ, XYZW */
>
>
>>
>>      /* Sampler state. */
>>      void *sampler_state;
>> @@ -285,9 +285,19 @@ struct blitter_context *util_blitter_create(struct
>> pipe_context *pipe)
>>      }
>>
>>      if (ctx->has_stream_out) {
>> -      velem[0].src_format = PIPE_FORMAT_R32_UINT;
>> -      velem[0].vertex_buffer_index = ctx->base.vb_slot;
>> -      ctx->velem_state_readbuf = pipe->create_vertex_elements_state(pipe,
>> 1,&velem[0]);
>>
>> +      static enum pipe_format formats[4] = {
>> +         PIPE_FORMAT_R32_UINT,
>> +         PIPE_FORMAT_R32G32_UINT,
>> +         PIPE_FORMAT_R32G32B32_UINT,
>> +         PIPE_FORMAT_R32G32B32A32_UINT
>> +      };
>> +
>> +      for (i = 0; i<  4; i++) {
>> +         velem[0].src_format = formats[i];
>> +         velem[0].vertex_buffer_index = ctx->base.vb_slot;
>> +         ctx->velem_state_readbuf[i] =
>> +               pipe->create_vertex_elements_state(pipe, 1,&velem[0]);
>>
>> +      }
>>      }
>>
>>      /* fragment shaders are created on-demand */
>> @@ -352,8 +362,11 @@ void util_blitter_destroy(struct blitter_context
>> *blitter)
>>         pipe->delete_vertex_elements_state(pipe, ctx->velem_sint_state);
>>         pipe->delete_vertex_elements_state(pipe, ctx->velem_uint_state);
>>      }
>> -   if (ctx->velem_state_readbuf)
>> -      pipe->delete_vertex_elements_state(pipe, ctx->velem_state_readbuf);
>> +   for (i = 0; i<  4; i++) {
>> +      if (ctx->velem_state_readbuf[i]) {
>> +         pipe->delete_vertex_elements_state(pipe,
>> ctx->velem_state_readbuf[i]);
>> +      }
>> +   }
>>
>>      for (i = 0; i<  PIPE_MAX_TEXTURE_TYPES; i++) {
>>         if (ctx->fs_texfetch_col[i])
>> @@ -1739,7 +1752,7 @@ void util_blitter_copy_buffer(struct blitter_context
>> *blitter,
>>      vb.stride = 4;
>>
>>      pipe->set_vertex_buffers(pipe, ctx->base.vb_slot, 1,&vb);
>> -   pipe->bind_vertex_elements_state(pipe, ctx->velem_state_readbuf);
>> +   pipe->bind_vertex_elements_state(pipe, ctx->velem_state_readbuf[0]);
>>      pipe->bind_vs_state(pipe, ctx->vs_pos_only);
>>      if (ctx->has_geometry_shader)
>>         pipe->bind_gs_state(pipe, NULL);
>> @@ -1756,6 +1769,60 @@ void util_blitter_copy_buffer(struct
>> blitter_context *blitter,
>>      pipe_so_target_reference(&so_target, NULL);
>>   }
>>
>> +void util_blitter_clear_buffer(struct blitter_context *blitter,
>> +                               struct pipe_resource *dst,
>> +                               unsigned offset, unsigned size,
>> +                               unsigned num_channels,
>> +                               const union pipe_color_union *clear_value)
>> +{
>> +   struct blitter_context_priv *ctx = (struct
>> blitter_context_priv*)blitter;
>> +   struct pipe_context *pipe = ctx->base.pipe;
>> +   struct pipe_vertex_buffer vb = {0};
>> +   struct pipe_stream_output_target *so_target;
>> +
>> +   assert(num_channels>= 1);
>> +   assert(num_channels<= 4);
>
>
> Do we want some sort of assertion to check that the driver actually supports
> SO?

The assertion is later in the code (along with the alignment
checking), but I'll separate it.

Marek


More information about the mesa-dev mailing list