SPV: Implement Vulkan 1.1 features and extensions.

This commit is contained in:
John Kessenich
2018-03-06 16:12:04 -07:00
parent b2ae1d0521
commit 66011cb2c2
121 changed files with 51726 additions and 7500 deletions

View File

@@ -70,7 +70,7 @@ enum class Source {
// Enum for shader compilation semantics.
enum class Semantics {
OpenGL,
Vulkan,
Vulkan
};
// Enum for compilation target.
@@ -197,14 +197,15 @@ public:
GlslangResult compileAndLink(
const std::string shaderName, const std::string& code,
const std::string& entryPointName, EShMessages controls,
glslang::EshTargetClientVersion clientTargetVersion,
bool flattenUniformArrays = false,
EShTextureSamplerTransformMode texSampTransMode = EShTexSampTransKeep,
bool disableOptimizer = true,
bool automap = true)
{
const EShLanguage kind = GetShaderStage(GetSuffix(shaderName));
const EShLanguage stage = GetShaderStage(GetSuffix(shaderName));
glslang::TShader shader(kind);
glslang::TShader shader(stage);
if (automap) {
shader.setAutoMapLocations(true);
shader.setAutoMapBindings(true);
@@ -212,6 +213,24 @@ public:
shader.setTextureSamplerTransformMode(texSampTransMode);
shader.setFlattenUniformArrays(flattenUniformArrays);
if (controls & EShMsgSpvRules) {
if (controls & EShMsgVulkanRules) {
shader.setEnvInput((controls & EShMsgReadHlsl) ? glslang::EShSourceHlsl
: glslang::EShSourceGlsl,
stage, glslang::EShClientVulkan, 100);
shader.setEnvClient(glslang::EShClientVulkan, clientTargetVersion);
shader.setEnvTarget(glslang::EShTargetSpv,
clientTargetVersion == glslang::EShTargetVulkan_1_1 ? glslang::EShTargetSpv_1_3
: glslang::EShTargetSpv_1_0);
} else {
shader.setEnvInput((controls & EShMsgReadHlsl) ? glslang::EShSourceHlsl
: glslang::EShSourceGlsl,
stage, glslang::EShClientOpenGL, 100);
shader.setEnvClient(glslang::EShClientOpenGL, clientTargetVersion);
shader.setEnvTarget(glslang::EshTargetSpv, glslang::EShTargetSpv_1_0);
}
}
bool success = compile(&shader, code, entryPointName, controls);
glslang::TProgram program;
@@ -224,7 +243,7 @@ public:
std::vector<uint32_t> spirv_binary;
glslang::SpvOptions options;
options.disableOptimizer = disableOptimizer;
glslang::GlslangToSpv(*program.getIntermediate(kind),
glslang::GlslangToSpv(*program.getIntermediate(stage),
spirv_binary, &logger, &options);
std::ostringstream disassembly_stream;
@@ -255,9 +274,9 @@ public:
bool autoMapBindings,
bool flattenUniformArrays)
{
const EShLanguage kind = GetShaderStage(GetSuffix(shaderName));
const EShLanguage stage = GetShaderStage(GetSuffix(shaderName));
glslang::TShader shader(kind);
glslang::TShader shader(stage);
shader.setShiftSamplerBinding(baseSamplerBinding);
shader.setShiftTextureBinding(baseTextureBinding);
shader.setShiftImageBinding(baseImageBinding);
@@ -279,7 +298,7 @@ public:
if (success && (controls & EShMsgSpvRules)) {
std::vector<uint32_t> spirv_binary;
glslang::GlslangToSpv(*program.getIntermediate(kind),
glslang::GlslangToSpv(*program.getIntermediate(stage),
spirv_binary, &logger);
std::ostringstream disassembly_stream;
@@ -303,9 +322,9 @@ public:
const std::string& entryPointName, EShMessages controls,
const unsigned int remapOptions = spv::spirvbin_t::NONE)
{
const EShLanguage kind = GetShaderStage(GetSuffix(shaderName));
const EShLanguage stage = GetShaderStage(GetSuffix(shaderName));
glslang::TShader shader(kind);
glslang::TShader shader(stage);
shader.setAutoMapBindings(true);
shader.setAutoMapLocations(true);
@@ -319,7 +338,7 @@ public:
if (success && (controls & EShMsgSpvRules)) {
std::vector<uint32_t> spirv_binary;
glslang::GlslangToSpv(*program.getIntermediate(kind),
glslang::GlslangToSpv(*program.getIntermediate(stage),
spirv_binary, &logger);
spv::spirvbin_t(0 /*verbosity*/).remap(spirv_binary, remapOptions);
@@ -388,6 +407,7 @@ public:
const std::string& testName,
Source source,
Semantics semantics,
glslang::EshTargetClientVersion clientTargetVersion,
Target target,
bool automap = true,
const std::string& entryPointName="",
@@ -403,8 +423,8 @@ public:
tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
const EShMessages controls = DeriveOptions(source, semantics, target);
GlslangResult result = compileAndLink(testName, input, entryPointName, controls, false, EShTexSampTransKeep,
disableOptimizer, automap);
GlslangResult result = compileAndLink(testName, input, entryPointName, controls, clientTargetVersion, false,
EShTexSampTransKeep, disableOptimizer, automap);
// Generate the hybrid output in the way of glslangValidator.
std::ostringstream stream;
@@ -430,7 +450,8 @@ public:
tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
const EShMessages controls = DeriveOptions(source, semantics, target);
GlslangResult result = compileAndLink(testName, input, entryPointName, controls, true);
GlslangResult result = compileAndLink(testName, input, entryPointName, controls,
glslang::EShTargetVulkan_1_0, true);
// Generate the hybrid output in the way of glslangValidator.
std::ostringstream stream;
@@ -599,7 +620,8 @@ public:
tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
const EShMessages controls = DeriveOptions(source, semantics, target);
GlslangResult result = compileAndLink(testName, input, entryPointName, controls, false,
GlslangResult result = compileAndLink(testName, input, entryPointName, controls,
glslang::EShTargetVulkan_1_0, false,
EShTexSampTransUpgradeTextureRemoveSampler);
// Generate the hybrid output in the way of glslangValidator.