[Solved]TextureCube issue

This is really doing my head in.

My renderer is multi-threaded, but the renderer itself runs on a single core. Not on the main thread though.

At the start of a render pass I render an environment cube by rendering each face into a texture cube using SetRenderTarget(RenderTargetCube,CubeMapFace)

Then I render the sky, and all the other geometry is rendered by pass number.

So think

Render environment map
Render sky
Render terrain
Render objects
etc.

I then use the rendered environment map as an input to a few shaders. Glass, water, ocean, etc.

Every shader that uses the environment map glitches. Every second or two it just goes horribly wrong.

It is driving me mad.

I wondered if my code was interfering with the graphics device on the main thread, but I have built in a profiler to my engine and even with a bunch of game objects , huge ocean, and sky … it’s not even reaching 4 mS .

I can also see my synchronisation is working well and I am not getting threading issues.

So … lost.

Anyone have any ideas what I can try?

Extra info, just tried rendering the environment map once at the start of the run, and the glitch goes away.
Not a lot of use as a dynamic environment map though.

I have three frames to show you the problem.

I changed my ocean shader to be a flat perfectly reflective plane and grabbed three frames to show you.



It looks like one face of the texture cube is at the wrong memory address most of the time.

I have checked that all rendering is done on the render thread, nothing anywhere else touches the graphics device , but I have left the base.Draw(gameTime) call in… maybe it’s in there…

This is driving me insane. I really need some ideas from you guys.

I ran it up in RenderDoc just to check everything was fine.

The six faces of my environment map are shown below. All good.

AND OF COURSE AS EVERY GAMES CODER KNOWS … when you run it in the debugger the problem goes away.

Whimper.

Help.






I won’t be able to help you for sure, but maybe you should make a minimal example showing the problem so that it can be reproduced by people who knows what is doing :slight_smile:

Have you tried the Visual Studio Graphics Debugging a part of RenderDoc? Maybe the problem is reproduced there…

The bug does not appear in visual studio graphics debugging. Such is not my life that a simple solution exists to anything I do.

No hope of doing a minimal solution, it would be completely different from my multi-threaded model.

It has to be a thread timing issue, but my profiler should show that up and nothing is showing up.

I can only speak for myself to say its not clear what the problem is at all.

Every shader that uses the environment map glitches. Every second or two it just goes horribly wrong.

Of course this begs the question what shader what code what kind of glitch what system are you on.

The shader code was nothing to do with it, the glitch was obvious, one face of the environment map was wrong randomly.

I eventually fixed it by moving my render code from a separate thread onto the main thread. Annoying I have to do this, but only solution I can see.

I am now working on moving my input device management off the main thread to help re-balance core usage.