panfrost: Unify bifrost_scratchpad with mali_shared_memory
[mesa.git] / src / panfrost / include / panfrost-job.h
index dfc5d83a80d6136766062c871e1848a0eba92883..d0d56810ecc623bbe72b5749884fbeaec8ee931c 100644 (file)
@@ -229,6 +229,9 @@ struct mali_channel_swizzle {
 
 /* The top 3 bits specify how the bits of each component are interpreted. */
 
+/* e.g. ETC2_RGB8 */
+#define MALI_FORMAT_COMPRESSED (0 << 5)
+
 /* e.g. R11F_G11F_B10F */
 #define MALI_FORMAT_SPECIAL (2 << 5)
 
@@ -273,6 +276,16 @@ struct mali_channel_swizzle {
 #define MALI_CHANNEL_FLOAT 7
 
 enum mali_format {
+       MALI_ETC2_RGB8       = MALI_FORMAT_COMPRESSED | 0x1,
+       MALI_ETC2_R11_UNORM  = MALI_FORMAT_COMPRESSED | 0x2,
+       MALI_ETC2_RGBA8      = MALI_FORMAT_COMPRESSED | 0x3,
+       MALI_ETC2_RG11_UNORM = MALI_FORMAT_COMPRESSED | 0x4,
+       MALI_ETC2_R11_SNORM  = MALI_FORMAT_COMPRESSED | 0x11,
+       MALI_ETC2_RG11_SNORM = MALI_FORMAT_COMPRESSED | 0x12,
+       MALI_ETC2_RGB8A1     = MALI_FORMAT_COMPRESSED | 0x13,
+       MALI_ASTC_SRGB_SUPP  = MALI_FORMAT_COMPRESSED | 0x16,
+       MALI_ASTC_HDR_SUPP   = MALI_FORMAT_COMPRESSED | 0x17,
+
        MALI_RGB565         = MALI_FORMAT_SPECIAL | 0x0,
        MALI_RGB5_A1_UNORM  = MALI_FORMAT_SPECIAL | 0x2,
        MALI_RGB10_A2_UNORM = MALI_FORMAT_SPECIAL | 0x3,
@@ -371,7 +384,10 @@ enum mali_format {
 #define MALI_ALPHA_COVERAGE(clampf) ((uint16_t) (int) (clampf * 15.0f))
 #define MALI_GET_ALPHA_COVERAGE(nibble) ((float) nibble / 15.0f)
 
-/* Applies to midgard1.flags */
+/* Applies to midgard1.flags_lo */
+
+/* Should be set when the fragment shader updates the depth value. */
+#define MALI_WRITES_Z (1 << 4)
 
 /* Should the hardware perform early-Z testing? Normally should be set
  * for performance reasons. Clear if you use: discard,
@@ -393,6 +409,11 @@ enum mali_format {
 #define MALI_READS_ZS (1 << 8)
 #define MALI_READS_TILEBUFFER (1 << 12)
 
+/* Applies to midgard1.flags_hi */
+
+/* Should be set when the fragment shader updates the stencil value. */
+#define MALI_WRITES_S (1 << 2)
+
 /* The raw Midgard blend payload can either be an equation or a shader
  * address, depending on the context */
 
@@ -521,12 +542,12 @@ struct mali_shader_meta {
                 } bifrost1;
                 struct {
                         unsigned uniform_buffer_count : 4;
-                        unsigned flags : 12;
+                        unsigned flags_lo : 12;
 
                         /* vec4 units */
                         unsigned work_count : 5;
                         unsigned uniform_count : 5;
-                        unsigned unknown2 : 6;
+                        unsigned flags_hi : 6;
                 } midgard1;
         };
 
@@ -1035,17 +1056,6 @@ struct bifrost_tiler_only {
         u64 zero8;
 } __attribute__((packed));
 
-struct bifrost_scratchpad {
-        u32 zero;
-        u32 flags; // = 0x1f
-        /* This is a pointer to a CPU-inaccessible buffer, 16 pages, allocated
-         * during startup. It seems to serve the same purpose as the
-         * gpu_scratchpad in the SFBD for Midgard, although it's slightly
-         * larger.
-         */
-        mali_ptr gpu_scratchpad;
-} __attribute__((packed));
-
 struct mali_vertex_tiler_postfix {
         /* Zero for vertex jobs. Pointer to the position (gl_Position) varying
          * output from the vertex shader for tiler jobs.
@@ -1079,11 +1089,10 @@ struct mali_vertex_tiler_postfix {
         u64 viewport;
         u64 occlusion_counter; /* A single bit as far as I can tell */
 
-        /* Note: on Bifrost, this isn't actually the FBD. It points to
-         * bifrost_scratchpad instead. However, it does point to the same thing
-         * in vertex and tiler jobs.
-         */
-        mali_ptr framebuffer;
+        /* On Bifrost, this points directly to a mali_shared_memory structure.
+         * On Midgard, this points to a framebuffer (either SFBD or MFBD as
+         * tagged), which embeds a mali_shared_memory structure */
+        mali_ptr shared_memory;
 } __attribute__((packed));
 
 struct midgard_payload_vertex_tiler {
@@ -1449,14 +1458,41 @@ struct mali_sfbd_format {
         unsigned unk3 : 4;
 };
 
-struct mali_single_framebuffer {
-        u32 unknown1;
-        u32 unknown2;
+/* Shared structure at the start of framebuffer descriptors, or used bare for
+ * compute jobs, configuring stack and shared memory */
+
+struct mali_shared_memory {
+        u32 stack_shift : 4;
+        u32 unk0 : 28;
+
+        /* Configuration for shared memory for compute shaders.
+         * shared_workgroup_count is logarithmic and may be computed for a
+         * compute shader using shared memory as:
+         *
+         *  shared_workgroup_count = MAX2(ceil(log2(count_x)) + ... + ceil(log2(count_z), 10)
+         *
+         * For compute shaders that don't use shared memory, or non-compute
+         * shaders, this is set to ~0
+         */
+
+        u32 shared_workgroup_count : 5;
+        u32 shared_unk1 : 3;
+        u32 shared_shift : 4;
+        u32 shared_zero : 20;
+
         mali_ptr scratchpad;
 
-        u64 zero1;
-        u64 zero0;
+        /* For compute shaders, the RAM backing of workgroup-shared memory. For
+         * fragment shaders on Bifrost, apparently multisampling locations */
+
+        mali_ptr shared_memory;
+        mali_ptr unknown1;
+} __attribute__((packed));
+
+
 
+struct mali_single_framebuffer {
+        struct mali_shared_memory shared_memory;
         struct mali_sfbd_format format;
 
         u32 clear_flags;
@@ -1519,13 +1555,6 @@ struct mali_single_framebuffer {
         /* More below this, maybe */
 } __attribute__((packed));
 
-/* On Midgard, this "framebuffer descriptor" is used for the framebuffer field
- * of compute jobs. Superficially resembles a single framebuffer descriptor */
-
-struct mali_compute_fbd {
-        u32 unknown1[8];
-} __attribute__((packed));
-
 /* Format bits for the render target flags */
 
 #define MALI_MFBD_FORMAT_MSAA    (1 << 1)
@@ -1597,11 +1626,10 @@ struct bifrost_render_target {
  * - TODO: Anything else?
  */
 
-/* Flags field: note, these are guesses */
+/* flags_hi */
+#define MALI_EXTRA_PRESENT      (0x10)
 
-#define MALI_EXTRA_PRESENT      (0x400)
-#define MALI_EXTRA_AFBC         (0x20)
-#define MALI_EXTRA_AFBC_ZS      (0x10)
+/* flags_lo */
 #define MALI_EXTRA_ZS           (0x4)
 
 struct bifrost_fb_extra {
@@ -1609,7 +1637,9 @@ struct bifrost_fb_extra {
         /* Each tile has an 8 byte checksum, so the stride is "width in tiles * 8" */
         u32 checksum_stride;
 
-        u32 flags;
+        unsigned flags_lo : 4;
+        enum mali_block_format zs_block : 2;
+        unsigned flags_hi : 26;
 
         union {
                 /* Note: AFBC is only allowed for 24/8 combined depth/stencil. */
@@ -1653,15 +1683,8 @@ struct bifrost_fb_extra {
 #define MALI_MFBD_EXTRA (1 << 13)
 
 struct bifrost_framebuffer {
-        u32 stack_shift : 4;
-        u32 unk0 : 28;
-
-        u32 unknown2; // = 0x1f, same as SFBD
-        mali_ptr scratchpad;
+        struct mali_shared_memory shared_memory;
 
-        /* 0x10 */
-        mali_ptr sample_locations;
-        mali_ptr unknown1;
         /* 0x20 */
         u16 width1, height1;
         u32 zero3;