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

Author: Faith Ekstrand <[email protected]>
Date:   Tue Nov 14 16:38:37 2023 -0600

nak: Move clip, cull, and XFB into a nak_shader_info.vtg

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26197>

---

 src/nouveau/compiler/nak.h      |  8 +++++---
 src/nouveau/compiler/nak.rs     | 22 +++++++++-------------
 src/nouveau/vulkan/nvk_shader.c | 10 +++++-----
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/src/nouveau/compiler/nak.h b/src/nouveau/compiler/nak.h
index 20fe928cadf..98e338e40a2 100644
--- a/src/nouveau/compiler/nak.h
+++ b/src/nouveau/compiler/nak.h
@@ -109,10 +109,12 @@ struct nak_shader_info {
       uint32_t dummy;
    };
 
-   uint8_t clip_enable;
-   uint8_t cull_enable;
+   struct {
+      uint8_t clip_enable;
+      uint8_t cull_enable;
 
-   struct nak_xfb_info xfb;
+      struct nak_xfb_info xfb;
+   } vtg;
 
    /** Shader header for 3D stages */
    uint32_t hdr[32];
diff --git a/src/nouveau/compiler/nak.rs b/src/nouveau/compiler/nak.rs
index 29a3802cf57..bb24027698f 100644
--- a/src/nouveau/compiler/nak.rs
+++ b/src/nouveau/compiler/nak.rs
@@ -351,26 +351,22 @@ pub extern "C" fn nak_compile_shader(
             }
             _ => nak_shader_info__bindgen_ty_1 { dummy: 0 },
         },
-        clip_enable: match &s.info.stage {
-            ShaderStageInfo::Geometry(_)
-            | ShaderStageInfo::Tessellation
-            | ShaderStageInfo::Vertex => {
-                let num_clip = nir.info.clip_distance_array_size();
-                ((1_u32 << num_clip) - 1).try_into().unwrap()
-            }
-            _ => 0,
-        },
-        cull_enable: match &s.info.stage {
+        vtg: match &s.info.stage {
             ShaderStageInfo::Geometry(_)
             | ShaderStageInfo::Tessellation
             | ShaderStageInfo::Vertex => {
                 let num_clip = nir.info.clip_distance_array_size();
                 let num_cull = nir.info.cull_distance_array_size();
-                (((1_u32 << num_cull) - 1) << num_clip).try_into().unwrap()
+                let clip_enable = (1_u32 << num_clip) - 1;
+                let cull_enable = ((1_u32 << num_cull) - 1) << num_clip;
+                nak_shader_info__bindgen_ty_2 {
+                    clip_enable: clip_enable.try_into().unwrap(),
+                    cull_enable: cull_enable.try_into().unwrap(),
+                    xfb: unsafe { nak_xfb_from_nir(nir.xfb_info) },
+                }
             }
-            _ => 0,
+            _ => unsafe { std::mem::zeroed() },
         },
-        xfb: unsafe { nak_xfb_from_nir(nir.xfb_info) },
         hdr: nak_sph::encode_header(&s.info, fs_key),
     };
 
diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c
index e2fe817e3b7..4580cf2cb66 100644
--- a/src/nouveau/vulkan/nvk_shader.c
+++ b/src/nouveau/vulkan/nvk_shader.c
@@ -428,8 +428,8 @@ nvk_compile_nir_with_nak(struct nvk_physical_device *pdev,
    case MESA_SHADER_VERTEX:
    case MESA_SHADER_TESS_EVAL:
    case MESA_SHADER_GEOMETRY: {
-      shader->vs.clip_enable = bin->info.clip_enable;
-      shader->vs.cull_enable = bin->info.cull_enable;
+      shader->vs.clip_enable = bin->info.vtg.clip_enable;
+      shader->vs.cull_enable = bin->info.vtg.cull_enable;
 
       if (nir->info.stage == MESA_SHADER_TESS_EVAL) {
          shader->tp.domain_type = bin->info.ts.domain;
@@ -441,7 +441,7 @@ nvk_compile_nir_with_nak(struct nvk_physical_device *pdev,
 
       bool has_xfb = false;
       for (unsigned b = 0; b < 4; b++) {
-         if (bin->info.xfb.attr_count[b] > 0) {
+         if (bin->info.vtg.xfb.attr_count[b] > 0) {
             has_xfb = true;
             break;
          }
@@ -449,8 +449,8 @@ nvk_compile_nir_with_nak(struct nvk_physical_device *pdev,
 
       if (has_xfb) {
          shader->xfb = malloc(sizeof(*shader->xfb));
-         STATIC_ASSERT(sizeof(*shader->xfb) == sizeof(bin->info.xfb));
-         memcpy(shader->xfb, &bin->info.xfb, sizeof(*shader->xfb));
+         STATIC_ASSERT(sizeof(*shader->xfb) == sizeof(bin->info.vtg.xfb));
+         memcpy(shader->xfb, &bin->info.vtg.xfb, sizeof(*shader->xfb));
       }
       break;
    }

Reply via email to