KhronosGroup / MoltenVK

MoltenVK is a Vulkan Portability implementation. It layers a subset of the high-performance, industry-standard Vulkan graphics and compute API over Apple's Metal graphics framework, enabling Vulkan applications to run on macOS, iOS and tvOS.
Apache License 2.0
4.79k stars 422 forks source link

shaderStorageImageMultisample is incorrectly reported as supported #502

Open baldurk opened 5 years ago

baldurk commented 5 years ago

The shaderStorageImageMultisample feature is reported as supported unconditionally, but from what I can tell this isn't actually supported by Metal. When compiling a shader with code that stores to an MSAA image I get this error:

[***MoltenVK ERROR***] VK_ERROR_INITIALIZATION_FAILED: Compute pipeline compile failed (error code 1):
Compiler encountered an internal error.
[***MoltenVK ERROR***] VK_ERROR_INITIALIZATION_FAILED: Shader library compile failed (error code 3):
Compilation failed: 

In file included from program_source:1:
In file included from /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/3902/Libraries/lib/clang/902.2/include/metal/metal_stdlib:22:
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/3902/Libraries/lib/clang/902.2/include/metal/metal_texture:3693:3: error: static_assert failed "Multisample textures must have access qualifier access::read"
  static_assert(_is_valid_ms_access(a), _err_ms_access);
  ^             ~~~~~~~~~~~~~~~~~~~~~~
program_source:14:154: note: in instantiation of template class 'metal::texture2d_ms_array<unsigned int, metal::access::write, void>' requested here
kernel void main0(constant multisamplePush& mscopy [[buffer(0)]], texture2d_array<uint> srcArray [[texture(0)]], texture2d_ms_array<uint, access::write> dstMS [[texture(2)]], sampler srcArraySmplr [[sampler(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
                                                                                                                                                         ^
.
[***MoltenVK ERROR***] VK_ERROR_INITIALIZATION_FAILED: Compute shader function could not be compiled into pipeline. See previous logged error.

Which indicates that MSAA textures are read-only. The commit that added this last year 6d4e95a7d7e15e45b32e899b2fa90c5a01a1e3b4 is confusing because it even says "Metal supports read-only access from shaders to multisampled textures" - but then enables the feature that allows write access to them.

cdavis5e commented 5 years ago

It's weird. Metal only supports read-only access to multisampled textures. So you can only use one as a storage image as long as you don't write to it. But the storage image capability in Vulkan implies that you can write to the image. I'm actually surprised that Apple didn't bother implementing this. I asked for this in rdar://47332558, so we'll see what happens.

Honestly, the reason I added this is that DXVK wanted it. I guess I could turn it back off, since it isn't fully supported and it's not strictly required to create a feature level 11 device--at least, not now.

baldurk commented 5 years ago

The problem is that any Vulkan application which checks for the presence of the feature and enables/disables codepaths will see that it's available but then fail to compile pipelines which actually use that feature and crash.

Talking to the DXVK author it seems like DXVK might not actually use the feature - D3D11 doesn't allow MSAA UAVs either. Also I don't think D3D12 does, so any D3D12 emulation project shouldn't need it.

cdavis5e commented 5 years ago

I have disabled the feature in #505. (And I really should've put a "Fixes #502" in there.)