Skip to content

Commit

Permalink
Stop disposing swapchain framebuffer texture on D3D11
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Apr 1, 2023
1 parent 367f3ec commit 59e0bb4
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/Veldrid/D3D11/D3D11Swapchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public D3D11Swapchain(D3D11GraphicsDevice gd, ref SwapchainDescription descripti
Resize(description.Width, description.Height);
}

private ID3D11Texture2D backBufferTexture;

public override void Resize(uint width, uint height)
{
lock (_referencedCLsLock)
Expand All @@ -167,6 +169,7 @@ public override void Resize(uint width, uint height)
_depthTexture.Dispose();
}

backBufferTexture.Dispose();
_framebuffer.Dispose();
}

Expand All @@ -178,29 +181,28 @@ public override void Resize(uint width, uint height)
}

// Get the backbuffer from the swapchain
using (ID3D11Texture2D backBufferTexture = _dxgiSwapChain.GetBuffer<ID3D11Texture2D>(0))
backBufferTexture = _dxgiSwapChain.GetBuffer<ID3D11Texture2D>(0);

if (_depthFormat != null)
{
if (_depthFormat != null)
{
TextureDescription depthDesc = new TextureDescription(
actualWidth, actualHeight, 1, 1, 1,
_depthFormat.Value,
TextureUsage.DepthStencil,
TextureType.Texture2D);
_depthTexture = new D3D11Texture(_gd.Device, ref depthDesc);
}
TextureDescription depthDesc = new TextureDescription(
actualWidth, actualHeight, 1, 1, 1,
_depthFormat.Value,
TextureUsage.DepthStencil,
TextureType.Texture2D);
_depthTexture = new D3D11Texture(_gd.Device, ref depthDesc);
}

D3D11Texture backBufferVdTexture = new D3D11Texture(
backBufferTexture,
TextureType.Texture2D,
D3D11Formats.ToVdFormat(_colorFormat));
D3D11Texture backBufferVdTexture = new D3D11Texture(
backBufferTexture,
TextureType.Texture2D,
D3D11Formats.ToVdFormat(_colorFormat));

FramebufferDescription desc = new FramebufferDescription(_depthTexture, backBufferVdTexture);
_framebuffer = new D3D11Framebuffer(_gd.Device, ref desc)
{
Swapchain = this
};
}
FramebufferDescription desc = new FramebufferDescription(_depthTexture, backBufferVdTexture);
_framebuffer = new D3D11Framebuffer(_gd.Device, ref desc)
{
Swapchain = this
};
}

public void AddCommandListReference(D3D11CommandList cl)
Expand Down

0 comments on commit 59e0bb4

Please sign in to comment.