Skip to content

Commit

Permalink
Merge pull request #824 from Sergio0694/dev/fix-zoom-in-crash
Browse files Browse the repository at this point in the history
Cap DX12 swapchain texture size to maximum
  • Loading branch information
Sergio0694 authored Jul 5, 2024
2 parents bbd6714 + 8ddf282 commit c67b849
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/ComputeSharp.WinUI/Helpers/SwapChainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,27 @@ private unsafe void ApplyResize()
? this.dynamicResolutionScale
: this.resolutionScale;

uint resizedWidth = (uint)Math.Max(Math.Ceiling(this.width * this.compositionScaleX * targetResolutionScale), 1.0);
uint resizeHeight = (uint)Math.Max(Math.Ceiling(this.height * this.compositionScaleY * targetResolutionScale), 1.0);
uint resizedWidth = (uint)Math.Max(Math.Ceiling(this.width * this.compositionScaleX * targetResolutionScale), 1.0f);
uint resizeHeight = (uint)Math.Max(Math.Ceiling(this.height * this.compositionScaleY * targetResolutionScale), 1.0f);

// Make sure not to exceed the maximum allowed size for textures. This might happen
// when the control is inside a ScrollView control that's zommed in to a very high
// amount, or when trying to manually set an invalid size to the control manually.
if (resizedWidth > D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION ||
resizeHeight > D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION)
{
// Make sure to scale down by preserving the aspect ratio
if (resizedWidth >= resizeHeight)
{
resizeHeight = (uint)Math.Max(resizeHeight * D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION / (float)resizedWidth, 1.0f);
resizedWidth = D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION;
}
else
{
resizedWidth = (uint)Math.Max(resizedWidth * D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION / (float)resizeHeight, 1.0f);
resizeHeight = D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION;
}
}

if (this.texture is null ||
this.texture.Width != resizedWidth ||
Expand Down

0 comments on commit c67b849

Please sign in to comment.