From a34edc7500c84bfd52cf71cb78db46c34d436ae2 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 30 Jan 2023 20:12:03 -0600 Subject: [PATCH] nvk: Fill out sample locations on Maxwell B+ Part-of: --- src/nouveau/vulkan/nvk_cmd_buffer.c | 2 + src/nouveau/vulkan/nvk_cmd_buffer.h | 1 + src/nouveau/vulkan/nvk_cmd_draw.c | 66 +++++++++++++++++++++- src/nouveau/vulkan/nvk_cmd_meta.c | 4 ++ src/nouveau/vulkan/nvk_graphics_pipeline.c | 1 + src/nouveau/vulkan/nvk_physical_device.c | 4 +- src/nouveau/vulkan/nvk_pipeline.h | 1 + 7 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/nouveau/vulkan/nvk_cmd_buffer.c b/src/nouveau/vulkan/nvk_cmd_buffer.c index ba4571f66e5..4a3f02e927c 100644 --- a/src/nouveau/vulkan/nvk_cmd_buffer.c +++ b/src/nouveau/vulkan/nvk_cmd_buffer.c @@ -51,6 +51,8 @@ nvk_create_cmd_buffer(struct vk_command_pool *vk_pool, cmd->vk.dynamic_graphics_state.vi = &cmd->state.gfx._dynamic_vi; + cmd->vk.dynamic_graphics_state.ms.sample_locations = + &cmd->state.gfx._dynamic_sl; list_inithead(&cmd->bos); util_dynarray_init(&cmd->pushes, NULL); diff --git a/src/nouveau/vulkan/nvk_cmd_buffer.h b/src/nouveau/vulkan/nvk_cmd_buffer.h index a991af93e2c..ef12cbef2c1 100644 --- a/src/nouveau/vulkan/nvk_cmd_buffer.h +++ b/src/nouveau/vulkan/nvk_cmd_buffer.h @@ -83,6 +83,7 @@ struct nvk_graphics_state { /* Needed by vk_command_buffer::dynamic_graphics_state */ struct vk_vertex_input_state _dynamic_vi; + struct vk_sample_locations_state _dynamic_sl; }; struct nvk_compute_state { diff --git a/src/nouveau/vulkan/nvk_cmd_draw.c b/src/nouveau/vulkan/nvk_cmd_draw.c index 052493e33bd..36e58c1ed94 100644 --- a/src/nouveau/vulkan/nvk_cmd_draw.c +++ b/src/nouveau/vulkan/nvk_cmd_draw.c @@ -9,6 +9,7 @@ #include "nvk_pipeline.h" #include "nil_format.h" +#include "util/bitpack_helpers.h" #include "vulkan/runtime/vk_render_pass.h" #include "vulkan/util/vk_format.h" @@ -909,6 +910,69 @@ nvk_flush_rs_state(struct nvk_cmd_buffer *cmd) } } +static VkSampleLocationEXT +vk_sample_location(const struct vk_sample_locations_state *sl, + uint32_t x, uint32_t y, uint32_t s) +{ + x = x % sl->grid_size.width; + y = y % sl->grid_size.height; + + return sl->locations[(x + y * sl->grid_size.width) * sl->per_pixel + s]; +} + +struct nvk_sample_location { + uint8_t x_u4:4; + uint8_t y_u4:4; +}; + +static struct nvk_sample_location +vk_to_nvk_sample_location(VkSampleLocationEXT loc) +{ + return (struct nvk_sample_location) { + .x_u4 = util_bitpack_ufixed(loc.x, 0, 3, 4), + .y_u4 = util_bitpack_ufixed(loc.y, 0, 3, 4), + }; +} + +static void +nvk_flush_ms_state(struct nvk_cmd_buffer *cmd) +{ + const struct vk_dynamic_graphics_state *dyn = + &cmd->vk.dynamic_graphics_state; + + if (BITSET_TEST(dyn->dirty, MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS)) { + const struct vk_sample_locations_state *sl = dyn->ms.sample_locations; + + if (nvk_cmd_buffer_3d_cls(cmd) >= MAXWELL_B) { + struct nvk_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)); + } + + struct nv_push *p = nvk_cmd_buffer_push(cmd, 5); + + P_MTHD(p, NVB197, SET_ANTI_ALIAS_SAMPLE_POSITIONS(0)); + for (uint32_t i = 0; i < 4; i++) { + P_NVB197_SET_ANTI_ALIAS_SAMPLE_POSITIONS(p, i, { + .x0 = loc[i * 4 + 0].x_u4, + .y0 = loc[i * 4 + 0].y_u4, + .x1 = loc[i * 4 + 1].x_u4, + .y1 = loc[i * 4 + 1].y_u4, + .x2 = loc[i * 4 + 2].x_u4, + .y2 = loc[i * 4 + 2].y_u4, + .x3 = loc[i * 4 + 3].x_u4, + .y3 = loc[i * 4 + 3].y_u4, + }); + } + } + } +} + static uint32_t vk_to_nv9097_compare_op(VkCompareOp vk_op) { @@ -1085,8 +1149,8 @@ nvk_flush_dynamic_state(struct nvk_cmd_buffer *cmd) nvk_flush_rs_state(cmd); /* MESA_VK_DYNAMIC_FSR */ - /* MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS */ + nvk_flush_ms_state(cmd); nvk_flush_ds_state(cmd); nvk_flush_cb_state(cmd); diff --git a/src/nouveau/vulkan/nvk_cmd_meta.c b/src/nouveau/vulkan/nvk_cmd_meta.c index 65ddb5c3c21..161cd168aa8 100644 --- a/src/nouveau/vulkan/nvk_cmd_meta.c +++ b/src/nouveau/vulkan/nvk_cmd_meta.c @@ -46,6 +46,7 @@ nvk_device_finish_meta(struct nvk_device *dev) struct nvk_meta_save { struct vk_vertex_input_state _dynamic_vi; + struct vk_sample_locations_state _dynamic_sl; struct vk_dynamic_graphics_state dynamic; struct nvk_graphics_pipeline *pipeline; struct nvk_addr_range vb0; @@ -61,6 +62,7 @@ nvk_meta_begin(struct nvk_cmd_buffer *cmd, { save->dynamic = cmd->vk.dynamic_graphics_state; save->_dynamic_vi = cmd->state.gfx._dynamic_vi; + save->_dynamic_sl = cmd->state.gfx._dynamic_sl; save->pipeline = cmd->state.gfx.pipeline; save->vb0 = cmd->state.gfx.vb0; @@ -105,8 +107,10 @@ nvk_meta_end(struct nvk_cmd_buffer *cmd, /* Restore the dynamic state */ assert(save->dynamic.vi == &cmd->state.gfx._dynamic_vi); + assert(save->dynamic.ms.sample_locations == &cmd->state.gfx._dynamic_sl); cmd->vk.dynamic_graphics_state = save->dynamic; cmd->state.gfx._dynamic_vi = save->_dynamic_vi; + cmd->state.gfx._dynamic_sl = save->_dynamic_sl; memcpy(cmd->vk.dynamic_graphics_state.dirty, cmd->vk.dynamic_graphics_state.set, sizeof(cmd->vk.dynamic_graphics_state.set)); diff --git a/src/nouveau/vulkan/nvk_graphics_pipeline.c b/src/nouveau/vulkan/nvk_graphics_pipeline.c index e0200fb74ea..278eeea6e00 100644 --- a/src/nouveau/vulkan/nvk_graphics_pipeline.c +++ b/src/nouveau/vulkan/nvk_graphics_pipeline.c @@ -355,6 +355,7 @@ nvk_graphics_pipeline_create(struct nvk_device *device, pipeline->push_dw_count = nv_push_dw_count(&push); pipeline->dynamic.vi = &pipeline->_dynamic_vi; + pipeline->dynamic.ms.sample_locations = &pipeline->_dynamic_sl; vk_dynamic_graphics_state_fill(&pipeline->dynamic, &state); *pPipeline = nvk_pipeline_to_handle(&pipeline->base); diff --git a/src/nouveau/vulkan/nvk_physical_device.c b/src/nouveau/vulkan/nvk_physical_device.c index 1488785d779..baad7d1892f 100644 --- a/src/nouveau/vulkan/nvk_physical_device.c +++ b/src/nouveau/vulkan/nvk_physical_device.c @@ -16,6 +16,7 @@ #include "cla0c0.h" #include "cla1c0.h" #include "clb0c0.h" +#include "clb197.h" #include "clb1c0.h" #include "clc0c0.h" #include "clc1c0.h" @@ -355,7 +356,7 @@ vk_icdGetPhysicalDeviceProcAddr(VkInstance _instance, const char *pName) } static void -nvk_get_device_extensions(const struct nvk_physical_device *device, +nvk_get_device_extensions(const struct nvk_physical_device *pdev, struct vk_device_extension_table *ext) { *ext = (struct vk_device_extension_table) { @@ -390,6 +391,7 @@ nvk_get_device_extensions(const struct nvk_physical_device *device, .EXT_inline_uniform_block = true, .EXT_pci_bus_info = true, .EXT_private_data = true, + .EXT_sample_locations = pdev->info.cls_eng3d >= MAXWELL_B, .EXT_vertex_input_dynamic_state = true, }; } diff --git a/src/nouveau/vulkan/nvk_pipeline.h b/src/nouveau/vulkan/nvk_pipeline.h index bedfcd86008..3313e0a3df0 100644 --- a/src/nouveau/vulkan/nvk_pipeline.h +++ b/src/nouveau/vulkan/nvk_pipeline.h @@ -54,6 +54,7 @@ struct nvk_graphics_pipeline { uint32_t push_dw_count; struct vk_vertex_input_state _dynamic_vi; + struct vk_sample_locations_state _dynamic_sl; struct vk_dynamic_graphics_state dynamic; };