zink: use ConstOffset for nir_tex_src_offset
Quote from the OpenGL Shading Language spec, version 4.40, section 8.9.2 "Texel Lookup Functions": > The offset value must be a constant expression. So, until we start consuming SPIR-V shaders, it seems we don't need to deal with non-constant offsets. This means we can avoid lowering this away in some cases. Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8327>
This commit is contained in:
parent
918cb23693
commit
b77f43f253
|
@ -2171,7 +2171,7 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
|
|||
assert(tex->texture_index == tex->sampler_index);
|
||||
|
||||
SpvId coord = 0, proj = 0, bias = 0, lod = 0, dref = 0, dx = 0, dy = 0,
|
||||
offset = 0, sample = 0, tex_offset = 0;
|
||||
const_offset = 0, sample = 0, tex_offset = 0;
|
||||
unsigned coord_components = 0;
|
||||
for (unsigned i = 0; i < tex->num_srcs; i++) {
|
||||
switch (tex->src[i].src_type) {
|
||||
|
@ -2191,7 +2191,8 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
|
|||
break;
|
||||
|
||||
case nir_tex_src_offset:
|
||||
offset = get_src_int(ctx, &tex->src[i].src);
|
||||
assert(nir_src_is_const(tex->src[i].src));
|
||||
const_offset = get_src_int(ctx, &tex->src[i].src);
|
||||
break;
|
||||
|
||||
case nir_tex_src_bias:
|
||||
|
@ -2332,22 +2333,23 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
|
|||
tex->op == nir_texop_txf_ms ||
|
||||
tex->op == nir_texop_tg4) {
|
||||
SpvId image = spirv_builder_emit_image(&ctx->builder, image_type, load);
|
||||
if (offset)
|
||||
spirv_builder_emit_cap(&ctx->builder, SpvCapabilityImageGatherExtended);
|
||||
if (tex->op == nir_texop_tg4)
|
||||
|
||||
if (tex->op == nir_texop_tg4) {
|
||||
if (const_offset)
|
||||
spirv_builder_emit_cap(&ctx->builder, SpvCapabilityImageGatherExtended);
|
||||
result = spirv_builder_emit_image_gather(&ctx->builder, dest_type,
|
||||
load, coord, emit_uint_const(ctx, 32, tex->component),
|
||||
lod, sample, offset, dref);
|
||||
else
|
||||
lod, sample, const_offset, dref);
|
||||
} else
|
||||
result = spirv_builder_emit_image_fetch(&ctx->builder, dest_type,
|
||||
image, coord, lod, sample, offset);
|
||||
image, coord, lod, sample, const_offset);
|
||||
} else {
|
||||
result = spirv_builder_emit_image_sample(&ctx->builder,
|
||||
actual_dest_type, load,
|
||||
coord,
|
||||
proj != 0,
|
||||
lod, bias, dref, dx, dy,
|
||||
offset);
|
||||
const_offset);
|
||||
}
|
||||
|
||||
spirv_builder_emit_decoration(&ctx->builder, result,
|
||||
|
|
|
@ -669,7 +669,7 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
|
|||
SpvId dref,
|
||||
SpvId dx,
|
||||
SpvId dy,
|
||||
SpvId offset)
|
||||
SpvId const_offset)
|
||||
{
|
||||
SpvId result = spirv_builder_new_id(b);
|
||||
|
||||
|
@ -699,9 +699,9 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
|
|||
extra_operands[++num_extra_operands] = dy;
|
||||
operand_mask |= SpvImageOperandsGradMask;
|
||||
}
|
||||
if (offset) {
|
||||
extra_operands[++num_extra_operands] = offset;
|
||||
operand_mask |= SpvImageOperandsOffsetMask;
|
||||
if (const_offset) {
|
||||
extra_operands[++num_extra_operands] = const_offset;
|
||||
operand_mask |= SpvImageOperandsConstOffsetMask;
|
||||
}
|
||||
|
||||
/* finalize num_extra_operands / extra_operands */
|
||||
|
@ -744,7 +744,7 @@ spirv_builder_emit_image_gather(struct spirv_builder *b,
|
|||
SpvId component,
|
||||
SpvId lod,
|
||||
SpvId sample,
|
||||
SpvId offset,
|
||||
SpvId const_offset,
|
||||
SpvId dref)
|
||||
{
|
||||
SpvId result = spirv_builder_new_id(b);
|
||||
|
@ -761,9 +761,9 @@ spirv_builder_emit_image_gather(struct spirv_builder *b,
|
|||
extra_operands[++num_extra_operands] = sample;
|
||||
operand_mask |= SpvImageOperandsSampleMask;
|
||||
}
|
||||
if (offset) {
|
||||
extra_operands[++num_extra_operands] = offset;
|
||||
operand_mask |= SpvImageOperandsOffsetMask;
|
||||
if (const_offset) {
|
||||
extra_operands[++num_extra_operands] = const_offset;
|
||||
operand_mask |= SpvImageOperandsConstOffsetMask;
|
||||
}
|
||||
if (dref)
|
||||
op = SpvOpImageDrefGather;
|
||||
|
@ -796,7 +796,7 @@ spirv_builder_emit_image_fetch(struct spirv_builder *b,
|
|||
SpvId coordinate,
|
||||
SpvId lod,
|
||||
SpvId sample,
|
||||
SpvId offset)
|
||||
SpvId const_offset)
|
||||
{
|
||||
SpvId result = spirv_builder_new_id(b);
|
||||
|
||||
|
@ -811,9 +811,9 @@ 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;
|
||||
if (const_offset) {
|
||||
extra_operands[++num_extra_operands] = const_offset;
|
||||
operand_mask |= SpvImageOperandsConstOffsetMask;
|
||||
}
|
||||
|
||||
/* finalize num_extra_operands / extra_operands */
|
||||
|
|
|
@ -431,7 +431,6 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
|
|||
if (!screen->info.feats.features.shaderImageGatherExtended) {
|
||||
nir_lower_tex_options tex_opts = {};
|
||||
tex_opts.lower_tg4_offsets = true;
|
||||
tex_opts.lower_txf_offset = true;
|
||||
NIR_PASS_V(nir, nir_lower_tex, &tex_opts);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue