Commit c708fd7e authored by Erik Faye-Lund 's avatar Erik Faye-Lund

zink: support shadow-samplers

parent f9e1ed9f
......@@ -1111,7 +1111,7 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
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) {
......@@ -1138,6 +1138,12 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
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");
......@@ -1187,14 +1193,26 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
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);
}
......
......@@ -512,15 +512,21 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
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];
......@@ -540,12 +546,14 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
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;
......
......@@ -212,7 +212,8 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
SpvId coordinate,
bool proj,
SpvId lod,
SpvId bias);
SpvId bias,
SpvId dref);
SpvId
spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment