From 3937e1a2980bbdcb9a24c0f0d97f342199e41807 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Mon, 1 Nov 2021 15:21:01 +0100 Subject: [PATCH] vkd3d: Handle illegal rendering to NULL DSV. Guardians of the Galaxy hits this case. Fallback is to disable depth attachment entirely in a fallback pipeline. Signed-off-by: Hans-Kristian Arntzen --- libs/vkd3d/command.c | 10 +--------- libs/vkd3d/state.c | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 5cbc48ec..e92998f0 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -4361,7 +4361,7 @@ static bool d3d12_command_list_has_depth_stencil_view(struct d3d12_command_list assert(d3d12_pipeline_state_is_graphics(list->state)); graphics = &list->state->graphics; - return graphics->dsv_format || (d3d12_pipeline_state_has_unknown_dsv_format(list->state) && list->dsv.format); + return list->dsv.format && (graphics->dsv_format || d3d12_pipeline_state_has_unknown_dsv_format(list->state)); } static void d3d12_command_list_get_fb_extent(struct d3d12_command_list *list, @@ -4583,14 +4583,6 @@ static bool d3d12_command_list_update_graphics_pipeline(struct d3d12_command_lis return false; } - /* Detect error case early, otherwise, we end up creating new pipelines - * and crash later when looking at DSV formats. */ - if (!list->dsv.view && list->state->graphics.dsv_format) - { - FIXME_ONCE("Attempting to render to NULL DSV with non-NULL format in PSO. Skipping draw call.\n"); - return false; - } - variant_flags = d3d12_command_list_variant_flags(list); /* Try to grab the pipeline we compiled ahead of time. If we cannot do so, fall back. */ diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 4091e3ef..4151e16f 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -2855,15 +2855,18 @@ static HRESULT d3d12_graphics_pipeline_state_create_render_pass_for_plane_mask( key.rtv_active_mask = rtv_active_mask; key.flags = 0; - if (graphics->dsv_format) + if (dynamic_dsv_format) { - dsv_format = graphics->dsv_format->vk_format; - aspects = graphics->dsv_format->vk_aspect_mask; - } - else if (dynamic_dsv_format && (graphics->null_attachment_mask & dsv_attachment_mask(graphics))) - { - dsv_format = dynamic_dsv_format->vk_format; - aspects = dynamic_dsv_format->vk_aspect_mask; + if (graphics->dsv_format) + { + dsv_format = graphics->dsv_format->vk_format; + aspects = graphics->dsv_format->vk_aspect_mask; + } + else if (graphics->null_attachment_mask & dsv_attachment_mask(graphics)) + { + dsv_format = dynamic_dsv_format->vk_format; + aspects = dynamic_dsv_format->vk_aspect_mask; + } } if (dsv_format) @@ -4009,6 +4012,7 @@ VkPipeline d3d12_pipeline_state_create_pipeline_variant(struct d3d12_pipeline_st struct d3d12_graphics_pipeline_state *graphics = &state->graphics; VkPipelineVertexInputDivisorStateCreateInfoEXT input_divisor_info; VkPipelineTessellationStateCreateInfo tessellation_info; + VkPipelineDepthStencilStateCreateInfo fallback_ds_desc; VkPipelineDynamicStateCreateInfo dynamic_create_info; VkPipelineVertexInputStateCreateInfo input_desc; VkPipelineInputAssemblyStateCreateInfo ia_desc; @@ -4101,6 +4105,16 @@ VkPipeline d3d12_pipeline_state_create_pipeline_variant(struct d3d12_pipeline_st TRACE("Compiling %p with fallback DSV format %#x.\n", state, dsv_format ? dsv_format->vk_format : VK_FORMAT_UNDEFINED); } + else if (!dsv_format && graphics->dsv_format) + { + TRACE("Compiling %p with fallback NULL DSV format.\n", state); + fallback_ds_desc = graphics->ds_desc; + fallback_ds_desc.depthTestEnable = VK_FALSE; + fallback_ds_desc.depthWriteEnable = VK_FALSE; + fallback_ds_desc.depthBoundsTestEnable = VK_FALSE; + fallback_ds_desc.stencilTestEnable = VK_FALSE; + pipeline_desc.pDepthStencilState = &fallback_ds_desc; + } rtv_active_mask = key ? key->rtv_active_mask : graphics->rtv_active_mask; if (graphics->rtv_active_mask != rtv_active_mask)