Skip to content

Commit

Permalink
Fix xfb stride limit issue (#2088)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
RuoyuAMD committed Jun 9, 2020
1 parent 8111268 commit 08328fe
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Test/baseResults/420.vert.out
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions Test/baseResults/430.vert.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions Test/baseResults/glsl.140.layoutOffset.error.vert.out
Original file line number Diff line number Diff line change
@@ -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)

49 changes: 49 additions & 0 deletions Test/baseResults/glsl.430.layoutOffset.error.vert.out
Original file line number Diff line number Diff line change
@@ -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)

51 changes: 51 additions & 0 deletions Test/baseResults/glsl.es300.layoutOffset.error.vert.out
Original file line number Diff line number Diff line change
@@ -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)

1 change: 1 addition & 0 deletions Test/baseResults/spv.140.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
69 changes: 69 additions & 0 deletions Test/baseResults/xfbUnsizedArray.error.vert.out
Original file line number Diff line number Diff line change
@@ -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)

14 changes: 14 additions & 0 deletions Test/glsl.140.layoutOffset.error.vert
Original file line number Diff line number Diff line change
@@ -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;
}
14 changes: 14 additions & 0 deletions Test/glsl.430.layoutOffset.error.vert
Original file line number Diff line number Diff line change
@@ -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;
}
14 changes: 14 additions & 0 deletions Test/glsl.es300.layoutOffset.error.vert
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions Test/spv.140.frag
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#version 140
#extension GL_ARB_enhanced_layouts : require

in vec4 k;
out vec4 o;
Expand Down
16 changes: 16 additions & 0 deletions Test/xfbUnsizedArray.error.vert
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 4 additions & 2 deletions glslang/MachineIndependent/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
}

Expand Down
4 changes: 2 additions & 2 deletions glslang/MachineIndependent/linkValidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions gtests/AST.FromFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -285,6 +289,7 @@ INSTANTIATE_TEST_CASE_P(
})),
FileNameAsCustomTestSuffix
);

// clang-format on

} // anonymous namespace
Expand Down

0 comments on commit 08328fe

Please sign in to comment.