Skip to content

Commit

Permalink
Fix visionOS build
Browse files Browse the repository at this point in the history
This adds a few macros to test which platform is currently being built.
Addresses some compile warnings such as missing return values.
  • Loading branch information
mkrus committed Mar 1, 2024
1 parent 37361cc commit 9082ca8
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 30 deletions.
11 changes: 7 additions & 4 deletions Common/MVKCommonEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ extern "C" {
#ifndef TARGET_OS_XR
# define TARGET_OS_XR 0 // Older SDK's don't define TARGET_OS_XR
#endif
#ifndef TARGET_OS_VISION
# define TARGET_OS_VISION 0 // Older SDK's don't define TARGET_OS_VISION
#endif
#ifndef MVK_VISIONOS
# define MVK_VISIONOS TARGET_OS_XR
# define MVK_VISIONOS (TARGET_OS_XR || TARGET_OS_VISION)
#endif

/** Building for iOS or tvOS. */
Expand All @@ -83,9 +86,9 @@ extern "C" {
# define MVK_MACOS_OR_IOS (MVK_MACOS || MVK_IOS)
#endif

/** Building for macOS, iOS or visionOS. */
#ifndef MVK_MACOS_OR_IOS_OR_VISIONOS
# define MVK_MACOS_OR_IOS_OR_VISIONOS (MVK_MACOS || MVK_IOS | MVK_VISIONOS)
/** Building for iOS or visionOS. */
#ifndef MVK_IOS_OR_VISIONOS
# define MVK_IOS_OR_VISIONOS (MVK_IOS || MVK_VISIONOS)
#endif

/** Building for a Simulator. */
Expand Down
3 changes: 1 addition & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKBuffer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@
return (mvkIsAnyFlagEnabled(barrier.dstStageMask, (VK_PIPELINE_STAGE_HOST_BIT)) &&
mvkIsAnyFlagEnabled(barrier.dstAccessMask, (VK_ACCESS_HOST_READ_BIT)) &&
isMemoryHostAccessible() && (!isMemoryHostCoherent() || _isHostCoherentTexelBuffer));
#endif
#if MVK_IOS_OR_TVOS
#else
return false;
#endif
}
Expand Down
11 changes: 5 additions & 6 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2936,7 +2936,7 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope

#endif //MVK_MACOS

#if MVK_IOS_OR_TVOS
#if !MVK_MACOS
// For Apple Silicon, the Device ID is determined by the highest
// GPU capability, which is a combination of OS version and GPU type.
void MVKPhysicalDevice::initGPUInfoProperties() {
Expand All @@ -2945,7 +2945,7 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
_properties.deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
strlcpy(_properties.deviceName, _mtlDevice.name.UTF8String, VK_MAX_PHYSICAL_DEVICE_NAME_SIZE);
}
#endif //MVK_IOS_OR_TVOS
#endif //!MVK_MACOS

// Since this is a uint8_t array, use Big-Endian byte ordering,
// so a hex dump of the array is human readable in its parts.
Expand Down Expand Up @@ -3013,7 +3013,7 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
}

// Fall back to legacy feature sets on older OS's
#if MVK_IOS
#if MVK_IOS_OR_VISIONOS
uint32_t maxFS = (uint32_t)MTLFeatureSet_iOS_GPUFamily5_v1;
uint32_t minFS = (uint32_t)MTLFeatureSet_iOS_GPUFamily1_v1;
#endif
Expand Down Expand Up @@ -3177,12 +3177,11 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
}

bool MVKPhysicalDevice::getHasUnifiedMemory() {
#if MVK_IOS_OR_TVOS
return true;
#endif
#if MVK_MACOS
return ([_mtlDevice respondsToSelector: @selector(hasUnifiedMemory)]
? _mtlDevice.hasUnifiedMemory : _mtlDevice.isLowPower);
#else
return true;
#endif
}

Expand Down
3 changes: 1 addition & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,7 @@
return ((barrier.newLayout == VK_IMAGE_LAYOUT_GENERAL) &&
mvkIsAnyFlagEnabled(barrier.dstAccessMask, (VK_ACCESS_HOST_READ_BIT | VK_ACCESS_MEMORY_READ_BIT)) &&
isMemoryHostAccessible() && (!_device->_pMetalFeatures->sharedLinearTextures || !isMemoryHostCoherent()));
#endif
#if MVK_IOS_OR_TVOS
#else
return false;
#endif
}
Expand Down
15 changes: 14 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
# define MTLPixelFormatX24_Stencil8 MTLPixelFormatInvalid
#endif

#if MVK_VISIONOS
# define MTLPixelFormatDepth24Unorm_Stencil8 MTLPixelFormatInvalid
# define MTLPixelFormatDepth16Unorm_Stencil8 MTLPixelFormatInvalid
# define MTLPixelFormatX24_Stencil8 MTLPixelFormatInvalid
#endif


#if MVK_TVOS
# define MTLPixelFormatASTC_4x4_HDR MTLPixelFormatInvalid
# define MTLPixelFormatASTC_5x4_HDR MTLPixelFormatInvalid
Expand Down Expand Up @@ -1321,8 +1328,8 @@
addMTLPixelFormatDesc ( Depth32Float, None, DRM, DRFMR );
addMTLPixelFormatDesc ( Stencil8, None, DRM, DRMR );
addMTLPixelFormatDesc ( Depth24Unorm_Stencil8, Depth24_Stencil8, None, None );
addMTLPixelFormatDesc ( Depth32Float_Stencil8, Depth32_Stencil8, DRM, DRFMR );
addMTLPixelFormatDesc ( X24_Stencil8, Depth24_Stencil8, None, DRMR );
addMTLPixelFormatDesc ( Depth32Float_Stencil8, Depth32_Stencil8, DRM, DRFMR );
addMTLPixelFormatDesc ( X32_Stencil8, Depth32_Stencil8, DRM, DRMR );

_mtlPixelFormatDescriptions.shrink_to_fit();
Expand Down Expand Up @@ -2004,6 +2011,9 @@
#endif
#if MVK_IOS || MVK_TVOS
bool supportsNativeTextureSwizzle = mtlDevice && mvkOSVersionIsAtLeast(13.0);
#endif
#if MVK_VISIONOS
bool supportsNativeTextureSwizzle = mtlDevice;
#endif
if (!supportsNativeTextureSwizzle && !getMVKConfig().fullImageViewSwizzle) {
vkDesc.mtlPixelFormat = vkDesc.mtlPixelFormatSubstitute = MTLPixelFormatInvalid;
Expand Down Expand Up @@ -2123,6 +2133,9 @@
#if MVK_TVOS
bool supportsStencilFeedback = false;
#endif
#if MVK_VISIONOS
bool supportsStencilFeedback = [mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily5_v1];
#endif

// Vulkan forbids blits between chroma-subsampled formats.
// If we can't write the stencil reference from the shader, we can't blit stencil.
Expand Down
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@
VkResult MVKSwapchain::getRefreshCycleDuration(VkRefreshCycleDurationGOOGLE *pRefreshCycleDuration) {
if (_device->getConfigurationResult() != VK_SUCCESS) { return _device->getConfigurationResult(); }

auto* screen = getCAMetalLayer().screenMVK; // Will be nil if headless
#if MVK_MACOS && !MVK_MACCAT
auto* screen = getCAMetalLayer().screenMVK; // Will be nil if headless
double framesPerSecond = 60;
if (screen) {
CGDirectDisplayID displayId = [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
Expand All @@ -207,6 +207,7 @@
framesPerSecond = 60.0;
}
#elif MVK_IOS_OR_TVOS || MVK_MACCAT
auto* screen = getCAMetalLayer().screenMVK; // Will be nil if headless
NSInteger framesPerSecond = 60;
if ([screen respondsToSelector: @selector(maximumFramesPerSecond)]) {
framesPerSecond = screen.maximumFramesPerSecond;
Expand Down
20 changes: 9 additions & 11 deletions MoltenVK/MoltenVK/OS/MTLRenderPassDescriptor+MoltenVK.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ -(NSUInteger) renderTargetArrayLengthMVK {
#if MVK_TVOS
return 0;
#endif
#if MVK_IOS
#if MVK_IOS_OR_VISIONOS
if ( [self respondsToSelector: @selector(renderTargetArrayLength)] ) {
return self.renderTargetArrayLength;
}
Expand All @@ -44,7 +44,7 @@ -(void) setRenderTargetArrayLengthMVK: (NSUInteger) length {
#if MVK_MACOS
self.renderTargetArrayLength = length;
#endif
#if MVK_IOS
#if MVK_IOS_OR_VISIONOS
if ( [self respondsToSelector: @selector(setRenderTargetArrayLength:)] ) {
self.renderTargetArrayLength = length;
}
Expand All @@ -56,18 +56,17 @@ -(NSUInteger) renderTargetWidthMVK {

#if MVK_TVOS
return 0;
#endif
#if MVK_MACOS_OR_IOS
if ([self respondsToSelector: @selector(renderTargetWidth)])
return self.renderTargetWidth;
return 0;
#else
if ([self respondsToSelector: @selector(renderTargetWidth)])
return self.renderTargetWidth;
return 0;
#endif

}

-(void) setRenderTargetWidthMVK: (NSUInteger) width {

#if MVK_MACOS_OR_IOS
#if !MVK_TVOS
if ([self respondsToSelector: @selector(setRenderTargetWidth:)])
self.renderTargetWidth = width;
#endif
Expand All @@ -78,8 +77,7 @@ -(NSUInteger) renderTargetHeightMVK {

#if MVK_TVOS
return 0;
#endif
#if MVK_MACOS_OR_IOS
#else
if ([self respondsToSelector: @selector(renderTargetHeight)])
return self.renderTargetHeight;
return 0;
Expand All @@ -89,7 +87,7 @@ -(NSUInteger) renderTargetHeightMVK {

-(void) setRenderTargetHeightMVK: (NSUInteger) height {

#if MVK_MACOS_OR_IOS
#if !MVK_TVOS
if ([self respondsToSelector: @selector(setRenderTargetHeight:)])
self.renderTargetHeight = height;
#endif
Expand Down
7 changes: 7 additions & 0 deletions MoltenVK/MoltenVK/Utility/MVKEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
# define MVK_SUPPORT_IOSURFACE_BOOL (__TV_OS_VERSION_MIN_REQUIRED >= __TVOS_11_0)
#endif

#if MVK_VISIONOS
# define MVK_SUPPORT_IOSURFACE_BOOL 1
#endif


#pragma mark -
#pragma mark MoltenVK Configuration
Expand Down Expand Up @@ -126,6 +130,9 @@ void mvkSetConfig(MVKConfiguration& dstMVKConfig, const MVKConfiguration& srcMVK
#if MVK_IOS_OR_TVOS
# define MVK_CONFIG_MTLEVENT_MIN_OS 12.0
#endif
#if MVK_VISIONOS
# define MVK_CONFIG_MTLEVENT_MIN_OS 1.0
#endif
#ifndef MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS
# define MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS mvkOSVersionIsAtLeast(MVK_CONFIG_MTLEVENT_MIN_OS)
#endif
Expand Down
5 changes: 2 additions & 3 deletions MoltenVK/MoltenVK/Utility/MVKFoundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,10 @@ static void mvkRemoveAllOccurances(C& container, T val) {
/** Selects and returns one of the values, based on the platform OS. */
template<typename T>
static constexpr const T& mvkSelectPlatformValue(const T& macOSVal, const T& iOSVal) {
#if MVK_IOS_OR_TVOS
return iOSVal;
#endif
#if MVK_MACOS
return macOSVal;
#else
return iOSVal;
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions MoltenVKPackaging.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
279BD8642B7FAE0A0021CE70 /* create_dylib_xros.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create_dylib_xros.sh; sourceTree = "<group>"; };
A92DB3E41CE0F37D00FBC835 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
A92DB3E51CE0F37D00FBC835 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
A92DB3E61CE0F37D00FBC835 /* Whats_New.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = Whats_New.md; path = Docs/Whats_New.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -278,6 +279,7 @@
A9C70F45221B04C800FBA31A /* create_dylib_ios.sh */,
A9C70F41221B04C800FBA31A /* create_dylib_macos.sh */,
A9FC5F64249D3778003CB086 /* create_dylib_tvos.sh */,
279BD8642B7FAE0A0021CE70 /* create_dylib_xros.sh */,
A975D55C213F25D700D4834F /* create_dylib.sh */,
A9B1007A24F837AF00EADC6E /* create_xcframework_func.sh */,
A980A25F24C628F3007A8F6F /* gen_moltenvk_rev_hdr.sh */,
Expand Down

0 comments on commit 9082ca8

Please sign in to comment.