From 315b788c7b30b99ceed8b98bb1ac5826a19dd7cb Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 5 Aug 2024 09:04:12 -0500 Subject: [PATCH] nvk: Move nvk_sample_location to NAK It's part of the NAK compiler interface so that's where it should live. Part-of: --- src/nouveau/compiler/nak.h | 21 +++++++++++++++++---- src/nouveau/vulkan/nvk_cmd_buffer.h | 9 +-------- src/nouveau/vulkan/nvk_cmd_draw.c | 14 +++++++------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/nouveau/compiler/nak.h b/src/nouveau/compiler/nak.h index 805b283b9f8..1b67b930d87 100644 --- a/src/nouveau/compiler/nak.h +++ b/src/nouveau/compiler/nak.h @@ -31,6 +31,13 @@ nak_nir_options(const struct nak_compiler *nak); void nak_preprocess_nir(nir_shader *nir, const struct nak_compiler *nak); +struct nak_sample_location { + uint8_t x_u4 : 4; + uint8_t y_u4 : 4; +}; +static_assert(sizeof(struct nak_sample_location) == 1, + "This struct has no holes"); + PRAGMA_DIAGNOSTIC_PUSH PRAGMA_DIAGNOSTIC_ERROR(-Wpadded) struct nak_fs_key { @@ -43,11 +50,17 @@ struct nak_fs_key { bool uses_underestimate; /** - * The constant buffer index and offset at which the sample locations table lives. - * Each sample location is two 4-bit unorm values packed into an 8-bit value - * with the bottom 4 bits for x and the top 4 bits for y. - */ + * The constant buffer index and offset at which the sample locations table + * lives. + */ uint8_t sample_locations_cb; + + /** + * The offset into sample_info_cb at which the sample locations live. The + * sample locations table is an array of nak_sample_location where each + * sample location is two 4-bit unorm values packed into an 8-bit value + * with the bottom 4 bits for x and the top 4 bits for y. + */ uint32_t sample_locations_offset; }; PRAGMA_DIAGNOSTIC_POP diff --git a/src/nouveau/vulkan/nvk_cmd_buffer.h b/src/nouveau/vulkan/nvk_cmd_buffer.h index ea93631ca56..8f4bc2d185c 100644 --- a/src/nouveau/vulkan/nvk_cmd_buffer.h +++ b/src/nouveau/vulkan/nvk_cmd_buffer.h @@ -29,13 +29,6 @@ struct nvk_push_descriptor_set; struct nvk_shader; struct vk_shader; -struct nvk_sample_location { - uint8_t x_u4:4; - uint8_t y_u4:4; -}; -static_assert(sizeof(struct nvk_sample_location) == 1, - "This struct has no holes"); - /** Root descriptor table. This gets pushed to the GPU directly */ struct nvk_root_descriptor_table { union { @@ -44,7 +37,7 @@ struct nvk_root_descriptor_table { uint32_t base_instance; uint32_t draw_index; uint32_t view_index; - struct nvk_sample_location sample_locations[NVK_MAX_SAMPLES]; + struct nak_sample_location sample_locations[NVK_MAX_SAMPLES]; } draw; struct { uint32_t base_group[3]; diff --git a/src/nouveau/vulkan/nvk_cmd_draw.c b/src/nouveau/vulkan/nvk_cmd_draw.c index ba9d0af78fc..52d3a8c1b96 100644 --- a/src/nouveau/vulkan/nvk_cmd_draw.c +++ b/src/nouveau/vulkan/nvk_cmd_draw.c @@ -1941,10 +1941,10 @@ vk_sample_location(const struct vk_sample_locations_state *sl, return sl->locations[(x + y * sl->grid_size.width) * sl->per_pixel + s]; } -static struct nvk_sample_location -vk_to_nvk_sample_location(VkSampleLocationEXT loc) +static struct nak_sample_location +vk_to_nak_sample_location(VkSampleLocationEXT loc) { - return (struct nvk_sample_location) { + return (struct nak_sample_location) { .x_u4 = util_bitpack_ufixed_clamp(loc.x, 0, 3, 4), .y_u4 = util_bitpack_ufixed_clamp(loc.y, 0, 3, 4), }; @@ -2013,23 +2013,23 @@ nvk_flush_ms_state(struct nvk_cmd_buffer *cmd) sl = vk_standard_sample_locations_state(samples); } - struct nvk_sample_location push_sl[NVK_MAX_SAMPLES]; + struct nak_sample_location push_sl[NVK_MAX_SAMPLES]; for (uint32_t i = 0; i < sl->per_pixel; i++) - push_sl[i] = vk_to_nvk_sample_location(sl->locations[i]); + push_sl[i] = vk_to_nak_sample_location(sl->locations[i]); nvk_descriptor_state_set_root_array(cmd, &cmd->state.gfx.descriptors, draw.sample_locations, 0, NVK_MAX_SAMPLES, push_sl); if (nvk_cmd_buffer_3d_cls(cmd) >= MAXWELL_B) { - struct nvk_sample_location loc[16]; + struct nak_sample_location loc[16]; for (uint32_t n = 0; n < ARRAY_SIZE(loc); n++) { const uint32_t s = n % sl->per_pixel; const uint32_t px = n / sl->per_pixel; const uint32_t x = px % 2; const uint32_t y = px / 2; - loc[n] = vk_to_nvk_sample_location(vk_sample_location(sl, x, y, s)); + loc[n] = vk_to_nak_sample_location(vk_sample_location(sl, x, y, s)); } struct nv_push *p = nvk_cmd_buffer_push(cmd, 5);