From 41cdc548eef8fe2579604db49fc5e98857f2382d Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 12 Jan 2026 12:21:56 -0500 Subject: [PATCH] nir/builder: infer txf_ms/txl/txb opcodes I'm not convinced these really should be separate opcodes at all in NIR, but that's not what this patch is about. Here we just infer the opcodes in the texture builder to allow simplified usage. This lets us drop nir_txl() & nir_txb() helpers in favour of nir_tex(.lod/bias) which is more normalized. We could also drop nir_txf_ms in favour of nir_txf but that affects more callsites and is not obviously a win (unlike nir_txl which is used once and nir_txb which is unused). Signed-off-by: Alyssa Rosenzweig Reviewed-by: Georg Lehmann Reviewed-by: Ian Romanick Part-of: --- src/compiler/nir/nir_builder.c | 9 +++++++++ src/compiler/nir/nir_builder.h | 12 ++---------- src/vulkan/runtime/vk_meta_blit_resolve.c | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/compiler/nir/nir_builder.c b/src/compiler/nir/nir_builder.c index 10fed480cab..fad83b190b5 100644 --- a/src/compiler/nir/nir_builder.c +++ b/src/compiler/nir/nir_builder.c @@ -274,6 +274,15 @@ nir_build_tex_struct(nir_builder *build, nir_texop op, struct nir_tex_builder f) glsl_get_sampler_result_type(type)); } + /* Fix up the opcode to allow simplified usage. This helps ergonomics. */ + if (op == nir_texop_txf && f.ms_index) { + op = nir_texop_txf_ms; + } else if (op == nir_texop_tex && f.lod) { + op = nir_texop_txl; + } else if (op == nir_texop_tex && f.bias) { + op = nir_texop_txb; + } + if (lod == NULL && nir_dim_has_lod(dim) && (op == nir_texop_txs || op == nir_texop_txf)) { diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 784ac33b81a..7ba628b75c7 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -2209,19 +2209,11 @@ nir_def *nir_build_tex_struct(nir_builder *build, nir_texop op, #define nir_tex(build, coord_, ...) \ nir_build_tex(build, nir_texop_tex, .coord = coord_, __VA_ARGS__) -#define nir_txl(build, coord_, lod_, ...) \ - nir_build_tex(build, nir_texop_txl, .coord = coord_, .lod = lod_, \ - __VA_ARGS__) - -#define nir_txb(build, coord_, bias_, ...) \ - nir_build_tex(build, nir_texop_txb, .coord = coord_, .bias = bias, \ - __VA_ARGS__) - #define nir_txf(build, coord_, ...) \ nir_build_tex(build, nir_texop_txf, .coord = coord_, __VA_ARGS__) -#define nir_txf_ms(build, coord_, ms_index_, ...) \ - nir_build_tex(build, nir_texop_txf_ms, .coord = coord_, \ +#define nir_txf_ms(build, coord_, ms_index_, ...) \ + nir_build_tex(build, nir_texop_txf, .coord = coord_, \ .ms_index = ms_index_, __VA_ARGS__) #define nir_txs(build, ...) nir_build_tex(build, nir_texop_txs, __VA_ARGS__) diff --git a/src/vulkan/runtime/vk_meta_blit_resolve.c b/src/vulkan/runtime/vk_meta_blit_resolve.c index ca49fcb22ef..c8a495a2123 100644 --- a/src/vulkan/runtime/vk_meta_blit_resolve.c +++ b/src/vulkan/runtime/vk_meta_blit_resolve.c @@ -304,7 +304,7 @@ build_blit_shader(const struct vk_meta_blit_key *key) nir_def *val; if (resolve_mode == VK_RESOLVE_MODE_NONE) { - val = nir_txl(b, src_coord, nir_imm_float(b, 0), + val = nir_tex(b, src_coord, .lod = nir_imm_float(b, 0), .texture_deref = t, .sampler_deref = s); } else { val = build_tex_resolve(b, t, nir_f2u32(b, src_coord),