anv: ensure CPS is initialized when KHR_fragment_shading_rate is disabled
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Sat, 19 Nov 2022 01:35:27 +0000 (03:35 +0200)
committerMarge Bot <emma+marge@anholt.net>
Tue, 22 Nov 2022 03:53:57 +0000 (03:53 +0000)
We need to set CPS_MODE_NONE when no per coarse pixel dispatch.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Fixes: 231651fd89fb ("anv: implement VK_KHR_fragment_shading_rate")
Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Ivan Briano <ivan.briano@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19867>

src/intel/vulkan/anv_device.c
src/intel/vulkan/genX_state.c

index 8179a35..1c384cd 100644 (file)
@@ -3540,8 +3540,10 @@ VkResult anv_CreateDevice(
    if (result != VK_SUCCESS)
       goto fail_ray_query_bo;
 
-   if (device->info->ver >= 12 &&
-       device->vk.enabled_extensions.KHR_fragment_shading_rate) {
+   /* Emit the CPS states before running the initialization batch as those
+    * structures are referenced.
+    */
+   if (device->info->ver >= 12) {
       uint32_t n_cps_states = 3 * 3; /* All combinaisons of X by Y CP sizes (1, 2, 4) */
 
       if (device->info->has_coarse_pixel_primitive_and_cb)
index b084ece..92ba28b 100644 (file)
@@ -178,7 +178,10 @@ init_common_queue_state(struct anv_queue *queue, struct anv_batch *batch)
    device->l3_config = cfg;
 #endif
 
-#if GFX_VERx10 >= 125
+   /* Emit STATE_BASE_ADDRESS on Gfx12+ because we set a default CPS_STATE and
+    * those are relative to STATE_BASE_ADDRESS::DynamicStateBaseAddress.
+    */
+#if GFX_VERx >= 12
    /* GEN:BUG:1607854226:
     *
     *  Non-pipelined state has issues with not applying in MEDIA/GPGPU mode.
@@ -452,6 +455,21 @@ init_render_queue_state(struct anv_queue *queue)
 
    init_common_queue_state(queue, &batch);
 
+   /* Because 3DSTATE_CPS::CoarsePixelShadingStateArrayPointer is relative to
+    * the dynamic state base address we need to emit this instruction after
+    * STATE_BASE_ADDRESS in init_common_queue_state().
+    */
+#if GFX_VER == 11
+   anv_batch_emit(&batch, GENX(3DSTATE_CPS), cps);
+#elif GFX_VER >= 12
+   anv_batch_emit(&batch, GENX(3DSTATE_CPS_POINTERS), cps) {
+      assert(device->cps_states.alloc_size != 0);
+      /* Offset 0 is the disabled state */
+      cps.CoarsePixelShadingStateArrayPointer =
+         device->cps_states.offset;
+   }
+#endif
+
    anv_batch_emit(&batch, GENX(MI_BATCH_BUFFER_END), bbe);
 
    assert(batch.next <= batch.end);
@@ -542,15 +560,19 @@ genX(init_cps_device_state)(struct anv_device *device)
 
    /* Disabled CPS mode */
    for (uint32_t __v = 0; __v < MAX_VIEWPORTS; __v++) {
+      /* ICL PRMs, Volume 2d: Command Reference: Structures: 3DSTATE_CPS_BODY:
+       *
+       *   "It is an INVALID configuration to set the CPS mode other than
+       *    CPS_MODE_NONE and request per-sample dispatch in 3DSTATE_PS_EXTRA.
+       *    Such configuration should be disallowed at the API level, and
+       *    rendering results are undefined."
+       *
+       * Since we select this state when per coarse pixel is disabled and that
+       * includes when per-sample dispatch is enabled, we need to ensure this
+       * is set to NONE.
+       */
       struct GENX(CPS_STATE) cps_state = {
-         .CoarsePixelShadingMode = CPS_MODE_CONSTANT,
-         .MinCPSizeX = 1,
-         .MinCPSizeY = 1,
-#if GFX_VERx10 >= 125
-         .Combiner0OpcodeforCPsize = PASSTHROUGH,
-         .Combiner1OpcodeforCPsize = PASSTHROUGH,
-#endif /* GFX_VERx10 >= 125 */
-
+         .CoarsePixelShadingMode = CPS_MODE_NONE,
       };
 
       GENX(CPS_STATE_pack)(NULL, cps_state_ptr, &cps_state);