[d3d9] Handle sampling from DS_READONLY properly

This commit is contained in:
Robin Kertels 2023-08-17 02:58:52 +02:00
parent 143eb8c710
commit 27ca48b12b
No known key found for this signature in database
GPG Key ID: 3824904F14D40757
2 changed files with 17 additions and 19 deletions

View File

@ -307,8 +307,8 @@ namespace dxvk {
return util::computeMipLevelExtent(GetExtent(), MipLevel);
}
bool MarkHazardous() {
return std::exchange(m_hazardous, true);
bool MarkTransitionedToHazardLayout() {
return std::exchange(m_transitionedToHazardLayout, true);
}
D3DRESOURCETYPE GetType() {
@ -340,7 +340,7 @@ namespace dxvk {
}
VkImageLayout DetermineRenderTargetLayout(VkImageLayout hazardLayout) const {
if (unlikely(m_hazardous))
if (unlikely(m_transitionedToHazardLayout))
return hazardLayout;
return m_image != nullptr &&
@ -350,18 +350,16 @@ namespace dxvk {
}
VkImageLayout DetermineDepthStencilLayout(bool write, bool hazardous, VkImageLayout hazardLayout) const {
VkImageLayout layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
if (unlikely(hazardous)) {
layout = write
? hazardLayout
: VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL;
}
if (unlikely(m_transitionedToHazardLayout))
return hazardLayout;
if (unlikely(m_image->info().tiling != VK_IMAGE_TILING_OPTIMAL))
layout = VK_IMAGE_LAYOUT_GENERAL;
return VK_IMAGE_LAYOUT_GENERAL;
return layout;
if (unlikely(hazardous && !write))
return VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL;
return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
}
Rc<DxvkImageView> CreateView(
@ -512,7 +510,7 @@ namespace dxvk {
int64_t m_size = 0;
bool m_hazardous = false;
bool m_transitionedToHazardLayout = false;
D3D9ColorView m_sampleView;

View File

@ -5595,8 +5595,7 @@ namespace dxvk {
m_activeHazardsDS = m_activeHazardsDS & (~texMask);
if (m_state.depthStencil != nullptr &&
m_state.depthStencil->GetBaseTexture() != nullptr &&
m_state.renderStates[D3DRS_ZWRITEENABLE]) {
m_state.depthStencil->GetBaseTexture() != nullptr) {
for (uint32_t samplerIdx : bit::BitMask(masks.samplerMask)) {
IDirect3DBaseTexture9* dsBase = m_state.depthStencil->GetBaseTexture();
IDirect3DBaseTexture9* texBase = m_state.textures[samplerIdx];
@ -5643,16 +5642,17 @@ namespace dxvk {
for (uint32_t samplerIdx : bit::BitMask(m_activeHazardsRT)) {
// Guaranteed to not be nullptr...
auto tex = GetCommonTexture(m_state.textures[samplerIdx]);
if (unlikely(!tex->MarkHazardous())) {
if (unlikely(!tex->MarkTransitionedToHazardLayout())) {
TransitionImage(tex, m_hazardLayout);
m_flags.set(D3D9DeviceFlag::DirtyFramebuffer);
}
}
if (m_activeHazardsDS != 0) {
bool zWriteEnabled = m_state.renderStates[D3DRS_ZWRITEENABLE];
if (m_activeHazardsDS != 0 && zWriteEnabled) {
// Guaranteed to not be nullptr...
auto tex = m_state.depthStencil->GetCommonTexture();
if (unlikely(!tex->MarkHazardous())) {
if (unlikely(!tex->MarkTransitionedToHazardLayout())) {
TransitionImage(tex, m_hazardLayout);
m_flags.set(D3D9DeviceFlag::DirtyFramebuffer);
}
@ -5904,7 +5904,7 @@ namespace dxvk {
if (m_hazardLayout == VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT) {
if (m_activeHazardsRT != 0)
feedbackLoopAspects |= VK_IMAGE_ASPECT_COLOR_BIT;
if (m_activeHazardsDS != 0)
if (m_activeHazardsDS != 0 && attachments.depth.layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL)
feedbackLoopAspects |= VK_IMAGE_ASPECT_DEPTH_BIT;
}