blob: bf55d06521af3b30eecdf28dd9439f20d98c3d2b [file] [log] [blame]
Jiawei Shao89be29a2017-11-06 14:36:45 +08001//
2// Copyright 2017 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// GeometryShaderTest.cpp : Tests of the implementation of geometry shader
8
9#include "test_utils/ANGLETest.h"
10
11using namespace angle;
12
13namespace
14{
15
16class GeometryShaderTest : public ANGLETest
17{
18};
19
20class GeometryShaderTestES3 : public ANGLETest
21{
22};
23
24// Verify that Geometry Shader cannot be created in an OpenGL ES 3.0 context.
25TEST_P(GeometryShaderTestES3, CreateGeometryShaderInES3)
26{
27 EXPECT_TRUE(!extensionEnabled("GL_EXT_geometry_shader"));
28 GLuint geometryShader = glCreateShader(GL_GEOMETRY_SHADER_EXT);
29 EXPECT_EQ(0u, geometryShader);
30 EXPECT_GL_ERROR(GL_INVALID_ENUM);
31}
32
33// Verify that Geometry Shader can be created and attached to a program.
34TEST_P(GeometryShaderTest, CreateAndAttachGeometryShader)
35{
36 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader"));
37
38 const std::string &geometryShaderSource =
39 R"(#version 310 es
40 #extension GL_EXT_geometry_shader : require
41 layout (invocations = 3, triangles) in;
42 layout (triangle_strip, max_vertices = 3) out;
43 in vec4 texcoord[];
44 out vec4 o_texcoord;
45 void main()
46 {
47 int n;
48 for (n = 0; n < gl_in.length(); n++)
49 {
50 gl_Position = gl_in[n].gl_Position;
51 gl_Layer = gl_InvocationID;
52 o_texcoord = texcoord[n];
53 EmitVertex();
54 }
55 EndPrimitive();
56 })";
57
58 GLuint geometryShader = CompileShader(GL_GEOMETRY_SHADER_EXT, geometryShaderSource);
59
60 EXPECT_NE(0u, geometryShader);
61
62 GLuint programID = glCreateProgram();
63 glAttachShader(programID, geometryShader);
64
65 glDetachShader(programID, geometryShader);
66 glDeleteShader(geometryShader);
67 glDeleteProgram(programID);
68
69 EXPECT_GL_NO_ERROR();
70}
71
Jiawei Shao361df072017-11-22 09:33:59 +080072// Verify that all the implementation dependent geometry shader related resource limits meet the
73// requirement of GL_EXT_geometry_shader SPEC.
74TEST_P(GeometryShaderTest, GeometryShaderImplementationDependentLimits)
75{
76 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader"));
77
78 const std::map<GLenum, int> limits = {{GL_MAX_FRAMEBUFFER_LAYERS_EXT, 256},
79 {GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT, 1024},
80 {GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT, 12},
81 {GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT, 64},
82 {GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT, 64},
83 {GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT, 256},
84 {GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT, 1024},
85 {GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT, 16},
86 {GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT, 0},
87 {GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT, 0},
88 {GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT, 0},
89 {GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT, 0},
90 {GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT, 32}};
91
92 GLint value;
93 for (const auto &limit : limits)
94 {
95 value = 0;
96 glGetIntegerv(limit.first, &value);
97 EXPECT_GL_NO_ERROR();
98 EXPECT_GE(value, limit.second);
99 }
100
101 value = 0;
102 glGetIntegerv(GL_LAYER_PROVOKING_VERTEX_EXT, &value);
103 EXPECT_GL_NO_ERROR();
104 EXPECT_TRUE(value == GL_FIRST_VERTEX_CONVENTION_EXT || value == GL_LAST_VERTEX_CONVENTION_EXT ||
105 value == GL_UNDEFINED_VERTEX_EXT);
106}
107
108// Verify that all the combined resource limits meet the requirement of GL_EXT_geometry_shader SPEC.
109TEST_P(GeometryShaderTest, CombinedResourceLimits)
110{
111 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader"));
112
113 // See http://anglebug.com/2261.
114 ANGLE_SKIP_TEST_IF(IsAndroid());
115
116 const std::map<GLenum, int> limits = {{GL_MAX_UNIFORM_BUFFER_BINDINGS, 48},
117 {GL_MAX_COMBINED_UNIFORM_BLOCKS, 36},
118 {GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, 64}};
119
120 GLint value;
121 for (const auto &limit : limits)
122 {
123 value = 0;
124 glGetIntegerv(limit.first, &value);
125 EXPECT_GL_NO_ERROR();
126 EXPECT_GE(value, limit.second);
127 }
128}
129
Jiawei Shao89be29a2017-11-06 14:36:45 +0800130ANGLE_INSTANTIATE_TEST(GeometryShaderTestES3, ES3_OPENGL(), ES3_OPENGLES(), ES3_D3D11());
131ANGLE_INSTANTIATE_TEST(GeometryShaderTest, ES31_OPENGL(), ES31_OPENGLES(), ES31_D3D11());
132}