nvk,nak: Store offsets in a const extern struct

Move some of this constant data out of fs_key and into a constant
struct. This reduces the size of the fs_key and gives us a spot to add
additional non-fs offsets like printf buffers.

Passing this through a const global may be a little odd but it has the
benefit that we don't need to hash the offsets as additinal state
relevant to a compilation, since they can never change without
a modification to the binary.

Reviewed-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39869>
This commit is contained in:
Mel Henning 2026-02-12 15:12:18 -05:00 committed by Marge Bot
parent bd5ebbb2f8
commit 013b21d52f
3 changed files with 17 additions and 11 deletions

View file

@ -58,6 +58,12 @@ struct nak_fs_key {
bool force_sample_shading;
bool uses_underestimate;
uint8_t pad;
};
PRAGMA_DIAGNOSTIC_POP
static_assert(sizeof(struct nak_fs_key) == 4, "This struct has no holes");
struct nak_constant_offset_info {
/**
* The constant buffer index and offset at which the sample locations and
* pass sample masks tables lives.
@ -80,9 +86,7 @@ struct nak_fs_key {
*/
uint32_t sample_masks_offset;
};
PRAGMA_DIAGNOSTIC_POP
static_assert(sizeof(struct nak_fs_key) == 12, "This struct has no holes");
const extern struct nak_constant_offset_info nak_const_offsets;
void nak_postprocess_nir(nir_shader *nir, const struct nak_compiler *nak,
nir_variable_mode robust2_modes,

View file

@ -100,9 +100,9 @@ load_sample_pos_u4_at(nir_builder *b, nir_def *sample_id,
const struct nak_fs_key *fs_key)
{
nir_def *loc = nir_ldc_nv(b, 1, 8,
nir_imm_int(b, fs_key->sample_info_cb),
nir_imm_int(b, nak_const_offsets.sample_info_cb),
nir_iadd_imm(b, sample_id,
fs_key->sample_locations_offset),
nak_const_offsets.sample_locations_offset),
.align_mul = 1, .align_offset = 0);
/* The rest of these calculations are in 32-bit */
@ -118,10 +118,10 @@ load_pass_sample_mask_at(nir_builder *b, nir_def *sample_id,
{
nir_def *offset =
nir_imul_imm(b, sample_id, sizeof(struct nak_sample_mask));
offset = nir_iadd_imm(b, offset, fs_key->sample_masks_offset);
offset = nir_iadd_imm(b, offset, nak_const_offsets.sample_masks_offset);
return nir_ldc_nv(b, 1, 8 * sizeof(struct nak_sample_mask),
nir_imm_int(b, fs_key->sample_info_cb), offset,
nir_imm_int(b, nak_const_offsets.sample_info_cb), offset,
.align_mul = sizeof(struct nak_sample_mask),
.align_offset = 0);
}

View file

@ -34,6 +34,12 @@
#include "nv_push_clc397.h"
#include "nv_push_clc797.h"
const struct nak_constant_offset_info nak_const_offsets = {
.sample_info_cb = 0,
.sample_locations_offset = nvk_root_descriptor_offset(draw.sample_locations),
.sample_masks_offset = nvk_root_descriptor_offset(draw.sample_masks),
};
static void
shared_var_info(const struct glsl_type *type, unsigned *size, unsigned *align)
{
@ -152,10 +158,6 @@ nvk_populate_fs_key(struct nak_fs_key *key,
{
memset(key, 0, sizeof(*key));
key->sample_info_cb = 0;
key->sample_locations_offset = nvk_root_descriptor_offset(draw.sample_locations);
key->sample_masks_offset = nvk_root_descriptor_offset(draw.sample_masks);
/* Turn underestimate on when no state is availaible or if explicitly set */
if (state == NULL || state->rs == NULL ||
state->rs->conservative_mode == VK_CONSERVATIVE_RASTERIZATION_MODE_UNDERESTIMATE_EXT)