From 08328fea5ab97a9e354d46446a3547d89d1416da Mon Sep 17 00:00:00 2001 From: "Roy.li" Date: Tue, 9 Jun 2020 16:30:14 +0800 Subject: [PATCH] Fix xfb stride limit issue (#2088) * Fix xfb_stride limit issue Unsized array can't apply to transform trace. layout qualifier "offset" require GL_ARB_enhanced_layouts enable or glsl core version > 440. * Add negative test for xfb limit * update case result * Fix compile information issue Fix compile information issue and test comment issue. * remove es profile condition, use profileRequires to limit. * Fix xfb_stride limit issue Unsized array can't apply to transform trace. layout qualifier "offset" require GL_ARB_enhanced_layouts enable or glsl core version > 440. Add negative test for xfb limit * Move es profile check out of version number check * Adjust error information and related cases remove the new version check, refine original version check. * Revert condition for vulkan, and remove redundant test code. --- Test/baseResults/420.vert.out | 2 +- Test/baseResults/430.vert.out | 6 +- .../glsl.140.layoutOffset.error.vert.out | 50 ++++++++++++++ .../glsl.430.layoutOffset.error.vert.out | 49 +++++++++++++ .../glsl.es300.layoutOffset.error.vert.out | 51 ++++++++++++++ Test/baseResults/spv.140.frag.out | 1 + .../xfbUnsizedArray.error.vert.out | 69 +++++++++++++++++++ Test/glsl.140.layoutOffset.error.vert | 14 ++++ Test/glsl.430.layoutOffset.error.vert | 14 ++++ Test/glsl.es300.layoutOffset.error.vert | 14 ++++ Test/spv.140.frag | 1 + Test/xfbUnsizedArray.error.vert | 16 +++++ glslang/MachineIndependent/ParseHelper.cpp | 6 +- glslang/MachineIndependent/linkValidate.cpp | 4 +- gtests/AST.FromFile.cpp | 5 ++ 15 files changed, 294 insertions(+), 8 deletions(-) create mode 100644 Test/baseResults/glsl.140.layoutOffset.error.vert.out create mode 100644 Test/baseResults/glsl.430.layoutOffset.error.vert.out create mode 100644 Test/baseResults/glsl.es300.layoutOffset.error.vert.out create mode 100644 Test/baseResults/xfbUnsizedArray.error.vert.out create mode 100644 Test/glsl.140.layoutOffset.error.vert create mode 100644 Test/glsl.430.layoutOffset.error.vert create mode 100644 Test/glsl.es300.layoutOffset.error.vert create mode 100644 Test/xfbUnsizedArray.error.vert diff --git a/Test/baseResults/420.vert.out b/Test/baseResults/420.vert.out index 3d4932702..1a57b3410 100644 --- a/Test/baseResults/420.vert.out +++ b/Test/baseResults/420.vert.out @@ -48,7 +48,7 @@ ERROR: 0:141: 'rgba32f' : does not apply to unsigned integer images ERROR: 0:142: 'r8_snorm' : does not apply to signed integer images ERROR: 0:143: 'rgba32ui' : does not apply to signed integer images ERROR: 0:144: 'r8ui' : does not apply to signed integer images -ERROR: 0:147: 'offset on block member' : not supported for this version or the enabled extensions +ERROR: 0:147: '"offset" on block member' : not supported for this version or the enabled extensions ERROR: 0:147: 'offset/align' : can only be used with std140, std430, or scalar layout packing ERROR: 0:157: 'textureQueryLevels' : no matching overloaded function found ERROR: 0:157: 'assign' : cannot convert from ' const float' to ' temp int' diff --git a/Test/baseResults/430.vert.out b/Test/baseResults/430.vert.out index 4bac5fc6b..db56eab9b 100644 --- a/Test/baseResults/430.vert.out +++ b/Test/baseResults/430.vert.out @@ -26,12 +26,12 @@ ERROR: 0:59: 'location on block member' : not supported for this version or the ERROR: 0:62: 'uniform buffer-member align' : not supported for this version or the enabled extensions ERROR: 0:64: 'uniform buffer-member align' : not supported for this version or the enabled extensions ERROR: 0:65: 'uniform buffer-member align' : not supported for this version or the enabled extensions -ERROR: 0:65: 'offset on block member' : not supported for this version or the enabled extensions -ERROR: 0:66: 'offset on block member' : not supported for this version or the enabled extensions +ERROR: 0:65: '"offset" on block member' : not supported for this version or the enabled extensions +ERROR: 0:66: '"offset" on block member' : not supported for this version or the enabled extensions ERROR: 0:64: 'align' : can only be used with std140, std430, or scalar layout packing ERROR: 0:65: 'offset/align' : can only be used with std140, std430, or scalar layout packing ERROR: 0:66: 'offset/align' : can only be used with std140, std430, or scalar layout packing -ERROR: 0:71: 'offset on block member' : not supported for this version or the enabled extensions +ERROR: 0:71: '"offset" on block member' : not supported for this version or the enabled extensions ERROR: 0:74: 'gl_MaxTransformFeedbackBuffers' : required extension not requested: GL_ARB_enhanced_layouts ERROR: 0:75: 'gl_MaxTransformFeedbackInterleavedComponents' : required extension not requested: GL_ARB_enhanced_layouts ERROR: 0:78: 'transform feedback qualifier' : not supported for this version or the enabled extensions diff --git a/Test/baseResults/glsl.140.layoutOffset.error.vert.out b/Test/baseResults/glsl.140.layoutOffset.error.vert.out new file mode 100644 index 000000000..ce33d1580 --- /dev/null +++ b/Test/baseResults/glsl.140.layoutOffset.error.vert.out @@ -0,0 +1,50 @@ +glsl.140.layoutOffset.error.vert +ERROR: 0:5: 'offset' : not supported with this profile: none +ERROR: 0:5: '"offset" on block member' : not supported for this version or the enabled extensions +ERROR: 2 compilation errors. No code generated. + + +Shader version: 140 +ERROR: node is still EOpNull! +0:11 Function Definition: main( ( global void) +0:11 Function Parameters: +0:13 Sequence +0:13 move second child to first child ( temp 4-component vector of float) +0:13 'out_vs' ( smooth out 4-component vector of float) +0:13 add ( temp 4-component vector of float) +0:13 'in_vs' ( in 4-component vector of float) +0:13 a: direct index for structure (layout( column_major std140 offset=0) uniform 4-component vector of float) +0:13 'anon@0' (layout( column_major std140) uniform block{layout( column_major std140 offset=0) uniform 4-component vector of float a}) +0:13 Constant: +0:13 0 (const uint) +0:? Linker Objects +0:? 'anon@0' (layout( column_major std140) uniform block{layout( column_major std140 offset=0) uniform 4-component vector of float a}) +0:? 'in_vs' ( in 4-component vector of float) +0:? 'out_vs' ( smooth out 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + + +Linked vertex stage: + + +Shader version: 140 +ERROR: node is still EOpNull! +0:11 Function Definition: main( ( global void) +0:11 Function Parameters: +0:13 Sequence +0:13 move second child to first child ( temp 4-component vector of float) +0:13 'out_vs' ( smooth out 4-component vector of float) +0:13 add ( temp 4-component vector of float) +0:13 'in_vs' ( in 4-component vector of float) +0:13 a: direct index for structure (layout( column_major std140 offset=0) uniform 4-component vector of float) +0:13 'anon@0' (layout( column_major std140) uniform block{layout( column_major std140 offset=0) uniform 4-component vector of float a}) +0:13 Constant: +0:13 0 (const uint) +0:? Linker Objects +0:? 'anon@0' (layout( column_major std140) uniform block{layout( column_major std140 offset=0) uniform 4-component vector of float a}) +0:? 'in_vs' ( in 4-component vector of float) +0:? 'out_vs' ( smooth out 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + diff --git a/Test/baseResults/glsl.430.layoutOffset.error.vert.out b/Test/baseResults/glsl.430.layoutOffset.error.vert.out new file mode 100644 index 000000000..64160ceeb --- /dev/null +++ b/Test/baseResults/glsl.430.layoutOffset.error.vert.out @@ -0,0 +1,49 @@ +glsl.430.layoutOffset.error.vert +ERROR: 0:5: '"offset" on block member' : not supported for this version or the enabled extensions +ERROR: 1 compilation errors. No code generated. + + +Shader version: 430 +ERROR: node is still EOpNull! +0:11 Function Definition: main( ( global void) +0:11 Function Parameters: +0:13 Sequence +0:13 move second child to first child ( temp 4-component vector of float) +0:13 'out_vs' ( smooth out 4-component vector of float) +0:13 add ( temp 4-component vector of float) +0:13 'in_vs' ( in 4-component vector of float) +0:13 a: direct index for structure (layout( column_major std140 offset=0) uniform 4-component vector of float) +0:13 'anon@0' (layout( column_major std140) uniform block{layout( column_major std140 offset=0) uniform 4-component vector of float a}) +0:13 Constant: +0:13 0 (const uint) +0:? Linker Objects +0:? 'anon@0' (layout( column_major std140) uniform block{layout( column_major std140 offset=0) uniform 4-component vector of float a}) +0:? 'in_vs' ( in 4-component vector of float) +0:? 'out_vs' ( smooth out 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + + +Linked vertex stage: + + +Shader version: 430 +ERROR: node is still EOpNull! +0:11 Function Definition: main( ( global void) +0:11 Function Parameters: +0:13 Sequence +0:13 move second child to first child ( temp 4-component vector of float) +0:13 'out_vs' ( smooth out 4-component vector of float) +0:13 add ( temp 4-component vector of float) +0:13 'in_vs' ( in 4-component vector of float) +0:13 a: direct index for structure (layout( column_major std140 offset=0) uniform 4-component vector of float) +0:13 'anon@0' (layout( column_major std140) uniform block{layout( column_major std140 offset=0) uniform 4-component vector of float a}) +0:13 Constant: +0:13 0 (const uint) +0:? Linker Objects +0:? 'anon@0' (layout( column_major std140) uniform block{layout( column_major std140 offset=0) uniform 4-component vector of float a}) +0:? 'in_vs' ( in 4-component vector of float) +0:? 'out_vs' ( smooth out 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + diff --git a/Test/baseResults/glsl.es300.layoutOffset.error.vert.out b/Test/baseResults/glsl.es300.layoutOffset.error.vert.out new file mode 100644 index 000000000..3343b9f00 --- /dev/null +++ b/Test/baseResults/glsl.es300.layoutOffset.error.vert.out @@ -0,0 +1,51 @@ +glsl.es300.layoutOffset.error.vert +ERROR: 0:3: 'binding' : not supported for this version or the enabled extensions +ERROR: 0:3: 'offset' : not supported for this version or the enabled extensions +ERROR: 0:3: 'offset' : only applies to block members, not blocks +ERROR: 3 compilation errors. No code generated. + + +Shader version: 300 +ERROR: node is still EOpNull! +0:11 Function Definition: main( ( global void) +0:11 Function Parameters: +0:13 Sequence +0:13 move second child to first child ( temp highp 4-component vector of float) +0:13 'out_vs' ( smooth out highp 4-component vector of float) +0:13 add ( temp highp 4-component vector of float) +0:13 'in_vs' ( in highp 4-component vector of float) +0:13 a: direct index for structure (layout( column_major shared) uniform highp 4-component vector of float) +0:13 'anon@0' (layout( binding=0 column_major shared offset=0) uniform block{layout( column_major shared) uniform highp 4-component vector of float a}) +0:13 Constant: +0:13 0 (const uint) +0:? Linker Objects +0:? 'anon@0' (layout( binding=0 column_major shared offset=0) uniform block{layout( column_major shared) uniform highp 4-component vector of float a}) +0:? 'in_vs' ( in highp 4-component vector of float) +0:? 'out_vs' ( smooth out highp 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId highp int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId highp int InstanceId) + + +Linked vertex stage: + + +Shader version: 300 +ERROR: node is still EOpNull! +0:11 Function Definition: main( ( global void) +0:11 Function Parameters: +0:13 Sequence +0:13 move second child to first child ( temp highp 4-component vector of float) +0:13 'out_vs' ( smooth out highp 4-component vector of float) +0:13 add ( temp highp 4-component vector of float) +0:13 'in_vs' ( in highp 4-component vector of float) +0:13 a: direct index for structure (layout( column_major shared) uniform highp 4-component vector of float) +0:13 'anon@0' (layout( binding=0 column_major shared offset=0) uniform block{layout( column_major shared) uniform highp 4-component vector of float a}) +0:13 Constant: +0:13 0 (const uint) +0:? Linker Objects +0:? 'anon@0' (layout( binding=0 column_major shared offset=0) uniform block{layout( column_major shared) uniform highp 4-component vector of float a}) +0:? 'in_vs' ( in highp 4-component vector of float) +0:? 'out_vs' ( smooth out highp 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId highp int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId highp int InstanceId) + diff --git a/Test/baseResults/spv.140.frag.out b/Test/baseResults/spv.140.frag.out index 45b751068..8e5e28a28 100644 --- a/Test/baseResults/spv.140.frag.out +++ b/Test/baseResults/spv.140.frag.out @@ -14,6 +14,7 @@ Validation failed EntryPoint Fragment 4 "main" 14 23 28 38 ExecutionMode 4 OriginUpperLeft Source GLSL 140 + SourceExtension "GL_ARB_enhanced_layouts" Name 4 "main" Name 8 "foo(" Name 11 "i1" diff --git a/Test/baseResults/xfbUnsizedArray.error.vert.out b/Test/baseResults/xfbUnsizedArray.error.vert.out new file mode 100644 index 000000000..360414139 --- /dev/null +++ b/Test/baseResults/xfbUnsizedArray.error.vert.out @@ -0,0 +1,69 @@ +xfbUnsizedArray.error.vert +ERROR: 0:4: 'xfb_offset' : unsized array in buffer 0 +ERROR: 1 compilation errors. No code generated. + + +Shader version: 430 +Requested GL_ARB_enhanced_layouts +in xfb mode +ERROR: node is still EOpNull! +0:9 Function Definition: main( ( global void) +0:9 Function Parameters: +0:11 Sequence +0:11 Sequence +0:11 move second child to first child ( temp 4-component vector of float) +0:11 'result' ( temp 4-component vector of float) +0:11 'in_vs' ( in 4-component vector of float) +0:13 move second child to first child ( temp 4-component vector of float) +0:13 direct index (layout( xfb_buffer=0 xfb_offset=0) smooth temp 4-component vector of float) +0:13 'xfb_buffer' (layout( xfb_buffer=0 xfb_offset=0) smooth out unsized 1-element array of 4-component vector of float) +0:13 Constant: +0:13 0 (const int) +0:13 divide ( temp 4-component vector of float) +0:13 'result' ( temp 4-component vector of float) +0:13 Constant: +0:13 2.000000 +0:15 move second child to first child ( temp 4-component vector of float) +0:15 'out_vs' ( smooth out 4-component vector of float) +0:15 'result' ( temp 4-component vector of float) +0:? Linker Objects +0:? 'xfb_buffer' (layout( xfb_buffer=0 xfb_offset=0) smooth out unsized 1-element array of 4-component vector of float) +0:? 'in_vs' ( in 4-component vector of float) +0:? 'out_vs' ( smooth out 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + + +Linked vertex stage: + + +Shader version: 430 +Requested GL_ARB_enhanced_layouts +in xfb mode +ERROR: node is still EOpNull! +0:9 Function Definition: main( ( global void) +0:9 Function Parameters: +0:11 Sequence +0:11 Sequence +0:11 move second child to first child ( temp 4-component vector of float) +0:11 'result' ( temp 4-component vector of float) +0:11 'in_vs' ( in 4-component vector of float) +0:13 move second child to first child ( temp 4-component vector of float) +0:13 direct index (layout( xfb_buffer=0 xfb_offset=0) smooth temp 4-component vector of float) +0:13 'xfb_buffer' (layout( xfb_buffer=0 xfb_offset=0) smooth out 1-element array of 4-component vector of float) +0:13 Constant: +0:13 0 (const int) +0:13 divide ( temp 4-component vector of float) +0:13 'result' ( temp 4-component vector of float) +0:13 Constant: +0:13 2.000000 +0:15 move second child to first child ( temp 4-component vector of float) +0:15 'out_vs' ( smooth out 4-component vector of float) +0:15 'result' ( temp 4-component vector of float) +0:? Linker Objects +0:? 'xfb_buffer' (layout( xfb_buffer=0 xfb_offset=0) smooth out 1-element array of 4-component vector of float) +0:? 'in_vs' ( in 4-component vector of float) +0:? 'out_vs' ( smooth out 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + diff --git a/Test/glsl.140.layoutOffset.error.vert b/Test/glsl.140.layoutOffset.error.vert new file mode 100644 index 000000000..c57b5bc49 --- /dev/null +++ b/Test/glsl.140.layoutOffset.error.vert @@ -0,0 +1,14 @@ +#version 140 + +layout (std140) uniform UBO // offset can't use under version 140 +{ + layout(offset = 0) vec4 a; +}; + +in vec4 in_vs; +out vec4 out_vs; + +void main() +{ + out_vs = in_vs + a; +} diff --git a/Test/glsl.430.layoutOffset.error.vert b/Test/glsl.430.layoutOffset.error.vert new file mode 100644 index 000000000..831d00226 --- /dev/null +++ b/Test/glsl.430.layoutOffset.error.vert @@ -0,0 +1,14 @@ +#version 430 core + +layout (std140) uniform UBO // offset can't use on 430 core with out extension require +{ + layout(offset = 0) vec4 a; +}; + +in vec4 in_vs; +out vec4 out_vs; + +void main() +{ + out_vs = in_vs + a; +} diff --git a/Test/glsl.es300.layoutOffset.error.vert b/Test/glsl.es300.layoutOffset.error.vert new file mode 100644 index 000000000..c966f94b0 --- /dev/null +++ b/Test/glsl.es300.layoutOffset.error.vert @@ -0,0 +1,14 @@ +#version 300 es + +layout (binding = 0, offset = 0) uniform UBO // offset can't use on under version es 300 +{ + vec4 a; +}; + +in vec4 in_vs; +out vec4 out_vs; + +void main() +{ + out_vs = in_vs + a; +} diff --git a/Test/spv.140.frag b/Test/spv.140.frag index ceeac47bf..92923eb50 100644 --- a/Test/spv.140.frag +++ b/Test/spv.140.frag @@ -1,4 +1,5 @@ #version 140 +#extension GL_ARB_enhanced_layouts : require in vec4 k; out vec4 o; diff --git a/Test/xfbUnsizedArray.error.vert b/Test/xfbUnsizedArray.error.vert new file mode 100644 index 000000000..5beb9f8e1 --- /dev/null +++ b/Test/xfbUnsizedArray.error.vert @@ -0,0 +1,16 @@ +#version 430 core +#extension GL_ARB_enhanced_layouts : require + +layout (xfb_offset = 0) out vec4 xfb_buffer[]; // ERROR: unsized array cannot be used for an xfb buffer? + +in vec4 in_vs; +out vec4 out_vs; + +void main() +{ + vec4 result = in_vs; + + xfb_buffer[0] = result / 2; + + out_vs = result; +} diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index a35d41a05..698006581 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -5776,6 +5776,8 @@ void TParseContext::layoutTypeCheck(const TSourceLoc& loc, const TType& type) int repeated = intermediate.addXfbBufferOffset(type); if (repeated >= 0) error(loc, "overlapping offsets at", "xfb_offset", "offset %d in buffer %d", repeated, qualifier.layoutXfbBuffer); + if (type.isUnsizedArray()) + error(loc, "unsized array", "xfb_offset", "in buffer %d", qualifier.layoutXfbBuffer); // "The offset must be a multiple of the size of the first component of the first // qualified variable or block member, or a compile-time error results. Further, if applied to an aggregate @@ -7461,8 +7463,8 @@ void TParseContext::declareBlock(const TSourceLoc& loc, TTypeList& typeList, con arraySizesCheck(memberLoc, currentBlockQualifier, memberType.getArraySizes(), nullptr, member == typeList.size() - 1); if (memberQualifier.hasOffset()) { if (spvVersion.spv == 0) { - requireProfile(memberLoc, ~EEsProfile, "offset on block member"); - profileRequires(memberLoc, ~EEsProfile, 440, E_GL_ARB_enhanced_layouts, "offset on block member"); + profileRequires(memberLoc, ~EEsProfile, 440, E_GL_ARB_enhanced_layouts, "\"offset\" on block member"); + profileRequires(memberLoc, EEsProfile, 300, E_GL_ARB_enhanced_layouts, "\"offset\" on block member"); } } diff --git a/glslang/MachineIndependent/linkValidate.cpp b/glslang/MachineIndependent/linkValidate.cpp index 96ea46876..f0bede53a 100755 --- a/glslang/MachineIndependent/linkValidate.cpp +++ b/glslang/MachineIndependent/linkValidate.cpp @@ -1362,9 +1362,9 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains // that component's size. Aggregate types are flattened down to the component // level to get this sequence of components." - if (type.isArray()) { + if (type.isSizedArray()) { // TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness - assert(type.isSizedArray()); + // Unsized array use to xfb should be a compile error. TType elementType(type, 0); return type.getOuterArraySize() * computeTypeXfbSize(elementType, contains64BitType, contains16BitType, contains16BitType); } diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index 50046719b..762713782 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -234,6 +234,9 @@ INSTANTIATE_TEST_CASE_P( "maxClipDistances.vert", "findFunction.frag", "constantUnaryConversion.comp", + "xfbUnsizedArray.error.vert", + "glsl.140.layoutOffset.error.vert", + "glsl.430.layoutOffset.error.vert", "glsl.450.subgroup.frag", "glsl.450.subgroup.geom", "glsl.450.subgroup.tesc", @@ -258,6 +261,7 @@ INSTANTIATE_TEST_CASE_P( "glsl.460.subgroup.rgen", "glsl.460.subgroup.rint", "glsl.460.subgroup.rmiss", + "glsl.es300.layoutOffset.error.vert", "glsl.es320.subgroup.frag", "glsl.es320.subgroup.geom", "glsl.es320.subgroup.tesc", @@ -285,6 +289,7 @@ INSTANTIATE_TEST_CASE_P( })), FileNameAsCustomTestSuffix ); + // clang-format on } // anonymous namespace