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

Disable unsupported Metal Pixel formats for iOS/tvOS Simulator #2361

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 11 additions & 10 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@
addSurfFmt(RGBA16Float);
addSurfFmt(RGB10A2Unorm);
addSurfFmt(BGR10A2Unorm);
#if MVK_APPLE_SILICON
#if MVK_APPLE_SILICON && !MVK_OS_SIMULATOR
addSurfFmt(BGRA10_XR);
addSurfFmt(BGRA10_XR_sRGB);
addSurfFmt(BGR10_XR);
Expand Down Expand Up @@ -2146,11 +2146,8 @@
if ( mvkOSVersionIsAtLeast(13.0) ) {
_metalFeatures.mslVersionEnum = MTLLanguageVersion2_2;
_metalFeatures.placementHeaps = getMVKConfig().useMTLHeap;
#if MVK_OS_SIMULATOR
_metalFeatures.nativeTextureSwizzle = false;
#else
_metalFeatures.nativeTextureSwizzle = true;
#endif

if (supportsMTLGPUFamily(Apple3)) {
_metalFeatures.native3DCompressedTextures = true;
}
Expand Down Expand Up @@ -2448,9 +2445,10 @@
#endif
}

// iOS and tvOS adjustments necessary when running on the simulator.
// iOS, tvOS and visionOS adjustments necessary when running on the simulator.
#if MVK_OS_SIMULATOR
_metalFeatures.mtlBufferAlignment = 256; // Even on Apple Silicon
_metalFeatures.nativeTextureSwizzle = false;
#endif

// Argument buffers
Expand Down Expand Up @@ -2543,13 +2541,15 @@
_features.textureCompressionASTC_LDR = true;

_features.dualSrcBlend = true;
_features.depthClamp = true;

if (supportsMTLGPUFamily(Apple3)) {
_features.occlusionQueryPrecise = true;
}

if (supportsMTLGPUFamily(Apple3)) {
_features.tessellationShader = true;
_features.shaderTessellationAndGeometryPointSize = true;
}
#endif

Expand All @@ -2566,13 +2566,9 @@

_features.dualSrcBlend = true;

#if MVK_OS_SIMULATOR
_features.depthClamp = false;
#else
if (supportsMTLGPUFamily(Apple2)) {
_features.depthClamp = true;
}
#endif

if (supportsMTLGPUFamily(Apple3)) {
_features.tessellationShader = true;
Expand All @@ -2592,6 +2588,11 @@
}
#endif

// iOS, tvOS and visionOS adjustments necessary when running on the simulator.
#if MVK_OS_SIMULATOR
_features.depthClamp = false;
#endif

#if MVK_MACOS
_features.occlusionQueryPrecise = true;
_features.imageCubeArray = true;
Expand Down
28 changes: 25 additions & 3 deletions MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@
# define MTLPixelFormatASTC_12x12_HDR MTLPixelFormatInvalid
#endif

#if MVK_OS_SIMULATOR
# define MTLPixelFormatR8Unorm_sRGB MTLPixelFormatInvalid
# define MTLPixelFormatRG8Unorm_sRGB MTLPixelFormatInvalid
# define MTLPixelFormatB5G6R5Unorm MTLPixelFormatInvalid
# define MTLPixelFormatA1BGR5Unorm MTLPixelFormatInvalid
# define MTLPixelFormatABGR4Unorm MTLPixelFormatInvalid
# define MTLPixelFormatBGR5A1Unorm MTLPixelFormatInvalid
# define MTLPixelFormatBGR10_XR MTLPixelFormatInvalid
# define MTLPixelFormatBGR10_XR_sRGB MTLPixelFormatInvalid
# define MTLPixelFormatBGRA10_XR MTLPixelFormatInvalid
# define MTLPixelFormatBGRA10_XR_sRGB MTLPixelFormatInvalid
# define MTLPixelFormatGBGR422 MTLPixelFormatInvalid
# define MTLPixelFormatBGRG422 MTLPixelFormatInvalid
#endif

#if !MVK_XCODE_15
# define MTLVertexFormatFloatRG11B10 MTLVertexFormatInvalid
# define MTLVertexFormatFloatRGB9E5 MTLVertexFormatInvalid
Expand Down Expand Up @@ -1179,13 +1194,17 @@

#define addMTLPixelFormatDescFull(mtlFmt, mtlFmtLinear, viewClass, appleGPUCaps, macGPUCaps) \
addValidatedMTLPixelFormatDesc(MTLPixelFormat ##mtlFmt, MTLPixelFormat ##mtlFmtLinear, MVKMTLViewClass:: viewClass, \
kMVKMTLFmtCaps ##appleGPUCaps, kMVKMTLFmtCaps ##macGPUCaps, gpuCaps, "MTLPixelFormat" #mtlFmt)
appleGPUCaps, macGPUCaps, gpuCaps, "MTLPixelFormat" #mtlFmt)

#define addMTLPixelFormatDesc(mtlFmt, viewClass, appleGPUCaps, macGPUCaps) \
addMTLPixelFormatDescFull(mtlFmt, mtlFmt, viewClass, appleGPUCaps, macGPUCaps)
addMTLPixelFormatDescFull(mtlFmt, mtlFmt, viewClass, kMVKMTLFmtCaps ##appleGPUCaps, kMVKMTLFmtCaps ##macGPUCaps)

#define addMTLPixelFormatDescSRGB(mtlFmt, viewClass, appleGPUCaps, macGPUCaps, mtlFmtLinear) \
addMTLPixelFormatDescFull(mtlFmt, mtlFmtLinear, viewClass, appleGPUCaps, macGPUCaps)
/* Cannot write to sRGB textures in the simulator */ \
if(MVK_OS_SIMULATOR) { MVKMTLFmtCaps appleFmtCaps = kMVKMTLFmtCaps ##appleGPUCaps; \
mvkDisableFlags(appleFmtCaps, kMVKMTLFmtCapsWrite); \
addMTLPixelFormatDescFull(mtlFmt, mtlFmtLinear, viewClass, appleFmtCaps, kMVKMTLFmtCaps ##macGPUCaps); } \
else { addMTLPixelFormatDescFull(mtlFmt, mtlFmtLinear, viewClass, kMVKMTLFmtCaps ##appleGPUCaps, kMVKMTLFmtCaps ##macGPUCaps); }

void MVKPixelFormats::initMTLPixelFormatCapabilities(const MVKMTLDeviceCapabilities& gpuCaps) {
_mtlPixelFormatDescriptions.reserve(KIBI); // High estimate to future-proof against allocations as elements are added. shrink_to_fit() below will collapse.
Expand Down Expand Up @@ -1508,6 +1527,9 @@
// on macOS is the least-intrusive way to handle this in a Vulkan-friendly way.
disableMTLPixFmtCapsIfGPU( Mac1, RGB9E5Float, Blend);

// RGB9E5Float cannot be used as a render target on the simulator
disableMTLPixFmtCapsIf( MVK_OS_SIMULATOR, RGB9E5Float, ColorAtt );

setMTLPixFmtCapsIf( iosOnly6, RG32Uint, RWC );
setMTLPixFmtCapsIf( iosOnly6, RG32Sint, RWC );

Expand Down
Loading