Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for geometry shaders #1524

Open
italomandara opened this issue Feb 11, 2022 · 41 comments
Open

Add support for geometry shaders #1524

italomandara opened this issue Feb 11, 2022 · 41 comments

Comments

@italomandara
Copy link
Contributor

italomandara commented Feb 11, 2022

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

@italomandara italomandara changed the title Geometry shaders Lack of geometry shaders Feb 12, 2022
@billhollings
Copy link
Contributor

Thanks for submitting the request and recommendation.

Interesting idea.

@italomandara italomandara changed the title Lack of geometry shaders Add support for geometry shaders Jun 10, 2022
@italomandara
Copy link
Contributor Author

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

@M1Minecraft
Copy link

#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. #1616 (comment)

@italomandara
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@italomandara
Copy link
Contributor Author

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
Copy link

K0bin commented Jul 30, 2022

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

@italomandara
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor

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

@Gcenx
Copy link

Gcenx commented Oct 15, 2022

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 Gcenx/DXVK-macOS@9340068 makes sure that anything the feature is requested the message will show up in the log.

@billhollings
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link

Gcenx commented Oct 15, 2022

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
Copy link

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
Copy link

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
Copy link

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
Copy link
Contributor Author

italomandara commented Nov 29, 2022

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
Copy link
Contributor

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
Copy link

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
Copy link

Degerz commented Dec 11, 2022

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
Copy link
Contributor Author

italomandara commented Dec 11, 2022

True TF should be implemented first.

@billhollings
Copy link
Contributor

Further development on Geometry shader substitutes from Ryujinx...

@sofakng
Copy link

sofakng commented Apr 25, 2023

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

@Gcenx
Copy link

Gcenx commented Apr 27, 2023

@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
Copy link
Contributor

@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
Copy link

Gcenx commented Apr 29, 2023

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

That’s indeed what I was thinking.

@billhollings
Copy link
Contributor

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
Copy link

Gcenx commented Apr 29, 2023

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
Copy link

K0bin commented Apr 29, 2023

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
Copy link

hauntek commented Jun 11, 2023

How is the Game Porting Toolkit addressed?

@Gcenx
Copy link

Gcenx commented Jun 11, 2023

How is the Game Porting Toolkit addressed?

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

@DarthMDev
Copy link

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

@billhollings
Copy link
Contributor

billhollings commented Jun 12, 2023

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
Copy link

hauntek commented Jun 12, 2023

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
Copy link

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
Copy link

Needed to get Stray working (currently black screen)

@Spidy123222
Copy link

Spidy123222 commented Dec 9, 2023

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
Copy link
Contributor

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
Copy link

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
Copy link

tamburro92 commented Jun 8, 2024

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”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests