2929 Commits

Author SHA1 Message Date
Bill Hollings
3a77f4ea97 Fixes to determination of VkPhysicalDeviceLimits::timestampPeriod.
- On Apple GPUs, set timestampPeriod to 1.0.
- On non-Apple GPUs, calculate timestampPeriod each time it is retrieved.
- On older devices that do not support GPU timestamps, use nanosecond
  CPU timestamps to be consistent with timestampPeriod of 1.0.
- Change MVKConfiguration::timestampPeriodLowPassAlpha and environment
  variable MVK_CONFIG_TIMESTAMP_PERIOD_LOWPASS_ALPHA to 1.0, to use
  only latest value by default.
- Add build-time verification that MVKConfigMembers.def
  includes all members of MVKConfiguration (unrelated).
2023-10-17 00:45:56 -04:00
Bill Hollings
107cf2c34e
Merge pull request #2042 from billhollings/VK_EXT_extended_dynamic_state-fixes
Fixes for VK_EXT_extended_dynamic_state.
2023-10-16 22:25:05 -04:00
Bill Hollings
d706ed0a63 Fixes for VK_EXT_extended_dynamic_state.
- MVKPipeline only work around zero stride if stride is static.
- Ensure dynamic vertex stride is not enabled on builds before Xcode 15.
- Add MVKRenderStateType::LineWidth for track all default options (unrelated).
2023-10-16 20:52:23 -04:00
Bill Hollings
61b8712178
Merge pull request #2036 from billhollings/VK_EXT_extended_dynamic_state
Add support for VK_EXT_extended_dynamic_state & VK_EXT_extended_dynamic_state2 extensions.
2023-10-11 17:37:11 -04:00
Bill Hollings
eb7cfa1006 Fixes based on VK_EXT_extended_dynamic_state code review.
- Fix runtime failure on Metal versions that don't support dynamic attribute stride.
- Add MVKCommandEncoder::encodeVertexAttributeBuffer() consolidation function.
- Remove unnecessary validations that will be caught by Vulkan validation layers.
- To reduce memory, remove command class and pools for rendering commands that
  are not supported, and perform no validation.
- Document extension conformance limitations in MoltenVK_Runtime_UserGuide.md.
2023-10-11 11:37:50 -04:00
Bill Hollings
ee271b34fc
Merge pull request #2037 from billhollings/fix-debug-msg-deadlock
Fix deadlock when reporting debug message on MVKInstance destruction.
2023-10-10 16:45:11 -04:00
Bill Hollings
659b1cecd7 VK_EXT_extended_dynamic_state fix build fail before Xcode 15. 2023-10-10 15:14:58 -04:00
Bill Hollings
0584aa0083 Fix deadlock when reporting debug message on MVKInstance destruction. 2023-10-10 15:02:06 -04:00
Bill Hollings
f4423428e3 Add support for VK_EXT_extended_dynamic_state2 extension.
- Add MVKPipelineCommandEncoderState subclasses
  MVKGraphicsPipelineCommandEncoderState & MVKComputePipelineCommandEncoderState,
  track patch control points in MVKGraphicsPipelineCommandEncoderState,
  and add getGraphicsPipeline() & getComputePipeline() to simplify casting.
- Rename MVKRasterizingCommandEncoderState to MVKRenderingCommandEncoderState,
  and MVKCommandEncoder::_rasterizingState to _renderingState.
- Rename MVKCmdRenderPass.h/mm to MVKCmdRendering.h/mm.
- Move MVKCmdExecuteCommands from MVKCmdRenderPass.h/mm to MVKCmdPipeline.h/mm.
- While working on vkCmdSetLogicOpEXT(), add support for
  vkCmdSetLogicOpEnableEXT() from VK_EXT_extended_dynamic_state3.
2023-10-10 12:19:15 -04:00
Bill Hollings
3c75e114dd Add support for VK_EXT_extended_dynamic_state extension.
- Add MVKRasterizingCommandEncoderState to consolidate handling
  of static and dynamic rasterizing states in a consistent manner.
- Rework MVKDepthStencilCommandEncoderState to consolidate handling
  of static and dynamic depth states in a consistent manner.
- MVKMTLDepthStencilDescriptorData clean up content setting, and struct layout.
- Add MVKRenderStateType to enumerate render state types.
- Add MVKRenderStateFlags to track binary info about states (enabled, dirty, etc).
- Add MVKMTLBufferBinding::stride.
- Add MVKPhysicalDeviceMetalFeatures::dynamicVertexStride.
- Set MVKPhysicalDeviceMetalFeatures::vertexStrideAlignment
  to 1 for Apple5+ GPUs (unrelated).
- Set VkPhysicalDeviceLimits::maxVertexInputBindingStride
  to unlimited for Apple2+ GPUs (unrelated).
- Add mvkVkRect2DFromMTLScissorRect() and simplify
  mvkMTLViewportFromVkViewport() and mvkMTLScissorRectFromVkRect2D().
- MVKFoundation:
  - Add mvkEnableAllFlags() and mvkDisableAllFlags().
  - Improve performance of mvkClear(), mvkCopy() & mvkAreEqual()
    when content is a single simple primitive type (unrelated).
  - Declare more functions as static constexpr (unrelated).
2023-10-05 17:33:01 -04:00
Bill Hollings
a06827c6fb Merge branch 'main' of https://github.com/billhollings/MoltenVK into VK_EXT_extended_dynamic_state 2023-10-03 13:00:28 -04:00
Bill Hollings
568cc3acc0
Merge pull request #2025 from etang-cw/MiscCleanup
Misc Cleanup
2023-09-28 16:44:29 -04:00
Evan Tang
27f4f6a6a0 Use MVKArrayRef<const T>, not const MVKArrayRef<T>
It's very easy to accidentally un-const a `const MVKArrayRef<T>`, since ArrayRefs are meant to be passed by value
2023-09-28 14:19:25 -05:00
Evan Tang
4ba3f335b4 MVKArrayRef cleanup
Make everything constexpr, remove direct access to members
2023-09-28 14:18:27 -05:00
Evan Tang
89195dc725 Remove count from mvkStringsAreEqual
It doesn't do anything, and we don't want anyone to think it does something
2023-09-26 23:48:16 -05:00
Evan Tang
aeae18d48b Remove getBaseObject
Nothing used it, and you should always be able to `static_cast<MVKBaseObject*>` for any object without a crazy inheritance tree
2023-09-26 23:48:15 -05:00
Evan Tang
5a216ab1f8 Refcounting cleanup
- Use relaxed atomics where possible
- Calling operator= on a refcounted object should not reinitialize the refcount
2023-09-26 23:47:44 -05:00
Bill Hollings
7f97fe2354 Merge branch 'KHR_extended_dynamic_state' of https://github.com/spnda/MoltenVK into VK_EXT_extended_dynamic_state 2023-09-19 17:36:05 -04:00
Bill Hollings
a7989c221f
Merge pull request #2023 from billhollings/promote-VK_EXT_private_data
Promote VK_EXT_private_data functions to Vulkan 1.3, and remove stubs.
2023-09-19 17:35:13 -04:00
Bill Hollings
2c3dc6415a Promote VK_EXT_private_data functions to Vulkan 1.3, and remove stubs. 2023-09-19 16:29:30 -04:00
Bill Hollings
6a4271c85f
Merge pull request #2021 from billhollings/VK_KHR_synchronization2
Add support for extension VK_KHR_synchronization2
2023-09-19 16:08:38 -04:00
Bill Hollings
6127918a32 Add support for extension VK_KHR_synchronization2.
- MVKPhysicalDevice add support for VkPhysicalDeviceSynchronization2Features.
- Pass sync2 structs to MVKPipelineBarrier, MVKCmdPipelineBarrier, MVKCmdSetEvent,
  MVKCmdResetEvent, MVKCmdWaitEvents, MVKRenderPass, MVKQueue & MVKQueueSubmission.
- Replace use of VkPipelineStageFlags & VkAccessFlags
  with VkPipelineStageFlags2 & VkAccessFlags2.
- Add stage masks to MVKPipelineBarrier, and redefine apply*MemoryBarrier()
  functions to remove separately passing stage masks.
- Add MVKSemaphoreSubmitInfo to track semaphores in MVKQueueSubmission.
- Add MVKCommandBufferSubmitInfo to track command buffers
  in MVKQueueCommandBufferSubmission.
- Add MVKSubpassDependency to combine VkSubpassDependency & VkMemoryBarrier2 in MVKRenderPass.
- Remove abstract MVKCmdSetResetEvent superclass.
- Streamline code in MVKMTLFunction::operator= (unrelated).
2023-09-19 14:20:55 -04:00
Bill Hollings
aed91cb563
Merge pull request #2020 from billhollings/incomplete-presentation-workaround-fix
Rework workaround to force incomplete CAMetalDrawable presentations to complete.
2023-09-15 19:23:31 -04:00
Bill Hollings
f0cb31a12b Rework workaround to force incomplete CAMetalDrawable presentations to complete.
- To force any incomplete CAMetalDrawable presentations to complete,
  don't force the creation of another transient drawable, as this can
  stall the creation of future drawables. Instead, when a swapchain
  is destroyed, or replaced by a new swapchain, set the CAMetalLayer
  drawableSize, which will force presentation completion.
- Add presentation completion handler in command buffer scheduling
  callback, move marking available to presentation completion handler,
  and minimize mutex locking.
- MVKQueue::waitIdle() remove wait for swapchain presentations,
  and remove callbacks to MVKQueue from drawable completions.
- MVKQueue::submit() don't bypass submitting a misconfigured submission,
  so that semaphores and fences will be signalled, and ensure misconfigured
  submissions are well behaved.
- Add MVKSwapchain::getCAMetalLayer() to streamline layer access (unrelated).
2023-09-15 09:54:48 -04:00
Bill Hollings
8f4619a788
Merge pull request #2018 from billhollings/depth-blit-msl
Fix MSL code used in vkCmdBlitImage() on depth-stencil formats.
2023-09-12 19:38:15 -04:00
Bill Hollings
9c206ecc79 Fix MSL code used in vkCmdBlitImage() on depth-stencil formats. 2023-09-12 16:44:33 -04:00
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