2902 Commits

Author SHA1 Message Date
Bill Hollings
54dad691e0
Merge pull request #2017 from billhollings/config-timestampPeriod-lowpass
Add configurable lowpass filter for VkPhysicalDeviceLimits::timestampPeriod.
2023-09-12 16:21:56 -04: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
a2d5b25a5c
Merge pull request #2015 from billhollings/mtlcmdbuff-retain-objs
Ensure objects retained for life of MTLCommandBuffer.
2023-09-11 11:56:41 -04:00
Bill Hollings
0ee15222c8 Ensure objects retained for life of MTLCommandBuffer.
- vkCmdBlitImage() ensure swizzle texture view is retained for life
  of MTLCommandBuffer.
- vkQueuePresentKHR() use MTLCommandBuffer that retains references.
- Update MoltenVK version to 1.2.6.
2023-09-08 20:46:28 -04:00
Bill Hollings
473ea0c2f1
Merge pull request #2008 from danginsburg/issue_2006_2
Fix crash in Dota 2 on macOS < 10.15 - closes #2006
2023-09-07 11:16:46 -04:00
Bill Hollings
ea5bf37e3b
Merge pull request #2012 from billhollings/fix-drwbl-invalid-format
Guard against CAMetalDrawable with invalid pixel format.
2023-09-07 10:37: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
781a834663
Merge pull request #2009 from billhollings/workaround-presentation-stalls
Improve behavior of swapchain image presentation stalls caused by Metal regression.
2023-09-06 14:19:24 -04:00
Bill Hollings
a28437d8f2 Updates to code review on swapchain image presentation improvement.
- Fix failure building on Xcode 14.
- Track frame interval statistics, regardless of whether performance
  tracking is enabled.
- Determine wait time for swapchain presentations from frame intervals.
- MVKSwapchain call markFrameInterval() from within mutex lock.
- MVKDevice rename addActivityPerformance() to addPerformanceInterval()
  and addActivityByteCount() to addPerformanceByteCount().
- Add documentation about performance being measured in milliseconds.
2023-09-06 09:56:33 -04:00
Bill Hollings
9f64faadbc Improve behavior of swapchain image presentation stalls caused by Metal regression.
In a recent Metal regression, Metal sometimes does not trigger the
[CAMetalDrawable addPresentedHandler:] callback on the final few (1-3)
CAMetalDrawable presentations, and retains internal memory associated
with these CAMetalDrawables. This does not occur for any CAMetalDrawable
presentations prior to those final few.

Most apps typically don't care much what happens after the last few
CAMetalDrawables are presented, and typically end shortly after that.

However, for some apps, such as Vulkan CTS WSI tests, which serially create
potentially hundreds, or thousands, of CAMetalLayers and MTLDevices,these
retained device memory allocations can pile up and cause the CTS WSI tests
to stall, block, or crash.

This issue has proven very difficult to debug, or replicate in incrementally
controlled environments. It appears consistently in some scenarios, and never
in other, almost identical scenarios.

For example, the MoltenVK Cube demo consistently runs without encountering
this issue, but CTS WSI test dEQP-VK.wsi.macos.swapchain.render.basic
consistently triggers the issue. Both apps run almost identical Vulkan
command paths, and identical swapchain image presentation paths, and
result in GPU captures that have identical swapchain image presentations.

We may ultimately have to wait for Apple to fix the core issue, but this
update includes workarounds that helps in some cases. During vkQueueWaitIdle()
and vkDeviceWaitIdle(), wait a short while for any in-flight swapchain image
presentations to finish, and attempt to force completion by calling
MVKPresentableSwapchainImage::forcePresentationCompletion(), which releases
the current CAMetalDrawable, and attempts to retrieve a new one, to trigger
the callback on the current CAMetalDrawable.

In exploring possible work-arounds for this issue, this update adds significant
structural improvements in the handling of swapchains, and quite a bit of new
performance and logging functionality that is useful for debugging purposes.

- Add several additional performance trackers, available via logging,
  or the mvk_private_api.h API.
- Rename MVKPerformanceTracker members, and refactor performance result
  collection, to support tracking and logging memory use, or other measurements,
  in addition to just durations.
- Redefine MVKQueuePerformance to add tracking separate performance metrics for
  MTLCommandBuffer retrieval, encoding, and execution, plus swapchain presentation.
- Add MVKDevicePerformance as part of MVKPerformanceStatistics to track device
  information, including GPU device memory allocated, and update device memory
  results whenever performance content is requested.
- Add MVKConfigActivityPerformanceLoggingStyle::
  MVK_CONFIG_ACTIVITY_PERFORMANCE_LOGGING_STYLE_DEVICE_LIFETIME_ACCUMULATE
  to accumulate performance and memory results across multiple serial
  invocations of VkDevices, during the lifetime of the app process. This
  is useful for accumulating performance results across multiple CTS tests.
- Log destruction of VkDevice, VkPhysicalDevice, and VkInstance, to bookend
  the corresponding logs performed upon their creation.
- Include consumed GPU memory in log when VkPhysicalDevice is destroyed.
- Add mvkGetAvailableMTLDevicesArray() to support consistency when retrieving
  MTLDevices available on the system.
- Add mvkVkCommandName() to generically map command use to a command name.
- MVKDevice:
    - Support MTLPhysicalDevice.recommendedMaxWorkingSetSize on iOS & tvOS.
    - Include available and consumed GPU memory in log of GPU device at
      VkInstance creation time.
- MVKQueue:
    - Add handleMTLCommandBufferError() to handle errors for all
      MTLCommandBuffer executions.
    - Track time to retrieve a MTLCommandBuffer.
    - If MTLCommandBuffer could not be retrieved during queue submission,
      report error, signal queue submission completion, and return
      VK_ERROR_OUT_OF_POOL_MEMORY.
    - waitIdle() simplify to use [MTLCommandBuffer waitUntilCompleted],
      plus also wait for in-flight presentations to complete, and attempt
      to force them to complete if they are stuck.
- MVKPresentableSwapchainImage:
    - Don't track presenting MTLCommandBuffer.
    - Add limit on number of attempts to retrieve a drawable, and report
      VK_ERROR_OUT_OF_POOL_MEMORY if drawable cannot be retrieved.
    - Return VkResult from acquireAndSignalWhenAvailable() to notify upstream
      if MTLCommandBuffer could not be created.
    - Track presentation time.
	- Notify MVKQueue when presentation has completed.
	- Add forcePresentationCompletion(), which releases the current
	  CAMetalDrawable, and attempts to retrieve a new one, to trigger the
	  callback on the current CAMetalDrawable. Called when a swapchain is
	  destroyed, or by queue if waiting for presentation to complete stalls,
	- If destroyed while in flight, stop tracking swapchain and
	  don't notify when presentation completes.
- MVKSwapchain:
    - Track active swapchain in MVKSurface to check oldSwapchain
    - Track MVKSurface to access layer and detect lost surface.
    - Don't track layer and layer observer, since MVKSurface handles these.
    - On destruction, wait until all in-flight presentable images have returned.
    - Remove empty and unused releaseUndisplayedSurfaces() function.
- MVKSurface:
	- Consolidate constructors into initLayer() function.
    - Update logic to test for valid layer and to set up layer observer.
- MVKSemaphoreImpl:
    - Add getReservationCount()
- MVKBaseObject:
    - Add reportResult() and reportWarning() functions to support logging
      and reporting Vulkan results that are not actual errors.
- Rename MVKCommandUse::kMVKCommandUseEndCommandBuffer to
  kMVKCommandUseBeginCommandBuffer, since that's where it is used.
- Update MVK_CONFIGURATION_API_VERSION and MVK_PRIVATE_API_VERSION to 38.
- Cube Demo support running a maximum number of frames.
2023-09-02 08:51:36 -04:00
Dan Ginsburg
6acdd9fb91 Fix crash in Dota 2 on macOS < 10.15 - closes #2006 2023-08-31 09:13:26 -04:00
Bill Hollings
fd418aa7fe
Merge pull request #2001 from billhollings/fix-unbound-vtx-attr-buff
Fix rare case where vertex attribute buffers are not bound to Metal.
2023-08-24 10:47:26 -04:00
Bill Hollings
7910083ffa Fix rare case where vertex attribute buffers are not bound to Metal.
In the rare case where vertex attribute buffers are bound to MVKCommandEncoder,
are not used by first pipeline, but are used by a subsequent pipeline, and no
other bindings are changed, the MVKResourcesCommandEncoderState will not appear
to be dirty to the second pipeline, and the buffer will not be bound to Metal.

When reverting a binding to dirty if it is not used by a pipeline, also revert
the enclosing MVKResourcesCommandEncoderState to dirty state.

Update MoltenVK to version 1.2.6 (unrelated).
2023-08-23 14:14:15 -04:00
Bill Hollings
02a8c011a8
Merge pull request #1997 from billhollings/fix-Intel-timestampPeriod
Fix VkPhysicalDeviceLimits::timestampPeriod calculations on Intel GPU.
2023-08-17 19:01:54 -04:00
Bill Hollings
530bde199b Fix VkPhysicalDeviceLimits::timestampPeriod calculations on Intel GPU.
- Guard against Intel returning zero values for CPU & GPU timestamps.
- Apply lowpass filter on timestampPeriod updates, to avoid wild temporary
  changes, particularly at startup before GPU has been really exercised.
2023-08-17 17:47:39 -04:00
Bill Hollings
b3c9f867ee
Merge pull request #1994 from billhollings/sdk-1.3.261
Update dependency libraries to match Vulkan SDK 1.3.261.
2023-08-15 18:37:35 -04:00
Bill Hollings
4fe8811665 Update dependency libraries to match Vulkan SDK 1.3.261.
- In MoltenVK Xcode projects, set iOS & tvOS deployment targets to 12.0,
  to avoid warnings while building MoltenVK.
- Add DYLD_LIBRARY_PATH to runcts script, to ensure Vulkan and MoltenVK
  libraries are found during CTS runs.
- Update Whats_New.md and MoltenVK_Runtime_UserGuide.md documents.
2023-08-15 16:03:31 -04:00
Bill Hollings
47840b9beb
Merge pull request #1993 from billhollings/fix-sim-buff-align
Ensure Xcode simulator always uses 256B buffer alignment.
2023-08-14 10:11:34 -04:00
Bill Hollings
8518a4f8db
Merge pull request #1992 from billhollings/fix-submit-sync-delay
Fix sync delay between calls to vkQueueSubmit() on non-Apple-Silicon devices.
2023-08-14 10:10:52 -04:00
Bill Hollings
41a5a97fef Ensure Xcode simulator always uses 256B buffer alignment.
Xcode simulator always requires 256B buffer alignment, even when running
on Apple Silicon. Previously, it was assumed that Apple Silicon would use
it's native 16B buffer alignment.
2023-08-13 20:14:20 -04:00
Bill Hollings
dd31587337 Fix sync delay between calls to vkQueueSubmit() on non-Apple-Silicon devices.
The [MTLDevice sampleTimestamps:gpuTimestamp:] function turns out to be
synchronized with other queue activities, and can block GPU execution
if it is called between MTLCommandBuffer submissions. On non-Apple-Silicon
devices, it was called before and after every vkQueueSubmit() submission,
to track the correlation between GPU and CPU timestamps, and was delaying
the start of GPU work on the next submission (on Apple Silicon, both
CPU & GPU timestamps are specified in nanoseconds, and the call was bypassed).

Move timestamp correlation from vkQueueSubmit() to
vkGetPhysicalDeviceProperties(), where it is used to update
VkPhysicalDeviceLimits::timestampPeriod on non-Apple-Silicon devices.

Delegate MVKPhysicalDevice::getProperties(VkPhysicalDeviceProperties2*)
to MVKPhysicalDevice::getProperties(VkPhysicalDeviceProperties*), plus
minimize wasted effort if pNext is empty (unrelated).

Move the declaration of several MVKPhysicalDevice member structs to
potentially reduce member spacing (unrelated).
2023-08-12 13:32:28 -04:00
Bill Hollings
7cb6096321
Merge pull request #1982 from stefand/main
Don't fetch a submodule if the commit is already known
2023-07-31 11:40:26 -04:00
Stefan Dösinger
f7e0d7db3e Don't fetch a submodule if the commit is already known
This allows rebuilding without an internet connection and avoids random
build failures on flaky connections.
2023-07-28 16:24:46 +03:00
Bill Hollings
d9b32e0c75
Merge pull request #1981 from billhollings/fix-bad-access-regression
Fix bad access regression to prematurely-deallocated MTLFunction.
2023-07-19 22:32:53 -04:00
Bill Hollings
5294c19687 Fix bad access regression to prematurely-deallocated MTLFunction.
When compiling tessellation vertex shaders, MVKGraphicsPipeline
pass array of MVKMTLFunction instead of MTLFunctions to retain
MTLFunctions for duration of processing.
2023-07-19 18:53:41 -04:00
Bill Hollings
cf531d04de
Merge pull request #1980 from mbechard/main
Fix regression caused by #1922
2023-07-19 15:30:22 -04:00
Malcolm Bechard's MacMini M1
817038e8d8 Fix regression caused by #1922
Needed to complete fix for #1874

We can't wait until getMTLComputeEncoder() is called to dirty the state,
because this call will be avoided by dirty checks themselves.
Those checks are comparing against leftover and now incorrect state since
the previous encoder has already ended.
It needs to be dirtied on encoder end.
2023-07-19 14:15:05 -04:00
Bill Hollings
42fa5117d9
Merge pull request #1977 from billhollings/drop-support-xcode-11
Drop official support for using Xcode 11 to build MoltenVK.
2023-07-12 18:43:32 -04:00
Bill Hollings
f6ba6f2dcc Drop official support for using Xcode 11 to build MoltenVK.
- Remove Xcode 11 build from GitHub CI.
- Leave MVK_XCODE_12 guards in place to allow devs to possibly continue to
  attempt to build existing MoltenVK code using Xcode 11, even though it's
  not officially supported. Such devs may have to add their own additional
  MVK_XCODE_12 guards for any Xcode 12 API features added after this change.
2023-07-12 17:32:58 -04:00
Bill Hollings
97eb80bd39
Merge pull request #1976 from billhollings/nginetechnologies-visionOS
Support building for visionOS platform
2023-07-12 12:03:15 -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
Bill Hollings
dff64e956c
Merge pull request #1972 from cdavis5e/incremental-present
Support the `VK_KHR_incremental_present` extension.
2023-07-11 08:50:17 -04:00
Bill Hollings
1728f7fd81
Merge pull request #1968 from cdavis5e/pipeline-creation-feedback
Support the `VK_EXT_pipeline_creation_feedback` extension.
2023-07-11 08:25:13 -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
Bill Hollings
ca8e060416
Merge pull request #1969 from cdavis5e/sonoma-depth-array-lod
MVKDevice: Don't enable sample LoD depth array workaround for macOS S…
2023-07-10 11:50:24 -04:00
Chip Davis
3914b0f07d Support the VK_KHR_incremental_present extension.
This extension allows apps to provide a hint to the presentation engine
indicating which parts of the surface need updating. To provide this
hint, we call `-[CALayer setNeedsDisplayInRect:]`, which indicates that
only the given rectangle needs updating.

I'm not sure if this will have any effect, especially if
`CAMetalLayer.presentsWithTransaction` is `NO`. Luckily for us, this is
only a hint, and it is permissible for the presentation engine to do
nothing with the hint.

The tests don't work because they apparently can't handle
`VK_SUBOPTIMAL_KHR` being returned.
2023-07-10 01:05:18 -07:00
Chip Davis
21ac7443b0 MVKDevice: Don't enable sample LoD depth array workaround for macOS Sonoma and up.
Apple have indicated to me that they have fixed the bug. I've confirmed
this.
2023-07-07 14:05:32 -07:00
Bill Hollings
2db85ea060
Merge pull request #1966 from AntarticCoder/msl-3-1
Added Enum for MSL Version 3.1
2023-07-05 15:36:50 -04:00
Antarctic Coder
056dec80e6 Completed the support for MSL 3.1 enum
This commit adds some extra code that was needed to define to MSL 3.1 enum that was not included in the first commit. Based on PR: #1940
2023-07-05 13:20:59 -04: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
Bill Hollings
41dbd9d490
Merge pull request #1962 from billhollings/tri-fans
Add support for VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN.
2023-07-01 11:15:36 -04:00
Bill Hollings
27f68eb5ac
Merge pull request #1964 from billhollings/fix-unreachable-code
Fix unreachable code in MVKDeferredOperation::join().
2023-06-30 11:33:55 -04:00
Bill Hollings
c34bb54d48 Fix unreachable code in MVKDeferredOperation::join().
- Fix unreachable code in MVKDeferredOperation::join().
- Refactor code so deferred functions call back to MVKDeferredOperation
  instance to update current status, and deferred function execution
  returns result of individual thread execution.
- MVKDeferredOperation use MVKSmallVector for _functionParameters.
- MVKDeferredOperation use a single mutex lock.
- Add additional comments explaining design to developers of
  future extensions that use deferred operations.
2023-06-30 08:54:27 -04:00
Bill Hollings
e5d3939322 Add support for VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN.
To reduce complexity and repetitive copy-pasted spaghetti code,
the design approach here was to implement triangle fan conversion on
MVKCmdDrawIndexedIndirect, as the most general of the draw commands,
and then populate and invoke a synthetic MVKCmdDrawIndexedIndirect
command from the other draw commands.

- Rename pipeline factory shader cmdDrawIndexedIndirectMultiviewConvertBuffers()
  to cmdDrawIndexedIndirectConvertBuffers, and in addition to original support
  for modifying indirect content to support multiview, add support for
  converting triangle fan indirect content and indexes to triangle list.
- Modify MVKCmdDrawIndexedIndirect to track need to convert triangle fans
  to triangle list, and invoke kernel function when needed.
- Modify MVKCmdDraw, MVKCmdDrawIndexed, and MVKCmdDrawIndirect to populate
  and invoke a synthetic MVKCmdDrawIndexedIndirect command to convert triangle
  fans to triangle lists.
- Add pipeline factory shader cmdDrawIndirectPopulateIndexes() to convert
  non-indexed indirect content to indexed indirect content.
- MVKCmdDrawIndexedIndirect add support for zero divisor vertex buffers
  potentially coming from MVKCmdDraw and MVKCmdDrawIndexed.

- Rename pipeline factory shader cmdDrawIndexedIndirectConvertBuffers()
  to cmdDrawIndexedIndirectTessConvertBuffers() so it will be invoked from
  MVKCommandEncodingPool::getCmdDrawIndirectTessConvertBuffersMTLComputePipelineState()
  (unrelated).
2023-06-28 00:01:12 -04:00
Bill Hollings
96204ada46
Merge pull request #1961 from cdavis5e/legacy-subgroup
Support `VK_EXT_shader_subgroup_ballot` and `VK_EXT_shader_subgroup_vote`.
2023-06-26 18:38:30 -04:00
Bill Hollings
c85507b996
Merge pull request #1960 from cdavis5e/shader-non-semantic-info
Advertise the `VK_KHR_shader_non_semantic_info` extension.
2023-06-26 17:20:41 -04:00
Chip Davis
b74feb7c77 Support VK_EXT_shader_subgroup_ballot and VK_EXT_shader_subgroup_vote.
Update SPIRV-Cross to pull in the needed support for these extensions.
2023-06-26 13:40:34 -07:00
Bill Hollings
714781ebf6
Merge pull request #1958 from cdavis5e/calibrated-timestamps
Support the `VK_EXT_calibrated_timestamps` extension.
2023-06-26 16:12:03 -04:00