Skip to content

Commit

Permalink
[d3d9] Handle sampling from DS_READONLY properly
Browse files Browse the repository at this point in the history
  • Loading branch information
K0bin committed Aug 17, 2023
1 parent 143eb8c commit 2086ea1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
24 changes: 11 additions & 13 deletions src/d3d9/d3d9_common_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ namespace dxvk {
return util::computeMipLevelExtent(GetExtent(), MipLevel);
}

bool MarkHazardous() {
return std::exchange(m_hazardous, true);
bool MarkTransitionedToFeedbackLoopLayout() {
return std::exchange(m_transitionedToHazardLayout, true);
}

D3DRESOURCETYPE GetType() {
Expand Down Expand Up @@ -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 &&
Expand All @@ -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;

if (unlikely(hazardous && !write))
return VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL;

return layout;
return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
}

Rc<DxvkImageView> CreateView(
Expand Down Expand Up @@ -512,7 +510,7 @@ namespace dxvk {

int64_t m_size = 0;

bool m_hazardous = false;
bool m_transitionedToHazardLayout = false;

D3D9ColorView m_sampleView;

Expand Down
12 changes: 6 additions & 6 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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->MarkTransitionedToFeedbackLoopLayout())) {
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->MarkTransitionedToFeedbackLoopLayout())) {
TransitionImage(tex, m_hazardLayout);
m_flags.set(D3D9DeviceFlag::DirtyFramebuffer);
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 2086ea1

Please sign in to comment.