diff options
author | Jason Ekstrand <jason.ekstrand@collabora.com> | 2022-04-14 11:41:41 -0500 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2022-06-23 23:18:06 +0000 |
commit | cd21d32fe404311fe7edc49801513525c19993c0 (patch) | |
tree | 9d80ec85beb38168e9ffb42046869abb4044292e | |
parent | 9b11618dfa18230b01d5dc5ad773a34f2a568c56 (diff) |
gallium: Add a u_default_clear_buffer helper
[Alyssa: Add a default CPU implementation of pipe->clear_buffer(). This hook is
mandatory for OpenCL support. Even though this implementation isn't optimal by
any means, having a conformant default available in core will lower the barrier
of entry to OpenCL support.]
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16044>
-rw-r--r-- | src/gallium/auxiliary/util/u_transfer.c | 32 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_transfer.h | 6 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c index 80576ddf10a..ba3f578caff 100644 --- a/src/gallium/auxiliary/util/u_transfer.c +++ b/src/gallium/auxiliary/util/u_transfer.c @@ -39,6 +39,38 @@ void u_default_buffer_subdata(struct pipe_context *pipe, pipe_buffer_unmap(pipe, transfer); } +void u_default_clear_buffer(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned offset, unsigned size, + const void *clear_value, + int clear_value_size) +{ + struct pipe_transfer *transfer = NULL; + struct pipe_box box; + uint8_t *map = NULL; + + /* the write flag is implicit by the nature of buffer_subdata */ + unsigned usage = PIPE_MAP_WRITE; + + /* clear_buffer implicitly discards the rewritten buffer range. */ + if (offset == 0 && size == resource->width0) { + usage |= PIPE_MAP_DISCARD_WHOLE_RESOURCE; + } else { + usage |= PIPE_MAP_DISCARD_RANGE; + } + + u_box_1d(offset, size, &box); + + map = pipe->buffer_map(pipe, resource, 0, usage, &box, &transfer); + if (!map) + return; + + assert(clear_value_size > 0); + for (unsigned off = 0; off < size; off += clear_value_size) + memcpy(map + off, clear_value, MIN2(clear_value_size, size - off)); + pipe_buffer_unmap(pipe, transfer); +} + void u_default_texture_subdata(struct pipe_context *pipe, struct pipe_resource *resource, unsigned level, diff --git a/src/gallium/auxiliary/util/u_transfer.h b/src/gallium/auxiliary/util/u_transfer.h index a885ad83009..5999d92a520 100644 --- a/src/gallium/auxiliary/util/u_transfer.h +++ b/src/gallium/auxiliary/util/u_transfer.h @@ -16,6 +16,12 @@ void u_default_buffer_subdata(struct pipe_context *pipe, unsigned usage, unsigned offset, unsigned size, const void *data); +void u_default_clear_buffer(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned offset, unsigned size, + const void *clear_value, + int clear_value_size); + void u_default_texture_subdata(struct pipe_context *pipe, struct pipe_resource *resource, unsigned level, |