Mesa (main): panfrost: Extract panfrost_get_index_buffer helper
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jun 6 15:12:28 UTC 2022
Module: Mesa
Branch: main
Commit: ca6d06fa91dfa90403a721200203041486faa8a0
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ca6d06fa91dfa90403a721200203041486faa8a0
Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date: Sat Jun 4 09:57:29 2022 -0400
panfrost: Extract panfrost_get_index_buffer helper
Memory-allocated IDVS does not require min/max indices to be calculated, but it
of course requires an index buffer. Extract a helper to upload the index buffer
without calculating bounds.
Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16867>
---
src/gallium/drivers/panfrost/pan_context.h | 5 +++
src/gallium/drivers/panfrost/pan_helpers.c | 54 ++++++++++++++++++------------
2 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h
index 0145e94e886..77933d7a4a4 100644
--- a/src/gallium/drivers/panfrost/pan_context.h
+++ b/src/gallium/drivers/panfrost/pan_context.h
@@ -406,6 +406,11 @@ panfrost_shader_compile(struct pipe_screen *pscreen,
void
panfrost_analyze_sysvals(struct panfrost_shader_state *ss);
+mali_ptr
+panfrost_get_index_buffer(struct panfrost_batch *batch,
+ const struct pipe_draw_info *info,
+ const struct pipe_draw_start_count_bias *draw);
+
mali_ptr
panfrost_get_index_buffer_bounded(struct panfrost_batch *batch,
const struct pipe_draw_info *info,
diff --git a/src/gallium/drivers/panfrost/pan_helpers.c b/src/gallium/drivers/panfrost/pan_helpers.c
index e428aa43553..c487ef023cd 100644
--- a/src/gallium/drivers/panfrost/pan_helpers.c
+++ b/src/gallium/drivers/panfrost/pan_helpers.c
@@ -83,6 +83,37 @@ panfrost_analyze_sysvals(struct panfrost_shader_state *ss)
ss->dirty_shader = dirty_shader;
}
+/*
+ * Gets a GPU address for the associated index buffer. Only gauranteed to be
+ * good for the duration of the draw (transient), could last longer. Bounds are
+ * not calculated.
+ */
+mali_ptr
+panfrost_get_index_buffer(struct panfrost_batch *batch,
+ const struct pipe_draw_info *info,
+ const struct pipe_draw_start_count_bias *draw)
+{
+ struct panfrost_resource *rsrc = pan_resource(info->index.resource);
+ off_t offset = draw->start * info->index_size;
+
+ if (!info->has_user_indices) {
+ /* Only resources can be directly mapped */
+ panfrost_batch_read_rsrc(batch, rsrc, PIPE_SHADER_VERTEX);
+ return rsrc->image.data.bo->ptr.gpu + offset;
+ } else {
+ /* Otherwise, we need to upload to transient memory */
+ const uint8_t *ibuf8 = (const uint8_t *) info->index.user;
+ struct panfrost_ptr T =
+ pan_pool_alloc_aligned(&batch->pool.base,
+ draw->count *
+ info->index_size,
+ info->index_size);
+
+ memcpy(T.cpu, ibuf8 + offset, draw->count * info->index_size);
+ return T.gpu;
+ }
+}
+
/* Gets a GPU address for the associated index buffer. Only gauranteed to be
* good for the duration of the draw (transient), could last longer. Also get
* the bounds on the index buffer for the range accessed by the draw. We do
@@ -97,38 +128,19 @@ panfrost_get_index_buffer_bounded(struct panfrost_batch *batch,
{
struct panfrost_resource *rsrc = pan_resource(info->index.resource);
struct panfrost_context *ctx = batch->ctx;
- off_t offset = draw->start * info->index_size;
bool needs_indices = true;
- mali_ptr out = 0;
if (info->index_bounds_valid) {
*min_index = info->min_index;
*max_index = info->max_index;
needs_indices = false;
- }
-
- if (!info->has_user_indices) {
- /* Only resources can be directly mapped */
- panfrost_batch_read_rsrc(batch, rsrc, PIPE_SHADER_VERTEX);
- out = rsrc->image.data.bo->ptr.gpu + offset;
-
+ } else if (!info->has_user_indices) {
/* Check the cache */
needs_indices = !panfrost_minmax_cache_get(rsrc->index_cache,
draw->start,
draw->count,
min_index,
max_index);
- } else {
- /* Otherwise, we need to upload to transient memory */
- const uint8_t *ibuf8 = (const uint8_t *) info->index.user;
- struct panfrost_ptr T =
- pan_pool_alloc_aligned(&batch->pool.base,
- draw->count *
- info->index_size,
- info->index_size);
-
- memcpy(T.cpu, ibuf8 + offset, draw->count * info->index_size);
- out = T.gpu;
}
if (needs_indices) {
@@ -141,7 +153,7 @@ panfrost_get_index_buffer_bounded(struct panfrost_batch *batch,
*min_index, *max_index);
}
- return out;
+ return panfrost_get_index_buffer(batch, info, draw);
}
/**
More information about the mesa-commit
mailing list