nvk: Put a sample map in the descriptor for MSAA storage images

This tells us exactly where each sample instead of assuming they're laid
out row-major. NIL_SAMPLE_LAYOUT_4X2_D3D is not row-major.

Fixes: 8f1697b12d ("nil: Use D3D sample modes by default")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31727>
This commit is contained in:
Faith Ekstrand
2024-10-17 16:19:14 -05:00
committed by Marge Bot
parent 9724028c15
commit d52a9d832e
4 changed files with 31 additions and 14 deletions
@@ -44,10 +44,6 @@ dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.n
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.non_multisample_buffer.sample_n_singlesample_rbo,Fail
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.non_multisample_buffer.sample_n_singlesample_texture,Fail
# Regression from a commit in the range c06a55fd...2fb4aed9
# Probably https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31585
KHR-GL46.multi_bind.dispatch_bind_textures,Fail
spec@!opengl 1.0@gl-1.0-no-op-paths,Fail
spec@!opengl 1.0@rasterpos,Fail
spec@!opengl 1.0@rasterpos@glsl_vs_gs_linked,Fail
+12
View File
@@ -136,6 +136,18 @@ get_storage_image_view_desc(const VkDescriptorImageInfo *const info,
nil_px_extent_sa(view->planes[plane].sample_layout);
desc.sw_log2 = util_logbase2(px_extent_sa.width);
desc.sh_log2 = util_logbase2(px_extent_sa.height);
const enum nil_sample_layout slayout = view->planes[plane].sample_layout;
if (slayout != NIL_SAMPLE_LAYOUT_1X1) {
uint32_t samples = nil_sample_layout_samples(slayout);
assert(samples <= 16);
for (uint32_t s = 0; s < samples; s++) {
const struct nil_sample_offset off = nil_sample_offset(slayout, s);
assert(off.x < 4 && off.y < 4);
uint32_t s_xy = off.y << 2 | off.x;
desc.sample_map |= s_xy << (s * 4);
}
}
}
assert(sizeof(desc) <= dst_size);
+8 -2
View File
@@ -28,10 +28,16 @@ struct nvk_storage_image_descriptor {
unsigned image_index:20;
unsigned sw_log2:2;
unsigned sh_log2:2;
unsigned pad:8;
unsigned _pad:8;
/* A 32-bit integer which acts as a map from sample index to x/y position
* within a pixel. Each nibble is a sample with x in the low 2 bits and y
* in the high 2 bits.
*/
unsigned sample_map:32;
};
PRAGMA_DIAGNOSTIC_POP
static_assert(sizeof(struct nvk_storage_image_descriptor) == 4,
static_assert(sizeof(struct nvk_storage_image_descriptor) == 8,
"nvk_storage_image_descriptor has no holes");
PRAGMA_DIAGNOSTIC_PUSH
+11 -8
View File
@@ -876,13 +876,16 @@ lower_msaa_image_intrin(nir_builder *b, nir_intrinsic_instr *intrin,
b->cursor = nir_before_instr(&intrin->instr);
nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
nir_def *desc = load_resource_deref_desc(b, 1, 32, deref, 0, ctx);
nir_def *desc = load_resource_deref_desc(b, 2, 32, deref, 0, ctx);
nir_def *desc0 = nir_channel(b, desc, 0);
nir_def *desc1 = nir_channel(b, desc, 1);
nir_def *img_index = nir_ubitfield_extract_imm(b, desc, 0, 20);
nir_def *img_index = nir_ubitfield_extract_imm(b, desc0, 0, 20);
nir_rewrite_image_intrinsic(intrin, img_index, true);
nir_def *sw_log2 = nir_ubitfield_extract_imm(b, desc, 20, 2);
nir_def *sh_log2 = nir_ubitfield_extract_imm(b, desc, 22, 2);
nir_def *sw_log2 = nir_ubitfield_extract_imm(b, desc0, 20, 2);
nir_def *sh_log2 = nir_ubitfield_extract_imm(b, desc0, 22, 2);
nir_def *s_map = desc1;
nir_def *sw = nir_ishl(b, nir_imm_int(b, 1), sw_log2);
nir_def *sh = nir_ishl(b, nir_imm_int(b, 1), sh_log2);
@@ -899,9 +902,9 @@ lower_msaa_image_intrin(nir_builder *b, nir_intrinsic_instr *intrin,
nir_def *w = nir_channel(b, intrin->src[1].ssa, 3);
nir_def *s = intrin->src[2].ssa;
nir_def *sw_mask = nir_iadd_imm(b, sw, -1);
nir_def *sx = nir_iand(b, s, sw_mask);
nir_def *sy = nir_ishr(b, s, sw_log2);
nir_def *s_xy = nir_ushr(b, s_map, nir_imul_imm(b, s, 4));
nir_def *sx = nir_ubitfield_extract_imm(b, s_xy, 0, 2);
nir_def *sy = nir_ubitfield_extract_imm(b, s_xy, 2, 2);
x = nir_imad(b, x, sw, sx);
y = nir_imad(b, y, sh, sy);
@@ -934,7 +937,7 @@ lower_msaa_image_intrin(nir_builder *b, nir_intrinsic_instr *intrin,
case nir_intrinsic_bindless_image_samples: {
/* We need to handle NULL descriptors explicitly */
nir_def *samples =
nir_bcsel(b, nir_ieq(b, desc, nir_imm_int(b, 0)),
nir_bcsel(b, nir_ieq(b, desc0, nir_imm_int(b, 0)),
nir_imm_int(b, 0), num_samples);
nir_def_rewrite_uses(&intrin->def, samples);
break;