565 Commits

Author SHA1 Message Date
Bill Hollings
e480e1570b Merge latest main into swapchain-mtce1 branch.
Update VK_MVK_MOLTENVK_SPEC_VERSION to version 37.
2023-02-04 14:37:08 -05:00
Bill Hollings
3250569260 Queue submissions retain wait semaphores until MTLCommandBuffer finishes.
Add additional Vulkan error strings (unrelated).
2023-02-04 11:27:16 -05:00
Chip Davis
2c01c8b7e0 Work around problems with explicit LoD with arrayed depth images on Apple Silicon.
Use an explicit gradient to make it sample the correct level.

Update SPIRV-Cross to pull in the change needed for this.
2023-02-03 14:48:25 -08:00
Bill Hollings
fabad21405 Add support for VK_EXT_swapchain_maintenance1 and VK_EXT_surface_maintenance1.
- Support querying scaling capabilities and present mode compatibilies
  when querying surface capabilities.
- Rename MVKPresentTimingInfo to MVKImagePresentInfo and add present mode
  and fence to support dynamic present mode changes and fence signaling.
- MVKPresentableSwapchainImage remove static functions from class declaration.
- MVKSwapchain support releasing swapchain images on command.
- MVKSwapchain support configuring with scaling and gravity info, apply it to
  CAMetalLayer.and do not return VK_SUBOPTIMAL_KHR if swapchain was configured
  with scaling info.
- Rename MVKSwapchain::acquireNextImageKHR to acquireNextImage.
- CAMetalLayer naturalDrawableSizeMVK compute precise drawable size.
- CAMetalLayer remove obsolete and unused updatedDrawableSizeMVK method.
- Rename MVKConfiguration::swapchainMagFilterUseNearest to
  swapchainMinMagFilterUseNearest to apply CAMetalLayer size
  filtering to both magnification and minification, and rename
  corresponding  env var MVK_CONFIG_SWAPCHAIN_MAG_FILTER_USE_NEAREST
  to MVK_CONFIG_SWAPCHAIN_MIN_MAG_FILTER_USE_NEAREST.
- Detect when size of surface has changed under the covers.
- Change rounding of surface size provided by Metal from truncation to
  rounding-with-half-to-even.
- Remove MVKLogSizeOf() logging macro as redundant to mvkPrintSizeOf() macro.
2023-02-02 23:00:37 -05:00
Bill Hollings
7e9b5b73de Fix issue where extension VK_KHR_fragment_shader_barycentric
was sometimes incorrectly disabled due to a Metal driver bug.

Update MoltenVK version to 1.2.3.
2023-01-30 15:22:33 -05:00
Bill Hollings
8bcbb2eb42 Update dependency libraries to match Vulkan SDK 1.3.239.
Update Whats New document.
2023-01-23 17:57:36 -05:00
Bill Hollings
e0333509a1 Set more accurate values for some VkPhysicalDeviceLimits members.
- Update maxClipDistances and maxCombinedClipAndCullDistances to more accurate values.
- Update maxDrawIndexedIndexValue to acknowledge primitive restart.
2023-01-13 19:03:00 -05: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
Bill Hollings
be51089f25 Fix small memory issues with MVKPresentableSwapchainImage.
- Fix Metal validation error caused by CAMetalDrawable released before
  MTLCommandBuffer is finished using it.
- When presenting, MVKPresentableSwapchainImage retains in-flight
  CAMetalDrawable until MTLCommandBuffer completion.

- Fix memory leak of MVKFences and MVKSemaphores when a
  swapchain image is acquired more than it is presented.
- Force MVKPresentableSwapchainImage to untrack any tracked fences or
  semaphores when it is destroyed.

- Update MoltenVK version to 1.2.2.
2022-12-29 21:50:04 -05:00
Bill Hollings
b09ee9d370 Revert commit e102ce1102dcdfd4d59df3fd5f3f381cb9a4ab81.
The now-reverted commit had caused fragment shader not
to run at all when no render attachment was available.
2022-12-27 14:09:24 -05:00
Bill Hollings
e102ce1102 Fix excessive Metal tile memory preallocation when rendering without attachments.
Metal uses MTLRenderPassDescriptor properties renderTargetWidth,
renderTargetHeight, and renderTargetArrayLength to preallocate tile memory
storage on machines using tiled rendering. This memory preallocation is not
necessary if we are not rendering to attachments, and some apps actively
define extremely oversized framebuffers when they know they are not rendering
to actual attachments, making this internal tile memory allocation even more
wasteful, occasionally to the point of triggering OOM crashes.

Update MoltenVK version to 1.2.2.
2022-12-11 19:11:38 -05:00
Bill Hollings
8965c87e14 Fix crash when buffer binding updates only offset while it is overridden.
MVKMTLBufferBinding don't allow justOffset if binding was overridden.
2022-12-08 18:38:49 -05:00
Bill Hollings
f5f6515dce Update dependency libraries to match Vulkan SDK 1.3.236.
Update Whats New document.
2022-12-08 14:10:58 -05:00
Bill Hollings
985ec99832 Fix app performance regression triggered by the previous introduction
of VK_KHR_shader_float_controls.

The introduction of shaderSignedZeroInfNanPreserveFloat32 was causing Metal
fast math to be aggressively disabled by the use of SignedZeroInfNanPreserve
in shaders in some apps, causing a regression in shader performance in those apps.

- Change MVKConfiguration::fastMathEnabled from bool to enumeration to distinguish
  between always using fast math or allowing shaders to selectively disable it.
- Default value to fast math always.
2022-12-07 12:40:50 -05:00
Bill Hollings
8e45217fbd Fix Metal buffer index binding overrides for push constants and attachment clearing.
Push constants and attachment clearing can temporarily override Metal buffer
bindings for descriptor sets and vertex attributes. Mark the overridden buffer
bindings and ensure they are reinstated when the pipeline is updated.

- Add MVKMTLBufferBinding::isOverridden to track if buffer binding is
  temporarily overridden.
- Rename MVKResourcesCommandEncoderState::markIndexDirty()
  to markBufferIndexOverridden() to mark buffer bindings as overridden.
- Rename MVKGraphicsResourcesCommandEncoderState::markBufferIndexDirty()
  to markBufferIndexOverridden().
- Rename MVKComputeResourcesCommandEncoderState::markBufferIndexDirty()
  to markBufferIndexOverridden().
- Add MVKResourcesCommandEncoderState::markOverriddenBufferIndexesDirty()
  to mark overridden buffer bindings as dirty.
- Add MVKGraphicsResourcesCommandEncoderState::markOverriddenBufferIndexesDirty()
  and call when render pipeline change is encoded
- Add MVKComputeResourcesCommandEncoderState::markOverriddenBufferIndexesDirty()
  and call when compute pipeline change is encoded.
2022-11-30 00:01:07 -05:00
Bill Hollings
bd497fe713 Fix mistaken YCBCR format support indication.
MVKVkFormatDesc::chromaSubsamplingPlaneCount must be > 1 to be considered supported.
2022-11-18 23:35:46 -05:00
Bill Hollings
7c0143c37b Support Xcode 14.1 build settings. 2022-11-15 20:49:17 -05:00
Bill Hollings
4d003bf256 Document new linkage model used by Xcode 14 and later, and how to link
MoltenVK to an app or game using Xcode 13 or earlier.
2022-11-15 18:48:36 -05:00
Bill Hollings
6d7f4330c7 Work around MTLCounterSet crash on additional Intel Iris Plus Graphics devices.
Add 0x8a5a and 0x8a5c to list of Intel Iris Plus Graphics
device IDs requiring workaround.
2022-11-15 17:44:55 -05:00
Bill Hollings
0287a3242c Fix crash on descriptor update with out-of-bounds descriptor count data.
Update MoltenVK version to 1.2.1.
2022-10-31 14:41:08 -04:00
Bill Hollings
00b2184c23 Fix crash and memory leaks when configured for prefilling Metal command buffers.
- Redefine enumeration values of MVKPrefillMetalCommandBuffersStyle.
- Add option to defer encoding prefilled MTLCommandBuffer to queue submission.
- Remove option to create an autorelease pool in the MVKCommandEncoder
  to span immediate command encodings, because it causes crashes when
  multiple command buffers were overlapping prefilling on the same thread.
- Replace MTLCommandEncoder retain/release macros with template member functions.
- Rename MVKCommandPool::newMTLCommandBuffer() to getMTLCommandBuffer()
  and do not retain the returned MTLCommandBuffer (unrelated).
- Revert MoltenVK logging to use stderr instead of stdout (unrelated).
- Merge branch from master.
2022-10-18 03:28:12 -04:00
Bill Hollings
e061e5ebf8 Update dependency libraries to match Vulkan SDK 1.3.231. 2022-10-17 16:05:43 -04:00
Bill Hollings
b751c07eb3 Fix memory leaks when configured for prefilling Metal command buffers.
- Add MVKPrefillMetalCommandBuffersStyle enumeration to enable prefilling,
  and configure memory recovery options.
- Redefine MVKConfiguration::prefillMetalCommandBuffers as a value from
  MVKPrefillMetalCommandBuffersStyle instead of a simple boolean. Set the
  values of MVKPrefillMetalCommandBuffersStyle and the default value of
  MVKConfiguration::prefillMetalCommandBuffers to be compatible with
  legacy use of this setting as a simple enable/disable boolean value.
- MVKCommandEncoder track prefill style, and support option to maintain
  a Metal autorelease pool that is created on vkBeginCommandBuffer()
  and drained on vkEndCommandBuffer(), when prefiling a command buffer
  from a single thread, and an option to wrap each command addition in
  a separate @autoreleasepool{} scope to create and drain an autorelease
  pool at every command addition to the Vulkan command buffer, when
  prefilling a single command buffer from multiple threads.
- MVKCommandEncoder retain Metal encoders when prefilling, because
  prefilling may span multiple autorelease pools.
- MVKCommandEncoder clean up memory leak of MTLBlitPassDescriptor
  during prefilling.
- MVKCommandEncoder rearrange declarations of MVKCommandUse member
  variables to tighten up class memory use (unrelated).
- MVKCommandBuffer remove unnecessary inline declarations (unrelated).
- Change MoltenVK logging to use stdout instead of stderr (unrelated).
2022-10-16 17:03:55 -04:00
Bill Hollings
ac39eb24e1 Add support for Vulkan 1.2.
- Set MVK_VULKAN_API_VERSION from VK_API_VERSION_1_2.
- Update MoltenVK version to 1.2.0.
- Remove several previously overlooked extension suffixes
  in use of promoted Vulkan struct and enum values.
- Update documentation.
2022-09-26 11:25:49 -04:00
Bill Hollings
31a77834f1 Advertise support for extension VK_KHR_spirv_1_4.
- Advertise support for extension VK_KHR_spirv_1_4.
- MoltenVKShaderConverter automatically map bindings when converting GLSL.
- MoltenVKShaderConverter improvements to diagnostic logging.
- Update Whats_New.md document.
2022-09-23 11:43:32 -04:00
Bill Hollings
63be111958 Fix undefined reference to vkGetBufferDeviceAddressEXT
when building with MVK_HIDE_VULKAN_SYMBOLS=1.

Alias vkGetBufferDeviceAddressEXT to core function,
and add it as promoted extension function in MVKInstance.
2022-09-19 15:29:40 -04:00
Bill Hollings
14de07b6f4 Vulkan semaphore functional improvements.
- Support option to use MTLEvents for Vulkan semaphores on NVIDIA and Rosetta2.
- Add public MVKVkSemaphoreSupportStyle enumeration.
- MVKConfiguration replace deprecated legacy booleans semaphoreUseMTLEvent,
  and semaphoreUseMTLFence with enumerated semaphoreSupportStyle.
- Alias legacy semaphoreUseMTLEvent to semaphoreSupportStyle and support legacy
  use of semaphoreUseMTLFence and semaphoreUseMTLEvent for backwards compatibility.
- MVKConfiguration rename recently renamed semaphoreUseSingleQueue back to
  semaphoreUseMTLFence for backwards compatibility.
2022-09-01 12:10:23 -04:00
Bill Hollings
4effb9a5fd Support automatically enable Metal argument buffers when
VK_EXT_descriptor_indexing extension is enabled.

- Change MVKConfiguration::useMetalArgumentBuffers to enum instead of boolean
  and default to enabling Metal argument buffers for VK_EXT_descriptor_indexing.
- Leave Metal argument buffers disabled by default until they are improved.
- Enable VkPhysicalDeviceVulkan12Features::descriptorIndexing.
- Add MVKPhysicalDeviceVulkan12FeaturesNoExt to track and enable Vulkan 1.2
  features not part of any prior extensions absorbed by Vulkan 1.2.
- Update VK_MVK_MOLTENVK_SPEC_VERSION to version `36`.
- MVKDeviceTrackingMixin remove unnecessary inline declarations.
- MoltenShaderConveter tool support Metal Argument Buffers and MSL 3.0.
2022-08-26 14:48:13 -04:00
Bill Hollings
e0a50c8f2d Add support for the VK_KHR_shader_float_controls extension.
- Enable shaderSignedZeroInfNanPreserveFloat16 and
  shaderSignedZeroInfNanPreserveFloat32.
  Other float control properties are not settable in Metal.
- MVKShaderModule log whether compiling with fast math enabled.
- Update MoltenVK_Runtime_UserGuide.md and Whats_New.md documents.
- runcts script enable MVK_CONFIG_FAST_MATH_ENABLED by default.
2022-08-18 13:35:35 -04:00
Bill Hollings
33ca59ef13 Fix retention of MVKSwapchain for future drawable presentations.
When presenting drawables in the future, the MVKPresentableSwapchainImage
and MVKSwapchain were both being retained by the drawable-presented callback,
so that the presentation timing info can be recorded on the swapchain.
Unfortunately, in the case where the presentation timing is set far enough
into the future (I'm looking at you CTS), the swapchain, and even the
CAMetalLayer's view may be destroyed, causing occasional bad access crashes.

- MVKSwapchainImage don't retain() the swapchain, and move clearing the
  swapchain from the destructor to destroy(), so the MVKSwapchain is not
  necessarily retained by the MVKSwapchainImage, for a drawable being
  presented in the future.
- MVKSwapchainImage add a lock around clearing swapchain and accessing
  it from callbacks.
- Add lockable releaseLayer() function in both MVKSwapchain and MVKSurface,
  which is called from both layer observer and destructor, to handle race
  conditions better.
- MVKSwapchain::initCAMetalLayer() call MVKSurface::getCAMetalLayer() only once.
- Update MoltenVK version to 1.1.12.
- Update What's New document.
2022-08-16 15:27:20 -04:00
Bill Hollings
f487a14975 Update dependency libraries to match Vulkan SDK 1.3.224.
Update What's New document.
2022-08-12 16:54:24 -04:00
Bill Hollings
5e324d620c Fix occasional missing Metal buffer binding when only offset changes.
This fixes an earlier regression, where when only the offset changes in
a buffer descriptor, the binding is not marked dirty if the same Metal
binding index is used by a push constant in between descriptor bindings.

- MVKPushConstantsCommandEncoderState::markDirty() call resource encoder
  state markPushConstantBinding() to find and mark dirty descriptor that
  uses same Metal index as a push constant binding.
- Add MVKResourcesCommandEncoderState::markMetalBufferIndexDirty() to
  find and mark dirty a descriptor buffer binding that uses
- MVKResourcesCommandEncoderState::bind() use range-based-for-loop
  for consistency (unrelated).
2022-08-10 20:21:25 -04:00
Bill Hollings
b16fef0ca2 Improve performance of vkResetDescriptorPool().
- MVKDescriptorPool::reset() don't waste time freeing
  descriptor sets that were never allocated.
- If descriptor set could not be allocated, set availability bit (unrelated).
- MVKBitArray add _lowestNeverClearedBitIndex to track the lowest bit index
  that has not been cleared since last reset.
- MVKBitArray rename _minUnclearedSectionIndex to _clearedSectionCount for clarity.
- MVKBitArray use _clearedSectionCount and _lowestNeverClearedBitIndex to optimize
  operation of setting or clearing all bits.
- MVKBitArray::setBit() ensure we don't try to change a bit that is out of range.
- MVKBitArray::resize() no-op if size doesn't actually change.
- MVKQueue don't include object pointer in error log, so CTS log results
  are consistent across multiple CTS runs (unrelated).
2022-08-09 16:28:22 -04:00
Bill Hollings
cfe259fce2 Report appropriate values of VkDebugUtilsMessageTypeFlagsEXT
for debug util messages generated within MoltenVK.
2022-07-30 17:38:20 -04:00
Bill Hollings
152c605c20 Fix retrieval of accurate refresh duration across multiple display screens.
- Add [CAMetalLayer screenMVK] extension method to retrieve screen.
- If the layer has a delegate view, use it to locate the screen, otherwise
  revert to iterating across windows, looking for the CAMetalLayer, to identify
  the window the layer is in, from which to retrieve the screen.
- Fix the iteration of the layer hierarchy, to accommodate that Apple may
  add superlayers to the CAMetalLayer under the covers.
- Update MoltenVK_Runtime_UserGuide.md to encourage the app to ensure the view
  is the delegate of the CAMetalLayer, to more efficiently access the screen.
2022-07-29 18:15:46 -04:00
Bill Hollings
991e1a9876 Update macOS Cube demo to demonstrate optimizing swapchain across multiple screens.
- DemoView implements NSViewLayerContentScaleDelegate protocol to update
  [CAMetalLayer contentsScale] property when moved between screens.
- Log contentsScale value during swapchain creation.
- Remove a few unnecessary inline declarations.
2022-07-28 16:33:10 -04:00
Bill Hollings
85c4b5c680 Fix vkUpdateDescriptorSetWithTemplate() for inline block descriptors.
Wrap incoming data in VkWriteDescriptorSetInlineUniformBlock
before passing to MVKInlineUniformBlockDescriptor::write().
2022-07-26 16:57:47 -04:00
Bill Hollings
3008ec71e8 Ignore sampler update in descriptor set bindings that use immutable samplers.
Inline MVKDescriptorSetLayoutBinding::getImmutableSampler()
for consistency with usesImmutableSamplers().
2022-07-24 20:36:02 -04:00
Bill Hollings
cb57bf9973 Fix query pool wait block when query is not encoded to be written to.
When checking query wait completion, all queries were previously
checked for Available status, and blocked until all became Available.
However, only queries that were encoded to be written should be checked.
It is okay for queries that are not encoded to be written to remain in
Initial state, and not block the wait.
2022-07-24 15:33:02 -04:00
Bill Hollings
b04a6db72e Check MTLDevice for gpuAddress support.
Support by the MTLDevice for Metal Tier 2 argument buffers has an
impact on both descriptor indexing and buffer device address support.
Add MVKPhysicalDeviceMetalFeatures::argumentBuffersTier, to track
the MTLDevice argument buffers support tier, set it from
[MTLDevice argumentBuffersSupport], and subsequently enable support for
VK_KHR_buffer_device_address and VK_EXT_buffer_device_address extensions,
and set descriptor indexing resource counts, based on it.
Update documentation requirements.
2022-07-19 14:30:38 -04:00
Bill Hollings
b54c701393 Check MTLDevice for barycentric coordinate support.
Add MVKPhysicalDeviceMetalFeatures::shaderBarycentricCoordinates,
enable it based on [MTLDevice supportsShaderBarycentricCoordinates],
and subsequently enable support for VK_KHR_fragment_shader_barycentric
and VK_NV_fragment_shader_barycentric extensions, based on it.
2022-07-15 13:43:48 -04:00
Bill Hollings
c5c7e80a6c Work around MTLCounterSet crash on additional Intel Iris Plus Graphics drivers.
Add 0x8a51 and 0x8a52 to list of device IDs requiring workaround.
2022-07-14 11:19:48 -04:00
Bill Hollings
6655beebd7 Enhancements to recent extensions.
- Update to latest SPIRV-Cross to support `SPV_KHR_physical_storage_buffer`
  for `VK_KHR_buffer_device_address` and `VK_EXT_buffer_device_address`
- Add support for `VK_EXT_buffer_device_address` extension.
- Advertise support for `VK_KHR_buffer_device_address`
  and `VK_EXT_buffer_device_address` on macOS 12.5.
- Add appropriate extension reporting and enablement for
  `VkPhysicalDeviceBufferDeviceAddressFeatures`,
  `VkPhysicalDeviceBufferDeviceAddressFeaturesEXT`, and
  `VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR`.
- Support reading `VkMemoryAllocateFlagsInfo` to identify memory allocations that
  need to support buffer pointer access (in case needed in future on non-shared memory).
- Update `Whats_New.md` and `MoltenVK_Runtime_UserGuide` documents.
2022-07-12 12:35:50 -04:00
Bill Hollings
26d4a13e34 Support Xcode 14, macOS 13, and iOS/tvOS 16.
- Update minimum Xcode deployment targets to macOS 10.13, iOS 11, and tvOS 11,
  to avoid Xcode build warnings.
- Add support for MTLLanguageVersion3_0 enumeration.
- Build efficiencies:
  - Build scripts create_dylib.sh and gen_moltenvk_rev_hdr.sh
    only run if build dependencies require it.
  - Packaging and copy_to_staging.sh scripts are too complex to define dependencies,
    and are fast, so configured to run every time, to avoid build warning.
- Replace use of deprecated sprintf() with  snprintf().
- Replace use of deprecated kIOMasterPortDefault with  kIOMainPortDefault.
- Support old-style GPU debug capture only if building for earlier minimum
  deployment targets, to avoid deprecation warning.
- Update minimum Xcode deployment targets of Cube demo to macOS 10.14, iOS 12,
  and tvOS 12, to avoid Xcode build warning regarding MTLSharedEvent in .
- Update README.md document regarding minimum Xcode deployment targets.
2022-07-06 18:15:10 -04:00
Bill Hollings
2b05b95974 Add support for VK_EXT_metal_objects extension.
Update Vulkan-Headers version to include new VK_EXT_metal_objects extension.
Update MoltenVK version to 1.1.11.
Update What's New document.
2022-06-11 20:10:06 -04:00
Bill Hollings
292ea5e55a Update dependency libraries to match Vulkan SDK 1.3.216.
Update What's New document.
2022-06-04 21:06:56 -04:00
sean
9253d5c212
Fix compilation issues 2022-05-25 18:23:30 +02:00
sean
9b1194afba
Note Metal requirement in UserGuide.md 2022-05-25 15:56:07 +02:00
sean
5e03632d69
Also support the NVIDIA specific extension 2022-05-25 15:17:21 +02:00