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.81k stars 425 forks source link

vkquake compiles ok but fails to launch under MacOS.. #81

Closed oscarbg closed 6 years ago

oscarbg commented 6 years ago

I tried vkquake available here: https://github.com/Novum/vkQuake

this is mostly copy&paste from: https://github.com/Novum/vkQuake/issues/132

so tried to compile vkquake using MacOS Vulkan SDK and to my surprise compiled ok changing only libvulkan.so for -framework vulkan on Makefile.. I did previously: brew upgrade libsdl to use also new SDL 2.0.8 supporting Vulkan for Macos..

seems to crash very late in the process of Vulkan init so seems good news: as said I have reported to vkquake devs asking if it is easy to fix from their side.. errors seems to be: VkPrimitiveTopology value 5 is not supported for rendering and shader compiler error: Compilation failed:

program_source:46:20: error: called object type 'float' is not a function or function pointer float dot = dot(vertexnormal, ubo.shade_vector);

./vkquake
Command line: ./vkquake
Found SDL version 2.0.8
Detected 4 CPUs.
Quake 1.09 (c) id Software
GLQuake 1.00 (c) id Software
FitzQuake 0.85 (c) John Fitzgibbons
FitzQuake SDL port (c) SleepwalkR, Baker
QuakeSpasm 0.93.0 (c) Ozkan Sezer, Eric Wasylishen & others
vkQuake 0.97.3 (c) Axel Gneiting & others
Host_Init
Playing shareware version.
Console initialized.
UDP_Init: skipping gethostbyname for iMac-de-oscar.local
UDP Initialized
Server using protocol 666 (FitzQuake)
Exe: 15:55:12 Mar 3 2018
256.0 megabyte heap

Vulkan Initialization
Vendor: NVIDIA
Device: AMD Radeon RX Vega 56
Using D32 depth buffer format
Creating command buffers
Initializing staging
Creating descriptor set layouts
Initializing dynamic vertex buffers
Initializing dynamic index buffers
Initializing dynamic uniform buffers
Initializing samplers
Creating pipeline layouts
Using FIFO present mode
fpCreateSwapchainKHR
Creating color buffer
AA disabled
Creating depth buffer
Creating render passes
Creating frame buffers
Creating pipelines
[MoltenVK ERROR] VK_ERROR_FORMAT_NOT_SUPPORTED: VkPrimitiveTopology value 5 is not supported for rendering.
[MoltenVK ERROR] VK_ERROR_FORMAT_NOT_SUPPORTED: VkPrimitiveTopology value 5 is not supported for rendering.
[MoltenVK ERROR] VK_ERROR_FORMAT_NOT_SUPPORTED: VkPrimitiveTopology value 5 is not supported for rendering.
[MoltenVK ERROR] VK_ERROR_FORMAT_NOT_SUPPORTED: VkPrimitiveTopology value 5 is not supported for rendering.
[MoltenVK ERROR] VK_ERROR_FORMAT_NOT_SUPPORTED: VkPrimitiveTopology value 5 is not supported for rendering.
[MoltenVK ERROR] VK_ERROR_FORMAT_NOT_SUPPORTED: VkPrimitiveTopology value 5 is not supported for rendering.
[MoltenVK ERROR] VK_ERROR_FORMAT_NOT_SUPPORTED: VkPrimitiveTopology value 5 is not supported for rendering.
[MoltenVK ERROR] VK_ERROR_INITIALIZATION_FAILED: Shader module compilation failed (code 3):

Compilation failed:

program_source:46:20: error: called object type 'float' is not a function or function pointer
float dot = dot(vertexnormal, ubo.shade_vector);
~~~^

-[MTLRenderPipelineDescriptorInternal validateWithDevice:]:2149: failed assertion `vertexFunction must not be nil.'
Abort trap: 6
mmaldacker commented 6 years ago

Triangle fan is not supported (which is what value 5 of VkPrimitiveTopology is).

The shader error is because the variable is named “dot” which is also the name of a function. This is valid in SPIRV but not metal shaders. The fix is to simply rename the variable.

karl-lunarg commented 6 years ago

VkPrimitiveTopology 5 is triangle fan, which is not supported in MoltenVK. This really needs to be added to the Known MoltenVK Limitations list in the Runtime User Guide.

oscarbg commented 6 years ago

@mmaldacker @karl-lunarg thanks to both.. In that case we have source code and we can "massage" it for MoltenVK.. but shouldn't be a motivation of MoltenVK project to do these "massage" on his own.. for example: knowing that a variable and function in Metal can't have the same name shouldn't have to be known by a user.. perhaps has learned Vulkan but has no interest on Metal.. I mean either SPIRV-Cross or MoltenVK should check these cases (in that case seems a request for SPIRV-cross) and rename the variable or function accordingly transparent to the user.. also similar to triangle fan case.. can't be emulated even if with some perf. loss? similar to geometry shaders case.. Metal doesn't support it but can be emulated and at least seems where aren't losing so much perf. by emulating correctly.. this is what Vmware Fusion is doing to support DX10.. I tested with DX10 geometry shader apps and Metal backend worked correctly and apps we running "realtime " i.e. perf loss of app vs native "overall" perhaps was less than say 2x.. that is from an old request I made on MoltenVK:

An interesting example is Vmware Fusion preview 2017 is which is using Metal to emulate up to level DX10 FL10_0(including geo shaders lacking on Metal).. from what’s new document:

“Metal Graphics support (Host) – Apple makes available an OpenGL replacement technology called ‘Metal’. The 2017 Fusion Tech Preview leverages this technology to deliver OpenGL and DirectX 10 to a Guest OS”

they say in forums full DX10 profile with geometry shaders so question is: can MoltenVK hack something similar to expose Vulkan geometry shader support in your product.. I’m afraid to repost on SPIR-V Cross the same request but seems some work of this support should be exposed there..

billhollings commented 6 years ago

@oscarbg

Yes...SPIRV-Cross should handle naming conflicts. If you haven't already done so...can you post that to SPIRV-Cross to be fixed, please? If you have a sample shader, please include it.

The Triangle Fan issue is a bit more complicated. It would require MoltenVK to dynamically rebuild a completely different set of vertex indices under the covers. It is doable? I should think so. Is it straightforward? I'm not so sure. Is it performant? Probably not.

Perhaps it is a priority question. Is Triangle Fan something that we will encounter repeatedly and needs to be dealt with in the driver?

oscarbg commented 6 years ago

Hi @billhollings, just posted the bug to SPIRV-Cross developers with a artifical shader showing same issue..

also regarding triangle fan.. well I was to say similar to geometry shader case that Vmware Fusion Metal support has someway in fact support translating to Metal triangle fans.. but I also saw triangle fans were removed from DX10 onwards so DX11 also doesn't support triangle fans.. as I'm mostly interested on potential D3D11 games ->Metal support via Wine Vulkan going from DX11->DXVK->MoltenVK route I think doesn't seem high priority as you say.. Anyway for completeness just say that as I learn more of these details I'm appreciating more your implementation and the also effort Vmware guys have done on VMware Fusion product..

oscarbg commented 6 years ago

now it's working!! only some minor issues changing screen res.. captura de pantalla 2018-04-23 a las 4 32 27