zink: ensure non-fragment shaders use lod-versions of texture
Acked-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
@@ -1076,8 +1076,8 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
|
|||||||
assert(nir_alu_type_get_base_type(tex->dest_type) == nir_type_float);
|
assert(nir_alu_type_get_base_type(tex->dest_type) == nir_type_float);
|
||||||
assert(tex->texture_index == tex->sampler_index);
|
assert(tex->texture_index == tex->sampler_index);
|
||||||
|
|
||||||
bool has_proj = false;
|
bool has_proj = false, has_lod = false;
|
||||||
SpvId coord = 0, proj;
|
SpvId coord = 0, proj, lod;
|
||||||
unsigned coord_components;
|
unsigned coord_components;
|
||||||
for (unsigned i = 0; i < tex->num_srcs; i++) {
|
for (unsigned i = 0; i < tex->num_srcs; i++) {
|
||||||
switch (tex->src[i].src_type) {
|
switch (tex->src[i].src_type) {
|
||||||
@@ -1092,12 +1092,23 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
|
|||||||
assert(nir_src_num_components(tex->src[i].src) == 1);
|
assert(nir_src_num_components(tex->src[i].src) == 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case nir_tex_src_lod:
|
||||||
|
has_lod = true;
|
||||||
|
lod = get_src_float(ctx, &tex->src[i].src);
|
||||||
|
assert(nir_src_num_components(tex->src[i].src) == 1);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "texture source: %d\n", tex->src[i].src_type);
|
fprintf(stderr, "texture source: %d\n", tex->src[i].src_type);
|
||||||
unreachable("unknown texture source");
|
unreachable("unknown texture source");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!has_lod && ctx->stage != MESA_SHADER_FRAGMENT) {
|
||||||
|
has_lod = true;
|
||||||
|
lod = spirv_builder_const_float(&ctx->builder, 32, 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool is_ms;
|
bool is_ms;
|
||||||
SpvDim dimension = type_to_dim(tex->sampler_dim, &is_ms);
|
SpvDim dimension = type_to_dim(tex->sampler_dim, &is_ms);
|
||||||
SpvId float_type = spirv_builder_type_float(&ctx->builder, 32);
|
SpvId float_type = spirv_builder_type_float(&ctx->builder, 32);
|
||||||
@@ -1131,14 +1142,29 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
|
|||||||
constituents,
|
constituents,
|
||||||
coord_components);
|
coord_components);
|
||||||
|
|
||||||
result = spirv_builder_emit_image_sample_proj_implicit_lod(&ctx->builder,
|
if (has_lod)
|
||||||
dest_type,
|
result = spirv_builder_emit_image_sample_proj_explicit_lod(&ctx->builder,
|
||||||
load,
|
dest_type,
|
||||||
merged);
|
load,
|
||||||
} else
|
merged,
|
||||||
result = spirv_builder_emit_image_sample_implicit_lod(&ctx->builder,
|
lod);
|
||||||
dest_type, load,
|
else
|
||||||
coord);
|
result = spirv_builder_emit_image_sample_proj_implicit_lod(&ctx->builder,
|
||||||
|
dest_type,
|
||||||
|
load,
|
||||||
|
merged);
|
||||||
|
} else {
|
||||||
|
if (has_lod)
|
||||||
|
result = spirv_builder_emit_image_sample_explicit_lod(&ctx->builder,
|
||||||
|
dest_type,
|
||||||
|
load,
|
||||||
|
coord, lod);
|
||||||
|
else
|
||||||
|
result = spirv_builder_emit_image_sample_implicit_lod(&ctx->builder,
|
||||||
|
dest_type,
|
||||||
|
load,
|
||||||
|
coord);
|
||||||
|
}
|
||||||
spirv_builder_emit_decoration(&ctx->builder, result,
|
spirv_builder_emit_decoration(&ctx->builder, result,
|
||||||
SpvDecorationRelaxedPrecision);
|
SpvDecorationRelaxedPrecision);
|
||||||
|
|
||||||
|
@@ -521,6 +521,25 @@ spirv_builder_emit_image_sample_implicit_lod(struct spirv_builder *b,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpvId
|
||||||
|
spirv_builder_emit_image_sample_explicit_lod(struct spirv_builder *b,
|
||||||
|
SpvId result_type,
|
||||||
|
SpvId sampled_image,
|
||||||
|
SpvId coordinate,
|
||||||
|
SpvId lod)
|
||||||
|
{
|
||||||
|
SpvId result = spirv_builder_new_id(b);
|
||||||
|
spirv_buffer_prepare(&b->instructions, 7);
|
||||||
|
spirv_buffer_emit_word(&b->instructions, SpvOpImageSampleExplicitLod | (7 << 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);
|
||||||
|
spirv_buffer_emit_word(&b->instructions, SpvImageOperandsLodMask);
|
||||||
|
spirv_buffer_emit_word(&b->instructions, lod);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
SpvId
|
SpvId
|
||||||
spirv_builder_emit_image_sample_proj_implicit_lod(struct spirv_builder *b,
|
spirv_builder_emit_image_sample_proj_implicit_lod(struct spirv_builder *b,
|
||||||
SpvId result_type,
|
SpvId result_type,
|
||||||
@@ -537,6 +556,25 @@ spirv_builder_emit_image_sample_proj_implicit_lod(struct spirv_builder *b,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpvId
|
||||||
|
spirv_builder_emit_image_sample_proj_explicit_lod(struct spirv_builder *b,
|
||||||
|
SpvId result_type,
|
||||||
|
SpvId sampled_image,
|
||||||
|
SpvId coordinate,
|
||||||
|
SpvId lod)
|
||||||
|
{
|
||||||
|
SpvId result = spirv_builder_new_id(b);
|
||||||
|
spirv_buffer_prepare(&b->instructions, 7);
|
||||||
|
spirv_buffer_emit_word(&b->instructions, SpvOpImageSampleProjImplicitLod | (7 << 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);
|
||||||
|
spirv_buffer_emit_word(&b->instructions, SpvImageOperandsLodMask);
|
||||||
|
spirv_buffer_emit_word(&b->instructions, lod);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
SpvId
|
SpvId
|
||||||
spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,
|
spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,
|
||||||
SpvId set, uint32_t instruction,
|
SpvId set, uint32_t instruction,
|
||||||
|
@@ -207,12 +207,26 @@ spirv_builder_emit_image_sample_implicit_lod(struct spirv_builder *b,
|
|||||||
SpvId sampled_image,
|
SpvId sampled_image,
|
||||||
SpvId coordinate);
|
SpvId coordinate);
|
||||||
|
|
||||||
|
SpvId
|
||||||
|
spirv_builder_emit_image_sample_explicit_lod(struct spirv_builder *b,
|
||||||
|
SpvId result_type,
|
||||||
|
SpvId sampled_image,
|
||||||
|
SpvId coordinate,
|
||||||
|
SpvId lod);
|
||||||
|
|
||||||
SpvId
|
SpvId
|
||||||
spirv_builder_emit_image_sample_proj_implicit_lod(struct spirv_builder *b,
|
spirv_builder_emit_image_sample_proj_implicit_lod(struct spirv_builder *b,
|
||||||
SpvId result_type,
|
SpvId result_type,
|
||||||
SpvId sampled_image,
|
SpvId sampled_image,
|
||||||
SpvId coordinate);
|
SpvId coordinate);
|
||||||
|
|
||||||
|
SpvId
|
||||||
|
spirv_builder_emit_image_sample_proj_explicit_lod(struct spirv_builder *b,
|
||||||
|
SpvId result_type,
|
||||||
|
SpvId sampled_image,
|
||||||
|
SpvId coordinate,
|
||||||
|
SpvId lod);
|
||||||
|
|
||||||
SpvId
|
SpvId
|
||||||
spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,
|
spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,
|
||||||
SpvId set, uint32_t instruction,
|
SpvId set, uint32_t instruction,
|
||||||
|
Reference in New Issue
Block a user