From cca3f1de56ad741d4ac37f3a1bbb17e2a6a305ab Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Mon, 25 Mar 2024 15:04:51 +0100 Subject: [PATCH] zink/ntv: use new struct to pass texture parameters v2: pass struct spirv_tex_src as const ptr (zmike) Signed-off-by: Gert Wollny Part-of: --- .../drivers/zink/nir_to_spirv/nir_to_spirv.c | 10 +- .../drivers/zink/nir_to_spirv/spirv_builder.c | 135 ++++++++---------- .../drivers/zink/nir_to_spirv/spirv_builder.h | 29 +--- 3 files changed, 65 insertions(+), 109 deletions(-) diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c index eaec65ca4c3..5d22d844a52 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c +++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c @@ -3845,8 +3845,7 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex) if (tex_src.const_offset) spirv_builder_emit_cap(&ctx->builder, SpvCapabilityImageGatherExtended); result = spirv_builder_emit_image_gather(&ctx->builder, actual_dest_type, - load, tex_src.coord, emit_uint_const(ctx, 32, tex->component), - tex_src.lod, tex_src.sample, tex_src.const_offset, tex_src.offset, tex_src.dref, tex->is_sparse); + load, &tex_src, emit_uint_const(ctx, 32, tex->component)); actual_dest_type = dest_type; } else { assert(tex->op == nir_texop_txf_ms || !tex_src.sample); @@ -3854,17 +3853,14 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex) type_to_dim(glsl_get_sampler_dim(glsl_without_array(var->type)), &is_ms); assert(is_ms || !tex_src.sample); result = spirv_builder_emit_image_fetch(&ctx->builder, actual_dest_type, - image, tex_src.coord, tex_src.lod, tex_src.sample, tex_src.const_offset, tex_src.offset, tex->is_sparse); + image, &tex_src); } } else { if (tex->op == nir_texop_txl) tex_src.min_lod = 0; result = spirv_builder_emit_image_sample(&ctx->builder, actual_dest_type, load, - tex_src.coord, - tex_src.proj != 0, - tex_src.lod, tex_src.bias, tex_src.dref, tex_src.dx, tex_src.dy, - tex_src.const_offset, tex_src.offset, tex_src.min_lod, tex->is_sparse); + &tex_src); } if (!bindless_var && (var->data.precision == GLSL_PRECISION_MEDIUM || var->data.precision == GLSL_PRECISION_LOW)) { diff --git a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c index 60b14114415..515d659e9af 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c +++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c @@ -869,29 +869,21 @@ SpvId spirv_builder_emit_image_sample(struct spirv_builder *b, SpvId result_type, SpvId sampled_image, - SpvId coordinate, - bool proj, - SpvId lod, - SpvId bias, - SpvId dref, - SpvId dx, - SpvId dy, - SpvId const_offset, - SpvId offset, - SpvId min_lod, - bool sparse) + const struct spriv_tex_src *src) { SpvId result = spirv_builder_new_id(b); + bool proj = src->proj != 0; + int operands = 5; int opcode; - if (sparse) { + if (src->sparse) { opcode = SpvOpImageSparseSampleImplicitLod; if (proj) opcode += SpvOpImageSparseSampleProjImplicitLod - SpvOpImageSparseSampleImplicitLod; - if (lod || (dx && dy)) + if (src->lod || (src->dx && src->dy)) opcode += SpvOpImageSparseSampleExplicitLod - SpvOpImageSparseSampleImplicitLod; - if (dref) { + if (src->dref) { opcode += SpvOpImageSparseSampleDrefImplicitLod - SpvOpImageSparseSampleImplicitLod; operands++; } @@ -900,9 +892,9 @@ spirv_builder_emit_image_sample(struct spirv_builder *b, opcode = SpvOpImageSampleImplicitLod; if (proj) opcode += SpvOpImageSampleProjImplicitLod - SpvOpImageSampleImplicitLod; - if (lod || (dx && dy)) + if (src->lod || (src->dx && src->dy)) opcode += SpvOpImageSampleExplicitLod - SpvOpImageSampleImplicitLod; - if (dref) { + if (src->dref) { opcode += SpvOpImageSampleDrefImplicitLod - SpvOpImageSampleImplicitLod; operands++; } @@ -911,28 +903,28 @@ spirv_builder_emit_image_sample(struct spirv_builder *b, SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone; SpvId extra_operands[6]; int num_extra_operands = 1; - if (bias) { - extra_operands[num_extra_operands++] = bias; + if (src->bias) { + extra_operands[num_extra_operands++] = src->bias; operand_mask |= SpvImageOperandsBiasMask; } - if (lod) { - extra_operands[num_extra_operands++] = lod; + if (src->lod) { + extra_operands[num_extra_operands++] = src->lod; operand_mask |= SpvImageOperandsLodMask; - } else if (dx && dy) { - extra_operands[num_extra_operands++] = dx; - extra_operands[num_extra_operands++] = dy; + } else if (src->dx && src->dy) { + extra_operands[num_extra_operands++] = src->dx; + extra_operands[num_extra_operands++] = src->dy; operand_mask |= SpvImageOperandsGradMask; } - assert(!(const_offset && offset)); - if (const_offset) { - extra_operands[num_extra_operands++] = const_offset; + assert(!(src->const_offset && src->offset)); + if (src->const_offset) { + extra_operands[num_extra_operands++] = src->const_offset; operand_mask |= SpvImageOperandsConstOffsetMask; - } else if (offset) { - extra_operands[num_extra_operands++] = offset; + } else if (src->offset) { + extra_operands[num_extra_operands++] = src->offset; operand_mask |= SpvImageOperandsOffsetMask; } - if (min_lod) { - extra_operands[num_extra_operands++] = min_lod; + if (src->min_lod) { + extra_operands[num_extra_operands++] = src->min_lod; operand_mask |= SpvImageOperandsMinLodMask; } @@ -944,9 +936,9 @@ spirv_builder_emit_image_sample(struct spirv_builder *b, spirv_buffer_emit_word(&b->instructions, result_type); spirv_buffer_emit_word(&b->instructions, result); spirv_buffer_emit_word(&b->instructions, sampled_image); - spirv_buffer_emit_word(&b->instructions, coordinate); - if (dref) - spirv_buffer_emit_word(&b->instructions, dref); + spirv_buffer_emit_word(&b->instructions, src->coord); + if (src->dref) + spirv_buffer_emit_word(&b->instructions, src->dref); for (int i = 0; i < num_extra_operands; ++i) spirv_buffer_emit_word(&b->instructions, extra_operands[i]); return result; @@ -1061,42 +1053,36 @@ spirv_builder_emit_image_write(struct spirv_builder *b, SpvId spirv_builder_emit_image_gather(struct spirv_builder *b, - SpvId result_type, - SpvId image, - SpvId coordinate, - SpvId component, - SpvId lod, - SpvId sample, - SpvId const_offset, - SpvId offset, - SpvId dref, - bool sparse) + SpvId result_type, + SpvId image, + const struct spriv_tex_src *src, + SpvId component) { SpvId result = spirv_builder_new_id(b); - SpvId op = sparse ? SpvOpImageSparseGather : SpvOpImageGather; + SpvId op = src->sparse ? SpvOpImageSparseGather : SpvOpImageGather; SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone; SpvId extra_operands[4]; int num_extra_operands = 1; - if (lod) { - extra_operands[num_extra_operands++] = lod; + if (src->lod) { + extra_operands[num_extra_operands++] = src->lod; operand_mask |= SpvImageOperandsLodMask; } - if (sample) { - extra_operands[num_extra_operands++] = sample; + if (src->sample) { + extra_operands[num_extra_operands++] = src->sample; operand_mask |= SpvImageOperandsSampleMask; } - assert(!(const_offset && offset)); - if (const_offset) { - extra_operands[num_extra_operands++] = const_offset; + assert(!(src->const_offset && src->offset)); + if (src->const_offset) { + extra_operands[num_extra_operands++] = src->const_offset; operand_mask |= SpvImageOperandsConstOffsetMask; - } else if (offset) { - extra_operands[num_extra_operands++] = offset; + } else if (src->offset) { + extra_operands[num_extra_operands++] = src->offset; operand_mask |= SpvImageOperandsOffsetMask; } - if (dref) - op = sparse ? SpvOpImageSparseDrefGather : SpvOpImageDrefGather; - if (sparse) + if (src->dref) + op = src->sparse ? SpvOpImageSparseDrefGather : SpvOpImageDrefGather; + if (src->sparse) result_type = sparse_wrap_result_type(b, result_type); /* finalize num_extra_operands / extra_operands */ extra_operands[0] = operand_mask; @@ -1107,9 +1093,9 @@ spirv_builder_emit_image_gather(struct spirv_builder *b, spirv_buffer_emit_word(&b->instructions, result_type); spirv_buffer_emit_word(&b->instructions, result); spirv_buffer_emit_word(&b->instructions, image); - spirv_buffer_emit_word(&b->instructions, coordinate); - if (dref) - spirv_buffer_emit_word(&b->instructions, dref); + spirv_buffer_emit_word(&b->instructions, src->coord); + if (src->dref) + spirv_buffer_emit_word(&b->instructions, src->dref); else spirv_buffer_emit_word(&b->instructions, component); for (int i = 0; i < num_extra_operands; ++i) @@ -1121,47 +1107,42 @@ SpvId spirv_builder_emit_image_fetch(struct spirv_builder *b, SpvId result_type, SpvId image, - SpvId coordinate, - SpvId lod, - SpvId sample, - SpvId const_offset, - SpvId offset, - bool sparse) + const struct spriv_tex_src *src) { SpvId result = spirv_builder_new_id(b); SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone; SpvId extra_operands[4]; int num_extra_operands = 1; - if (lod) { - extra_operands[num_extra_operands++] = lod; + if (src->lod) { + extra_operands[num_extra_operands++] = src->lod; operand_mask |= SpvImageOperandsLodMask; } - if (sample) { - extra_operands[num_extra_operands++] = sample; + if (src->sample) { + extra_operands[num_extra_operands++] = src->sample; operand_mask |= SpvImageOperandsSampleMask; } - assert(!(const_offset && offset)); - if (const_offset) { - extra_operands[num_extra_operands++] = const_offset; + assert(!(src->const_offset && src->offset)); + if (src->const_offset) { + extra_operands[num_extra_operands++] = src->const_offset; operand_mask |= SpvImageOperandsConstOffsetMask; - } else if (offset) { - extra_operands[num_extra_operands++] = offset; + } else if (src->offset) { + extra_operands[num_extra_operands++] = src->offset; operand_mask |= SpvImageOperandsOffsetMask; } - if (sparse) + if (src->sparse) result_type = sparse_wrap_result_type(b, result_type); /* finalize num_extra_operands / extra_operands */ extra_operands[0] = operand_mask; spirv_buffer_prepare(&b->instructions, b->mem_ctx, 5 + num_extra_operands); - spirv_buffer_emit_word(&b->instructions, (sparse ? SpvOpImageSparseFetch : SpvOpImageFetch) | + spirv_buffer_emit_word(&b->instructions, (src->sparse ? SpvOpImageSparseFetch : SpvOpImageFetch) | ((5 + num_extra_operands) << 16)); spirv_buffer_emit_word(&b->instructions, result_type); spirv_buffer_emit_word(&b->instructions, result); spirv_buffer_emit_word(&b->instructions, image); - spirv_buffer_emit_word(&b->instructions, coordinate); + spirv_buffer_emit_word(&b->instructions, src->coord); for (int i = 0; i < num_extra_operands; ++i) spirv_buffer_emit_word(&b->instructions, extra_operands[i]); return result; diff --git a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h index 9160b804373..dbdf9d1fba6 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h +++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h @@ -314,17 +314,7 @@ SpvId spirv_builder_emit_image_sample(struct spirv_builder *b, SpvId result_type, SpvId sampled_image, - SpvId coordinate, - bool proj, - SpvId lod, - SpvId bias, - SpvId dref, - SpvId dx, - SpvId dy, - SpvId const_offset, - SpvId offset, - SpvId min_lod, - bool sparse); + const struct spriv_tex_src *src); SpvId spirv_builder_emit_image(struct spirv_builder *b, SpvId result_type, @@ -360,24 +350,13 @@ SpvId spirv_builder_emit_image_fetch(struct spirv_builder *b, SpvId result_type, SpvId image, - SpvId coordinate, - SpvId lod, - SpvId sample, - SpvId const_offset, - SpvId offset, - bool sparse); + const struct spriv_tex_src *src); SpvId spirv_builder_emit_image_gather(struct spirv_builder *b, SpvId result_type, SpvId image, - SpvId coordinate, - SpvId component, - SpvId lod, - SpvId sample, - SpvId const_offset, - SpvId offset, - SpvId dref, - bool sparse); + const struct spriv_tex_src *src, + SpvId component); SpvId spirv_builder_emit_image_query_size(struct spirv_builder *b,