Behavior of pooled textures is broken with ping/pong textures

More
9 months 2 weeks ago - 9 months 2 weeks ago #1 by luluco250
UPDATE: It appears that the behavior still occurs in DirectX 12, but somehow it allows textures to be read/written in the same pass?

I figured this out by trying to output one of the ping/pong textures that was read last, yet it shows the output of the texture that was *written* last, thus appearing as if it's just using the same texture.

Original post...

When attempting to use two textures of the same size and format (ping/pong textures) with the pooled flag turned on, ReShade seems to try sharing them within the same technique, which causes problems when reading from the first texture to write to the other (as shaders cannot read and write from a texture in the same pass).

This does not seem to happen on another game I tested that runs on DirectX 12, I assume it may be the case for 11 and 10 as well but I have not tried.

Here is an example shader that breaks under these conditions: gist.github.com/luluco250/986d6d4b34e5a865819a9c8ef4553dd9

It should just show the image as normal if it's working correctly, otherwise a black screen due to the attempted read/write on the same texture.

PS: Is this website broken? The <textarea> for the topic text box has its visibility set to hidden in the style for some reason, I had to unset that to post here.
Last edit: 9 months 2 weeks ago by luluco250. Reason: Misspelling and minor improvement.

Please Log in or Create an account to join the conversation.

More
9 months 2 weeks ago #2 by crosire
ReShade does not give guarantees on how pooled textures are shared. It will share every texture with the same dimensions no matter their usage, so this is expected behavior. Pooling primarily exists so that ReShade can share textures you use in your effect with other effects, when you know that the contents only need to stay valid within a technique. But sharing textures within the same effect is not working well for this reason. Not sure what a good solution would be. Could maybe ignore all textures from the same effect file when searching for candidates to share.

The reason you are seeing a difference between DX12 and earlier DX is that earlier DX automatically unbind any textures that are also bound as render target, whereas DX12 does not do that (since it does no validation, it's a low-level API so expects you to be responsible that all bindings are correct). You'll get corruptions and all kinds of funky stuff there when reading/writing simultaneously instead.

Thanks for the broken website notice btw., that's fixed now!
The following user(s) said Thank You: luluco250

Please Log in or Create an account to join the conversation.

More
9 months 2 weeks ago - 9 months 2 weeks ago #3 by luluco250
Gotcha, I think ignoring pooling for textures in the same effect would be a fine trade-off since we as devs could share the textures internally ourselves, it only really matters for sharing resources with other effects (personally I like pooling everything except for temporal/persistence textures).

It's strange that it seemingly used to work before (pooling ping/pong textures that is), but I can't prove it. :P

And yeah I noticed there were some weird corruption/memory leakage (?) on the output in DirectX 12, guess it's undefined behavior going on.

In any case, thank you for the explanation! I'll just avoid pooling for ping/pongs for now.
Last edit: 9 months 2 weeks ago by luluco250.

Please Log in or Create an account to join the conversation.

More
9 months 2 weeks ago #4 by crosire
Done in github.com/crosire/reshade/commit/171c4c...f0f652fb11fe6662f128 now. So starting with ReShade 4.9 this will work.
The following user(s) said Thank You: luluco250

Please Log in or Create an account to join the conversation.

More
9 months 2 weeks ago #5 by luluco250
Nice! Thank you.

Please Log in or Create an account to join the conversation.