2875 Commits

Author SHA1 Message Date
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
Chip Davis
5253e6f9e0 Advertise the VK_KHR_shader_non_semantic_info extension.
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.
2023-06-24 16:48:30 -07: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
Chip Davis
591eb6bdaa
Merge pull request #1955 from cdavis5e/4444-formats
Support the `VK_EXT_4444_formats` extension.
2023-06-23 13:07:10 -06:00
Filip Lundgren
67814ba3f3 Fix build with latest main 2023-06-23 10:51:28 -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
Chip Davis
5d173d0e09 Support the VK_EXT_4444_formats extension.
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.
2023-06-22 15:14:50 -07:00
Bill Hollings
3e1fb4fe52
Merge pull request #1954 from AntarticCoder/khr-deferred-operation
Implemented Deferred Host Operations
2023-06-22 10:35:50 -04:00
Antarctic Coder
e5bfc2d66e C-Style Arrays instead of MVKSmallVector
This commit changes the MVKSmallVector to a C-Style array because the parameters array will not have to resize, and it seems that a C-Style array is just as capable of doing the job.
2023-06-21 11:00:15 -04:00
Antarctic Coder
fa19fcc962 Push to Compile MVKSmallVector with void*
Pushing to Github to compile with Github Actions to see if MVKVectors with void* can work
2023-06-20 13:11:54 -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
Antarctic Coder
ab7087165a
Fixed comments for deferred operations
Co-authored-by: Chip Davis <cdavis5x@gmail.com>
2023-06-20 08:28:59 -04:00
Antarctic Coder
33cd6f24c4 Implemented Deferred Host Operations
Implemented deferred host operations in this commit. It was pretty simple with nothing Metal specific. I am a bit concerned on the return types of MVKDeferredOperation::join and about how to store the operation to be executed for later.
2023-06-19 15:18:15 -04:00
Bill Hollings
9356c89bd5
Merge pull request #1949 from billhollings/swap-system-GPU-fix
Don't call MTLCreateSystemDefaultDevice() on every swapchain creation.
2023-06-16 09:00:02 -04:00
Bill Hollings
78f3e1ee28
Merge pull request #1951 from billhollings/log-shdr-conv-err-info
Log more info about SPIR-V to MSL conversion errors.
2023-06-15 20:33:18 -04:00
Bill Hollings
e69c249348 Log more info about SPIR-V to MSL conversion errors.
Remove unhelpful "Shader module does not contain
an entry point named 'main0'" error message.
2023-06-15 19:56:36 -04:00
Bill Hollings
425505da47 Don't call MTLCreateSystemDefaultDevice() on every swapchain creation.
- When forcing the window system to use the same high-power GPU as the app,
  move the call to MTLCreateSystemDefaultDevice() to MVKDevice constructor,
  instead of MVKDevice::createSwapchain(), and test whether the
  VK_KHR_swapchain extension is enabled to determine the need to swap GPUs.

- After calling MTLCreateSystemDefaultDevice() the GPU will already be
  the same high-power GPU, so remove attempting to replace the MTLDevice.

- Remove MVKPhysicalDevice::replaceMTLDevice() as no longer used.

- Remove many unnecessary inline declarations in MVKDevice.h (unrelated).
2023-06-15 17:24:50 -04:00
Bill Hollings
4a9bf78e03
Merge pull request #1946 from billhollings/no-rendpass-no-dyn-rend-info
Allow both renderPass and VkPipelineRenderingCreateInfo to be missing.
2023-06-15 10:34:57 -04:00
Bill Hollings
b94553dbb3 Allow both renderPass and VkPipelineRenderingCreateInfo to be missing.
This avoids crashes in CTS when creating a graphics pipeline.
2023-06-14 18:49:40 -04:00
Bill Hollings
bdbf9abf0a
Merge pull request #1944 from RaafatAkkad/main
Allows maximizing the concurrent executing compilation tasks.
2023-06-14 17:58:40 -04:00
Raafat Akkad
e7243572d7 Allows maximizing the concurrent executing compilation tasks.
https://developer.apple.com/videos/play/wwdc2023/10127/?time=540
On an M1 Pro Macbook Pro 16" maximumConcurrentCompilationTaskCount goes from 2 to 8
2023-06-14 20:17:53 +01:00
Bill Hollings
4949c34b4d
Merge pull request #1936 from billhollings/present-imm-mode-unless-present-time
Support VK_PRESENT_MODE_IMMEDIATE_KHR if VkPresentTimeGOOGLE::desiredPresentTime is zero.
2023-06-07 18:41:57 -04:00
Bill Hollings
49748602dd
Merge pull request #1935 from cdavis5e/shader-demote-to-helper
Advertise the VK_EXT_shader_demote_to_helper_invocation extension.
2023-06-07 16:10:27 -04:00
Chip Davis
750adcaae2 Advertise the VK_EXT_shader_demote_to_helper_invocation extension.
As of macOS Big Sur and iOS/tvOS 14, the `discard_fragment()` function
in MSL is defined to have demote semantics; that is, fragment shader
output is discarded, but the fragment shader thread continues to run as
a helper invocation. This is very useful for Direct3D emulation, since
this is the semantic that HLSL `discard` has.

Signed-off-by: Chip Davis <chip@holochip.com>
2023-06-07 12:48:02 -07:00
Bill Hollings
3690a52a0e
Merge pull request #1942 from rcombs/spirv-cross-fix
Update SPIRV-Cross revision to include function constant fix
2023-06-07 11:35:08 -04:00