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

Author: M Henning <dra...@darkrefraction.com>
Date:   Fri Dec  1 23:07:23 2023 -0500

nak: Provide robustness info to postprocess_nir

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

---

 src/nouveau/compiler/nak.h                 |  4 +++-
 src/nouveau/compiler/nak.rs                |  3 ++-
 src/nouveau/compiler/nak_nir.c             |  1 +
 src/nouveau/vulkan/nvk_compute_pipeline.c  |  2 +-
 src/nouveau/vulkan/nvk_graphics_pipeline.c |  3 ++-
 src/nouveau/vulkan/nvk_shader.c            | 12 ++++++++++--
 src/nouveau/vulkan/nvk_shader.h            |  1 +
 7 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/nouveau/compiler/nak.h b/src/nouveau/compiler/nak.h
index de38a395f1e..d7cb5aaa66a 100644
--- a/src/nouveau/compiler/nak.h
+++ b/src/nouveau/compiler/nak.h
@@ -7,6 +7,7 @@
 #define NAK_H
 
 #include "compiler/shader_enums.h"
+#include "nir.h"
 
 #include <assert.h>
 #include <stdbool.h>
@@ -18,7 +19,6 @@ extern "C" {
 
 struct nak_compiler;
 struct nir_shader_compiler_options;
-typedef struct nir_shader nir_shader;
 struct nv_device_info;
 
 struct nak_compiler *nak_compiler_create(const struct nv_device_info *dev);
@@ -50,6 +50,7 @@ struct nak_fs_key {
 };
 
 void nak_postprocess_nir(nir_shader *nir, const struct nak_compiler *nak,
+                         nir_variable_mode robust2_modes,
                          const struct nak_fs_key *fs_key);
 
 enum PACKED nak_ts_domain {
@@ -143,6 +144,7 @@ void nak_shader_bin_destroy(struct nak_shader_bin *bin);
 struct nak_shader_bin *
 nak_compile_shader(nir_shader *nir, bool dump_asm,
                    const struct nak_compiler *nak,
+                   nir_variable_mode robust2_modes,
                    const struct nak_fs_key *fs_key);
 
 #ifdef __cplusplus
diff --git a/src/nouveau/compiler/nak.rs b/src/nouveau/compiler/nak.rs
index fae3d24d987..ec0c0a2a5eb 100644
--- a/src/nouveau/compiler/nak.rs
+++ b/src/nouveau/compiler/nak.rs
@@ -229,9 +229,10 @@ pub extern "C" fn nak_compile_shader(
     nir: *mut nir_shader,
     dump_asm: bool,
     nak: *const nak_compiler,
+    robust2_modes: nir_variable_mode,
     fs_key: *const nak_fs_key,
 ) -> *mut nak_shader_bin {
-    unsafe { nak_postprocess_nir(nir, nak, fs_key) };
+    unsafe { nak_postprocess_nir(nir, nak, robust2_modes, fs_key) };
     let nak = unsafe { &*nak };
     let nir = unsafe { &*nir };
     let fs_key = if fs_key.is_null() {
diff --git a/src/nouveau/compiler/nak_nir.c b/src/nouveau/compiler/nak_nir.c
index 4c808173860..bbb355d1c38 100644
--- a/src/nouveau/compiler/nak_nir.c
+++ b/src/nouveau/compiler/nak_nir.c
@@ -1037,6 +1037,7 @@ nir_shader_has_local_variables(const nir_shader *nir)
 void
 nak_postprocess_nir(nir_shader *nir,
                     const struct nak_compiler *nak,
+                    nir_variable_mode robust2_modes,
                     const struct nak_fs_key *fs_key)
 {
    UNUSED bool progress = false;
diff --git a/src/nouveau/vulkan/nvk_compute_pipeline.c 
b/src/nouveau/vulkan/nvk_compute_pipeline.c
index 80a9df4374b..f5ebde5154f 100644
--- a/src/nouveau/vulkan/nvk_compute_pipeline.c
+++ b/src/nouveau/vulkan/nvk_compute_pipeline.c
@@ -186,7 +186,7 @@ nvk_compute_pipeline_create(struct nvk_device *dev,
 
    nvk_lower_nir(dev, nir, &robustness, false, pipeline_layout);
 
-   result = nvk_compile_nir(pdev, nir, pipeline_flags, NULL,
+   result = nvk_compile_nir(pdev, nir, pipeline_flags, &robustness, NULL,
                             &pipeline->base.shaders[MESA_SHADER_COMPUTE]);
    ralloc_free(nir);
    if (result != VK_SUCCESS)
diff --git a/src/nouveau/vulkan/nvk_graphics_pipeline.c 
b/src/nouveau/vulkan/nvk_graphics_pipeline.c
index 05d37aa637f..809fa8444df 100644
--- a/src/nouveau/vulkan/nvk_graphics_pipeline.c
+++ b/src/nouveau/vulkan/nvk_graphics_pipeline.c
@@ -361,7 +361,8 @@ nvk_graphics_pipeline_create(struct nvk_device *dev,
          fs_key = &fs_key_tmp;
       }
 
-      result = nvk_compile_nir(pdev, nir[stage], pipeline_flags, fs_key,
+      result = nvk_compile_nir(pdev, nir[stage], pipeline_flags,
+                               &robustness[stage], fs_key,
                                &pipeline->base.shaders[stage]);
       ralloc_free(nir[stage]);
       if (result != VK_SUCCESS)
diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c
index 97b206147d7..d3313d51078 100644
--- a/src/nouveau/vulkan/nvk_shader.c
+++ b/src/nouveau/vulkan/nvk_shader.c
@@ -412,13 +412,20 @@ static VkResult
 nvk_compile_nir_with_nak(struct nvk_physical_device *pdev,
                          nir_shader *nir,
                          VkPipelineCreateFlagBits2KHR pipeline_flags,
+                         const struct vk_pipeline_robustness_state *rs,
                          const struct nak_fs_key *fs_key,
                          struct nvk_shader *shader)
 {
    const bool dump_asm =
       pipeline_flags & 
VK_PIPELINE_CREATE_2_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_KHR;
 
-   shader->nak = nak_compile_shader(nir, dump_asm, pdev->nak, fs_key);
+   nir_variable_mode robust2_modes = 0;
+   if (rs->uniform_buffers == 
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_2_EXT)
+      robust2_modes |= nir_var_mem_ubo;
+   if (rs->storage_buffers == 
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_2_EXT)
+      robust2_modes |= nir_var_mem_ssbo;
+
+   shader->nak = nak_compile_shader(nir, dump_asm, pdev->nak, robust2_modes, 
fs_key);
    shader->info = shader->nak->info;
    shader->code_ptr = shader->nak->code;
    shader->code_size = shader->nak->code_size;
@@ -429,11 +436,12 @@ nvk_compile_nir_with_nak(struct nvk_physical_device *pdev,
 VkResult
 nvk_compile_nir(struct nvk_physical_device *pdev, nir_shader *nir,
                 VkPipelineCreateFlagBits2KHR pipeline_flags,
+                const struct vk_pipeline_robustness_state *rs,
                 const struct nak_fs_key *fs_key,
                 struct nvk_shader *shader)
 {
    if (use_nak(pdev, nir->info.stage)) {
-      return nvk_compile_nir_with_nak(pdev, nir, pipeline_flags,
+      return nvk_compile_nir_with_nak(pdev, nir, pipeline_flags, rs,
                                       fs_key, shader);
    } else {
       return nvk_cg_compile_nir(pdev, nir, fs_key, shader);
diff --git a/src/nouveau/vulkan/nvk_shader.h b/src/nouveau/vulkan/nvk_shader.h
index 7ce8187236c..62e1879e161 100644
--- a/src/nouveau/vulkan/nvk_shader.h
+++ b/src/nouveau/vulkan/nvk_shader.h
@@ -91,6 +91,7 @@ nvk_lower_nir(struct nvk_device *dev, nir_shader *nir,
 VkResult
 nvk_compile_nir(struct nvk_physical_device *dev, nir_shader *nir,
                 VkPipelineCreateFlagBits2KHR pipeline_flags,
+                const struct vk_pipeline_robustness_state *rstate,
                 const struct nak_fs_key *fs_key,
                 struct nvk_shader *shader);
 

Reply via email to