aco: Fix integer overflows when emitting parallel copies during RA
[mesa.git] / src / amd / vulkan / vk_format_parse.py
index ba730388a7b302fd3f7f34aa3b1b572b9a24ad7a..506c723ea515f0f615239f58ef6c3d82cf7bd99f 100644 (file)
@@ -113,7 +113,7 @@ class Channel:
 class Format:
     '''Describe a pixel format.'''
 
-    def __init__(self, name, layout, block_width, block_height, le_channels, le_swizzles, be_channels, be_swizzles, colorspace):
+    def __init__(self, name, layout, block_width, block_height, le_channels, le_swizzles, be_channels, be_swizzles, colorspace, width_divisor, height_divisor, plane_formats):
         self.name = name
         self.layout = layout
         self.block_width = block_width
@@ -124,6 +124,13 @@ class Format:
         self.be_swizzles = be_swizzles
         self.name = name
         self.colorspace = colorspace
+        self.plane_count = len(plane_formats)
+        self.width_divisor = width_divisor
+        self.height_divisor = height_divisor
+        self.plane_formats = plane_formats
+
+        while len(self.plane_formats) < 3:
+            self.plane_formats.append("VK_FORMAT_UNDEFINED")
 
     def __str__(self):
         return self.name
@@ -334,6 +341,16 @@ def _parse_channels(fields, layout, colorspace, swizzles):
 
     return channels
 
+def parse_plane_divisor(format):
+    if format == '444':
+        return (1, 1)
+    elif format == '422':
+        return (2, 1)
+    elif format == '420':
+        return (2, 2)
+    else:
+        return (1, 1)
+
 def parse(filename):
     '''Parse the format description in CSV format in terms of the
     Channel and Format classes above.'''
@@ -354,10 +371,9 @@ def parse(filename):
         fields = [field.strip() for field in line.split(',')]
         if len (fields) < 10:
            continue
-        if len (fields) == 10:
-           fields += fields[4:9]
-        assert len (fields) == 15
-        
+
+        be_fields = fields[4:9]
+
         name = fields[0]
         layout = fields[1]
         block_width, block_height = map(int, fields[2:4])
@@ -366,8 +382,8 @@ def parse(filename):
         le_swizzles = [_swizzle_parse_map[swizzle] for swizzle in fields[8]]
         le_channels = _parse_channels(fields[4:8], layout, colorspace, le_swizzles)
 
-        be_swizzles = [_swizzle_parse_map[swizzle] for swizzle in fields[14]]
-        be_channels = _parse_channels(fields[10:14], layout, colorspace, be_swizzles)
+        be_swizzles = [_swizzle_parse_map[swizzle] for swizzle in be_fields[4]]
+        be_channels = _parse_channels(be_fields, layout, colorspace, be_swizzles)
 
         le_shift = 0
         for channel in le_channels:
@@ -383,7 +399,18 @@ def parse(filename):
         for i in range(4):
             assert (le_swizzles[i] != SWIZZLE_NONE) == (be_swizzles[i] != SWIZZLE_NONE)
 
-        format = Format(name, layout, block_width, block_height, le_channels, le_swizzles, be_channels, be_swizzles, colorspace)
+        width_divisor = 1
+        height_divisor = 1
+        plane_formats = [name]
+        if layout == "multiplane":
+            plane_formats = []
+            (width_divisor, height_divisor) = parse_plane_divisor(fields[10])
+
+            for i in range(11, len(fields)):
+                plane_formats.append(fields[i])
+            assert (len(plane_formats) > 1)
+
+        format = Format(name, layout, block_width, block_height, le_channels, le_swizzles, be_channels, be_swizzles, colorspace, width_divisor, height_divisor, plane_formats)
         formats.append(format)
     return formats