glslang AEP: The extension scheme, extension-enabled stage-existence testing, and compute-shader interface. Still needs in/out blocks, unsized arrays, etc. before real testing can be done.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31479 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2015-06-12 05:01:25 +00:00
parent 4751ce3fc1
commit 453bb26ef5
10 changed files with 627 additions and 32 deletions

View file

@ -989,7 +989,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
"vec4 texture3DLod(sampler3D, vec3, float);" // GL_ARB_shader_texture_lod // OES_texture_3D, but caught by keyword check
"vec4 texture3DProjLod(sampler3D, vec4, float);" // GL_ARB_shader_texture_lod // OES_texture_3D, but caught by keyword check
"vec4 textureCubeLod(samplerCube, vec3, float);" // GL_ARB_shader_texture_lod
"\n");
}
if ( profile == ECompatibilityProfile ||
@ -1026,14 +1026,15 @@ void TBuiltIns::initialize(int version, EProfile profile)
"\n");
}
if (profile != EEsProfile && version >= 150) {
if ((profile != EEsProfile && version >= 150) ||
(profile == EEsProfile && version >= 310)) {
//============================================================================
//
// Prototypes for built-in functions seen by geometry shaders only.
//
//============================================================================
if (version >= 400) {
if (profile != EEsProfile && version >= 400) {
stageBuiltins[EShLangGeometry].append(
"void EmitStreamVertex(int);"
"void EndStreamPrimitive(int);"
@ -1093,7 +1094,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
"vec4 texture3D(sampler3D, vec3, float);" // OES_texture_3D
"vec4 texture3DProj(sampler3D, vec4, float);" // OES_texture_3D
"vec4 textureCube(samplerCube, vec3, float);"
"\n");
}
if (profile != EEsProfile && version > 100) {
@ -1105,7 +1106,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
"vec4 shadow2D(sampler2DShadow, vec3, float);"
"vec4 shadow1DProj(sampler1DShadow, vec4, float);"
"vec4 shadow2DProj(sampler2DShadow, vec4, float);"
"\n");
}
if (profile == EEsProfile) {
@ -1114,7 +1115,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
"vec4 texture2DProjLodEXT(sampler2D, vec3, float);" // GL_EXT_shader_texture_lod
"vec4 texture2DProjLodEXT(sampler2D, vec4, float);" // GL_EXT_shader_texture_lod
"vec4 textureCubeLodEXT(samplerCube, vec3, float);" // GL_EXT_shader_texture_lod
"\n");
}
@ -1128,12 +1129,12 @@ void TBuiltIns::initialize(int version, EProfile profile)
"vec2 dFdy(vec2 p);"
"vec3 dFdy(vec3 p);"
"vec4 dFdy(vec4 p);"
"float fwidth(float p);"
"vec2 fwidth(vec2 p);"
"vec3 fwidth(vec3 p);"
"vec4 fwidth(vec4 p);"
"\n");
// GL_ARB_derivative_control
@ -1143,17 +1144,17 @@ void TBuiltIns::initialize(int version, EProfile profile)
"vec2 dFdxFine(vec2 p);"
"vec3 dFdxFine(vec3 p);"
"vec4 dFdxFine(vec4 p);"
"float dFdyFine(float p);"
"vec2 dFdyFine(vec2 p);"
"vec3 dFdyFine(vec3 p);"
"vec4 dFdyFine(vec4 p);"
"float fwidthFine(float p);"
"vec2 fwidthFine(vec2 p);"
"vec3 fwidthFine(vec3 p);"
"vec4 fwidthFine(vec4 p);"
"\n");
stageBuiltins[EShLangFragment].append(
@ -1161,7 +1162,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
"vec2 dFdxCoarse(vec2 p);"
"vec3 dFdxCoarse(vec3 p);"
"vec4 dFdxCoarse(vec4 p);"
"float dFdyCoarse(float p);"
"vec2 dFdyCoarse(vec2 p);"
"vec3 dFdyCoarse(vec3 p);"
@ -1505,7 +1506,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
"float gl_PointSize;"
"float gl_ClipDistance[];"
"\n");
if (version >= 400 && profile == ECompatibilityProfile)
if (profile == ECompatibilityProfile && version >= 400)
stageBuiltins[EShLangGeometry].append(
"vec4 gl_ClipVertex;"
"vec4 gl_FrontColor;"
@ -1525,23 +1526,43 @@ void TBuiltIns::initialize(int version, EProfile profile)
"out int gl_PrimitiveID;"
"out int gl_Layer;");
if (version < 400 && profile == ECompatibilityProfile)
if (profile == ECompatibilityProfile && version < 400)
stageBuiltins[EShLangGeometry].append(
"out vec4 gl_ClipVertex;"
);
if (version >= 400 && profile != EEsProfile)
if (version >= 400)
stageBuiltins[EShLangGeometry].append(
"in int gl_InvocationID;"
);
// GL_ARB_viewport_array
if (version >= 150 && profile != EEsProfile)
if (version >= 150)
stageBuiltins[EShLangGeometry].append(
"out int gl_ViewportIndex;"
);
stageBuiltins[EShLangGeometry].append("\n");
} else if (profile == EEsProfile && version >= 310) {
stageBuiltins[EShLangGeometry].append(
"in gl_PerVertex {"
"highp vec4 gl_Position;"
"highp float gl_PointSize;"
"} gl_in[];"
"\n"
"in highp int gl_PrimitiveIDIn;"
"in highp int gl_InvocationID;"
"\n"
"out gl_PerVertex {"
"vec4 gl_Position;"
"float gl_PointSize;"
"};"
"\n"
"out int gl_PrimitiveID;"
"out int gl_Layer;"
"\n"
);
}
//============================================================================
//
// Define the interface to the tessellation control shader.
@ -2275,6 +2296,29 @@ void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProf
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
s.append(builtInConstant);
}
// geometry
if (version >= 310) {
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.maxGeometryAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.maxGeometryAtomicCounterBuffers);
s.append(builtInConstant);
}
} else {
// non-ES profile

View file

@ -157,7 +157,8 @@ bool TParseContext::parseShaderStrings(TPpContext& ppContext, TInputScanner& inp
currentScanner = &input;
ppContext.setInput(input, versionWillBeError);
yyparse(this);
finalErrorCheck();
if (! parsingBuiltins)
finalErrorCheck();
return numErrors == 0;
}
@ -3105,6 +3106,30 @@ void TParseContext::finalErrorCheck()
// Check on array indexes for ES 2.0 (version 100) limitations.
for (size_t i = 0; i < needsIndexLimitationChecking.size(); ++i)
constantIndexExpressionCheck(needsIndexLimitationChecking[i]);
// Check for stages that are enabled by extension.
// Can't do this at the beginning, it is chicken and egg to add a stage by extension.
// Specific stage-specific features were correctly tested for already, this is just
// about the stage itself.
switch (language) {
case EShLangGeometry:
if (profile == EEsProfile && version == 310)
requireExtensions(getCurrentLoc(), 1, &GL_EXT_geometry_shader, "geometry shaders");
break;
case EShLangTessControl:
case EShLangTessEvaluation:
if (profile == EEsProfile && version == 310)
requireExtensions(getCurrentLoc(), 1, &GL_EXT_tessellation_shader, "tessellation shaders");
else if (profile != EEsProfile && version < 400)
requireExtensions(getCurrentLoc(), 1, &GL_ARB_tessellation_shader, "tessellation shaders");
break;
case EShLangCompute:
if (profile != EEsProfile && version < 430)
requireExtensions(getCurrentLoc(), 1, &GL_ARB_compute_shader, "tessellation shaders");
break;
default:
break;
}
}
//

View file

@ -224,6 +224,7 @@ protected:
TIntermNode* executeInitializer(TSourceLoc, TIntermTyped* initializer, TVariable* variable);
TIntermTyped* convertInitializerList(TSourceLoc, const TType&, TIntermTyped* initializer);
TOperator mapTypeToConstructorOp(const TType&) const;
void updateExtensionBehavior(const char* const extension, TExtensionBehavior);
void finalErrorCheck();
public:

View file

@ -347,28 +347,32 @@ bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool versionNo
// Correct for stage type...
switch (stage) {
case EShLangGeometry:
if (version < 150 || (profile != ECoreProfile && profile != ECompatibilityProfile)) {
if ((profile == EEsProfile && version < 310) ||
(profile != EEsProfile && version < 150)) {
correct = false;
infoSink.info.message(EPrefixError, "#version: geometry shaders require non-es profile and version 150 or above");
version = 150;
profile = ECoreProfile;
infoSink.info.message(EPrefixError, "#version: geometry shaders require es profile with version 310 or non-es profile with version 150 or above");
version = (profile == EEsProfile) ? 310 : 150;
if (profile == EEsProfile || profile == ENoProfile)
profile = ECoreProfile;
}
break;
case EShLangTessControl:
case EShLangTessEvaluation:
if (version < 150 || (profile != ECoreProfile && profile != ECompatibilityProfile)) {
if ((profile == EEsProfile && version < 310) ||
(profile != EEsProfile && version < 150)) {
correct = false;
infoSink.info.message(EPrefixError, "#version: tessellation shaders require non-es profile and version 150 or above");
version = 150;
profile = ECoreProfile;
infoSink.info.message(EPrefixError, "#version: tessellation shaders require es profile with version 310 or non-es profile with version 150 or above");
version = (profile == EEsProfile) ? 310 : 400; // 150 supports the extension, correction is to 400 which does not
if (profile == EEsProfile || profile == ENoProfile)
profile = ECoreProfile;
}
break;
case EShLangCompute:
if ((profile == EEsProfile && version < 310) ||
(profile != EEsProfile && version < 430)) {
(profile != EEsProfile && version < 420)) {
correct = false;
infoSink.info.message(EPrefixError, "#version: compute shaders require es profile with version 310 or above, or non-es profile with version 430 or above");
version = profile == EEsProfile ? 310 : 430;
infoSink.info.message(EPrefixError, "#version: compute shaders require es profile with version 310 or above, or non-es profile with version 420 or above");
version = profile == EEsProfile ? 310 : 430; // 420 supports the extension, correction is to 430 which does not
profile = ECoreProfile;
}
break;

View file

@ -161,6 +161,7 @@ void TParseContext::initializeExtensionBehavior()
extensionBehavior[GL_ARB_texture_gather] = EBhDisable;
extensionBehavior[GL_ARB_gpu_shader5] = EBhDisablePartial;
extensionBehavior[GL_ARB_separate_shader_objects] = EBhDisable;
extensionBehavior[GL_ARB_compute_shader] = EBhDisablePartial;
extensionBehavior[GL_ARB_tessellation_shader] = EBhDisable;
extensionBehavior[GL_ARB_enhanced_layouts] = EBhDisable;
extensionBehavior[GL_ARB_texture_cube_map_array] = EBhDisable;
@ -172,6 +173,23 @@ void TParseContext::initializeExtensionBehavior()
extensionBehavior[GL_ARB_shader_texture_image_samples] = EBhDisable;
extensionBehavior[GL_ARB_viewport_array] = EBhDisable;
// extensionBehavior[GL_ARB_cull_distance] = EBhDisable; // present for 4.5, but need extension control over block members
// AEP
extensionBehavior[GL_ANDROID_extension_pack_es31a] = EBhDisablePartial;
extensionBehavior[GL_KHR_blend_equation_advanced] = EBhDisablePartial;
extensionBehavior[GL_OES_sample_variables] = EBhDisablePartial;
extensionBehavior[GL_OES_shader_image_atomic] = EBhDisablePartial;
extensionBehavior[GL_OES_shader_multisample_interpolation] = EBhDisablePartial;
extensionBehavior[GL_OES_texture_storage_multisample_2d_array] = EBhDisablePartial;
extensionBehavior[GL_EXT_geometry_shader] = EBhDisablePartial;
extensionBehavior[GL_EXT_geometry_point_size] = EBhDisablePartial;
extensionBehavior[GL_EXT_gpu_shader5] = EBhDisablePartial;
extensionBehavior[GL_EXT_primitive_bounding_box] = EBhDisablePartial;
extensionBehavior[GL_EXT_shader_io_blocks] = EBhDisablePartial;
extensionBehavior[GL_EXT_tessellation_shader] = EBhDisablePartial;
extensionBehavior[GL_EXT_tessellation_point_size] = EBhDisablePartial;
extensionBehavior[GL_EXT_texture_buffer] = EBhDisablePartial;
extensionBehavior[GL_EXT_texture_cube_map_array] = EBhDisablePartial;
}
// Get code that is not part of a shared symbol table, is specific to this shader,
@ -187,6 +205,23 @@ const char* TParseContext::getPreamble()
"#define GL_EXT_frag_depth 1\n"
"#define GL_OES_EGL_image_external 1\n"
"#define GL_EXT_shader_texture_lod 1\n"
// AEP
"#define GL_ANDROID_extension_pack_es31a 1\n"
"#define GL_KHR_blend_equation_advanced 1\n"
"#define GL_OES_sample_variables 1\n"
"#define GL_OES_shader_image_atomic 1\n"
"#define GL_OES_shader_multisample_interpolation 1\n"
"#define GL_OES_texture_storage_multisample_2d_array 1\n"
"#define GL_EXT_geometry_shader 1\n"
"#define GL_EXT_geometry_point_size 1\n"
"#define GL_EXT_gpu_shader5 1\n"
"#define GL_EXT_primitive_bounding_box 1\n"
"#define GL_EXT_shader_io_blocks 1\n"
"#define GL_EXT_tessellation_shader 1\n"
"#define GL_EXT_tessellation_point_size 1\n"
"#define GL_EXT_texture_buffer 1\n"
"#define GL_EXT_texture_cube_map_array 1\n"
;
} else {
return
@ -196,6 +231,7 @@ const char* TParseContext::getPreamble()
"#define GL_ARB_texture_gather 1\n"
"#define GL_ARB_gpu_shader5 1\n"
"#define GL_ARB_separate_shader_objects 1\n"
"#define GL_ARB_compute_shader 1\n"
"#define GL_ARB_tessellation_shader 1\n"
"#define GL_ARB_enhanced_layouts 1\n"
"#define GL_ARB_texture_cube_map_array 1\n"
@ -434,12 +470,36 @@ void TParseContext::updateExtensionBehavior(const char* extension, const char* b
behavior = EBhDisable;
else if (! strcmp("warn", behaviorString))
behavior = EBhWarn;
else
error(getCurrentLoc(), "behavior not supported", "#extension", behaviorString);
else {
error(getCurrentLoc(), "behavior not supported:", "#extension", behaviorString);
return;
}
// update the requested extension
updateExtensionBehavior(extension, behavior);
// see if need to propagate to everything in AEP
if (strcmp(extension, "GL_ANDROID_extension_pack_es31a") == 0) {
updateExtensionBehavior("GL_KHR_blend_equation_advanced", behaviorString);
updateExtensionBehavior("GL_OES_sample_variables", behaviorString);
updateExtensionBehavior("GL_OES_shader_image_atomic", behaviorString);
updateExtensionBehavior("GL_OES_shader_multisample_interpolation", behaviorString);
updateExtensionBehavior("GL_OES_texture_storage_multisample_2d_array", behaviorString);
updateExtensionBehavior("GL_EXT_geometry_shader", behaviorString);
updateExtensionBehavior("GL_EXT_gpu_shader5", behaviorString);
updateExtensionBehavior("GL_EXT_primitive_bounding_box", behaviorString);
updateExtensionBehavior("GL_EXT_shader_io_blocks", behaviorString);
updateExtensionBehavior("GL_EXT_tessellation_shader", behaviorString);
updateExtensionBehavior("GL_EXT_texture_buffer", behaviorString);
updateExtensionBehavior("GL_EXT_texture_cube_map_array", behaviorString);
}
}
void TParseContext::updateExtensionBehavior(const char* extension, TExtensionBehavior behavior)
{
// Update the current behavior
TMap<TString, TExtensionBehavior>::iterator iter;
if (! strcmp(extension, "all")) {
if (strcmp(extension, "all") == 0) {
// special case for the 'all' extension; apply it to every extension present
if (behavior == EBhRequire || behavior == EBhEnable) {
error(getCurrentLoc(), "extension 'all' cannot have 'require' or 'enable' behavior", "#extension", "");

View file

@ -85,6 +85,7 @@ const char* const GL_ARB_shading_language_420pack = "GL_ARB_shading_language
const char* const GL_ARB_texture_gather = "GL_ARB_texture_gather";
const char* const GL_ARB_gpu_shader5 = "GL_ARB_gpu_shader5";
const char* const GL_ARB_separate_shader_objects = "GL_ARB_separate_shader_objects";
const char* const GL_ARB_compute_shader = "GL_ARB_compute_shader";
const char* const GL_ARB_tessellation_shader = "GL_ARB_tessellation_shader";
const char* const GL_ARB_enhanced_layouts = "GL_ARB_enhanced_layouts";
const char* const GL_ARB_texture_cube_map_array = "GL_ARB_texture_cube_map_array";
@ -97,6 +98,23 @@ const char* const GL_ARB_shader_texture_image_samples = "GL_ARB_shader_texture_i
const char* const GL_ARB_viewport_array = "GL_ARB_viewport_array";
//const char* const GL_ARB_cull_distance = "GL_ARB_cull_distance"; // present for 4.5, but need extension control over block members
// AEP
const char* const GL_ANDROID_extension_pack_es31a = "GL_ANDROID_extension_pack_es31a";
const char* const GL_KHR_blend_equation_advanced = "GL_KHR_blend_equation_advanced";
const char* const GL_OES_sample_variables = "GL_OES_sample_variables";
const char* const GL_OES_shader_image_atomic = "GL_OES_shader_image_atomic";
const char* const GL_OES_shader_multisample_interpolation = "GL_OES_shader_multisample_interpolation";
const char* const GL_OES_texture_storage_multisample_2d_array = "GL_OES_texture_storage_multisample_2d_array";
const char* const GL_EXT_geometry_shader = "GL_EXT_geometry_shader";
const char* const GL_EXT_geometry_point_size = "GL_EXT_geometry_point_size";
const char* const GL_EXT_gpu_shader5 = "GL_EXT_gpu_shader5";
const char* const GL_EXT_primitive_bounding_box = "GL_EXT_primitive_bounding_box";
const char* const GL_EXT_shader_io_blocks = "GL_EXT_shader_io_blocks";
const char* const GL_EXT_tessellation_shader = "GL_EXT_tessellation_shader";
const char* const GL_EXT_tessellation_point_size = "GL_EXT_tessellation_point_size";
const char* const GL_EXT_texture_buffer = "GL_EXT_texture_buffer";
const char* const GL_EXT_texture_cube_map_array = "GL_EXT_texture_cube_map_array";
} // end namespace glslang
#endif // _VERSIONS_INCLUDED_