1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program OpenGL ES 3.1 Module
3*35238bceSAndroid Build Coastguard Worker * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2017 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker *
7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker *
11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker *
13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker *
19*35238bceSAndroid Build Coastguard Worker *//*!
20*35238bceSAndroid Build Coastguard Worker * \file
21*35238bceSAndroid Build Coastguard Worker * \brief Negative Sample Variables Tests
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "es31fNegativeSampleVariablesTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
26*35238bceSAndroid Build Coastguard Worker
27*35238bceSAndroid Build Coastguard Worker namespace deqp
28*35238bceSAndroid Build Coastguard Worker {
29*35238bceSAndroid Build Coastguard Worker namespace gles31
30*35238bceSAndroid Build Coastguard Worker {
31*35238bceSAndroid Build Coastguard Worker namespace Functional
32*35238bceSAndroid Build Coastguard Worker {
33*35238bceSAndroid Build Coastguard Worker namespace NegativeTestShared
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker namespace
36*35238bceSAndroid Build Coastguard Worker {
37*35238bceSAndroid Build Coastguard Worker
38*35238bceSAndroid Build Coastguard Worker enum ExpectResult
39*35238bceSAndroid Build Coastguard Worker {
40*35238bceSAndroid Build Coastguard Worker EXPECT_RESULT_PASS = 0,
41*35238bceSAndroid Build Coastguard Worker EXPECT_RESULT_FAIL,
42*35238bceSAndroid Build Coastguard Worker EXPECT_RESULT_LAST
43*35238bceSAndroid Build Coastguard Worker };
44*35238bceSAndroid Build Coastguard Worker
verifyShader(NegativeTestContext & ctx,glu::ShaderType shaderType,std::string shaderSource,ExpectResult expect)45*35238bceSAndroid Build Coastguard Worker void verifyShader(NegativeTestContext &ctx, glu::ShaderType shaderType, std::string shaderSource, ExpectResult expect)
46*35238bceSAndroid Build Coastguard Worker {
47*35238bceSAndroid Build Coastguard Worker DE_ASSERT(expect >= EXPECT_RESULT_PASS && expect < EXPECT_RESULT_LAST);
48*35238bceSAndroid Build Coastguard Worker
49*35238bceSAndroid Build Coastguard Worker tcu::TestLog &log = ctx.getLog();
50*35238bceSAndroid Build Coastguard Worker bool testFailed = false;
51*35238bceSAndroid Build Coastguard Worker const char *const source = shaderSource.c_str();
52*35238bceSAndroid Build Coastguard Worker const int length = (int)shaderSource.size();
53*35238bceSAndroid Build Coastguard Worker glu::Shader shader(ctx.getRenderContext(), shaderType);
54*35238bceSAndroid Build Coastguard Worker std::string message;
55*35238bceSAndroid Build Coastguard Worker
56*35238bceSAndroid Build Coastguard Worker shader.setSources(1, &source, &length);
57*35238bceSAndroid Build Coastguard Worker shader.compile();
58*35238bceSAndroid Build Coastguard Worker
59*35238bceSAndroid Build Coastguard Worker log << shader;
60*35238bceSAndroid Build Coastguard Worker
61*35238bceSAndroid Build Coastguard Worker if (expect == EXPECT_RESULT_PASS)
62*35238bceSAndroid Build Coastguard Worker {
63*35238bceSAndroid Build Coastguard Worker testFailed = !shader.getCompileStatus();
64*35238bceSAndroid Build Coastguard Worker message = "Shader did not compile.";
65*35238bceSAndroid Build Coastguard Worker }
66*35238bceSAndroid Build Coastguard Worker else
67*35238bceSAndroid Build Coastguard Worker {
68*35238bceSAndroid Build Coastguard Worker testFailed = shader.getCompileStatus();
69*35238bceSAndroid Build Coastguard Worker message = "Shader was not expected to compile.";
70*35238bceSAndroid Build Coastguard Worker }
71*35238bceSAndroid Build Coastguard Worker
72*35238bceSAndroid Build Coastguard Worker if (testFailed)
73*35238bceSAndroid Build Coastguard Worker {
74*35238bceSAndroid Build Coastguard Worker log << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
75*35238bceSAndroid Build Coastguard Worker ctx.fail(message);
76*35238bceSAndroid Build Coastguard Worker }
77*35238bceSAndroid Build Coastguard Worker }
78*35238bceSAndroid Build Coastguard Worker
getVersionAndExtension(NegativeTestContext & ctx)79*35238bceSAndroid Build Coastguard Worker std::string getVersionAndExtension(NegativeTestContext &ctx)
80*35238bceSAndroid Build Coastguard Worker {
81*35238bceSAndroid Build Coastguard Worker const bool isES32 = contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
82*35238bceSAndroid Build Coastguard Worker const glu::GLSLVersion version = isES32 ? glu::GLSL_VERSION_320_ES : glu::GLSL_VERSION_310_ES;
83*35238bceSAndroid Build Coastguard Worker
84*35238bceSAndroid Build Coastguard Worker std::string versionAndExtension = glu::getGLSLVersionDeclaration(version);
85*35238bceSAndroid Build Coastguard Worker versionAndExtension += " \n";
86*35238bceSAndroid Build Coastguard Worker
87*35238bceSAndroid Build Coastguard Worker if (!isES32)
88*35238bceSAndroid Build Coastguard Worker versionAndExtension += "#extension GL_OES_sample_variables : require \n";
89*35238bceSAndroid Build Coastguard Worker
90*35238bceSAndroid Build Coastguard Worker return versionAndExtension;
91*35238bceSAndroid Build Coastguard Worker }
92*35238bceSAndroid Build Coastguard Worker
checkSupported(NegativeTestContext & ctx)93*35238bceSAndroid Build Coastguard Worker void checkSupported(NegativeTestContext &ctx)
94*35238bceSAndroid Build Coastguard Worker {
95*35238bceSAndroid Build Coastguard Worker const bool isES32orGL45 = contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)) ||
96*35238bceSAndroid Build Coastguard Worker contextSupports(ctx.getRenderContext().getType(), glu::ApiType::core(4, 5));
97*35238bceSAndroid Build Coastguard Worker
98*35238bceSAndroid Build Coastguard Worker if (!isES32orGL45 && !ctx.isExtensionSupported("GL_OES_sample_variables"))
99*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "GL_OES_sample_variables is not supported.");
100*35238bceSAndroid Build Coastguard Worker }
101*35238bceSAndroid Build Coastguard Worker
write_to_read_only_types(NegativeTestContext & ctx)102*35238bceSAndroid Build Coastguard Worker void write_to_read_only_types(NegativeTestContext &ctx)
103*35238bceSAndroid Build Coastguard Worker {
104*35238bceSAndroid Build Coastguard Worker checkSupported(ctx);
105*35238bceSAndroid Build Coastguard Worker
106*35238bceSAndroid Build Coastguard Worker std::ostringstream shader;
107*35238bceSAndroid Build Coastguard Worker
108*35238bceSAndroid Build Coastguard Worker struct testConfig
109*35238bceSAndroid Build Coastguard Worker {
110*35238bceSAndroid Build Coastguard Worker std::string builtInType;
111*35238bceSAndroid Build Coastguard Worker std::string varyingCheck;
112*35238bceSAndroid Build Coastguard Worker } testConfigs[] = {{"gl_SampleID", " lowp int writeValue = 1; \n gl_SampleID = writeValue; \n"},
113*35238bceSAndroid Build Coastguard Worker {"gl_SamplePosition",
114*35238bceSAndroid Build Coastguard Worker " mediump vec2 writeValue = vec2(1.0f, 1.0f); \n gl_SamplePosition = writeValue; \n"},
115*35238bceSAndroid Build Coastguard Worker {"gl_SampleMaskIn", " lowp int writeValue = 1; \n gl_SampleMaskIn[0] = writeValue; \n"}};
116*35238bceSAndroid Build Coastguard Worker
117*35238bceSAndroid Build Coastguard Worker for (int idx = 0; idx < DE_LENGTH_OF_ARRAY(testConfigs); idx++)
118*35238bceSAndroid Build Coastguard Worker {
119*35238bceSAndroid Build Coastguard Worker shader.str("");
120*35238bceSAndroid Build Coastguard Worker shader << getVersionAndExtension(ctx) << "layout (location = 0) out mediump vec4 fs_color; \n"
121*35238bceSAndroid Build Coastguard Worker << "void main() \n"
122*35238bceSAndroid Build Coastguard Worker << "{ \n"
123*35238bceSAndroid Build Coastguard Worker << testConfigs[idx].varyingCheck << " fs_color = vec4(1.0f, 0.0f, 0.0f, 1.0f); \n"
124*35238bceSAndroid Build Coastguard Worker << "} \n";
125*35238bceSAndroid Build Coastguard Worker
126*35238bceSAndroid Build Coastguard Worker ctx.beginSection("OES_sample_variables: trying to write to built-in read-only variable" +
127*35238bceSAndroid Build Coastguard Worker testConfigs[idx].builtInType);
128*35238bceSAndroid Build Coastguard Worker verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, shader.str(), EXPECT_RESULT_FAIL);
129*35238bceSAndroid Build Coastguard Worker ctx.endSection();
130*35238bceSAndroid Build Coastguard Worker }
131*35238bceSAndroid Build Coastguard Worker }
132*35238bceSAndroid Build Coastguard Worker
access_built_in_types_inside_other_shaders(NegativeTestContext & ctx)133*35238bceSAndroid Build Coastguard Worker void access_built_in_types_inside_other_shaders(NegativeTestContext &ctx)
134*35238bceSAndroid Build Coastguard Worker {
135*35238bceSAndroid Build Coastguard Worker checkSupported(ctx);
136*35238bceSAndroid Build Coastguard Worker
137*35238bceSAndroid Build Coastguard Worker if (glu::isContextTypeES(ctx.getRenderContext().getType()))
138*35238bceSAndroid Build Coastguard Worker {
139*35238bceSAndroid Build Coastguard Worker if ((!ctx.isExtensionSupported("GL_EXT_tessellation_shader") &&
140*35238bceSAndroid Build Coastguard Worker !ctx.isExtensionSupported("GL_OES_tessellation_shader")) ||
141*35238bceSAndroid Build Coastguard Worker (!ctx.isExtensionSupported("GL_EXT_geometry_shader") &&
142*35238bceSAndroid Build Coastguard Worker !ctx.isExtensionSupported("GL_OES_geometry_shader")))
143*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "tessellation and geometry shader extensions not supported");
144*35238bceSAndroid Build Coastguard Worker }
145*35238bceSAndroid Build Coastguard Worker
146*35238bceSAndroid Build Coastguard Worker std::ostringstream shader;
147*35238bceSAndroid Build Coastguard Worker
148*35238bceSAndroid Build Coastguard Worker struct testConfig
149*35238bceSAndroid Build Coastguard Worker {
150*35238bceSAndroid Build Coastguard Worker std::string builtInType;
151*35238bceSAndroid Build Coastguard Worker std::string varyingCheck;
152*35238bceSAndroid Build Coastguard Worker } testConfigs[] = {
153*35238bceSAndroid Build Coastguard Worker {"gl_SampleID", " lowp int writeValue = 1; \n gl_SampleID = writeValue; \n"},
154*35238bceSAndroid Build Coastguard Worker {"gl_SamplePosition",
155*35238bceSAndroid Build Coastguard Worker " mediump vec2 writeValue = vec2(1.0f, 1.0f); \n gl_SamplePosition = writeValue; \n"},
156*35238bceSAndroid Build Coastguard Worker {"gl_SampleMaskIn", " lowp int writeValue = 1; \n gl_SampleMaskIn[0] = writeValue; \n"},
157*35238bceSAndroid Build Coastguard Worker {"gl_SampleMask", " highp int readValue = gl_SampleMask[0]; \n"},
158*35238bceSAndroid Build Coastguard Worker };
159*35238bceSAndroid Build Coastguard Worker
160*35238bceSAndroid Build Coastguard Worker for (int idx = 0; idx < DE_LENGTH_OF_ARRAY(testConfigs); idx++)
161*35238bceSAndroid Build Coastguard Worker {
162*35238bceSAndroid Build Coastguard Worker shader.str("");
163*35238bceSAndroid Build Coastguard Worker shader << getVersionAndExtension(ctx) << "void main () \n"
164*35238bceSAndroid Build Coastguard Worker << "{ \n"
165*35238bceSAndroid Build Coastguard Worker << testConfigs[idx].varyingCheck << " gl_Position = vec4(1.0f, 0.0f, 0.0f , 1.0f); \n"
166*35238bceSAndroid Build Coastguard Worker << "} \n";
167*35238bceSAndroid Build Coastguard Worker
168*35238bceSAndroid Build Coastguard Worker ctx.beginSection("OES_sample_variables: trying to use fragment shader built-in sampler variable " +
169*35238bceSAndroid Build Coastguard Worker testConfigs[idx].builtInType + " inside vertex shader");
170*35238bceSAndroid Build Coastguard Worker verifyShader(ctx, glu::SHADERTYPE_VERTEX, shader.str(), EXPECT_RESULT_FAIL);
171*35238bceSAndroid Build Coastguard Worker ctx.endSection();
172*35238bceSAndroid Build Coastguard Worker }
173*35238bceSAndroid Build Coastguard Worker
174*35238bceSAndroid Build Coastguard Worker for (int idx = 0; idx < DE_LENGTH_OF_ARRAY(testConfigs); idx++)
175*35238bceSAndroid Build Coastguard Worker {
176*35238bceSAndroid Build Coastguard Worker shader.str("");
177*35238bceSAndroid Build Coastguard Worker shader << getVersionAndExtension(ctx) << "layout (vertices = 3) out; \n"
178*35238bceSAndroid Build Coastguard Worker << "void main () \n"
179*35238bceSAndroid Build Coastguard Worker << "{ \n"
180*35238bceSAndroid Build Coastguard Worker << testConfigs[idx].varyingCheck << "} \n";
181*35238bceSAndroid Build Coastguard Worker
182*35238bceSAndroid Build Coastguard Worker ctx.beginSection("OES_sample_variables: trying to use fragment shader built-in sampler variable " +
183*35238bceSAndroid Build Coastguard Worker testConfigs[idx].builtInType + " inside tessellation control shader");
184*35238bceSAndroid Build Coastguard Worker verifyShader(ctx, glu::SHADERTYPE_TESSELLATION_CONTROL, shader.str(), EXPECT_RESULT_FAIL);
185*35238bceSAndroid Build Coastguard Worker ctx.endSection();
186*35238bceSAndroid Build Coastguard Worker }
187*35238bceSAndroid Build Coastguard Worker
188*35238bceSAndroid Build Coastguard Worker for (int idx = 0; idx < DE_LENGTH_OF_ARRAY(testConfigs); idx++)
189*35238bceSAndroid Build Coastguard Worker {
190*35238bceSAndroid Build Coastguard Worker shader.str("");
191*35238bceSAndroid Build Coastguard Worker shader << getVersionAndExtension(ctx) << "layout (triangles, equal_spacing, ccw) in; \n"
192*35238bceSAndroid Build Coastguard Worker << "void main () \n"
193*35238bceSAndroid Build Coastguard Worker << "{ \n"
194*35238bceSAndroid Build Coastguard Worker << testConfigs[idx].varyingCheck << "} \n";
195*35238bceSAndroid Build Coastguard Worker
196*35238bceSAndroid Build Coastguard Worker ctx.beginSection("OES_sample_variables: trying to use fragment shader built-in sampler variable " +
197*35238bceSAndroid Build Coastguard Worker testConfigs[idx].builtInType + " inside tessellation evaluation shader");
198*35238bceSAndroid Build Coastguard Worker verifyShader(ctx, glu::SHADERTYPE_TESSELLATION_EVALUATION, shader.str(), EXPECT_RESULT_FAIL);
199*35238bceSAndroid Build Coastguard Worker ctx.endSection();
200*35238bceSAndroid Build Coastguard Worker }
201*35238bceSAndroid Build Coastguard Worker
202*35238bceSAndroid Build Coastguard Worker for (int idx = 0; idx < DE_LENGTH_OF_ARRAY(testConfigs); idx++)
203*35238bceSAndroid Build Coastguard Worker {
204*35238bceSAndroid Build Coastguard Worker shader.str("");
205*35238bceSAndroid Build Coastguard Worker shader << getVersionAndExtension(ctx) << "layout (triangles) in; \n"
206*35238bceSAndroid Build Coastguard Worker << "layout (triangle_strip, max_vertices = 32) out; \n"
207*35238bceSAndroid Build Coastguard Worker << "void main () \n"
208*35238bceSAndroid Build Coastguard Worker << "{ \n"
209*35238bceSAndroid Build Coastguard Worker << testConfigs[idx].varyingCheck << "} \n";
210*35238bceSAndroid Build Coastguard Worker
211*35238bceSAndroid Build Coastguard Worker ctx.beginSection("OES_sample_variables: trying to use fragment shader built-in sampler variable " +
212*35238bceSAndroid Build Coastguard Worker testConfigs[idx].builtInType + " inside geometry shader");
213*35238bceSAndroid Build Coastguard Worker verifyShader(ctx, glu::SHADERTYPE_GEOMETRY, shader.str(), EXPECT_RESULT_FAIL);
214*35238bceSAndroid Build Coastguard Worker ctx.endSection();
215*35238bceSAndroid Build Coastguard Worker }
216*35238bceSAndroid Build Coastguard Worker }
217*35238bceSAndroid Build Coastguard Worker
index_outside_sample_mask_range(NegativeTestContext & ctx)218*35238bceSAndroid Build Coastguard Worker void index_outside_sample_mask_range(NegativeTestContext &ctx)
219*35238bceSAndroid Build Coastguard Worker {
220*35238bceSAndroid Build Coastguard Worker // Skip this test for GL4.5 - shader will compile
221*35238bceSAndroid Build Coastguard Worker if (!glu::isContextTypeES(ctx.getRenderContext().getType()))
222*35238bceSAndroid Build Coastguard Worker return;
223*35238bceSAndroid Build Coastguard Worker
224*35238bceSAndroid Build Coastguard Worker checkSupported(ctx);
225*35238bceSAndroid Build Coastguard Worker
226*35238bceSAndroid Build Coastguard Worker std::ostringstream shader;
227*35238bceSAndroid Build Coastguard Worker const int MAX_TYPES = 2;
228*35238bceSAndroid Build Coastguard Worker const int MAX_INDEXES = 2;
229*35238bceSAndroid Build Coastguard Worker
230*35238bceSAndroid Build Coastguard Worker struct testConfig
231*35238bceSAndroid Build Coastguard Worker {
232*35238bceSAndroid Build Coastguard Worker std::string builtInType[MAX_TYPES];
233*35238bceSAndroid Build Coastguard Worker std::string invalidIndex[MAX_INDEXES];
234*35238bceSAndroid Build Coastguard Worker } testConfigs = {{"gl_SampleMask", "gl_SampleMaskIn"},
235*35238bceSAndroid Build Coastguard Worker {" const highp int invalidIndex = (gl_MaxSamples + 31) / 32; \n",
236*35238bceSAndroid Build Coastguard Worker " const highp int invalidIndex = -1; \n"}};
237*35238bceSAndroid Build Coastguard Worker
238*35238bceSAndroid Build Coastguard Worker for (int typeIdx = 0; typeIdx < MAX_TYPES; typeIdx++)
239*35238bceSAndroid Build Coastguard Worker {
240*35238bceSAndroid Build Coastguard Worker for (int invalidIdx = 0; invalidIdx < MAX_INDEXES; invalidIdx++)
241*35238bceSAndroid Build Coastguard Worker {
242*35238bceSAndroid Build Coastguard Worker shader.str("");
243*35238bceSAndroid Build Coastguard Worker shader << getVersionAndExtension(ctx) << "layout (location = 0) out mediump vec4 fs_color; \n"
244*35238bceSAndroid Build Coastguard Worker << "void main() \n"
245*35238bceSAndroid Build Coastguard Worker << "{ \n"
246*35238bceSAndroid Build Coastguard Worker << testConfigs.invalidIndex[invalidIdx]
247*35238bceSAndroid Build Coastguard Worker << " highp int invalidValue = " << testConfigs.builtInType[typeIdx] << "[invalidIndex]; \n"
248*35238bceSAndroid Build Coastguard Worker << " fs_color = vec4(1.0f, 0.0f, 0.0f, 1.0f); \n"
249*35238bceSAndroid Build Coastguard Worker << "} \n";
250*35238bceSAndroid Build Coastguard Worker
251*35238bceSAndroid Build Coastguard Worker ctx.beginSection("OES_sample_variables: using constant integral expression outside of " +
252*35238bceSAndroid Build Coastguard Worker testConfigs.builtInType[typeIdx] + " bounds");
253*35238bceSAndroid Build Coastguard Worker verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, shader.str(), EXPECT_RESULT_FAIL);
254*35238bceSAndroid Build Coastguard Worker ctx.endSection();
255*35238bceSAndroid Build Coastguard Worker }
256*35238bceSAndroid Build Coastguard Worker }
257*35238bceSAndroid Build Coastguard Worker }
258*35238bceSAndroid Build Coastguard Worker
access_built_in_types_without_extension(NegativeTestContext & ctx)259*35238bceSAndroid Build Coastguard Worker void access_built_in_types_without_extension(NegativeTestContext &ctx)
260*35238bceSAndroid Build Coastguard Worker {
261*35238bceSAndroid Build Coastguard Worker checkSupported(ctx);
262*35238bceSAndroid Build Coastguard Worker
263*35238bceSAndroid Build Coastguard Worker std::ostringstream shader;
264*35238bceSAndroid Build Coastguard Worker
265*35238bceSAndroid Build Coastguard Worker struct testConfig
266*35238bceSAndroid Build Coastguard Worker {
267*35238bceSAndroid Build Coastguard Worker std::string builtInType;
268*35238bceSAndroid Build Coastguard Worker std::string varyingCheck;
269*35238bceSAndroid Build Coastguard Worker } testConfigs[] = {
270*35238bceSAndroid Build Coastguard Worker {"gl_SampleID", " lowp int writeValue = 1; \n gl_SampleID = writeValue; \n"},
271*35238bceSAndroid Build Coastguard Worker {"gl_SamplePosition",
272*35238bceSAndroid Build Coastguard Worker " mediump vec2 writeValue = vec2(1.0f, 1.0f); \n gl_SamplePosition = writeValue; \n"},
273*35238bceSAndroid Build Coastguard Worker {"gl_SampleMaskIn", " lowp int writeValue = 1; \n gl_SampleMaskIn[0] = writeValue; \n"},
274*35238bceSAndroid Build Coastguard Worker {"gl_SampleMask", " highp int readValue = gl_SampleMask[0]; \n"},
275*35238bceSAndroid Build Coastguard Worker };
276*35238bceSAndroid Build Coastguard Worker
277*35238bceSAndroid Build Coastguard Worker for (int idx = 0; idx < DE_LENGTH_OF_ARRAY(testConfigs); idx++)
278*35238bceSAndroid Build Coastguard Worker {
279*35238bceSAndroid Build Coastguard Worker shader.str("");
280*35238bceSAndroid Build Coastguard Worker shader << "#version 310 es \n"
281*35238bceSAndroid Build Coastguard Worker << "layout (location = 0) out mediump vec4 fs_color; \n"
282*35238bceSAndroid Build Coastguard Worker << "void main() \n"
283*35238bceSAndroid Build Coastguard Worker << "{ \n"
284*35238bceSAndroid Build Coastguard Worker << testConfigs[idx].varyingCheck << " fs_color = vec4(1.0f, 0.0f, 0.0f, 1.0f); \n"
285*35238bceSAndroid Build Coastguard Worker << "} \n";
286*35238bceSAndroid Build Coastguard Worker
287*35238bceSAndroid Build Coastguard Worker ctx.beginSection("OES_sample_variables: accessing built-in type " + testConfigs[idx].builtInType +
288*35238bceSAndroid Build Coastguard Worker " in shader version 310 ES without required extension");
289*35238bceSAndroid Build Coastguard Worker verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, shader.str(), EXPECT_RESULT_FAIL);
290*35238bceSAndroid Build Coastguard Worker ctx.endSection();
291*35238bceSAndroid Build Coastguard Worker }
292*35238bceSAndroid Build Coastguard Worker }
293*35238bceSAndroid Build Coastguard Worker
redeclare_built_in_types(NegativeTestContext & ctx)294*35238bceSAndroid Build Coastguard Worker void redeclare_built_in_types(NegativeTestContext &ctx)
295*35238bceSAndroid Build Coastguard Worker {
296*35238bceSAndroid Build Coastguard Worker // skip this test for core GL
297*35238bceSAndroid Build Coastguard Worker if (glu::isContextTypeGLCore(ctx.getRenderContext().getType()))
298*35238bceSAndroid Build Coastguard Worker return;
299*35238bceSAndroid Build Coastguard Worker
300*35238bceSAndroid Build Coastguard Worker checkSupported(ctx);
301*35238bceSAndroid Build Coastguard Worker
302*35238bceSAndroid Build Coastguard Worker std::ostringstream shader;
303*35238bceSAndroid Build Coastguard Worker std::ostringstream testName;
304*35238bceSAndroid Build Coastguard Worker
305*35238bceSAndroid Build Coastguard Worker const char *const testConfigs[] = {
306*35238bceSAndroid Build Coastguard Worker "gl_SampleID",
307*35238bceSAndroid Build Coastguard Worker "gl_SamplePosition",
308*35238bceSAndroid Build Coastguard Worker "gl_SampleMaskIn",
309*35238bceSAndroid Build Coastguard Worker "gl_SampleMask",
310*35238bceSAndroid Build Coastguard Worker };
311*35238bceSAndroid Build Coastguard Worker
312*35238bceSAndroid Build Coastguard Worker for (int idx = 0; idx < DE_LENGTH_OF_ARRAY(testConfigs); idx++)
313*35238bceSAndroid Build Coastguard Worker {
314*35238bceSAndroid Build Coastguard Worker shader.str("");
315*35238bceSAndroid Build Coastguard Worker shader << getVersionAndExtension(ctx) << "layout (location = 0) out mediump vec4 fs_color; \n"
316*35238bceSAndroid Build Coastguard Worker << "uniform lowp int " << testConfigs[idx] << "; \n"
317*35238bceSAndroid Build Coastguard Worker << "void main() \n"
318*35238bceSAndroid Build Coastguard Worker << "{ \n"
319*35238bceSAndroid Build Coastguard Worker << " if (" << testConfigs[idx] << " == 0) \n"
320*35238bceSAndroid Build Coastguard Worker << " fs_color = vec4(1.0f, 0.0f, 0.0f, 1.0f); \n"
321*35238bceSAndroid Build Coastguard Worker << " else \n"
322*35238bceSAndroid Build Coastguard Worker << " fs_color = vec4(0.0f, 1.0f, 0.0f, 1.0f); \n"
323*35238bceSAndroid Build Coastguard Worker << "} \n";
324*35238bceSAndroid Build Coastguard Worker
325*35238bceSAndroid Build Coastguard Worker testName.str("");
326*35238bceSAndroid Build Coastguard Worker testName << "OES_sample_variables: redeclare built-in type " << testConfigs[idx];
327*35238bceSAndroid Build Coastguard Worker ctx.beginSection(testName.str());
328*35238bceSAndroid Build Coastguard Worker verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, shader.str(), EXPECT_RESULT_FAIL);
329*35238bceSAndroid Build Coastguard Worker ctx.endSection();
330*35238bceSAndroid Build Coastguard Worker }
331*35238bceSAndroid Build Coastguard Worker }
332*35238bceSAndroid Build Coastguard Worker
333*35238bceSAndroid Build Coastguard Worker } // namespace
334*35238bceSAndroid Build Coastguard Worker
getNegativeSampleVariablesTestFunctions(void)335*35238bceSAndroid Build Coastguard Worker std::vector<FunctionContainer> getNegativeSampleVariablesTestFunctions(void)
336*35238bceSAndroid Build Coastguard Worker {
337*35238bceSAndroid Build Coastguard Worker const FunctionContainer funcs[] = {
338*35238bceSAndroid Build Coastguard Worker {write_to_read_only_types, "write_to_read_only_types",
339*35238bceSAndroid Build Coastguard Worker "tests trying writing to read-only built-in sample variables"},
340*35238bceSAndroid Build Coastguard Worker {access_built_in_types_inside_other_shaders, "access_built_in_types_inside_other_shaders",
341*35238bceSAndroid Build Coastguard Worker "Tests try to access fragment shader sample variables in other shaders"},
342*35238bceSAndroid Build Coastguard Worker {index_outside_sample_mask_range, "index_outside_sample_mask_range",
343*35238bceSAndroid Build Coastguard Worker "tests try to index into built-in sample array types out of bounds"},
344*35238bceSAndroid Build Coastguard Worker {access_built_in_types_without_extension, "access_built_in_types_without_extension",
345*35238bceSAndroid Build Coastguard Worker "tests try to access built-in sample types without the correct extension using version 310 es"},
346*35238bceSAndroid Build Coastguard Worker {redeclare_built_in_types, "redeclare_built_in_types", "Tests try to redeclare built-in sample types"},
347*35238bceSAndroid Build Coastguard Worker };
348*35238bceSAndroid Build Coastguard Worker
349*35238bceSAndroid Build Coastguard Worker return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
350*35238bceSAndroid Build Coastguard Worker }
351*35238bceSAndroid Build Coastguard Worker
352*35238bceSAndroid Build Coastguard Worker } // namespace NegativeTestShared
353*35238bceSAndroid Build Coastguard Worker } // namespace Functional
354*35238bceSAndroid Build Coastguard Worker } // namespace gles31
355*35238bceSAndroid Build Coastguard Worker } // namespace deqp
356