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.73k stars 411 forks source link

Add support for geometry shaders #1524

Open italomandara opened 2 years ago

italomandara commented 2 years ago

Since MSL3 still doesn't support geometry shaders, and it seems a requirement (along with tessellation) for modern 3D applications, would it be possible to add this in MoltenVK as a polyfill? I saw this repo that gives an example of geometry shader for MSL https://github.com/Kosalos/GeometryShader

billhollings commented 2 years ago

Thanks for submitting the request and recommendation.

Interesting idea.

italomandara commented 2 years ago

https://github.com/KhronosGroup/MoltenVK/issues/1657#issuecomment-1193364216 Geometry shaders were introduced in OpenGL 3.2 so support could be hidden somewere in the Metal API? Wishful thinking...

M1Minecraft commented 2 years ago

#1657 (comment) Geometry shaders were introduced in OpenGL 3.2 so support could be hidden somewere in the Metal API? Wishful thinking...

Metal 3 has new features which help support Geometry Shaders. https://github.com/KhronosGroup/MoltenVK/discussions/1616#discussion-4126755

italomandara commented 2 years ago

Metal 3 has new features which help support Geometry Shaders. #1616 (comment)

I Agree but metal 3 is not there yet, also you want to support users that for some reason want to use older OSs for some time?

italomandara commented 2 years ago

more suggestions discussed here: http://hacksoflife.blogspot.com/2015/06/os-x-metal-raw-notes.html

italomandara commented 2 years ago

If it's still important providing support for the current os without waiting the future release of metal3 with the next OS: more sugggestions on this repo: https://github.com/openglonmetal/MGL#spirv-to-metal.

There are some parts in GLSL that Metal just doesn't support like Geometry Shaders, I think the way forward on support for Geometry Shaders is to translate the vertex and geometry shaders into LLVM from SPIRV then execute the results from processing them on the CPU through a passthrough vertex shader in the pipeline.

Also: one of the contributors also pointed that another source of inspiration is looking into zink and how it emulates geometry shaders.

K0bin commented 2 years ago

Doing it on the CPU is a waste of time. That would be too slow to be usable anyway.

italomandara commented 2 years ago

Doing it on the CPU is a waste of time. That would be too slow to be usable anyway.

Agree, but there are many other ways of solving this problem anyway. It's worth trying tho, everything is better than nothing at all.

italomandara commented 2 years ago

The functionality doesn’t exist in Metal, so I just jumped directly to Compute Shaders which Metal does support and is to be honest the future path for GPU’s.

Again from that project.

billhollings commented 1 year ago

Related issue #1741 outlines real-world needs for geometry shaders.

Gcenx commented 1 year ago

There’s really many games that require geometry shaders but it’s not always so in your face.

One reason it’s not so obvious is DXVK-CX and some third-party builds aimed at macOS have a hard requirement on faking extensions on the MoltenVK side.

Instead doing the following https://github.com/Gcenx/DXVK-macOS/commit/934006899a02571f4a381d9be69b3a5104a2132b makes sure that anything the feature is requested the message will show up in the log.

billhollings commented 1 year ago

One reason it’s not so obvious is DXVK-CX and some third-party builds aimed at macOS have a hard requirement on faking extensions on the MoltenVK side.

Can you elaborate on what you mean by that? Specifically, what "hard requirement on faking extensions" means?

Are you saying frameworks like DXVK-CX have two code paths, one when geometry shaders are available in the driver, and one when they are not, and both work (maybe not equally well)? And in the second case, how do these frameworks "fake" geometry shaders?

Or are you saying DXVK-CX will not run when geometry shaders are not available because they have a hard requirement to not fake extensions?

italomandara commented 1 year ago

Sorry to interrupt the conversation... Just for taking some inspiration for a solution, there's a patent registered by vmware giving some explanation on how it's implemented with compute: https://uspto.report/patent/app/20200265631. I hope this helps somehow.

Gcenx commented 1 year ago

Or are you saying DXVK-CX will not run when geometry shaders are not available because they have a hard requirement to not fake extensions?

DXVK-CX and some other third-party packages won’t run unless MoltenVK fakes support for geometry shaders (and some other extensions)

The DXVK-macOS packages I advertise are used in XIV on Mac|Wineskin|PortingKit will use geometry shaders and other extensions if available, if these are missing it will continue to run just give a message (for geometry shaders)

Here’s the current version of DXVK-CX shipped with recent versions of crossover https://media.codeweavers.com/pub/crossover/dxvk/dxvk-v1.7-14-gef993b2f_x86_64.tar.bz2 this won’t run on stock MoltenVK

Here’s my own build of the same version but does function on stock MoltenVK https://github.com/Gcenx/DXVK-macOS/releases/download/v1.7/dxvk-macOS-1.7.tar.gz

Or the very latest version https://github.com/Gcenx/DXVK-macOS/releases/download/v1.10.3/dxvk-macOS-async-1.10.3.tar.gz (async is enabled by default on select titles)


There’s no fallback for these missing Vulkan extensions with my packages I simply allow the games to still function (that’s fine until more recent DXVK-git), prior DXVK releases allowed this I’d simply reverted some changes to still allow it.

andyoneal commented 1 year ago

In older Unity games (at least 2018), geometry shaders are used for gpu skinning. That causes models to not render at all in Crossover.

josh-the-tech commented 1 year ago

Now that Ventura has released today, with Metal 3 support, hopefully this will become a reality. Can't wait to be able to use CrossOver to play my UE4 based games rather than having to rely on a virtual machine! +1 for this and the team working on it! :)

PekaPete commented 1 year ago

Let me just say that I know almost nothing about any of these. But I was reading the Ryujinx blog update and they mentioned this about geometry shaders:

"Geometry Shaders: Geometry shaders do not exist in Metal or MoltenVK. Used for writing 3D textures in UE4 games, and a number of complex graphical effects in others, missing this would definitely hurt compatibility. However, gdkchan has come up with a clever method to emulate these stages using additional draws to vertex shader only. The result is incredibly impressive - hardware-accelerated geometry shaders on a GPU that doesn't support them. Coup de grâce!"

Since Ryujinx is open source, is this a possible solution to this issue?

italomandara commented 1 year ago

The compute shader or mesh shader solution would be much more efficient than the Vertex shader solution, but if the Vertex one is easier to accomplish, always better than nothing at all.

billhollings commented 1 year ago

There is some PoC effort currently underway using Mesh shaders to provide Geometry shaders.

We're expecting initial availability to be sometime in Q1/23.

PekaPete commented 1 year ago

That's really good news! I was somewhat worried that Metal 3's features are not enough to provide a solution for geometry shaders.

Also, with regards to other problems that I've read about, Ryujinx also made workarounds for 4-byte Vertex Buffer Alignment Requirement & Transform Feedback.

Degerz commented 1 year ago

Mesh shaders alone may not be enough to handle the case where geometry shaders interacts with transform feedback ...

It's a possibility that either tessellation or geometry shaders implementation over mesh shaders on MoltenVK/Metal may never reach parity in functionality with other graphics APIs out there ...

italomandara commented 1 year ago

True TF should be implemented first.

billhollings commented 1 year ago

Further development on Geometry shader substitutes from Ryujinx...

sofakng commented 1 year ago

Any new updates? I'd also be willing to contribute to any available bounties or donate to anybody working on this issue.

Gcenx commented 1 year ago

@billhollings your probably aware of this but could this somehow be usable as a pollyfill for older version of macOS https://developer.apple.com/documentation/metal/metal_sample_code_library/mixing_metal_and_opengl_rendering_in_a_view

billhollings commented 1 year ago

@billhollings your probably aware of this but could this somehow be usable as a pollyfill for older version of macOS https://developer.apple.com/documentation/metal/metal_sample_code_library/mixing_metal_and_opengl_rendering_in_a_view

Can you elaborate? How are you thinking we could use OpenGL to provide Geometry Shaders?

Gcenx commented 1 year ago

Can you elaborate? How are you thinking we could use OpenGL to provide Geometry Shaders?

That’s indeed what I was thinking.

billhollings commented 1 year ago

That’s indeed what I was thinking.

Yes. But how do you envision it hanging together in a pipeline that is otherwise Vulkan/SPIR-V?

Gcenx commented 1 year ago

Yes. But how do you envision it hanging together in a pipeline that is otherwise Vulkan/SPIR-V?

It’s probably better someone more knowledgeable with Metal/Vulkan look into how/if this could be made viable, it seems technically possible but not sure how viable.

K0bin commented 1 year ago

It's not viable. You'd have to write a Vulkan to OpenGL translation layer, which is impossible, especially with Apples ancient OpenGL 4.1 and then somehow dynamically switch to that based on the rendering pipeline while remembering to sync all previously set state over.

hauntek commented 1 year ago

How is the Game Porting Toolkit addressed?

Gcenx commented 1 year ago

How is the Game Porting Toolkit addressed?

Apple directly maps to Metal when possible and emulate what Metal 3.1 doesn’t support.

DarthMDev commented 1 year ago

does apple use mesh shaders in place of geometry shaders for their dx to metal in gptk? 🤔

billhollings commented 1 year ago

does apple use mesh shaders in place of geometry shaders for their dx to metal in gptk? 🤔

Yes. GPTK and Apple's Shader Converter convert HLSL Tessellation and Geometry shaders to MSL Mesh shaders. Plus, it's done at a binary level, without source code involved.

I'm starting to look into whether we can leverage this in MoltenVK.

hauntek commented 1 year ago

does apple use mesh shaders in place of geometry shaders for their dx to metal in gptk? 🤔

Yes. GPTK and Apple's Shader Converter convert HLSL Tessellation and Geometry shaders to MSL Mesh shaders.

I'm starting to look into whether we can leverage this in MoltenVK.

HLSL Tessellation and Geometry shaders to MSL Mesh shaders. This is the best solution, because Apple is doing this

DarthMDev commented 1 year ago

does apple use mesh shaders in place of geometry shaders for their dx to metal in gptk? 🤔

Yes. GPTK and Apple's Shader Converter convert HLSL Tessellation and Geometry shaders to MSL Mesh shaders. I'm starting to look into whether we can leverage this in MoltenVK.

HLSL Tessellation and Geometry shaders to MSL Mesh shaders. This is the best solution, because Apple is doing this

i agree the performance of doing it this way was really good when i tested unreal engine games on gptk

Mateus109 commented 1 year ago

Needed to get Stray working (currently black screen)

Spidy123222 commented 9 months ago

does apple use mesh shaders in place of geometry shaders for their dx to metal in gptk? 🤔

Yes. GPTK and Apple's Shader Converter convert HLSL Tessellation and Geometry shaders to MSL Mesh shaders. Plus, it's done at a binary level, without source code involved.

I'm starting to look into whether we can leverage this in MoltenVK.

Do you think moltenvk can leverage this? I'm sure there is other projects that would use moltenvk on macOS and iOS to do their own ports that also utilize transform feedback.

billhollings commented 9 months ago

I'm starting to look into whether we can leverage this in MoltenVK.

Do you think moltenvk can leverage this? I'm sure there is other projects that would use moltenvk on macOS and iOS to do their own ports that also utilize transform feedback.

Unfortunately, I haven't had time yet to delve into this in depth. It's on the to-do list.

alyssarosenzweig commented 9 months ago

I'm starting to look into whether we can leverage this in MoltenVK.

Do you think moltenvk can leverage this? I'm sure there is other projects that would use moltenvk on macOS and iOS to do their own ports that also utilize transform feedback.

Unfortunately, I haven't had time yet to delve into this in depth. It's on the to-do list.

If you use this approach, what's the plan for transform feedback? #1943

tamburro92 commented 3 months ago

I read some works have been done in WIP Geometry shaders #1815

Also this is present from crossover 23 beta1 release which says: “We’re pleased to announce that this release also includes initial support for geometry shaders and transform feedback on macOS”