Compute Shader

I posted it in the suggestions already, but actually something I would like to hear more about.

I guess ComputeShader is not implemented nor planned for MonoGame right?

Would there be a lot of people interested? Is there demand at all?

I guess most indies that are interested in 3d graphics are probably on Unity or Unreal, so I don’t know if it should be a priority, but ComputeShader is very important for efficient culling and texture manipulation and is basically essential to most tiled/clustered rendering solutions and imho the most important shader after vs/ps.

What do you guys think?

Me :slightly_smiling: , as soon as the problem with custom content processors and effects on models is less hack-style…
It would allow a whole new level of quality in games effects.

I’d like this too! I thought of this when I was working on a noise/texture generation library because CPU didn’t do for performance and it could all be done in parallel. On the GPU with regular rendering wasn’t optimal either, because it took away a lot of flexibility since you’re working with actual textures (which are computed for a certain range of input) rather than functions where you can use any value as a parameter. I’m convinced that this would be a nice feature to have in MonoGame :slight_smile:

I have never personally used compute shaders or even come across an engine using them, so my experience with them is zero and knowledge of how to use them is quite limited.

Mojoshader supports DX9 shader bytecode only, which does not support compute shaders. We would have to use something like HLSLCrossCompiler as it supports DX10-11 including compute shaders (cs_4_0, cs_4_1, cs_5_0). For mobile platforms, we would have to switch to OpenGL ES 3.1, which is not widely supported yet on Android (requires Android 5.0 and a GPU that supports it). These are all things that need to be considered in addition to the API additions/changes required in MonoGame.

Neat, it supports geometry shaders too and from the readme it sounds like reflection information is handled nicely as well! At a glance this looks like it would be a huge step forward from MojoShader :slight_smile: Something worth exploring at least!

The latest Idtech is using compute shaders :wink: and ue4 if a remember well its specs.

basically every modern 3d engine uses compute shaders.

Compute shader is generally used for optimization (typical example in engines is moving average box blur for mobile phones post processing), for visual quality Geometry shader will make bigger impact. I mean… I want both, just saying. Anyway as far as I know SharpDX wouldn´t have problem with either, but since MonoGame is about portability (which I respect) it might be bit of a hassle.

Does “compute shaders” encapsulate the “geometry” shaders ?
Or computer shader is the Dx term, and geometry the OpenGL one ?
Or Compute shaders are working on pixels, whereas geometry on triangles/vertices ?

I was reading some particles casting shadows tutorials and they were speaking of geometry shader for pointlight to do a single geometry pass instead of 6 with a cubemap.

Compute shaders are intended to use the number-crunching power and parallelism of the GPU to help the CPU with complex calculations, e.g. mining Bitcoins, searching for the next prime number, etc.

Geometry shaders are used to generate geometry on the GPU, e.g. subdividing surfaces to get smoother curves, etc.

At the moment, games trying to get the best visual quality avoid geometry shaders. Usually you get more performance via other methods. This could change in the future as GPUs/drivers change, but for now geometry shaders have issues.

Because of this, and because raw compute power can sometimes be limited by the .NET runtime (array bounds checks, lack of full SIMD coverage etc) I would love to see a very nice API for using compute shaders. For instance, the fastest I can do perlin noise in C# is ~5x slower than I can do with C++, due to SIMD limitations in System.Numerics. With a compute shader I could do it ~1000 times faster than in C++. Anyone doing procedural generation at runtime could benefit from nice compute shader support.

I assume at the moment you could just use opentk to do compute shaders though, yes?

OpenTK is almost completely removed from MonoGame in the develop branch. But because MojoShader is the showstopper for compute, we can start looking at implementing a compute api once we get a decent hlsl -> glsl translator in place.

My team would also be interested in compute shaders.
We have been developing a real time ray tracer on compute shaders with opengl, and have been thinking mono game as a layer for adding more platforms. Porting our shaders to hlsl isn’t a problem.
Keep me posted