mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 09:28:07 +02:00
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>
This commit is contained in:
parent
9b11618dfa
commit
cd21d32fe4
2 changed files with 38 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue