anv/cmd_buffer: Stop relying on the framebuffer for 3DSTATE_SF on gen7
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 19 Oct 2016 23:37:03 +0000 (16:37 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 16 Nov 2016 18:11:07 +0000 (10:11 -0800)
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
src/intel/vulkan/gen7_cmd_buffer.c

index c1b7724599f1f39838e630c8a1ebfb2a3320b858..38e400b2d17b07cca8ba5adb5cea0948811761f7 100644 (file)
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 
 #include "anv_private.h"
+#include "vk_format_info.h"
 
 #include "genxml/gen_macros.h"
 #include "genxml/genX_pack.h"
@@ -121,6 +122,36 @@ void genX(CmdBindIndexBuffer)(
    cmd_buffer->state.gen7.index_offset = offset;
 }
 
+static uint32_t
+get_depth_format(struct anv_cmd_buffer *cmd_buffer)
+{
+   const struct anv_render_pass *pass = cmd_buffer->state.pass;
+   const struct anv_subpass *subpass = cmd_buffer->state.subpass;
+
+   if (subpass->depth_stencil_attachment >= pass->attachment_count)
+      return D16_UNORM;
+
+   struct anv_render_pass_attachment *att =
+      &pass->attachments[subpass->depth_stencil_attachment];
+
+   switch (att->format) {
+   case VK_FORMAT_D16_UNORM:
+   case VK_FORMAT_D16_UNORM_S8_UINT:
+      return D16_UNORM;
+
+   case VK_FORMAT_X8_D24_UNORM_PACK32:
+   case VK_FORMAT_D24_UNORM_S8_UINT:
+      return D24_UNORM_X8_UINT;
+
+   case VK_FORMAT_D32_SFLOAT:
+   case VK_FORMAT_D32_SFLOAT_S8_UINT:
+      return D32_FLOAT;
+
+   default:
+      return D16_UNORM;
+   }
+}
+
 void
 genX(cmd_buffer_flush_dynamic_state)(struct anv_cmd_buffer *cmd_buffer)
 {
@@ -130,20 +161,10 @@ genX(cmd_buffer_flush_dynamic_state)(struct anv_cmd_buffer *cmd_buffer)
                                   ANV_CMD_DIRTY_RENDER_TARGETS |
                                   ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH |
                                   ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS)) {
-
-      const struct anv_image_view *iview =
-         anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
-      const struct anv_image *image = iview ? iview->image : NULL;
-      const bool has_depth =
-         image && (image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT);
-      const uint32_t depth_format = has_depth ?
-         isl_surf_get_depth_format(&cmd_buffer->device->isl_dev,
-                                   &image->depth_surface.isl) : D16_UNORM;
-
       uint32_t sf_dw[GENX(3DSTATE_SF_length)];
       struct GENX(3DSTATE_SF) sf = {
          GENX(3DSTATE_SF_header),
-         .DepthBufferSurfaceFormat = depth_format,
+         .DepthBufferSurfaceFormat = get_depth_format(cmd_buffer),
          .LineWidth = cmd_buffer->state.dynamic.line_width,
          .GlobalDepthOffsetConstant = cmd_buffer->state.dynamic.depth_bias.bias,
          .GlobalDepthOffsetScale = cmd_buffer->state.dynamic.depth_bias.slope,