nvk: Squash txq results to 0 for null descriptors

We don't have "real" null descriptors on Maxwell.  They return 0 okay
but they don't query right so we have to smash the result.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30381>
This commit is contained in:
Faith Ekstrand 2024-07-25 10:23:53 -05:00 committed by Marge Bot
parent efd86d6daa
commit 940e52ad15

View file

@ -12,6 +12,8 @@
#include "nir_builder.h"
#include "nir_deref.h"
#include "clc397.h"
struct lower_desc_cbuf {
struct nvk_cbuf key;
@ -48,6 +50,7 @@ compar_cbufs(const void *_a, const void *_b)
}
struct lower_descriptors_ctx {
const struct nv_device_info *dev_info;
const struct nvk_descriptor_set_layout *set_layouts[NVK_MAX_SETS];
bool use_bindless_cbuf;
@ -1051,12 +1054,13 @@ lower_tex(nir_builder *b, nir_tex_instr *tex,
const uint64_t plane_offset_B =
plane * sizeof(struct nvk_sampled_image_descriptor);
nir_def *texture_desc =
load_resource_deref_desc(b, 1, 32, texture, plane_offset_B, ctx);
nir_def *combined_handle;
if (texture == sampler) {
combined_handle = load_resource_deref_desc(b, 1, 32, texture, plane_offset_B, ctx);
combined_handle = texture_desc;
} else {
nir_def *texture_desc =
load_resource_deref_desc(b, 1, 32, texture, plane_offset_B, ctx);
combined_handle = nir_iand_imm(b, texture_desc,
NVK_IMAGE_DESCRIPTOR_IMAGE_INDEX_MASK);
@ -1086,6 +1090,23 @@ lower_tex(nir_builder *b, nir_tex_instr *tex,
tex->src[sampler_src_idx].src_type = nir_tex_src_sampler_handle;
}
/* On pre-Volta hardware, we don't have real null descriptors. Null
* descriptors work well enough for sampling but they may not return the
* correct query results.
*/
if (ctx->dev_info->cls_eng3d < VOLTA_A && nir_tex_instr_is_query(tex)) {
b->cursor = nir_after_instr(&tex->instr);
/* This should get CSE'd with the earlier load */
nir_def *texture_handle =
nir_iand_imm(b, texture_desc, NVK_IMAGE_DESCRIPTOR_IMAGE_INDEX_MASK);
nir_def *is_null = nir_ieq_imm(b, texture_handle, 0);
nir_def *zero = nir_imm_zero(b, tex->def.num_components,
tex->def.bit_size);
nir_def *res = nir_bcsel(b, is_null, zero, &tex->def);
nir_def_rewrite_uses_after(&tex->def, res, res->parent_instr);
}
return true;
}
@ -1318,6 +1339,7 @@ nvk_nir_lower_descriptors(nir_shader *nir,
struct nvk_cbuf_map *cbuf_map_out)
{
struct lower_descriptors_ctx ctx = {
.dev_info = &pdev->info,
.use_bindless_cbuf = nvk_use_bindless_cbuf(&pdev->info),
.clamp_desc_array_bounds =
rs->storage_buffers != VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT ||