Skip to content

Commit

Permalink
Merge pull request #54 from smoogipoo/fix-d3d-texture-disposal
Browse files Browse the repository at this point in the history
Work around D3D11 texture pointer getting lost before disposal
  • Loading branch information
smoogipoo authored May 3, 2024
2 parents f258ed0 + 8c2aedf commit 0c0f356
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Veldrid/D3D11/D3D11Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public D3D11Texture(ID3D11Device device, ref TextureDescription description)

DeviceTexture = device.CreateTexture3D(desc3D);
}

// See: https://github.com/ppy/veldrid/issues/53
GC.SuppressFinalize(DeviceTexture);
}

public D3D11Texture(ID3D11Texture2D existingTexture, TextureType type, PixelFormat format)
Expand All @@ -167,6 +170,9 @@ public D3D11Texture(ID3D11Texture2D existingTexture, TextureType type, PixelForm
format,
(Usage & TextureUsage.DepthStencil) == TextureUsage.DepthStencil);
TypelessDxgiFormat = D3D11Formats.GetTypelessFormat(DxgiFormat);

// See: https://github.com/ppy/veldrid/issues/53
GC.SuppressFinalize(DeviceTexture);
}

private protected override TextureView CreateFullTextureView(GraphicsDevice gd)
Expand Down
7 changes: 7 additions & 0 deletions src/Veldrid/D3D11/D3D11TextureView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public D3D11TextureView(D3D11GraphicsDevice gd, ref TextureViewDescription descr
description.BaseArrayLayer,
description.ArrayLayers,
Format);

ShaderResourceView = device.CreateShaderResourceView(d3dTex.DeviceTexture, srvDesc);

// See: https://github.com/ppy/veldrid/issues/53
GC.SuppressFinalize(ShaderResourceView);

if ((d3dTex.Usage & TextureUsage.Storage) == TextureUsage.Storage)
{
var uavDesc = new UnorderedAccessViewDescription
Expand Down Expand Up @@ -93,6 +97,9 @@ public D3D11TextureView(D3D11GraphicsDevice gd, ref TextureViewDescription descr
}

UnorderedAccessView = device.CreateUnorderedAccessView(d3dTex.DeviceTexture, uavDesc);

// See: https://github.com/ppy/veldrid/issues/53
GC.SuppressFinalize(UnorderedAccessView);
}
}

Expand Down

0 comments on commit 0c0f356

Please sign in to comment.