Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around D3D11 texture pointer getting lost before disposal #54

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading