[Mesa-dev] [PATCH 07/25] anv/cmd_buffer: Stop relying on the framebuffer for 3DSTATE_SF on gen7

Jason Ekstrand jason at jlekstrand.net
Sat Oct 22 17:50:38 UTC 2016


---
 src/intel/vulkan/gen7_cmd_buffer.c | 43 ++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/src/intel/vulkan/gen7_cmd_buffer.c b/src/intel/vulkan/gen7_cmd_buffer.c
index c1b7724..38e400b 100644
--- a/src/intel/vulkan/gen7_cmd_buffer.c
+++ b/src/intel/vulkan/gen7_cmd_buffer.c
@@ -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,
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list