From 7690d35aaa565d5cb829c83e40d0f567a3875f0e Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Fri, 30 May 2025 21:54:45 -0400 Subject: [PATCH] nvk: Rework non-uniform access lowering The UBO lowering did nothing because nir_lower_non_uniform_access doesn't handle load_deref. For texture and storage image lowering, nir_lower_non_uniform_access handles bindless handles just as well as derefs. For textures, it's probably better this way anyway because we combine the image and sampler into a single handle in nvk_nir_lower_descriptors() and this way nir_lower_non_uniform_access() will generate a loop on a single 32-bit handle instead of multiple array indices. Reviewed-by: Mel Henning Part-of: --- src/nouveau/vulkan/nvk_shader.c | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c index 20f980efb2e..a074243c0ac 100644 --- a/src/nouveau/vulkan/nvk_shader.c +++ b/src/nouveau/vulkan/nvk_shader.c @@ -372,27 +372,6 @@ nvk_lower_nir(struct nvk_device *dev, nir_shader *nir, NIR_PASS(_, nir, nir_lower_explicit_io, nir_var_mem_push_const, nir_address_format_32bit_offset); - /* Lower non-uniform access before lower_descriptors */ - enum nir_lower_non_uniform_access_type lower_non_uniform_access_types = - nir_lower_non_uniform_ubo_access; - - if (pdev->info.cls_eng3d < TURING_A) { - lower_non_uniform_access_types |= nir_lower_non_uniform_texture_access | - nir_lower_non_uniform_image_access; - } - - /* In practice, most shaders do not have non-uniform-qualified accesses - * thus a cheaper and likely to fail check is run first. - */ - if (nir_has_non_uniform_access(nir, lower_non_uniform_access_types)) { - struct nir_lower_non_uniform_access_options opts = { - .types = lower_non_uniform_access_types, - .callback = NULL, - }; - NIR_PASS(_, nir, nir_opt_non_uniform_access); - NIR_PASS(_, nir, nir_lower_non_uniform_access, &opts); - } - struct nvk_cbuf_map *cbuf_map = NULL; if (!(pdev->debug_flags & NVK_DEBUG_NO_CBUF)) { cbuf_map = cbuf_map_out; @@ -419,6 +398,27 @@ nvk_lower_nir(struct nvk_device *dev, nir_shader *nir, NIR_PASS(_, nir, nvk_nir_lower_descriptors, pdev, shader_flags, rs, set_layout_count, set_layouts, cbuf_map); + + if (pdev->info.cls_eng3d < TURING_A) { + /* NOTE: This does nothing for images on Kepler since those are lowered + * to suldga/sustga before we get here. That's fine, though, because + * our nil_su_info fetches and calculations work fine with non-uniform + * descriptors. + */ + struct nir_lower_non_uniform_access_options opts = { + .types = nir_lower_non_uniform_texture_access | + nir_lower_non_uniform_image_access, + .callback = NULL, + }; + /* In practice, most shaders do not have non-uniform-qualified accesses + * thus a cheaper and likely to fail check is run first. + */ + if (nir_has_non_uniform_access(nir, opts.types)) { + NIR_PASS(_, nir, nir_opt_non_uniform_access); + NIR_PASS(_, nir, nir_lower_non_uniform_access, &opts); + } + } + 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,