Mesa (main): Revert "freedreno: Use a BO bitset for faster checks for resource referenced."
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Oct 4 21:10:40 UTC 2021
Module: Mesa
Branch: main
Commit: 52a2253071cccef9bfa9e5cdeda5948a40f6405a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=52a2253071cccef9bfa9e5cdeda5948a40f6405a
Author: Rob Clark <robdclark at chromium.org>
Date: Sat Oct 2 11:16:16 2021 -0700
Revert "freedreno: Use a BO bitset for faster checks for resource referenced."
This reverts commit 3ade94df862ccc9562fd82ff8baa14b62b8be031.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13159>
---
src/freedreno/drm/freedreno_bo.c | 13 --------
src/freedreno/drm/freedreno_drmif.h | 1 -
src/gallium/drivers/freedreno/freedreno_batch.c | 36 +++++-----------------
src/gallium/drivers/freedreno/freedreno_batch.h | 3 --
src/gallium/drivers/freedreno/freedreno_resource.c | 22 ++++++-------
src/gallium/drivers/freedreno/freedreno_resource.h | 7 +----
6 files changed, 19 insertions(+), 63 deletions(-)
diff --git a/src/freedreno/drm/freedreno_bo.c b/src/freedreno/drm/freedreno_bo.c
index 69a1d8628db..3854c8146ba 100644
--- a/src/freedreno/drm/freedreno_bo.c
+++ b/src/freedreno/drm/freedreno_bo.c
@@ -408,19 +408,6 @@ fd_bo_handle(struct fd_bo *bo)
return bo->handle;
}
-/**
- * Returns a small integer ID for the BO valid for the lifetime of the fd_bo.
- *
- * It happens to be the GEM handle, but don't use it as one since this getter
- * doesn't do any flushing or marking the BO as uncacheable like you would need
- * for most cases of using a GEM handle.
- */
-uint32_t
-fd_bo_id(struct fd_bo *bo)
-{
- return bo->handle;
-}
-
int
fd_bo_dmabuf(struct fd_bo *bo)
{
diff --git a/src/freedreno/drm/freedreno_drmif.h b/src/freedreno/drm/freedreno_drmif.h
index 258ed0d4de5..5c2b1d9ad18 100644
--- a/src/freedreno/drm/freedreno_drmif.h
+++ b/src/freedreno/drm/freedreno_drmif.h
@@ -204,7 +204,6 @@ struct fd_bo *fd_bo_ref(struct fd_bo *bo);
void fd_bo_del(struct fd_bo *bo);
int fd_bo_get_name(struct fd_bo *bo, uint32_t *name);
uint32_t fd_bo_handle(struct fd_bo *bo);
-uint32_t fd_bo_id(struct fd_bo *bo);
int fd_bo_dmabuf(struct fd_bo *bo);
uint32_t fd_bo_size(struct fd_bo *bo);
void *fd_bo_map(struct fd_bo *bo);
diff --git a/src/gallium/drivers/freedreno/freedreno_batch.c b/src/gallium/drivers/freedreno/freedreno_batch.c
index 17a5363b41b..f8ada703900 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch.c
+++ b/src/gallium/drivers/freedreno/freedreno_batch.c
@@ -282,9 +282,6 @@ batch_reset_resources(struct fd_batch *batch)
* rather than having any deleted keys.
*/
_mesa_set_clear(batch->resources, NULL);
-
- free(batch->bos);
- batch->bos = NULL;
}
static void
@@ -424,27 +421,13 @@ fd_batch_add_dep(struct fd_batch *batch, struct fd_batch *dep)
static void
fd_batch_add_resource(struct fd_batch *batch, struct fd_resource *rsc)
{
- if (fd_batch_references(batch, rsc))
- return;
-
- ASSERTED bool found = false;
+ bool found = false;
_mesa_set_search_or_add_pre_hashed(batch->resources, rsc->hash, rsc, &found);
- assert(!found);
-
- struct pipe_resource *table_ref = NULL;
- pipe_resource_reference(&table_ref, &rsc->b.b);
- p_atomic_inc(&rsc->batch_references);
-
- uint32_t handle = fd_bo_id(rsc->bo);
- if (batch->bos_size <= handle) {
- uint32_t new_size = MAX2(BITSET_WORDBITS,
- util_next_power_of_two(handle + 1));
- batch->bos = realloc(batch->bos, new_size / 8);
- memset(&batch->bos[batch->bos_size / BITSET_WORDBITS], 0,
- (new_size - batch->bos_size) / 8);
- batch->bos_size = new_size;
+ if (!found) {
+ struct pipe_resource *table_ref = NULL;
+ pipe_resource_reference(&table_ref, &rsc->b.b);
+ p_atomic_inc(&rsc->batch_references);
}
- BITSET_SET(batch->bos, handle);
}
void
@@ -460,13 +443,6 @@ fd_batch_resource_write(struct fd_batch *batch, struct fd_resource *rsc)
*/
rsc->valid = true;
- /* This has to happen before the early out, because
- * fd_bc_invalidate_resource() may not have been called on our context to
- * clear our writer when reallocating the BO, and otherwise we could end up
- * with our batch writing the BO but returning !fd_batch_references(rsc).
- */
- fd_batch_add_resource(batch, rsc);
-
struct fd_batch *prev_writer = fd_bc_writer(ctx, rsc);
if (prev_writer == batch)
return;
@@ -491,6 +467,8 @@ fd_batch_resource_write(struct fd_batch *batch, struct fd_resource *rsc)
pipe_resource_reference(&table_rsc_ref, &rsc->b.b);
_mesa_hash_table_insert_pre_hashed(cache->written_resources, rsc->hash, rsc,
batch);
+
+ fd_batch_add_resource(batch, rsc);
}
void
diff --git a/src/gallium/drivers/freedreno/freedreno_batch.h b/src/gallium/drivers/freedreno/freedreno_batch.h
index 6123016f759..c74e5e862f2 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch.h
+++ b/src/gallium/drivers/freedreno/freedreno_batch.h
@@ -246,9 +246,6 @@ struct fd_batch {
*/
struct set *resources;
- BITSET_WORD *bos;
- uint32_t bos_size;
-
/** key in batch-cache (if not null): */
struct fd_batch_key *key;
uint32_t hash;
diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c
index b701d96ecec..f09d194ea2f 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.c
+++ b/src/gallium/drivers/freedreno/freedreno_resource.c
@@ -433,6 +433,17 @@ fd_try_shadow_resource(struct fd_context *ctx, struct fd_resource *rsc,
DBG("shadow: %p (%d) -> %p (%d)", rsc, rsc->b.b.reference.count,
shadow, shadow->b.b.reference.count);
+ swap(rsc->bo, shadow->bo);
+ swap(rsc->valid, shadow->valid);
+
+ /* swap() doesn't work because you can't typeof() the bitfield. */
+ bool temp = shadow->needs_ubwc_clear;
+ shadow->needs_ubwc_clear = rsc->needs_ubwc_clear;
+ rsc->needs_ubwc_clear = temp;
+
+ swap(rsc->layout, shadow->layout);
+ rsc->seqno = p_atomic_inc_return(&ctx->screen->rsc_seqno);
+
/* At this point, the newly created shadow buffer is not referenced by any
* batches, but the existing rsc may be as a reader (we flushed writers
* above). We want to remove the old reader references to rsc so that we
@@ -455,17 +466,6 @@ fd_try_shadow_resource(struct fd_context *ctx, struct fd_resource *rsc,
}
}
- swap(rsc->bo, shadow->bo);
- swap(rsc->valid, shadow->valid);
-
- /* swap() doesn't work because you can't typeof() the bitfield. */
- bool temp = shadow->needs_ubwc_clear;
- shadow->needs_ubwc_clear = rsc->needs_ubwc_clear;
- rsc->needs_ubwc_clear = temp;
-
- swap(rsc->layout, shadow->layout);
- rsc->seqno = p_atomic_inc_return(&ctx->screen->rsc_seqno);
-
struct pipe_blit_info blit = {};
blit.dst.resource = prsc;
blit.dst.format = prsc->format;
diff --git a/src/gallium/drivers/freedreno/freedreno_resource.h b/src/gallium/drivers/freedreno/freedreno_resource.h
index 64184cb1cfc..ba2825a742c 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.h
+++ b/src/gallium/drivers/freedreno/freedreno_resource.h
@@ -27,7 +27,6 @@
#ifndef FREEDRENO_RESOURCE_H_
#define FREEDRENO_RESOURCE_H_
-#include "util/bitset.h"
#include "util/list.h"
#include "util/set.h"
#include "util/simple_mtx.h"
@@ -144,11 +143,7 @@ fd_memory_object(struct pipe_memory_object *pmemobj)
static inline bool
fd_batch_references(struct fd_batch *batch, struct fd_resource *rsc)
{
- /* Currently each rsc has an individual BO, so we can use the bo handle as a
- * unique index for the resource.
- */
- uint32_t handle = fd_bo_id(rsc->bo);
- return handle < batch->bos_size && BITSET_TEST(batch->bos, handle);
+ return _mesa_set_search_pre_hashed(batch->resources, rsc->hash, rsc) != NULL;
}
static inline struct fd_batch *
More information about the mesa-commit
mailing list