Add --no-link option
Adds the --no-link option which outputs the compiled shader binaries without linking them. This is a first step towards allowing users to create SPIR-v binary, non-executable libraries. When using the --no-link option, all functions are decorated with the Export linkage attribute.
This commit is contained in:
parent
a4aceb57de
commit
4c57db1595
24 changed files with 1671 additions and 1454 deletions
|
|
@ -65,6 +65,7 @@ std::string FileNameAsCustomTestSuffixIoMap(
|
|||
}
|
||||
|
||||
using CompileVulkanToSpirvTest = GlslangTest<::testing::TestWithParam<std::string>>;
|
||||
using CompileVulkanToSpirvTestNoLink = GlslangTest<::testing::TestWithParam<std::string>>;
|
||||
using CompileVulkanToSpirvDeadCodeElimTest = GlslangTest<::testing::TestWithParam<std::string>>;
|
||||
using CompileVulkanToDebugSpirvTest = GlslangTest<::testing::TestWithParam<std::string>>;
|
||||
using CompileVulkan1_1ToSpirvTest = GlslangTest<::testing::TestWithParam<std::string>>;
|
||||
|
|
@ -92,6 +93,16 @@ TEST_P(CompileVulkanToSpirvTest, FromFile)
|
|||
Target::Spv);
|
||||
}
|
||||
|
||||
// Compiling GLSL to SPIR-V under Vulkan semantics without linking. Expected to successfully generate SPIR-V.
|
||||
TEST_P(CompileVulkanToSpirvTestNoLink, FromFile)
|
||||
{
|
||||
options().compileOnly = true;
|
||||
// NOTE: Vulkan 1.3 is currently required to use the linkage capability
|
||||
// TODO(ncesario) make sure this is actually necessary
|
||||
loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(), Source::GLSL, Semantics::Vulkan,
|
||||
glslang::EShTargetVulkan_1_3, glslang::EShTargetSpv_1_0, Target::Spv);
|
||||
}
|
||||
|
||||
TEST_P(CompileVulkanToSpirvDeadCodeElimTest, FromFile)
|
||||
{
|
||||
loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam(),
|
||||
|
|
@ -534,6 +545,14 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
FileNameAsCustomTestSuffix
|
||||
);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
Glsl, CompileVulkanToSpirvTestNoLink,
|
||||
::testing::ValuesIn(std::vector<std::string>({
|
||||
"spv.exportFunctions.comp",
|
||||
})),
|
||||
FileNameAsCustomTestSuffix
|
||||
);
|
||||
|
||||
// Cases with deliberately unreachable code.
|
||||
// By default the compiler will aggressively eliminate
|
||||
// unreachable merges and continues.
|
||||
|
|
|
|||
|
|
@ -248,36 +248,58 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
if (options().compileOnly)
|
||||
shader.setCompileOnly();
|
||||
|
||||
bool success = compile(
|
||||
&shader, code, entryPointName, controls, nullptr, &shaderName);
|
||||
|
||||
glslang::TProgram program;
|
||||
program.addShader(&shader);
|
||||
success &= program.link(controls);
|
||||
if (success)
|
||||
program.mapIO();
|
||||
spv::SpvBuildLogger logger;
|
||||
std::vector<uint32_t> spirv_binary;
|
||||
|
||||
if (success && (controls & EShMsgSpvRules)) {
|
||||
spv::SpvBuildLogger logger;
|
||||
std::vector<uint32_t> spirv_binary;
|
||||
if (!options().compileOnly) {
|
||||
program.addShader(&shader);
|
||||
success &= program.link(controls);
|
||||
if (success)
|
||||
program.mapIO();
|
||||
|
||||
if (success && (controls & EShMsgSpvRules)) {
|
||||
options().disableOptimizer = !enableOptimizer;
|
||||
options().generateDebugInfo = enableDebug;
|
||||
options().emitNonSemanticShaderDebugInfo = enableNonSemanticShaderDebugInfo;
|
||||
options().emitNonSemanticShaderDebugSource = enableNonSemanticShaderDebugInfo;
|
||||
glslang::GlslangToSpv(*program.getIntermediate(stage), spirv_binary, &logger, &options());
|
||||
} else {
|
||||
return {{
|
||||
{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},
|
||||
},
|
||||
program.getInfoLog(),
|
||||
program.getInfoDebugLog(),
|
||||
true,
|
||||
"",
|
||||
""};
|
||||
}
|
||||
} else {
|
||||
options().disableOptimizer = !enableOptimizer;
|
||||
options().generateDebugInfo = enableDebug;
|
||||
options().emitNonSemanticShaderDebugInfo = enableNonSemanticShaderDebugInfo;
|
||||
options().emitNonSemanticShaderDebugSource = enableNonSemanticShaderDebugInfo;
|
||||
glslang::GlslangToSpv(*program.getIntermediate(stage),
|
||||
spirv_binary, &logger, &options());
|
||||
|
||||
std::ostringstream disassembly_stream;
|
||||
spv::Parameterize();
|
||||
spv::Disassemble(disassembly_stream, spirv_binary);
|
||||
bool validation_result = !options().validate || logger.getAllMessages().empty();
|
||||
return {{{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},},
|
||||
program.getInfoLog(), program.getInfoDebugLog(),
|
||||
validation_result, logger.getAllMessages(), disassembly_stream.str()};
|
||||
} else {
|
||||
return {{{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},},
|
||||
program.getInfoLog(), program.getInfoDebugLog(), true, "", ""};
|
||||
glslang::GlslangToSpv(*shader.getIntermediate(), spirv_binary, &logger, &options());
|
||||
}
|
||||
|
||||
std::ostringstream disassembly_stream;
|
||||
spv::Parameterize();
|
||||
spv::Disassemble(disassembly_stream, spirv_binary);
|
||||
bool validation_result = !options().validate || logger.getAllMessages().empty();
|
||||
return {{
|
||||
{shaderName, shader.getInfoLog(), shader.getInfoDebugLog()},
|
||||
},
|
||||
program.getInfoLog(),
|
||||
program.getInfoDebugLog(),
|
||||
validation_result,
|
||||
logger.getAllMessages(),
|
||||
disassembly_stream.str()};
|
||||
}
|
||||
|
||||
// Compiles and links the given source |code| of the given shader
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue