Skip to content

Commit

Permalink
Revert "Merge branch 'main' into khr-acceleration-structures"
Browse files Browse the repository at this point in the history
This reverts commit a7569c1, reversing
changes made to 1cf021e.
  • Loading branch information
AntarticCoder committed Nov 12, 2023
1 parent a7569c1 commit edf5303
Show file tree
Hide file tree
Showing 89 changed files with 2,418 additions and 4,013 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ on:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
# See the following, which includes links to supported macOS versions, including supported Xcode versions
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
jobs:
build:
strategy:
matrix:
xcode: [ "15.0" ]
xcode: [ "14.3.1" ]
platform: [ "all", "macos", "ios" ]
os: [ "macos-13" ]
upload_artifacts: [ true ]
Expand All @@ -39,11 +39,6 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Python 3.12 removed distutils, which is used by glslang::update_glslang_sources.py called from fetchDependencies
- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Select Xcode version
run: sudo xcode-select -switch "${XCODE_DEV_PATH}"

Expand Down
73 changes: 55 additions & 18 deletions Common/MVKOSExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,27 @@ static const MVKOSVersion kMVKOSVersionUnsupported = std::numeric_limits<MVKOSVe
MVKOSVersion mvkOSVersion();

/** Returns a MVKOSVersion built from the version components. */
static inline MVKOSVersion mvkMakeOSVersion(uint32_t major, uint32_t minor, uint32_t patch) {
inline MVKOSVersion mvkMakeOSVersion(uint32_t major, uint32_t minor, uint32_t patch) {
return (float)major + ((float)minor / 100.0f) + ((float)patch / 10000.0f);
}

/** Returns whether the operating system version is at least minVer. */
static inline bool mvkOSVersionIsAtLeast(MVKOSVersion minVer) { return mvkOSVersion() >= minVer; }
inline bool mvkOSVersionIsAtLeast(MVKOSVersion minVer) { return mvkOSVersion() >= minVer; }

/**
* Returns whether the operating system version is at least the appropriate min version.
* The constant kMVKOSVersionUnsupported can be used for any of the values to cause the test
* to always fail on that OS, which is useful for indicating that functionalty guarded by
* The constant kMVKOSVersionUnsupported can be used for either value to cause the test
* to always fail on that OS, which is useful for indidicating functionalty guarded by
* this test is not supported on that OS.
*/
static inline bool mvkOSVersionIsAtLeast(MVKOSVersion macOSMinVer,
MVKOSVersion iOSMinVer,
MVKOSVersion visionOSMinVer) {
inline bool mvkOSVersionIsAtLeast(MVKOSVersion macOSMinVer, MVKOSVersion iOSMinVer, MVKOSVersion visionOSMinVer) {
#if MVK_MACOS
return mvkOSVersionIsAtLeast(macOSMinVer);
#endif
#if MVK_IOS_OR_TVOS
return mvkOSVersionIsAtLeast(iOSMinVer);
#endif
#if MVK_VISIONOS
return mvkOSVersionIsAtLeast(visionOSMinVer);
#elif MVK_IOS_OR_TVOS
return mvkOSVersionIsAtLeast(iOSMinVer);
#endif
}

Expand Down Expand Up @@ -108,22 +105,62 @@ void mvkDispatchToMainAndWait(dispatch_block_t block);
#pragma mark Process environment

/**
* Sets the value of the environment variable at the given name, into the
* std::string, and returns whether the environment variable was found.
* Returns the value of the environment variable at the given name,
* or an empty string if no environment variable with that name exists.
*
* If pWasFound is not null, its value is set to true if the environment
* variable exists, or false if not.
*/
bool mvkGetEnvVar(const char* evName, std::string& evStr);
std::string mvkGetEnvVar(std::string varName, bool* pWasFound = nullptr);

/**
* Returns a pointer to a string containing the value of the environment variable at
* the given name, or returns the default value if the environment variable was not set.
* Returns the value of the environment variable at the given name,
* or zero if no environment variable with that name exists.
*
* If pWasFound is not null, its value is set to true if the environment
* variable exists, or false if not.
*/
const char* mvkGetEnvVarString(const char* evName, std::string& evStr, const char* defaultValue = "");
int64_t mvkGetEnvVarInt64(std::string varName, bool* pWasFound = nullptr);

/**
* Returns the value of the environment variable at the given name,
* or returns the default value if the environment variable was not set.
* or false if no environment variable with that name exists.
*
* If pWasFound is not null, its value is set to true if the environment
* variable exists, or false if not.
*/
double mvkGetEnvVarNumber(const char* evName, double defaultValue = 0.0);
bool mvkGetEnvVarBool(std::string varName, bool* pWasFound = nullptr);

#define MVK_SET_FROM_ENV_OR_BUILD_BOOL(cfgVal, EV) \
do { \
bool wasFound = false; \
bool ev = mvkGetEnvVarBool(#EV, &wasFound); \
cfgVal = wasFound ? ev : EV; \
} while(false)

#define MVK_SET_FROM_ENV_OR_BUILD_INT64(cfgVal, EV) \
do { \
bool wasFound = false; \
int64_t ev = mvkGetEnvVarInt64(#EV, &wasFound); \
cfgVal = wasFound ? ev : EV; \
} while(false)

// Pointer cast permits cfgVal to be an enum var
#define MVK_SET_FROM_ENV_OR_BUILD_INT32(cfgVal, EV) \
do { \
bool wasFound = false; \
int64_t ev = mvkGetEnvVarInt64(#EV, &wasFound); \
int64_t val = wasFound ? ev : EV; \
*(int32_t*)&cfgVal = (int32_t)std::min(std::max(val, (int64_t)INT32_MIN), (int64_t)INT32_MAX); \
} while(false)

#define MVK_SET_FROM_ENV_OR_BUILD_STRING(cfgVal, EV, strObj) \
do { \
bool wasFound = false; \
std::string ev = mvkGetEnvVar(#EV, &wasFound); \
strObj = wasFound ? std::move(ev) : EV; \
cfgVal = strObj.c_str(); \
} while(false)


#pragma mark -
Expand Down
17 changes: 8 additions & 9 deletions Common/MVKOSExtensions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,21 @@ void mvkDispatchToMainAndWait(dispatch_block_t block) {
#pragma mark -
#pragma mark Process environment

bool mvkGetEnvVar(const char* varName, string& evStr) {
string mvkGetEnvVar(string varName, bool* pWasFound) {
@autoreleasepool {
NSDictionary* nsEnv = [[NSProcessInfo processInfo] environment];
NSString* nsStr = nsEnv[@(varName)];
if (nsStr) { evStr = nsStr.UTF8String; }
return nsStr != nil;
NSString* envStr = nsEnv[@(varName.c_str())];
if (pWasFound) { *pWasFound = envStr != nil; }
return envStr ? envStr.UTF8String : "";
}
}

const char* mvkGetEnvVarString(const char* varName, string& evStr, const char* defaultValue) {
return mvkGetEnvVar(varName, evStr) ? evStr.c_str() : defaultValue;
int64_t mvkGetEnvVarInt64(string varName, bool* pWasFound) {
return strtoll(mvkGetEnvVar(varName, pWasFound).c_str(), NULL, 0);
}

double mvkGetEnvVarNumber(const char* varName, double defaultValue) {
string evStr;
return mvkGetEnvVar(varName, evStr) ? strtod(evStr.c_str(), nullptr) : defaultValue;
bool mvkGetEnvVarBool(std::string varName, bool* pWasFound) {
return mvkGetEnvVarInt64(varName, pWasFound) != 0;
}


Expand Down
2 changes: 1 addition & 1 deletion Demos/Cube/Cube.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
Expand Down
19 changes: 9 additions & 10 deletions Demos/Cube/iOS/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ @implementation DemoViewController {
struct demo demo;
}

/** Since this is a single-view app, initialize Vulkan as view is appearing. */
-(void) viewWillAppear: (BOOL) animated {
[super viewWillAppear: animated];
-(void) dealloc {
demo_cleanup(&demo);
[_displayLink release];
[super dealloc];
}

/** Since this is a single-view app, init Vulkan when the view is loaded. */
-(void) viewDidLoad {
[super viewDidLoad];

self.view.contentScaleFactor = UIScreen.mainScreen.nativeScale;

Expand Down Expand Up @@ -62,13 +68,6 @@ -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coord
demo_resize(&demo);
}

-(void) viewDidDisappear: (BOOL) animated {
[_displayLink invalidate];
[_displayLink release];
demo_cleanup(&demo);
[super viewDidDisappear: animated];
}

@end


Expand Down
64 changes: 19 additions & 45 deletions Demos/Cube/macOS/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#import "DemoViewController.h"
#import <QuartzCore/CAMetalLayer.h>
#import <CoreVideo/CVDisplayLink.h>

#include <MoltenVK/mvk_vulkan.h>
#include "../../Vulkan-Tools/cube/cube.c"
Expand All @@ -28,68 +27,47 @@
#pragma mark DemoViewController

@implementation DemoViewController {
CVDisplayLinkRef _displayLink;
CVDisplayLinkRef _displayLink;
struct demo demo;
uint32_t _maxFrameCount;
uint64_t _frameCount;
BOOL _stop;
BOOL _useDisplayLink;
}

/** Since this is a single-view app, initialize Vulkan as view is appearing. */
-(void) viewWillAppear {
[super viewWillAppear];
-(void) dealloc {
demo_cleanup(&demo);
CVDisplayLinkRelease(_displayLink);
[super dealloc];
}

self.view.wantsLayer = YES; // Back the view with a layer created by the makeBackingLayer method.
/** Since this is a single-view app, initialize Vulkan during view loading. */
-(void) viewDidLoad {
[super viewDidLoad];

// Enabling this will sync the rendering loop with the natural display link
// (monitor refresh rate, typically 60 fps). Disabling this will allow the
// rendering loop to run flat out, limited only by the rendering speed.
_useDisplayLink = YES;
self.view.wantsLayer = YES; // Back the view with a layer created by the makeBackingLayer method.

// If this value is set to zero, the demo will render frames until the window is closed.
// If this value is not zero, it establishes a maximum number of frames that will be
// rendered, and once this count has been reached, the demo will stop rendering.
// Once rendering is finished, if _useDisplayLink is false, the demo will immediately
// clean up the Vulkan objects, or if _useDisplayLink is true, the demo will delay
// cleaning up Vulkan objects until the window is closed.
_maxFrameCount = 0;
// 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;
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);

_stop = NO;
_frameCount = 0;
if (_useDisplayLink) {
if (useDisplayLink) {
CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
CVDisplayLinkSetOutputCallback(_displayLink, &DisplayLinkCallback, self);
CVDisplayLinkSetOutputCallback(_displayLink, &DisplayLinkCallback, &demo);
CVDisplayLinkStart(_displayLink);
} else {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
do {
while(true) {
demo_draw(&demo);
_stop = _stop || (_maxFrameCount && ++_frameCount >= _maxFrameCount);
} while( !_stop );
demo_cleanup(&demo);
}
});
}
}

-(void) viewDidDisappear {
_stop = YES;
if (_useDisplayLink) {
CVDisplayLinkRelease(_displayLink);
demo_cleanup(&demo);
}

[super viewDidDisappear];
}


#pragma mark Display loop callback function

Expand All @@ -100,11 +78,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink,
CVOptionFlags flagsIn,
CVOptionFlags* flagsOut,
void* target) {
DemoViewController* demoVC =(DemoViewController*)target;
if ( !demoVC->_stop ) {
demo_draw(&demoVC->demo);
demoVC->_stop = (demoVC->_maxFrameCount && ++demoVC->_frameCount >= demoVC->_maxFrameCount);
}
demo_draw((struct demo*)target);
return kCVReturnSuccess;
}

Expand Down
Loading

0 comments on commit edf5303

Please sign in to comment.