v3d: fix flushing of SSBOs and shader images
[mesa.git] / src / gallium / drivers / v3d / v3d_cl.h
index 7025b5a672b1219dce36258e0e52301a4e7c6c6a..271d407132a674930829ebea04ef18678a07dd60 100644 (file)
 
 #include "util/u_math.h"
 #include "util/macros.h"
+#include "broadcom/cle/v3d_packet_helpers.h"
 
-struct vc5_bo;
-struct vc5_job;
-struct vc5_cl;
+struct v3d_bo;
+struct v3d_job;
+struct v3d_cl;
 
 /**
  * Undefined structure, used for typechecking that you're passing the pointers
  * to these functions correctly.
  */
-struct vc5_cl_out;
+struct v3d_cl_out;
 
 /** A reference to a BO used in the CL packing functions */
-struct vc5_cl_reloc {
-        struct vc5_bo *bo;
+struct v3d_cl_reloc {
+        struct v3d_bo *bo;
         uint32_t offset;
 };
 
-static inline void cl_pack_emit_reloc(struct vc5_cl *cl, const struct vc5_cl_reloc *);
+static inline void cl_pack_emit_reloc(struct v3d_cl *cl, const struct v3d_cl_reloc *);
 
-#define __gen_user_data struct vc5_cl
-#define __gen_address_type struct vc5_cl_reloc
+#define __gen_user_data struct v3d_cl
+#define __gen_address_type struct v3d_cl_reloc
 #define __gen_address_offset(reloc) (((reloc)->bo ? (reloc)->bo->offset : 0) + \
                                      (reloc)->offset)
 #define __gen_emit_reloc cl_pack_emit_reloc
+#define __gen_unpack_address(cl, s, e) __unpack_address(cl, s, e)
 
-struct vc5_cl {
+static inline struct v3d_cl_reloc
+__unpack_address(const uint8_t *cl, uint32_t s, uint32_t e)
+{
+    struct v3d_cl_reloc reloc =
+            { NULL, __gen_unpack_uint(cl, s, e) << (31 - (e - s)) };
+    return reloc;
+}
+
+struct v3d_cl {
         void *base;
-        struct vc5_job *job;
-        struct vc5_cl_out *next;
-        struct vc5_bo *bo;
+        struct v3d_job *job;
+        struct v3d_cl_out *next;
+        struct v3d_bo *bo;
         uint32_t size;
 };
 
-void vc5_init_cl(struct vc5_job *job, struct vc5_cl *cl);
-void vc5_destroy_cl(struct vc5_cl *cl);
-void vc5_dump_cl(void *cl, uint32_t size, bool is_render);
-uint32_t vc5_gem_hindex(struct vc5_job *job, struct vc5_bo *bo);
+void v3d_init_cl(struct v3d_job *job, struct v3d_cl *cl);
+void v3d_destroy_cl(struct v3d_cl *cl);
+void v3d_dump_cl(void *cl, uint32_t size, bool is_render);
+uint32_t v3d_gem_hindex(struct v3d_job *job, struct v3d_bo *bo);
 
 struct PACKED unaligned_16 { uint16_t x; };
 struct PACKED unaligned_32 { uint32_t x; };
 
-static inline uint32_t cl_offset(struct vc5_cl *cl)
+static inline uint32_t cl_offset(struct v3d_cl *cl)
 {
         return (char *)cl->next - (char *)cl->base;
 }
 
-static inline struct vc5_cl_reloc cl_get_address(struct vc5_cl *cl)
+static inline struct v3d_cl_reloc cl_get_address(struct v3d_cl *cl)
 {
-        return (struct vc5_cl_reloc){ .bo = cl->bo, .offset = cl_offset(cl) };
+        return (struct v3d_cl_reloc){ .bo = cl->bo, .offset = cl_offset(cl) };
 }
 
 static inline void
-cl_advance(struct vc5_cl_out **cl, uint32_t n)
+cl_advance(struct v3d_cl_out **cl, uint32_t n)
 {
-        (*cl) = (struct vc5_cl_out *)((char *)(*cl) + n);
+        (*cl) = (struct v3d_cl_out *)((char *)(*cl) + n);
 }
 
-static inline struct vc5_cl_out *
-cl_start(struct vc5_cl *cl)
+static inline struct v3d_cl_out *
+cl_start(struct v3d_cl *cl)
 {
         return cl->next;
 }
 
 static inline void
-cl_end(struct vc5_cl *cl, struct vc5_cl_out *next)
+cl_end(struct v3d_cl *cl, struct v3d_cl_out *next)
 {
         cl->next = next;
         assert(cl_offset(cl) <= cl->size);
@@ -100,71 +110,71 @@ cl_end(struct vc5_cl *cl, struct vc5_cl_out *next)
 
 
 static inline void
-put_unaligned_32(struct vc5_cl_out *ptr, uint32_t val)
+put_unaligned_32(struct v3d_cl_out *ptr, uint32_t val)
 {
         struct unaligned_32 *p = (void *)ptr;
         p->x = val;
 }
 
 static inline void
-put_unaligned_16(struct vc5_cl_out *ptr, uint16_t val)
+put_unaligned_16(struct v3d_cl_out *ptr, uint16_t val)
 {
         struct unaligned_16 *p = (void *)ptr;
         p->x = val;
 }
 
 static inline void
-cl_u8(struct vc5_cl_out **cl, uint8_t n)
+cl_u8(struct v3d_cl_out **cl, uint8_t n)
 {
         *(uint8_t *)(*cl) = n;
         cl_advance(cl, 1);
 }
 
 static inline void
-cl_u16(struct vc5_cl_out **cl, uint16_t n)
+cl_u16(struct v3d_cl_out **cl, uint16_t n)
 {
         put_unaligned_16(*cl, n);
         cl_advance(cl, 2);
 }
 
 static inline void
-cl_u32(struct vc5_cl_out **cl, uint32_t n)
+cl_u32(struct v3d_cl_out **cl, uint32_t n)
 {
         put_unaligned_32(*cl, n);
         cl_advance(cl, 4);
 }
 
 static inline void
-cl_aligned_u32(struct vc5_cl_out **cl, uint32_t n)
+cl_aligned_u32(struct v3d_cl_out **cl, uint32_t n)
 {
         *(uint32_t *)(*cl) = n;
         cl_advance(cl, 4);
 }
 
 static inline void
-cl_aligned_reloc(struct vc5_cl *cl,
-                 struct vc5_cl_out **cl_out,
-                 struct vc5_bo *bo, uint32_t offset)
+cl_aligned_reloc(struct v3d_cl *cl,
+                 struct v3d_cl_out **cl_out,
+                 struct v3d_bo *bo, uint32_t offset)
 {
         cl_aligned_u32(cl_out, bo->offset + offset);
-        vc5_job_add_bo(cl->job, bo);
+        v3d_job_add_bo(cl->job, bo);
 }
 
 static inline void
-cl_ptr(struct vc5_cl_out **cl, void *ptr)
+cl_ptr(struct v3d_cl_out **cl, void *ptr)
 {
-        *(struct vc5_cl_out **)(*cl) = ptr;
+        *(struct v3d_cl_out **)(*cl) = ptr;
         cl_advance(cl, sizeof(void *));
 }
 
 static inline void
-cl_f(struct vc5_cl_out **cl, float f)
+cl_f(struct v3d_cl_out **cl, float f)
 {
         cl_u32(cl, fui(f));
 }
 
 static inline void
-cl_aligned_f(struct vc5_cl_out **cl, float f)
+cl_aligned_f(struct v3d_cl_out **cl, float f)
 {
         cl_aligned_u32(cl, fui(f));
 }
@@ -172,18 +182,18 @@ cl_aligned_f(struct vc5_cl_out **cl, float f)
 /**
  * Reference to a BO with its associated offset, used in the pack process.
  */
-static inline struct vc5_cl_reloc
-cl_address(struct vc5_bo *bo, uint32_t offset)
+static inline struct v3d_cl_reloc
+cl_address(struct v3d_bo *bo, uint32_t offset)
 {
-        struct vc5_cl_reloc reloc = {
+        struct v3d_cl_reloc reloc = {
                 .bo = bo,
                 .offset = offset,
         };
         return reloc;
 }
 
-uint32_t vc5_cl_ensure_space(struct vc5_cl *cl, uint32_t size, uint32_t align);
-void vc5_cl_ensure_space_with_branch(struct vc5_cl *cl, uint32_t size);
+uint32_t v3d_cl_ensure_space(struct v3d_cl *cl, uint32_t size, uint32_t align);
+void v3d_cl_ensure_space_with_branch(struct v3d_cl *cl, uint32_t size);
 
 #define cl_packet_header(packet) V3DX(packet ## _header)
 #define cl_packet_length(packet) V3DX(packet ## _length)
@@ -191,7 +201,7 @@ void vc5_cl_ensure_space_with_branch(struct vc5_cl *cl, uint32_t size);
 #define cl_packet_struct(packet) V3DX(packet)
 
 static inline void *
-cl_get_emit_space(struct vc5_cl_out **cl, size_t size)
+cl_get_emit_space(struct v3d_cl_out **cl, size_t size)
 {
         void *addr = *cl;
         cl_advance(cl, size);
@@ -219,7 +229,7 @@ cl_get_emit_space(struct vc5_cl_out **cl, size_t size)
         *_loop_terminate = &name;                                \
         __builtin_expect(_loop_terminate != NULL, 1);            \
         ({                                                       \
-                struct vc5_cl_out *cl_out = cl_start(cl);        \
+                struct v3d_cl_out *cl_out = cl_start(cl);        \
                 cl_packet_pack(packet)(cl, (uint8_t *)cl_out, &name); \
                 cl_advance(&cl_out, cl_packet_length(packet));   \
                 cl_end(cl, cl_out);                              \
@@ -233,7 +243,7 @@ cl_get_emit_space(struct vc5_cl_out **cl, size_t size)
         *_loop_terminate = &name;                                \
         __builtin_expect(_loop_terminate != NULL, 1);            \
         ({                                                       \
-                struct vc5_cl_out *cl_out = cl_start(cl);        \
+                struct v3d_cl_out *cl_out = cl_start(cl);        \
                 uint8_t packed[cl_packet_length(packet)];         \
                 cl_packet_pack(packet)(cl, packed, &name);       \
                 for (int _i = 0; _i < cl_packet_length(packet); _i++) \
@@ -243,11 +253,14 @@ cl_get_emit_space(struct vc5_cl_out **cl, size_t size)
                 _loop_terminate = NULL;                          \
         }))                                                      \
 
-#define cl_emit_prepacked(cl, packet) do {                       \
-        memcpy((cl)->next, packet, sizeof(*packet));             \
-        cl_advance(&(cl)->next, sizeof(*packet));                \
+#define cl_emit_prepacked_sized(cl, packet, size) do {                \
+        memcpy((cl)->next, packet, size);             \
+        cl_advance(&(cl)->next, size);                \
 } while (0)
 
+#define cl_emit_prepacked(cl, packet) \
+        cl_emit_prepacked_sized(cl, packet, sizeof(*(packet)))
+
 #define v3dx_pack(packed, packet, name)                          \
         for (struct cl_packet_struct(packet) name = {            \
                 cl_packet_header(packet)                         \
@@ -270,10 +283,10 @@ cl_get_emit_space(struct vc5_cl_out **cl, size_t size)
  * for this exec.
  */
 static inline void
-cl_pack_emit_reloc(struct vc5_cl *cl, const struct vc5_cl_reloc *reloc)
+cl_pack_emit_reloc(struct v3d_cl *cl, const struct v3d_cl_reloc *reloc)
 {
         if (reloc->bo)
-                vc5_job_add_bo(cl->job, reloc->bo);
+                v3d_job_add_bo(cl->job, reloc->bo);
 }
 
 #endif /* VC5_CL_H */