From 64168e58cda8af3ace9101e6709b08ff64962a22 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Tue, 12 Sep 2023 14:48:30 -0500 Subject: [PATCH] nvk,nak: Plumb through the zs_self_dep key bit Part-of: --- src/nouveau/compiler/nak.h | 8 +++++++- src/nouveau/compiler/nak.rs | 17 ++++++++++++++--- src/nouveau/vulkan/nvk_shader.c | 13 +++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/nouveau/compiler/nak.h b/src/nouveau/compiler/nak.h index fca0411e1a3..e3426a10ffc 100644 --- a/src/nouveau/compiler/nak.h +++ b/src/nouveau/compiler/nak.h @@ -33,6 +33,10 @@ void nak_optimize_nir(nir_shader *nir, const struct nak_compiler *nak); void nak_preprocess_nir(nir_shader *nir, const struct nak_compiler *nak); void nak_postprocess_nir(nir_shader *nir, const struct nak_compiler *nak); +struct nak_fs_key { + bool zs_self_dep; +}; + struct nak_shader_info { gl_shader_stage stage; @@ -66,7 +70,9 @@ struct nak_shader_bin { void nak_shader_bin_destroy(struct nak_shader_bin *bin); struct nak_shader_bin * -nak_compile_shader(nir_shader *nir, const struct nak_compiler *nak); +nak_compile_shader(nir_shader *nir, + const struct nak_compiler *nak, + const struct nak_fs_key *fs_key); #ifdef __cplusplus } diff --git a/src/nouveau/compiler/nak.rs b/src/nouveau/compiler/nak.rs index e04337585e3..ccd41077c2e 100644 --- a/src/nouveau/compiler/nak.rs +++ b/src/nouveau/compiler/nak.rs @@ -203,7 +203,11 @@ pub extern "C" fn nak_shader_bin_destroy(bin: *mut nak_shader_bin) { }; } -fn encode_hdr_for_nir(nir: &nir_shader, tls_size: u32) -> [u32; 32] { +fn encode_hdr_for_nir( + nir: &nir_shader, + tls_size: u32, + fs_key: Option<&nak_fs_key>, +) -> [u32; 32] { if nir.info.stage() == MESA_SHADER_COMPUTE { return [0_u32; 32]; } @@ -232,7 +236,8 @@ fn encode_hdr_for_nir(nir: &nir_shader, tls_size: u32) -> [u32; 32] { if nir.info.stage() == MESA_SHADER_FRAGMENT { cw0.set_bit(14, nir.num_outputs > 1); let info_fs = unsafe { &nir.info.__bindgen_anon_1.fs }; - cw0.set_bit(15, info_fs.uses_discard()); + let zs_self_dep = fs_key.map_or(false, |key| key.zs_self_dep); + cw0.set_bit(15, info_fs.uses_discard() || zs_self_dep); } cw0.set_bit(16, false /* TODO: DoesGlobalStore */); cw0.set_field(17..21, 1_u32 /* SassVersion */); @@ -434,10 +439,16 @@ fn eprint_hex(label: &str, data: &[u32]) { pub extern "C" fn nak_compile_shader( nir: *mut nir_shader, nak: *const nak_compiler, + fs_key: *const nak_fs_key, ) -> *mut nak_shader_bin { unsafe { nak_postprocess_nir(nir, nak) }; - let nir = unsafe { &*nir }; let nak = unsafe { &*nak }; + let nir = unsafe { &*nir }; + let fs_key = if fs_key.is_null() { + None + } else { + Some(unsafe { &*fs_key }) + }; let mut s = nak_shader_from_nir(nir, nak.sm); diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c index 47b1e9f8648..4b73a83287a 100644 --- a/src/nouveau/vulkan/nvk_shader.c +++ b/src/nouveau/vulkan/nvk_shader.c @@ -1221,10 +1221,19 @@ nvk_fill_transform_feedback_state(struct nir_shader *nir, static VkResult nvk_compile_nir_with_nak(struct nvk_physical_device *pdev, nir_shader *nir, - const struct nvk_fs_key *fs_key, + const struct nvk_fs_key *nvk_fs_key, struct nvk_shader *shader) { - struct nak_shader_bin *bin = nak_compile_shader(nir, pdev->nak); + struct nak_fs_key fs_key_tmp; + const struct nak_fs_key *fs_key = NULL; + if (nir->info.stage == MESA_SHADER_FRAGMENT && nvk_fs_key != NULL) { + fs_key_tmp = (struct nak_fs_key) { + .zs_self_dep = nvk_fs_key->zs_self_dep, + }; + fs_key = &fs_key_tmp; + } + + struct nak_shader_bin *bin = nak_compile_shader(nir, pdev->nak, fs_key); shader->stage = nir->info.stage;