nvk: Avoid passing garbage data in descriptor buffers for UBOs.

With the existing union setup, only the first 8 bytes are initialized
properly for UBOs, yet the UBO size is 16, and all 16 bytes are copied
to applications. This leads to broken capture-replay since the
descriptor payload is no longer invariant.

Fix this by ensuring all union members are 16 bytes, which then get
properly initialized with the designated initializers.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
Fixes: 8b5835af31 ("nvk: Use bindless cbufs on Turing+")
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37053>
This commit is contained in:
Hans-Kristian Arntzen 2025-08-28 14:06:58 +02:00
parent 603d6fe240
commit f28f72a5a2

View file

@ -74,9 +74,12 @@ PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
struct nvk_bindless_cbuf {
uint64_t base_addr_shift_4:45;
uint64_t size_shift_4:19;
/* For descriptor buffers, avoid returning garbage data.
* The descriptor payload must be invariant. */
uint64_t padding;
};
PRAGMA_DIAGNOSTIC_POP
static_assert(sizeof(struct nvk_bindless_cbuf) == 8,
static_assert(sizeof(struct nvk_bindless_cbuf) == 16,
"nvk_bindless_cbuf has no holes");
/* Hopper+ uses a new cbuf format */
@ -85,9 +88,12 @@ PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
struct nvk_bindless_cbuf_2 {
uint64_t base_addr_shift_6:51;
uint64_t size_shift_4:13;
/* For descriptor buffers, avoid returning garbage data.
* The descriptor payload must be invariant. */
uint64_t padding;
};
PRAGMA_DIAGNOSTIC_POP
static_assert(sizeof(struct nvk_bindless_cbuf_2) == 8,
static_assert(sizeof(struct nvk_bindless_cbuf_2) == 16,
"nvk_bindless_cbuf_2 has no holes");
/* This has to match nir_address_format_64bit_bounded_global */