diff --git a/src/mbgl/mtl/offscreen_texture.cpp b/src/mbgl/mtl/offscreen_texture.cpp index 8226b946d..b24658d1b 100644 --- a/src/mbgl/mtl/offscreen_texture.cpp +++ b/src/mbgl/mtl/offscreen_texture.cpp @@ -35,6 +35,8 @@ public: ->setUsage(MTL::TextureUsageShaderRead | MTL::TextureUsageShaderWrite | MTL::TextureUsageRenderTarget); } + // On iOS simulator, the depth target is PixelFormatDepth32Float_Stencil8 +#if !TARGET_OS_SIMULATOR if (stencil) { stencilTexture = context.createTexture2D(); stencilTexture->setSize(size); @@ -44,6 +46,8 @@ public: static_cast(stencilTexture.get()) ->setUsage(MTL::TextureUsageShaderRead | MTL::TextureUsageShaderWrite | MTL::TextureUsageRenderTarget); } +#endif + context.renderingStats().numFrameBuffers++; } diff --git a/src/mbgl/mtl/texture2d.cpp b/src/mbgl/mtl/texture2d.cpp index 6d10d2d28..b42d4b698 100644 --- a/src/mbgl/mtl/texture2d.cpp +++ b/src/mbgl/mtl/texture2d.cpp @@ -82,6 +82,19 @@ size_t Texture2D::numChannels() const noexcept { } MTL::PixelFormat Texture2D::getMetalPixelFormat() const noexcept { + // On iOS simulator, we need to use the combined depth/stencil format. If the depth and stencil + // formats are both set on a render pipeline, they have to be identical or we'll get, e.g.: + // validateWithDevice:4343: failed assertion `Render Pipeline Descriptor Validation + // depthAttachmentPixelFormat (MTLPixelFormatDepth32Float) and + // stencilAttachmentPixelFormat (MTLPixelFormatStencil8) must match. + +#if TARGET_OS_SIMULATOR + if (channelType == gfx::TextureChannelDataType::Float && pixelFormat == gfx::TexturePixelType::Depth && + (usage & MTL::TextureUsageRenderTarget)) { + return MTL::PixelFormatDepth32Float_Stencil8; + } +#endif + switch (channelType) { case gfx::TextureChannelDataType::UnsignedByte: switch (pixelFormat) { @@ -138,6 +151,24 @@ void Texture2D::createMetalTexture() noexcept { if (auto textureDescriptor = NS::RetainPtr( MTL::TextureDescriptor::texture2DDescriptor(format, size.width, size.height, /*mipmapped=*/false))) { textureDescriptor->setUsage(usage); +#if TARGET_OS_SIMULATOR + switch (format) { + case MTL::PixelFormatDepth16Unorm: + case MTL::PixelFormatDepth32Float: + case MTL::PixelFormatStencil8: + case MTL::PixelFormatDepth24Unorm_Stencil8: + case MTL::PixelFormatDepth32Float_Stencil8: + case MTL::PixelFormatX32_Stencil8: + case MTL::PixelFormatX24_Stencil8: + // On iOS simulator, the default shared mode is invalid for depth and stencil textures. + // 'Texture Descriptor Validation MTLTextureDescriptor: Depth, Stencil, DepthStencil + // textures cannot be allocated with MTLStorageModeShared on this device. + textureDescriptor->setStorageMode(MTL::StorageMode::StorageModePrivate); + break; + default: + break; + } +#endif metalTexture = context.createMetalTexture(std::move(textureDescriptor)); } diff --git a/test/include/mbgl/test/util.hpp b/test/include/mbgl/test/util.hpp index cac435705..c1abe6bad 100644 --- a/test/include/mbgl/test/util.hpp +++ b/test/include/mbgl/test/util.hpp @@ -6,7 +6,8 @@ #define TEST_READ_ONLY 0 -#if !ANDROID +// iOS simulator server can work if port 3000 is available +#if !ANDROID && !TARGET_OS_SIMULATOR #ifndef TEST_HAS_SERVER #define TEST_HAS_SERVER 1 #endif diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 9b0827164..81050434e 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include