From 2e15b42eece01c0dc0ba2026848bad4a8e1170ab Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 14 Apr 2025 12:29:31 -0400 Subject: [PATCH] nir: unvendor lod_bias(_agx) this will be useful for other backends. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_nir_lower_texture.c | 2 +- src/asahi/vulkan/hk_nir_lower_descriptors.c | 2 +- src/asahi/vulkan/hk_shader.c | 2 +- src/compiler/nir/nir.c | 4 ++-- src/compiler/nir/nir.h | 4 ++-- src/compiler/nir/nir_print.c | 6 +++--- src/compiler/nir/nir_validate.c | 2 +- src/compiler/spirv/spirv_to_nir.c | 4 +++- src/gallium/drivers/asahi/agx_nir_lower_sysvals.c | 2 +- 9 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/asahi/compiler/agx_nir_lower_texture.c b/src/asahi/compiler/agx_nir_lower_texture.c index 309a47a0066..040c8e604b8 100644 --- a/src/asahi/compiler/agx_nir_lower_texture.c +++ b/src/asahi/compiler/agx_nir_lower_texture.c @@ -367,7 +367,7 @@ lower_regular_texture(nir_builder *b, nir_instr *instr, UNUSED void *data) static nir_def * bias_for_tex(nir_builder *b, nir_tex_instr *tex) { - return nir_build_texture_query(b, tex, nir_texop_lod_bias_agx, 1, + return nir_build_texture_query(b, tex, nir_texop_lod_bias, 1, nir_type_float16, false, false); } diff --git a/src/asahi/vulkan/hk_nir_lower_descriptors.c b/src/asahi/vulkan/hk_nir_lower_descriptors.c index 4f336e30ba7..9bf40370c87 100644 --- a/src/asahi/vulkan/hk_nir_lower_descriptors.c +++ b/src/asahi/vulkan/hk_nir_lower_descriptors.c @@ -598,7 +598,7 @@ lower_tex(nir_builder *b, nir_tex_instr *tex, * the sampler descriptor. There's no spot in the hardware descriptor, * plus this saves on precious sampler heap spots. */ - if (tex->op == nir_texop_lod_bias_agx) { + if (tex->op == nir_texop_lod_bias) { unsigned offs = offsetof(struct hk_sampled_image_descriptor, lod_bias_fp16); diff --git a/src/asahi/vulkan/hk_shader.c b/src/asahi/vulkan/hk_shader.c index 6089a10f858..54370654e59 100644 --- a/src/asahi/vulkan/hk_shader.c +++ b/src/asahi/vulkan/hk_shader.c @@ -710,7 +710,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, NIR_PASS(_, nir, nir_lower_robust_access, should_lower_robust, NULL); /* We must do early lowering before hk_nir_lower_descriptors, since this will - * create lod_bias_agx instructions. + * create lod_bias instructions. */ NIR_PASS(_, nir, agx_nir_lower_texture_early, true /* support_lod_bias */); diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index eb05cea70bc..4fa4041ca39 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -3206,8 +3206,8 @@ nir_tex_instr_result_size(const nir_tex_instr *instr) case nir_texop_texture_samples: case nir_texop_query_levels: case nir_texop_samples_identical: + case nir_texop_lod_bias: case nir_texop_fragment_mask_fetch_amd: - case nir_texop_lod_bias_agx: case nir_texop_image_min_lod_agx: case nir_texop_has_custom_border_color_agx: return 1; @@ -3241,9 +3241,9 @@ nir_tex_instr_is_query(const nir_tex_instr *instr) case nir_texop_lod: case nir_texop_texture_samples: case nir_texop_query_levels: + case nir_texop_lod_bias: case nir_texop_descriptor_amd: case nir_texop_sampler_descriptor_amd: - case nir_texop_lod_bias_agx: case nir_texop_image_min_lod_agx: case nir_texop_custom_border_color_agx: case nir_texop_has_custom_border_color_agx: diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 9f898346cf3..4c71c977249 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2309,6 +2309,8 @@ typedef enum nir_texop { nir_texop_samples_identical, /** Regular texture look-up, eligible for pre-dispatch */ nir_texop_tex_prefetch, + /** Returns the sampler's LOD bias (if sampler LOD bias is lowered) */ + nir_texop_lod_bias, /** Multisample fragment color texture fetch */ nir_texop_fragment_fetch_amd, /** Multisample fragment mask texture fetch */ @@ -2317,8 +2319,6 @@ typedef enum nir_texop { nir_texop_descriptor_amd, /** Returns a sampler descriptor. */ nir_texop_sampler_descriptor_amd, - /** Returns the sampler's LOD bias */ - nir_texop_lod_bias_agx, /** Returns the image view's min LOD */ nir_texop_image_min_lod_agx, /** Returns a bool indicating that the sampler uses a custom border colour */ diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index 9e923baeb54..c393bc3186d 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -1759,6 +1759,9 @@ print_tex_instr(nir_tex_instr *instr, print_state *state) case nir_texop_tex_prefetch: fprintf(fp, "tex (pre-dispatchable) "); break; + case nir_texop_lod_bias: + fprintf(fp, "lod_bias "); + break; case nir_texop_fragment_fetch_amd: fprintf(fp, "fragment_fetch_amd "); break; @@ -1771,9 +1774,6 @@ print_tex_instr(nir_tex_instr *instr, print_state *state) case nir_texop_sampler_descriptor_amd: fprintf(fp, "sampler_descriptor_amd "); break; - case nir_texop_lod_bias_agx: - fprintf(fp, "lod_bias_agx "); - break; case nir_texop_image_min_lod_agx: fprintf(fp, "image_min_lod_agx "); break; diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c index c1c38fc90c7..c36a2ba0eca 100644 --- a/src/compiler/nir/nir_validate.c +++ b/src/compiler/nir/nir_validate.c @@ -825,7 +825,7 @@ validate_tex_src_texture_deref(nir_tex_instr *instr, validate_state *state, case nir_texop_custom_border_color_agx: break; case nir_texop_lod: - case nir_texop_lod_bias_agx: + case nir_texop_lod_bias: validate_assert(state, nir_alu_type_get_base_type(instr->dest_type) == nir_type_float); break; case nir_texop_image_min_lod_agx: diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index f22f74369cd..31e74339c2c 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -3382,11 +3382,13 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode, case nir_texop_tex_prefetch: vtn_fail("unexpected nir_texop_tex_prefetch"); break; + case nir_texop_lod_bias: + vtn_fail("unexpected nir_texop_lod_bias"); + break; case nir_texop_descriptor_amd: case nir_texop_sampler_descriptor_amd: vtn_fail("unexpected nir_texop_*descriptor_amd"); break; - case nir_texop_lod_bias_agx: case nir_texop_image_min_lod_agx: case nir_texop_custom_border_color_agx: case nir_texop_has_custom_border_color_agx: diff --git a/src/gallium/drivers/asahi/agx_nir_lower_sysvals.c b/src/gallium/drivers/asahi/agx_nir_lower_sysvals.c index 93113887184..abe0c36ecef 100644 --- a/src/gallium/drivers/asahi/agx_nir_lower_sysvals.c +++ b/src/gallium/drivers/asahi/agx_nir_lower_sysvals.c @@ -253,7 +253,7 @@ lower_sysvals(nir_builder *b, nir_instr *instr, void *data) nir_tex_instr *tex = nir_instr_as_tex(instr); old = &tex->def; - if (tex->op != nir_texop_lod_bias_agx) + if (tex->op != nir_texop_lod_bias) return false; struct agx_stage_uniforms *s = NULL;