vkd3d: Correctly handle dynamic depth/stencil attachment infos.

{depth,stencil}AttachmentFormat and p{Depth,Stencil}Attachment are only
allowed if the format contains that aspect. Check this explicitly.

Fixes some validation errors.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
This commit is contained in:
Hans-Kristian Arntzen 2022-03-24 15:48:48 +01:00
parent 1b5f7e8fc3
commit 2e8fb27182
3 changed files with 27 additions and 11 deletions

View File

@ -4553,10 +4553,20 @@ static bool d3d12_command_list_update_rendering_info(struct d3d12_command_list *
}
}
rendering_info->info.pDepthAttachment = NULL;
rendering_info->info.pStencilAttachment = NULL;
if (d3d12_command_list_has_depth_stencil_view(list))
{
rendering_info->dsv.imageView = list->dsv.view->vk_image_view;
rendering_info->dsv.imageLayout = list->dsv_layout;
/* Spec says that to use pDepthAttachment or pStencilAttachment, with non-NULL image view,
* the format must have the aspect mask set. */
if (list->dsv.view->format->vk_aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT)
rendering_info->info.pDepthAttachment = &rendering_info->dsv;
if (list->dsv.view->format->vk_aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)
rendering_info->info.pStencilAttachment = &rendering_info->dsv;
}
else
{
@ -6033,8 +6043,10 @@ static void d3d12_command_list_copy_image(struct d3d12_command_list *list,
if (dst_is_depth_stencil)
{
rendering_info.pDepthAttachment = &attachment_info;
rendering_info.pStencilAttachment = &attachment_info;
if (dst_format->vk_aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT)
rendering_info.pDepthAttachment = &attachment_info;
if (dst_format->vk_aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)
rendering_info.pStencilAttachment = &attachment_info;
}
else
{
@ -10053,8 +10065,6 @@ static void d3d12_command_list_init_rendering_info(struct d3d12_device *device,
rendering_info->info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR;
rendering_info->info.colorAttachmentCount = D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT;
rendering_info->info.pColorAttachments = rendering_info->rtv;
rendering_info->info.pDepthAttachment = &rendering_info->dsv;
rendering_info->info.pStencilAttachment = &rendering_info->dsv;
for (i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
d3d12_command_list_init_attachment_info(&rendering_info->rtv[i]);

View File

@ -138,7 +138,7 @@ static VkResult vkd3d_meta_create_compute_pipeline(struct d3d12_device *device,
}
static VkResult vkd3d_meta_create_graphics_pipeline(struct vkd3d_meta_ops *meta_ops,
VkPipelineLayout layout, VkFormat color_format, VkFormat ds_format,
VkPipelineLayout layout, VkFormat color_format, VkFormat ds_format, VkImageAspectFlags vk_aspect_mask,
VkShaderModule vs_module, VkShaderModule fs_module,
VkSampleCountFlagBits samples, const VkPipelineDepthStencilStateCreateInfo *ds_state,
const VkPipelineColorBlendStateCreateInfo *cb_state, const VkSpecializationInfo *spec_info,
@ -218,10 +218,10 @@ static VkResult vkd3d_meta_create_graphics_pipeline(struct vkd3d_meta_ops *meta_
rendering_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR;
rendering_info.pNext = NULL;
rendering_info.viewMask = 0;
rendering_info.colorAttachmentCount = color_format ? 1 : 0;
rendering_info.colorAttachmentCount = color_format && (vk_aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) ? 1 : 0;
rendering_info.pColorAttachmentFormats = color_format ? &color_format : NULL;
rendering_info.depthAttachmentFormat = ds_format;
rendering_info.stencilAttachmentFormat = ds_format;
rendering_info.depthAttachmentFormat = (vk_aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) ? ds_format : VK_FORMAT_UNDEFINED;
rendering_info.stencilAttachmentFormat = (vk_aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) ? ds_format : VK_FORMAT_UNDEFINED;
pipeline_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipeline_info.pNext = &rendering_info;
@ -611,7 +611,7 @@ static HRESULT vkd3d_meta_create_swapchain_pipeline(struct vkd3d_meta_ops *meta_
VK_COLOR_COMPONENT_A_BIT;
if ((vr = vkd3d_meta_create_graphics_pipeline(meta_ops,
meta_swapchain_ops->vk_pipeline_layouts[key->filter], key->format, VK_FORMAT_UNDEFINED,
meta_swapchain_ops->vk_pipeline_layouts[key->filter], key->format, VK_FORMAT_UNDEFINED, VK_IMAGE_ASPECT_COLOR_BIT,
meta_swapchain_ops->vk_vs_module, meta_swapchain_ops->vk_fs_module, 1,
NULL, &cb_state,
NULL, &pipeline->vk_pipeline)) < 0)
@ -731,6 +731,7 @@ static HRESULT vkd3d_meta_create_copy_image_pipeline(struct vkd3d_meta_ops *meta
meta_copy_image_ops->vk_pipeline_layout,
has_depth_target ? VK_FORMAT_UNDEFINED : key->format->vk_format,
has_depth_target ? key->format->vk_format : VK_FORMAT_UNDEFINED,
key->format->vk_aspect_mask,
VK_NULL_HANDLE, vk_module, key->sample_count,
has_depth_target ? &ds_state : NULL, has_depth_target ? NULL : &cb_state,
&spec_info, &pipeline->vk_pipeline)) < 0)

View File

@ -3949,8 +3949,13 @@ VkPipeline d3d12_pipeline_state_create_pipeline_variant(struct d3d12_pipeline_st
rendering_info.viewMask = 0;
rendering_info.colorAttachmentCount = graphics->rt_count;
rendering_info.pColorAttachmentFormats = rtv_formats;
rendering_info.depthAttachmentFormat = dsv_format ? dsv_format->vk_format : VK_FORMAT_UNDEFINED;
rendering_info.stencilAttachmentFormat = dsv_format ? dsv_format->vk_format : VK_FORMAT_UNDEFINED;
/* From spec: If depthAttachmentFormat is not VK_FORMAT_UNDEFINED, it must be a format that includes a depth aspect. */
rendering_info.depthAttachmentFormat = dsv_format && (dsv_format->vk_aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) ?
dsv_format->vk_format : VK_FORMAT_UNDEFINED;
/* From spec: If stencilAttachmentFormat is not VK_FORMAT_UNDEFINED, it must be a format that includes a stencil aspect. */
rendering_info.stencilAttachmentFormat = dsv_format && (dsv_format->vk_aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) ?
dsv_format->vk_format : VK_FORMAT_UNDEFINED;
for (i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
{