Mesa (master): zink: use Offset param for txf ops
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jan 4 16:00:01 UTC 2021
Module: Mesa
Branch: master
Commit: fd39bf6c06c9b7b8f1cc5ea1e74d624b996925fe
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd39bf6c06c9b7b8f1cc5ea1e74d624b996925fe
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Wed Jul 15 15:18:24 2020 -0400
zink: use Offset param for txf ops
there's an image operand for handling offsets, so we can use this when it
hasn't previously been lowered away
Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8151>
---
.../drivers/zink/nir_to_spirv/nir_to_spirv.c | 44 ++--------------------
.../drivers/zink/nir_to_spirv/spirv_builder.c | 9 ++++-
.../drivers/zink/nir_to_spirv/spirv_builder.h | 4 +-
3 files changed, 13 insertions(+), 44 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 4c1af8192bb..232c3c074b6 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
@@ -2095,29 +2095,6 @@ tex_instr_is_lod_allowed(nir_tex_instr *tex)
tex->sampler_dim == GLSL_SAMPLER_DIM_CUBE);
}
-static SpvId
-pad_coord_vector(struct ntv_context *ctx, SpvId orig, unsigned old_size, unsigned new_size)
-{
- SpvId int_type = spirv_builder_type_int(&ctx->builder, 32);
- SpvId type = get_ivec_type(ctx, 32, new_size);
- SpvId constituents[NIR_MAX_VEC_COMPONENTS] = {0};
- SpvId zero = emit_int_const(ctx, 32, 0);
- assert(new_size < NIR_MAX_VEC_COMPONENTS);
-
- if (old_size == 1)
- constituents[0] = orig;
- else {
- for (unsigned i = 0; i < old_size; i++)
- constituents[i] = spirv_builder_emit_vector_extract(&ctx->builder, int_type, orig, i);
- }
-
- for (unsigned i = old_size; i < new_size; i++)
- constituents[i] = zero;
-
- return spirv_builder_emit_composite_construct(&ctx->builder, type,
- constituents, new_size);
-}
-
static void
emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
{
@@ -2133,7 +2110,7 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
SpvId coord = 0, proj = 0, bias = 0, lod = 0, dref = 0, dx = 0, dy = 0,
offset = 0, sample = 0, tex_offset = 0;
- unsigned coord_components = 0, coord_bitsize = 0, offset_components = 0;
+ unsigned coord_components = 0;
for (unsigned i = 0; i < tex->num_srcs; i++) {
switch (tex->src[i].src_type) {
case nir_tex_src_coord:
@@ -2143,7 +2120,6 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
else
coord = get_src_float(ctx, &tex->src[i].src);
coord_components = nir_src_num_components(tex->src[i].src);
- coord_bitsize = nir_src_bit_size(tex->src[i].src);
break;
case nir_tex_src_projector:
@@ -2154,7 +2130,6 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
case nir_tex_src_offset:
offset = get_src_int(ctx, &tex->src[i].src);
- offset_components = nir_src_num_components(tex->src[i].src);
break;
case nir_tex_src_bias:
@@ -2294,21 +2269,10 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
if (tex->op == nir_texop_txf ||
tex->op == nir_texop_txf_ms) {
SpvId image = spirv_builder_emit_image(&ctx->builder, image_type, load);
- if (offset) {
- /* SPIRV requires matched length vectors for OpIAdd, so if a shader
- * uses vecs of differing sizes we need to make a new vec padded with zeroes
- * to mimic how GLSL does this implicitly
- */
- if (offset_components > coord_components)
- coord = pad_coord_vector(ctx, coord, coord_components, offset_components);
- else if (coord_components > offset_components)
- offset = pad_coord_vector(ctx, offset, offset_components, coord_components);
- coord = emit_binop(ctx, SpvOpIAdd,
- get_ivec_type(ctx, coord_bitsize, coord_components),
- coord, offset);
- }
+ if (offset)
+ spirv_builder_emit_cap(&ctx->builder, SpvCapabilityImageGatherExtended);
result = spirv_builder_emit_image_fetch(&ctx->builder, dest_type,
- image, coord, lod, sample);
+ image, coord, lod, sample, offset);
} else {
result = spirv_builder_emit_image_sample(&ctx->builder,
actual_dest_type, load,
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 5ec876d9392..6d0e6384924 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
+++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
@@ -716,12 +716,13 @@ spirv_builder_emit_image_fetch(struct spirv_builder *b,
SpvId image,
SpvId coordinate,
SpvId lod,
- SpvId sample)
+ SpvId sample,
+ SpvId offset)
{
SpvId result = spirv_builder_new_id(b);
SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone;
- SpvId extra_operands[3];
+ SpvId extra_operands[4];
int num_extra_operands = 0;
if (lod) {
extra_operands[++num_extra_operands] = lod;
@@ -731,6 +732,10 @@ spirv_builder_emit_image_fetch(struct spirv_builder *b,
extra_operands[++num_extra_operands] = sample;
operand_mask |= SpvImageOperandsSampleMask;
}
+ if (offset) {
+ extra_operands[++num_extra_operands] = offset;
+ operand_mask |= SpvImageOperandsOffsetMask;
+ }
/* finalize num_extra_operands / extra_operands */
if (num_extra_operands > 0) {
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 47d8f3a576f..6fd38f151c9 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
+++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
@@ -263,8 +263,8 @@ spirv_builder_emit_image_fetch(struct spirv_builder *b,
SpvId image,
SpvId coordinate,
SpvId lod,
- SpvId sample);
-
+ SpvId sample,
+ SpvId offset);
SpvId
spirv_builder_emit_image_query_size(struct spirv_builder *b,
SpvId result_type,
More information about the mesa-commit
mailing list