Fix issue where push constants contain a buffer address, but no descriptor
resources are encoded, resulting in addressed buffer not resident in GPU.
- Add MVKGPUAddressableBuffersCommandEncoderState to track when the
GPU-addressable buffer usage needs to be encoded, and only encode
them once per Metal renderpass.
- Set MVKGPUAddressableBuffersCommandEncoderState dirty whenever
a buffer is bound for a descriptor or a push constant.
Unrelated changes:
- MVKCommandEncoder::finalizeDrawState() reorder encoding of encoder
states to encode resource and push-constant encoder states together.
- Move getGraphicsPipeline() and getComputePipeline() to MVKCommandEncoder.
- MVKDevice Remove preallocation on _resources and _gpuAddressableBuffers.
- Align conditions for VkPhysicalDeviceVulkan12Features::bufferDeviceAddress
to those for VK_KHR_buffer_device_address/VK_EXT_buffer_device_address.
- MVKImage add functions to consolidate mapping plane indexes to memory bindings
to add safety in situation where one memory binding supports all planes.
- Update MoltenVK version to 1.2.8 (unrelated).
- Statically expose vkGetInstanceProcAddr(), even
when MVK_HIDE_VULKAN_SYMBOLS is enabled.
- To support Volk, link Cube demo dynamically to libMoltenVK.dylib
instead of statically to MoltenVK.xcframework.
- Document the name of the MoltenVK driver layer.
- Support future multiple string members in MVKConfiguration.
- Add static assert on number of string members in MVKConfigruation.
- Rename global mvkConfig() to getGlobalMVKConfig().
- Rename global mvkSetConfig() to mvkSetGlobalConfig().
- Remove unused mvkPrintSizeOf() macro. (unrelated).
- Trim trailing spaces from Markdown documents because
it causes double-spaces in some Markdown readers (unrelated).
- Add MoltenVK_Configuration_Parameters.md to
document the MoltenVK configuration parameters.
- Deprecate vkSetMoltenVKConfigurationMVK().
- Deprecate mvk_config.h and move content to mvk_private_api.h and mvk_deprecated_api.h.
- Streamline lock on retrieval of MVKLayerManager singleton (unrelated).
- 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).
- Don't update value of timestampPeriod on first measurement.
- Force that first measurement upon creation of MVKPhysicalDevice, so an
accurate value for timestampPeriod will be calculated when next queried.
- Move patch point tracking from pipeline state to render state, and
remove MVKPipelineCommandEncoderState subclasses no longer needed.
- Move sample location tracking from renderpass input to pipeline
static or dynamic state tracking.
- Restart Metal render pass when sample locations change, and enable
VkPhysicalDeviceSampleLocationsPropertiesEXT::variableSampleLocations.
- Fix regression that broke VK_POLYGON_MODE_LINE (unrelated).
- Fix regression in marking MVKRenderingCommandEncoderState
dirty after vkCmdClearAttachments() (unrelated).
- Don't create global MVKPixelFormats instance during launch,
as this triggers a call to MTLCopyAllDevices(), which can
deadlock if app is also launching other services that use Metal.
- Update to latest SPIRV-Cross contining the fix.
- Modify CTS options in runcts script to avoid outputting full CTS log,
and use less file caching, all to reduce memory and filespace consumption,
and possibly improve performance (unrelated).
- Update MoltenVKShaderConverter tool to include Metal 3.1 support
and improved argument buffer settings (unrelated).
- Force Github CI to use Python 3.11, to avoid crash in
glslang::update_glslang_sources.py due to use of distutils,
removed in Python 3.12 (unrelated).
- Small unrelated non-functional edits.
- Add --keep-cache option to control whether or not to retain the
External/build/Intermediates directory (default not retained).
- Export KEEP_CACHE & SKIP_PACKAGING to be available within scripts
used by ExternalDependencies Xcode builds.
- Move BLD_SPECIFIED to build() instead of build_impl() to avoid
updating it from background thread (which will fail).
- Update MoltenVK version to 1.2.7 (unrelated).
- Add CompilerMSL::Options::replace_recursive_inputs to pipeline cache (unrelated).
- Update GitHub CI to Xcode 15.0.
- Update Whats_new.md document.
- 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).
- 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.
- 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.
- 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).
- 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().
- vkCmdBlitImage() ensure swizzle texture view is retained for life
of MTLCommandBuffer.
- vkQueuePresentKHR() use MTLCommandBuffer that retains references.
- Update MoltenVK version to 1.2.6.
- 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).
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.
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).
- 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.
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.
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).
- 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.
- 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).
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).
This just provides support for the `SPV_KHR_non_semantic_info`
extension, which supports extended instruction sets that do not affect
the semantics of a SPIR-V shader (e.g. debug info). SPIRV-Cross already
handles these instruction sets, so no additional work is required on our
part to support this 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`.
This turned out to be a little bit more involved than I had hoped. But,
with this, we can now use the `VK_FORMAT_A4R4G4B4_UNORM_PACK16` and
`VK_FORMAT_A4B4G4R4_UNORM_PACK16` formats from shaders, use them as blit
sources, and even clear them. Storage images and render targets of these
formats aren't supported, however. To support the latter would require
the insertion of a swizzle into the fragment shader before returning.
The former cannot be reasonably supported.