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

Crash using Metal renderer when using RGB5A1 textures #3344

Open
zacbrannelly opened this issue Aug 25, 2024 · 0 comments
Open

Crash using Metal renderer when using RGB5A1 textures #3344

zacbrannelly opened this issue Aug 25, 2024 · 0 comments

Comments

@zacbrannelly
Copy link

Describe the bug

In the Metal renderer, a simple call to createTexture2D to create a RGB5A1 texture has side effects that breaks reset, specifically when the depth buffer is resized.

After calling createTexture2D with a pixel format that uses texture swizzle which applies swizzle that isn't just R -> R, G -> G, B -> B, A -> A (for RGB5A1 it is R -> B, G -> G, B -> R, A -> A), then I get the following error when calling reset, which I call after window resize:

-[MTLTextureDescriptorInternal validateWithDevice:]:1357: failed assertion `Texture Descriptor Validation
Texture swizzling is not compatable with MTLTextureUsageRenderTarget

To Reproduce

bgfx::createTexture2D(100, 100, false, 1, RGB5A1, BGFX_TEXTURE_NONE, NULL);
bgfx::reset(1920, 1080, 0);

Expected behavior

reset to complete without hitting an assertion.

Additional context

I can fix the problem by editing the SwapChainMtl::resize function in renderer_mtl.mm, where I change this:

if (s_renderMtl->m_hasPixelFormatDepth32Float_Stencil8)
{
    desc.pixelFormat = MTLPixelFormatDepth32Float_Stencil8;
}

To this:

if (s_renderMtl->m_hasPixelFormatDepth32Float_Stencil8)
{
    desc.pixelFormat = MTLPixelFormatDepth32Float_Stencil8;
    desc.swizzle = { MTLTextureSwizzleRed, MTLTextureSwizzleGreen, MTLTextureSwizzleBlue, MTLTextureSwizzleAlpha };
}

Happy to make a PR but cognisant of the fact I'm not entirely sure what/if there are any other issues this would cause.

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