@@ -1264,9 +1264,15 @@ void DeviceContextD3D12Impl::CommitRenderTargets(RESOURCE_STATE_TRANSITION_MODE
12641264 {
12651265 const auto ViewType = m_pBoundDepthStencil->GetDesc ().ViewType ;
12661266 VERIFY_EXPR (ViewType == TEXTURE_VIEW_DEPTH_STENCIL || ViewType == TEXTURE_VIEW_READ_ONLY_DEPTH_STENCIL);
1267- const auto NewState = ViewType == TEXTURE_VIEW_DEPTH_STENCIL ?
1267+ auto NewState = ViewType == TEXTURE_VIEW_DEPTH_STENCIL ?
12681268 RESOURCE_STATE_DEPTH_WRITE :
12691269 RESOURCE_STATE_DEPTH_READ;
1270+ if (NewState == RESOURCE_STATE_DEPTH_READ && StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION)
1271+ {
1272+ // Read-only depth is likely to be used as shader resource, so set this flag.
1273+ // If this is not intended, the app should manually transition resource states.
1274+ NewState |= RESOURCE_STATE_SHADER_RESOURCE;
1275+ }
12701276
12711277 auto * pTexture = ClassPtrCast<TextureD3D12Impl>(pDSV->GetTexture ());
12721278
@@ -1481,10 +1487,13 @@ void DeviceContextD3D12Impl::CommitSubpassRenderTargets()
14811487
14821488 const auto & DSAttachmentRef = *Subpass.pDepthStencilAttachment ;
14831489 VERIFY_EXPR (Subpass.pDepthStencilAttachment != nullptr && DSAttachmentRef.AttachmentIndex != ATTACHMENT_UNUSED);
1484- VERIFY (m_pBoundDepthStencil == FBDesc.ppAttachments [DSAttachmentRef.AttachmentIndex ],
1485- " Depth-stencil buffer in the device context is inconsistent with the framebuffer" );
14861490 const auto FirstLastUse = m_pActiveRenderPass->GetAttachmentFirstLastUse (DSAttachmentRef.AttachmentIndex );
14871491 const auto & DSAttachmentDesc = RPDesc.pAttachments [DSAttachmentRef.AttachmentIndex ];
1492+ VERIFY (m_pBoundDepthStencil ==
1493+ (DSAttachmentRef.State == RESOURCE_STATE_DEPTH_READ ?
1494+ m_pBoundFramebuffer->GetReadOnlyDSV (m_SubpassIndex) :
1495+ FBDesc.ppAttachments [DSAttachmentRef.AttachmentIndex ]),
1496+ " Depth-stencil buffer in the device context is inconsistent with the framebuffer" );
14881497
14891498 RenderPassDS.cpuDescriptor = m_pBoundDepthStencil->GetCPUDescriptorHandle ();
14901499 if (FirstLastUse.first == m_SubpassIndex)
0 commit comments