SPV: Further refine OpenGL vs. Vulkan differences for SPIR-V.
Includes adding test cases to verify the differences.
This commit is contained in:
parent
2d0cc786f3
commit
91e4aa5900
23 changed files with 305 additions and 27 deletions
|
|
@ -1985,17 +1985,14 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
|
|||
"\n");
|
||||
}
|
||||
if (version >= 130 && spvVersion.vulkan == 0)
|
||||
// gl_spirv TODO
|
||||
stageBuiltins[EShLangVertex].append(
|
||||
"int gl_VertexID;" // needs qualifier fixed later
|
||||
);
|
||||
if (version >= 140 && spvVersion.vulkan == 0)
|
||||
// gl_spirv TODO
|
||||
stageBuiltins[EShLangVertex].append(
|
||||
"int gl_InstanceID;" // needs qualifier fixed later
|
||||
);
|
||||
if (spvVersion.vulkan >= 100 && version >= 140)
|
||||
// gl_spirv TODO
|
||||
stageBuiltins[EShLangVertex].append(
|
||||
"in int gl_VertexIndex;"
|
||||
"in int gl_InstanceIndex;"
|
||||
|
|
@ -2016,13 +2013,11 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
|
|||
);
|
||||
} else {
|
||||
if (spvVersion.vulkan == 0)
|
||||
// gl_spirv TODO
|
||||
stageBuiltins[EShLangVertex].append(
|
||||
"in highp int gl_VertexID;" // needs qualifier fixed later
|
||||
"in highp int gl_InstanceID;" // needs qualifier fixed later
|
||||
);
|
||||
if (spvVersion.vulkan >= 100)
|
||||
// gl_spirv TODO
|
||||
stageBuiltins[EShLangVertex].append(
|
||||
"in highp int gl_VertexIndex;"
|
||||
"in highp int gl_InstanceIndex;"
|
||||
|
|
@ -3633,13 +3628,14 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
|
|||
}
|
||||
|
||||
if (spvVersion.vulkan == 0) {
|
||||
// gl_spirv TODO
|
||||
SpecialQualifier("gl_VertexID", EvqVertexId, EbvVertexId, symbolTable);
|
||||
SpecialQualifier("gl_InstanceID", EvqInstanceId, EbvInstanceId, symbolTable);
|
||||
}
|
||||
|
||||
BuiltInVariable("gl_VertexIndex", EbvVertexIndex, symbolTable);
|
||||
BuiltInVariable("gl_InstanceIndex", EbvInstanceIndex, symbolTable);
|
||||
if (spvVersion.vulkan >= 100) {
|
||||
BuiltInVariable("gl_VertexIndex", EbvVertexIndex, symbolTable);
|
||||
BuiltInVariable("gl_InstanceIndex", EbvInstanceIndex, symbolTable);
|
||||
}
|
||||
|
||||
// Fall through
|
||||
|
||||
|
|
|
|||
|
|
@ -4109,7 +4109,10 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi
|
|||
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
|
||||
|
||||
if (id == "offset") {
|
||||
const char* feature = "uniform offset";
|
||||
// "offset" can be for either
|
||||
// - uniform offsets
|
||||
// - atomic_uint offsets
|
||||
const char* feature = "offset";
|
||||
requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, feature);
|
||||
const char* exts[2] = { E_GL_ARB_enhanced_layouts, E_GL_ARB_shader_atomic_counters };
|
||||
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 420, 2, exts, feature);
|
||||
|
|
@ -4140,6 +4143,8 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi
|
|||
error(loc, "set is too large", id.c_str(), "");
|
||||
else
|
||||
publicType.qualifier.layoutSet = value;
|
||||
if (value != 0)
|
||||
requireVulkan(loc, "descriptor set");
|
||||
return;
|
||||
} else if (id == "binding") {
|
||||
profileRequires(loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, "binding");
|
||||
|
|
|
|||
|
|
@ -468,7 +468,11 @@ bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool versionNo
|
|||
infoSink.info.message(EPrefixError, "#version: ES shaders for Vulkan SPIR-V require version 310 or higher");
|
||||
version = 310;
|
||||
}
|
||||
// gl_spirv TODO: test versions
|
||||
if (spvVersion.openGl >= 100) {
|
||||
correct = false;
|
||||
infoSink.info.message(EPrefixError, "#version: ES shaders for OpenGL SPIR-V are not supported");
|
||||
version = 310;
|
||||
}
|
||||
break;
|
||||
case ECompatibilityProfile:
|
||||
infoSink.info.message(EPrefixError, "#version: compilation for SPIR-V does not support the compatibility profile");
|
||||
|
|
@ -479,7 +483,11 @@ bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool versionNo
|
|||
infoSink.info.message(EPrefixError, "#version: Desktop shaders for Vulkan SPIR-V require version 140 or higher");
|
||||
version = 140;
|
||||
}
|
||||
// gl_spirv TODO: test versions
|
||||
if (spvVersion.openGl >= 100 && version < 330) {
|
||||
correct = false;
|
||||
infoSink.info.message(EPrefixError, "#version: Desktop shaders for OpenGL SPIR-V require version 330 or higher");
|
||||
version = 330;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -623,6 +631,10 @@ bool ProcessDeferred(
|
|||
if (messages & EShMsgSpvRules)
|
||||
spvVersion.spv = 0x00010000; // TODO: eventually have this come from the outside
|
||||
EShSource source = (messages & EShMsgReadHlsl) ? EShSourceHlsl : EShSourceGlsl;
|
||||
if (messages & EShMsgVulkanRules)
|
||||
spvVersion.vulkan = 100; // TODO: eventually have this come from the outside
|
||||
else if (spvVersion.spv != 0)
|
||||
spvVersion.openGl = 100; // TODO: eventually have this come from the outside
|
||||
bool goodVersion = DeduceVersionProfile(compiler->infoSink, compiler->getLanguage(), versionNotFirst, defaultVersion, source, version, profile, spvVersion);
|
||||
bool versionWillBeError = (versionNotFound || (profile == EEsProfile && version >= 300 && versionNotFirst));
|
||||
bool warnVersionNotFirst = false;
|
||||
|
|
@ -633,10 +645,6 @@ bool ProcessDeferred(
|
|||
versionWillBeError = true;
|
||||
}
|
||||
|
||||
if (messages & EShMsgVulkanRules)
|
||||
spvVersion.vulkan = 100; // TODO: eventually have this come from the outside
|
||||
else if (spvVersion.spv != 0)
|
||||
spvVersion.openGl = 100;
|
||||
intermediate.setSource(source);
|
||||
intermediate.setVersion(version);
|
||||
intermediate.setProfile(profile);
|
||||
|
|
|
|||
|
|
@ -176,7 +176,6 @@ void TParseVersions::initializeExtensionBehavior()
|
|||
extensionBehavior[E_GL_ARB_shader_texture_image_samples] = EBhDisable;
|
||||
extensionBehavior[E_GL_ARB_viewport_array] = EBhDisable;
|
||||
extensionBehavior[E_GL_ARB_gpu_shader_int64] = EBhDisable;
|
||||
extensionBehavior[E_GL_ARB_gl_spirv] = EBhDisable;
|
||||
extensionBehavior[E_GL_ARB_shader_ballot] = EBhDisable;
|
||||
extensionBehavior[E_GL_ARB_sparse_texture2] = EBhDisable;
|
||||
extensionBehavior[E_GL_ARB_sparse_texture_clamp] = EBhDisable;
|
||||
|
|
@ -282,7 +281,6 @@ void TParseVersions::getPreamble(std::string& preamble)
|
|||
"#define GL_ARB_shader_texture_image_samples 1\n"
|
||||
"#define GL_ARB_viewport_array 1\n"
|
||||
"#define GL_ARB_gpu_shader_int64 1\n"
|
||||
"#define GL_ARB_gl_spirv 1\n"
|
||||
"#define GL_ARB_shader_ballot 1\n"
|
||||
"#define GL_ARB_sparse_texture2 1\n"
|
||||
"#define GL_ARB_sparse_texture_clamp 1\n"
|
||||
|
|
@ -298,14 +296,22 @@ void TParseVersions::getPreamble(std::string& preamble)
|
|||
;
|
||||
|
||||
// #define VULKAN XXXX
|
||||
const int numberBufSize = 12;
|
||||
char numberBuf[numberBufSize];
|
||||
if (spvVersion.vulkan > 0) {
|
||||
preamble += "#define VULKAN ";
|
||||
char number[12];
|
||||
snprintf(number, 12, "%d", spvVersion.vulkan);
|
||||
preamble += number;
|
||||
snprintf(numberBuf, numberBufSize, "%d", spvVersion.vulkan);
|
||||
preamble += numberBuf;
|
||||
preamble += "\n";
|
||||
}
|
||||
// gl_spirv TODO
|
||||
// #define GL_SPIRV XXXX
|
||||
if (spvVersion.openGl > 0) {
|
||||
preamble += "#define GL_SPIRV ";
|
||||
snprintf(numberBuf, numberBufSize, "%d", spvVersion.openGl);
|
||||
preamble += numberBuf;
|
||||
preamble += "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ struct SpvVersion {
|
|||
SpvVersion() : spv(0), vulkan(0), openGl(0) {}
|
||||
unsigned int spv; // the version of the targeted SPIR-V, as defined by SPIR-V in word 1 of the SPIR-V binary header
|
||||
int vulkan; // the version of semantics for Vulkan; e.g., for GLSL from KHR_vulkan_glsl "#define VULKAN"
|
||||
int openGl; // the version of semantics for OpenGL; gl_spirv TODO
|
||||
int openGl; // the version of semantics for OpenGL; e.g., for GLSL from KHR_vulkan_glsl "#define GL_SPIRV"
|
||||
};
|
||||
|
||||
//
|
||||
|
|
@ -124,7 +124,6 @@ const char* const E_GL_ARB_derivative_control = "GL_ARB_derivative_con
|
|||
const char* const E_GL_ARB_shader_texture_image_samples = "GL_ARB_shader_texture_image_samples";
|
||||
const char* const E_GL_ARB_viewport_array = "GL_ARB_viewport_array";
|
||||
const char* const E_GL_ARB_gpu_shader_int64 = "GL_ARB_gpu_shader_int64";
|
||||
const char* const E_GL_ARB_gl_spirv = "GL_ARB_gl_spirv";
|
||||
const char* const E_GL_ARB_shader_ballot = "GL_ARB_shader_ballot";
|
||||
const char* const E_GL_ARB_sparse_texture2 = "GL_ARB_sparse_texture2";
|
||||
const char* const E_GL_ARB_sparse_texture_clamp = "GL_ARB_sparse_texture_clamp";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue