From c0d69b40bcf73e972c87bcaca30bf4a1b4af48f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 28 Oct 2022 08:32:02 -0400 Subject: [PATCH] nir: add nir_texop_sampler_descriptor_amd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We'll use it to query the min/mag filter in the shader. Reviewed-by: Rhys Perry Reviewed-by: Timur Kristóf Part-of: --- src/amd/llvm/ac_nir_to_llvm.c | 8 +++++++- src/compiler/nir/nir.c | 4 ++++ src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_print.c | 3 +++ src/compiler/nir/nir_validate.c | 1 + src/compiler/spirv/spirv_to_nir.c | 3 ++- 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index 7e89d45a780..89b1af3842c 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -4767,13 +4767,19 @@ static void visit_tex(struct ac_nir_context *ctx, nir_tex_instr *instr) /* Don't use the waterfall loop when returning a descriptor. */ tex_fetch_ptrs(ctx, instr, wctx, &args.resource, &args.sampler, &fmask_ptr, - instr->op != nir_texop_descriptor_amd); + instr->op != nir_texop_descriptor_amd && + instr->op != nir_texop_sampler_descriptor_amd); if (instr->op == nir_texop_descriptor_amd) { result = args.resource; goto write_result; } + if (instr->op == nir_texop_sampler_descriptor_amd) { + result = args.sampler; + goto write_result; + } + for (unsigned i = 0; i < instr->num_srcs; i++) { switch (instr->src[i].src_type) { case nir_tex_src_coord: { diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 5983274496c..c579755f46e 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -3237,6 +3237,9 @@ nir_tex_instr_result_size(const nir_tex_instr *instr) case nir_texop_descriptor_amd: return instr->sampler_dim == GLSL_SAMPLER_DIM_BUF ? 4 : 8; + case nir_texop_sampler_descriptor_amd: + return 4; + default: if (instr->is_shadow && instr->is_new_style_shadow) return 1; @@ -3254,6 +3257,7 @@ nir_tex_instr_is_query(const nir_tex_instr *instr) case nir_texop_texture_samples: case nir_texop_query_levels: case nir_texop_descriptor_amd: + case nir_texop_sampler_descriptor_amd: return true; case nir_texop_tex: case nir_texop_txb: diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index d81c04ad2aa..0a551ad12d3 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2198,6 +2198,7 @@ typedef enum { nir_texop_fragment_fetch_amd, /**< Multisample fragment color texture fetch */ nir_texop_fragment_mask_fetch_amd, /**< Multisample fragment mask texture fetch */ nir_texop_descriptor_amd, /**< Returns a buffer or image descriptor. */ + nir_texop_sampler_descriptor_amd, /**< Returns a sampler descriptor. */ } nir_texop; /** Represents a texture instruction */ diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index dd1b1d2b07d..da56f7e2e5b 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -1275,6 +1275,9 @@ print_tex_instr(nir_tex_instr *instr, print_state *state) case nir_texop_descriptor_amd: fprintf(fp, "descriptor_amd "); break; + case nir_texop_sampler_descriptor_amd: + fprintf(fp, "sampler_descriptor_amd "); + break; default: unreachable("Invalid texture operation"); break; diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c index 14af0e66fdd..166dca828fe 100644 --- a/src/compiler/nir/nir_validate.c +++ b/src/compiler/nir/nir_validate.c @@ -900,6 +900,7 @@ validate_tex_instr(nir_tex_instr *instr, validate_state *state) glsl_type_is_sampler(deref->type)); switch (instr->op) { case nir_texop_descriptor_amd: + case nir_texop_sampler_descriptor_amd: break; case nir_texop_lod: validate_assert(state, nir_alu_type_get_base_type(instr->dest_type) == nir_type_float); diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 5f602274013..5dbd90c5def 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -2844,7 +2844,8 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode, vtn_fail("unexpected nir_texop_tex_prefetch"); break; case nir_texop_descriptor_amd: - vtn_fail("unexpected nir_texop_descriptor_amd"); + case nir_texop_sampler_descriptor_amd: + vtn_fail("unexpected nir_texop_*descriptor_amd"); break; }