doitsujin / dxvk

Vulkan-based implementation of D3D8, 9, 10 and 11 for Linux / Wine
zlib License
13.15k stars 846 forks source link

Do all depth-stencil images need `VK_IMAGE_USAGE_SAMPLED_BIT` set by default? #4191

Closed werman closed 1 month ago

werman commented 2 months ago

All depth-stencil attachments in DXVK have VK_IMAGE_USAGE_SAMPLED_BIT set (I'm sure about d3d9, but haven't looked at d3d11 too close), which is fine for Turnip for all formats but VK_FORMAT_D24_UNORM_S8_UINT. For this format when customBorderColorWithoutFormat is enabled we have to use different internal format and disable compression (UBWC) for it, which is obviously bad.

In D3D9_COMMON_TEXTURE_DESC I see IsAttachmentOnly. Maybe in such case DS image may skip SAMPLED flag?

Anyway, I'm not versed in D3D api, so the question is whether it's possible to skip VK_IMAGE_USAGE_SAMPLED_BIT for DS attachments?

K0bin commented 2 months ago

On the D3D11 side of things, the sampling usage already mostly depends on whether the game passes the equivalent D3D11 bind flag. There are a few cases where we add USAGE_SAMPLING without that but in those cases it's usually necessary for meta passes like blits/copies.

I need to re-check the D3D9 side, I think we can probably indeed get rid of the sampling usage in a lot of scenarios. IIRC D3D9 doesn't allow sampling depth buffers aside from a few special driver-hack texture formats but I need to make sure my memory isn't wrong there. On top of that I also need to make sure we don't need it for some internal meta pass like D3D9Device::StretchRect.

werman commented 2 months ago

Ok, with the additional discussion in discord, it seems that the best solution is to ignore this edge case for DXVK and VKD3D-proton in Turnip, since there is no app that relies on this behavior.

Added the workaround in turnip: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30545

K0bin commented 2 months ago

I'll have a look at removing unnecessary SAMPLE_BIT flags regardless but ignoring it for engine name = DXVK obviously covers all cases.

doitsujin commented 1 month ago

This was addressed in 2.4.1.