From eb99488f042ed05f0f7cfca142b2c8ad4cd3b4d4 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Sat, 11 Apr 2020 16:19:03 -0400 Subject: [PATCH] Reinstate VulkanSamples API-Samples demo apps. MVKShaderConverterTool add support to output SPIR-V as header (.h) files. Add MVKShaderConverterTool Xcode target. Add MVKShaderConverterTool Package Xcode scheme. fetchDependencies builds MVKShaderConverterTool and runs it on shader files in VulkanSamples API-Samples directory. --- Common/MVKStrings.h | 31 +++++++++ .../contents.xcworkspacedata | 3 + .../API-Samples/Samples.h | 2 + Demos/README.md | 54 +++++++-------- MoltenVKPackaging.xcodeproj/project.pbxproj | 62 +++++++++++++++++ .../MVKShaderConverterTool Package.xcscheme | 67 +++++++++++++++++++ .../Common/SPIRVSupport.cpp | 23 +++++++ MoltenVKShaderConverter/Common/SPIRVSupport.h | 6 ++ .../MoltenVKSPIRVToMSLConverter/FileSupport.h | 4 +- .../FileSupport.mm | 6 +- .../MoltenVKShaderConverterTool.cpp | 65 +++++++++++++----- .../MoltenVKShaderConverterTool.h | 3 + fetchDependencies | 23 +++++++ 13 files changed, 298 insertions(+), 51 deletions(-) create mode 100644 MoltenVKPackaging.xcodeproj/xcshareddata/xcschemes/MVKShaderConverterTool Package.xcscheme diff --git a/Common/MVKStrings.h b/Common/MVKStrings.h index ded1cf79..3fdb96c8 100644 --- a/Common/MVKStrings.h +++ b/Common/MVKStrings.h @@ -24,6 +24,9 @@ namespace mvk { +#pragma mark - +#pragma mark Strings + static std::string _mvkDefaultWhitespaceChars = " \f\n\r\t\v"; /** Returns a string with whitespace trimmed from the right end of the specified string. */ @@ -45,6 +48,21 @@ namespace mvk { return ( (startPos != std::string::npos) && (endPos != std::string::npos) ) ? s.substr(startPos, endPos + 1) : ""; } + /** Cleanse variable name by replacing any illegal chars and leading digit with underscores. */ + inline std::string cleanseVarName(const std::string& name) { + std::string varName(name); + size_t cCnt = varName.length(); + for (size_t cIdx = 0; cIdx < cCnt; cIdx++) { + char& c = varName[cIdx]; + if ( !(c == '_' || isalpha(c) || (isdigit(c) && cIdx > 0)) ) { c = '_'; } + } + return varName; + } + + +#pragma mark - +#pragma mark Streams + /** A memory-based stream buffer. */ class membuf : public std::streambuf { public: @@ -65,6 +83,19 @@ namespace mvk { } }; + /** A stream buffer underpinned by a vector. */ + class charvectorbuf : public std::streambuf { + public: + charvectorbuf(std::vector* pVec) : _pVec(pVec) {} + private: + std::streamsize xsputn (const char* s, std::streamsize n) override { + _pVec->insert(_pVec->end(), s, s + n); + return n; + } + + std::vector* _pVec; + }; + } #endif diff --git a/Demos/Demos.xcworkspace/contents.xcworkspacedata b/Demos/Demos.xcworkspace/contents.xcworkspacedata index c306685b..4a9447fc 100644 --- a/Demos/Demos.xcworkspace/contents.xcworkspacedata +++ b/Demos/Demos.xcworkspace/contents.xcworkspacedata @@ -13,5 +13,8 @@ + + diff --git a/Demos/LunarG-VulkanSamples/API-Samples/Samples.h b/Demos/LunarG-VulkanSamples/API-Samples/Samples.h index 4647e582..3587dd05 100644 --- a/Demos/LunarG-VulkanSamples/API-Samples/Samples.h +++ b/Demos/LunarG-VulkanSamples/API-Samples/Samples.h @@ -39,6 +39,8 @@ #ifdef MVK_SAMP_15_draw_cube +# define _5_draw_cube_vert __draw_cube_vert +# define _5_draw_cube_frag __draw_cube_frag # include "../VulkanSamples/API-Samples/15-draw_cube/15-draw_cube.cpp" #endif diff --git a/Demos/README.md b/Demos/README.md index 3b33c84e..91ae1367 100644 --- a/Demos/README.md +++ b/Demos/README.md @@ -18,8 +18,8 @@ Table of Contents - [LunarG Vulkan Samples](#lunarg-vulkan-samples) - [*Cube*](#lunarg-vulkan-samples-cube) - - [*API-Samples*](#lunarg-vulkan-samples-api) - [*Hologram*](#lunarg-vulkan-samples-hologram) + - [*API-Samples*](#lunarg-vulkan-samples-api) - [Sascha Willems Vulkan Samples](#sascha-willems-vulkan-samples) - [Installing the *Sascha Willems* Library](#sascha-willems-install) - [Cinder Vulkan Samples](#cinder-vulkan-samples) @@ -60,15 +60,33 @@ the **MoltenVK** *dynamic library* is embedded in the application, but it could as a system library instead. + +### *Hologram* + +> **_Note:_** In order to build the `Hologram` demo, you must have *Python3* installed +> on your build computer. + +This is a sophisticated particle demo that populates command buffers from multiple threads. + +This demo can be found in the `LunarG-VulkanSamples/Hologram` folder, and in the +`LunarG-VulkanSamples/Hologram` group in the *Xcode Project Navigator* in the +`Demos.xcworkspace` *Xcode* workspace. + +To run this demo, run either the `Hologram-iOS` or `Hologram-macOS` *Scheme* from within *Xcode*. + +On *macOS*, once the demo is open, you can use the *Up-arrow* and *Down-arrow* keys on the +keyboard to zoom the camera in and out of the scene. Zooming out will show more items on screen. + +The demo allows some customization, by modifying the arguments passed to the demo at startup. +To customize, modify the arguments created in the `DemoViewController viewDidLoad` method +found in the `iOS/DemoViewController.mm` or `macOS/DemoViewController.mm` file. + +The `Hologram` demo is a simple example of installing **MoltenVK** as a *static library*. + ### *API-Samples* -> **_Note:_** The `Vulkan-Samples API-Samples` have recently changed to use a different build - process that involves converting GLSL to SPIR-V via scripts. This upgrade has not yet been - integrated into the *Xcode*-based build environment used to build these demos here. - As a result, the `API-Samples` demos have been disabled here until this can be corrected. - This *Xcode* project contains a large number of modular demos, with each demo demonstrating a particular *Vulkan* feature, or suite of calls. @@ -93,30 +111,6 @@ To see descriptions and screenshots of each of the demos, open The `API-Samples` demo is a simple example of installing **MoltenVK** as a *static framework*. - -### *Hologram* - -> **_Note:_** In order to build the `Hologram` demo, you must have *Python3* installed -> on your build computer. - -This is a sophisticated particle demo that populates command buffers from multiple threads. - -This demo can be found in the `LunarG-VulkanSamples/Hologram` folder, and in the -`LunarG-VulkanSamples/Hologram` group in the *Xcode Project Navigator* in the -`Demos.xcworkspace` *Xcode* workspace. - -To run this demo, run either the `Hologram-iOS` or `Hologram-macOS` *Scheme* from within *Xcode*. - -On *macOS*, once the demo is open, you can use the *Up-arrow* and *Down-arrow* keys on the -keyboard to zoom the camera in and out of the scene. Zooming out will show more items on screen. - -The demo allows some customization, by modifying the arguments passed to the demo at startup. -To customize, modify the arguments created in the `DemoViewController viewDidLoad` method -found in the `iOS/DemoViewController.mm` or `macOS/DemoViewController.mm` file. - -The `Hologram` demo is a simple example of installing **MoltenVK** as a *static library*. - - Sascha Willems Vulkan Samples diff --git a/MoltenVKPackaging.xcodeproj/project.pbxproj b/MoltenVKPackaging.xcodeproj/project.pbxproj index 39f73fbf..a6599f18 100644 --- a/MoltenVKPackaging.xcodeproj/project.pbxproj +++ b/MoltenVKPackaging.xcodeproj/project.pbxproj @@ -33,6 +33,18 @@ name = "MoltenVK-macOS"; productName = Package; }; + A9AD700D2440ED3B00B9E254 /* MVKShaderConverterTool */ = { + isa = PBXAggregateTarget; + buildConfigurationList = A9AD70132440ED3B00B9E254 /* Build configuration list for PBXAggregateTarget "MVKShaderConverterTool" */; + buildPhases = ( + A9AD70122440ED3B00B9E254 /* Package MoltenVK */, + ); + dependencies = ( + A9AD70102440ED3B00B9E254 /* PBXTargetDependency */, + ); + name = MVKShaderConverterTool; + productName = Package; + }; A9FEADBC1F3517480010240E /* MoltenVK */ = { isa = PBXAggregateTarget; buildConfigurationList = A9FEADDC1F3517480010240E /* Build configuration list for PBXAggregateTarget "MoltenVK" */; @@ -125,6 +137,13 @@ remoteGlobalIDString = A93903C71C57E9ED00FE90DC; remoteInfo = "MoltenVKSPIRVToMSLConverter-macOS"; }; + A9AD70112440ED3B00B9E254 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A92DB40E1CE0F89600FBC835 /* MoltenVKShaderConverter.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = A9092A8C1A81717B00051823; + remoteInfo = MoltenVKShaderConverter; + }; A9AFC25F2184EEF60084B396 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = A90B2B1D1A9B6170008EE819 /* Project object */; @@ -280,6 +299,7 @@ A9FEADBC1F3517480010240E /* MoltenVK */, A975D5782140585200D4834F /* MoltenVK-iOS */, A975D58B2140586700D4834F /* MoltenVK-macOS */, + A9AD700D2440ED3B00B9E254 /* MVKShaderConverterTool */, ); }; /* End PBXProject section */ @@ -365,6 +385,20 @@ shellPath = /bin/sh; shellScript = "\"${SRCROOT}/Scripts/package_macos.sh\"\n"; }; + A9AD70122440ED3B00B9E254 /* Package MoltenVK */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Package MoltenVK"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "export MVK_BUILT_PROD_PATH=\"${BUILT_PRODUCTS_DIR}\"\n\"${SRCROOT}/Scripts/package_shader_converter_tool.sh\"\n\"${SRCROOT}/Scripts/package_update_latest.sh\"\n"; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -388,6 +422,11 @@ name = MoltenVKShaderConverter; targetProxy = A975D5992140586700D4834F /* PBXContainerItemProxy */; }; + A9AD70102440ED3B00B9E254 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = MoltenVKShaderConverter; + targetProxy = A9AD70112440ED3B00B9E254 /* PBXContainerItemProxy */; + }; A9AFC2602184EEF60084B396 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = A975D5782140585200D4834F /* MoltenVK-iOS */; @@ -441,6 +480,20 @@ }; name = Release; }; + A9AD70142440ED3B00B9E254 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + A9AD70152440ED3B00B9E254 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; A9FEADDD1F3517480010240E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -485,6 +538,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + A9AD70132440ED3B00B9E254 /* Build configuration list for PBXAggregateTarget "MVKShaderConverterTool" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A9AD70142440ED3B00B9E254 /* Debug */, + A9AD70152440ED3B00B9E254 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; A9FEADDC1F3517480010240E /* Build configuration list for PBXAggregateTarget "MoltenVK" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/MoltenVKPackaging.xcodeproj/xcshareddata/xcschemes/MVKShaderConverterTool Package.xcscheme b/MoltenVKPackaging.xcodeproj/xcshareddata/xcschemes/MVKShaderConverterTool Package.xcscheme new file mode 100644 index 00000000..f1086b58 --- /dev/null +++ b/MoltenVKPackaging.xcodeproj/xcshareddata/xcschemes/MVKShaderConverterTool Package.xcscheme @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MoltenVKShaderConverter/Common/SPIRVSupport.cpp b/MoltenVKShaderConverter/Common/SPIRVSupport.cpp index bfaeb41e..3e189b5a 100644 --- a/MoltenVKShaderConverter/Common/SPIRVSupport.cpp +++ b/MoltenVKShaderConverter/Common/SPIRVSupport.cpp @@ -17,7 +17,10 @@ */ #include "SPIRVSupport.h" +#include "MVKStrings.h" #include +#include + #import using namespace mvk; @@ -31,6 +34,26 @@ void mvk::spirvToBytes(const vector& spv, vector& bytes) { bytes.insert(bytes.end(), cBytes, cBytes + byteCnt); } +void mvk::spirvToHeaderBytes(const vector& spv, vector& bytes, const string& varName) { + bytes.clear(); + charvectorbuf cb(&bytes); + ostream hdr(&cb); + size_t spvCnt = spv.size(); + + hdr << "// Automatically generated. Do not edit.\n\n"; + hdr << "#include \n\n"; + hdr << "\tstatic const uint32_t " << cleanseVarName(varName) << '[' << spvCnt << "] = {"; + + // Output the SPIR-V content, 8 elements per line + if (spvCnt > 0) { + hdr << "\n\t\t" << spv.front(); + for (size_t spvIdx = 1; spvIdx < spvCnt; spvIdx++) { + hdr << (spvIdx % 8 ? ", " : ",\n\t\t") << spv[spvIdx]; + } + } + hdr << "\n\t};\n"; +} + void mvk::bytesToSPIRV(const vector& bytes, vector& spv) { size_t spvCnt = bytes.size() / sizeof(uint32_t); uint32_t* cSPV = (uint32_t*)bytes.data(); diff --git a/MoltenVKShaderConverter/Common/SPIRVSupport.h b/MoltenVKShaderConverter/Common/SPIRVSupport.h index 0677b1f1..4740cfa1 100644 --- a/MoltenVKShaderConverter/Common/SPIRVSupport.h +++ b/MoltenVKShaderConverter/Common/SPIRVSupport.h @@ -30,6 +30,12 @@ namespace mvk { /** Converts the SPIR-V code to an array of bytes (suitable for writing to a file). */ void spirvToBytes(const std::vector& spv, std::vector& bytes); + /** + * Converts the SPIR-V code to header content (suitable for writing to a file) + * with the SPIR-V content assigned to a named uint32_t variable. + */ + void spirvToHeaderBytes(const std::vector& spv, std::vector& bytes, const std::string& varName); + /** Converts an array of bytes (as read from a file) to SPIR-V code. */ void bytesToSPIRV(const std::vector& bytes, std::vector& spv); diff --git a/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/FileSupport.h b/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/FileSupport.h index 80db7a32..dcc24743 100644 --- a/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/FileSupport.h +++ b/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/FileSupport.h @@ -29,8 +29,8 @@ namespace mvk { /** Returns an absolute path from the specified path, which may be absolute or relative. */ std::string absolutePath(const std::string& path); - /** Returns the last component of the specified path. */ - std::string lastPathComponent(const std::string& path); + /** Returns the file name from the path, with or without the file extension. */ + std::string fileName(const std::string& path, bool includeExtenison = true); /** Returns the extension component (after the .) of the specified path. */ std::string pathExtension(const std::string& path); diff --git a/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/FileSupport.mm b/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/FileSupport.mm index 782313af..bf77bdd4 100644 --- a/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/FileSupport.mm +++ b/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/FileSupport.mm @@ -33,9 +33,11 @@ MVK_PUBLIC_SYMBOL string mvk::absolutePath(const string& path) { return nsPath.UTF8String; } -MVK_PUBLIC_SYMBOL string mvk::lastPathComponent(const string& path) { +MVK_PUBLIC_SYMBOL string mvk::fileName(const string& path, bool includeExtension) { NSString* nsPath = @(path.data()); - return nsPath.lastPathComponent.UTF8String; + NSString* fName = nsPath.lastPathComponent; + if ( !includeExtension ) { fName = fName.stringByDeletingPathExtension; } + return fName.UTF8String; } MVK_PUBLIC_SYMBOL string mvk::pathExtension(const string& path) { diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.cpp b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.cpp index 5815cae5..882f85ee 100644 --- a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.cpp +++ b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.cpp @@ -111,7 +111,7 @@ bool MoltenVKShaderConverterTool::convertGLSL(string& glslInFile, path = glslInFile; if (readFile(path, fileContents, errMsg)) { - string logMsg = "Read GLSL from file: " + lastPathComponent(path); + string logMsg = "Read GLSL from file: " + fileName(path); log(logMsg.data()); } else { errMsg = "Could not read GLSL file. " + errMsg; @@ -153,11 +153,16 @@ bool MoltenVKShaderConverterTool::convertGLSL(string& glslInFile, // If no file has been supplied, create one from the GLSL file name. if (_shouldWriteSPIRV) { path = spvOutFile; - if (path.empty()) { path = pathWithExtension(glslInFile, "spv", _shouldIncludeOrigPathExtn, _origPathExtnSep); } + if (path.empty()) { path = pathWithExtension(glslInFile, _shouldOutputAsHeaders ? "h" : "spv", + _shouldIncludeOrigPathExtn, _origPathExtnSep); } + if (_shouldOutputAsHeaders) { + spirvToHeaderBytes(spv, fileContents, fileName(path, false)); + } else { + spirvToBytes(spv, fileContents); + } - spirvToBytes(spv, fileContents); if (writeFile(path, fileContents, errMsg)) { - string logMsg = "Saved SPIR-V to file: " + lastPathComponent(path); + string logMsg = "Saved SPIR-V to file: " + fileName(path); log(logMsg.data()); } else { errMsg = "Could not write SPIR-V file. " + errMsg; @@ -184,7 +189,7 @@ bool MoltenVKShaderConverterTool::convertSPIRV(string& spvInFile, string& mslOut path = spvInFile; if (readFile(path, fileContents, errMsg)) { - string logMsg = "Read SPIR-V from file: " + lastPathComponent(path); + string logMsg = "Read SPIR-V from file: " + fileName(path); log(logMsg.data()); } else { errMsg = "Could not read SPIR-V file. " + errMsg; @@ -244,7 +249,7 @@ bool MoltenVKShaderConverterTool::convertSPIRV(const vector& spv, fileContents.insert(fileContents.end(), msl.begin(), msl.end()); string writeErrMsg; if (writeFile(path, fileContents, writeErrMsg)) { - string logMsg = "Saved MSL to file: " + lastPathComponent(path); + string logMsg = "Saved MSL to file: " + fileName(path); log(logMsg.c_str()); return true; } else { @@ -274,10 +279,15 @@ bool MoltenVKShaderConverterTool::isSPIRVFileExtension(string& pathExtension) { } // Log the specified message to the console. -void MoltenVKShaderConverterTool::log(const char* logMsg) { printf("%s\n", logMsg); } +void MoltenVKShaderConverterTool::log(const char* logMsg) { + if ( !_quietMode ) { printf("%s\n", logMsg); } +} // Display usage information about this application on the console. void MoltenVKShaderConverterTool::showUsage() { + bool qm = _quietMode; + _quietMode = false; + string line = "\n\e[1m" + _processName + "\e[0m converts OpenGL Shading Language (GLSL) source code to"; log((const char*)line.c_str()); log("SPIR-V code, and/or to Metal Shading Language (MSL) source code, or converts"); @@ -294,21 +304,21 @@ void MoltenVKShaderConverterTool::showUsage() { log(" the current working directory."); log(" -r - (when using -d) Process directories recursively."); log(" -gi [\"glslInFile\"] - Indicates that GLSL shader code should be input."); - log(" The optional path parameter specifies the path to a"); + log(" The optional glslInFile parameter specifies the path to a"); log(" single file containing GLSL source code to be converted."); - log(" When using the -d option, the path parameter is ignored."); + log(" When using the -d option, the glslInFile parameter is ignored."); log(" -si [\"spvInFile\"] - Indicates that SPIR-V shader code should be input."); - log(" The optional path parameter specifies the path to a"); + log(" The optional spvInFile parameter specifies the path to a"); log(" single file containing SPIR-V code to be converted."); - log(" When using the -d option, the path parameter is ignored."); + log(" When using the -d option, the spvInFile parameter is ignored."); log(" -so [\"spvOutFile\"] - Indicates that SPIR-V shader code should be output."); - log(" The optional path parameter specifies the path to a single"); + log(" The optional spvOutFile parameter specifies the path to a single"); log(" file to contain the SPIR-V code. When using the -d option,"); - log(" the path parameter is ignored."); + log(" the spvOutFile parameter is ignored."); log(" -mo [\"mslOutFile\"] - Indicates that MSL shader source code should be output."); - log(" The optional path parameter specifies the path to a single"); + log(" The optional mslOutFile parameter specifies the path to a single"); log(" file to contain the MSL code. When using the -d option,"); - log(" the path parameter is ignored."); + log(" the mslOutFile parameter is ignored."); log(" -mv mslVersion - MSL version to output."); log(" Must be in form n[.n][.n] (eg. 2, 2.1, or 2.1.0)."); log(" Defaults to the most recent MSL version for the platform"); @@ -319,6 +329,11 @@ void MoltenVKShaderConverterTool::showUsage() { log(" May be omitted to auto-detect."); log(" -c - Combine the GLSL and converted Metal Shader source code"); log(" into a single ouput file."); + log(" -oh [varName] - Save the output as header (.h) files."); + log(" Affects the output of the -so option."); + log(" The optional varName parameter specifies the name of the"); + log(" variable in the header file to which the output code is assigned."); + log(" When using the -d option, the varName parameter is ignored."); log(" -Iv - Disable inversion of the vertex coordinate Y-axis"); log(" (default is to invert vertex coordinates)."); log(" -xs \"xtnSep\" - Separator to use when including file extension of original"); @@ -337,7 +352,10 @@ void MoltenVKShaderConverterTool::showUsage() { log(" May be omitted for defaults (\"spv spirv\")."); log(" -l - Log the conversion results to the console (to aid debugging)."); log(" -p - Log the performance of the shader conversions."); + log(" -q - Quiet mode. Stops logging of informational messages."); log(""); + + _quietMode = qm; } void MoltenVKShaderConverterTool::reportPerformance() { @@ -383,9 +401,11 @@ MoltenVKShaderConverterTool::MoltenVKShaderConverterTool(int argc, const char* a _shouldIncludeOrigPathExtn = true; _shouldLogConversions = false; _shouldReportPerformance = false; + _shouldOutputAsHeaders = false; + _quietMode = false; _mslVersionMajor = 2; - _mslVersionMinor = 1; + _mslVersionMinor = 2; _mslVersionPatch = 0; _mslPlatform = SPIRVToMSLConversionOptions().mslOptions.platform; @@ -397,7 +417,7 @@ bool MoltenVKShaderConverterTool::parseArgs(int argc, const char* argv[]) { if (argc == 0) { return false; } string execPath(argv[0]); - _processName = lastPathComponent(execPath); + _processName = fileName(execPath, false); for (int argIdx = 1; argIdx < argc; argIdx++) { string arg = argv[argIdx]; @@ -501,6 +521,12 @@ bool MoltenVKShaderConverterTool::parseArgs(int argc, const char* argv[]) { continue; } + if(equal(arg, "-oh", true)) { + _shouldOutputAsHeaders = true; + argIdx = optionalParam(_hdrOutVarName, argIdx, argc, argv); + continue; + } + if(equal(arg, "-Iv", true)) { _shouldFlipVertexY = false; continue; @@ -564,6 +590,11 @@ bool MoltenVKShaderConverterTool::parseArgs(int argc, const char* argv[]) { continue; } + if(equal(arg, "-q", true)) { + _quietMode = true; + continue; + } + } return true; diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.h b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.h index 09b7e570..b8714bf0 100644 --- a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.h +++ b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.h @@ -95,6 +95,7 @@ namespace mvk { std::string _spvInFilePath; std::string _spvOutFilePath; std::string _mslOutFilePath; + std::string _hdrOutVarName; std::string _origPathExtnSep; std::vector _glslVtxFileExtns; std::vector _glslFragFileExtns; @@ -118,6 +119,8 @@ namespace mvk { bool _shouldIncludeOrigPathExtn; bool _shouldLogConversions; bool _shouldReportPerformance; + bool _shouldOutputAsHeaders; + bool _quietMode; }; diff --git a/fetchDependencies b/fetchDependencies index a1d77529..6d1c4146 100755 --- a/fetchDependencies +++ b/fetchDependencies @@ -289,5 +289,28 @@ xcodebuild \ ${XC_BUILD_VERBOSITY} \ build + +# -------------- Convert sample shader files ----------------- +echo +echo ========== Building MoltenVKShaderConverter tool ========== +echo + +XC_PROJ="MoltenVKPackaging.xcodeproj" +XC_SCHEME="MVKShaderConverterTool Package" + +xcodebuild \ + -project "${XC_PROJ}" \ + -scheme "${XC_SCHEME}" \ + ${XC_BUILD_VERBOSITY} \ + build + +echo +echo ========== Converting API-Samples shader files ========== +echo + +"Package/Latest/MoltenVKShaderConverter/Tools/MoltenVKShaderConverter" \ + -r -gi -so -oh -xs . -q \ + -d "Demos/LunarG-VulkanSamples/VulkanSamples/API-Samples" + echo ========== Done! ==========