#include <fcntl.h>
#include "anv_private.h"
+#include "vk_format_info.h"
#include "genxml/gen_macros.h"
#include "genxml/genX_pack.h"
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)
{
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,