diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index d72774df83a..8210e72e0a6 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed issue when changing volume profiles at runtime with a script (case 1364256). +- Fixed an issue causing Render Graph execution errors after a random amount of time. ## [13.1.1] - 2021-10-04 diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs index 6577d4b28b1..673e9ea0eb2 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs @@ -48,14 +48,21 @@ public bool IsValid() static public void NewFrame(int executionIndex) { + uint previousValidBit = s_CurrentValidBit; // Scramble frame count to avoid collision when wrapping around. s_CurrentValidBit = (uint)(((executionIndex >> 16) ^ (executionIndex & 0xffff) * 58546883) << 16); // In case the current valid bit is 0, even though perfectly valid, 0 represents an invalid handle, hence we'll // trigger an invalid state incorrectly. To account for this, we actually skip 0 as a viable s_CurrentValidBit and // start from 1 again. - if (s_CurrentValidBit == 0) + // In the same spirit, s_SharedResourceValidBit is reserved for shared textures so we should never use it otherwise + // resources could be considered valid at frame N+1 (because shared) even though they aren't. + if (s_CurrentValidBit == 0 || s_CurrentValidBit == s_SharedResourceValidBit) { - s_CurrentValidBit = 1 << 16; + // We need to make sure we don't pick the same value twice. + uint value = 1; + while (previousValidBit == (value << 16)) + value++; + s_CurrentValidBit = (value << 16); } } }