Calling .DispatchCompute() deletes data

I dont know exactly how to describe this weird problem, but whenever I .DispatchCompute() once and pass the StructuredBuffer to another shader everythings works just fine, but if I call it another time and the texture suddenly disappears and I am left with a black model (because the data is somehow vanished).
What is the reason for this? Is this a bug, or a limitation? Even if I create a entire new compute-shader that has NOTHING to do with any data what-so-ever, calling DispatchCompute on this entire new shader deletes every data that was created by another compute-shader-dispatch.

Why?

Best regards

That will be extremely hard to debug without all of the code

You can reproduce it very simply: Just create a compute shader that consists of a StructuredBuffer with two techniques and then create a normal shader for rendering stuff (either 3d or 2d), which uses the StructuredBuffer managed by the compute shader.

The first technique of the compute-shader writes on the StructuredBuffer, while the other technique just doesnt do anything.

If you now apply the first compute-shader-technique and call DispatchCompute(), and pass the resulting StructuredBuffer to the normal shader everything works fine. Now if you just for fun apply the second compute-shader-technique and call DispatchCompute() for some reason the StructuredBuffer suddenly disappears on your normal shader.

I dont know whether this is a monogame-custom-fork bug or something sharpdx-related…

I found some caching problem myself recently. I think this could be responsible for what you are experiencing. I’m in the process of getting rid of the TextureCollection in favor of the ShaderReourceCollection. This should solve this caching problem. Are you building from source, or do you use the Nuget packages? I hope you can test it once I’ve pushed my changes.

Hello,
I am using this project solution: https://github.com/cpt-max/MonoGame-Shader-Samples/tree/compute_write_to_3d_texture

… which itself uses the nuget-package I guess.
Your assumption may be correct, because whenever I call .DispatchCompute() not only the StructuredBuffer “vanishes” , but Texture2Ds too: The model suddenly turns black after calling .DispatchCompute().

Best regards!

There’s a new version online for the MonoGame.Framework.Compute.WindowsDX package. Could you please update your project to use the new 3.8.1.3 version and see if that changes anything?

In case it doesn’t, could you share the relevant code, so I can reproduce the problem?

1 Like

Hello markus,

I changed the whole code-base and switched to compute-shader. There is nearly no way testing whether it works for pixel-shader now. But it made even more sense to just use the compute-shader anyway. I even can adjust the amount of threads to start (8, 8, 1 for raytacer): It seems to work better on compute shader than on pixel-shader. So this bug was more helpful than I initially assumed.

But for your information: It didnt worked on the CS at first either: I then used RWTexture3D which then worked fine.

I will try to use Texture3D again and report whether it works or not.

Best regards

It works! I even switched back to the old version, tried Texture3D with the old version, result: It didnt worked. But with the latest version it works.

The bug seems fixed.
_

1 Like

Awesome!