diff --git a/Graphics/GraphicsTools/CMakeLists.txt b/Graphics/GraphicsTools/CMakeLists.txt index bd5a36bb4..3f21d8946 100644 --- a/Graphics/GraphicsTools/CMakeLists.txt +++ b/Graphics/GraphicsTools/CMakeLists.txt @@ -127,7 +127,7 @@ endif() if(METAL_SUPPORTED) list(APPEND SOURCE src/GraphicsUtilitiesMtl.mm) - list(APPEND DEPENDENCIES Diligent-GraphicsEngineMetalInterface) + list(APPEND DEPENDENCIES Diligent-GraphicsEngineMetal-static) endif() add_library(Diligent-GraphicsTools STATIC ${SOURCE} ${INCLUDE} ${INTERFACE}) diff --git a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp index 75e72599d..d21606b4f 100644 --- a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp +++ b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp @@ -60,6 +60,11 @@ int64_t GetNativeTextureFormatVk(TEXTURE_FORMAT TexFormat); TEXTURE_FORMAT GetTextureFormatFromNativeVk(int64_t NativeFormat); #endif +#if METAL_SUPPORTED +int64_t GetNativeTextureFormatMtl(TEXTURE_FORMAT TexFormat); +TEXTURE_FORMAT GetTextureFormatFromNativeMtl(int64_t NativeFormat); +#endif + #if WEBGPU_SUPPORTED int64_t GetNativeTextureFormatWebGPU(TEXTURE_FORMAT TexFormat); TEXTURE_FORMAT GetTextureFormatFromNativeWebGPU(int64_t NativeFormat); @@ -597,6 +602,11 @@ int64_t GetNativeTextureFormat(TEXTURE_FORMAT TexFormat, RENDER_DEVICE_TYPE Devi return GetNativeTextureFormatVk(TexFormat); #endif +#if VULKAN_SUPPORTED + case RENDER_DEVICE_TYPE_METAL: + return GetNativeTextureFormatMtl(TexFormat); +#endif + #if WEBGPU_SUPPORTED case RENDER_DEVICE_TYPE_WEBGPU: return GetNativeTextureFormatWebGPU(TexFormat); @@ -628,6 +638,11 @@ TEXTURE_FORMAT GetTextureFormatFromNative(int64_t NativeFormat, RENDER_DEVICE_TY return GetTextureFormatFromNativeGL(NativeFormat); #endif +#if VULKAN_SUPPORTED + case RENDER_DEVICE_TYPE_METAL: + return GetTextureFormatFromNativeMtl(NativeFormat); +#endif + #if VULKAN_SUPPORTED case RENDER_DEVICE_TYPE_VULKAN: return GetTextureFormatFromNativeVk(NativeFormat); diff --git a/Graphics/GraphicsTools/src/GraphicsUtilitiesMtl.mm b/Graphics/GraphicsTools/src/GraphicsUtilitiesMtl.mm index 6b6daf5ca..beaff6808 100644 --- a/Graphics/GraphicsTools/src/GraphicsUtilitiesMtl.mm +++ b/Graphics/GraphicsTools/src/GraphicsUtilitiesMtl.mm @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 Diligent Graphics LLC + * Copyright 2019-2024 Diligent Graphics LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,9 @@ namespace Diligent { +MTLPixelFormat TextureFormatToMTLPixelFormat(TEXTURE_FORMAT TexFormat); +TEXTURE_FORMAT MTLPixelFormatToTextureFormat(MTLPixelFormat mtlPixelFormat); + void CreateSparseTextureMtl(IRenderDevice* pDevice, const TextureDesc& TexDesc, IDeviceMemory* pMemory, @@ -54,4 +57,14 @@ void CreateSparseTextureMtl(IRenderDevice* pDevice, pDeviceMtl->CreateSparseTexture(TexDesc, pMemory, ppTexture); } +int64_t GetNativeTextureFormatMtl(TEXTURE_FORMAT TexFormat) +{ + return static_cast(TextureFormatToMTLPixelFormat(TexFormat)); +} + +TEXTURE_FORMAT GetTextureFormatFromNativeMtl(int64_t NativeFormat) +{ + return MTLPixelFormatToTextureFormat(static_cast(NativeFormat)); +} + } // namespace Diligent diff --git a/Tests/DiligentCoreTest/src/GraphicsTools/GraphicsUtilitiesTest.cpp b/Tests/DiligentCoreTest/src/GraphicsTools/GraphicsUtilitiesTest.cpp index 8921e585a..2d93a46d0 100644 --- a/Tests/DiligentCoreTest/src/GraphicsTools/GraphicsUtilitiesTest.cpp +++ b/Tests/DiligentCoreTest/src/GraphicsTools/GraphicsUtilitiesTest.cpp @@ -81,6 +81,25 @@ TEST(GraphicsUtilitiesTest, GetNativeTextureFormat_GetTextureFormatFromNative) TEX_FORMAT_BGRX8_UNORM_SRGB, }; + const std::unordered_set SkipFormatsMtl{ + TEX_FORMAT_RGB32_FLOAT, + TEX_FORMAT_RGB32_UINT, + TEX_FORMAT_RGB32_SINT, + TEX_FORMAT_R32_FLOAT_X8X24_TYPELESS, + TEX_FORMAT_X32_TYPELESS_G8X24_UINT, + TEX_FORMAT_R24_UNORM_X8_TYPELESS, + TEX_FORMAT_X24_TYPELESS_G8_UINT, + TEX_FORMAT_A8_UNORM, + TEX_FORMAT_R1_UNORM, + TEX_FORMAT_RG8_B8G8_UNORM, + TEX_FORMAT_G8R8_G8B8_UNORM, + TEX_FORMAT_B5G6R5_UNORM, + TEX_FORMAT_B5G5R5A1_UNORM, + TEX_FORMAT_BGRX8_UNORM, + TEX_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, + TEX_FORMAT_BGRX8_UNORM_SRGB, + }; + const std::unordered_set SkipFormatsWebGPU{ TEX_FORMAT_RGB32_FLOAT, TEX_FORMAT_RGB32_UINT, @@ -142,6 +161,13 @@ TEST(GraphicsUtilitiesTest, GetNativeTextureFormat_GetTextureFormatFromNative) } #endif +#if METAL_SUPPORTED + if (SkipFormatsMtl.find(Fmt) == SkipFormatsMtl.end()) + { + Test(RENDER_DEVICE_TYPE_METAL); + } +#endif + #if WEBGPU_SUPPORTED if (SkipFormatsWebGPU.find(Fmt) == SkipFormatsWebGPU.end()) {