Get unit and render tests running on iOS simulator (#2129)

This commit is contained in:
Tim Sylvester
2024-02-21 04:53:43 -08:00
committed by GitHub
parent 61fd33f526
commit 02eeec172d
4 changed files with 37 additions and 2 deletions

View File

@@ -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<Texture2D*>(stencilTexture.get())
->setUsage(MTL::TextureUsageShaderRead | MTL::TextureUsageShaderWrite | MTL::TextureUsageRenderTarget);
}
#endif
context.renderingStats().numFrameBuffers++;
}

View File

@@ -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));
}

View File

@@ -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

View File

@@ -8,7 +8,6 @@
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gfx/headless_frontend.hpp>
#include <mbgl/gfx/shader_registry.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/math/log2.hpp>
#include <mbgl/renderer/renderer.hpp>