Skip to content

Commit 2fde3e8

Browse files
committed
Updated SPIRV-Tools and glslang.
Replaced usage of the removed SPIRV remapper from glslang with equivalents in SPIRV-Tool's optimizer. Also replaced spirv.hpp to that brought in from SPIRV-Headers. Use UTF-8 codepage for Windows, allowing for using Unicode paths similar to what is currently done on Mac and Linux. Avoid printing full output on invalid arguments. This makes it easier to see what the error is for a simple mistake. Running tools by themselves will still show the full help output, but now without other errors, though will still have a non-zero exit code to indicate that it wasn't a successful run.
1 parent e8ef033 commit 2fde3e8

File tree

12 files changed

+111
-41
lines changed

12 files changed

+111
-41
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ endif()
9090

9191
set(MSL_MAJOR_VERSION 1)
9292
set(MSL_MINOR_VERSION 8)
93-
set(MSL_PATCH_VERSION 1)
93+
set(MSL_PATCH_VERSION 2)
9494
set(MSL_VERSION ${MSL_MAJOR_VERSION}.${MSL_MINOR_VERSION}.${MSL_PATCH_VERSION})
9595

9696
set(MSL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

Compile/SPIRV-Tools

Submodule SPIRV-Tools updated 302 files

Compile/glslang

Submodule glslang updated 457 files

Compile/src/Compiler.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#endif
3535

3636
#include "SPIRV/GlslangToSpv.h"
37-
#include "SPIRV/SPVRemapper.h"
3837
#include "glslang/Public/ResourceLimits.h"
3938

4039
#if MSL_GCC || MSL_CLANG
@@ -344,30 +343,26 @@ void Compiler::process(SpirV& spirv, int processOptions)
344343
if (processOptions == 0)
345344
return;
346345

347-
std::uint32_t options = 0;
346+
// NOTE: We have some known invalid code, such as missing bindings. Therefore we need to skip
347+
// validation.
348+
spv_optimizer_options options = spvOptimizerOptionsCreate();
349+
spvOptimizerOptionsSetRunValidator(options, false);
350+
spvtools::Optimizer optimizer(SPV_ENV_VULKAN_1_0);
348351
if (processOptions & RemapVariables)
349-
options |= spv::spirvbin_t::MAP_ALL;
352+
optimizer.RegisterPass(spvtools::CreateCanonicalizeIdsPass());
350353
if (processOptions & DeadCodeElimination)
351-
options |= spv::spirvbin_t::DCE_ALL;
354+
{
355+
optimizer.RegisterPass(spvtools::CreateEliminateDeadFunctionsPass());
356+
optimizer.RegisterPass(spvtools::CreateEliminateDeadConstantPass());
357+
}
352358
if (processOptions & StripDebug)
353-
options |= spv::spirvbin_t::STRIP;
354-
355-
spv::spirvbin_t remapper;
356-
remapper.remap(spirv, options);
357-
359+
optimizer.RegisterPass(spvtools::CreateStripDebugInfoPass());
358360
if (processOptions & Optimize)
359-
{
360-
// NOTE: We have some known invalid code, such as missing bindings. Therefore we need to
361-
// skip validation.
362-
spv_optimizer_options options = spvOptimizerOptionsCreate();
363-
spvOptimizerOptionsSetRunValidator(options, false);
364-
spvtools::Optimizer optimizer(SPV_ENV_VULKAN_1_0);
365361
optimizer.RegisterPerformancePasses();
366-
SpirV optimizedSpirV;
367-
if (optimizer.Run(spirv.data(), spirv.size(), &optimizedSpirV, options))
368-
spirv = std::move(optimizedSpirV);
369-
spvOptimizerOptionsDestroy(options);
370-
}
362+
SpirV optimizedSpirV;
363+
if (optimizer.Run(spirv.data(), spirv.size(), &optimizedSpirV, options))
364+
spirv = std::move(optimizedSpirV);
365+
spvOptimizerOptionsDestroy(options);
371366
}
372367

373368
} // namespace msl

Compile/src/SpirVProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "SpirVProcessor.h"
1818
#include <MSL/Compile/CompiledResult.h>
1919
#include <MSL/Compile/Output.h>
20-
#include <SPIRV/spirv.hpp>
20+
#include <spirv/unified1/spirv.hpp>
2121
#include <algorithm>
2222
#include <cassert>
2323
#include <cstring>

Compile/src/Target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <boost/algorithm/string/classification.hpp>
3030
#include <boost/algorithm/string/split.hpp>
3131
#include <boost/algorithm/string/trim.hpp>
32-
#include <SPIRV/spirv.hpp>
32+
#include <spirv/unified1/spirv.hpp>
3333

3434
#include <algorithm>
3535
#include <cassert>

tools/mslb-extract/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ find_package(Boost CONFIG COMPONENTS program_options filesystem)
33
file(GLOB_RECURSE sources *.cpp *.h)
44
add_executable(mslb-extract ${sources})
55

6+
if (WIN32)
7+
configure_file(mslb-extract.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/mslb-extract.manifest @ONLY)
8+
target_sources(mslb-extract PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/mslb-extract.manifest)
9+
endif()
10+
611
target_link_libraries(mslb-extract PRIVATE MSL::Client Boost::program_options Boost::filesystem)
712
target_compile_definitions(mslb-extract PRIVATE BOOST_ALL_NO_LIB
813
MSL_MAJOR_VERSION=${MSL_MAJOR_VERSION} MSL_MINOR_VERSION=${MSL_MINOR_VERSION}

tools/mslb-extract/mslb-extract.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,24 @@ static const char* stageNames[] =
359359
static_assert(sizeof(stageNames)/sizeof(*stageNames) == msl::stageCount,
360360
"stageNames out of sync with enum");
361361

362+
static const char* programName(const char* programPath)
363+
{
364+
std::size_t length = std::strlen(programPath);
365+
for (std::size_t i = length; i-- > 0;)
366+
{
367+
#if MSL_WINDOWS
368+
if (programPath[i] == '/' || programPath[i] == '\\')
369+
#else
370+
if (programPath[i] == '/')
371+
#endif
372+
{
373+
return programPath + i + 1;
374+
}
375+
}
376+
377+
return programPath;
378+
}
379+
362380
static bool shadersAreText(const msl::Module& module)
363381
{
364382
uint32_t targetId = module.targetId();
@@ -1188,12 +1206,13 @@ int main(int argc, char** argv)
11881206
{
11891207
if (!options.count("help") && !options.count("version"))
11901208
{
1191-
std::cerr << "error: " << e.what() << std::endl << std::endl;
1209+
if (argc > 1)
1210+
std::cerr << "error: " << e.what() << std::endl;
11921211
exitCode = 1;
11931212
}
11941213
}
11951214

1196-
if (options.count("help") || exitCode != 0)
1215+
if (options.count("help") || argc <= 1)
11971216
{
11981217
std::cout << "Usage: mslb-extract -i input -o output" << std::endl <<
11991218
std::endl;
@@ -1227,6 +1246,11 @@ int main(int argc, char** argv)
12271246
"." << MSL_PATCH_VERSION << std::endl;
12281247
return exitCode;
12291248
}
1249+
else if (exitCode != 0)
1250+
{
1251+
std::cerr << "Run " << programName(argv[0]) << " -h for usage." << std::endl;
1252+
return exitCode;
1253+
}
12301254

12311255
msl::Module module;
12321256
std::string moduleFile = options["input"].as<std::string>();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<assemblyIdentity type="win32" name="mslb-extract" version="@[email protected]"/>
4+
<application>
5+
<windowsSettings>
6+
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
7+
</windowsSettings>
8+
</application>
9+
</assembly>

tools/mslc/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ find_package(Boost CONFIG COMPONENTS program_options)
33
file(GLOB_RECURSE sources *.cpp *.h)
44
add_executable(mslc ${sources})
55

6+
if (WIN32)
7+
configure_file(mslc.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/mslc.manifest @ONLY)
8+
target_sources(mslc PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/mslc.manifest)
9+
endif()
10+
611
target_link_libraries(mslc PRIVATE MSL::Compile Boost::program_options)
712
target_compile_definitions(mslc PRIVATE BOOST_ALL_NO_LIB
813
MSL_MAJOR_VERSION=${MSL_MAJOR_VERSION} MSL_MINOR_VERSION=${MSL_MINOR_VERSION}

0 commit comments

Comments
 (0)