protonscr

Strange Brigade: About compute shader translation in vkd3d

vkd3dopen
HansKristian-Work/vkd3d-proton#1594 · opened 2023-06-14 by Zhiwei-Lii · updated 2023-06-14 · 2 comments · github
ZZhiwei-Lii 2023-06-14 github

Hi Community
We discovered that some compute shader show bad performance after vkd3d translation.
Here is the detail.
Strange Brigade support two version: dx12 and vulkan. But the dx12 benchmark score is 70%~80% of vulkan. (Both on linux)
With "INTEL_MEASURE=draw,file=/tmp/mesure.csv", mesa profiling result shows that there is a big difference in compute shader. (375us vs 184us)

1
According to the perfetto result, the compute operation blocks following draw call. So the performance can be improved if we can optimize compute here.
2
Here is the link about compute shader of dx12_to_vulkan and native vulkan.
https://drive.google.com/drive/folders/1HoVMaDrTl4pwzA4qS2slymr2-BG0Cwq8
3
4
The amount of Load and Store OP is as below. And can find that Load operation is extremely high in Dx12->vulkan.

Spirv Load Store
Dx12->vulkan 573 237
Native vulkan 47 5

We suspect that it's related to the below code in 4f003e374340035c.spv.glsl

...
r4 = fma(r4, vec4(_11[_216]._m0[1u].x, _11[_216]._m0[1u].y, _11[_216]._m0[1u].z, _11[_216]._m0[1u].w), vec4(_11[_228]._m0[2u].x, _11[_228]._m0[2u].    y, _11[_228]._m0[2u].z, _11[_228]._m0[2u].w));
...
r4 = uintBitsToFloat(uvec4(_28[_289]._m0[_298], _28[_289]._m0[_298 + 1u], _28[_289]._m0[_298 + 2u], _28[_289]._m0[_298 + 3u]));
...

According to https://themaister.net/blog/2021/11/07/my-personal-hell-of-translating-dxil-to-spir-v-part-3/ , maybe related to more levels of indirections of loads and un-guaranteed alignments, so component loads are unrolled mostly to scalar loads?

Ddoitsujin maintainer 2023-06-14 github

If there is heavy reliance on StructuredBuffer or ByteAddressBuffer loads, this is somewhat expected. There is currently no good way to implement these efficiently in Vulkan for hardware that has alignment restrictions on vectorized loads, we can't really make any assumptions about the data structure being loaded, and BDA isn't a good use case for this either since we'd have to manually implement bounds-checking and would potentially hit even slower paths on certain hardware.

HHansKristian-Work maintainer 2023-06-14 github

fwiw, we are able to vectorize a bunch of stuff in DXIL, but DXBC is basically a non-starter due to its non-SSA formulation.

Nothing extracted yet.