Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Geometry shaders #1815

Open
wants to merge 134 commits into
base: geometry-shaders
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
6f3a2b7
Allow to disable Explicit LOD Workaround
italomandara Apr 4, 2023
912b2ed
Merge pull request #1861 from italomandara/allow-disable-explicit-lod…
billhollings Apr 4, 2023
5183856
Several simple maintenance fixes.
billhollings Apr 12, 2023
1d213e5
Merge pull request #1865 from billhollings/timeline-semaphore-mem-leak
billhollings Apr 12, 2023
5092330
Support BC compression on iOS/tvOS, where available.
billhollings Apr 12, 2023
b0e6df6
Replace references to macOS 10.16 with 11.0, and standardize use
billhollings Apr 12, 2023
f99ea66
Merge pull request #1866 from billhollings/ios-support-bc-compression
billhollings Apr 12, 2023
13e8103
Ensure shaders using PhysicalStorageBufferAddresses encode the associ…
billhollings Apr 14, 2023
5cbeaaa
Merge pull request #1868 from billhollings/gpu-addr-buff-use
billhollings Apr 15, 2023
fc8e818
Disable pipeline cache compression prior to macOS 10.15 and iOS/tvOS …
billhollings Apr 24, 2023
4aa2b6d
Support separate depth and stencil attachments during dynamic rendering.
billhollings Apr 24, 2023
abb12a5
Fix Metal validation errors with dynamic rendering.
billhollings Apr 26, 2023
331cea9
Merge pull request #1877 from billhollings/pipeline-compress-older-os…
billhollings Apr 26, 2023
fd6b973
Clear attachments support separate depth and stencil attachments.
billhollings Apr 27, 2023
e50cb32
Merge pull request #1878 from billhollings/dyn-rend-separate-depth-st…
billhollings Apr 28, 2023
937b0bf
Deprecate the obsolete and non-standard VK_MVK_moltenvk extension.
billhollings May 1, 2023
f33e718
Expose pointers to functions from removed VK_MVK_moltenvk extension.
billhollings May 3, 2023
d2f57fc
Merge pull request #1881 from billhollings/deprecate-VK_MVK_moltenvk-…
billhollings May 3, 2023
789d432
Avoid Metal validation warning when depth component swizzled away.
billhollings May 4, 2023
53a4eb2
Merge pull request #1885 from billhollings/fix-mtl-valid-err-depth-sw…
billhollings May 4, 2023
3db62a1
Reinstate VK_MVK_moltenvk extension and add simplified config functions.
billhollings May 4, 2023
cfa0ed2
Merge pull request #1886 from billhollings/reinstate-mvk-extn
billhollings May 4, 2023
cde220a
Remove vkGetMoltenVKConfiguration2MVK() and vkSetMoltenVKConfiguratio…
billhollings May 5, 2023
af9544d
Merge pull request #1889 from billhollings/rmv-config2
billhollings May 5, 2023
9e46669
Fix race condition when updating values in VkPastPresentationTimingGO…
billhollings May 5, 2023
dfc0af8
Merge pull request #1890 from billhollings/fix-display-timing-race-co…
billhollings May 5, 2023
ab5429b
GitHub CI improvements.
billhollings May 8, 2023
fbaba84
Merge pull request #1893 from billhollings/ci-improvements
billhollings May 9, 2023
f19ac2c
Add GitHub Actions workflow for automatically creating releases.
May 10, 2023
5bce402
Merge pull request #1895 from Steveice10/main
billhollings May 10, 2023
3247bd4
GitHub CI streamline uploaded artifact sizes.
billhollings May 10, 2023
dd5faf2
Merge pull request #1896 from billhollings/ci-reduce-artifact-sizes
billhollings May 10, 2023
0618c43
Update release action artifact glob.
May 11, 2023
c893a03
Merge pull request #1897 from Steveice10/main
billhollings May 11, 2023
9c72022
Make the GitHub Actions release workflow more lenient.
May 12, 2023
1b6750b
Respect the bind point supplied to vkCmdBindDescriptorSets
etang-cw May 10, 2023
d3b64c8
Merge pull request #1900 from Steveice10/release-workflow-patch
billhollings May 12, 2023
734a185
Merge pull request #1898 from etang-cw/PushBindPoint
billhollings May 12, 2023
47ce47a
Fix reorder-ctor warning
etang-cw May 12, 2023
0139b95
Fix simulator feature discovery
ChibiDenDen May 12, 2023
9bdc29a
Merge pull request #1902 from etang-cw/FixReorderCtor
billhollings May 13, 2023
7d4f574
Merge pull request #1903 from ChibiDenDen/simulator_feature_discovery…
billhollings May 13, 2023
4893f78
Identify each unsupported device feature flag that the app attempts t…
billhollings May 15, 2023
9c55ef3
Merge pull request #1905 from billhollings/id-unsupp-dvc-feat-flags
billhollings May 15, 2023
65ce195
Ensure swapchain image presented time is always populated when reques…
billhollings May 15, 2023
44c3063
Merge pull request #1906 from billhollings/ensure-present-time
billhollings May 15, 2023
d29092a
Do not fail on request for timestamp query pool that is too large.
billhollings May 16, 2023
6111aab
Merge pull request #1910 from billhollings/fix-ts-qp
billhollings May 17, 2023
665ef6d
Improve support for deviceUUID and deviceLUID.
billhollings May 16, 2023
ae0ee6a
Merge pull request #1908 from billhollings/fix-deviceUUID
billhollings May 17, 2023
75b4d26
Check if shader compiled before adding it to a pipeline
etang-cw May 17, 2023
b3ae0f4
Merge pull request #1911 from etang-cw/NoAbortOnCompilationFailure
billhollings May 18, 2023
6c633a7
update SPIRV-Cross revision to include explicit LOD workaround regres…
italomandara May 20, 2023
0125e5b
Revert "Allow to disable Explicit LOD Workaround"
italomandara May 20, 2023
1a386e0
Merge pull request #1913 from italomandara/update-spirv-cross-revision
billhollings May 21, 2023
c231c90
Update dependency libraries to match Vulkan SDK 1.3.250.
billhollings May 23, 2023
a832e38
Merge pull request #1916 from billhollings/sdk-1.3.250
billhollings May 23, 2023
b863ece
Accumulate render stages when a resource is used by multiple descript…
billhollings May 23, 2023
3d7f996
Merge pull request #1918 from billhollings/accumulate-render-stages
billhollings May 23, 2023
b26ce32
Advertise VK_KHR_depth_stencil_resolve extension on all devices.
billhollings May 23, 2023
4c6bfbe
Merge pull request #1920 from billhollings/always-advertise-VK_KHR_de…
billhollings May 24, 2023
83a1811
Ensure compute encoding state is marked dirty for non-dispatch commands.
billhollings May 26, 2023
2a4e415
Merge pull request #1922 from billhollings/fix-comp-enc-state
billhollings May 26, 2023
107be11
Add support for VK_PRESENT_MODE_IMMEDIATE_KHR to macOS Cube demo.
billhollings May 31, 2023
0332055
Merge pull request #1927 from billhollings/demo-support-immediate-pre…
billhollings May 31, 2023
6fb5347
Support VK_PRESENT_MODE_IMMEDIATE_KHR if VkPresentTimeGOOGLE::desired…
billhollings Jun 5, 2023
3fbde16
update SPIRV-Cross revision to include function constant fix; closes …
rcombs Jun 6, 2023
3690a52
Merge pull request #1942 from rcombs/spirv-cross-fix
billhollings Jun 7, 2023
750adca
Advertise the VK_EXT_shader_demote_to_helper_invocation extension.
cdavis5e Oct 29, 2020
4974860
Merge pull request #1935 from cdavis5e/shader-demote-to-helper
billhollings Jun 7, 2023
4949c34
Merge pull request #1936 from billhollings/present-imm-mode-unless-pr…
billhollings Jun 7, 2023
e724357
Allows maximizing the concurrent executing compilation tasks.
RaafatAkkad Jun 10, 2023
bdbf9ab
Merge pull request #1944 from RaafatAkkad/main
billhollings Jun 14, 2023
b94553d
Allow both renderPass and VkPipelineRenderingCreateInfo to be missing.
billhollings Jun 14, 2023
4a9bf78
Merge pull request #1946 from billhollings/no-rendpass-no-dyn-rend-info
billhollings Jun 15, 2023
425505d
Don't call MTLCreateSystemDefaultDevice() on every swapchain creation.
billhollings Jun 15, 2023
e69c249
Log more info about SPIR-V to MSL conversion errors.
billhollings Jun 15, 2023
78f3e1e
Merge pull request #1951 from billhollings/log-shdr-conv-err-info
billhollings Jun 16, 2023
9356c89
Merge pull request #1949 from billhollings/swap-system-GPU-fix
billhollings Jun 16, 2023
33cd6f2
Implemented Deferred Host Operations
AntarticCoder Jun 19, 2023
ab70871
Fixed comments for deferred operations
AntarticCoder Jun 20, 2023
c0705c8
Made some fixes for Deferred Operations
AntarticCoder Jun 20, 2023
fa19fcc
Push to Compile MVKSmallVector with void*
AntarticCoder Jun 20, 2023
e5bfc2d
C-Style Arrays instead of MVKSmallVector
AntarticCoder Jun 21, 2023
3e1fb4f
Merge pull request #1954 from AntarticCoder/khr-deferred-operation
billhollings Jun 22, 2023
5d173d0
Support the `VK_EXT_4444_formats` extension.
cdavis5e Jun 7, 2023
16990ef
Support building for visionOS
ifiddynine Jun 23, 2023
d8b5a7d
Merge branch 'main' of https://github.com/KhronosGroup/MoltenVK into …
ifiddynine Jun 23, 2023
a756b8c
Fix MVK_MACOS_OR_IOS_OR_VISIONOS check
ifiddynine Jun 23, 2023
67814ba
Fix build with latest main
ifiddynine Jun 23, 2023
591eb6b
Merge pull request #1955 from cdavis5e/4444-formats
cdavis5e Jun 23, 2023
4540175
Fix mvkOSVersionIsAtLeast on Vision
ifiddynine Jun 23, 2023
4e3ac69
Support the `VK_EXT_calibrated_timestamps` extension.
cdavis5e Jun 23, 2023
5253e6f
Advertise the `VK_KHR_shader_non_semantic_info` extension.
cdavis5e Jun 24, 2023
714781e
Merge pull request #1958 from cdavis5e/calibrated-timestamps
billhollings Jun 26, 2023
b74feb7
Support `VK_EXT_shader_subgroup_ballot` and `VK_EXT_shader_subgroup_v…
cdavis5e Jun 24, 2023
c85507b
Merge pull request #1960 from cdavis5e/shader-non-semantic-info
billhollings Jun 26, 2023
96204ad
Merge pull request #1961 from cdavis5e/legacy-subgroup
billhollings Jun 26, 2023
e5d3939
Add support for VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN.
billhollings Jun 28, 2023
c34bb54
Fix unreachable code in MVKDeferredOperation::join().
billhollings Jun 29, 2023
27f68eb
Merge pull request #1964 from billhollings/fix-unreachable-code
billhollings Jun 30, 2023
41dbd9d
Merge pull request #1962 from billhollings/tri-fans
billhollings Jul 1, 2023
6bca44c
Added MSL Version 3.1 for switch case
AntarticCoder Jul 5, 2023
056dec8
Completed the support for MSL 3.1 enum
AntarticCoder Jul 5, 2023
2db85ea
Merge pull request #1966 from AntarticCoder/msl-3-1
billhollings Jul 5, 2023
21ac744
MVKDevice: Don't enable sample LoD depth array workaround for macOS S…
cdavis5e Jul 7, 2023
3914b0f
Support the `VK_KHR_incremental_present` extension.
cdavis5e Jul 10, 2023
ca8e060
Merge pull request #1969 from cdavis5e/sonoma-depth-array-lod
billhollings Jul 10, 2023
561e14b
Support the `VK_EXT_pipeline_creation_feedback` extension.
cdavis5e Jul 7, 2023
1728f7f
Merge pull request #1968 from cdavis5e/pipeline-creation-feedback
billhollings Jul 11, 2023
dff64e9
Merge pull request #1972 from cdavis5e/incremental-present
billhollings Jul 11, 2023
855c7a6
Merge branch 'visionOS' of https://github.com/nginetechnologies/Molte…
billhollings Jul 11, 2023
6374d9d
Fix visionOS build errors and warnings where possible.
billhollings Jul 11, 2023
97eb80b
Merge pull request #1976 from billhollings/nginetechnologies-visionOS
billhollings Jul 12, 2023
f6ba6f2
Drop official support for using Xcode 11 to build MoltenVK.
billhollings Jul 12, 2023
42fa511
Merge pull request #1977 from billhollings/drop-support-xcode-11
billhollings Jul 12, 2023
817038e
Fix regression caused by #1922
mbechard Jul 19, 2023
cf531d0
Merge pull request #1980 from mbechard/main
billhollings Jul 19, 2023
5294c19
Fix bad access regression to prematurely-deallocated MTLFunction.
billhollings Jul 19, 2023
d9b32e0
Merge pull request #1981 from billhollings/fix-bad-access-regression
billhollings Jul 20, 2023
f7e0d7d
Don't fetch a submodule if the commit is already known
stefand Jul 28, 2023
7cb6096
Merge pull request #1982 from stefand/main
billhollings Jul 31, 2023
dd31587
Fix sync delay between calls to vkQueueSubmit() on non-Apple-Silicon …
billhollings Aug 12, 2023
41a5a97
Ensure Xcode simulator always uses 256B buffer alignment.
billhollings Aug 14, 2023
8518a4f
Merge pull request #1992 from billhollings/fix-submit-sync-delay
billhollings Aug 14, 2023
47840b9
Merge pull request #1993 from billhollings/fix-sim-buff-align
billhollings Aug 14, 2023
4fe8811
Update dependency libraries to match Vulkan SDK 1.3.261.
billhollings Aug 15, 2023
b3c9f86
Merge pull request #1994 from billhollings/sdk-1.3.261
billhollings Aug 15, 2023
530bde1
Fix VkPhysicalDeviceLimits::timestampPeriod calculations on Intel GPU.
billhollings Aug 17, 2023
02a8c01
Merge pull request #1997 from billhollings/fix-Intel-timestampPeriod
billhollings Aug 17, 2023
7910083
Fix rare case where vertex attribute buffers are not bound to Metal.
billhollings Aug 23, 2023
fd418aa
Merge pull request #2001 from billhollings/fix-unbound-vtx-attr-buff
billhollings Aug 24, 2023
4544e76
Implement geometry shaders using mesh pipelines.
js6i Sep 8, 2023
8cbaaa6
Temporarily switch SPIRV-Cross repository.
js6i Sep 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 47 additions & 16 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@ jobs:
build:
strategy:
matrix:
xcode: [ "14.2" ]
platform: [ "macos", "maccat", "ios", "tvos" ]
os: [ "macos-latest" ]
xcode: [ "14.3.1" ]
platform: [ "all", "macos", "ios" ]
os: [ "macos-13" ]
upload_artifacts: [ true ]
# additional specific configurations

# Legacy configurations
include:
# "Legacy" Xcode 12.5.1 & 11.7 macOS builds
- xcode: "12.5.1"
platform: "macos"
os: "macos-11"
upload_artifacts: false
- xcode: "11.7"
platform: "macos"
os: "macos-11"
upload_artifacts: false
fail-fast: false

name: 'MoltenVK (Xcode ${{ matrix.xcode }} - ${{ matrix.platform }})'
Expand All @@ -41,7 +37,7 @@ jobs:

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Select Xcode version
run: sudo xcode-select -switch "${XCODE_DEV_PATH}"
Expand All @@ -54,12 +50,12 @@ jobs:
echo "${XCODE_VERSION}"
XCODE_VERSION="$(echo "${XCODE_VERSION}" | tr '\t\r\n ' '_')"
echo "${XCODE_VERSION}"
echo "::set-output name=XCODE_VERSION::${XCODE_VERSION}"
echo "XCODE_VERSION=${XCODE_VERSION}" >> $GITHUB_OUTPUT

- name: Cache Dependencies
id: cache-dependencies
if: success() && !(github.event_name == 'push' && contains(github.ref, 'refs/tags/')) # never cache dependencies for pushed tags
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
External/build
Expand Down Expand Up @@ -94,11 +90,46 @@ jobs:
- name: Tar Artifacts
if: success() && matrix.upload_artifacts == true
# See: https://github.com/actions/upload-artifact#maintaining-file-permissions-and-case-sensitive-files
run: tar -cvf "${{ matrix.platform }}.tar" Package/Release/
# To reduce artifact size, don't include any stand-alone shader converter binaries.
run: |
rm -rf Package/Release/MoltenVKShaderConverter
tar -C Package -s/Release/MoltenVK/ -cvf "MoltenVK-${{ matrix.platform }}.tar" Release/

- name: Upload Artifacts
if: success() && matrix.upload_artifacts == true
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: "MoltenVK-${{ matrix.platform }}"
path: "MoltenVK-${{ matrix.platform }}.tar"

release:
name: 'Release'

needs: [build]

runs-on: ubuntu-latest

if: ${{ startsWith(github.ref, 'refs/tags/') }}

permissions:
contents: write

steps:
- name: Download Artifacts
uses: actions/download-artifact@v3

- name: Create Release
uses: ncipollo/release-action@v1
with:
name: ${{ matrix.platform }}
path: "${{ matrix.platform }}.tar"
# Allow updating existing releases if the workflow is triggered by release creation or re-run.
allowUpdates: true
# When the release is updated, delete the existing artifacts for replacement.
removeArtifacts: true
# If a release is being replaced, omit updating the name and body.
# Allows for creating a release and filling these in before the workflow runs.
# Then, the workflow will populate the release with the artifacts.
omitNameDuringUpdate: true
omitBodyDuringUpdate: true
# Upload all MoltenVK CI artifacts as release assets.
artifacts: "MoltenVK*/*"
artifactErrorsFailBuild: true
31 changes: 26 additions & 5 deletions Common/MVKCommonEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ extern "C" {
# define MVK_TVOS TARGET_OS_TV
#endif

/** Building for visionOS. */
#ifndef TARGET_OS_XR
# define TARGET_OS_XR 0 // Older SDK's don't define TARGET_OS_XR
#endif
#ifndef MVK_VISIONOS
# define MVK_VISIONOS TARGET_OS_XR
#endif

/** Building for iOS or tvOS. */
#ifndef MVK_IOS_OR_TVOS
# define MVK_IOS_OR_TVOS (MVK_IOS || MVK_TVOS)
Expand All @@ -72,6 +80,11 @@ extern "C" {
# define MVK_MACOS_OR_IOS (MVK_MACOS || MVK_IOS)
#endif

/** Building for macOS, iOS or visionOS. */
#ifndef MVK_MACOS_OR_IOS_OR_VISIONOS
# define MVK_MACOS_OR_IOS_OR_VISIONOS (MVK_MACOS || MVK_IOS | MVK_VISIONOS)
#endif

/** Building for a Simulator. */
#ifndef MVK_OS_SIMULATOR
# define MVK_OS_SIMULATOR TARGET_OS_SIMULATOR
Expand All @@ -87,18 +100,26 @@ extern "C" {
# define MVK_MACOS_APPLE_SILICON (MVK_MACOS && MVK_APPLE_SILICON)
#endif

/** Building with Xcode versions. */
/** Building with Xcode versions. iOS version also covers tvOS. */
#ifndef MVK_XCODE_15
# define MVK_XCODE_15 ((__MAC_OS_X_VERSION_MAX_ALLOWED >= 140000) || \
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 170000))
#endif
#ifndef MVK_XCODE_14_3
# define MVK_XCODE_14_3 ((__MAC_OS_X_VERSION_MAX_ALLOWED >= 130300) || \
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 160400))
#endif
#ifndef MVK_XCODE_14
# define MVK_XCODE_14 ((__MAC_OS_X_VERSION_MAX_ALLOWED >= 130000) || \
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 160000)) // Also covers tvOS
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 160000))
#endif
#ifndef MVK_XCODE_13
# define MVK_XCODE_13 ((__MAC_OS_X_VERSION_MAX_ALLOWED >= 120000) || \
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 150000)) // Also covers tvOS
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 150000))
#endif
#ifndef MVK_XCODE_12
# define MVK_XCODE_12 ((__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600) || \
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000)) // Also covers tvOS
# define MVK_XCODE_12 ((__MAC_OS_X_VERSION_MAX_ALLOWED >= 110000) || \
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000))
#endif

/** Directive to identify public symbols. */
Expand Down
23 changes: 21 additions & 2 deletions Common/MVKOSExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ inline bool mvkOSVersionIsAtLeast(MVKOSVersion minVer) { return mvkOSVersion() >
* to always fail on that OS, which is useful for indidicating functionalty guarded by
* this test is not supported on that OS.
*/
inline bool mvkOSVersionIsAtLeast(MVKOSVersion macOSMinVer, MVKOSVersion iOSMinVer) {
inline bool mvkOSVersionIsAtLeast(MVKOSVersion macOSMinVer, MVKOSVersion iOSMinVer, MVKOSVersion visionOSMinVer) {
#if MVK_MACOS
return mvkOSVersionIsAtLeast(macOSMinVer);
#endif
#if MVK_IOS_OR_TVOS
#if MVK_VISIONOS
return mvkOSVersionIsAtLeast(visionOSMinVer);
#elif MVK_IOS_OR_TVOS
return mvkOSVersionIsAtLeast(iOSMinVer);
#endif
}
Expand All @@ -76,6 +78,14 @@ uint64_t mvkGetTimestamp();
/** Returns the number of nanoseconds between each increment of the value returned by mvkGetTimestamp(). */
double mvkGetTimestampPeriod();

/**
* Returns the number of nanoseconds elapsed between startTimestamp and endTimestamp,
* each of which should be a value returned by mvkGetTimestamp().
* If endTimestamp is zero or not supplied, it is taken to be the current time.
* If startTimestamp is zero or not supplied, it is taken to be the time the app was initialized.
*/
uint64_t mvkGetElapsedNanoseconds(uint64_t startTimestamp = 0, uint64_t endTimestamp = 0);

/**
* Returns the number of milliseconds elapsed between startTimestamp and endTimestamp,
* each of which should be a value returned by mvkGetTimestamp().
Expand All @@ -84,6 +94,9 @@ double mvkGetTimestampPeriod();
*/
double mvkGetElapsedMilliseconds(uint64_t startTimestamp = 0, uint64_t endTimestamp = 0);

/** Returns the current absolute time in nanoseconds. */
uint64_t mvkGetAbsoluteTime();

/** Ensures the block is executed on the main thread. */
void mvkDispatchToMainAndWait(dispatch_block_t block);

Expand Down Expand Up @@ -164,3 +177,9 @@ uint64_t mvkGetUsedMemorySize();

/** Returns the size of a page of host memory on this platform. */
uint64_t mvkGetHostMemoryPageSize();

#pragma mark -
#pragma mark Threading

/** Returns the amount of avaliable CPU cores. */
uint32_t mvkGetAvaliableCPUCores();
25 changes: 19 additions & 6 deletions Common/MVKOSExtensions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,23 @@ MVKOSVersion mvkOSVersion() {

static uint64_t _mvkTimestampBase;
static double _mvkTimestampPeriod;
static mach_timebase_info_data_t _mvkMachTimebase;

uint64_t mvkGetTimestamp() { return mach_absolute_time() - _mvkTimestampBase; }

double mvkGetTimestampPeriod() { return _mvkTimestampPeriod; }

double mvkGetElapsedMilliseconds(uint64_t startTimestamp, uint64_t endTimestamp) {
uint64_t mvkGetElapsedNanoseconds(uint64_t startTimestamp, uint64_t endTimestamp) {
if (endTimestamp == 0) { endTimestamp = mvkGetTimestamp(); }
return (double)(endTimestamp - startTimestamp) * _mvkTimestampPeriod / 1e6;
return (endTimestamp - startTimestamp) * _mvkTimestampPeriod;
}

double mvkGetElapsedMilliseconds(uint64_t startTimestamp, uint64_t endTimestamp) {
return mvkGetElapsedNanoseconds(startTimestamp, endTimestamp) / 1e6;
}

uint64_t mvkGetAbsoluteTime() { return mach_continuous_time() * _mvkMachTimebase.numer / _mvkMachTimebase.denom; }

// Initialize timestamping capabilities on app startup.
//Called automatically when the framework is loaded and initialized.
static bool _mvkTimestampsInitialized = false;
Expand All @@ -58,9 +65,8 @@ MVKOSVersion mvkOSVersion() {
_mvkTimestampsInitialized = true;

_mvkTimestampBase = mach_absolute_time();
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
_mvkTimestampPeriod = (double)timebase.numer / (double)timebase.denom;
mach_timebase_info(&_mvkMachTimebase);
_mvkTimestampPeriod = (double)_mvkMachTimebase.numer / (double)_mvkMachTimebase.denom;
}

void mvkDispatchToMainAndWait(dispatch_block_t block) {
Expand Down Expand Up @@ -97,7 +103,7 @@ bool mvkGetEnvVarBool(std::string varName, bool* pWasFound) {
#pragma mark System memory

uint64_t mvkGetSystemMemorySize() {
#if MVK_MACOS_OR_IOS
#if MVK_MACOS_OR_IOS_OR_VISIONOS
mach_msg_type_number_t host_size = HOST_BASIC_INFO_COUNT;
host_basic_info_data_t info;
if (host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&info, &host_size) == KERN_SUCCESS) {
Expand Down Expand Up @@ -138,3 +144,10 @@ uint64_t mvkGetUsedMemorySize() {

uint64_t mvkGetHostMemoryPageSize() { return sysconf(_SC_PAGESIZE); }

#pragma mark -
#pragma mark Threading

/** Returns the amount of avaliable CPU cores. */
uint32_t mvkGetAvaliableCPUCores() {
return (uint32_t)[[NSProcessInfo processInfo] activeProcessorCount];
}
22 changes: 22 additions & 0 deletions Common/MVKStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <string>
#include <streambuf>
#include <vector>
#include <cxxabi.h>

namespace mvk {

Expand Down Expand Up @@ -59,6 +61,26 @@ namespace mvk {
return varName;
}

/** Returns a string containing the ordinal suffix for a numeric value.*/
inline const char* getOrdinalSuffix(int64_t val) {
static const char* suffixes[] = {"th", "st", "nd", "rd"};
auto ord = val % 100;
if (ord > 10 && ord < 20) { return suffixes[0]; } // All teens end in th.
ord = ord % 10;
if (ord > 3) { return suffixes[0]; } // 4-9 end in th.
return suffixes[ord];
}

/** Returns the name of a C++ type. */
template<typename T>
inline std::string getTypeName(const T* pObj) {
int status;
char* demangledName = abi::__cxa_demangle(typeid(*pObj).name(), 0, 0, &status);
std::string tName = demangledName;
free(demangledName);
return tName;
}


#pragma mark -
#pragma mark Streams
Expand Down
24 changes: 20 additions & 4 deletions Demos/Cube/macOS/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,29 @@ -(void) viewDidLoad {

self.view.wantsLayer = YES; // Back the view with a layer created by the makeBackingLayer method.

const char* argv[] = { "cube" };
// Enabling this will sync the rendering loop with the natural display link (60 fps).
// Disabling this will allow the rendering loop to run flat out, limited only by the rendering speed.
bool useDisplayLink = true;

VkPresentModeKHR vkPresentMode = useDisplayLink ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_IMMEDIATE_KHR;
char vkPresentModeStr[64];
sprintf(vkPresentModeStr, "%d", vkPresentMode);

const char* argv[] = { "cube", "--present_mode", vkPresentModeStr };
int argc = sizeof(argv)/sizeof(char*);
demo_main(&demo, self.view.layer, argc, argv);

CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
CVDisplayLinkSetOutputCallback(_displayLink, &DisplayLinkCallback, &demo);
CVDisplayLinkStart(_displayLink);
if (useDisplayLink) {
CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
CVDisplayLinkSetOutputCallback(_displayLink, &DisplayLinkCallback, &demo);
CVDisplayLinkStart(_displayLink);
} else {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
while(true) {
demo_draw(&demo);
}
});
}
}


Expand Down
Loading
Loading