assert(nir_alu_type_get_base_type(tex->dest_type) == nir_type_float);
assert(tex->texture_index == tex->sampler_index);
- SpvId coord = 0, proj = 0, bias = 0, lod = 0;
+ SpvId coord = 0, proj = 0, bias = 0, lod = 0, dref = 0;
unsigned coord_components;
for (unsigned i = 0; i < tex->num_srcs; i++) {
switch (tex->src[i].src_type) {
assert(lod != 0);
break;
+ case nir_tex_src_comparator:
+ assert(nir_src_num_components(tex->src[i].src) == 1);
+ dref = get_src_float(ctx, &tex->src[i].src);
+ assert(dref != 0);
+ break;
+
default:
fprintf(stderr, "texture source: %d\n", tex->src[i].src_type);
unreachable("unknown texture source");
coord_components);
}
+ SpvId actual_dest_type = dest_type;
+ if (dref)
+ actual_dest_type = float_type;
+
SpvId result = spirv_builder_emit_image_sample(&ctx->builder,
- dest_type, load,
+ actual_dest_type, load,
coord,
proj != 0,
- lod, bias);
+ lod, bias, dref);
spirv_builder_emit_decoration(&ctx->builder, result,
SpvDecorationRelaxedPrecision);
+ if (dref) {
+ SpvId components[4] = { result, result, result, result };
+ result = spirv_builder_emit_composite_construct(&ctx->builder,
+ dest_type,
+ components,
+ 4);
+ }
+
store_dest(ctx, &tex->dest, result, tex->dest_type);
}
SpvId coordinate,
bool proj,
SpvId lod,
- SpvId bias)
+ SpvId bias,
+ SpvId dref)
{
SpvId result = spirv_builder_new_id(b);
int opcode = SpvOpImageSampleImplicitLod;
+ int operands = 5;
if (proj)
opcode += SpvOpImageSampleProjImplicitLod - SpvOpImageSampleImplicitLod;
if (lod)
opcode += SpvOpImageSampleExplicitLod - SpvOpImageSampleImplicitLod;
+ if (dref) {
+ opcode += SpvOpImageSampleDrefImplicitLod - SpvOpImageSampleImplicitLod;
+ operands++;
+ }
SpvImageOperandsMask operand_mask = 0;
SpvId extra_operands[3];
num_extra_operands++;
}
- spirv_buffer_prepare(&b->instructions, 5 + num_extra_operands);
- spirv_buffer_emit_word(&b->instructions, opcode | ((5 + num_extra_operands) << 16));
+ spirv_buffer_prepare(&b->instructions, operands + num_extra_operands);
+ spirv_buffer_emit_word(&b->instructions, opcode | ((operands + 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, sampled_image);
spirv_buffer_emit_word(&b->instructions, coordinate);
+ if (dref)
+ spirv_buffer_emit_word(&b->instructions, dref);
for (int i = 0; i < num_extra_operands; ++i)
spirv_buffer_emit_word(&b->instructions, extra_operands[i]);
return result;