From 46d3a30bd9b68a30929d7ff1587f1c38f55a04c8 Mon Sep 17 00:00:00 2001 From: ZhiqianXia Date: Mon, 2 Aug 2021 14:52:11 +0800 Subject: [PATCH] Support the #extension GL_ARB_draw_instanced. Signed-off-by: ZhiqianXia --- Test/GL_ARB_draw_instanced.vert | 18 ++ .../GL_ARB_draw_instanced.vert.out | 189 ++++++++++++++++++ glslang/MachineIndependent/Versions.cpp | 2 + glslang/MachineIndependent/Versions.h | 1 + gtests/AST.FromFile.cpp | 3 +- 5 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 Test/GL_ARB_draw_instanced.vert create mode 100644 Test/baseResults/GL_ARB_draw_instanced.vert.out diff --git a/Test/GL_ARB_draw_instanced.vert b/Test/GL_ARB_draw_instanced.vert new file mode 100644 index 00000000..6e390866 --- /dev/null +++ b/Test/GL_ARB_draw_instanced.vert @@ -0,0 +1,18 @@ +#version 150 +#extension GL_ARB_draw_instanced : require +#define ID gl_InstanceID + +uniform mat4 gtf_ModelViewProjectionMatrix; +uniform vec3 instanceOffsets[3]; +in vec4 va[gl_MaxVertexAttribs]; +out vec4 color; + +void main (void) +{ + vec4 vertex = vec4(va[0].xy / 3.0, va[0].zw) + vec4(instanceOffsets[ID], 1.0); + color = vec4(0, 0, 0, 0); + for (int i = 1; i < gl_MaxVertexAttribs; i++) + color += va[i]; + gl_Position = gtf_ModelViewProjectionMatrix * vertex; + gl_PointSize = 1.0; +} diff --git a/Test/baseResults/GL_ARB_draw_instanced.vert.out b/Test/baseResults/GL_ARB_draw_instanced.vert.out new file mode 100644 index 00000000..e601bc86 --- /dev/null +++ b/Test/baseResults/GL_ARB_draw_instanced.vert.out @@ -0,0 +1,189 @@ +GL_ARB_draw_instanced.vert +Shader version: 150 +Requested GL_ARB_draw_instanced +0:? Sequence +0:10 Function Definition: main( ( global void) +0:10 Function Parameters: +0:12 Sequence +0:12 Sequence +0:12 move second child to first child ( temp 4-component vector of float) +0:12 'vertex' ( temp 4-component vector of float) +0:12 add ( temp 4-component vector of float) +0:12 Construct vec4 ( temp 4-component vector of float) +0:12 divide ( temp 2-component vector of float) +0:12 vector swizzle ( temp 2-component vector of float) +0:12 direct index ( temp 4-component vector of float) +0:12 'va' ( in 64-element array of 4-component vector of float) +0:12 Constant: +0:12 0 (const int) +0:12 Sequence +0:12 Constant: +0:12 0 (const int) +0:12 Constant: +0:12 1 (const int) +0:12 Constant: +0:12 3.000000 +0:12 vector swizzle ( temp 2-component vector of float) +0:12 direct index ( temp 4-component vector of float) +0:12 'va' ( in 64-element array of 4-component vector of float) +0:12 Constant: +0:12 0 (const int) +0:12 Sequence +0:12 Constant: +0:12 2 (const int) +0:12 Constant: +0:12 3 (const int) +0:12 Construct vec4 ( temp 4-component vector of float) +0:12 indirect index ( temp 3-component vector of float) +0:12 'instanceOffsets' ( uniform 3-element array of 3-component vector of float) +0:12 'gl_InstanceID' ( gl_InstanceId int InstanceId) +0:12 Constant: +0:12 1.000000 +0:13 move second child to first child ( temp 4-component vector of float) +0:13 'color' ( smooth out 4-component vector of float) +0:13 Constant: +0:13 0.000000 +0:13 0.000000 +0:13 0.000000 +0:13 0.000000 +0:14 Sequence +0:14 Sequence +0:14 move second child to first child ( temp int) +0:14 'i' ( temp int) +0:14 Constant: +0:14 1 (const int) +0:14 Loop with condition tested first +0:14 Loop Condition +0:14 Compare Less Than ( temp bool) +0:14 'i' ( temp int) +0:14 Constant: +0:14 64 (const int) +0:14 Loop Body +0:15 add second child into first child ( temp 4-component vector of float) +0:15 'color' ( smooth out 4-component vector of float) +0:15 indirect index ( temp 4-component vector of float) +0:15 'va' ( in 64-element array of 4-component vector of float) +0:15 'i' ( temp int) +0:14 Loop Terminal Expression +0:14 Post-Increment ( temp int) +0:14 'i' ( temp int) +0:16 move second child to first child ( temp 4-component vector of float) +0:16 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:16 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:16 Constant: +0:16 0 (const uint) +0:16 matrix-times-vector ( temp 4-component vector of float) +0:16 'gtf_ModelViewProjectionMatrix' ( uniform 4X4 matrix of float) +0:16 'vertex' ( temp 4-component vector of float) +0:17 move second child to first child ( temp float) +0:17 gl_PointSize: direct index for structure ( gl_PointSize float PointSize) +0:17 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:17 Constant: +0:17 1 (const uint) +0:17 Constant: +0:17 1.000000 +0:? Linker Objects +0:? 'gtf_ModelViewProjectionMatrix' ( uniform 4X4 matrix of float) +0:? 'instanceOffsets' ( uniform 3-element array of 3-component vector of float) +0:? 'va' ( in 64-element array of 4-component vector of float) +0:? 'color' ( smooth out 4-component vector of float) +0:? 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out unsized 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + + +Linked vertex stage: + + +Shader version: 150 +Requested GL_ARB_draw_instanced +0:? Sequence +0:10 Function Definition: main( ( global void) +0:10 Function Parameters: +0:12 Sequence +0:12 Sequence +0:12 move second child to first child ( temp 4-component vector of float) +0:12 'vertex' ( temp 4-component vector of float) +0:12 add ( temp 4-component vector of float) +0:12 Construct vec4 ( temp 4-component vector of float) +0:12 divide ( temp 2-component vector of float) +0:12 vector swizzle ( temp 2-component vector of float) +0:12 direct index ( temp 4-component vector of float) +0:12 'va' ( in 64-element array of 4-component vector of float) +0:12 Constant: +0:12 0 (const int) +0:12 Sequence +0:12 Constant: +0:12 0 (const int) +0:12 Constant: +0:12 1 (const int) +0:12 Constant: +0:12 3.000000 +0:12 vector swizzle ( temp 2-component vector of float) +0:12 direct index ( temp 4-component vector of float) +0:12 'va' ( in 64-element array of 4-component vector of float) +0:12 Constant: +0:12 0 (const int) +0:12 Sequence +0:12 Constant: +0:12 2 (const int) +0:12 Constant: +0:12 3 (const int) +0:12 Construct vec4 ( temp 4-component vector of float) +0:12 indirect index ( temp 3-component vector of float) +0:12 'instanceOffsets' ( uniform 3-element array of 3-component vector of float) +0:12 'gl_InstanceID' ( gl_InstanceId int InstanceId) +0:12 Constant: +0:12 1.000000 +0:13 move second child to first child ( temp 4-component vector of float) +0:13 'color' ( smooth out 4-component vector of float) +0:13 Constant: +0:13 0.000000 +0:13 0.000000 +0:13 0.000000 +0:13 0.000000 +0:14 Sequence +0:14 Sequence +0:14 move second child to first child ( temp int) +0:14 'i' ( temp int) +0:14 Constant: +0:14 1 (const int) +0:14 Loop with condition tested first +0:14 Loop Condition +0:14 Compare Less Than ( temp bool) +0:14 'i' ( temp int) +0:14 Constant: +0:14 64 (const int) +0:14 Loop Body +0:15 add second child into first child ( temp 4-component vector of float) +0:15 'color' ( smooth out 4-component vector of float) +0:15 indirect index ( temp 4-component vector of float) +0:15 'va' ( in 64-element array of 4-component vector of float) +0:15 'i' ( temp int) +0:14 Loop Terminal Expression +0:14 Post-Increment ( temp int) +0:14 'i' ( temp int) +0:16 move second child to first child ( temp 4-component vector of float) +0:16 gl_Position: direct index for structure ( gl_Position 4-component vector of float Position) +0:16 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:16 Constant: +0:16 0 (const uint) +0:16 matrix-times-vector ( temp 4-component vector of float) +0:16 'gtf_ModelViewProjectionMatrix' ( uniform 4X4 matrix of float) +0:16 'vertex' ( temp 4-component vector of float) +0:17 move second child to first child ( temp float) +0:17 gl_PointSize: direct index for structure ( gl_PointSize float PointSize) +0:17 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:17 Constant: +0:17 1 (const uint) +0:17 Constant: +0:17 1.000000 +0:? Linker Objects +0:? 'gtf_ModelViewProjectionMatrix' ( uniform 4X4 matrix of float) +0:? 'instanceOffsets' ( uniform 3-element array of 3-component vector of float) +0:? 'va' ( in 64-element array of 4-component vector of float) +0:? 'color' ( smooth out 4-component vector of float) +0:? 'anon@0' ( out block{ gl_Position 4-component vector of float Position gl_Position, gl_PointSize float PointSize gl_PointSize, out 1-element array of float ClipDistance gl_ClipDistance}) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp index 70a5d5e4..2fc0d9e0 100644 --- a/glslang/MachineIndependent/Versions.cpp +++ b/glslang/MachineIndependent/Versions.cpp @@ -225,6 +225,7 @@ void TParseVersions::initializeExtensionBehavior() extensionBehavior[E_GL_ARB_shading_language_packing] = EBhDisable; extensionBehavior[E_GL_ARB_texture_query_lod] = EBhDisable; extensionBehavior[E_GL_ARB_vertex_attrib_64bit] = EBhDisable; + extensionBehavior[E_GL_ARB_draw_instanced] = EBhDisable; extensionBehavior[E_GL_KHR_shader_subgroup_basic] = EBhDisable; extensionBehavior[E_GL_KHR_shader_subgroup_vote] = EBhDisable; @@ -465,6 +466,7 @@ void TParseVersions::getPreamble(std::string& preamble) "#define GL_ARB_shader_storage_buffer_object 1\n" "#define GL_ARB_texture_query_lod 1\n" "#define GL_ARB_vertex_attrib_64bit 1\n" + "#define GL_ARB_draw_instanced 1\n" "#define GL_EXT_shader_non_constant_global_initializers 1\n" "#define GL_EXT_shader_image_load_formatted 1\n" "#define GL_EXT_post_depth_coverage 1\n" diff --git a/glslang/MachineIndependent/Versions.h b/glslang/MachineIndependent/Versions.h index 949a7a17..2dbac0b4 100644 --- a/glslang/MachineIndependent/Versions.h +++ b/glslang/MachineIndependent/Versions.h @@ -161,6 +161,7 @@ const char* const E_GL_ARB_shader_storage_buffer_object = "GL_ARB_shader_storage const char* const E_GL_ARB_shading_language_packing = "GL_ARB_shading_language_packing"; const char* const E_GL_ARB_texture_query_lod = "GL_ARB_texture_query_lod"; const char* const E_GL_ARB_vertex_attrib_64bit = "GL_ARB_vertex_attrib_64bit"; +const char* const E_GL_ARB_draw_instanced = "GL_ARB_draw_instanced"; const char* const E_GL_KHR_shader_subgroup_basic = "GL_KHR_shader_subgroup_basic"; const char* const E_GL_KHR_shader_subgroup_vote = "GL_KHR_shader_subgroup_vote"; diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index 0db97541..f9680dd6 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -285,7 +285,8 @@ INSTANTIATE_TEST_SUITE_P( "atomicAdd.comp", "GL_ARB_gpu_shader5.u2i.vert", "atomicCounterARBOps.vert", - "GL_EXT_shader_integer_mix.vert" + "GL_EXT_shader_integer_mix.vert", + "GL_ARB_draw_instanced.vert", })), FileNameAsCustomTestSuffix );