panfrost: Enumify bifrost blend types
[mesa.git] / src / panfrost / include / panfrost-job.h
index 1a59f4c77c838b3b52ad400ae986ec25bc1afeb0..ae70cb6b6562a63bc5915f5347af10bd88034d3c 100644 (file)
@@ -287,16 +287,17 @@ enum mali_format {
        MALI_ASTC_HDR_SUPP   = MALI_FORMAT_COMPRESSED | 0x17,
 
        MALI_RGB565         = MALI_FORMAT_SPECIAL | 0x0,
+       MALI_RGB5_X1_UNORM  = MALI_FORMAT_SPECIAL | 0x1,
        MALI_RGB5_A1_UNORM  = MALI_FORMAT_SPECIAL | 0x2,
        MALI_RGB10_A2_UNORM = MALI_FORMAT_SPECIAL | 0x3,
        MALI_RGB10_A2_SNORM = MALI_FORMAT_SPECIAL | 0x5,
        MALI_RGB10_A2UI     = MALI_FORMAT_SPECIAL | 0x7,
        MALI_RGB10_A2I      = MALI_FORMAT_SPECIAL | 0x9,
 
-       /* YUV formats */
-       MALI_NV12           = MALI_FORMAT_SPECIAL | 0xc,
+       MALI_RGB332_UNORM   = MALI_FORMAT_SPECIAL | 0xb,
+       MALI_RGB233_UNORM   = MALI_FORMAT_SPECIAL | 0xc,
 
-       MALI_Z32_UNORM      = MALI_FORMAT_SPECIAL | 0xD,
+       MALI_Z32_UNORM      = MALI_FORMAT_SPECIAL | 0xd,
        MALI_R32_FIXED      = MALI_FORMAT_SPECIAL | 0x11,
        MALI_RG32_FIXED     = MALI_FORMAT_SPECIAL | 0x12,
        MALI_RGB32_FIXED    = MALI_FORMAT_SPECIAL | 0x13,
@@ -456,6 +457,15 @@ struct midgard_blend_rt {
 /* On Bifrost systems (all MRT), each render target gets one of these
  * descriptors */
 
+enum bifrost_shader_type {
+        BIFROST_BLEND_F16 = 0,
+        BIFROST_BLEND_F32 = 1,
+        BIFROST_BLEND_I32 = 2,
+        BIFROST_BLEND_U32 = 3,
+        BIFROST_BLEND_I16 = 4,
+        BIFROST_BLEND_U16 = 5,
+};
+
 struct bifrost_blend_rt {
         /* This is likely an analogue of the flags on
          * midgard_blend_rt */
@@ -498,14 +508,8 @@ struct bifrost_blend_rt {
                        enum mali_format format : 8;
 
                        /* Type of the shader output variable. Note, this can
-                        * be different from the format.
-                        *
-                        * 0: f16 (mediump float)
-                        * 1: f32 (highp float)
-                        * 2: i32 (highp int)
-                        * 3: u32 (highp uint)
-                        * 4: i16 (mediump int)
-                        * 5: u16 (mediump uint)
+                         * be different from the format.
+                         * enum bifrost_shader_type
                         */
                        u32 shader_type : 3;
                        u32 zero : 9;
@@ -601,6 +605,11 @@ struct mali_shader_meta {
                          * - R61 : gl_SampleMaskIn and gl_SampleID, used by
                          *   varying interpolation.
                          * - R62 : unknown (bit always unset).
+                         *
+                         * Later GPUs (starting with Mali-G52?) support
+                         * preloading float varyings into r0-r7. This is
+                         * indicated by setting 0x40. There is no distinction
+                         * here between 1 varying and 2.
                          */
                         u32 preload_regs : 8;
                         /* In units of 8 bytes or 64 bits, since the
@@ -614,8 +623,7 @@ struct mali_shader_meta {
                 } midgard2;
         };
 
-        /* zero on bifrost */
-        u32 unknown2_8;
+        u32 padding;
 
         /* Blending information for the older non-MRT Midgard HW. Check for
          * MALI_HAS_BLEND_SHADER to decide how to interpret.
@@ -877,20 +885,23 @@ struct mali_attr_meta {
 /* ORed into an MFBD address to specify the fbx section is included */
 #define MALI_MFBD_TAG_EXTRA (0x2)
 
-struct mali_uniform_buffer_meta {
-        /* This is actually the size minus 1 (MALI_POSITIVE), in units of 16
-         * bytes. This gives a maximum of 2^14 bytes, which just so happens to
-         * be the GL minimum-maximum for GL_MAX_UNIFORM_BLOCK_SIZE.
-         */
-        u64 size : 10;
+/* Uniform buffer objects are 64-bit fields divided as:
+ *
+ *      u64 size : 10;
+ *      mali_ptr ptr : 64 - 10;
+ *
+ * The size is actually the size minus 1 (MALI_POSITIVE), in units of 16 bytes.
+ * This gives a maximum of 2^14 bytes, which just so happens to be the GL
+ * minimum-maximum for GL_MAX_UNIFORM_BLOCK_SIZE.
+ *
+ * The pointer is missing the bottom 2 bits and top 8 bits. The top 8 bits
+ * should be 0 for userspace pointers, according to
+ * https://lwn.net/Articles/718895/. By reusing these bits, we can make each
+ * entry in the table only 64 bits.
+ */
 
-        /* This is missing the bottom 2 bits and top 8 bits. The top 8 bits
-         * should be 0 for userspace pointers, according to
-         * https://lwn.net/Articles/718895/. By reusing these bits, we can make
-         * each entry in the table only 64 bits.
-         */
-        mali_ptr ptr : 64 - 10;
-};
+#define MALI_MAKE_UBO(elements, ptr) \
+        (MALI_POSITIVE((elements)) | (((ptr) >> 2) << 10))
 
 /* On Bifrost, these fields are the same between the vertex and tiler payloads.
  * They also seem to be the same between Bifrost and Midgard. They're shared in
@@ -1011,14 +1022,6 @@ union midgard_primitive_size {
         u64 pointer;
 };
 
-struct bifrost_vertex_only {
-        u32 unk2; /* =0x2 */
-
-        u32 zero0;
-
-        u64 zero1;
-} __attribute__((packed));
-
 struct bifrost_tiler_heap_meta {
         u32 zero;
         u32 heap_size;
@@ -1028,12 +1031,14 @@ struct bifrost_tiler_heap_meta {
         mali_ptr tiler_heap_end;
 
         /* hierarchy weights? but they're still 0 after the job has run... */
-        u32 zeros[12];
+        u32 zeros[10];
+        u32 unk1;
+        u32 unk7e007e;
 } __attribute__((packed));
 
 struct bifrost_tiler_meta {
         u64 zero0;
-        u16 hierarchy_mask;
+        u16 hierarchy_mask; /* Five values observed: 0xa, 0x14, 0x28, 0x50, 0xa0 */
         u16 flags;
         u16 width;
         u16 height;
@@ -1050,24 +1055,25 @@ struct bifrost_tiler_only {
         mali_ptr tiler_meta;
 
         u64 zero1, zero2, zero3, zero4, zero5, zero6;
-
-        u32 gl_enables;
-        u32 zero7;
-        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 {
+        u16 gl_enables; // 0x6 on Midgard, 0x2 on Bifrost
+
+        /* Both zero for non-instanced draws. For instanced draws, a
+         * decomposition of padded_num_vertices. See the comments about the
+         * corresponding fields in mali_attr for context. */
+
+        unsigned instance_shift : 5;
+        unsigned instance_odd : 3;
+
+        u8 zero4;
+
+        /* Offset for first vertex in buffer */
+        u32 offset_start;
+
+       u64 zero5;
+
         /* Zero for vertex jobs. Pointer to the position (gl_Position) varying
          * output from the vertex shader for tiler jobs.
          */
@@ -1079,11 +1085,12 @@ struct mali_vertex_tiler_postfix {
          */
         u64 uniform_buffers;
 
-        /* This is a pointer to an array of pointers to the texture
+        /* On Bifrost, this is a pointer to an array of bifrost_texture_descriptor.
+         * On Midgard, this is a pointer to an array of pointers to the texture
          * descriptors, number of pointers bounded by number of textures. The
          * indirection is needed to accomodate varying numbers and sizes of
          * texture descriptors */
-        u64 texture_trampoline;
+        u64 textures;
 
         /* For OpenGL, from what I've seen, this is intimately connected to
          * texture_meta. cwabbott says this is not the case under Vulkan, hence
@@ -1100,32 +1107,14 @@ 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 {
         struct mali_vertex_tiler_prefix prefix;
-
-        u16 gl_enables; // 0x5
-
-        /* Both zero for non-instanced draws. For instanced draws, a
-         * decomposition of padded_num_vertices. See the comments about the
-         * corresponding fields in mali_attr for context. */
-
-        unsigned instance_shift : 5;
-        unsigned instance_odd : 3;
-
-        u8 zero4;
-
-        /* Offset for first vertex in buffer */
-        u32 offset_start;
-
-       u64 zero5;
-
         struct mali_vertex_tiler_postfix postfix;
 
         union midgard_primitive_size primitive_size;
@@ -1133,7 +1122,6 @@ struct midgard_payload_vertex_tiler {
 
 struct bifrost_payload_vertex {
         struct mali_vertex_tiler_prefix prefix;
-        struct bifrost_vertex_only vertex;
         struct mali_vertex_tiler_postfix postfix;
 } __attribute__((packed));
 
@@ -1148,7 +1136,6 @@ struct bifrost_payload_fused {
         struct bifrost_tiler_only tiler;
         struct mali_vertex_tiler_postfix tiler_postfix;
         u64 padding; /* zero */
-        struct bifrost_vertex_only vertex;
         struct mali_vertex_tiler_postfix vertex_postfix;
 } __attribute__((packed));
 
@@ -1255,6 +1242,38 @@ struct mali_texture_descriptor {
         uint32_t unknown7;
 } __attribute__((packed));
 
+/* While Midgard texture descriptors are variable length, Bifrost descriptors
+ * are fixed like samplers with more pointers to expand if necessary */
+
+struct bifrost_texture_descriptor {
+        unsigned format_unk : 4; /* 2 */
+        enum mali_texture_type type : 2;
+        unsigned format_unk2 : 16; /* 0 */
+        enum mali_format format : 8;
+        unsigned srgb : 1;
+        unsigned format_unk3 : 1; /* 0 */
+
+        uint16_t width; /* MALI_POSITIVE */
+        uint16_t height; /* MALI_POSITIVE */
+
+        /* OpenGL swizzle */
+        unsigned swizzle : 12;
+        enum mali_texture_layout layout : 4;
+        uint8_t levels : 8; /* Number of levels-1 if mipmapped, 0 if not */
+        unsigned unk1 : 4;
+
+        unsigned levels_unk : 24; /* 0 */
+        unsigned level_2 : 8; /* Number of levels, again? */
+
+        mali_ptr payload;
+
+        uint16_t array_size;
+        uint16_t unk4;
+
+        uint16_t depth;
+        uint16_t unk5;
+} __attribute__((packed));
+
 /* filter_mode */
 
 #define MALI_SAMP_MAG_NEAREST (1 << 0)
@@ -1316,6 +1335,35 @@ struct mali_sampler_descriptor {
         float border_color[4];
 } __attribute__((packed));
 
+/* Bifrost sampler descriptors look pretty similar */
+
+#define BIFROST_SAMP_MIN_NEAREST        (1)
+#define BIFROST_SAMP_MAG_LINEAR         (1)
+
+struct bifrost_sampler_descriptor {
+        uint8_t unk1;
+
+        enum mali_wrap_mode wrap_s : 4;
+        enum mali_wrap_mode wrap_t : 4;
+        enum mali_wrap_mode wrap_r : 4;
+        uint8_t unk8 : 4;
+
+        uint8_t unk2 : 3;
+        uint8_t min_filter : 1;
+        uint8_t norm_coords : 1;
+        uint8_t zero1 : 1;
+        uint8_t mip_filter : 1;
+        uint8_t mag_filter : 1;
+
+        int16_t min_lod;
+        int16_t max_lod;
+        int8_t zero2;
+        int8_t zero3;
+
+        uint32_t zero4;
+        uint32_t zero5;
+} __attribute__((packed));
+
 /* viewport0/viewport1 form the arguments to glViewport. viewport1 is
  * modified by MALI_POSITIVE; viewport0 is as-is.
  */
@@ -1470,14 +1518,48 @@ 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;
 
+        /* 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));
+
+/* Configures multisampling on Bifrost fragment jobs */
+
+struct bifrost_multisampling {
         u64 zero1;
-        u64 zero0;
+        u64 zero2;
+        mali_ptr sample_locations;
+        u64 zero4;
+} __attribute__((packed));
 
+struct mali_single_framebuffer {
+        struct mali_shared_memory shared_memory;
         struct mali_sfbd_format format;
 
         u32 clear_flags;
@@ -1540,13 +1622,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)
@@ -1576,7 +1651,7 @@ struct mali_rt_format {
         unsigned no_preload : 1;
 } __attribute__((packed));
 
-struct bifrost_render_target {
+struct mali_render_target {
         struct mali_rt_format format;
 
         u64 zero1;
@@ -1609,7 +1684,7 @@ struct bifrost_render_target {
         u32 clear_color_4; // always equal, but unclear function?
 } __attribute__((packed));
 
-/* An optional part of bifrost_framebuffer. It comes between the main structure
+/* An optional part of mali_framebuffer. It comes between the main structure
  * and the array of render targets. It must be included if any of these are
  * enabled:
  *
@@ -1624,7 +1699,7 @@ struct bifrost_render_target {
 /* flags_lo */
 #define MALI_EXTRA_ZS           (0x4)
 
-struct bifrost_fb_extra {
+struct mali_framebuffer_extra  {
         mali_ptr checksum;
         /* Each tile has an 8 byte checksum, so the stride is "width in tiles * 8" */
         u32 checksum_stride;
@@ -1660,7 +1735,9 @@ struct bifrost_fb_extra {
         };
 
 
-        u64 zero3, zero4;
+        u32 clear_color_1;
+        u32 clear_color_2;
+        u64 zero3;
 } __attribute__((packed));
 
 /* Flags for mfbd_flags */
@@ -1670,20 +1747,16 @@ struct bifrost_fb_extra {
 
 #define MALI_MFBD_DEPTH_WRITE (1 << 10)
 
-/* The MFBD contains the extra bifrost_fb_extra section */
+/* The MFBD contains the extra mali_framebuffer_extra  section */
 
 #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_framebuffer {
+        union {
+                struct mali_shared_memory shared_memory;
+                struct bifrost_multisampling msaa;
+        };
 
-        /* 0x10 */
-        mali_ptr sample_locations;
-        mali_ptr unknown1;
         /* 0x20 */
         u16 width1, height1;
         u32 zero3;
@@ -1698,10 +1771,16 @@ struct bifrost_framebuffer {
         u32 mfbd_flags : 24; // = 0x100
         float clear_depth;
 
-        struct midgard_tiler_descriptor tiler;
+        union {
+                struct midgard_tiler_descriptor tiler;
+                struct {
+                        mali_ptr tiler_meta;
+                        u32 zeros[16];
+                };
+        };
 
-        /* optional: struct bifrost_fb_extra extra */
-        /* struct bifrost_render_target rts[] */
+        /* optional: struct mali_framebuffer_extra  extra */
+        /* struct mali_render_target rts[] */
 } __attribute__((packed));
 
 #endif /* __PANFROST_JOB_H__ */