question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StackOverflow on running compute shader

See original GitHub issue

I’m playing around with benchmarking architectural changes for my C# particle engine, and for kicks I decided to see what timing a compute shader implementation would look like. So I created the following code as a best guess from the current docs:

ComputeShaderRepro.zip

However, when this runs I get:

Stack overflow.
   at TerraFX.Interop.IDxcCompiler.Compile(TerraFX.Interop.IDxcBlob*, UInt16*, UInt16*, UInt16*, UInt16**, UInt32, TerraFX.Interop.DxcDefine*, UInt32, TerraFX.Interop.IDxcIncludeHandler*, TerraFX.Interop.IDxcOperationResult**)
   at ComputeSharp.Shaders.Translation.ShaderCompiler.CompileShader(System.ReadOnlySpan`1<Char>)
   at ComputeSharp.Shaders.ShaderRunner`1[[ParticleBenchmark.Shader, ParticleBenchmark, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].LoadShader(Int32, Int32, Int32, ParticleBenchmark.Shader ByRef, ComputeSharp.Shaders.Translation.Models.CachedShader`1<ParticleBenchmark.Shader> ByRef)
   at ComputeSharp.Shaders.ShaderRunner`1[[ParticleBenchmark.Shader, ParticleBenchmark, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Run(ComputeSharp.GraphicsDevice, Int32, Int32, Int32, Int32, Int32, Int32, ParticleBenchmark.Shader ByRef)
   at ComputeSharp.Shaders.ShaderRunner`1[[ParticleBenchmark.Shader, ParticleBenchmark, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Run(ComputeSharp.GraphicsDevice, Int32, Int32, Int32, ParticleBenchmark.Shader ByRef)
   at ComputeSharp.GraphicsDeviceExtensions.For[[ParticleBenchmark.Shader, ParticleBenchmark, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](ComputeSharp.GraphicsDevice, Int32, ParticleBenchmark.Shader ByRef)
   at ParticleBenchmark.ComputeShaderParticles+Emitter.Update(Single)
   at ParticleBenchmark.Program.Main(System.String[])

I’m not really sure what to look at here to address this. This is using the 2.0.0-alpha.2 nuget package, which seems recent. Any ideas on what I"m doing wrong?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
KallDrexxcommented, Apr 13, 2021

The reason for the crash in this case is that you’re using a buffer of type byte, which is not supported (see the full list of supported types in the readme). In this case, a simple fix is to make that buffer an int buffer, and to also change that (byte) cast in the shader body to be (int), possibly by adding an Hlsl.Clamp(..., 0, 255) call if you need to ensure the range there. I did that fix locally and the shader runs fine after that 🙂

Aha that worked! I only used byte for those anyway for memory considerations, not because I necessarily need the values clamped (its rare it’ll go over 20, let alone 255).

Note: you can get rid of that huge constructor in your shader type by just making the shader type partial, and adding [AutoConstructor] on it, then ComputeSharp will create a constructor for you to assign all those declared fields 👍

I tried that but it didn’t generate any constructors for me. I wasn’t sure at if I had to call the constructor first to generate it or what (and how it matched things up) so I just removed it and went with a manual constructor.

Thanks for the swift reply 😃

1reaction
Sergio0694commented, Apr 13, 2021

“I tried that but it didn’t generate any constructors for me. I wasn’t sure at if I had to call the constructor first to generate it or what (and how it matched things up) so I just removed it and went with a manual constructor.”

If you see the red squiggles, that’s just because the tooling isn’t still perfect in Visual Studio yet (still in preview). If you try using the constructor anyway and build and run, it should actually work fine even if IntelliSense thinks the constructor doesn’t exist 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compute shaders in Kha
I am reworking an old voxels module for an opensource game engine, and am unable to get the compute shaders to work;.
Read more >
directx11 - Looking for an advice on how to possibly boost ...
So I moved to a compute shader to achieve this goal (DX11 CS5). I have found that I'm limited to R32_UINT for read/write...
Read more >
unity - Noise in compute shader related to threadsPerGroup
Please help me to understand how to minimize noise while maximizing game performance at the same time, without relying on the threadsPerGroup , ......
Read more >
What exactly are compute shaders? [closed]
A shader takes inputs (from the GPU memory) and computes outputs (to the GPU memory). For example, a vertex shader takes the vertices...
Read more >
What a very bad day at work taught me about building ...
What a very bad day at work taught me about building Stack Overflow's community. Hi, my name is Sara Chipps, first time Stack...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found