1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2017 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker // ProgramInterfaceTest: Tests of program interfaces.
8*8975f5c5SAndroid Build Coastguard Worker
9*8975f5c5SAndroid Build Coastguard Worker #include "common/string_utils.h"
10*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/ANGLETest.h"
11*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/gl_raii.h"
12*8975f5c5SAndroid Build Coastguard Worker
13*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
14*8975f5c5SAndroid Build Coastguard Worker
15*8975f5c5SAndroid Build Coastguard Worker namespace
16*8975f5c5SAndroid Build Coastguard Worker {
17*8975f5c5SAndroid Build Coastguard Worker
18*8975f5c5SAndroid Build Coastguard Worker // Variations:
19*8975f5c5SAndroid Build Coastguard Worker //
20*8975f5c5SAndroid Build Coastguard Worker // - bool: whether the program must be created and recreated, so that it's reloaded from cache.
21*8975f5c5SAndroid Build Coastguard Worker using ProgramInterfaceTestParams = std::tuple<angle::PlatformParameters, bool>;
22*8975f5c5SAndroid Build Coastguard Worker
ProgramInterfaceTestPrint(const::testing::TestParamInfo<ProgramInterfaceTestParams> & paramsInfo)23*8975f5c5SAndroid Build Coastguard Worker std::string ProgramInterfaceTestPrint(
24*8975f5c5SAndroid Build Coastguard Worker const ::testing::TestParamInfo<ProgramInterfaceTestParams> ¶msInfo)
25*8975f5c5SAndroid Build Coastguard Worker {
26*8975f5c5SAndroid Build Coastguard Worker const ProgramInterfaceTestParams ¶ms = paramsInfo.param;
27*8975f5c5SAndroid Build Coastguard Worker std::ostringstream out;
28*8975f5c5SAndroid Build Coastguard Worker
29*8975f5c5SAndroid Build Coastguard Worker out << std::get<0>(params);
30*8975f5c5SAndroid Build Coastguard Worker
31*8975f5c5SAndroid Build Coastguard Worker if (std::get<1>(params))
32*8975f5c5SAndroid Build Coastguard Worker {
33*8975f5c5SAndroid Build Coastguard Worker out << "__cached";
34*8975f5c5SAndroid Build Coastguard Worker }
35*8975f5c5SAndroid Build Coastguard Worker
36*8975f5c5SAndroid Build Coastguard Worker return out.str();
37*8975f5c5SAndroid Build Coastguard Worker }
38*8975f5c5SAndroid Build Coastguard Worker
39*8975f5c5SAndroid Build Coastguard Worker class ProgramInterfaceTestES31 : public ANGLETest<ProgramInterfaceTestParams>
40*8975f5c5SAndroid Build Coastguard Worker {
41*8975f5c5SAndroid Build Coastguard Worker protected:
ProgramInterfaceTestES31()42*8975f5c5SAndroid Build Coastguard Worker ProgramInterfaceTestES31()
43*8975f5c5SAndroid Build Coastguard Worker {
44*8975f5c5SAndroid Build Coastguard Worker setWindowWidth(64);
45*8975f5c5SAndroid Build Coastguard Worker setWindowHeight(64);
46*8975f5c5SAndroid Build Coastguard Worker setConfigRedBits(8);
47*8975f5c5SAndroid Build Coastguard Worker setConfigGreenBits(8);
48*8975f5c5SAndroid Build Coastguard Worker setConfigBlueBits(8);
49*8975f5c5SAndroid Build Coastguard Worker setConfigAlphaBits(8);
50*8975f5c5SAndroid Build Coastguard Worker }
51*8975f5c5SAndroid Build Coastguard Worker
52*8975f5c5SAndroid Build Coastguard Worker void createGraphicsProgram(GLProgram &program,
53*8975f5c5SAndroid Build Coastguard Worker const char *vs,
54*8975f5c5SAndroid Build Coastguard Worker const char *fs,
55*8975f5c5SAndroid Build Coastguard Worker bool cacheAndReload);
56*8975f5c5SAndroid Build Coastguard Worker void createComputeProgram(GLProgram &program, const char *cs, bool cacheAndReload);
57*8975f5c5SAndroid Build Coastguard Worker };
58*8975f5c5SAndroid Build Coastguard Worker
createGraphicsProgram(GLProgram & program,const char * vs,const char * fs,bool cacheAndReload)59*8975f5c5SAndroid Build Coastguard Worker void ProgramInterfaceTestES31::createGraphicsProgram(GLProgram &program,
60*8975f5c5SAndroid Build Coastguard Worker const char *vs,
61*8975f5c5SAndroid Build Coastguard Worker const char *fs,
62*8975f5c5SAndroid Build Coastguard Worker bool cacheAndReload)
63*8975f5c5SAndroid Build Coastguard Worker {
64*8975f5c5SAndroid Build Coastguard Worker program.makeRaster(vs, fs);
65*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(program.valid());
66*8975f5c5SAndroid Build Coastguard Worker
67*8975f5c5SAndroid Build Coastguard Worker if (cacheAndReload)
68*8975f5c5SAndroid Build Coastguard Worker {
69*8975f5c5SAndroid Build Coastguard Worker program.reset();
70*8975f5c5SAndroid Build Coastguard Worker program.makeRaster(vs, fs);
71*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(program.valid());
72*8975f5c5SAndroid Build Coastguard Worker }
73*8975f5c5SAndroid Build Coastguard Worker }
74*8975f5c5SAndroid Build Coastguard Worker
createComputeProgram(GLProgram & program,const char * cs,bool cacheAndReload)75*8975f5c5SAndroid Build Coastguard Worker void ProgramInterfaceTestES31::createComputeProgram(GLProgram &program,
76*8975f5c5SAndroid Build Coastguard Worker const char *cs,
77*8975f5c5SAndroid Build Coastguard Worker bool cacheAndReload)
78*8975f5c5SAndroid Build Coastguard Worker {
79*8975f5c5SAndroid Build Coastguard Worker program.makeCompute(cs);
80*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(program.valid());
81*8975f5c5SAndroid Build Coastguard Worker
82*8975f5c5SAndroid Build Coastguard Worker if (cacheAndReload)
83*8975f5c5SAndroid Build Coastguard Worker {
84*8975f5c5SAndroid Build Coastguard Worker program.reset();
85*8975f5c5SAndroid Build Coastguard Worker program.makeCompute(cs);
86*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(program.valid());
87*8975f5c5SAndroid Build Coastguard Worker }
88*8975f5c5SAndroid Build Coastguard Worker }
89*8975f5c5SAndroid Build Coastguard Worker
90*8975f5c5SAndroid Build Coastguard Worker // Tests glGetProgramResourceIndex.
TEST_P(ProgramInterfaceTestES31,GetResourceIndex)91*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetResourceIndex)
92*8975f5c5SAndroid Build Coastguard Worker {
93*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
94*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
95*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
96*8975f5c5SAndroid Build Coastguard Worker "uniform vec4 color;\n"
97*8975f5c5SAndroid Build Coastguard Worker "out vec4 oColor;\n"
98*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
99*8975f5c5SAndroid Build Coastguard Worker "{\n"
100*8975f5c5SAndroid Build Coastguard Worker " oColor = color;\n"
101*8975f5c5SAndroid Build Coastguard Worker "}";
102*8975f5c5SAndroid Build Coastguard Worker
103*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
104*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, essl31_shaders::vs::Simple(), kFS, std::get<1>(GetParam()));
105*8975f5c5SAndroid Build Coastguard Worker
106*8975f5c5SAndroid Build Coastguard Worker GLuint index =
107*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceIndex(program, GL_PROGRAM_INPUT, essl31_shaders::PositionAttrib());
108*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
109*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
110*8975f5c5SAndroid Build Coastguard Worker
111*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_PROGRAM_INPUT, "missing");
112*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
113*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_INVALID_INDEX, index);
114*8975f5c5SAndroid Build Coastguard Worker
115*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_PROGRAM_OUTPUT, "oColor");
116*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
117*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
118*8975f5c5SAndroid Build Coastguard Worker
119*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_PROGRAM_OUTPUT, "missing");
120*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
121*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_INVALID_INDEX, index);
122*8975f5c5SAndroid Build Coastguard Worker
123*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_ATOMIC_COUNTER_BUFFER, "missing");
124*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_ERROR(GL_INVALID_ENUM);
125*8975f5c5SAndroid Build Coastguard Worker }
126*8975f5c5SAndroid Build Coastguard Worker
127*8975f5c5SAndroid Build Coastguard Worker // Tests glGetProgramResourceName.
TEST_P(ProgramInterfaceTestES31,GetResourceName)128*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetResourceName)
129*8975f5c5SAndroid Build Coastguard Worker {
130*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
131*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
132*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
133*8975f5c5SAndroid Build Coastguard Worker "uniform vec4 color;\n"
134*8975f5c5SAndroid Build Coastguard Worker "out vec4 oColor[4];\n"
135*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
136*8975f5c5SAndroid Build Coastguard Worker "{\n"
137*8975f5c5SAndroid Build Coastguard Worker " oColor[0] = color;\n"
138*8975f5c5SAndroid Build Coastguard Worker "}";
139*8975f5c5SAndroid Build Coastguard Worker
140*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
141*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, essl31_shaders::vs::Simple(), kFS, std::get<1>(GetParam()));
142*8975f5c5SAndroid Build Coastguard Worker
143*8975f5c5SAndroid Build Coastguard Worker GLuint index =
144*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceIndex(program, GL_PROGRAM_INPUT, essl31_shaders::PositionAttrib());
145*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
146*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
147*8975f5c5SAndroid Build Coastguard Worker
148*8975f5c5SAndroid Build Coastguard Worker GLchar name[64];
149*8975f5c5SAndroid Build Coastguard Worker GLsizei length;
150*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_PROGRAM_INPUT, index, sizeof(name), &length, name);
151*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
152*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(static_cast<int>(strlen(essl31_shaders::PositionAttrib())), length);
153*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(essl31_shaders::PositionAttrib(), std::string(name));
154*8975f5c5SAndroid Build Coastguard Worker
155*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_PROGRAM_INPUT, index, 4, &length, name);
156*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
157*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, length);
158*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(angle::BeginsWith(essl31_shaders::PositionAttrib(), name));
159*8975f5c5SAndroid Build Coastguard Worker
160*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_PROGRAM_INPUT, index, -1, &length, name);
161*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_ERROR(GL_INVALID_VALUE);
162*8975f5c5SAndroid Build Coastguard Worker
163*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_PROGRAM_INPUT, GL_INVALID_INDEX, sizeof(name), &length,
164*8975f5c5SAndroid Build Coastguard Worker name);
165*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_ERROR(GL_INVALID_VALUE);
166*8975f5c5SAndroid Build Coastguard Worker
167*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_PROGRAM_OUTPUT, "oColor");
168*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
169*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
170*8975f5c5SAndroid Build Coastguard Worker
171*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_PROGRAM_OUTPUT, index, sizeof(name), &length, name);
172*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
173*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(9, length);
174*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("oColor[0]", std::string(name));
175*8975f5c5SAndroid Build Coastguard Worker
176*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_PROGRAM_OUTPUT, index, 8, &length, name);
177*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
178*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(7, length);
179*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("oColor[", std::string(name));
180*8975f5c5SAndroid Build Coastguard Worker }
181*8975f5c5SAndroid Build Coastguard Worker
182*8975f5c5SAndroid Build Coastguard Worker // Tests glGetProgramResourceLocation.
TEST_P(ProgramInterfaceTestES31,GetResourceLocation)183*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetResourceLocation)
184*8975f5c5SAndroid Build Coastguard Worker {
185*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
186*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
187*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
188*8975f5c5SAndroid Build Coastguard Worker "layout(location = 3) in highp vec4 position;\n"
189*8975f5c5SAndroid Build Coastguard Worker "in highp vec4 noLocationSpecified;\n"
190*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
191*8975f5c5SAndroid Build Coastguard Worker "{\n"
192*8975f5c5SAndroid Build Coastguard Worker " gl_Position = position;\n"
193*8975f5c5SAndroid Build Coastguard Worker "}";
194*8975f5c5SAndroid Build Coastguard Worker
195*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
196*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
197*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
198*8975f5c5SAndroid Build Coastguard Worker "uniform vec4 color;\n"
199*8975f5c5SAndroid Build Coastguard Worker "layout(location = 1) out vec4 oColor[3];\n"
200*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
201*8975f5c5SAndroid Build Coastguard Worker "{\n"
202*8975f5c5SAndroid Build Coastguard Worker " oColor[0] = color;\n"
203*8975f5c5SAndroid Build Coastguard Worker "}";
204*8975f5c5SAndroid Build Coastguard Worker
205*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
206*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, kVS, kFS, std::get<1>(GetParam()));
207*8975f5c5SAndroid Build Coastguard Worker
208*8975f5c5SAndroid Build Coastguard Worker GLenum invalidInterfaces[] = {GL_UNIFORM_BLOCK, GL_TRANSFORM_FEEDBACK_VARYING,
209*8975f5c5SAndroid Build Coastguard Worker GL_BUFFER_VARIABLE, GL_SHADER_STORAGE_BLOCK,
210*8975f5c5SAndroid Build Coastguard Worker GL_ATOMIC_COUNTER_BUFFER};
211*8975f5c5SAndroid Build Coastguard Worker GLint location;
212*8975f5c5SAndroid Build Coastguard Worker for (auto &invalidInterface : invalidInterfaces)
213*8975f5c5SAndroid Build Coastguard Worker {
214*8975f5c5SAndroid Build Coastguard Worker location = glGetProgramResourceLocation(program, invalidInterface, "any");
215*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_ERROR(GL_INVALID_ENUM);
216*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, location);
217*8975f5c5SAndroid Build Coastguard Worker }
218*8975f5c5SAndroid Build Coastguard Worker
219*8975f5c5SAndroid Build Coastguard Worker location = glGetProgramResourceLocation(program, GL_PROGRAM_INPUT, "position");
220*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
221*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, location);
222*8975f5c5SAndroid Build Coastguard Worker
223*8975f5c5SAndroid Build Coastguard Worker location = glGetProgramResourceLocation(program, GL_PROGRAM_INPUT, "noLocationSpecified");
224*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
225*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, location);
226*8975f5c5SAndroid Build Coastguard Worker
227*8975f5c5SAndroid Build Coastguard Worker location = glGetProgramResourceLocation(program, GL_PROGRAM_INPUT, "missing");
228*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
229*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, location);
230*8975f5c5SAndroid Build Coastguard Worker
231*8975f5c5SAndroid Build Coastguard Worker location = glGetProgramResourceLocation(program, GL_PROGRAM_OUTPUT, "oColor");
232*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
233*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, location);
234*8975f5c5SAndroid Build Coastguard Worker location = glGetProgramResourceLocation(program, GL_PROGRAM_OUTPUT, "oColor[0]");
235*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
236*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, location);
237*8975f5c5SAndroid Build Coastguard Worker location = glGetProgramResourceLocation(program, GL_PROGRAM_OUTPUT, "oColor[2]");
238*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
239*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, location);
240*8975f5c5SAndroid Build Coastguard Worker }
241*8975f5c5SAndroid Build Coastguard Worker
242*8975f5c5SAndroid Build Coastguard Worker // Tests glGetProgramResource.
TEST_P(ProgramInterfaceTestES31,GetResource)243*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetResource)
244*8975f5c5SAndroid Build Coastguard Worker {
245*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
246*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
247*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
248*8975f5c5SAndroid Build Coastguard Worker "layout(location = 3) in highp vec4 position;\n"
249*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
250*8975f5c5SAndroid Build Coastguard Worker "{\n"
251*8975f5c5SAndroid Build Coastguard Worker " gl_Position = position;\n"
252*8975f5c5SAndroid Build Coastguard Worker "}";
253*8975f5c5SAndroid Build Coastguard Worker
254*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
255*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
256*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
257*8975f5c5SAndroid Build Coastguard Worker "uniform vec4 color;\n"
258*8975f5c5SAndroid Build Coastguard Worker "layout(location = 1) out vec4 oColor[3];\n"
259*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
260*8975f5c5SAndroid Build Coastguard Worker "{\n"
261*8975f5c5SAndroid Build Coastguard Worker " oColor[0] = color;\n"
262*8975f5c5SAndroid Build Coastguard Worker "}";
263*8975f5c5SAndroid Build Coastguard Worker
264*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
265*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, kVS, kFS, std::get<1>(GetParam()));
266*8975f5c5SAndroid Build Coastguard Worker
267*8975f5c5SAndroid Build Coastguard Worker GLuint index = glGetProgramResourceIndex(program, GL_PROGRAM_INPUT, "position");
268*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
269*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
270*8975f5c5SAndroid Build Coastguard Worker
271*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_TYPE,
272*8975f5c5SAndroid Build Coastguard Worker GL_ARRAY_SIZE,
273*8975f5c5SAndroid Build Coastguard Worker GL_LOCATION,
274*8975f5c5SAndroid Build Coastguard Worker GL_NAME_LENGTH,
275*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_VERTEX_SHADER,
276*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_FRAGMENT_SHADER,
277*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_COMPUTE_SHADER};
278*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
279*8975f5c5SAndroid Build Coastguard Worker GLint params[ArraySize(props)];
280*8975f5c5SAndroid Build Coastguard Worker GLsizei length;
281*8975f5c5SAndroid Build Coastguard Worker
282*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_PROGRAM_INPUT, index, propCount, props, propCount, &length,
283*8975f5c5SAndroid Build Coastguard Worker params);
284*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
285*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
286*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_FLOAT_VEC4, params[0]); // type
287*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[1]); // array_size
288*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, params[2]); // location
289*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(9, params[3]); // name_length
290*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[4]); // referenced_by_vertex_shader
291*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[5]); // referenced_by_fragment_shader
292*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[6]); // referenced_by_compute_shader
293*8975f5c5SAndroid Build Coastguard Worker
294*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_PROGRAM_OUTPUT, "oColor[0]");
295*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
296*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(index, GL_INVALID_INDEX);
297*8975f5c5SAndroid Build Coastguard Worker // bufSize is smaller than propCount.
298*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_PROGRAM_OUTPUT, index, propCount, props, propCount - 1,
299*8975f5c5SAndroid Build Coastguard Worker &length, params);
300*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
301*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount - 1, length);
302*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_FLOAT_VEC4, params[0]); // type
303*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, params[1]); // array_size
304*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[2]); // location
305*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(10, params[3]); // name_length
306*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[4]); // referenced_by_vertex_shader
307*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[5]); // referenced_by_fragment_shader
308*8975f5c5SAndroid Build Coastguard Worker
309*8975f5c5SAndroid Build Coastguard Worker GLenum invalidOutputProp = GL_OFFSET;
310*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_PROGRAM_OUTPUT, index, 1, &invalidOutputProp, 1, &length,
311*8975f5c5SAndroid Build Coastguard Worker params);
312*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_ERROR(GL_INVALID_OPERATION);
313*8975f5c5SAndroid Build Coastguard Worker }
314*8975f5c5SAndroid Build Coastguard Worker
315*8975f5c5SAndroid Build Coastguard Worker // Tests glGetProgramInterfaceiv.
TEST_P(ProgramInterfaceTestES31,GetProgramInterface)316*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetProgramInterface)
317*8975f5c5SAndroid Build Coastguard Worker {
318*8975f5c5SAndroid Build Coastguard Worker // TODO([email protected]): Don't skip this test once SSBO are supported on render pipeline.
319*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/40644618
320*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsD3D11());
321*8975f5c5SAndroid Build Coastguard Worker
322*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
323*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
324*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
325*8975f5c5SAndroid Build Coastguard Worker "uniform vec4 color;\n"
326*8975f5c5SAndroid Build Coastguard Worker "out vec4 oColor;\n"
327*8975f5c5SAndroid Build Coastguard Worker "uniform ub {\n"
328*8975f5c5SAndroid Build Coastguard Worker " vec4 mem0;\n"
329*8975f5c5SAndroid Build Coastguard Worker " vec4 mem1;\n"
330*8975f5c5SAndroid Build Coastguard Worker "} instance;\n"
331*8975f5c5SAndroid Build Coastguard Worker "layout(std430) buffer shaderStorageBlock1 {\n"
332*8975f5c5SAndroid Build Coastguard Worker " vec3 target;\n"
333*8975f5c5SAndroid Build Coastguard Worker "};\n"
334*8975f5c5SAndroid Build Coastguard Worker "layout(std430) buffer shaderStorageBlock2 {\n"
335*8975f5c5SAndroid Build Coastguard Worker " vec3 target;\n"
336*8975f5c5SAndroid Build Coastguard Worker "} blockInstance2[1];\n"
337*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
338*8975f5c5SAndroid Build Coastguard Worker "{\n"
339*8975f5c5SAndroid Build Coastguard Worker " oColor = color;\n"
340*8975f5c5SAndroid Build Coastguard Worker " target = vec3(0, 0, 0);\n"
341*8975f5c5SAndroid Build Coastguard Worker " blockInstance2[0].target = vec3(1, 1, 1);\n"
342*8975f5c5SAndroid Build Coastguard Worker "}";
343*8975f5c5SAndroid Build Coastguard Worker
344*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
345*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, essl31_shaders::vs::Simple(), kFS, std::get<1>(GetParam()));
346*8975f5c5SAndroid Build Coastguard Worker
347*8975f5c5SAndroid Build Coastguard Worker GLint num;
348*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &num);
349*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
350*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, num);
351*8975f5c5SAndroid Build Coastguard Worker
352*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_MAX_NAME_LENGTH, &num);
353*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
354*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(static_cast<GLint>(strlen(essl3_shaders::PositionAttrib())) + 1, num);
355*8975f5c5SAndroid Build Coastguard Worker
356*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_MAX_NUM_ACTIVE_VARIABLES, &num);
357*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_ERROR(GL_INVALID_OPERATION);
358*8975f5c5SAndroid Build Coastguard Worker
359*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_PROGRAM_OUTPUT, GL_ACTIVE_RESOURCES, &num);
360*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
361*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, num);
362*8975f5c5SAndroid Build Coastguard Worker
363*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_PROGRAM_OUTPUT, GL_MAX_NAME_LENGTH, &num);
364*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
365*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(7, num);
366*8975f5c5SAndroid Build Coastguard Worker
367*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_PROGRAM_OUTPUT, GL_MAX_NUM_ACTIVE_VARIABLES, &num);
368*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_ERROR(GL_INVALID_OPERATION);
369*8975f5c5SAndroid Build Coastguard Worker
370*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_UNIFORM_BLOCK, GL_ACTIVE_RESOURCES, &num);
371*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
372*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, num);
373*8975f5c5SAndroid Build Coastguard Worker
374*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_UNIFORM_BLOCK, GL_MAX_NAME_LENGTH, &num);
375*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
376*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, num);
377*8975f5c5SAndroid Build Coastguard Worker
378*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_UNIFORM_BLOCK, GL_MAX_NUM_ACTIVE_VARIABLES, &num);
379*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
380*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, num); // mem0, mem1
381*8975f5c5SAndroid Build Coastguard Worker
382*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_UNIFORM, GL_ACTIVE_RESOURCES, &num);
383*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
384*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, num);
385*8975f5c5SAndroid Build Coastguard Worker
386*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_UNIFORM, GL_MAX_NAME_LENGTH, &num);
387*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
388*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(8, num); // "ub.mem0"
389*8975f5c5SAndroid Build Coastguard Worker
390*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_UNIFORM, GL_MAX_NUM_ACTIVE_VARIABLES, &num);
391*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_ERROR(GL_INVALID_OPERATION);
392*8975f5c5SAndroid Build Coastguard Worker
393*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &num);
394*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
395*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, num);
396*8975f5c5SAndroid Build Coastguard Worker
397*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_MAX_NAME_LENGTH, &num);
398*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
399*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(23, num); // "shaderStorageBlock2[0]"
400*8975f5c5SAndroid Build Coastguard Worker
401*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_MAX_NUM_ACTIVE_VARIABLES, &num);
402*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
403*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, num);
404*8975f5c5SAndroid Build Coastguard Worker }
405*8975f5c5SAndroid Build Coastguard Worker
406*8975f5c5SAndroid Build Coastguard Worker // Tests the resource property query for uniform can be done correctly.
TEST_P(ProgramInterfaceTestES31,GetUniformProperties)407*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetUniformProperties)
408*8975f5c5SAndroid Build Coastguard Worker {
409*8975f5c5SAndroid Build Coastguard Worker // Check atomic support.
410*8975f5c5SAndroid Build Coastguard Worker GLint numSupported;
411*8975f5c5SAndroid Build Coastguard Worker glGetIntegerv(GL_MAX_VERTEX_ATOMIC_COUNTERS, &numSupported);
412*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
413*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(numSupported < 1);
414*8975f5c5SAndroid Build Coastguard Worker
415*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
416*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
417*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
418*8975f5c5SAndroid Build Coastguard Worker "uniform layout(location=12) vec4 color;\n"
419*8975f5c5SAndroid Build Coastguard Worker "layout(binding = 2, offset = 4) uniform atomic_uint foo;\n"
420*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
421*8975f5c5SAndroid Build Coastguard Worker "{\n"
422*8975f5c5SAndroid Build Coastguard Worker " atomicCounterIncrement(foo);\n"
423*8975f5c5SAndroid Build Coastguard Worker "}";
424*8975f5c5SAndroid Build Coastguard Worker
425*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
426*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
427*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
428*8975f5c5SAndroid Build Coastguard Worker "uniform vec4 color;\n"
429*8975f5c5SAndroid Build Coastguard Worker "out vec4 oColor;\n"
430*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
431*8975f5c5SAndroid Build Coastguard Worker "{\n"
432*8975f5c5SAndroid Build Coastguard Worker " oColor = color;\n"
433*8975f5c5SAndroid Build Coastguard Worker "}";
434*8975f5c5SAndroid Build Coastguard Worker
435*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
436*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, kVS, kFS, std::get<1>(GetParam()));
437*8975f5c5SAndroid Build Coastguard Worker
438*8975f5c5SAndroid Build Coastguard Worker GLuint index = glGetProgramResourceIndex(program, GL_UNIFORM, "color");
439*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
440*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
441*8975f5c5SAndroid Build Coastguard Worker
442*8975f5c5SAndroid Build Coastguard Worker GLchar name[64];
443*8975f5c5SAndroid Build Coastguard Worker GLsizei length;
444*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_UNIFORM, index, sizeof(name), &length, name);
445*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
446*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(5, length);
447*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("color", std::string(name));
448*8975f5c5SAndroid Build Coastguard Worker
449*8975f5c5SAndroid Build Coastguard Worker GLint location = glGetProgramResourceLocation(program, GL_UNIFORM, "color");
450*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
451*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(12, location);
452*8975f5c5SAndroid Build Coastguard Worker
453*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_TYPE,
454*8975f5c5SAndroid Build Coastguard Worker GL_ARRAY_SIZE,
455*8975f5c5SAndroid Build Coastguard Worker GL_LOCATION,
456*8975f5c5SAndroid Build Coastguard Worker GL_NAME_LENGTH,
457*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_VERTEX_SHADER,
458*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_FRAGMENT_SHADER,
459*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_COMPUTE_SHADER,
460*8975f5c5SAndroid Build Coastguard Worker GL_ARRAY_STRIDE,
461*8975f5c5SAndroid Build Coastguard Worker GL_BLOCK_INDEX,
462*8975f5c5SAndroid Build Coastguard Worker GL_IS_ROW_MAJOR,
463*8975f5c5SAndroid Build Coastguard Worker GL_MATRIX_STRIDE,
464*8975f5c5SAndroid Build Coastguard Worker GL_OFFSET,
465*8975f5c5SAndroid Build Coastguard Worker GL_ATOMIC_COUNTER_BUFFER_INDEX};
466*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
467*8975f5c5SAndroid Build Coastguard Worker GLint params[ArraySize(props)];
468*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_UNIFORM, index, propCount, props, propCount, &length,
469*8975f5c5SAndroid Build Coastguard Worker params);
470*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
471*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
472*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_FLOAT_VEC4, params[0]); // type
473*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[1]); // array_size
474*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(12, params[2]); // location
475*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(6, params[3]); // name_length
476*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[4]); // referenced_by_vertex_shader
477*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[5]); // referenced_by_fragment_shader
478*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[6]); // referenced_by_compute_shader
479*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, params[7]); // array_stride
480*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, params[8]); // block_index
481*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[9]); // is_row_major
482*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, params[10]); // matrix_stride
483*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, params[11]); // offset
484*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, params[12]); // atomic_counter_buffer_index
485*8975f5c5SAndroid Build Coastguard Worker
486*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_UNIFORM, "foo");
487*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
488*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
489*8975f5c5SAndroid Build Coastguard Worker
490*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_UNIFORM, index, sizeof(name), &length, name);
491*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
492*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, length);
493*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("foo", std::string(name));
494*8975f5c5SAndroid Build Coastguard Worker
495*8975f5c5SAndroid Build Coastguard Worker location = glGetProgramResourceLocation(program, GL_UNIFORM, "foo");
496*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
497*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, location);
498*8975f5c5SAndroid Build Coastguard Worker
499*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_UNIFORM, index, propCount, props, propCount, &length,
500*8975f5c5SAndroid Build Coastguard Worker params);
501*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
502*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
503*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_UNSIGNED_INT_ATOMIC_COUNTER, params[0]); // type
504*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[1]); // array_size
505*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, params[2]); // location
506*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(4, params[3]); // name_length
507*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[4]); // referenced_by_vertex_shader
508*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[5]); // referenced_by_fragment_shader
509*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[6]); // referenced_by_compute_shader
510*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[7]); // array_stride
511*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(-1, params[8]); // block_index
512*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[9]); // is_row_major
513*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[10]); // matrix_stride
514*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(4, params[11]); // offset
515*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(-1, params[12]); // atomic_counter_buffer_index
516*8975f5c5SAndroid Build Coastguard Worker }
517*8975f5c5SAndroid Build Coastguard Worker
518*8975f5c5SAndroid Build Coastguard Worker // Tests the resource property query for uniform block can be done correctly.
TEST_P(ProgramInterfaceTestES31,GetUniformBlockProperties)519*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetUniformBlockProperties)
520*8975f5c5SAndroid Build Coastguard Worker {
521*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
522*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
523*8975f5c5SAndroid Build Coastguard Worker "in vec2 position;\n"
524*8975f5c5SAndroid Build Coastguard Worker "out vec2 v;\n"
525*8975f5c5SAndroid Build Coastguard Worker "layout(binding = 2) uniform blockName {\n"
526*8975f5c5SAndroid Build Coastguard Worker " float f1;\n"
527*8975f5c5SAndroid Build Coastguard Worker " float f2;\n"
528*8975f5c5SAndroid Build Coastguard Worker "} instanceName;\n"
529*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
530*8975f5c5SAndroid Build Coastguard Worker " v = vec2(instanceName.f1, instanceName.f2);\n"
531*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(position, 0, 1);\n"
532*8975f5c5SAndroid Build Coastguard Worker "}";
533*8975f5c5SAndroid Build Coastguard Worker
534*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
535*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
536*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
537*8975f5c5SAndroid Build Coastguard Worker "in vec2 v;\n"
538*8975f5c5SAndroid Build Coastguard Worker "out vec4 color;\n"
539*8975f5c5SAndroid Build Coastguard Worker "void main() {\n"
540*8975f5c5SAndroid Build Coastguard Worker " color = vec4(v, 0, 1);\n"
541*8975f5c5SAndroid Build Coastguard Worker "}";
542*8975f5c5SAndroid Build Coastguard Worker
543*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
544*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, kVS, kFS, std::get<1>(GetParam()));
545*8975f5c5SAndroid Build Coastguard Worker
546*8975f5c5SAndroid Build Coastguard Worker GLuint index = glGetProgramResourceIndex(program, GL_UNIFORM_BLOCK, "blockName");
547*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
548*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
549*8975f5c5SAndroid Build Coastguard Worker
550*8975f5c5SAndroid Build Coastguard Worker GLchar name[64];
551*8975f5c5SAndroid Build Coastguard Worker GLsizei length;
552*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_UNIFORM_BLOCK, index, sizeof(name), &length, name);
553*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
554*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(9, length);
555*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("blockName", std::string(name));
556*8975f5c5SAndroid Build Coastguard Worker
557*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_BUFFER_BINDING,
558*8975f5c5SAndroid Build Coastguard Worker GL_BUFFER_DATA_SIZE,
559*8975f5c5SAndroid Build Coastguard Worker GL_NAME_LENGTH,
560*8975f5c5SAndroid Build Coastguard Worker GL_NUM_ACTIVE_VARIABLES,
561*8975f5c5SAndroid Build Coastguard Worker GL_ACTIVE_VARIABLES,
562*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_VERTEX_SHADER,
563*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_FRAGMENT_SHADER,
564*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_COMPUTE_SHADER};
565*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
566*8975f5c5SAndroid Build Coastguard Worker constexpr int kBufSize = 256;
567*8975f5c5SAndroid Build Coastguard Worker GLint params[kBufSize];
568*8975f5c5SAndroid Build Coastguard Worker GLint magic = 0xBEEF;
569*8975f5c5SAndroid Build Coastguard Worker
570*8975f5c5SAndroid Build Coastguard Worker // Tests bufSize is respected even some prop returns more than one value.
571*8975f5c5SAndroid Build Coastguard Worker params[propCount] = magic;
572*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_UNIFORM_BLOCK, index, propCount, props, propCount, &length,
573*8975f5c5SAndroid Build Coastguard Worker params);
574*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
575*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
576*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, params[0]); // buffer_binding
577*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(0, params[1]); // buffer_data_size
578*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(10, params[2]); // name_length
579*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, params[3]); // num_active_variables
580*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[4]); // index of 'f1' or 'f2'
581*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[5]); // index of 'f1' or 'f2'
582*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[6]); // referenced_by_vertex_shader
583*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[7]); // referenced_by_fragment_shader
584*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(magic, params[8]);
585*8975f5c5SAndroid Build Coastguard Worker
586*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_UNIFORM_BLOCK, index, propCount, props, kBufSize, &length,
587*8975f5c5SAndroid Build Coastguard Worker params);
588*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
589*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount + 1, length);
590*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[8]); // referenced_by_compute_shader
591*8975f5c5SAndroid Build Coastguard Worker
592*8975f5c5SAndroid Build Coastguard Worker // bufSize is reached in middle of outputting values for GL_ACTIVE_VARIABLES.
593*8975f5c5SAndroid Build Coastguard Worker GLenum actvieVariablesProperty = GL_ACTIVE_VARIABLES;
594*8975f5c5SAndroid Build Coastguard Worker params[1] = magic;
595*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_UNIFORM_BLOCK, index, 1, &actvieVariablesProperty, 1,
596*8975f5c5SAndroid Build Coastguard Worker &length, params);
597*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
598*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, length);
599*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[0]); // index of 'f1' or 'f2'
600*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(magic, params[1]);
601*8975f5c5SAndroid Build Coastguard Worker }
602*8975f5c5SAndroid Build Coastguard Worker
603*8975f5c5SAndroid Build Coastguard Worker // Tests atomic counter buffer qeury works correctly.
TEST_P(ProgramInterfaceTestES31,QueryAtomicCounteBuffer)604*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, QueryAtomicCounteBuffer)
605*8975f5c5SAndroid Build Coastguard Worker {
606*8975f5c5SAndroid Build Coastguard Worker // Check atomic support.
607*8975f5c5SAndroid Build Coastguard Worker GLint numSupportedInVertex;
608*8975f5c5SAndroid Build Coastguard Worker GLint numSupportedInFragment;
609*8975f5c5SAndroid Build Coastguard Worker glGetIntegerv(GL_MAX_VERTEX_ATOMIC_COUNTERS, &numSupportedInVertex);
610*8975f5c5SAndroid Build Coastguard Worker glGetIntegerv(GL_MAX_FRAGMENT_ATOMIC_COUNTERS, &numSupportedInFragment);
611*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
612*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(numSupportedInVertex < 1 || numSupportedInFragment < 1);
613*8975f5c5SAndroid Build Coastguard Worker
614*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
615*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
616*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
617*8975f5c5SAndroid Build Coastguard Worker "layout(binding = 2, offset = 0) uniform atomic_uint vcounter;\n"
618*8975f5c5SAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
619*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
620*8975f5c5SAndroid Build Coastguard Worker "{\n"
621*8975f5c5SAndroid Build Coastguard Worker " atomicCounterIncrement(vcounter);\n"
622*8975f5c5SAndroid Build Coastguard Worker " gl_Position = a_position;\n"
623*8975f5c5SAndroid Build Coastguard Worker "}\n";
624*8975f5c5SAndroid Build Coastguard Worker
625*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
626*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
627*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
628*8975f5c5SAndroid Build Coastguard Worker "layout(binding = 2, offset = 4) uniform atomic_uint fcounter;\n"
629*8975f5c5SAndroid Build Coastguard Worker "out highp vec4 my_color;\n"
630*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
631*8975f5c5SAndroid Build Coastguard Worker "{\n"
632*8975f5c5SAndroid Build Coastguard Worker " atomicCounterDecrement(fcounter);\n"
633*8975f5c5SAndroid Build Coastguard Worker " my_color = vec4(0.0);\n"
634*8975f5c5SAndroid Build Coastguard Worker "}\n";
635*8975f5c5SAndroid Build Coastguard Worker
636*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
637*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, kVS, kFS, std::get<1>(GetParam()));
638*8975f5c5SAndroid Build Coastguard Worker
639*8975f5c5SAndroid Build Coastguard Worker GLint num;
640*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_ATOMIC_COUNTER_BUFFER, GL_ACTIVE_RESOURCES, &num);
641*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
642*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, num);
643*8975f5c5SAndroid Build Coastguard Worker
644*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_ATOMIC_COUNTER_BUFFER, GL_MAX_NUM_ACTIVE_VARIABLES, &num);
645*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
646*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, num);
647*8975f5c5SAndroid Build Coastguard Worker
648*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_BUFFER_BINDING, GL_NUM_ACTIVE_VARIABLES, GL_REFERENCED_BY_VERTEX_SHADER,
649*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_FRAGMENT_SHADER, GL_REFERENCED_BY_COMPUTE_SHADER};
650*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
651*8975f5c5SAndroid Build Coastguard Worker GLint params[ArraySize(props)];
652*8975f5c5SAndroid Build Coastguard Worker GLsizei length = 0;
653*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_ATOMIC_COUNTER_BUFFER, 0, propCount, props, propCount,
654*8975f5c5SAndroid Build Coastguard Worker &length, params);
655*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
656*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
657*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, params[0]); // buffer_binding
658*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, params[1]); // num_active_variables
659*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[2]); // referenced_by_vertex_shader
660*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[3]); // referenced_by_fragment_shader
661*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[4]); // referenced_by_compute_shader
662*8975f5c5SAndroid Build Coastguard Worker }
663*8975f5c5SAndroid Build Coastguard Worker
664*8975f5c5SAndroid Build Coastguard Worker // Tests the resource property query for buffer variable can be done correctly.
TEST_P(ProgramInterfaceTestES31,GetBufferVariableProperties)665*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetBufferVariableProperties)
666*8975f5c5SAndroid Build Coastguard Worker {
667*8975f5c5SAndroid Build Coastguard Worker // TODO([email protected]): Don't skip this test once non-simple SSBO sentences are supported
668*8975f5c5SAndroid Build Coastguard Worker // on d3d backend. http://anglebug.com/40644618
669*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsD3D11());
670*8975f5c5SAndroid Build Coastguard Worker
671*8975f5c5SAndroid Build Coastguard Worker // Check SSBO support
672*8975f5c5SAndroid Build Coastguard Worker GLint numSupported;
673*8975f5c5SAndroid Build Coastguard Worker glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &numSupported);
674*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
675*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(numSupported < 2);
676*8975f5c5SAndroid Build Coastguard Worker
677*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
678*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
679*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
680*8975f5c5SAndroid Build Coastguard Worker "struct S {\n"
681*8975f5c5SAndroid Build Coastguard Worker " vec3 a;\n"
682*8975f5c5SAndroid Build Coastguard Worker " ivec2 b[4];\n"
683*8975f5c5SAndroid Build Coastguard Worker "};\n"
684*8975f5c5SAndroid Build Coastguard Worker "layout(std140) buffer blockName0 {\n"
685*8975f5c5SAndroid Build Coastguard Worker " S s0;\n"
686*8975f5c5SAndroid Build Coastguard Worker " vec2 v0;\n"
687*8975f5c5SAndroid Build Coastguard Worker " S s1[2];\n"
688*8975f5c5SAndroid Build Coastguard Worker " uint u0;\n"
689*8975f5c5SAndroid Build Coastguard Worker "};\n"
690*8975f5c5SAndroid Build Coastguard Worker "layout(binding = 1) buffer blockName1 {\n"
691*8975f5c5SAndroid Build Coastguard Worker " uint u1[2];\n"
692*8975f5c5SAndroid Build Coastguard Worker " float f1;\n"
693*8975f5c5SAndroid Build Coastguard Worker "} instanceName1[2];\n"
694*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
695*8975f5c5SAndroid Build Coastguard Worker "{\n"
696*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(instanceName1[0].f1, s1[0].a);\n"
697*8975f5c5SAndroid Build Coastguard Worker "}\n";
698*8975f5c5SAndroid Build Coastguard Worker
699*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
700*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
701*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
702*8975f5c5SAndroid Build Coastguard Worker "layout(binding = 1) buffer blockName1 {\n"
703*8975f5c5SAndroid Build Coastguard Worker " uint u1[2];\n"
704*8975f5c5SAndroid Build Coastguard Worker " float f1;\n"
705*8975f5c5SAndroid Build Coastguard Worker "} instanceName1[2];\n"
706*8975f5c5SAndroid Build Coastguard Worker "out vec4 oColor;\n"
707*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
708*8975f5c5SAndroid Build Coastguard Worker "{\n"
709*8975f5c5SAndroid Build Coastguard Worker " oColor = vec4(instanceName1[0].f1, 0, 0, 1);\n"
710*8975f5c5SAndroid Build Coastguard Worker "}";
711*8975f5c5SAndroid Build Coastguard Worker
712*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
713*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, kVS, kFS, std::get<1>(GetParam()));
714*8975f5c5SAndroid Build Coastguard Worker
715*8975f5c5SAndroid Build Coastguard Worker GLuint index = glGetProgramResourceIndex(program, GL_BUFFER_VARIABLE, "blockName1.f1");
716*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
717*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
718*8975f5c5SAndroid Build Coastguard Worker
719*8975f5c5SAndroid Build Coastguard Worker GLchar name[64];
720*8975f5c5SAndroid Build Coastguard Worker GLsizei length;
721*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_BUFFER_VARIABLE, index, sizeof(name), &length, name);
722*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
723*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(13, length);
724*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("blockName1.f1", std::string(name));
725*8975f5c5SAndroid Build Coastguard Worker
726*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_ARRAY_SIZE,
727*8975f5c5SAndroid Build Coastguard Worker GL_ARRAY_STRIDE,
728*8975f5c5SAndroid Build Coastguard Worker GL_BLOCK_INDEX,
729*8975f5c5SAndroid Build Coastguard Worker GL_IS_ROW_MAJOR,
730*8975f5c5SAndroid Build Coastguard Worker GL_MATRIX_STRIDE,
731*8975f5c5SAndroid Build Coastguard Worker GL_NAME_LENGTH,
732*8975f5c5SAndroid Build Coastguard Worker GL_OFFSET,
733*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_VERTEX_SHADER,
734*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_FRAGMENT_SHADER,
735*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_COMPUTE_SHADER,
736*8975f5c5SAndroid Build Coastguard Worker GL_TOP_LEVEL_ARRAY_SIZE,
737*8975f5c5SAndroid Build Coastguard Worker GL_TOP_LEVEL_ARRAY_STRIDE,
738*8975f5c5SAndroid Build Coastguard Worker GL_TYPE};
739*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
740*8975f5c5SAndroid Build Coastguard Worker constexpr int kBufSize = 256;
741*8975f5c5SAndroid Build Coastguard Worker GLint params[kBufSize];
742*8975f5c5SAndroid Build Coastguard Worker
743*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_BUFFER_VARIABLE, index, propCount, props, kBufSize, &length,
744*8975f5c5SAndroid Build Coastguard Worker params);
745*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
746*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
747*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[0]); // array_size
748*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[1]); // array_stride
749*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[2]); // block_index
750*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[3]); // is_row_major
751*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[4]); // matrix_stride
752*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(14, params[5]); // name_length
753*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[6]); // offset
754*8975f5c5SAndroid Build Coastguard Worker
755*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[7]); // referenced_by_vertex_shader
756*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[8]); // referenced_by_fragment_shader
757*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[9]); // referenced_by_compute_shader
758*8975f5c5SAndroid Build Coastguard Worker
759*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[10]); // top_level_array_size
760*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[11]); // top_level_array_stride
761*8975f5c5SAndroid Build Coastguard Worker
762*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_FLOAT, params[12]); // type
763*8975f5c5SAndroid Build Coastguard Worker
764*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_BUFFER_VARIABLE, "s1[0].a");
765*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
766*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
767*8975f5c5SAndroid Build Coastguard Worker
768*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_BUFFER_VARIABLE, index, sizeof(name), &length, name);
769*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
770*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(7, length);
771*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("s1[0].a", std::string(name));
772*8975f5c5SAndroid Build Coastguard Worker
773*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_BUFFER_VARIABLE, index, propCount, props, kBufSize, &length,
774*8975f5c5SAndroid Build Coastguard Worker params);
775*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
776*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
777*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[0]); // array_size
778*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[1]); // array_stride
779*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[2]); // block_index
780*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[3]); // is_row_major
781*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[4]); // matrix_stride
782*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(8, params[5]); // name_length
783*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[6]); // offset
784*8975f5c5SAndroid Build Coastguard Worker
785*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[7]); // referenced_by_vertex_shader
786*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[8]); // referenced_by_fragment_shader
787*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[9]); // referenced_by_compute_shader
788*8975f5c5SAndroid Build Coastguard Worker
789*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, params[10]); // top_level_array_size
790*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(80, params[11]); // top_level_array_stride
791*8975f5c5SAndroid Build Coastguard Worker
792*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_FLOAT_VEC3, params[12]); // type
793*8975f5c5SAndroid Build Coastguard Worker }
794*8975f5c5SAndroid Build Coastguard Worker
795*8975f5c5SAndroid Build Coastguard Worker // Tests the resource property querying for buffer variable in std430 SSBO works correctly.
TEST_P(ProgramInterfaceTestES31,GetStd430BufferVariableProperties)796*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetStd430BufferVariableProperties)
797*8975f5c5SAndroid Build Coastguard Worker {
798*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
799*8975f5c5SAndroid Build Coastguard Worker
800*8975f5c5SAndroid Build Coastguard Worker constexpr char kComputeShaderSource[] =
801*8975f5c5SAndroid Build Coastguard Worker R"(#version 310 es
802*8975f5c5SAndroid Build Coastguard Worker layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
803*8975f5c5SAndroid Build Coastguard Worker struct S
804*8975f5c5SAndroid Build Coastguard Worker {
805*8975f5c5SAndroid Build Coastguard Worker uvec2 v;
806*8975f5c5SAndroid Build Coastguard Worker mat2 m;
807*8975f5c5SAndroid Build Coastguard Worker };
808*8975f5c5SAndroid Build Coastguard Worker layout(std430, binding = 0) buffer blockIn {
809*8975f5c5SAndroid Build Coastguard Worker uint u;
810*8975f5c5SAndroid Build Coastguard Worker uint a[2];
811*8975f5c5SAndroid Build Coastguard Worker S s;
812*8975f5c5SAndroid Build Coastguard Worker } instanceIn;
813*8975f5c5SAndroid Build Coastguard Worker layout(std430, binding = 1) buffer blockOut {
814*8975f5c5SAndroid Build Coastguard Worker uint u;
815*8975f5c5SAndroid Build Coastguard Worker uint a[2];
816*8975f5c5SAndroid Build Coastguard Worker S s;
817*8975f5c5SAndroid Build Coastguard Worker } instanceOut;
818*8975f5c5SAndroid Build Coastguard Worker void main()
819*8975f5c5SAndroid Build Coastguard Worker {
820*8975f5c5SAndroid Build Coastguard Worker instanceOut.u = instanceIn.u;
821*8975f5c5SAndroid Build Coastguard Worker instanceOut.a[0] = instanceIn.a[0];
822*8975f5c5SAndroid Build Coastguard Worker instanceOut.a[1] = instanceIn.a[1];
823*8975f5c5SAndroid Build Coastguard Worker instanceOut.s.v = instanceIn.s.v;
824*8975f5c5SAndroid Build Coastguard Worker instanceOut.s.m = instanceIn.s.m;
825*8975f5c5SAndroid Build Coastguard Worker }
826*8975f5c5SAndroid Build Coastguard Worker )";
827*8975f5c5SAndroid Build Coastguard Worker
828*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
829*8975f5c5SAndroid Build Coastguard Worker createComputeProgram(program, kComputeShaderSource, std::get<1>(GetParam()));
830*8975f5c5SAndroid Build Coastguard Worker
831*8975f5c5SAndroid Build Coastguard Worker GLuint index = glGetProgramResourceIndex(program, GL_BUFFER_VARIABLE, "blockIn.a");
832*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
833*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
834*8975f5c5SAndroid Build Coastguard Worker
835*8975f5c5SAndroid Build Coastguard Worker GLchar name[64];
836*8975f5c5SAndroid Build Coastguard Worker GLsizei length;
837*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_BUFFER_VARIABLE, index, sizeof(name), &length, name);
838*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
839*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(12, length);
840*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("blockIn.a[0]", std::string(name));
841*8975f5c5SAndroid Build Coastguard Worker
842*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_ARRAY_SIZE,
843*8975f5c5SAndroid Build Coastguard Worker GL_ARRAY_STRIDE,
844*8975f5c5SAndroid Build Coastguard Worker GL_BLOCK_INDEX,
845*8975f5c5SAndroid Build Coastguard Worker GL_IS_ROW_MAJOR,
846*8975f5c5SAndroid Build Coastguard Worker GL_MATRIX_STRIDE,
847*8975f5c5SAndroid Build Coastguard Worker GL_NAME_LENGTH,
848*8975f5c5SAndroid Build Coastguard Worker GL_OFFSET,
849*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_VERTEX_SHADER,
850*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_FRAGMENT_SHADER,
851*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_COMPUTE_SHADER,
852*8975f5c5SAndroid Build Coastguard Worker GL_TOP_LEVEL_ARRAY_SIZE,
853*8975f5c5SAndroid Build Coastguard Worker GL_TOP_LEVEL_ARRAY_STRIDE,
854*8975f5c5SAndroid Build Coastguard Worker GL_TYPE};
855*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
856*8975f5c5SAndroid Build Coastguard Worker constexpr int kBufSize = 256;
857*8975f5c5SAndroid Build Coastguard Worker GLint params[kBufSize];
858*8975f5c5SAndroid Build Coastguard Worker
859*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_BUFFER_VARIABLE, index, propCount, props, kBufSize, &length,
860*8975f5c5SAndroid Build Coastguard Worker params);
861*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
862*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
863*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, params[0]); // array_size
864*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(4, params[1]); // array_stride
865*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[2]); // block_index
866*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[3]); // is_row_major
867*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[4]); // matrix_stride
868*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(13, params[5]); // name_length
869*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(4, params[6]); // offset
870*8975f5c5SAndroid Build Coastguard Worker
871*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[7]); // referenced_by_vertex_shader
872*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[8]); // referenced_by_fragment_shader
873*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[9]); // referenced_by_compute_shader
874*8975f5c5SAndroid Build Coastguard Worker
875*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[10]); // top_level_array_size
876*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[11]); // top_level_array_stride
877*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_UNSIGNED_INT, params[12]); // type
878*8975f5c5SAndroid Build Coastguard Worker
879*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_BUFFER_VARIABLE, "blockIn.s.m");
880*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
881*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
882*8975f5c5SAndroid Build Coastguard Worker
883*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_BUFFER_VARIABLE, index, sizeof(name), &length, name);
884*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
885*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(11, length);
886*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("blockIn.s.m", std::string(name));
887*8975f5c5SAndroid Build Coastguard Worker
888*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_BUFFER_VARIABLE, index, propCount, props, kBufSize, &length,
889*8975f5c5SAndroid Build Coastguard Worker params);
890*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
891*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
892*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[0]); // array_size
893*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[1]); // array_stride
894*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[2]); // block_index
895*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[3]); // is_row_major
896*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(8, params[4]); // matrix_stride
897*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(12, params[5]); // name_length
898*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(24, params[6]); // offset
899*8975f5c5SAndroid Build Coastguard Worker
900*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[7]); // referenced_by_vertex_shader
901*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[8]); // referenced_by_fragment_shader
902*8975f5c5SAndroid Build Coastguard Worker // TODO([email protected]): referenced_by_compute_shader is not
903*8975f5c5SAndroid Build Coastguard Worker // correctly handled. http://anglebug.com/42260711.
904*8975f5c5SAndroid Build Coastguard Worker // EXPECT_EQ(1, params[9]); // referenced_by_compute_shader
905*8975f5c5SAndroid Build Coastguard Worker
906*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[10]); // top_level_array_size
907*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[11]); // top_level_array_stride
908*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_FLOAT_MAT2, params[12]); // type
909*8975f5c5SAndroid Build Coastguard Worker }
910*8975f5c5SAndroid Build Coastguard Worker
911*8975f5c5SAndroid Build Coastguard Worker // Test that TOP_LEVEL_ARRAY_STRIDE for buffer variable with aggregate type works correctly.
TEST_P(ProgramInterfaceTestES31,TopLevelArrayStrideWithAggregateType)912*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, TopLevelArrayStrideWithAggregateType)
913*8975f5c5SAndroid Build Coastguard Worker {
914*8975f5c5SAndroid Build Coastguard Worker constexpr char kComputeShaderSource[] =
915*8975f5c5SAndroid Build Coastguard Worker R"(#version 310 es
916*8975f5c5SAndroid Build Coastguard Worker layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
917*8975f5c5SAndroid Build Coastguard Worker struct S
918*8975f5c5SAndroid Build Coastguard Worker {
919*8975f5c5SAndroid Build Coastguard Worker uvec2 v;
920*8975f5c5SAndroid Build Coastguard Worker mat2 m;
921*8975f5c5SAndroid Build Coastguard Worker };
922*8975f5c5SAndroid Build Coastguard Worker layout(std430, binding = 0) buffer blockIn {
923*8975f5c5SAndroid Build Coastguard Worker uint u;
924*8975f5c5SAndroid Build Coastguard Worker uint a[2];
925*8975f5c5SAndroid Build Coastguard Worker S s;
926*8975f5c5SAndroid Build Coastguard Worker } instanceIn;
927*8975f5c5SAndroid Build Coastguard Worker layout(std430, binding = 1) buffer blockOut {
928*8975f5c5SAndroid Build Coastguard Worker uint u;
929*8975f5c5SAndroid Build Coastguard Worker uint a[4][3];
930*8975f5c5SAndroid Build Coastguard Worker S s[3][2];
931*8975f5c5SAndroid Build Coastguard Worker } instanceOut;
932*8975f5c5SAndroid Build Coastguard Worker void main()
933*8975f5c5SAndroid Build Coastguard Worker {
934*8975f5c5SAndroid Build Coastguard Worker instanceOut.u = instanceIn.u;
935*8975f5c5SAndroid Build Coastguard Worker instanceOut.a[0][0] = instanceIn.a[0];
936*8975f5c5SAndroid Build Coastguard Worker instanceOut.a[0][1] = instanceIn.a[1];
937*8975f5c5SAndroid Build Coastguard Worker instanceOut.s[0][0].v = instanceIn.s.v;
938*8975f5c5SAndroid Build Coastguard Worker instanceOut.s[0][0].m = instanceIn.s.m;
939*8975f5c5SAndroid Build Coastguard Worker }
940*8975f5c5SAndroid Build Coastguard Worker )";
941*8975f5c5SAndroid Build Coastguard Worker
942*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
943*8975f5c5SAndroid Build Coastguard Worker createComputeProgram(program, kComputeShaderSource, std::get<1>(GetParam()));
944*8975f5c5SAndroid Build Coastguard Worker
945*8975f5c5SAndroid Build Coastguard Worker GLuint index = glGetProgramResourceIndex(program, GL_BUFFER_VARIABLE, "blockOut.s[0][0].m");
946*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
947*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
948*8975f5c5SAndroid Build Coastguard Worker
949*8975f5c5SAndroid Build Coastguard Worker GLchar name[64];
950*8975f5c5SAndroid Build Coastguard Worker GLsizei length;
951*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_BUFFER_VARIABLE, index, sizeof(name), &length, name);
952*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
953*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(18, length);
954*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("blockOut.s[0][0].m", std::string(name));
955*8975f5c5SAndroid Build Coastguard Worker
956*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_ARRAY_SIZE,
957*8975f5c5SAndroid Build Coastguard Worker GL_ARRAY_STRIDE,
958*8975f5c5SAndroid Build Coastguard Worker GL_BLOCK_INDEX,
959*8975f5c5SAndroid Build Coastguard Worker GL_IS_ROW_MAJOR,
960*8975f5c5SAndroid Build Coastguard Worker GL_MATRIX_STRIDE,
961*8975f5c5SAndroid Build Coastguard Worker GL_NAME_LENGTH,
962*8975f5c5SAndroid Build Coastguard Worker GL_OFFSET,
963*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_VERTEX_SHADER,
964*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_FRAGMENT_SHADER,
965*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_COMPUTE_SHADER,
966*8975f5c5SAndroid Build Coastguard Worker GL_TOP_LEVEL_ARRAY_SIZE,
967*8975f5c5SAndroid Build Coastguard Worker GL_TOP_LEVEL_ARRAY_STRIDE,
968*8975f5c5SAndroid Build Coastguard Worker GL_TYPE};
969*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
970*8975f5c5SAndroid Build Coastguard Worker constexpr int kBufSize = 256;
971*8975f5c5SAndroid Build Coastguard Worker GLint params[kBufSize];
972*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_BUFFER_VARIABLE, index, propCount, props, kBufSize, &length,
973*8975f5c5SAndroid Build Coastguard Worker params);
974*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
975*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
976*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[0]); // array_size
977*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[1]); // array_stride
978*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[2]); // block_index
979*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[3]); // is_row_major
980*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(8, params[4]); // matrix_stride
981*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(19, params[5]); // name_length
982*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(64, params[6]); // offset
983*8975f5c5SAndroid Build Coastguard Worker
984*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[7]); // referenced_by_vertex_shader
985*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[8]); // referenced_by_fragment_shader
986*8975f5c5SAndroid Build Coastguard Worker // TODO([email protected]): referenced_by_compute_shader is not
987*8975f5c5SAndroid Build Coastguard Worker // correctly handled. http://anglebug.com/42260711.
988*8975f5c5SAndroid Build Coastguard Worker // EXPECT_EQ(1, params[9]); // referenced_by_compute_shader
989*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, params[10]); // top_level_array_size
990*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(48, params[11]); // top_level_array_stride
991*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_FLOAT_MAT2, params[12]); // type
992*8975f5c5SAndroid Build Coastguard Worker
993*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_BUFFER_VARIABLE, "blockOut.a[0][0]");
994*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
995*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
996*8975f5c5SAndroid Build Coastguard Worker
997*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_BUFFER_VARIABLE, index, sizeof(name), &length, name);
998*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
999*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(16, length);
1000*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("blockOut.a[0][0]", std::string(name));
1001*8975f5c5SAndroid Build Coastguard Worker
1002*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_BUFFER_VARIABLE, index, propCount, props, kBufSize, &length,
1003*8975f5c5SAndroid Build Coastguard Worker params);
1004*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1005*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
1006*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, params[0]); // array_size
1007*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[1]); // array_stride
1008*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[2]); // block_index
1009*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[3]); // is_row_major
1010*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[4]); // matrix_stride
1011*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(17, params[5]); // name_length
1012*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(4, params[6]); // offset
1013*8975f5c5SAndroid Build Coastguard Worker
1014*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[7]); // referenced_by_vertex_shader
1015*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[8]); // referenced_by_fragment_shader
1016*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[9]); // referenced_by_compute_shader
1017*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(4, params[10]); // top_level_array_size
1018*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(12, params[11]); // top_level_array_stride
1019*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_UNSIGNED_INT, params[12]); // type
1020*8975f5c5SAndroid Build Coastguard Worker }
1021*8975f5c5SAndroid Build Coastguard Worker
1022*8975f5c5SAndroid Build Coastguard Worker // Tests the resource property query for shader storage block can be done correctly.
TEST_P(ProgramInterfaceTestES31,GetShaderStorageBlockProperties)1023*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetShaderStorageBlockProperties)
1024*8975f5c5SAndroid Build Coastguard Worker {
1025*8975f5c5SAndroid Build Coastguard Worker // TODO([email protected]): Don't skip this test once non-simple SSBO sentences are supported
1026*8975f5c5SAndroid Build Coastguard Worker // on d3d backend. http://anglebug.com/40644618
1027*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsD3D11());
1028*8975f5c5SAndroid Build Coastguard Worker
1029*8975f5c5SAndroid Build Coastguard Worker // Check SSBO support
1030*8975f5c5SAndroid Build Coastguard Worker GLint numSupported;
1031*8975f5c5SAndroid Build Coastguard Worker glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &numSupported);
1032*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1033*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(numSupported < 3);
1034*8975f5c5SAndroid Build Coastguard Worker
1035*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
1036*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
1037*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
1038*8975f5c5SAndroid Build Coastguard Worker "struct S {\n"
1039*8975f5c5SAndroid Build Coastguard Worker " vec3 a;\n"
1040*8975f5c5SAndroid Build Coastguard Worker " ivec2 b[4];\n"
1041*8975f5c5SAndroid Build Coastguard Worker "};\n"
1042*8975f5c5SAndroid Build Coastguard Worker "layout(std140) buffer blockName0 {\n"
1043*8975f5c5SAndroid Build Coastguard Worker " S s0;\n"
1044*8975f5c5SAndroid Build Coastguard Worker " vec2 v0;\n"
1045*8975f5c5SAndroid Build Coastguard Worker " S s1[2];\n"
1046*8975f5c5SAndroid Build Coastguard Worker " uint u0;\n"
1047*8975f5c5SAndroid Build Coastguard Worker "};\n"
1048*8975f5c5SAndroid Build Coastguard Worker "layout(binding = 1) buffer blockName1 {\n"
1049*8975f5c5SAndroid Build Coastguard Worker " uint u1[2];\n"
1050*8975f5c5SAndroid Build Coastguard Worker " float f1;\n"
1051*8975f5c5SAndroid Build Coastguard Worker "} instanceName1[2];\n"
1052*8975f5c5SAndroid Build Coastguard Worker "layout(binding = 2) buffer blockName2 {\n"
1053*8975f5c5SAndroid Build Coastguard Worker " uint u2;\n"
1054*8975f5c5SAndroid Build Coastguard Worker " float f2;\n"
1055*8975f5c5SAndroid Build Coastguard Worker "};\n"
1056*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
1057*8975f5c5SAndroid Build Coastguard Worker "{\n"
1058*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(instanceName1[0].f1, s1[0].a);\n"
1059*8975f5c5SAndroid Build Coastguard Worker "}\n";
1060*8975f5c5SAndroid Build Coastguard Worker
1061*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] =
1062*8975f5c5SAndroid Build Coastguard Worker "#version 310 es\n"
1063*8975f5c5SAndroid Build Coastguard Worker "precision highp float;\n"
1064*8975f5c5SAndroid Build Coastguard Worker "uniform vec4 color;\n"
1065*8975f5c5SAndroid Build Coastguard Worker "out vec4 oColor;\n"
1066*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
1067*8975f5c5SAndroid Build Coastguard Worker "{\n"
1068*8975f5c5SAndroid Build Coastguard Worker " oColor = color;\n"
1069*8975f5c5SAndroid Build Coastguard Worker "}";
1070*8975f5c5SAndroid Build Coastguard Worker
1071*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
1072*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, kVS, kFS, std::get<1>(GetParam()));
1073*8975f5c5SAndroid Build Coastguard Worker
1074*8975f5c5SAndroid Build Coastguard Worker GLuint index = glGetProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, "blockName0");
1075*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1076*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
1077*8975f5c5SAndroid Build Coastguard Worker
1078*8975f5c5SAndroid Build Coastguard Worker GLchar name[64];
1079*8975f5c5SAndroid Build Coastguard Worker GLsizei length;
1080*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_SHADER_STORAGE_BLOCK, index, sizeof(name), &length, name);
1081*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1082*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(10, length);
1083*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("blockName0", std::string(name));
1084*8975f5c5SAndroid Build Coastguard Worker
1085*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_ACTIVE_VARIABLES,
1086*8975f5c5SAndroid Build Coastguard Worker GL_BUFFER_BINDING,
1087*8975f5c5SAndroid Build Coastguard Worker GL_NUM_ACTIVE_VARIABLES,
1088*8975f5c5SAndroid Build Coastguard Worker GL_BUFFER_DATA_SIZE,
1089*8975f5c5SAndroid Build Coastguard Worker GL_NAME_LENGTH,
1090*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_VERTEX_SHADER,
1091*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_FRAGMENT_SHADER,
1092*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_COMPUTE_SHADER};
1093*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
1094*8975f5c5SAndroid Build Coastguard Worker constexpr int kBufSize = 256;
1095*8975f5c5SAndroid Build Coastguard Worker GLint params[kBufSize];
1096*8975f5c5SAndroid Build Coastguard Worker
1097*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_SHADER_STORAGE_BLOCK, index, propCount, props, kBufSize,
1098*8975f5c5SAndroid Build Coastguard Worker &length, params);
1099*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1100*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(13, length);
1101*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[0]); // active_variables s0.a
1102*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[1]); // active_variables s0.b
1103*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[2]); // active_variables v0
1104*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[3]); // active_variables s1[0].a
1105*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[4]); // active_variables s1[0].b
1106*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[5]); // active_variables u0
1107*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[6]); // buffer_binding
1108*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(6, params[7]); // num_active_variables
1109*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[8]); // buffer_data_size
1110*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(11, params[9]); // name_length
1111*8975f5c5SAndroid Build Coastguard Worker
1112*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[10]); // referenced_by_vertex_shader
1113*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[11]); // referenced_by_fragment_shader
1114*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[12]); // referenced_by_compute_shader
1115*8975f5c5SAndroid Build Coastguard Worker
1116*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, "blockName1");
1117*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1118*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
1119*8975f5c5SAndroid Build Coastguard Worker
1120*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceName(program, GL_SHADER_STORAGE_BLOCK, index, sizeof(name), &length, name);
1121*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1122*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(13, length);
1123*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ("blockName1[0]", std::string(name));
1124*8975f5c5SAndroid Build Coastguard Worker }
1125*8975f5c5SAndroid Build Coastguard Worker
1126*8975f5c5SAndroid Build Coastguard Worker // Tests querying the program resources of atomic counter buffers.
TEST_P(ProgramInterfaceTestES31,GetAtomicCounterProperties)1127*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, GetAtomicCounterProperties)
1128*8975f5c5SAndroid Build Coastguard Worker {
1129*8975f5c5SAndroid Build Coastguard Worker constexpr char kCSSource[] = R"(#version 310 es
1130*8975f5c5SAndroid Build Coastguard Worker layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
1131*8975f5c5SAndroid Build Coastguard Worker layout(binding = 0) uniform atomic_uint acbase;
1132*8975f5c5SAndroid Build Coastguard Worker layout(binding = 0, offset = 8) uniform atomic_uint ac[1];
1133*8975f5c5SAndroid Build Coastguard Worker layout(binding = 0) uniform atomic_uint ac2;
1134*8975f5c5SAndroid Build Coastguard Worker
1135*8975f5c5SAndroid Build Coastguard Worker void main()
1136*8975f5c5SAndroid Build Coastguard Worker {
1137*8975f5c5SAndroid Build Coastguard Worker atomicCounterIncrement(acbase);
1138*8975f5c5SAndroid Build Coastguard Worker atomicCounterIncrement(ac[0]);
1139*8975f5c5SAndroid Build Coastguard Worker atomicCounterIncrement(ac2);
1140*8975f5c5SAndroid Build Coastguard Worker })";
1141*8975f5c5SAndroid Build Coastguard Worker
1142*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
1143*8975f5c5SAndroid Build Coastguard Worker createComputeProgram(program, kCSSource, std::get<1>(GetParam()));
1144*8975f5c5SAndroid Build Coastguard Worker
1145*8975f5c5SAndroid Build Coastguard Worker GLuint index = glGetProgramResourceIndex(program, GL_UNIFORM, "ac");
1146*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1147*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(GL_INVALID_INDEX, index);
1148*8975f5c5SAndroid Build Coastguard Worker
1149*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_ATOMIC_COUNTER_BUFFER_INDEX};
1150*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
1151*8975f5c5SAndroid Build Coastguard Worker GLint atomicIndex;
1152*8975f5c5SAndroid Build Coastguard Worker GLsizei length;
1153*8975f5c5SAndroid Build Coastguard Worker
1154*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_UNIFORM, index, propCount, props, 1, &length, &atomicIndex);
1155*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1156*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, length);
1157*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, atomicIndex);
1158*8975f5c5SAndroid Build Coastguard Worker
1159*8975f5c5SAndroid Build Coastguard Worker GLenum atomicProps[] = {GL_ACTIVE_VARIABLES,
1160*8975f5c5SAndroid Build Coastguard Worker GL_BUFFER_BINDING,
1161*8975f5c5SAndroid Build Coastguard Worker GL_NUM_ACTIVE_VARIABLES,
1162*8975f5c5SAndroid Build Coastguard Worker GL_BUFFER_DATA_SIZE,
1163*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_VERTEX_SHADER,
1164*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_FRAGMENT_SHADER,
1165*8975f5c5SAndroid Build Coastguard Worker GL_REFERENCED_BY_COMPUTE_SHADER};
1166*8975f5c5SAndroid Build Coastguard Worker
1167*8975f5c5SAndroid Build Coastguard Worker GLsizei atomicPropsCount = static_cast<GLsizei>(ArraySize(atomicProps));
1168*8975f5c5SAndroid Build Coastguard Worker constexpr int kBufSize = 256;
1169*8975f5c5SAndroid Build Coastguard Worker GLint params[kBufSize];
1170*8975f5c5SAndroid Build Coastguard Worker GLsizei length2;
1171*8975f5c5SAndroid Build Coastguard Worker
1172*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_ATOMIC_COUNTER_BUFFER, atomicIndex, atomicPropsCount,
1173*8975f5c5SAndroid Build Coastguard Worker atomicProps, kBufSize, &length2, params);
1174*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1175*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(9, length2);
1176*8975f5c5SAndroid Build Coastguard Worker
1177*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[0]); // active_variables acbase
1178*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[1]); // active_variables ac[1]
1179*8975f5c5SAndroid Build Coastguard Worker EXPECT_LE(0, params[2]); // active_variables ac2
1180*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[3]); // buffer_binding
1181*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3, params[4]); // num_active_variables
1182*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(16, params[5]); // buffer_data_size
1183*8975f5c5SAndroid Build Coastguard Worker
1184*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[6]); // referenced_by_vertex_shader
1185*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0, params[7]); // referenced_by_fragment_shader
1186*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[8]); // referenced_by_compute_shader
1187*8975f5c5SAndroid Build Coastguard Worker }
1188*8975f5c5SAndroid Build Coastguard Worker
1189*8975f5c5SAndroid Build Coastguard Worker // Tests transform feedback varying qeury works correctly.
TEST_P(ProgramInterfaceTestES31,QueryTransformFeedbackVarying)1190*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, QueryTransformFeedbackVarying)
1191*8975f5c5SAndroid Build Coastguard Worker {
1192*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] = R"(#version 310 es
1193*8975f5c5SAndroid Build Coastguard Worker in vec3 position;
1194*8975f5c5SAndroid Build Coastguard Worker out float outSingleType;
1195*8975f5c5SAndroid Build Coastguard Worker out vec2 outWholeArray[2];
1196*8975f5c5SAndroid Build Coastguard Worker out vec3 outArrayElements[16];
1197*8975f5c5SAndroid Build Coastguard Worker void main() {
1198*8975f5c5SAndroid Build Coastguard Worker outSingleType = 0.0;
1199*8975f5c5SAndroid Build Coastguard Worker outWholeArray[0] = vec2(position);
1200*8975f5c5SAndroid Build Coastguard Worker outArrayElements[7] = vec3(0, 0, 0);
1201*8975f5c5SAndroid Build Coastguard Worker outArrayElements[15] = position;
1202*8975f5c5SAndroid Build Coastguard Worker gl_Position = vec4(position, 1);
1203*8975f5c5SAndroid Build Coastguard Worker })";
1204*8975f5c5SAndroid Build Coastguard Worker
1205*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] = R"(#version 310 es
1206*8975f5c5SAndroid Build Coastguard Worker precision mediump float;
1207*8975f5c5SAndroid Build Coastguard Worker out vec4 color;
1208*8975f5c5SAndroid Build Coastguard Worker in float outSingleType;
1209*8975f5c5SAndroid Build Coastguard Worker in vec2 outWholeArray[2];
1210*8975f5c5SAndroid Build Coastguard Worker in vec3 outArrayElements[16];
1211*8975f5c5SAndroid Build Coastguard Worker void main() {
1212*8975f5c5SAndroid Build Coastguard Worker color = vec4(0);
1213*8975f5c5SAndroid Build Coastguard Worker })";
1214*8975f5c5SAndroid Build Coastguard Worker
1215*8975f5c5SAndroid Build Coastguard Worker std::vector<std::string> tfVaryings;
1216*8975f5c5SAndroid Build Coastguard Worker tfVaryings.push_back("outArrayElements[7]");
1217*8975f5c5SAndroid Build Coastguard Worker tfVaryings.push_back("outArrayElements[15]");
1218*8975f5c5SAndroid Build Coastguard Worker tfVaryings.push_back("outSingleType");
1219*8975f5c5SAndroid Build Coastguard Worker tfVaryings.push_back("outWholeArray");
1220*8975f5c5SAndroid Build Coastguard Worker
1221*8975f5c5SAndroid Build Coastguard Worker GLuint program =
1222*8975f5c5SAndroid Build Coastguard Worker CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS);
1223*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, program);
1224*8975f5c5SAndroid Build Coastguard Worker
1225*8975f5c5SAndroid Build Coastguard Worker GLint num;
1226*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_TRANSFORM_FEEDBACK_VARYING, GL_ACTIVE_RESOURCES, &num);
1227*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1228*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(4, num);
1229*8975f5c5SAndroid Build Coastguard Worker
1230*8975f5c5SAndroid Build Coastguard Worker glGetProgramInterfaceiv(program, GL_TRANSFORM_FEEDBACK_VARYING, GL_MAX_NAME_LENGTH, &num);
1231*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1232*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(21, num); // outArrayElements[15]
1233*8975f5c5SAndroid Build Coastguard Worker
1234*8975f5c5SAndroid Build Coastguard Worker // GLES 3.10, Page 77:
1235*8975f5c5SAndroid Build Coastguard Worker // For TRANSFORM_FEEDBACK_VARYING, the active resource list will use the variable order
1236*8975f5c5SAndroid Build Coastguard Worker // specified in the most recent call to TransformFeedbackVaryings before the last call to
1237*8975f5c5SAndroid Build Coastguard Worker // LinkProgram.
1238*8975f5c5SAndroid Build Coastguard Worker GLuint index =
1239*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceIndex(program, GL_TRANSFORM_FEEDBACK_VARYING, "outArrayElements[7]");
1240*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1241*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0u, index);
1242*8975f5c5SAndroid Build Coastguard Worker index =
1243*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceIndex(program, GL_TRANSFORM_FEEDBACK_VARYING, "outArrayElements[15]");
1244*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1245*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1u, index);
1246*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_TRANSFORM_FEEDBACK_VARYING, "outSingleType");
1247*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1248*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2u, index);
1249*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_TRANSFORM_FEEDBACK_VARYING, "outWholeArray");
1250*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1251*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(3u, index);
1252*8975f5c5SAndroid Build Coastguard Worker
1253*8975f5c5SAndroid Build Coastguard Worker // GLES 3.10, Page 80:
1254*8975f5c5SAndroid Build Coastguard Worker // For TRANSFORM_FEEDBACK_VARYING resources, name must match one of the variables to be captured
1255*8975f5c5SAndroid Build Coastguard Worker // as specified by a previous call to TransformFeedbackVaryings. Otherwise, INVALID_INDEX is
1256*8975f5c5SAndroid Build Coastguard Worker // returned.
1257*8975f5c5SAndroid Build Coastguard Worker // If name does not match a resource as described above, the value INVALID_INDEX is returned,
1258*8975f5c5SAndroid Build Coastguard Worker // but no GL error is generated.
1259*8975f5c5SAndroid Build Coastguard Worker index = glGetProgramResourceIndex(program, GL_TRANSFORM_FEEDBACK_VARYING, "outWholeArray[0]");
1260*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1261*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_INVALID_INDEX, index);
1262*8975f5c5SAndroid Build Coastguard Worker
1263*8975f5c5SAndroid Build Coastguard Worker GLenum props[] = {GL_TYPE, GL_ARRAY_SIZE, GL_NAME_LENGTH};
1264*8975f5c5SAndroid Build Coastguard Worker GLsizei propCount = static_cast<GLsizei>(ArraySize(props));
1265*8975f5c5SAndroid Build Coastguard Worker GLint params[ArraySize(props)];
1266*8975f5c5SAndroid Build Coastguard Worker GLsizei length = 0;
1267*8975f5c5SAndroid Build Coastguard Worker // Query properties of 'outArrayElements[15]'.
1268*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_TRANSFORM_FEEDBACK_VARYING, 1, propCount, props, propCount,
1269*8975f5c5SAndroid Build Coastguard Worker &length, params);
1270*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1271*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
1272*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_FLOAT_VEC3, params[0]); // type
1273*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(1, params[1]); // array_size
1274*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(21, params[2]); // name_length
1275*8975f5c5SAndroid Build Coastguard Worker
1276*8975f5c5SAndroid Build Coastguard Worker // Query properties of 'outWholeArray'.
1277*8975f5c5SAndroid Build Coastguard Worker glGetProgramResourceiv(program, GL_TRANSFORM_FEEDBACK_VARYING, 3, propCount, props, propCount,
1278*8975f5c5SAndroid Build Coastguard Worker &length, params);
1279*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1280*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(propCount, length);
1281*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(GL_FLOAT_VEC2, params[0]); // type
1282*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(2, params[1]); // array_size
1283*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(14, params[2]); // name_length
1284*8975f5c5SAndroid Build Coastguard Worker
1285*8975f5c5SAndroid Build Coastguard Worker glDeleteProgram(program);
1286*8975f5c5SAndroid Build Coastguard Worker }
1287*8975f5c5SAndroid Build Coastguard Worker
1288*8975f5c5SAndroid Build Coastguard Worker // Regression test for crash report in http://anglebug.com/42264603.
TEST_P(ProgramInterfaceTestES31,ReloadFromCacheShouldNotCrash)1289*8975f5c5SAndroid Build Coastguard Worker TEST_P(ProgramInterfaceTestES31, ReloadFromCacheShouldNotCrash)
1290*8975f5c5SAndroid Build Coastguard Worker {
1291*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_multi_draw"));
1292*8975f5c5SAndroid Build Coastguard Worker
1293*8975f5c5SAndroid Build Coastguard Worker // TODO([email protected]): Don't skip this test once non-simple SSBO sentences are supported
1294*8975f5c5SAndroid Build Coastguard Worker // on d3d backend. http://anglebug.com/40644618
1295*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsD3D11());
1296*8975f5c5SAndroid Build Coastguard Worker
1297*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] = R"(#version 310 es
1298*8975f5c5SAndroid Build Coastguard Worker #extension GL_ANGLE_multi_draw : require
1299*8975f5c5SAndroid Build Coastguard Worker precision highp int;
1300*8975f5c5SAndroid Build Coastguard Worker precision highp float;
1301*8975f5c5SAndroid Build Coastguard Worker layout(std140) buffer;
1302*8975f5c5SAndroid Build Coastguard Worker struct TransformInfo
1303*8975f5c5SAndroid Build Coastguard Worker {
1304*8975f5c5SAndroid Build Coastguard Worker mat4 mvp;
1305*8975f5c5SAndroid Build Coastguard Worker };
1306*8975f5c5SAndroid Build Coastguard Worker layout(binding = 0) buffer pe_transforms
1307*8975f5c5SAndroid Build Coastguard Worker {
1308*8975f5c5SAndroid Build Coastguard Worker TransformInfo transforms[];
1309*8975f5c5SAndroid Build Coastguard Worker };
1310*8975f5c5SAndroid Build Coastguard Worker out vec2 texCoord;
1311*8975f5c5SAndroid Build Coastguard Worker uniform int pe_base_draw_id;
1312*8975f5c5SAndroid Build Coastguard Worker layout(location = 0) in vec3 pe_vertex;
1313*8975f5c5SAndroid Build Coastguard Worker layout(location = 1) in vec3 pe_normal;
1314*8975f5c5SAndroid Build Coastguard Worker layout(location = 2) in vec2 pe_tex_coord;
1315*8975f5c5SAndroid Build Coastguard Worker void main()
1316*8975f5c5SAndroid Build Coastguard Worker {
1317*8975f5c5SAndroid Build Coastguard Worker vec4 v = vec4(pe_vertex, 1.0);
1318*8975f5c5SAndroid Build Coastguard Worker texCoord = pe_tex_coord;
1319*8975f5c5SAndroid Build Coastguard Worker gl_Position = transforms[(gl_DrawID + pe_base_draw_id)].mvp * v;
1320*8975f5c5SAndroid Build Coastguard Worker })";
1321*8975f5c5SAndroid Build Coastguard Worker
1322*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] = R"(#version 310 es
1323*8975f5c5SAndroid Build Coastguard Worker #extension GL_ANGLE_multi_draw : require
1324*8975f5c5SAndroid Build Coastguard Worker precision highp int;
1325*8975f5c5SAndroid Build Coastguard Worker precision highp float;
1326*8975f5c5SAndroid Build Coastguard Worker layout(std140) buffer;
1327*8975f5c5SAndroid Build Coastguard Worker in vec2 texCoord;
1328*8975f5c5SAndroid Build Coastguard Worker layout(binding = 0) uniform sampler2D pe_tex_main;
1329*8975f5c5SAndroid Build Coastguard Worker out vec4 pe_frag_color;
1330*8975f5c5SAndroid Build Coastguard Worker void main()
1331*8975f5c5SAndroid Build Coastguard Worker {
1332*8975f5c5SAndroid Build Coastguard Worker vec4 u = texture(pe_tex_main, texCoord);
1333*8975f5c5SAndroid Build Coastguard Worker if(u.a < 0.05)
1334*8975f5c5SAndroid Build Coastguard Worker discard;
1335*8975f5c5SAndroid Build Coastguard Worker pe_frag_color = u;
1336*8975f5c5SAndroid Build Coastguard Worker }
1337*8975f5c5SAndroid Build Coastguard Worker )";
1338*8975f5c5SAndroid Build Coastguard Worker
1339*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
1340*8975f5c5SAndroid Build Coastguard Worker createGraphicsProgram(program, kVS, kFS, std::get<1>(GetParam()));
1341*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1342*8975f5c5SAndroid Build Coastguard Worker }
1343*8975f5c5SAndroid Build Coastguard Worker
1344*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ProgramInterfaceTestES31);
1345*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_COMBINE_1(ProgramInterfaceTestES31,
1346*8975f5c5SAndroid Build Coastguard Worker ProgramInterfaceTestPrint,
1347*8975f5c5SAndroid Build Coastguard Worker testing::Bool(),
1348*8975f5c5SAndroid Build Coastguard Worker ANGLE_ALL_TEST_PLATFORMS_ES31);
1349*8975f5c5SAndroid Build Coastguard Worker
1350*8975f5c5SAndroid Build Coastguard Worker } // anonymous namespace
1351