[Mesa-dev] [PATCH 07/13] winsys/amdgpu: add amdgpu_ib and amdgpu_cs_from_ib helper functions

Nicolai Hähnle nhaehnle at gmail.com
Tue May 17 20:42:01 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

The latter function allows getting the containing amdgpu_cs from any IB
(including non-main ones).

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
---
 src/gallium/winsys/amdgpu/drm/amdgpu_cs.c |  4 ++++
 src/gallium/winsys/amdgpu/drm/amdgpu_cs.h | 40 +++++++++++++++++++++++++------
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
index 67b26db..1b2e89e 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
@@ -531,6 +531,10 @@ amdgpu_cs_create(struct radeon_winsys_ctx *rwctx,
    cs->flush_data = flush_ctx;
    cs->ring_type = ring_type;
 
+   cs->main.ib_type = IB_MAIN;
+   cs->const_ib.ib_type = IB_CONST;
+   cs->const_preamble_ib.ib_type = IB_CONST_PREAMBLE;
+
    if (!amdgpu_init_cs_context(&cs->csc1, ring_type)) {
       FREE(cs);
       return NULL;
diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h
index 69e5995..25bad07 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h
@@ -50,6 +50,13 @@ struct amdgpu_cs_buffer {
    enum radeon_bo_domain domains;
 };
 
+enum ib_type {
+   IB_CONST_PREAMBLE = 0,
+   IB_CONST = 1, /* the const IB must be first */
+   IB_MAIN = 2,
+   IB_NUM
+};
+
 struct amdgpu_ib {
    struct radeon_winsys_cs base;
 
@@ -57,13 +64,7 @@ struct amdgpu_ib {
    struct pb_buffer        *big_ib_buffer;
    uint8_t                 *ib_mapped;
    unsigned                used_ib_space;
-};
-
-enum ib_type {
-   IB_CONST_PREAMBLE = 0,
-   IB_CONST = 1, /* the const IB must be first */
-   IB_MAIN = 2,
-   IB_NUM
+   enum ib_type            ib_type;
 };
 
 struct amdgpu_cs_context {
@@ -148,12 +149,37 @@ static inline void amdgpu_fence_reference(struct pipe_fence_handle **dst,
 
 int amdgpu_lookup_buffer(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *bo);
 
+static inline struct amdgpu_ib *
+amdgpu_ib(struct radeon_winsys_cs *base)
+{
+   return (struct amdgpu_ib *)base;
+}
+
 static inline struct amdgpu_cs *
 amdgpu_cs(struct radeon_winsys_cs *base)
 {
+   assert(amdgpu_ib(base)->ib_type == IB_MAIN);
    return (struct amdgpu_cs*)base;
 }
 
+#define get_container(member_ptr, container_type, container_member) \
+   (container_type *)((char *)(member_ptr) - offsetof(container_type, container_member))
+
+static inline struct amdgpu_cs *
+amdgpu_cs_from_ib(struct amdgpu_ib *ib)
+{
+   switch (ib->ib_type) {
+   case IB_MAIN:
+      return get_container(ib, struct amdgpu_cs, main);
+   case IB_CONST:
+      return get_container(ib, struct amdgpu_cs, const_ib);
+   case IB_CONST_PREAMBLE:
+      return get_container(ib, struct amdgpu_cs, const_preamble_ib);
+   default:
+      unreachable("bad ib_type");
+   }
+}
+
 static inline boolean
 amdgpu_bo_is_referenced_by_cs(struct amdgpu_cs *cs,
                               struct amdgpu_winsys_bo *bo)
-- 
2.7.4



More information about the mesa-dev mailing list