mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 05:08:08 +02:00
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:
parent
97abab160b
commit
410e5a36ec
2 changed files with 29 additions and 14 deletions
|
|
@ -32,7 +32,6 @@ from functools import reduce
|
||||||
global_prefix = "mali"
|
global_prefix = "mali"
|
||||||
|
|
||||||
v6_format_printer = """
|
v6_format_printer = """
|
||||||
|
|
||||||
#define mali_pixel_format_print(fp, format) \\
|
#define mali_pixel_format_print(fp, format) \\
|
||||||
fprintf(fp, "%*sFormat (v6): %s%s%s %s%s%s%s\\n", indent, "", \\
|
fprintf(fp, "%*sFormat (v6): %s%s%s %s%s%s%s\\n", indent, "", \\
|
||||||
mali_format_as_str((enum mali_format)((format >> 12) & 0xFF)), \\
|
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 >> 3) & 0x7)), \\
|
||||||
mali_channel_as_str((enum mali_channel)((format >> 6) & 0x7)), \\
|
mali_channel_as_str((enum mali_channel)((format >> 6) & 0x7)), \\
|
||||||
mali_channel_as_str((enum mali_channel)((format >> 9) & 0x7)));
|
mali_channel_as_str((enum mali_channel)((format >> 9) & 0x7)));
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
v7_format_printer = """
|
v7_format_printer = """
|
||||||
|
|
||||||
#define mali_pixel_format_print(fp, format) \\
|
#define mali_pixel_format_print(fp, format) \\
|
||||||
fprintf(fp, "%*sFormat (v7): %s%s %s%s\\n", indent, "", \\
|
fprintf(fp, "%*sFormat (v7): %s%s %s%s\\n", indent, "", \\
|
||||||
mali_format_as_str((enum mali_format)((format >> 12) & 0xFF)), \\
|
mali_format_as_str((enum mali_format)((format >> 12) & 0xFF)), \\
|
||||||
(format & (1 << 20)) ? " sRGB" : "", \\
|
(format & (1 << 20)) ? " sRGB" : "", \\
|
||||||
mali_rgb_component_order_as_str((enum mali_rgb_component_order)(format & ((1 << 12) - 1))), \\
|
mali_rgb_component_order_as_str((enum mali_rgb_component_order)(format & ((1 << 12) - 1))), \\
|
||||||
(format & (1 << 21)) ? " XXX BAD BIT" : "");
|
(format & (1 << 21)) ? " XXX BAD BIT" : "");
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def to_alphanum(name):
|
def to_alphanum(name):
|
||||||
|
|
@ -670,12 +666,14 @@ class Parser(object):
|
||||||
print("} while (0);\n")
|
print("} while (0);\n")
|
||||||
|
|
||||||
def emit_print_function(self, name, group):
|
def emit_print_function(self, name, group):
|
||||||
|
print("#ifndef __OPENCL_VERSION__")
|
||||||
print("static inline void")
|
print("static inline void")
|
||||||
print("{}_print(FILE *fp, const struct {} * values, unsigned indent)\n{{".format(name.upper(), name))
|
print("{}_print(FILE *fp, const struct {} * values, unsigned indent)\n{{".format(name.upper(), name))
|
||||||
|
|
||||||
group.emit_print_function()
|
group.emit_print_function()
|
||||||
|
|
||||||
print("}\n")
|
print("}\n")
|
||||||
|
print("#endif")
|
||||||
|
|
||||||
def emit_struct(self):
|
def emit_struct(self):
|
||||||
name = self.struct
|
name = self.struct
|
||||||
|
|
@ -702,6 +700,7 @@ class Parser(object):
|
||||||
print(' % -36s = %6d,' % (name, value.value))
|
print(' % -36s = %6d,' % (name, value.value))
|
||||||
print('};\n')
|
print('};\n')
|
||||||
|
|
||||||
|
print("#ifndef __OPENCL_VERSION__")
|
||||||
print("static inline const char *")
|
print("static inline const char *")
|
||||||
print("{}_as_str(enum {} imm)\n{{".format(e_name.lower(), e_name))
|
print("{}_as_str(enum {} imm)\n{{".format(e_name.lower(), e_name))
|
||||||
print(" switch (imm) {")
|
print(" switch (imm) {")
|
||||||
|
|
@ -712,6 +711,7 @@ class Parser(object):
|
||||||
print(' default: return "XXX: INVALID";')
|
print(' default: return "XXX: INVALID";')
|
||||||
print(" }")
|
print(" }")
|
||||||
print("}\n")
|
print("}\n")
|
||||||
|
print("#endif\n")
|
||||||
|
|
||||||
def parse(self, filename):
|
def parse(self, filename):
|
||||||
file = open(filename, "rb")
|
file = open(filename, "rb")
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,19 @@
|
||||||
#ifndef PAN_PACK_HELPERS_H
|
#ifndef PAN_PACK_HELPERS_H
|
||||||
#define 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 <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "util/bitpack_helpers.h"
|
#ifdef __OPENCL_VERSION__
|
||||||
|
#define fprintf(...) \
|
||||||
|
do { \
|
||||||
|
} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
__gen_padded(uint32_t v, uint32_t start, uint32_t end)
|
__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; \
|
_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) \
|
#define pan_unpack(src, T, name) \
|
||||||
UNUSED struct PREFIX1(T) name; \
|
UNUSED struct PREFIX1(T) name; \
|
||||||
PREFIX2(T, unpack)((src), &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_print(fp, T, var, indent) PREFIX2(T, print)(fp, &(var), indent)
|
||||||
|
|
||||||
#define pan_size(T) PREFIX2(T, LENGTH)
|
#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)
|
#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) \
|
#define pan_section_ptr(base, A, S) \
|
||||||
((PREFIX4(A, SECTION, S, PACKED_TYPE) *)((uint8_t *)(base) + \
|
((PREFIX4(A, SECTION, S, PACKED_TYPE) *)((uint8_t *)(base) + \
|
||||||
pan_section_offset(A, S)))
|
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) \
|
#define pan_section_unpack(src, A, S, name) \
|
||||||
UNUSED PREFIX4(A, SECTION, S, TYPE) name; \
|
UNUSED PREFIX4(A, SECTION, S, TYPE) name; \
|
||||||
PREFIX4(A, SECTION, S, unpack)(pan_section_ptr(src, A, S), &name)
|
PREFIX4(A, SECTION, S, unpack)(pan_section_ptr(src, A, S), &name)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define pan_section_print(fp, A, S, var, indent) \
|
#define pan_section_print(fp, A, S, var, indent) \
|
||||||
PREFIX4(A, SECTION, S, print)(fp, &(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) \
|
#define pan_merge(packed1, packed2, type) \
|
||||||
pan_merge_helper((packed1).opaque, (packed2).opaque, pan_size(type))
|
pan_merge_helper((packed1).opaque, (packed2).opaque, pan_size(type))
|
||||||
|
|
||||||
|
#ifndef __OPENCL_VERSION__
|
||||||
static inline const char *
|
static inline const char *
|
||||||
mali_component_swizzle(unsigned val)
|
mali_component_swizzle(unsigned val)
|
||||||
{
|
{
|
||||||
|
|
@ -161,6 +175,7 @@ mali_component_swizzle(unsigned val)
|
||||||
*outp = 0;
|
*outp = 0;
|
||||||
return out_str;
|
return out_str;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* From presentations, 16x16 tiles externally. Use shift for fast computation
|
/* From presentations, 16x16 tiles externally. Use shift for fast computation
|
||||||
* of tile numbers. */
|
* of tile numbers. */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue