if (tex->op == nir_texop_tg4)
result = spirv_builder_emit_image_gather(&ctx->builder, dest_type,
load, coord, emit_uint_const(ctx, 32, tex->component),
- lod, sample, offset);
+ lod, sample, offset, dref);
else
result = spirv_builder_emit_image_fetch(&ctx->builder, dest_type,
image, coord, lod, sample, offset);
spirv_builder_emit_decoration(&ctx->builder, result,
SpvDecorationRelaxedPrecision);
- if (dref && nir_dest_num_components(tex->dest) > 1) {
+ if (dref && nir_dest_num_components(tex->dest) > 1 && tex->op != nir_texop_tg4) {
SpvId components[4] = { result, result, result, result };
result = spirv_builder_emit_composite_construct(&ctx->builder,
dest_type,
SpvId component,
SpvId lod,
SpvId sample,
- SpvId offset)
+ SpvId offset,
+ SpvId dref)
{
SpvId result = spirv_builder_new_id(b);
+ SpvId op = SpvOpImageGather;
SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone;
SpvId extra_operands[4];
extra_operands[++num_extra_operands] = offset;
operand_mask |= SpvImageOperandsOffsetMask;
}
+ if (dref)
+ op = SpvOpImageDrefGather;
/* finalize num_extra_operands / extra_operands */
if (num_extra_operands > 0) {
extra_operands[0] = operand_mask;
}
spirv_buffer_prepare(&b->instructions, b->mem_ctx, 6 + num_extra_operands);
- spirv_buffer_emit_word(&b->instructions, SpvOpImageGather |
+ spirv_buffer_emit_word(&b->instructions, op |
((6 + 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, component);
+ if (dref)
+ spirv_buffer_emit_word(&b->instructions, dref);
+ else
+ spirv_buffer_emit_word(&b->instructions, component);
for (int i = 0; i < num_extra_operands; ++i)
spirv_buffer_emit_word(&b->instructions, extra_operands[i]);
return result;