From fb2fb0d4fede6f65de939efbc5c48c488267a7c2 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Sun, 16 May 2021 10:38:20 -0400 Subject: [PATCH] gallium/aux: add helper for pre-clamping clear_buffer value to dword MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit copied from radeonsi Reviewed-by: Marek Olšák Part-of: --- src/gallium/auxiliary/util/u_helpers.c | 38 ++++++++++++++++++++++++++ src/gallium/auxiliary/util/u_helpers.h | 3 ++ 2 files changed, 41 insertions(+) diff --git a/src/gallium/auxiliary/util/u_helpers.c b/src/gallium/auxiliary/util/u_helpers.c index 1d2707e15a3..d7db32d124b 100644 --- a/src/gallium/auxiliary/util/u_helpers.c +++ b/src/gallium/auxiliary/util/u_helpers.c @@ -374,3 +374,41 @@ util_throttle_memory_usage(struct pipe_context *pipe, t->ring[t->flush_index].mem_usage += memory_size; } + +bool +util_lower_clearsize_to_dword(const void *clearValue, int *clearValueSize, uint32_t *clamped) +{ + /* Reduce a large clear value size if possible. */ + if (*clearValueSize > 4) { + bool clear_dword_duplicated = true; + const uint32_t *clear_value = clearValue; + + /* See if we can lower large fills to dword fills. */ + for (unsigned i = 1; i < *clearValueSize / 4; i++) { + if (clear_value[0] != clear_value[i]) { + clear_dword_duplicated = false; + break; + } + } + if (clear_dword_duplicated) { + *clamped = *clear_value; + *clearValueSize = 4; + } + return clear_dword_duplicated; + } + + /* Expand a small clear value size. */ + if (*clearValueSize <= 2) { + if (*clearValueSize == 1) { + *clamped = *(uint8_t *)clearValue; + *clamped |= + (*clamped << 8) | (*clamped << 16) | (*clamped << 24); + } else { + *clamped = *(uint16_t *)clearValue; + *clamped |= *clamped << 16; + } + *clearValueSize = 4; + return true; + } + return false; +} diff --git a/src/gallium/auxiliary/util/u_helpers.h b/src/gallium/auxiliary/util/u_helpers.h index a3f15cd6c44..0bfc91700c1 100644 --- a/src/gallium/auxiliary/util/u_helpers.h +++ b/src/gallium/auxiliary/util/u_helpers.h @@ -113,6 +113,9 @@ void util_throttle_deinit(struct pipe_screen *screen, struct util_throttle *t); void util_throttle_memory_usage(struct pipe_context *pipe, struct util_throttle *t, uint64_t memory_size); +bool +util_lower_clearsize_to_dword(const void *clearValue, int *clearValueSize, uint32_t *clamped); + #ifdef __cplusplus } #endif