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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion 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
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