#define MALI_ALPHA_TO_COVERAGE (1 << 1)
+#define MALI_SFBD_ENABLE (1 << 4)
+#define MALI_SFBD_SRGB (1 << 8)
#define MALI_NO_DITHER (1 << 9)
#define MALI_DEPTH_RANGE_A (1 << 12)
#define MALI_DEPTH_RANGE_B (1 << 13)
#define MALI_NO_MSAA (1 << 14)
-/* Stencil test state is all encoded in a single u32, just with a lot of
- * enums... */
-
-struct mali_stencil_test {
- unsigned ref : 8;
- unsigned mask : 8;
- enum mali_func func : 3;
- enum mali_stencil_op sfail : 3;
- enum mali_stencil_op dpfail : 3;
- enum mali_stencil_op dppass : 3;
- unsigned zero : 4;
-} __attribute__((packed));
-
#define MALI_MASK_R (1 << 0)
#define MALI_MASK_G (1 << 1)
#define MALI_MASK_B (1 << 2)
unsigned complement_dominant : 1;
} __attribute__((packed));
-struct mali_blend_equation {
- /* Of type mali_blend_mode */
- unsigned rgb_mode : 12;
- unsigned alpha_mode : 12;
-
- unsigned zero1 : 4;
-
- /* Corresponds to MALI_MASK_* above and glColorMask arguments */
-
- unsigned color_mask : 4;
-} __attribute__((packed));
-
-/* Used with channel swizzling */
-enum mali_channel {
- MALI_CHANNEL_RED = 0,
- MALI_CHANNEL_GREEN = 1,
- MALI_CHANNEL_BLUE = 2,
- MALI_CHANNEL_ALPHA = 3,
- MALI_CHANNEL_ZERO = 4,
- MALI_CHANNEL_ONE = 5,
- MALI_CHANNEL_RESERVED_0 = 6,
- MALI_CHANNEL_RESERVED_1 = 7,
-};
-
-struct mali_channel_swizzle {
- enum mali_channel r : 3;
- enum mali_channel g : 3;
- enum mali_channel b : 3;
- enum mali_channel a : 3;
-} __attribute__((packed));
-
/* Compressed per-pixel formats. Each of these formats expands to one to four
* floating-point or integer numbers, as defined by the OpenGL specification.
* There are various places in OpenGL where the user can specify a compressed
#define MALI_CHANNEL_FLOAT 7
#define MALI_EXTRACT_BITS(fmt) (fmt & 0x7)
-enum mali_format {
- /* Not all formats are in fact available, need to query dynamically to
- * check. Factory settings for Juno enables only ETC2 and ASTC, no
- * DXT/RGTC formats.
- * */
-
- /* 0x0 invalid */
- 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,
- /* 0x5 reserved */
- MALI_NXR = MALI_FORMAT_COMPRESSED | 0x6, /* Nokia eXtended Range */
- MALI_BC1_UNORM = MALI_FORMAT_COMPRESSED | 0x7, /* DXT1 */
- MALI_BC2_UNORM = MALI_FORMAT_COMPRESSED | 0x8, /* DXT3 */
- MALI_BC3_UNORM = MALI_FORMAT_COMPRESSED | 0x9, /* DXT5 */
- MALI_BC4_UNORM = MALI_FORMAT_COMPRESSED | 0xA, /* RGTC1_UNORM */
- MALI_BC4_SNORM = MALI_FORMAT_COMPRESSED | 0xB, /* RGTC1_SNORM */
- MALI_BC5_UNORM = MALI_FORMAT_COMPRESSED | 0xC, /* RGTC2_UNORM */
- MALI_BC5_SNORM = MALI_FORMAT_COMPRESSED | 0xD, /* RGTC2_SNORM */
- MALI_BC6H_UF16 = MALI_FORMAT_COMPRESSED | 0xE,
- MALI_BC6H_SF16 = MALI_FORMAT_COMPRESSED | 0xF,
- MALI_BC7_UNORM = MALI_FORMAT_COMPRESSED | 0x10,
- MALI_ETC2_R11_SNORM = MALI_FORMAT_COMPRESSED | 0x11, /* EAC_SNORM */
- MALI_ETC2_RG11_SNORM = MALI_FORMAT_COMPRESSED | 0x12, /* EAC_SNORM */
- MALI_ETC2_RGB8A1 = MALI_FORMAT_COMPRESSED | 0x13,
- MALI_ASTC_3D_LDR = MALI_FORMAT_COMPRESSED | 0x14,
- MALI_ASTC_3D_HDR = MALI_FORMAT_COMPRESSED | 0x15,
- MALI_ASTC_2D_LDR = MALI_FORMAT_COMPRESSED | 0x16,
- MALI_ASTC_2D_HDR = 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,
-
- MALI_RGB332_UNORM = MALI_FORMAT_SPECIAL | 0xb,
- MALI_RGB233_UNORM = MALI_FORMAT_SPECIAL | 0xc,
-
- MALI_Z24X8_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,
- MALI_RGBA32_FIXED = MALI_FORMAT_SPECIAL | 0x14,
- MALI_R11F_G11F_B10F = MALI_FORMAT_SPECIAL | 0x19,
- MALI_R9F_G9F_B9F_E5F = MALI_FORMAT_SPECIAL | 0x1b,
- /* Only used for varyings, to indicate the transformed gl_Position */
- MALI_VARYING_POS = MALI_FORMAT_SPECIAL | 0x1e,
- /* Only used for varyings, to indicate that the write should be
- * discarded.
- */
- MALI_VARYING_DISCARD = MALI_FORMAT_SPECIAL | 0x1f,
-
- MALI_R8_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_8,
- MALI_R16_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_16,
- MALI_R32_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_32,
- MALI_RG8_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_8,
- MALI_RG16_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_16,
- MALI_RG32_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_32,
- MALI_RGB8_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_8,
- MALI_RGB16_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_16,
- MALI_RGB32_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_32,
- MALI_RGBA8_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_8,
- MALI_RGBA16_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_16,
- MALI_RGBA32_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_32,
-
- MALI_R8UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_8,
- MALI_R16UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_16,
- MALI_R32UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_32,
- MALI_RG8UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_8,
- MALI_RG16UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_16,
- MALI_RG32UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_32,
- MALI_RGB8UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_8,
- MALI_RGB16UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_16,
- MALI_RGB32UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_32,
- MALI_RGBA8UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_8,
- MALI_RGBA16UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_16,
- MALI_RGBA32UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_32,
-
- MALI_R8_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_8,
- MALI_R16_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_16,
- MALI_R32_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_32,
- MALI_R32F = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_FLOAT,
- MALI_RG8_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_8,
- MALI_RG16_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_16,
- MALI_RG32_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_32,
- MALI_RG32F = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_FLOAT,
- MALI_RGB8_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_8,
- MALI_RGB16_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_16,
- MALI_RGB32_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_32,
- MALI_RGB32F = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_FLOAT,
- MALI_RGBA4_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_4,
- MALI_RGBA8_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_8,
- MALI_RGBA16_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_16,
- MALI_RGBA32_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_32,
- MALI_RGBA32F = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_FLOAT,
-
- MALI_R8I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_8,
- MALI_R16I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_16,
- MALI_R32I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_32,
- MALI_R16F = MALI_FORMAT_SINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_FLOAT,
- MALI_RG8I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_8,
- MALI_RG16I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_16,
- MALI_RG32I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_32,
- MALI_RG16F = MALI_FORMAT_SINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_FLOAT,
- MALI_RGB8I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_8,
- MALI_RGB16I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_16,
- MALI_RGB32I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_32,
- MALI_RGB16F = MALI_FORMAT_SINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_FLOAT,
- MALI_RGBA8I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_8,
- MALI_RGBA16I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_16,
- MALI_RGBA32I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_32,
- MALI_RGBA16F = MALI_FORMAT_SINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_FLOAT,
-
- MALI_RGBA4 = MALI_FORMAT_SPECIAL2 | 0x8,
- MALI_RGBA8_2 = MALI_FORMAT_SPECIAL2 | 0xd,
- MALI_RGB10_A2_2 = MALI_FORMAT_SPECIAL2 | 0xe,
-};
-
-
-/* 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? Set if the shader does not use
- * discard, alpha-to-coverage, shader depth writes, and if the shader has no
- * side effects (writes to global memory or images) unless early-z testing is
- * forced in the shader.
- */
-
-#define MALI_EARLY_Z (1 << 6)
-
-/* Should the hardware calculate derivatives (via helper invocations)? Set in a
- * fragment shader that uses texturing or derivative functions */
-
-#define MALI_HELPER_INVOCATIONS (1 << 7)
-
-/* Flags denoting the fragment shader's use of tilebuffer readback. If the
- * shader might read any part of the tilebuffer, set MALI_READS_TILEBUFFER. If
- * it might read depth/stencil in particular, also set MALI_READS_ZS */
-
-#define MALI_READS_ZS (1 << 8)
-
-/* The shader might write to global memory (via OpenCL, SSBOs, or images).
- * Reading is okay, as are ordinary writes to the tilebuffer/varyings. Setting
- * incurs a performance penalty. On a fragment shader, this bit implies there
- * are side effects, hence it interacts with early-z. */
-#define MALI_WRITES_GLOBAL (1 << 9)
-
-#define MALI_READS_TILEBUFFER (1 << 10)
-
-/* Applies to midgard1.flags_hi */
-
-/* Should be set when the fragment shader updates the stencil value. */
-#define MALI_WRITES_S (1 << 2)
-
-/* Mode to suppress generation of Infinity and NaN values by clamping inf
- * (-inf) to MAX_FLOAT (-MIN_FLOAT) and flushing NaN to 0.0
- *
- * Compare suppress_inf/suppress_nan flags on the Bifrost clause header for the
- * same functionality.
- *
- * This is not conformant on GLES3 or OpenCL, but is optional on GLES2, where
- * it works around app bugs (e.g. in glmark2-es2 -bterrain with FP16).
- */
-#define MALI_SUPPRESS_INF_NAN (1 << 3)
-
-/* Flags for bifrost1.unk1 */
-
-/* Shader uses less than 32 registers, partitioned as [R0, R15] U [R48, R63],
- * allowing for full thread count. If clear, the full [R0, R63] register set is
- * available at half thread count */
-#define MALI_BIFROST_FULL_THREAD (1 << 9)
-
-/* Enable early-z testing (presumably). This flag may not be set if the shader:
- *
- * - Uses blending
- * - Uses discard
- * - Writes gl_FragDepth
- *
- * This differs from Midgard which sets the MALI_EARLY_Z flag even with
- * blending, although I've begun to suspect that flag does not in fact enable
- * EARLY_Z alone. */
-#define MALI_BIFROST_EARLY_Z (1 << 15)
-
-/* First clause type is ATEST */
-#define MALI_BIFROST_FIRST_ATEST (1 << 26)
-
/* The raw Midgard blend payload can either be an equation or a shader
* address, depending on the context */
mali_ptr shader;
struct {
- struct mali_blend_equation equation;
+ struct mali_blend_equation_packed equation;
float constant;
};
};
-/* We need to load the tilebuffer to blend (i.e. the destination factor is not
- * ZERO) */
-
-#define MALI_BLEND_LOAD_TIB (0x1)
-
-/* A blend shader is used to blend this render target */
-#define MALI_BLEND_MRT_SHADER (0x2)
-
-/* On MRT Midgard systems (using an MFBD), each render target gets its own
- * blend descriptor */
-
-#define MALI_BLEND_SRGB (0x400)
-
-/* Dithering is specified here for MFBD, otherwise NO_DITHER for SFBD */
-#define MALI_BLEND_NO_DITHER (0x800)
-
struct midgard_blend_rt {
- /* Flags base value of 0x200 to enable the render target.
- * OR with 0x1 for blending (anything other than REPLACE).
- * OR with 0x2 for programmable blending
- * OR with MALI_BLEND_SRGB for implicit sRGB
- */
-
- u64 flags;
+ struct mali_blend_flags_packed flags;
+ u32 zero;
union midgard_blend blend;
} __attribute__((packed));
*/
u16 constant;
- struct mali_blend_equation equation;
+ struct mali_blend_equation_packed equation;
/*
* - 0x19 normally
u16 varying_count;
union {
- struct {
- u32 uniform_buffer_count : 4;
- u32 unk1 : 28; // = 0x800000 for vertex, 0x958020 for tiler
- } bifrost1;
- struct {
- unsigned uniform_buffer_count : 4;
- unsigned flags_lo : 12;
-
- /* vec4 units */
- unsigned work_count : 5;
- unsigned uniform_count : 5;
- unsigned flags_hi : 6;
- } midgard1;
+ struct mali_bifrost_properties_packed bifrost_props;
+ struct mali_midgard_properties_packed midgard_props;
};
/* Same as glPolygoOffset() arguments */
u8 stencil_mask_back;
u16 unknown2_4;
- struct mali_stencil_test stencil_front;
- struct mali_stencil_test stencil_back;
+ struct mali_stencil_packed stencil_front;
+ struct mali_stencil_packed stencil_back;
union {
- struct {
- u32 unk3 : 7;
- /* On Bifrost, some system values are preloaded in
- * registers R55-R62 by the thread dispatcher prior to
- * the start of shader execution. This is a bitfield
- * with one entry for each register saying which
- * registers need to be preloaded. Right now, the known
- * values are:
- *
- * Vertex/compute:
- * - R55 : gl_LocalInvocationID.xy
- * - R56 : gl_LocalInvocationID.z + unknown in high 16 bits
- * - R57 : gl_WorkGroupID.x
- * - R58 : gl_WorkGroupID.y
- * - R59 : gl_WorkGroupID.z
- * - R60 : gl_GlobalInvocationID.x
- * - R61 : gl_GlobalInvocationID.y/gl_VertexID (without base)
- * - R62 : gl_GlobalInvocationID.z/gl_InstanceID (without base)
- *
- * Fragment:
- * - R55 : unknown, never seen (but the bit for this is
- * always set?)
- * - R56 : unknown (bit always unset)
- * - R57 : gl_PrimitiveID
- * - R58 : gl_FrontFacing in low bit, potentially other stuff
- * - R59 : u16 fragment coordinates (used to compute
- * gl_FragCoord.xy, together with sample positions)
- * - R60 : gl_SampleMask (used in epilog, so pretty
- * much always used, but the bit is always 0 -- is
- * this just always pushed?)
- * - 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
- * uniform/const port loads 64 bits at a time.
- */
- u32 uniform_count : 7;
- u32 unk4 : 10; // = 2
- } bifrost2;
+ struct mali_preload_packed bifrost_preload;
struct {
u32 unknown2_7;
} midgard2;
u64 next_job;
} __attribute__((packed));
-/* These concern exception_status */
-
-/* Access type causing a fault, paralleling AS_FAULTSTATUS_* entries in the
- * kernel */
-
-enum mali_exception_access {
- /* Atomic in the kernel for MMU, but that doesn't make sense for a job
- * fault so it's just unused */
- MALI_EXCEPTION_ACCESS_NONE = 0,
-
- MALI_EXCEPTION_ACCESS_EXECUTE = 1,
- MALI_EXCEPTION_ACCESS_READ = 2,
- MALI_EXCEPTION_ACCESS_WRITE = 3
-};
-
/* Details about write_value from panfrost igt tests which use it as a generic
* dword write primitive */
* 3. If e <= 2^shift, then we need to use the round-down algorithm. Set
* magic_divisor = m - 1 and extra_flags = 1.
* 4. Otherwise, set magic_divisor = m and extra_flags = 0.
- *
- * Unrelated to instancing/actual attributes, images (the OpenCL kind) are
- * implemented as special attributes, denoted by MALI_ATTR_IMAGE. For images,
- * let shift=extra_flags=0. Stride is set to the image format's bytes-per-pixel
- * (*NOT the row stride*). Size is set to the size of the image itself.
- *
- * Special internal attribtues and varyings (gl_VertexID, gl_FrontFacing, etc)
- * use particular fixed addresses with modified structures.
*/
-enum mali_attr_mode {
- MALI_ATTR_UNUSED = 0,
- MALI_ATTR_LINEAR = 1,
- MALI_ATTR_POT_DIVIDE = 2,
- MALI_ATTR_MODULO = 3,
- MALI_ATTR_NPOT_DIVIDE = 4,
- MALI_ATTR_IMAGE = 5,
-};
-
-/* Pseudo-address for gl_VertexID, gl_FragCoord, gl_FrontFacing */
-
-#define MALI_ATTR_VERTEXID (0x22)
-#define MALI_ATTR_INSTANCEID (0x24)
-#define MALI_VARYING_FRAG_COORD (0x25)
-#define MALI_VARYING_FRONT_FACING (0x26)
-
-/* This magic "pseudo-address" is used as `elements` to implement
- * gl_PointCoord. When read from a fragment shader, it generates a point
- * coordinate per the OpenGL ES 2.0 specification. Flipped coordinate spaces
- * require an affine transformation in the shader. */
-
-#define MALI_VARYING_POINT_COORD (0x61)
-
-/* Used for comparison to check if an address is special. Mostly a guess, but
- * it doesn't really matter. */
-
-#define MALI_RECORD_SPECIAL (0x100)
-
-union mali_attr {
- /* This is used for actual attributes. */
- struct {
- /* The bottom 3 bits are the mode */
- mali_ptr elements : 64 - 8;
- u32 shift : 5;
- u32 extra_flags : 3;
- u32 stride;
- u32 size;
- };
- /* The entry after an NPOT_DIVIDE entry has this format. It stores
- * extra information that wouldn't fit in a normal entry.
- */
- struct {
- u32 unk; /* = 0x20 */
- u32 magic_divisor;
- u32 zero;
- /* This is the original, GL-level divisor. */
- u32 divisor;
- };
-} __attribute__((packed));
-
-struct mali_attr_meta {
- /* Vertex buffer index */
- u8 index;
-
- unsigned unknown1 : 2;
- unsigned swizzle : 12;
- enum mali_format format : 8;
-
- /* Always observed to be zero at the moment */
- unsigned unknown3 : 2;
-
- /* When packing multiple attributes in a buffer, offset addresses by
- * this value. Obscurely, this is signed. */
- int32_t src_offset;
-} __attribute__((packed));
-
#define FBD_MASK (~0x3f)
/* MFBD, rather than SFBD */
/* ORed into an MFBD address to specify the fbx section is included */
#define MALI_MFBD_TAG_EXTRA (0x2)
-/* 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.
- */
-
-#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
* fused payloads.
#define MALI_POSITIVE(dim) (dim - 1)
-/* Shared across both command stream and Midgard, and even with Bifrost */
-
-enum mali_texture_type {
- MALI_TEX_CUBE = 0x0,
- MALI_TEX_1D = 0x1,
- MALI_TEX_2D = 0x2,
- MALI_TEX_3D = 0x3
-};
-
/* 8192x8192 */
#define MAX_MIP_LEVELS (13)
/* For each pointer, there is an address and optionally also a stride */
#define MAX_ELEMENTS (2)
-/* It's not known why there are 4-bits allocated -- this enum is almost
- * certainly incomplete */
-
-enum mali_texture_layout {
- /* For a Z/S texture, this is linear */
- MALI_TEXTURE_TILED = 0x1,
-
- /* Z/S textures cannot be tiled */
- MALI_TEXTURE_LINEAR = 0x2,
-
- /* 16x16 sparse */
- MALI_TEXTURE_AFBC = 0xC
-};
-
-/* Corresponds to the type passed to glTexImage2D and so forth */
-
-struct mali_texture_format {
- unsigned swizzle : 12;
- enum mali_format format : 8;
-
- unsigned srgb : 1;
- unsigned unknown1 : 1;
-
- enum mali_texture_type type : 2;
- enum mali_texture_layout layout : 4;
-
- /* Always set */
- unsigned unknown2 : 1;
-
- /* Set to allow packing an explicit stride */
- unsigned manual_stride : 1;
-
- unsigned zero : 2;
-} __attribute__((packed));
-
-struct mali_texture_descriptor {
- uint16_t width;
- uint16_t height;
- uint16_t depth;
- uint16_t array_size;
-
- struct mali_texture_format format;
-
- uint16_t unknown3;
-
- /* One for non-mipmapped, zero for mipmapped */
- uint8_t unknown3A;
-
- /* Zero for non-mipmapped, (number of levels - 1) for mipmapped */
- uint8_t levels;
-
- /* Swizzling is a single 32-bit word, broken up here for convenience.
- * Here, swizzling refers to the ES 3.0 texture parameters for channel
- * level swizzling, not the internal pixel-level swizzling which is
- * below OpenGL's reach */
-
- unsigned swizzle : 12;
- unsigned swizzle_zero : 20;
-
- uint32_t unknown5;
- uint32_t unknown6;
- 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 zero : 4;
- unsigned format_swizzle : 12;
- 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 : 8;
-
- 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)
-#define MALI_SAMP_MIN_NEAREST (1 << 1)
-
-/* TODO: What do these bits mean individually? Only seen set together */
-
-#define MALI_SAMP_MIP_LINEAR_1 (1 << 3)
-#define MALI_SAMP_MIP_LINEAR_2 (1 << 4)
-
-/* Flag in filter_mode, corresponding to OpenCL's NORMALIZED_COORDS_TRUE
- * sampler_t flag. For typical OpenGL textures, this is always set. */
-
-#define MALI_SAMP_NORM_COORDS (1 << 5)
-
/* Used for lod encoding. Thanks @urjaman for pointing out these routines can
* be cleaned up a lot. */
return (int) (x * 256.0);
}
-struct mali_sampler_descriptor {
- uint16_t filter_mode;
-
- /* Fixed point, signed.
- * Upper 7 bits before the decimal point, although it caps [0-31].
- * Lower 8 bits after the decimal point: int(round(x * 256)) */
-
- int16_t lod_bias;
- int16_t min_lod;
- int16_t max_lod;
-
- /* All one word in reality, but packed a bit. Comparisons are flipped
- * from OpenGL. */
-
- enum mali_wrap_mode wrap_s : 4;
- enum mali_wrap_mode wrap_t : 4;
- enum mali_wrap_mode wrap_r : 4;
- enum mali_func compare_func : 3;
-
- /* No effect on 2D textures. For cubemaps, set for ES3 and clear for
- * ES2, controlling seamless cubemapping */
- unsigned seamless_cube_map : 1;
-
- unsigned zero : 16;
-
- uint32_t zero2;
- 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_r : 4;
- enum mali_wrap_mode wrap_t : 4;
- enum mali_wrap_mode wrap_s : 4;
- uint8_t unk8 : 4;
-
- uint8_t unk2 : 1;
- uint8_t norm_coords : 1;
- uint8_t unk3 : 1;
- uint8_t min_filter : 1;
- uint8_t zero1 : 1;
- uint8_t mag_filter : 1;
- uint8_t mip_filter : 1;
-
- int16_t min_lod;
- int16_t max_lod;
-
- uint64_t zero2;
- uint64_t zero3;
- uint64_t zero4;
-} __attribute__((packed));
-
/* From presentations, 16x16 tiles externally. Use shift for fast computation
* of tile numbers. */
u32 weights[8];
};
-enum mali_block_format {
- MALI_BLOCK_TILED = 0x0,
- MALI_BLOCK_UNKNOWN = 0x1,
- MALI_BLOCK_LINEAR = 0x2,
- MALI_BLOCK_AFBC = 0x3,
-};
-
struct mali_sfbd_format {
/* 0x1 */
unsigned unk1 : 6;
} __attribute__((packed));
-/* SINGLE to disable multisampling, AVERAGE for
- * EXT_multisampled_render_to_texture operation where multiple tilebuffer
- * samples are implicitly resolved before writeout, MULTIPLE to write multiple
- * samples inline, and LAYERED for ES3-style multisampling with each sample in
- * a different buffer.
- */
-
-enum mali_msaa_mode {
- MALI_MSAA_SINGLE = 0,
- MALI_MSAA_AVERAGE = 1,
- MALI_MSAA_MULTIPLE = 2,
- MALI_MSAA_LAYERED = 3,
-};
-
#define MALI_MFBD_FORMAT_SRGB (1 << 0)
struct mali_rt_format {
unsigned unk3 : 4;
unsigned unk4 : 1;
enum mali_block_format block : 2;
- enum mali_msaa_mode msaa : 2;
+ enum mali_msaa msaa : 2;
unsigned flags : 2;
unsigned swizzle : 12;