pan/genxml: Rework gen_pack.py to support OpenCL

This changes the codegen to make it compatible with CL C.

Signed-off-by: Mary Guillemard <mary.guillemard@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32720>
This commit is contained in:
Mary Guillemard 2024-12-02 11:36:11 +01:00 committed by Marge Bot
parent 97abab160b
commit 410e5a36ec
2 changed files with 29 additions and 14 deletions

View file

@ -32,7 +32,6 @@ from functools import reduce
global_prefix = "mali"
v6_format_printer = """
#define mali_pixel_format_print(fp, format) \\
fprintf(fp, "%*sFormat (v6): %s%s%s %s%s%s%s\\n", indent, "", \\
mali_format_as_str((enum mali_format)((format >> 12) & 0xFF)), \\
@ -42,18 +41,15 @@ v6_format_printer = """
mali_channel_as_str((enum mali_channel)((format >> 3) & 0x7)), \\
mali_channel_as_str((enum mali_channel)((format >> 6) & 0x7)), \\
mali_channel_as_str((enum mali_channel)((format >> 9) & 0x7)));
"""
v7_format_printer = """
#define mali_pixel_format_print(fp, format) \\
fprintf(fp, "%*sFormat (v7): %s%s %s%s\\n", indent, "", \\
mali_format_as_str((enum mali_format)((format >> 12) & 0xFF)), \\
(format & (1 << 20)) ? " sRGB" : "", \\
mali_rgb_component_order_as_str((enum mali_rgb_component_order)(format & ((1 << 12) - 1))), \\
(format & (1 << 21)) ? " XXX BAD BIT" : "");
"""
def to_alphanum(name):
@ -670,12 +666,14 @@ class Parser(object):
print("} while (0);\n")
def emit_print_function(self, name, group):
print("#ifndef __OPENCL_VERSION__")
print("static inline void")
print("{}_print(FILE *fp, const struct {} * values, unsigned indent)\n{{".format(name.upper(), name))
group.emit_print_function()
print("}\n")
print("#endif")
def emit_struct(self):
name = self.struct
@ -702,6 +700,7 @@ class Parser(object):
print(' % -36s = %6d,' % (name, value.value))
print('};\n')
print("#ifndef __OPENCL_VERSION__")
print("static inline const char *")
print("{}_as_str(enum {} imm)\n{{".format(e_name.lower(), e_name))
print(" switch (imm) {")
@ -712,6 +711,7 @@ class Parser(object):
print(' default: return "XXX: INVALID";')
print(" }")
print("}\n")
print("#endif\n")
def parse(self, filename):
file = open(filename, "rb")

View file

@ -6,10 +6,19 @@
#ifndef PAN_PACK_HELPERS_H
#define PAN_PACK_HELPERS_H
#include "compiler/libcl/libcl.h"
#include "util/bitpack_helpers.h"
#ifndef __OPENCL_VERSION__
#include <inttypes.h>
#include <stdio.h>
#endif
#include "util/bitpack_helpers.h"
#ifdef __OPENCL_VERSION__
#define fprintf(...) \
do { \
} while (0)
#endif
static inline uint32_t
__gen_padded(uint32_t v, uint32_t start, uint32_t end)
@ -97,19 +106,10 @@ __gen_padded(uint32_t v, uint32_t start, uint32_t end)
_loop_terminate = NULL; \
}))
#define pan_cast_and_pack(dst, T, name) \
pan_pack((PREFIX2(T, PACKED_T) *)dst, T, name)
#define pan_cast_and_pack_nodefaults(dst, T, name) \
pan_pack_nodefaults((PREFIX2(T, PACKED_T) *)dst, T, name)
#define pan_unpack(src, T, name) \
UNUSED struct PREFIX1(T) name; \
PREFIX2(T, unpack)((src), &name)
#define pan_cast_and_unpack(src, T, name) \
pan_unpack((const PREFIX2(T, PACKED_T) *)(src), T, name)
#define pan_print(fp, T, var, indent) PREFIX2(T, print)(fp, &(var), indent)
#define pan_size(T) PREFIX2(T, LENGTH)
@ -117,6 +117,18 @@ __gen_padded(uint32_t v, uint32_t start, uint32_t end)
#define pan_section_offset(A, S) PREFIX4(A, SECTION, S, OFFSET)
/* Those APIs aren't safe in OpenCL C because we lose information on the
* pointer address space */
#ifndef __OPENCL_VERSION__
#define pan_cast_and_pack(dst, T, name) \
pan_pack((PREFIX2(T, PACKED_T) *)dst, T, name)
#define pan_cast_and_pack_nodefaults(dst, T, name) \
pan_pack_nodefaults((PREFIX2(T, PACKED_T) *)dst, T, name)
#define pan_cast_and_unpack(src, T, name) \
pan_unpack((const PREFIX2(T, PACKED_T) *)(src), T, name)
#define pan_section_ptr(base, A, S) \
((PREFIX4(A, SECTION, S, PACKED_TYPE) *)((uint8_t *)(base) + \
pan_section_offset(A, S)))
@ -133,6 +145,7 @@ __gen_padded(uint32_t v, uint32_t start, uint32_t end)
#define pan_section_unpack(src, A, S, name) \
UNUSED PREFIX4(A, SECTION, S, TYPE) name; \
PREFIX4(A, SECTION, S, unpack)(pan_section_ptr(src, A, S), &name)
#endif
#define pan_section_print(fp, A, S, var, indent) \
PREFIX4(A, SECTION, S, print)(fp, &(var), indent)
@ -149,6 +162,7 @@ pan_merge_helper(uint32_t *dst, const uint32_t *src, size_t bytes)
#define pan_merge(packed1, packed2, type) \
pan_merge_helper((packed1).opaque, (packed2).opaque, pan_size(type))
#ifndef __OPENCL_VERSION__
static inline const char *
mali_component_swizzle(unsigned val)
{
@ -161,6 +175,7 @@ mali_component_swizzle(unsigned val)
*outp = 0;
return out_str;
}
#endif
/* From presentations, 16x16 tiles externally. Use shift for fast computation
* of tile numbers. */