Skip to content

Commit 0fde80a

Browse files
kechosebastienlagarde
authored andcommitted
[Fogbugz # 1383093] Fixing leaky state of hardware resolution when turned off from camera (#6492)
* * Fixing leaky state of hardware resolution dx12 when we disable DRS on a camera object through inspector or script * Fixing dirty state of depth mip pyramid * Changelog update for case 1383093, bad hw drs for ao Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent f8b2b5c commit 0fde80a

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

com.unity.render-pipelines.core/Runtime/Common/DynamicResolutionHandler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ private bool FlushScalableBufferManagerState()
102102

103103
s_GlobalHwUpresActive = HardwareDynamicResIsEnabled();
104104
s_GlobalHwFraction = m_CurrentFraction;
105-
ScalableBufferManager.ResizeBuffers(s_GlobalHwFraction, s_GlobalHwFraction);
105+
float currentFraction = s_GlobalHwUpresActive ? s_GlobalHwFraction : 1.0f;
106+
ScalableBufferManager.ResizeBuffers(currentFraction, currentFraction);
106107
return true;
107108
}
108109

@@ -290,6 +291,7 @@ public void Update(GlobalDynamicResolutionSettings settings, Action OnResolution
290291

291292
if (!m_Enabled && !s_ActiveInstanceDirty)
292293
{
294+
FlushScalableBufferManagerState();
293295
s_ActiveInstanceDirty = false;
294296
return;
295297
}

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,13 @@ internal static void RestoreRenderPipelineAsset(bool wasUnsetFromQuality, Render
631631
internal struct PackedMipChainInfo
632632
{
633633
public Vector2Int textureSize;
634-
public Vector2Int hardwareTextureSize;
635634
public int mipLevelCount;
636635
public Vector2Int[] mipLevelSizes;
637636
public Vector2Int[] mipLevelOffsets;
638637

638+
private Vector2 cachedTextureScale;
639+
private Vector2Int cachedHardwareTextureSize;
640+
639641
private bool m_OffsetBufferWillNeedUpdate;
640642

641643
public void Allocate()
@@ -650,13 +652,16 @@ public void Allocate()
650652
// This function is NOT fast, but it is illustrative, and can be optimized later.
651653
public void ComputePackedMipChainInfo(Vector2Int viewportSize)
652654
{
655+
bool isHardwareDrsOn = DynamicResolutionHandler.instance.HardwareDynamicResIsEnabled();
656+
Vector2Int hardwareTextureSize = isHardwareDrsOn ? DynamicResolutionHandler.instance.ApplyScalesOnSize(viewportSize) : viewportSize;
657+
Vector2 textureScale = isHardwareDrsOn ? new Vector2((float)viewportSize.x / (float)hardwareTextureSize.x, (float)viewportSize.y / (float)hardwareTextureSize.y) : new Vector2(1.0f, 1.0f);
658+
653659
// No work needed.
654-
if (viewportSize == mipLevelSizes[0])
660+
if (cachedHardwareTextureSize == hardwareTextureSize && cachedTextureScale == textureScale)
655661
return;
656662

657-
bool isHardwareDrsOn = DynamicResolutionHandler.instance.HardwareDynamicResIsEnabled();
658-
hardwareTextureSize = isHardwareDrsOn ? DynamicResolutionHandler.instance.ApplyScalesOnSize(viewportSize) : viewportSize;
659-
Vector2 textureScale = isHardwareDrsOn ? new Vector2((float)viewportSize.x / (float)hardwareTextureSize.x, (float)viewportSize.y / (float)hardwareTextureSize.y) : new Vector2(1.0f, 1.0f);
663+
cachedHardwareTextureSize = hardwareTextureSize;
664+
cachedTextureScale = textureScale;
660665

661666
mipLevelSizes[0] = hardwareTextureSize;
662667
mipLevelOffsets[0] = Vector2Int.zero;

0 commit comments

Comments
 (0)