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

Destroying a texture after GraphicsDevice.UpdateTexture #471

Open
Helco opened this issue Dec 8, 2022 · 0 comments
Open

Destroying a texture after GraphicsDevice.UpdateTexture #471

Helco opened this issue Dec 8, 2022 · 0 comments

Comments

@Helco
Copy link
Contributor

Helco commented Dec 8, 2022

This could very well be just a misunderstanding on my part, so a change to documentation might suffice:
When destroying a texture shortly after using GraphicsDevice.UpdateTexture the validation layers can throw VUID-vkDestroyImage-image-01000 as internally a command list is submitted for the update but not waited for completion. Maybe even data races might be possible by updating the same texture twice?

In other words is the following code correct as per the intention of Veldrid:

[Fact]
public unsafe void Update_ThenDispose()
{
    Texture texture = RF.CreateTexture(new(256, 256, 1, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled, TextureType.Texture2D));
    byte[] data = Enumerable.Range(0, 256 * 256 * 4).Select(i => (byte)i).ToArray();
    fixed (byte* dataPtr = data)
    {
        GD.UpdateTexture(texture, (IntPtr)dataPtr, 256 * 256 * 4 * sizeof(byte), 0, 0, 0, 256, 256, 1, 0, 0);
    }
    texture.Dispose();
}

Such ambiguities should be solved by the documentation or prevented by waiting after every update, which of course could produce a performance problem.

btw: The workaround for single-threaded applications would be calling GraphicsDevice.WaitForIdle before disposing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant