75 Commits

Author SHA1 Message Date
karelrooted
d483d620b6 Fix system memory size of tvOS
use sysctlbyname("hw.memsize") to get sytem memory size instead of host_info,
host_info is not available on tvOS, so we change to sysctlbyname which support all apple platforms

apple document didn't stat this API is available on tvOS though,
https://developer.apple.com/documentation/kernel/1387446-sysctlbyname
2023-12-19 14:00:45 +08:00
Bill Hollings
90eb1af19f Add support for extension VK_EXT_headless_surface.
- Consolidate info about CAMetalLayer and headless in MVKSurface.
- MVKSwapchainImage remove getCAMetalDrawable()
  and focus on abstracting getMTLTexture().
- MVKPresentableSwapchainImage::getCAMetalDrawable() return nil if headless.
- Add MVKPresentableSwapchainImage::_mtlTextureHeadless to support
  a fixed MTLTexture that is not retrieved from a CAMetalDrawable.
- MVKPresentableSwapchainImage refactor signalling semaphores and fences.
- MVKPresentableSwapchainImage don't lock when signalling semaphores and fences.
- If no present occurs, actualPresentTime will be zero. Set it to current
  time, instead of to desiredPresentTime, since it's more accurate.
- Rework timestamps:
  - Remove _mvkTimestampBase so mvkGetTimestamp() is equal to
    mach_absolute_time(), which is used in presentation timing.
  - Add mvkGetRuntimeNanoseconds().
  - Rename mvkGetAbsoluteTime() to mvkGetContinuousNanoseconds().
  - Remove mvkGetTimestampPeriod() as unused.
- MVKSemaphoreMTLEvent::encodeDeferredSignal remove redundant nil test (unrelated).
- Fix swapchain and surface bugs when windowing system
  is accessed from off the main thread (unrelated).
- Log warning when deprecated functions vkCreateMacOSSurfaceMVK()
  or vkCreateIOSSurfaceMVK() are used (unrelated).
- Remove documentation for visionos, as support is not ready (unrelated).
2023-12-04 11:56:22 -05:00
Bill Hollings
62e0368e21 Add configurable lowpass filter for VkPhysicalDeviceLimits::timestampPeriod.
- Add MVKConfiguration::timestampPeriodLowPassAlpha, along with matching
  MVK_CONFIG_TIMESTAMP_PERIOD_LOWPASS_ALPHA env var.
- Add MVKConfigMembers.def file to describe MVKConfiguration members,
  to support consistent batch handling of members.
- Add env var & build settings MVK_CONFIG_DEBUG, plus legacy
  MVK_CONFIG_ALLOW_METAL_EVENTS & MVK_CONFIG_ALLOW_METAL_FENCES.
- Simplify environment variable retrieval functions and macros.
- Rename MVKDevice::updateTimestampsAndPeriod() to updateTimestampPeriod().
2023-09-12 11:41:43 -04:00
Bill Hollings
6c6139ca92
Update Common/MVKOSExtensions.h
Co-authored-by: Chip Davis <cdavis5x@gmail.com>
2023-09-07 09:33:40 -04:00
Bill Hollings
7fe4963985 Guard against CAMetalDrawable with invalid pixel format.
- Calling nextDrawable may result in a nil drawable, or a drawable with no
  pixel format. Attempt several times to retrieve a drawable with a valid
  pixel format, and if unsuccessful, return an error from vkQueuePresentKHR()
  and vkAcquireNextImageKHR(), to force swapchain to be re-created.
- Reorganize MVKQueuePresentSurfaceSubmission::execute() to detect drawable
  with invalid format, attach MTLCommandBuffer completion handler just before
  commit, and delay enqueuing MTLCommandBuffer until commit.
- Refactor mvkOSVersionIsAtLeast() for clarity (unrelated).
2023-09-06 16:16:11 -04:00
Bill Hollings
6374d9d29b Fix visionOS build errors and warnings where possible.
- Remove visionOS from multi-platform builds because it
  requires Xcode 15+ and will abort a multi-platform build.
- Define TARGET_OS_XR for older SDK's.
- A number of SDK deprecation warnings remain when building for visionOS.
  These cannot be removed without significant refactoring.
- Build visionOS dependencies for Release build by default.
- Fix local variable initialization warning (unrelated).
2023-07-11 15:43:41 -04:00
Bill Hollings
855c7a6c36 Merge branch 'visionOS' of https://github.com/nginetechnologies/MoltenVK into nginetechnologies-visionOS 2023-07-11 10:58:46 -04:00
Chip Davis
561e14ba62 Support the VK_EXT_pipeline_creation_feedback extension.
This provides feedback that indicates:
* how long it took to compile each shader stage and the pipeline as a
  whole;
* whether or not the pipeline or any shader stage were found in any
  supplied pipeline cache; and
* whether or not any supplied base pipeline were used to accelerate
  pipeline creation.

This is similar to the performance statistics that MoltenVK already
collects.

Since we don't use any supplied base pipeline at all, this
implementation never sets
`VK_PIPELINE_CREATION_FEEDBACK_BASE_PIPELINE_ACCELERATION_BIT`. However,
I've identified several places where we could probably use the base
pipeline to accelerate pipeline creation. One day, I should probably
implement that.

Likewise, because we don't yet support using `MTLBinaryArchive`s,
`VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT` is
never set on the whole pipeline, though it *is* set for individual
stages, on the assumption that any shader found in a cache is likely to
be found in Metal's own implicit cache.

In this implementation, shader stage compilation time includes any time
needed to build the `MTLComputePipelineState`s needed for vertex and
tessellation control shaders in tessellated pipelines.

This patch also changes compilation of the vertex stage
`MTLComputePipelineState`s in tessellated pipelines to be eager instead
of lazy. We really ought to have been doing this anyway, in order to
report pipeline failures at creation time instead of draw time. I'm not
happy, though, that we now pay the cost of all three pipeline states all
the time, instead of just the ones that are used.

This also gets rid of some fields of `MVKGraphicsPipeline` that were
only used during pipeline construction, which should save some memory,
particularly for apps that create lots of pipelines.
2023-07-10 18:25:03 -07:00
Antarctic Coder
6bca44c612 Added MSL Version 3.1 for switch case
In this commit, I've added support for Xcode 15, and added a case for MSL version 3.1. I added this because I noticed xcode was throwing some warnings about an unhandled switch case.
2023-07-05 09:47:38 -04:00
Chip Davis
4e3ac69305 Support the VK_EXT_calibrated_timestamps extension.
This extension has a direct Metal equivalent in the
`-[MTLDevice sampleTimestamps:gpuTimestamp:]` method. However, that
method returns CPU timestamps in the Mach absolute time domain, which is
*not* that of `CLOCK_MONOTONIC_RAW` but of `CLOCK_UPTIME_RAW`. The
function that corresponds to `CLOCK_MONOTONIC_RAW` is
`mach_continuous_time()`. Therefore, this implementation uses the
`mach_continuous_time()` function for the CPU timestamp. Perhaps we
should lobby the WG for `VK_TIME_DOMAIN_CLOCK_UPTIME_RAW_EXT`.
2023-06-23 12:08:56 -07:00
Filip Lundgren
4540175a7d Fix mvkOSVersionIsAtLeast on Vision 2023-06-23 15:08:00 -04:00
Filip Lundgren
a756b8cd6e Fix MVK_MACOS_OR_IOS_OR_VISIONOS check 2023-06-23 10:31:22 -04:00
Filip Lundgren
d8b5a7df55 Merge branch 'main' of https://github.com/KhronosGroup/MoltenVK into visionOS 2023-06-23 10:29:57 -04:00
Filip Lundgren
16990efeb1 Support building for visionOS
Note: Internal naming is xrOS, but publicly it should be referred to as visionOS
2023-06-23 10:25:05 -04:00
Antarctic Coder
c0705c8f7d Made some fixes for Deferred Operations
The changes are as follows:

* Moved the code around to fit with the ordering system
* Added a function to get available cpu cores
* Renamed variables with _ in front of them
* Added mutexes and lock guards for the getters and setters of the max concurrency and result variables
* Made max concurrency dynamic by returning 0 when the operation is finished
2023-06-20 10:19:29 -04:00
Bill Hollings
4893f78b29 Identify each unsupported device feature flag that the app attempts to be enable.
- Make MVKDevice::enableFeatures() functions into templates to pass struct type.
- Add mvkGetAddressOfFirstMember() to retrieve the address of the first member of
  a struct, taking into consideration whether the struct has a Vulkan pNext member.
- Add mvk::getTypeName() and mvk::getOrdinalSuffix() string functions.
2023-05-15 15:14:30 -04:00
Bill Hollings
5092330273 Support BC compression on iOS/tvOS, where available.
- Add MVK_XCODE_14_3 macro to compile for iOS/tvOS 16.4 and above.
- Add support for BC compression on iOS/tvOS 16.4 and above where supported.
- Consolidate MVKPixelFormats::modifyMTLFormatCapabilities(mtlDev)
  and centralize querying MTLDevice format methods for all platforms.
2023-04-12 11:50:09 -04:00
Bill Hollings
cd8d0c30bb Add support for VK_EXT_external_memory_host extension.
- To expose host memory page size, add mvkGetHostMemoryPageSize() and
  MVKPhysicalDeviceMetalFeatures::hostMemoryPageSize.
- MVKPhysicalDevice::getProperties() sort EXT property structs alphabetically (unrelated).
- MVKExtensions.def fix alignment in OS versions (unrelated).
2023-03-19 22:53:36 -04:00
Bill Hollings
12592abbc9 Update copyright notices to year 2023. 2023-01-13 12:19:37 -05:00
Bill Hollings
682906976d Fix linking issues with dynamic Vulkan functions.
- Ensure Vulkan public symbols are not stripped from the library when
  statically linked to an app that calls all Vulkan functions dynamically.
- Per Vulkan 1.2 spec, support calling vkGetInstanceProcAddr() with a
  null instance, when vkGetInstanceProcAddr itself is the function name.
- Replace uses of strcmp() with mvkStringsAreEqual() to protect against
  null pointers, and provide a direct bool output (unrelated cleanup).
2023-01-10 07:22:05 -05:00
sean
83c0ca60fb
Add support for KHR_buffer_device_address 2022-06-16 17:32:25 +02:00
Bill Hollings
16408fd6ae Remove logged warning if MoltenVK does not support VkApplicationInfo::apiVersion value.
Update MoltenVK version to 1.1.8.
Minor spelling fixes in comments.
2022-02-09 13:36:08 -05:00
Nikita Fediuchin
4efb90b3c1 Update license year 2022-02-04 13:33:27 +02:00
Bill Hollings
52568efb27 Optionally hide additional static Vulkan linkage symbols.
Move the aliasing of promoted function pointers to the function pointer
lookup collection, because non-global function alias symbols are not
available in separately compiled object file.

Add public aliased Vulkan extension functions that were promoted to 1.1 to
the public symbols that are hidden when MVK_HIDE_VULKAN_SYMBOLS is enabled.

Add functions from the private VK_MVK_moltenvk extension that depend on
Vulkan object handles to the public symbols that are hidden when
MVK_HIDE_VULKAN_SYMBOLS is enabled, to discourage their use by apps that
are using the Vulkan Loader and Layers, because they are not supported by
the Vulkan Loader and Layers.

Update VK_MVK_MOLTENVK_SPEC_VERSION to version 33.
2021-12-18 14:00:37 -05:00
Nikita Fediuchin
6ac92fbacf Clean up MVKLogging
* Replaced ASL levels with MVKConfigLogLevel.
* Moved MVKLogging.h to Utility/ directory.
* Added MVKConfigLogLevel Warning and Debug levels.
2021-11-25 09:47:43 +02:00
Bill Hollings
5de7f5551c Support building MoltenVK with static Vulkan linkage symbols hidden.
Add build environment variable MVK_HIDE_VULKAN_SYMBOLS. to allow MoltenVK
to be built with static Vulkan API symbols hidden, to avoid library linking
conflicts when bound to a Vulkan Loader that also exports identical symbols.

The default value of MVK_HIDE_VULKAN_SYMBOLS is 0,
meaning Vulkan static symbols are exposed by default.

Add MVK_PUBLIC_VULKAN_SYMBOL directive to mark each Vulkan call symbols
for exporting or hiding.

Update the MoltenVK Xcode project to add the MVK_HIDE_VULKAN_SYMBOLS build
setting, and set the ENABLE_TESTABILITY build setting to NO, because it
conflicts with stripping symbols.

Update MoltenVK version to 1.1.7.
2021-11-17 18:22:33 -05:00
Nikita Fediuchin
c8813898cf Add MVKLogWarning, apiVersion warning
* Added MVKLogWarning logger, and updated header comments.
* Added greater _appInfo.apiVersion  than MoltenVK version warning.
2021-10-04 12:03:36 +03:00
Bill Hollings
6b502bcb60 Upgrade projects to Xcode 13 SDK APIs.
Add MVK_XCODE_13 code macro.
Support MTLLanguageVersion2_4 enum value.
MoltenVKPackaging project add DISABLE_MANUAL_TARGET_ORDER_BUILD_WARNING
build setting to suppress build warnings about using manual build orders.
2021-06-14 16:24:32 -04:00
Bill Hollings
cfc2556c31 Fix use of VkFlags in MVKConfiguration enumerated values.
MVKConfigLogLevel, MVKConfigTraceVulkanCalls, and MVKConfigAutoGPUCaptureScope
do not need to be VkFlags, since they aren't bitwise flags.

MVK_SET_FROM_ENV_OR_BUILD_INT32 supports setting enumerated values.
2021-03-10 09:26:59 -05:00
Bill Hollings
8e610a43a8 Support configuring supported Vulkan API version.
Add MVKConfiguration::apiVersionToAdvertise and MVK_CONFIG_API_VERSION_TO_ADVERTISE
env var to configure MoltenVK to advertise a particular Vulkan version.

Advertise MVKConfiguration::apiVersionToAdvertise in:
  vkEnumerateInstanceVersion()
  vkGetPhysicalDeviceProperties()
  vkEnumerateInstanceLayerProperties()
  vkEnumerateDeviceLayerProperties()

Add MVKConfiguration::advertiseExtensions and MVK_CONFIG_ADVERTISE_EXTENSIONS
env var to configure MoltenVK to not advertise support for any Vulkan  extensions.
Refactor population of MVKConfiguration from environment variables to better
support validating and baking config values set by app.
Update MoltenVK version to 1.1.3.
Update VK_MVK_MOLTENVK_SPEC_VERSION to 31.
2021-02-24 16:32:14 -05:00
Bill Hollings
4675481a06 Redefine derivations of MVK_APPLE_SILICON, MVK_MACOS_APPLE_SILICON, and MVK_XCODE_12.
Derive MVK_APPLE_SILICON from target CPU.
Derive MVK_MACOS_APPLE_SILICON from target CPU and macOS platform.
Derive MVK_XCODE_12 from macOS and iOS SDK versions.
Test for simulator on non-Apple GPU using MVK_OS_SIMULATOR && !MVK_APPLE_SILICON.
2021-02-20 09:33:32 -05:00
Bill Hollings
e1b3585413 Add MVK_APPLE_SILICON macro definition.
Use MVK_APPLE_SILICON instead of
MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON or
MVK_MACOS_APPLE_SILICON || MVK_IOS_OR_TVOS.
2021-01-21 16:53:17 -05:00
Bill Hollings
015031c955 Update copyright notices to year 2021 and Xcode build settings check to Xcode 12.3. 2021-01-21 13:37:07 -05:00
Bill Hollings
7f62362db3 Fixes from review for Mac Catalyst on macOS 11.0+.
MVKPixelFormats revert testing for stencil feedback and add Mac Catalyst test.
Revert mvkOSVersionIsAtLeast(mac, ios) to remove test for Mac Catalyst version.
MVKRenderPass revert testing for MTLStorageModeMemoryless for iOS.
2020-12-02 16:22:38 -05:00
Bill Hollings
1ec58c9a92 Support building for Mac Catalyst on macOS 11.0+.
Define MVK_MACCAT build macro and use it to conditionally compile code to align
with build features and capabilities of Mac Catalyst platform on macOS 11.0+.
Treat Mac Catalyst as minor variation of macOS 11.0.
Update documentation.

Currently only support Mac Catalyst on macOS 11.0+, to avoid complexities of
deselecting iOS features and capabilities for Mac Catalyst on previous macOS versions.

Mac Catalyst (and Simulators) require use of XCFrameworks.
Currently unable to generate a dylib for Mac Catalyst.
2020-12-01 19:26:15 -05:00
Chip Davis
d73017f4db MVKDevice: Set properties for Apple Silicon GPUs on macOS. 2020-10-28 19:35:24 -05:00
Chip Davis
2c40e39699 Fix aliases on ARM64.
The semicolon is the comment character in ARM64 assembly. Just put the
alias symbol definition on another line.
2020-09-10 20:21:02 -05:00
Chip Davis
78963db6cc Export core names of Vulkan 1.1 calls promoted from extensions.
The functions are now defined under their core names. To avoid code
bloat, I've defined the suffixed names as aliases of the core names.
Both symbols will be globally defined with the same value, and in the
dylib both will be exported.

Fix the default API version when none is given. Zero is the same as
`VK_API_VERSION_1_0`. Prior to this, we were overwriting it with zero if
no app info were given, or if it were zero in the app info. It wasn't
important before, but now that we gate API availability on maximum
Vulkan version, we need to make sure it's a valid version.
2020-09-08 13:22:17 -05:00
Bill Hollings
72c4ba1118 Remove unneeded MVK_IOS_SIMULATOR and MVK_TVOS_SIMULATOR macros. 2020-07-17 22:18:08 -04:00
Bill Hollings
40d3485cec Remove unneeded switch default for MTLLanguageVersion.
Minor doc fixes from PR review.
2020-06-24 17:04:30 -04:00
Bill Hollings
7910f43867 MVKPixelFormats reduce some MTLPixelFormat capabilities for simulators.
Add MVK_IOS_SIMULATOR and MVK_TVOS_SIMULATOR macros.
MVKPixelFormats add disableMTLPixelFormatCapabilities().
MVKPixelFormats add disableAllMTLPixelFormatCapabilities().
2020-06-22 23:52:51 -04:00
Bill Hollings
72517a2474 Cleanup tvOS build warnings.
Use platform macros to conditionally build outstanding tvOS code.
Log validation error message when tvOS code doesn't support expected functionality.
2020-06-22 21:55:51 -04:00
Bill Hollings
37e8e3182c Redefine MoltenVK platform macros in terms of newer Apple target conditionals. 2020-06-22 21:37:30 -04:00
Aman Gupta
b8fb92a9e3 oops forgot this return 2020-06-18 16:36:45 -07:00
Aman Gupta
bdff52283d remove !MVK_TVOS usage 2020-06-17 17:14:31 -07:00
Aman Gupta
e847fb38e9 fix some missing return warnings 2020-06-17 14:46:06 -07:00
Aman Gupta
7392e23db2 unncessary change in the diff 2020-06-17 10:30:41 -07:00
Aman Gupta
a0e357fab5 Merge remote-tracking branch 'upstream/master' into tvos 2020-06-17 10:05:40 -07:00
Aman Gupta
9694169da6 split out MVK_IOS_OR_TVOS 2020-06-15 16:36:05 -07:00
Aman Gupta
b250212c6f add MVK_TVOS and start conditionalizing build failures 2020-06-15 16:21:13 -07:00