Module: Mesa
Branch: main
Commit: 976ba09f576147857b477209d91853c9e914477b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=976ba09f576147857b477209d91853c9e914477b

Author: Karol Herbst <[email protected]>
Date:   Sun Jun 18 18:14:24 2023 +0200

rusticl/format: move format table generation into a macro

Signed-off-by: Karol Herbst <[email protected]>
Reviewed-by: Dave Airlie <[email protected]>
Reviewed-by: Nora Allen <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23714>

---

 src/gallium/frontends/rusticl/core/format.rs | 94 ++++++++++++----------------
 1 file changed, 40 insertions(+), 54 deletions(-)

diff --git a/src/gallium/frontends/rusticl/core/format.rs 
b/src/gallium/frontends/rusticl/core/format.rs
index b2348e95691..30815650c50 100644
--- a/src/gallium/frontends/rusticl/core/format.rs
+++ b/src/gallium/frontends/rusticl/core/format.rs
@@ -40,40 +40,50 @@ pub struct RusticlImageFormat {
 // UNSIGNED_INT => x  UINT
 // HALF_FLOAT   => 16 FLOAT
 // FLOAT        => 32 FLOAT
-#[rustfmt::skip]
-const fn cl_format_to_pipe(
-    ch_order: cl_channel_order,
-    ch_type: cl_channel_type
-) -> Option<pipe_format> {
-    Some(match (ch_order, ch_type) {
-        (CL_R,    CL_HALF_FLOAT)     => pipe_format::PIPE_FORMAT_R16_FLOAT,
-        (CL_RGBA, CL_HALF_FLOAT)     => 
pipe_format::PIPE_FORMAT_R16G16B16A16_FLOAT,
+macro_rules! cl_format_table {
+    ([$(($order: ident, $type: ident) => $pipe: expr,)+]) => {
+        const fn cl_format_to_pipe(
+            ch_order: cl_channel_order,
+            ch_type: cl_channel_type
+        ) -> Option<pipe_format> {
+            Some(match (ch_order, ch_type) {
+                $(($order, $type) => $pipe,)+
+                _ => return None,
+            })
+        }
 
-        (CL_R,    CL_FLOAT)          => pipe_format::PIPE_FORMAT_R32_FLOAT,
-        (CL_RGBA, CL_FLOAT)          => 
pipe_format::PIPE_FORMAT_R32G32B32A32_FLOAT,
+        pub const FORMATS: &[RusticlImageFormat] = &[
+            $(rusticl_image_format($order, $type),)+
+        ];
+    };
+}
 
-        (CL_R,    CL_SIGNED_INT8)    => pipe_format::PIPE_FORMAT_R8_SINT,
-        (CL_RGBA, CL_SIGNED_INT8)    => pipe_format::PIPE_FORMAT_R8G8B8A8_SINT,
-        (CL_R,    CL_SIGNED_INT16)   => pipe_format::PIPE_FORMAT_R16_SINT,
-        (CL_RGBA, CL_SIGNED_INT16)   => 
pipe_format::PIPE_FORMAT_R16G16B16A16_SINT,
-        (CL_R,    CL_SIGNED_INT32)   => pipe_format::PIPE_FORMAT_R32_SINT,
-        (CL_RGBA, CL_SIGNED_INT32)   => 
pipe_format::PIPE_FORMAT_R32G32B32A32_SINT,
-        (CL_R,    CL_UNSIGNED_INT8)  => pipe_format::PIPE_FORMAT_R8_UINT,
-        (CL_RGBA, CL_UNSIGNED_INT8)  => pipe_format::PIPE_FORMAT_R8G8B8A8_UINT,
-        (CL_R,    CL_UNSIGNED_INT16) => pipe_format::PIPE_FORMAT_R16_UINT,
-        (CL_RGBA, CL_UNSIGNED_INT16) => 
pipe_format::PIPE_FORMAT_R16G16B16A16_UINT,
-        (CL_R,    CL_UNSIGNED_INT32) => pipe_format::PIPE_FORMAT_R32_UINT,
-        (CL_RGBA, CL_UNSIGNED_INT32) => 
pipe_format::PIPE_FORMAT_R32G32B32A32_UINT,
+cl_format_table!([
+    (CL_R,    CL_HALF_FLOAT)     => pipe_format::PIPE_FORMAT_R16_FLOAT,
+    (CL_RGBA, CL_HALF_FLOAT)     => 
pipe_format::PIPE_FORMAT_R16G16B16A16_FLOAT,
 
-        (CL_R,    CL_UNORM_INT8)     => pipe_format::PIPE_FORMAT_R8_UNORM,
-        (CL_RGBA, CL_UNORM_INT8)     => 
pipe_format::PIPE_FORMAT_R8G8B8A8_UNORM,
-        (CL_BGRA, CL_UNORM_INT8)     => 
pipe_format::PIPE_FORMAT_B8G8R8A8_UNORM,
-        (CL_R,    CL_UNORM_INT16)    => pipe_format::PIPE_FORMAT_R16_UNORM,
-        (CL_RGBA, CL_UNORM_INT16)    => 
pipe_format::PIPE_FORMAT_R16G16B16A16_UNORM,
+    (CL_R,    CL_FLOAT)          => pipe_format::PIPE_FORMAT_R32_FLOAT,
+    (CL_RGBA, CL_FLOAT)          => 
pipe_format::PIPE_FORMAT_R32G32B32A32_FLOAT,
 
-        _ => return None,
-    })
-}
+    (CL_R,    CL_SIGNED_INT8)    => pipe_format::PIPE_FORMAT_R8_SINT,
+    (CL_RGBA, CL_SIGNED_INT8)    => pipe_format::PIPE_FORMAT_R8G8B8A8_SINT,
+    (CL_R,    CL_SIGNED_INT16)   => pipe_format::PIPE_FORMAT_R16_SINT,
+    (CL_RGBA, CL_SIGNED_INT16)   => pipe_format::PIPE_FORMAT_R16G16B16A16_SINT,
+    (CL_R,    CL_SIGNED_INT32)   => pipe_format::PIPE_FORMAT_R32_SINT,
+    (CL_RGBA, CL_SIGNED_INT32)   => pipe_format::PIPE_FORMAT_R32G32B32A32_SINT,
+    (CL_R,    CL_UNSIGNED_INT8)  => pipe_format::PIPE_FORMAT_R8_UINT,
+    (CL_RGBA, CL_UNSIGNED_INT8)  => pipe_format::PIPE_FORMAT_R8G8B8A8_UINT,
+    (CL_R,    CL_UNSIGNED_INT16) => pipe_format::PIPE_FORMAT_R16_UINT,
+    (CL_RGBA, CL_UNSIGNED_INT16) => pipe_format::PIPE_FORMAT_R16G16B16A16_UINT,
+    (CL_R,    CL_UNSIGNED_INT32) => pipe_format::PIPE_FORMAT_R32_UINT,
+    (CL_RGBA, CL_UNSIGNED_INT32) => pipe_format::PIPE_FORMAT_R32G32B32A32_UINT,
+
+    (CL_R,    CL_UNORM_INT8)     => pipe_format::PIPE_FORMAT_R8_UNORM,
+    (CL_RGBA, CL_UNORM_INT8)     => pipe_format::PIPE_FORMAT_R8G8B8A8_UNORM,
+    (CL_BGRA, CL_UNORM_INT8)     => pipe_format::PIPE_FORMAT_B8G8R8A8_UNORM,
+    (CL_R,    CL_UNORM_INT16)    => pipe_format::PIPE_FORMAT_R16_UNORM,
+    (CL_RGBA, CL_UNORM_INT16)    => 
pipe_format::PIPE_FORMAT_R16G16B16A16_UNORM,
+]);
 
 #[rustfmt::skip]
 const fn req_for_full_r_or_w(
@@ -209,30 +219,6 @@ const fn rusticl_image_format(
     }
 }
 
-pub const FORMATS: &[RusticlImageFormat] = &[
-    rusticl_image_format(CL_R, CL_HALF_FLOAT),
-    rusticl_image_format(CL_R, CL_FLOAT),
-    rusticl_image_format(CL_R, CL_SIGNED_INT8),
-    rusticl_image_format(CL_R, CL_SIGNED_INT16),
-    rusticl_image_format(CL_R, CL_SIGNED_INT32),
-    rusticl_image_format(CL_R, CL_UNORM_INT8),
-    rusticl_image_format(CL_R, CL_UNORM_INT16),
-    rusticl_image_format(CL_R, CL_UNSIGNED_INT8),
-    rusticl_image_format(CL_R, CL_UNSIGNED_INT16),
-    rusticl_image_format(CL_R, CL_UNSIGNED_INT32),
-    rusticl_image_format(CL_RGBA, CL_HALF_FLOAT),
-    rusticl_image_format(CL_RGBA, CL_FLOAT),
-    rusticl_image_format(CL_RGBA, CL_SIGNED_INT8),
-    rusticl_image_format(CL_RGBA, CL_SIGNED_INT16),
-    rusticl_image_format(CL_RGBA, CL_SIGNED_INT32),
-    rusticl_image_format(CL_RGBA, CL_UNORM_INT8),
-    rusticl_image_format(CL_RGBA, CL_UNORM_INT16),
-    rusticl_image_format(CL_RGBA, CL_UNSIGNED_INT8),
-    rusticl_image_format(CL_RGBA, CL_UNSIGNED_INT16),
-    rusticl_image_format(CL_RGBA, CL_UNSIGNED_INT32),
-    rusticl_image_format(CL_BGRA, CL_UNORM_INT8),
-];
-
 pub trait CLFormatInfo {
     fn channels(&self) -> Option<u8>;
     fn format_info(&self) -> Option<(u8, bool)>;

Reply via email to