nvk: Support dynamic state for enabling sample locations
authorGeorge Ouzounoudis <geothrock@gmail.com>
Wed, 9 Aug 2023 21:03:24 +0000 (00:03 +0300)
committerMarge Bot <emma+marge@anholt.net>
Fri, 11 Aug 2023 19:27:24 +0000 (19:27 +0000)
When switching dynamically we should also push the corresponding sample
locations, the default when disabled or the custom ones when enabled.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24592>

src/nouveau/vulkan/nvk_cmd_draw.c
src/nouveau/vulkan/nvk_physical_device.c

index 6eeb9c6..3e7c665 100644 (file)
@@ -11,6 +11,7 @@
 #include "nil_format.h"
 #include "util/bitpack_helpers.h"
 #include "vulkan/runtime/vk_render_pass.h"
+#include "vulkan/runtime/vk_standard_sample_locations.h"
 #include "vulkan/util/vk_format.h"
 
 #include "nouveau_context.h"
@@ -1206,8 +1207,8 @@ 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),
+      .x_u4 = util_bitpack_ufixed_clamp(loc.x, 0, 3, 4),
+      .y_u4 = util_bitpack_ufixed_clamp(loc.y, 0, 3, 4),
    };
 }
 
@@ -1217,8 +1218,14 @@ 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 (BITSET_TEST(dyn->dirty, MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS) ||
+       BITSET_TEST(dyn->dirty, MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS_ENABLE)) {
+      const struct vk_sample_locations_state *sl;
+      if (dyn->ms.sample_locations_enable) {
+         sl = dyn->ms.sample_locations;
+      } else {
+         sl = vk_standard_sample_locations_state(dyn->ms.rasterization_samples);
+      }
 
       if (nvk_cmd_buffer_3d_cls(cmd) >= MAXWELL_B) {
          struct nvk_sample_location loc[16];
index aa9b3a9..7e0834f 100644 (file)
@@ -293,7 +293,7 @@ nvk_get_device_features(const struct nv_device_info *info,
       .extendedDynamicState3ConservativeRasterizationMode = false,
       .extendedDynamicState3ExtraPrimitiveOverestimationSize = false,
       .extendedDynamicState3DepthClipEnable = false,
-      .extendedDynamicState3SampleLocationsEnable = false,
+      .extendedDynamicState3SampleLocationsEnable = info->cls_eng3d >= MAXWELL_B,
       .extendedDynamicState3ColorBlendAdvanced = false,
       .extendedDynamicState3ProvokingVertexMode = true,
       .extendedDynamicState3LineRasterizationMode = true,