[Mesa-dev] [PATCH 2/4] intel/gen_pack_header: Emit C enums for inline values
Kristian H. Kristensen
hoegsberg at gmail.com
Wed Nov 30 06:06:40 UTC 2016
This new feature lets us generate C enums for inline values of a
field. If the type attribute on a field is an otherwise undefined type,
the generator will create an enum with that type name and the inline
values. The enum can be referenced further down in the XML as if it had
be declared independently and will generate a C enum.
For example:
<field name="Tile Mode" start="12" end="13" type="TILE_MODE">
<value name="LINEAR" value="0"/>
<value name="WMAJOR" value="1"/>
<value name="XMAJOR" value="2"/>
<value name="YMAJOR" value="3"/>
</field>
will generate the TILE_MODE enum and in the C header we'll get
enum GEN9_TILE_MODE {
LINEAR = 0,
WMAJOR = 1,
XMAJOR = 2,
YMAJOR = 3,
};
and in struct GEN9_RENDER_SURFACE_STATE:
struct GEN9_RENDER_SURFACE_STATE {
...
enum GEN9_SURFACE_FORMAT SurfaceFormat;
...
};
This can be combined with the prefix attribute:
<field name="Color Clamp Range" start="34" end="35" type="Color Clamp" prefix="COLORCLAMP">
<value name="UNORM" value="0"/>
<value name="SNORM" value="1"/>
<value name="RTFORMAT" value="2"/>
</field>
generates
enum GEN9_Color Clamp {
COLORCLAMP_UNORM = 0,
COLORCLAMP_SNORM = 1,
COLORCLAMP_RTFORMAT = 2,
};
Signed-off-by: Kristian H. Kristensen <hoegsberg at gmail.com>
---
src/intel/genxml/gen_pack_header.py | 41 ++++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/src/intel/genxml/gen_pack_header.py b/src/intel/genxml/gen_pack_header.py
index 001ad17..fb70951 100644
--- a/src/intel/genxml/gen_pack_header.py
+++ b/src/intel/genxml/gen_pack_header.py
@@ -293,8 +293,9 @@ class Field(object):
else:
prefix = ""
- for value in self.values:
- print("#define %-40s %d" % (prefix + value.name, value.value))
+ if self.is_builtin_type():
+ for value in self.values:
+ print("#define %-40s %d" % (prefix + value.name, value.value))
class Group(object):
def __init__(self, parser, parent, start, count, size):
@@ -305,6 +306,18 @@ class Group(object):
self.size = size
self.fields = []
+
+ def emit_inline_enums(self):
+ for field in self.fields:
+ if type(field) is Group:
+ field.emit_inline_enums()
+ elif not (field.is_builtin_type() or
+ field.is_struct_type() or
+ field.is_enum_type()):
+ self.parser.enums[field.type] = 1
+ self.parser.emit_enum(safe_name(field.type),
+ field.prefix, field.values)
+
def emit_template_struct(self, dim):
if self.count == 0:
print(" /* variable length fields follow */")
@@ -574,7 +587,7 @@ class Parser(object):
elif name == "field":
self.group.fields[-1].values = self.values
elif name == "enum":
- self.emit_enum()
+ self.emit_enum(self.enum, self.prefix, self.values)
self.enum = None
elif name == "genxml":
print('#endif /* %s */' % self.gen_guard())
@@ -585,6 +598,8 @@ class Parser(object):
print("};\n")
def emit_pack_function(self, name, group):
+ group.emit_inline_enums()
+
name = self.gen_prefix(name)
print("static inline void\n%s_pack(__gen_user_data *data, void * restrict dst,\n%sconst struct %s * restrict values)\n{" %
(name, ' ' * (len(name) + 6), name))
@@ -597,6 +612,8 @@ class Parser(object):
print("}\n")
def emit_instruction(self):
+ self.group.emit_inline_enums()
+
name = self.instruction
if not self.length == None:
print('#define %-33s %6d' %
@@ -622,6 +639,8 @@ class Parser(object):
self.emit_pack_function(self.instruction, self.group)
def emit_register(self):
+ self.group.emit_inline_enums()
+
name = self.register
if not self.reg_num == None:
print('#define %-33s 0x%04x' %
@@ -635,6 +654,8 @@ class Parser(object):
self.emit_pack_function(self.register, self.group)
def emit_struct(self):
+ self.group.emit_inline_enums()
+
name = self.struct
if not self.length == None:
print('#define %-33s %6d' %
@@ -643,14 +664,14 @@ class Parser(object):
self.emit_template_struct(self.struct, self.group)
self.emit_pack_function(self.struct, self.group)
- def emit_enum(self):
- print('enum %s {' % self.gen_prefix(self.enum))
- for value in self.values:
- if self.prefix:
- name = self.prefix + "_" + value.name
+ def emit_enum(self, name, prefix, values):
+ print('enum %s {' % self.gen_prefix(name))
+ for value in values:
+ if prefix:
+ value_name = prefix + "_" + value.name
else:
- name = value.name
- print(' %-36s = %6d,' % (name.upper(), value.value))
+ value_name = value.name
+ print(' %-36s = %6d,' % (value_name.upper(), value.value))
print('};\n')
def parse(self, filename):
--
2.9.3
More information about the mesa-dev
mailing list