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

Metal: Ensure texture_create_from_extension returns correct pixel format #99905

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
24 changes: 19 additions & 5 deletions drivers/metal/rendering_device_driver_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,25 @@ _FORCE_INLINE_ MTLSize mipmapLevelSizeFromSize(MTLSize p_size, NSUInteger p_leve
}

RDD::TextureID RenderingDeviceDriverMetal::texture_create_from_extension(uint64_t p_native_texture, TextureType p_type, DataFormat p_format, uint32_t p_array_layers, bool p_depth_stencil) {
id<MTLTexture> obj = (__bridge id<MTLTexture>)(void *)(uintptr_t)p_native_texture;

// We only need to create a RDD::TextureID for an existing, natively-provided texture.

return rid::make(obj);
id<MTLTexture> res = (__bridge id<MTLTexture>)(void *)(uintptr_t)p_native_texture;

// If the requested format is different, we need to create a view.
MTLPixelFormat format = pixel_formats->getMTLPixelFormat(p_format);
if (res.pixelFormat != format) {
MTLTextureSwizzleChannels swizzle = MTLTextureSwizzleChannelsMake(
MTLTextureSwizzleRed,
MTLTextureSwizzleGreen,
MTLTextureSwizzleBlue,
MTLTextureSwizzleAlpha);
res = [res newTextureViewWithPixelFormat:format
textureType:res.textureType
levels:NSMakeRange(0, res.mipmapLevelCount)
slices:NSMakeRange(0, p_array_layers)
swizzle:swizzle];
ERR_FAIL_NULL_V_MSG(res, TextureID(), "Unable to create texture view.");
}

return rid::make(res);
}

RDD::TextureID RenderingDeviceDriverMetal::texture_create_shared(TextureID p_original_texture, const TextureView &p_view) {
Expand Down