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

Author: Faith Ekstrand <faith.ekstr...@collabora.com>
Date:   Fri Dec  8 16:53:30 2023 -0600

nvk: Add a cbuf_bind_map to nvk_shader

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

---

 src/nouveau/vulkan/nvk_compute_pipeline.c  | 10 +++++-----
 src/nouveau/vulkan/nvk_graphics_pipeline.c |  3 ++-
 src/nouveau/vulkan/nvk_shader.c            | 22 ++++++++++++++++++++--
 src/nouveau/vulkan/nvk_shader.h            |  4 +++-
 4 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/src/nouveau/vulkan/nvk_compute_pipeline.c 
b/src/nouveau/vulkan/nvk_compute_pipeline.c
index f5ebde5154f..a74b3765aa1 100644
--- a/src/nouveau/vulkan/nvk_compute_pipeline.c
+++ b/src/nouveau/vulkan/nvk_compute_pipeline.c
@@ -184,20 +184,20 @@ nvk_compute_pipeline_create(struct nvk_device *dev,
    if (result != VK_SUCCESS)
       goto fail;
 
-   nvk_lower_nir(dev, nir, &robustness, false, pipeline_layout);
+   struct nvk_shader *shader = &pipeline->base.shaders[MESA_SHADER_COMPUTE];
+
+   nvk_lower_nir(dev, nir, &robustness, false, pipeline_layout, shader);
 
    result = nvk_compile_nir(pdev, nir, pipeline_flags, &robustness, NULL,
-                            &pipeline->base.shaders[MESA_SHADER_COMPUTE]);
+                            shader);
    ralloc_free(nir);
    if (result != VK_SUCCESS)
       goto fail;
 
-   result = nvk_shader_upload(dev,
-                              &pipeline->base.shaders[MESA_SHADER_COMPUTE]);
+   result = nvk_shader_upload(dev, shader);
    if (result != VK_SUCCESS)
       goto fail;
 
-   struct nvk_shader *shader = &pipeline->base.shaders[MESA_SHADER_COMPUTE];
    if (pdev->info.cls_compute >= AMPERE_COMPUTE_A)
       nvc6c0_compute_setup_launch_desc_template(pipeline->qmd_template, 
shader);
    else if (pdev->info.cls_compute >= VOLTA_COMPUTE_A)
diff --git a/src/nouveau/vulkan/nvk_graphics_pipeline.c 
b/src/nouveau/vulkan/nvk_graphics_pipeline.c
index f8ca5f41ec3..2d8d23e7866 100644
--- a/src/nouveau/vulkan/nvk_graphics_pipeline.c
+++ b/src/nouveau/vulkan/nvk_graphics_pipeline.c
@@ -343,7 +343,8 @@ nvk_graphics_pipeline_create(struct nvk_device *dev,
       const VkPipelineShaderStageCreateInfo *sinfo = &pCreateInfo->pStages[i];
       gl_shader_stage stage = vk_to_mesa_shader_stage(sinfo->stage);
       nvk_lower_nir(dev, nir[stage], &robustness[stage],
-                    state.rp->view_mask != 0, pipeline_layout);
+                    state.rp->view_mask != 0, pipeline_layout,
+                    &pipeline->base.shaders[stage]);
    }
 
    for (gl_shader_stage stage = 0; stage < MESA_SHADER_STAGES; stage++) {
diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c
index ab6f98fbefd..9c42f12972c 100644
--- a/src/nouveau/vulkan/nvk_shader.c
+++ b/src/nouveau/vulkan/nvk_shader.c
@@ -297,7 +297,8 @@ void
 nvk_lower_nir(struct nvk_device *dev, nir_shader *nir,
               const struct vk_pipeline_robustness_state *rs,
               bool is_multiview,
-              const struct vk_pipeline_layout *layout)
+              const struct vk_pipeline_layout *layout,
+              struct nvk_shader *shader)
 {
    struct nvk_physical_device *pdev = nvk_device_physical(dev);
 
@@ -348,7 +349,24 @@ nvk_lower_nir(struct nvk_device *dev, nir_shader *nir,
     */
    assert(dev->pdev->info.cls_eng3d >= MAXWELL_A || !nir_has_image_var(nir));
 
-   NIR_PASS(_, nir, nvk_nir_lower_descriptors, rs, layout, NULL);
+   struct nvk_cbuf_map *cbuf_map = NULL;
+   if (use_nak(pdev, nir->info.stage) && 0) {
+      cbuf_map = &shader->cbuf_map;
+   } else {
+      /* Codegen sometimes puts stuff in cbuf 1 and adds 1 to our cbuf indices
+       * so we can't really rely on it for lowering to cbufs and instead place
+       * the root descriptors in both cbuf 0 and cbuf 1.
+       */
+      shader->cbuf_map = (struct nvk_cbuf_map) {
+         .cbuf_count = 2,
+         .cbufs = {
+            { .type = NVK_CBUF_TYPE_ROOT_DESC },
+            { .type = NVK_CBUF_TYPE_ROOT_DESC },
+         }
+      };
+   }
+
+   NIR_PASS(_, nir, nvk_nir_lower_descriptors, rs, layout, cbuf_map);
    NIR_PASS(_, nir, nir_lower_explicit_io, nir_var_mem_global,
             nir_address_format_64bit_global);
    NIR_PASS(_, nir, nir_lower_explicit_io, nir_var_mem_ssbo,
diff --git a/src/nouveau/vulkan/nvk_shader.h b/src/nouveau/vulkan/nvk_shader.h
index a432a237336..80380b36cdb 100644
--- a/src/nouveau/vulkan/nvk_shader.h
+++ b/src/nouveau/vulkan/nvk_shader.h
@@ -47,6 +47,7 @@ struct nvk_cbuf_map {
 
 struct nvk_shader {
    struct nak_shader_info info;
+   struct nvk_cbuf_map cbuf_map;
 
    struct nak_shader_bin *nak;
    const void *code_ptr;
@@ -107,7 +108,8 @@ void
 nvk_lower_nir(struct nvk_device *dev, nir_shader *nir,
               const struct vk_pipeline_robustness_state *rs,
               bool is_multiview,
-              const struct vk_pipeline_layout *layout);
+              const struct vk_pipeline_layout *layout,
+              struct nvk_shader *shader);
 
 VkResult
 nvk_compile_nir(struct nvk_physical_device *dev, nir_shader *nir,

Reply via email to