Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[d3d9] Handle sampling from DS_READONLY properly #3624

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 MarkTransitionedToHazardLayout() {
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->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);
}
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