From 486ae7c655e86d3f1b08f9356b11fe4eaee707bb Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Fri, 16 Oct 2020 11:09:09 -0700 Subject: [PATCH] isl: Add isl_format_layout::uniform_channel_type If each format channel has the same base type (such unorm), then that is the format's "uniform channel type". Calculating the field at buildtime is probably better than looping over all channels at runtime each time we wish to query it. Reviewed-by: Jason Ekstrand --- src/intel/isl/gen_format_layout.py | 29 +++++++++++++++++++++++++++++ src/intel/isl/isl.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/src/intel/isl/gen_format_layout.py b/src/intel/isl/gen_format_layout.py index c1f22707fb9..b1c4df2574e 100644 --- a/src/intel/isl/gen_format_layout.py +++ b/src/intel/isl/gen_format_layout.py @@ -81,6 +81,7 @@ isl_format_layouts[] = { % endif % endfor }, + .uniform_channel_type = ISL_${format.uniform_channel_type}, .colorspace = ISL_COLORSPACE_${format.colorspace}, .txc = ISL_TXC_${format.txc}, }, @@ -179,6 +180,23 @@ class Format(object): chan.start = bit bit = bit + chan.size + # Set the uniform channel type, if the format has one. + # + # Iterate over all channels, not just those in self.order, because + # some formats have an empty 'order' field in the CSV (such as + # YCRCB_NORMAL). + self.uniform_channel_type = 'VOID' + for chan in self.channels: + if chan.type in (None, 'VOID'): + pass + elif self.uniform_channel_type == 'VOID': + self.uniform_channel_type = chan.type + elif self.uniform_channel_type == chan.type: + pass + else: + self.uniform_channel_type = 'VOID' + break + # alpha doesn't have a colorspace of it's own. self.colorspace = line[13].strip().upper() if self.colorspace in ['']: @@ -188,6 +206,17 @@ class Format(object): self.txc = line[14].strip().upper() or 'NONE' + @property + def channels(self): + yield self.r + yield self.g + yield self.b + yield self.a + yield self.l + yield self.i + yield self.p + + def reader(csvfile): """Wrapper around csv.reader that skips comments and blanks.""" # csv.reader actually reads the file one line at a time (it was designed to diff --git a/src/intel/isl/isl.h b/src/intel/isl/isl.h index 378caa9fe8f..fff52afce2b 100644 --- a/src/intel/isl/isl.h +++ b/src/intel/isl/isl.h @@ -1133,6 +1133,9 @@ struct isl_format_layout { struct isl_channel_layout channels_array[7]; }; + /** Set if all channels have the same isl_base_type. Otherwise, ISL_BASE_VOID. */ + enum isl_base_type uniform_channel_type; + enum isl_colorspace colorspace; enum isl_txc txc; };