[Mesa-dev] [PATCH] softpipe: implement clear_texture

Lars Hamre chemecse at gmail.com
Wed Feb 15 15:16:50 UTC 2017


Happy to rework the implementation.
Would creating a util_clear_texture function which pulls out the
necessary components from util_clear_render_target be in alignment
with what you're imagining?
The idea would be to have util_clear_texture take a pipe_resource
instead of a pipe_surface.
Something similar would also be done for clear_depth_stencil.

Lars

On Mon, Feb 13, 2017 at 7:41 PM, Roland Scheidegger <sroland at vmware.com> wrote:
> Am 13.02.2017 um 16:20 schrieb Lars Hamre:
>> Implements the ARB_clear_texture extension for softpipe.
>> Passes all corresponding piglit tests.
>>
>> Signed-off-by: Lars Hamre <chemecse at gmail.com>
>>
>> ---
>>
>> NOTE: someone with access will need to commit this post
>>       review process
>>
>>  src/gallium/drivers/softpipe/sp_screen.c  |  3 +-
>>  src/gallium/drivers/softpipe/sp_texture.c | 60 +++++++++++++++++++++++++++++++
>>  2 files changed, 62 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
>> index 02eff91..aa061d7 100644
>> --- a/src/gallium/drivers/softpipe/sp_screen.c
>> +++ b/src/gallium/drivers/softpipe/sp_screen.c
>> @@ -260,6 +260,8 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
>>     case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
>>     case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
>>        return 1;
>> +   case PIPE_CAP_CLEAR_TEXTURE:
>> +      return 1;
>>     case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
>>     case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
>>     case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
>> @@ -268,7 +270,6 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
>>     case PIPE_CAP_TGSI_TXQS:
>>     case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
>>     case PIPE_CAP_SHAREABLE_SHADERS:
>> -   case PIPE_CAP_CLEAR_TEXTURE:
>>     case PIPE_CAP_DRAW_PARAMETERS:
>>     case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
>>     case PIPE_CAP_MULTI_DRAW_INDIRECT:
>> diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c
>> index 8dca158..3794cf3 100644
>> --- a/src/gallium/drivers/softpipe/sp_texture.c
>> +++ b/src/gallium/drivers/softpipe/sp_texture.c
>> @@ -37,6 +37,7 @@
>>  #include "util/u_math.h"
>>  #include "util/u_memory.h"
>>  #include "util/u_transfer.h"
>> +#include "util/u_surface.h"
>>
>>  #include "sp_context.h"
>>  #include "sp_flush.h"
>> @@ -341,6 +342,64 @@ softpipe_surface_destroy(struct pipe_context *pipe,
>>  }
>>
>>
>> +static void
>> +softpipe_clear_texture(struct pipe_context *pipe,
>> +                       struct pipe_resource *tex,
>> +                       unsigned level,
>> +                       const struct pipe_box *box,
>> +                       const void *data)
>> +{
>> +   struct pipe_surface tmpl = {{0}};
>> +   struct pipe_surface *sf;
>> +   const struct util_format_description *desc =
>> +          util_format_description(tex->format);
>> +
>> +   if (level > tex->last_level)
>> +      return;
>> +
>> +   tmpl.format = tex->format;
>> +   tmpl.u.tex.first_layer = box->z;
>> +   tmpl.u.tex.last_layer = box->z + box->depth - 1;
>> +   tmpl.u.tex.level = level;
>> +   sf = pipe->create_surface(pipe, tex, &tmpl);
> I am not quite convinced of that solution. The problem is you're not
> supposed to call create_surface() on resources which didn't have the
> appropriate bind flag (although unlike llvmpipe softpipe won't warn
> about this). And in fact, there's formats where clear_texture is
> supposed to work which are definitely not renderable, so it really is an
> error to do this (even though softpipe won't actually care).
>
> But OTOH I suppose this method works...
>
> Roland
>
>
>> +   if (!sf)
>> +      return;
>> +
>> +   if (util_format_is_depth_or_stencil(tex->format)) {
>> +      unsigned clear = 0;
>> +      float depth = 0.0f;
>> +      uint8_t stencil = 0;
>> +
>> +      if (util_format_has_depth(desc)) {
>> +         clear |= PIPE_CLEAR_DEPTH;
>> +         desc->unpack_z_float(&depth, 0, data, 0, 1, 1);
>> +      }
>> +
>> +      if (util_format_has_stencil(desc)) {
>> +         clear |= PIPE_CLEAR_STENCIL;
>> +         desc->unpack_s_8uint(&stencil, 0, data, 0, 1, 1);
>> +      }
>> +
>> +      pipe->clear_depth_stencil(pipe, sf, clear, depth, stencil,
>> +                                box->x, box->y,
>> +                                box->width, box->height, false);
>> +   } else {
>> +      union pipe_color_union color;
>> +
>> +      if (util_format_is_pure_uint(tex->format))
>> +         desc->unpack_rgba_uint(color.ui, 0, data, 0, 1, 1);
>> +      else if (util_format_is_pure_sint(tex->format))
>> +         desc->unpack_rgba_sint(color.i, 0, data, 0, 1, 1);
>> +      else
>> +         desc->unpack_rgba_float(color.f, 0, data, 0, 1, 1);
>> +
>> +      util_clear_render_target(pipe, sf, &color, box->x, box->y,
>> +                               box->width, box->height);
>> +   }
>> +   pipe_surface_reference(&sf, NULL);
>> +}
>> +
>> +
>>  /**
>>   * Geta pipe_transfer object which is used for moving data in/out of
>>   * a resource object.
>> @@ -520,6 +579,7 @@ softpipe_init_texture_funcs(struct pipe_context *pipe)
>>
>>     pipe->create_surface = softpipe_create_surface;
>>     pipe->surface_destroy = softpipe_surface_destroy;
>> +   pipe->clear_texture = softpipe_clear_texture;
>>  }
>>
>>
>> --
>> 2.7.4
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>
>


More information about the mesa-dev mailing list