anv/gen7: A bunch of depth-stencil fixes
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 18 Nov 2015 19:43:48 +0000 (11:43 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 18 Nov 2015 19:43:52 +0000 (11:43 -0800)
There are various bits which move around between Haswell and Ivy Bridge
that we weren't taking into account.  This also makes us actually set the
StencilWriteEnable in a sane way.

src/vulkan/anv_private.h
src/vulkan/gen7_cmd_buffer.c
src/vulkan/gen7_pipeline.c

index 03e05fcb238073ed22995c6c848180478a62e994..fa6d48f7481fc4e5de1f3958e5bee54676eb919e 100644 (file)
@@ -838,6 +838,7 @@ enum anv_cmd_dirty_bits {
    ANV_CMD_DIRTY_DYNAMIC_ALL                       = (1 << 9) - 1,
    ANV_CMD_DIRTY_PIPELINE                          = 1 << 9,
    ANV_CMD_DIRTY_INDEX_BUFFER                      = 1 << 10,
+   ANV_CMD_DIRTY_RENDER_TARGETS                    = 1 << 11,
 };
 typedef uint32_t anv_cmd_dirty_mask_t;
 
index db420cdaa22a3edd4118b494c64529a47b1ebe44..9b10f080850037ad77a67c018add4ce547a740ef 100644 (file)
@@ -531,14 +531,16 @@ cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer)
    }
 
    if (cmd_buffer->state.dirty & (ANV_CMD_DIRTY_PIPELINE |
+                                  ANV_CMD_DIRTY_RENDER_TARGETS |
                                   ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK |
                                   ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK)) {
       uint32_t depth_stencil_dw[GEN7_DEPTH_STENCIL_STATE_length];
 
+      const struct anv_image_view *iview =
+         anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
+
       struct GEN7_DEPTH_STENCIL_STATE depth_stencil = {
-         /* Is this what we need to do? */
-         .StencilBufferWriteEnable =
-            cmd_buffer->state.dynamic.stencil_write_mask.front != 0,
+         .StencilBufferWriteEnable = iview && iview->format->has_stencil,
 
          .StencilTestMask =
             cmd_buffer->state.dynamic.stencil_compare_mask.front & 0xff,
@@ -920,7 +922,7 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
 
    /* Emit 3DSTATE_DEPTH_BUFFER */
    if (has_depth) {
-      anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_DEPTH_BUFFER,
+      anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DEPTH_BUFFER),
          .SurfaceType = SURFTYPE_2D,
          .DepthWriteEnable = iview->format->depth_format,
          .StencilWriteEnable = has_stencil,
@@ -936,7 +938,7 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
          .LOD = 0,
          .Depth = 1 - 1,
          .MinimumArrayElement = 0,
-         .DepthBufferObjectControlState = GEN7_MOCS,
+         .DepthBufferObjectControlState = GENX(MOCS),
          .RenderTargetViewExtent = 1 - 1);
    } else {
       /* Even when no depth buffer is present, the hardware requires that
@@ -956,7 +958,7 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
        * actual framebuffer's width and height, even when neither depth buffer
        * nor stencil buffer is present.
        */
-      anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_DEPTH_BUFFER,
+      anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DEPTH_BUFFER),
          .SurfaceType = SURFTYPE_2D,
          .SurfaceFormat = D16_UNORM,
          .Width = fb->width - 1,
@@ -966,8 +968,11 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
 
    /* Emit 3DSTATE_STENCIL_BUFFER */
    if (has_stencil) {
-      anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_STENCIL_BUFFER,
-         .StencilBufferObjectControlState = GEN7_MOCS,
+      anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_STENCIL_BUFFER),
+#     if (ANV_IS_HASWELL)
+         .StencilBufferEnable = true,
+#     endif
+         .StencilBufferObjectControlState = GENX(MOCS),
 
          /* Stencil buffers have strange pitch. The PRM says:
           *
@@ -997,6 +1002,7 @@ genX(cmd_buffer_begin_subpass)(struct anv_cmd_buffer *cmd_buffer,
 {
    cmd_buffer->state.subpass = subpass;
    cmd_buffer->state.descriptors_dirty |= VK_SHADER_STAGE_FRAGMENT_BIT;
+   cmd_buffer->state.dirty |= ANV_CMD_DIRTY_RENDER_TARGETS;
 
    cmd_buffer_emit_depth_stencil(cmd_buffer);
 }
index bcfa986769e9ec4d07dffd8a786728bd8e77528c..7d44c72b1a2310fbed31c213d9706df8fe2766bd 100644 (file)
@@ -224,17 +224,12 @@ gen7_emit_ds_state(struct anv_pipeline *pipeline,
       return;
    }
 
-   bool has_stencil = false;  /* enable if subpass has stencil? */
-
    struct GEN7_DEPTH_STENCIL_STATE state = {
       .DepthTestEnable = info->depthTestEnable,
       .DepthBufferWriteEnable = info->depthWriteEnable,
       .DepthTestFunction = vk_to_gen_compare_op[info->depthCompareOp],
       .DoubleSidedStencilEnable = true,
 
-      /* Is this what we need to do? */
-      .StencilBufferWriteEnable = has_stencil,
-
       .StencilTestEnable = info->stencilTestEnable,
       .StencilFailOp = vk_to_gen_stencil_op[info->front.stencilFailOp],
       .StencilPassDepthPassOp = vk_to_gen_stencil_op[info->front.stencilPassOp],