framework/replay: re-try more aggressively, even over the 50x HTTP errors
[piglit.git] / generated_tests / gen_shader_framebuffer_fetch_tests.py
blob3171fd8099c5c457caccb0abdc1b8511ed932dd5
1 # coding=utf-8
3 # Copyright © 2014-2016 Intel Corporation
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 # IN THE SOFTWARE.
24 import os.path
25 from textwrap import dedent
27 from mako.template import Template
29 from modules import utils
32 def product(ps, *qss):
33 """
34 Generate the cartesian product of a number of lists of dictionaries.
36 Generate a sequence with every possible combination of elements of
37 the specified lists of dictionaries. Each element of the result
38 will be the union of some combination of dictionaries from the
39 lists given as argument. The 'name' attribute of each dictionary
40 given as input is concatenated with the names of other
41 dictionaries part of the same combination to give the 'name'
42 attribute of the result.
43 """
44 for q in (product(*qss) if qss else [{}]):
45 for p in ps:
46 r = dict(p, **q)
47 r['name'] = ''.join(s['name'] for s in (p, q) if s.get('name'))
48 yield r
51 def gen(src, tests):
52 """
53 Expand a source template for the provided list of test definitions.
55 Generate a test script for each element of the 'tests' iterable,
56 each of them should be a dictionary of definitions that will be
57 used as environment to render the source template.
59 The 'path' attribute of each dictionary gives the filename each
60 test will be written to.
61 """
62 template = Template(dedent(src))
64 for t in tests:
65 print(t['path'])
66 utils.safe_makedirs(os.path.dirname(t['path']))
67 with open(t['path'], 'w') as f:
68 f.write(template.render(**t))
71 def gen_execution(src, tests):
72 """
73 Generate a shader runner test for each element of the 'tests'
74 iterable.
75 """
76 return gen(src,
77 (dict(t, path = os.path.join(
78 'spec', t['extension'], 'execution', t['api'],
79 t['name'] + '.shader_test')) for t in tests))
82 def gen_compiler(src, tests):
83 """
84 Generate a GLSL parser test for each element of the 'tests'
85 iterable.
86 """
87 return gen(src,
88 (dict(t, path = os.path.join(
89 'spec', t['extension'], 'compiler', t['api'],
90 t['name'] + '.' + t['shader_stage'])) for t in tests))
94 # Common test definitions independent of the framebuffer fetch
95 # extension.
97 common_defs = [{# Allocate and bind a framebuffer object of the given
98 # format and number of samples.
99 'bind_fb': lambda fmt, samples = 0:
100 'fb ms {0} 250 250 {1}'.format(fmt, samples) if samples > 0 else
101 ('texture storage 0 2D {0} (1 250 250)\n'
102 'fb tex 2d 0').format(fmt) if fmt[-1] == 'I' else
103 ('texture rgbw 0 (250, 250) {0}\n'
104 'fb tex 2d 0').format(fmt),
106 # Resolve the contents of a framebuffer previously
107 # allocated with 'bind_fb' of the given format and
108 # samples into a newly allocated single-sample
109 # framebuffer.
110 'resolve_fb': lambda fmt, samples:
111 '' if samples == 0 else
112 ('texture storage 0 2D {0} (1 250 250)\n'
113 'fb draw tex 2d 0\n'
114 'blit color nearest\n'
115 'fb read tex 2d 0\n').format(fmt) if fmt[-1] == 'I' else
116 ('texture rgbw 0 (250, 250) {0}\n'
117 'fb draw tex 2d 0\n'
118 'blit color linear\n'
119 'fb read tex 2d 0').format(fmt),
121 # Blit the contents of the current read framebuffer
122 # into the window system framebuffer. XXX - Requires
123 # GL(ES) 3.0+ since glBlitFramebuffer doesn't exist on
124 # earlier API versions.
125 'display_fb': lambda api_version:
126 '' if api_version < 3.0 else
127 ('fb draw winsys\n'
128 'blit color linear'),
130 # Declare a fragment color array set up for
131 # framebuffer fetch with the specified number of
132 # elements (n=0 indicates a single scalar output).
134 # The fragment color array can be accessed using the
135 # 'frag_data' and 'last_frag_data' macros defined
136 # below to make sure the generated test is valid
137 # irrespective of the GLSL version.
138 'decl_frag_data': lambda api_version, layout, n = 0, \
139 t = 'vec4', p = 'mediump':
140 '' if api_version < 3.0 and not layout and t == 'vec4' \
141 and p == 'mediump' else
142 layout + ' ' + p + ' ' + t + ' gl_LastFragData[gl_MaxDrawBuffers];' \
143 if api_version < 3.0 else
144 layout + ' inout ' + p + ' ' + t + ' fcolor;' if n == 0 else
145 layout + ' inout ' + p + ' ' + t + ' fcolor[{0}];'.format(n),
147 'frag_data': lambda api_version, i = -1:
148 'gl_FragData[{0}]'.format(max(0, i)) if api_version < 3.0 else
149 'fcolor[{0}]'.format(i) if i >= 0 else
150 'fcolor',
152 'last_frag_data': lambda api_version, i = -1:
153 'gl_LastFragData[{0}]'.format(max(0, i)) if api_version < 3.0 else
154 'fcolor[{0}]'.format(i) if i >= 0 else
155 'fcolor'}]
159 # Common test definitions for all supported extensions.
161 all_defs = list(product(common_defs,
162 [{'extension': 'EXT_shader_framebuffer_fetch',
163 'layout': '',
164 'barrier': ''},
165 {'extension': 'EXT_shader_framebuffer_fetch_non_coherent',
166 'layout': 'layout(noncoherent)',
167 'barrier': 'fbfetch barrier'}]))
170 def main():
171 """Main function."""
174 # Test that the GL(ES) 2 gl_LastFragData built-in is not defined
175 # in more recent GLSL versions.
177 gen_compiler("""\
179 * [config]
180 * expect_result: fail
181 * glsl_version: 3.0 es
182 * require_extensions: GL_${extension}
183 * [end config]
185 #version 300 es
186 #extension GL_${extension} : enable
188 out highp vec4 color;
190 void main()
192 color = gl_LastFragData[0];
194 """, product(all_defs,
195 [{'name': 'negative-gl_LastFragData',
196 'api': 'gles3',
197 'shader_stage': 'frag'}]))
200 # Test that the GL(ES) 2 gl_LastFragData built-in is read-only.
201 # From the EXT_shader_framebuffer_fetch extension: "[...] fragment
202 # shaders should use the read-only input array gl_LastFragData."
204 gen_compiler("""\
206 * [config]
207 * expect_result: fail
208 * glsl_version: 1.0 es
209 * require_extensions: GL_${extension}
210 * [end config]
212 #version 100
213 #extension GL_${extension} : enable
215 void main()
217 gl_LastFragData[0] = vec4(1.0);
219 """, product(all_defs,
220 [{'name': 'negative-gl_LastFragData-write',
221 'api': 'gles2',
222 'shader_stage': 'frag'}]))
225 # Test framebuffer fetch output declarations with invalid layout
226 # qualifiers. From the EXT_shader_framebuffer_fetch extension:
228 # "It is an error to declare an inout fragment output not
229 # qualified with layout(noncoherent) if the
230 # GL_EXT_shader_framebuffer_fetch extension hasn't been enabled."
232 # "The ability to use the inout and layout(noncoherent) qualifiers
233 # at global scope in a fragment shader are optional and can be
234 # enabled by
235 # #extension GL_EXT_shader_framebuffer_fetch_non_coherent : <behavior>"
237 gen_compiler("""\
239 * [config]
240 * expect_result: fail
241 * glsl_version: ${3.0 if api_version >= 3.0 else 1.0} es
242 * require_extensions: GL_${extension}
243 * [end config]
245 #version ${'300 es' if api_version >= 3.0 else '100'}
246 #extension GL_${extension} : enable
248 ${decl_frag_data(api_version, '' if layout else 'layout(noncoherent)')}
250 void main()
252 ${last_frag_data(api_version)};
254 """, product(all_defs,
255 [{'name': 'negative-output-layout',
256 'shader_stage': 'frag'}],
257 [{'api': 'gles2', 'api_version': 2.0},
258 {'api': 'gles3', 'api_version': 3.0}]))
261 # Test that GL(ES) 3+ user-defined inout arrays are not accepted
262 # in earlier GLSL versions.
264 gen_compiler("""\
266 * [config]
267 * expect_result: fail
268 * glsl_version: 1.0 es
269 * require_extensions: GL_${extension}
270 * [end config]
272 #version 100
273 #extension GL_${extension} : enable
275 inout highp vec4 color;
277 void main()
279 color += vec4(0.5);
281 """, product(all_defs,
282 [{'name': 'negative-inout-fragment-output',
283 'api': 'gles2',
284 'shader_stage': 'frag'}]))
287 # Test that redeclaring an existing built-in fragment output as
288 # 'inout' leads to an error.
290 gen_compiler("""\
292 * [config]
293 * expect_result: fail
294 * glsl_version: 3.0 es
295 * require_extensions: GL_${extension}
296 * [end config]
298 #version 300 es
299 #extension GL_${extension} : enable
301 inout highp float gl_FragDepth;
303 void main()
305 gl_FragDepth += 0.5;
307 """, product(all_defs,
308 [{'name': 'negative-inout-gl_FragDepth',
309 'api': 'gles3',
310 'shader_stage': 'frag'}]))
313 # Test that vertex shader interface variables cannot be declared
314 # 'inout'.
316 gen_compiler("""\
318 * [config]
319 * expect_result: fail
320 * glsl_version: 3.0 es
321 * require_extensions: GL_${extension}
322 * [end config]
324 #version 300 es
325 #extension GL_${extension} : enable
327 inout highp vec4 vcolor;
329 void main()
332 """, product(all_defs,
333 [{'name': 'negative-inout-vertex-output',
334 'api': 'gles3',
335 'shader_stage': 'vert'}]))
338 # Test basic framebuffer fetch functionality.
340 gen_execution("""\
341 [require]
342 GL ES >= ${api_version}
343 GLSL ES >= ${3.0 if api_version >= 3.0 else 1.0}
344 %if samples > 0:
345 INT GL_MAX_SAMPLES >= ${samples}
346 %endif
347 GL_${extension}
349 [vertex shader passthrough]
351 [fragment shader]
352 #version ${'300 es' if api_version >= 3.0 else '100'}
353 #extension GL_${extension} : enable
355 ${decl_frag_data(api_version, layout)}
357 void main()
359 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
360 vec4(0.5, 0.0, 0.0, 0.0);
363 [test]
364 ${bind_fb('GL_RGBA8', samples)}
366 clear color 0.0 0.0 1.0 0.0
367 clear
368 ${barrier}
369 draw rect -1 -1 2 2
370 ${barrier}
371 draw rect -1 -1 2 2
373 ${resolve_fb('GL_RGBA8', samples)}
375 relative probe rect rgb (0, 0.0, 1.0, 1.0) (1.0, 0.0, 1.0)
377 ${display_fb(api_version)}
378 """, product(all_defs,
379 [{'name': 'simple-'}],
380 [{'name': 'ss', 'api': 'gles2', 'api_version': 2.0, 'samples': 0},
381 {'name': 'ss', 'api': 'gles3', 'api_version': 3.0, 'samples': 0},
382 {'name': 'ms2', 'api': 'gles3', 'api_version': 3.0, 'samples': 2},
383 {'name': 'ms8', 'api': 'gles3', 'api_version': 3.0, 'samples': 8},
384 {'name': 'ms16', 'api': 'gles3', 'api_version': 3.0, 'samples': 16}]))
387 # Test read-back from a framebuffer with non-uniform contents
388 # rendered during a previous draw call.
390 gen_execution("""\
391 [require]
392 GL ES >= ${api_version}
393 GLSL ES >= ${3.0 if api_version >= 3.0 else 1.0}
394 %if samples > 0:
395 INT GL_MAX_SAMPLES >= ${samples}
396 %endif
397 GL_${extension}
399 [vertex shader]
400 #version ${'300 es' if api_version >= 3.0 else '100'}
402 ${'in' if api_version >= 3.0 else 'attribute'} highp vec4 vertex;
403 ${'out' if api_version >= 3.0 else 'varying'} highp vec4 vcolor;
405 void main()
407 gl_Position = vertex;
408 // Transform the vertex coordinates so that the R and G
409 // components of the vertex color range between 0.0 and 1.0.
410 vcolor = vec4((1.0 + vertex.x) / 2.0,
411 (1.0 + vertex.y) / 2.0, 0.0, 1.0);
414 [fragment shader]
415 #version ${'300 es' if api_version >= 3.0 else '100'}
416 #extension GL_${extension} : enable
418 ${'in' if api_version >= 3.0 else 'varying'} highp vec4 vcolor;
419 ${decl_frag_data(api_version, layout, p=precision)}
421 void main()
423 // The condition makes sure that the else branch is
424 // taken for the top and right quadrants during the second
425 // overdraw.
426 if (${last_frag_data(api_version)}.x <= 0.5 &&
427 ${last_frag_data(api_version)}.y <= 0.5) {
428 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
429 vcolor;
430 } else {
431 // Will give a solid color as result different for
432 // each quadrant, assuming that the first branch was
433 // taken during the first pass.
434 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
435 vec4((vcolor.x >= 0.5 ? 1.0 : 0.0) - vcolor.x,
436 (vcolor.y >= 0.5 ? 1.0 : 0.0) - vcolor.y,
437 0, 0);
441 [test]
442 ${bind_fb('GL_RGBA8', samples)}
444 clear color 0.0 0.0 1.0 0.0
445 clear
446 ${barrier}
447 draw rect -1 -1 2 2
448 ${barrier}
449 draw rect -1 -1 2 2
451 ${resolve_fb('GL_RGBA8', samples)}
453 relative probe rect rgb (0.55, 0.0, 0.45, 0.45) (1.0, 0.0, 1.0)
454 relative probe rect rgb (0.0, 0.55, 0.45, 0.45) (0.0, 1.0, 1.0)
455 relative probe rect rgb (0.55, 0.55, 0.45, 0.45) (1.0, 1.0, 1.0)
457 ${display_fb(api_version)}
458 """, product(all_defs,
459 [{'name': 'nonuniform-'}],
460 [{'name': 'ss', 'api': 'gles2', 'api_version': 2.0,
461 'samples': 0, 'precision': 'mediump'},
462 {'name': 'ss-redecl-highp', 'api': 'gles2',
463 'api_version': 2.0, 'samples': 0, 'precision': 'highp'},
464 {'name': 'ss-redecl-lowp', 'api': 'gles2',
465 'api_version': 2.0, 'samples': 0, 'precision': 'lowp'},
466 {'name': 'ss', 'api': 'gles3', 'api_version': 3.0,
467 'samples': 0, 'precision': 'mediump'},
468 {'name': 'ms2', 'api': 'gles3', 'api_version': 3.0,
469 'samples': 2, 'precision': 'mediump'},
470 {'name': 'ms8', 'api': 'gles3', 'api_version': 3.0,
471 'samples': 8, 'precision': 'mediump'},
472 {'name': 'ms16', 'api': 'gles3', 'api_version': 3.0,
473 'samples': 16, 'precision': 'mediump'}]))
476 # Test basic framebuffer fetch functionality in combination with
477 # texturing.
479 gen_execution("""\
480 [require]
481 GL ES >= ${api_version}
482 GLSL ES >= 3.00
483 GL_${extension}
485 [vertex shader passthrough]
487 [fragment shader]
488 #version 300 es
489 #extension GL_${extension} : enable
491 uniform sampler2D s;
492 ${decl_frag_data(api_version, layout)}
494 void main()
496 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
497 texelFetch(s, ivec2(gl_FragCoord), 0) / 4.0;
500 [test]
501 ${bind_fb('GL_RGBA8')}
503 texture rgbw 1 (250, 250) GL_RGBA8
504 uniform int s 1
506 clear color 0.5 0.0 0.0 0.0
507 clear
508 ${barrier}
509 draw rect -1 -1 2 2
510 ${barrier}
511 draw rect -1 -1 2 2
513 relative probe rect rgb (0.0, 0.0, 0.45, 0.45) (1.0, 0.0, 0.0)
514 relative probe rect rgb (0.55, 0.0, 0.45, 0.45) (0.5, 0.5, 0.0)
515 relative probe rect rgb (0.0, 0.55, 0.45, 0.45) (0.5, 0.0, 0.5)
516 relative probe rect rgb (0.55, 0.55, 0.45, 0.45) (1.0, 0.5, 0.5)
518 ${display_fb(api_version)}
519 """, product(all_defs,
520 [{'name': 'texture',
521 'api': 'gles3',
522 'api_version': 3.0}]))
525 # Test non-uniform fragment discard dependent on the result read
526 # back from the framebuffer. The EXT_shader_framebuffer_fetch
527 # multisample test will be skipped if the implementation doesn't
528 # claim to support per-sample discard.
530 gen_execution("""\
531 [require]
532 GL ES >= ${api_version}
533 GLSL ES >= 3.00
534 GL_${extension}
535 %if samples > 0:
536 INT GL_MAX_SAMPLES >= ${samples}
537 %endif
538 INT GL_FRAGMENT_SHADER_DISCARDS_SAMPLES_EXT >= ${1 if samples else 0}
540 [vertex shader]
541 #version 300 es
543 in highp vec4 vertex;
544 out highp vec4 vcolor;
546 void main()
548 gl_Position = vertex;
549 // Transform the vertex coordinates so that the R and G
550 // components of the vertex color range between 0.0 and 1.0.
551 vcolor = vec4((1.0 + vertex.x) / 2.0,
552 (1.0 + vertex.y) / 2.0, 0.0, 1.0);
555 [fragment shader]
556 #version 300 es
557 #extension GL_${extension} : enable
559 in highp vec4 vcolor;
560 ${decl_frag_data(api_version, layout)}
562 void main()
564 // The condition makes sure that the discard branch is
565 // taken for the top and right quadrants during the second
566 // overdraw.
567 if (${last_frag_data(api_version)}.x <= 0.45 &&
568 ${last_frag_data(api_version)}.y < 0.45)
569 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
570 vec4(vcolor.x >= 0.5 ? 0.5 : 0.1,
571 vcolor.y >= 0.5 ? 0.5 : 0.1,
572 0.0, 0.0);
573 else
574 discard;
577 [test]
578 ${bind_fb('GL_RGBA8', samples)}
580 clear color 0.0 0.0 1.0 0.0
581 clear
582 ${barrier}
583 draw rect -1 -1 2 2
584 ${barrier}
585 draw rect -1 -1 2 2
587 ${resolve_fb('GL_RGBA8', samples)}
589 relative probe rect rgb (0.0, 0.0, 0.45, 0.45) (0.2, 0.2, 1.0)
590 relative probe rect rgb (0.55, 0.0, 0.45, 0.45) (0.5, 0.1, 1.0)
591 relative probe rect rgb (0.0, 0.55, 0.45, 0.45) (0.1, 0.5, 1.0)
592 relative probe rect rgb (0.55, 0.55, 0.45, 0.45) (0.5, 0.5, 1.0)
594 ${display_fb(api_version)}
595 """, product(all_defs,
596 [{'name': 'discard-',
597 'api': 'gles3',
598 'api_version': 3.0}],
599 [{'name': 'ss', 'samples': 0},
600 {'name': 'ms8', 'samples': 8}]))
603 # Test read-back from an integer framebuffer with non-uniform
604 # contents rendered during a previous draw call. Similar to the
605 # "nonuniform" test above but using an integer framebuffer.
607 gen_execution("""\
608 [require]
609 GL ES >= ${api_version}
610 GLSL ES >= 3.00
611 GL_${extension}
612 %if samples > 0:
613 INT GL_MAX_SAMPLES >= ${samples}
614 %endif
616 [vertex shader]
617 #version 300 es
619 in highp vec4 vertex;
620 out highp vec4 vcolor;
622 void main()
624 gl_Position = vertex;
625 // Transform the vertex coordinates so that the R and G
626 // components of the vertex color range between 0.0 and 1.0.
627 vcolor = vec4((1.0 + vertex.x) / 2.0,
628 (1.0 + vertex.y) / 2.0, 0.0, 1.0);
631 [fragment shader]
632 #version 300 es
633 #extension GL_${extension} : enable
634 #define SCALE 100
636 in highp vec4 vcolor;
637 ${decl_frag_data(api_version, layout, t='ivec4')}
639 void main()
641 if (${last_frag_data(api_version)}.x <= SCALE / 2 &&
642 ${last_frag_data(api_version)}.y <= SCALE / 2)
643 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
644 ivec4(vcolor * float(SCALE));
645 else
646 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
647 ivec4((vcolor.x >= 0.5 ? SCALE : 0)
648 - int(vcolor.x * float(SCALE)),
649 (vcolor.y >= 0.5 ? SCALE : 0)
650 - int(vcolor.y * float(SCALE)),
651 0, 0);
654 [test]
655 ${bind_fb('GL_RGBA8I', samples)}
657 clear color 0 0 1 0
658 clear
659 ${barrier}
660 draw rect -1 -1 2 2
661 ${barrier}
662 draw rect -1 -1 2 2
664 ${resolve_fb('GL_RGBA8I', samples)}
666 relative probe rect rgba int (0.55, 0.0, 0.45, 0.45) (100, 0, 127, 100)
667 relative probe rect rgba int (0.0, 0.55, 0.45, 0.45) (0, 100, 127, 100)
668 relative probe rect rgba int (0.55, 0.55, 0.45, 0.45) (100, 100, 127, 100)
669 """, product(all_defs,
670 [{'name': 'integer-', 'api': 'gles3'}],
671 [{'name': 'ss', 'samples': 0, 'api_version': 3.0},
672 {'name': 'ms2', 'samples': 2, 'api_version': 3.1},
673 {'name': 'ms8', 'samples': 8, 'api_version': 3.1}]))
676 # Test framebuffer fetch functionality in combination with
677 # multiple render targets.
679 gen_execution("""\
680 [require]
681 GL ES >= ${api_version}
682 GLSL ES >= ${3.0 if api_version >= 3.0 else 1.0}
683 GL_${extension}
685 [vertex shader passthrough]
687 [fragment shader]
688 #version ${'300 es' if api_version >= 3.0 else '100'}
689 #extension GL_${extension} : enable
691 ${decl_frag_data(api_version, layout, 4)}
693 void main()
695 ${frag_data(api_version, 0)} = ${last_frag_data(api_version, 0)} +
696 vec4(0.5, 0.0, 0.0, 0.0);
697 ${frag_data(api_version, 1)} = ${last_frag_data(api_version, 1)} +
698 vec4(0.0, 0.5, 0.0, 0.0);
699 ${frag_data(api_version, 2)} = ${last_frag_data(api_version, 2)} +
700 vec4(0.5, 0.5, 0.0, 0.0);
701 ${frag_data(api_version, 3)} = ${last_frag_data(api_version, 3)} +
702 vec4(0.0, 0.0, 0.5, 0.0);
705 [test]
706 texture rgbw 0 (250, 250) GL_RGBA8
707 texture rgbw 1 (250, 250) GL_RGBA8
708 texture rgbw 2 (250, 250) GL_RGBA8
709 texture rgbw 3 (250, 250) GL_RGBA8
710 fb tex 2d 0 1 2 3
712 clear color 0.0 0.0 0.5 0.0
713 clear
714 ${barrier}
715 draw rect -1 -1 2 2
716 ${barrier}
717 draw rect -1 -1 2 2
719 fb tex 2d 0
720 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) (1.0, 0.0, 0.5)
722 fb tex 2d 1
723 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) (0.0, 1.0, 0.5)
725 fb tex 2d 2
726 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) (1.0, 1.0, 0.5)
728 fb tex 2d 3
729 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) (0.0, 0.0, 1.0)
731 ${display_fb(api_version)}
732 """, product(all_defs,
733 [{'name': 'mrt'}],
734 [{'api': 'gles2', 'api_version': 2.0},
735 {'api': 'gles3', 'api_version': 3.0}]))
738 # Test framebuffer fetch functionality with multiple assignments
739 # of the fragment color input-output.
741 gen_execution("""\
742 [require]
743 GL ES >= ${api_version}
744 GLSL ES >= 3.00
745 GL_${extension}
747 [vertex shader]
748 #version 300 es
750 in vec4 vertex;
751 out vec4 vcolor;
753 void main()
755 gl_Position = vertex;
756 // Transform the vertex coordinates so that the R and G
757 // components of the vertex color range between 0.0 and 1.0.
758 vcolor = vec4((1.0 + vertex.x) / 2.0,
759 (1.0 + vertex.y) / 2.0, 0.0, 1.0);
762 [fragment shader]
763 #version 300 es
764 #extension GL_${extension} : enable
766 in highp vec4 vcolor;
767 ${decl_frag_data(api_version, layout)}
769 void main()
771 // The conditional assignment will be executed for the top
772 // and right quadrants.
773 if (vcolor.x >= 0.5 || vcolor.y >= 0.5)
774 ${frag_data(api_version)} += vec4(0.5, 0, 0, 0);
776 ${frag_data(api_version)} += vec4(0.0, 0.5, 0, 0);
779 [test]
780 ${bind_fb('GL_RGBA8')}
782 clear color 0.0 0.0 1.0 0.0
783 clear
784 ${barrier}
785 draw rect -1 -1 2 2
786 ${barrier}
787 draw rect -1 -1 2 2
789 relative probe rect rgb (0.0, 0.0, 0.45, 0.45) (0.0, 1.0, 1.0)
790 relative probe rect rgb (0.55, 0.0, 0.45, 0.45) (1.0, 1.0, 1.0)
791 relative probe rect rgb (0.0, 0.55, 0.45, 0.45) (1.0, 1.0, 1.0)
792 relative probe rect rgb (0.55, 0.55, 0.45, 0.45) (1.0, 1.0, 1.0)
794 ${display_fb(api_version)}
795 """, product(all_defs,
796 [{'name': 'overwrite',
797 'api': 'gles3',
798 'api_version': 3.0}]))
801 # Test framebuffer fetch functionality on individual slices of a
802 # texture render target with multiple layers or mipmap levels.
804 gen_execution("""\
805 [require]
806 GL ES >= ${api_version}
807 GLSL ES >= 3.00
808 GL_${extension}
810 [vertex shader passthrough]
812 [fragment shader]
813 #version 300 es
814 #extension GL_${extension} : enable
816 ${decl_frag_data(api_version, layout)}
817 uniform highp vec4 ucolor;
819 void main()
821 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
822 ucolor;
825 [test]
826 %if target == 'Cube':
827 texture storage 0 ${target} GL_RGBA8 (${levels} 250 250)
828 %else:
829 texture storage 0 ${target} GL_RGBA8 (${levels} 250 250 ${layers})
830 %endif
832 <%! blend_colors = ['0.5 0.0 0.0 0.0',
833 '0.0 0.5 0.0 0.0',
834 '0.5 0.5 0.0 0.0',
835 '0.0 0.0 0.5 0.0'] %>
837 %for l in range(0, levels):
838 %for z in range(0, layers):
839 fb tex slice ${target} 0 ${l} ${z}
840 uniform vec4 ucolor ${blend_colors[(l + z) % 4]}
841 clear color 0.0 0.0 0.5 0.0
842 clear
843 ${barrier}
844 draw rect -1 -1 2 2
845 ${barrier}
846 draw rect -1 -1 2 2
848 %endfor
849 %endfor
851 <%! expected_colors = ['(1.0, 0.0, 0.5)',
852 '(0.0, 1.0, 0.5)',
853 '(1.0, 1.0, 0.5)',
854 '(0.0, 0.0, 1.0)'] %>
856 %for l in range(0, levels):
857 %for z in range(0, layers):
858 fb tex slice ${target} 0 ${l} ${z}
859 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) ${expected_colors[(l + z) % 4]}
861 %endfor
862 %endfor
864 ${display_fb(api_version)}
865 """, product(all_defs,
866 [{'name': 'single-slice-',
867 'api': 'gles3',
868 'api_version': 3.0}],
869 [{'name': '2darray', 'target': '2DArray',
870 'levels': 1, 'layers': 4},
871 {'name': '2darray-mipmap', 'target': '2DArray',
872 'levels': 4, 'layers': 1},
873 {'name': '3d', 'target': '3D',
874 'levels': 1, 'layers': 4},
875 {'name': 'cubemap', 'target': 'Cube',
876 'levels': 1, 'layers': 6}]))
879 # Test framebuffer fetch functionality on a 1D framebuffer.
881 gen_execution("""\
882 [require]
883 GL >= ${api_version}
884 GLSL >= 1.50
885 GL_ARB_texture_storage
886 GL_${extension}
888 [vertex shader]
889 #version 150
891 in vec4 vertex;
892 out vec4 vcolor;
894 void main()
896 gl_Position = vertex;
897 // Transform the vertex coordinates so that the R
898 // component of the vertex color ranges between 0.0 and 1.0.
899 vcolor = vec4((1.0 + vertex.x) / 2.0, 0.7, 0.0, 1.0);
902 [fragment shader]
903 #version 150
904 #extension GL_${extension} : enable
906 in vec4 vcolor;
907 ${decl_frag_data(api_version, layout)}
909 void main()
911 // The else branch will be executed during the second
912 // overdraw.
913 if (${last_frag_data(api_version)}.x <= 0.5 &&
914 ${last_frag_data(api_version)}.y <= 0.5) {
915 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
916 vcolor;
917 } else {
918 // Will give a solid color as result different for
919 // each half, assuming that the first branch was taken
920 // during the first pass.
921 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
922 vec4((vcolor.x >= 0.5 ? 1.0 : 0.0) - vcolor.x,
923 (vcolor.y >= 0.5 ? 1.0 : 0.0) - vcolor.y, 0, 0);
927 [test]
928 texture storage 0 1D GL_RGBA8 (1 250)
929 fb tex slice 1D 0 0 0
931 clear color 0.0 0.0 1.0 0.0
932 clear
933 ${barrier}
934 draw rect -1 -1 2 2
935 ${barrier}
936 draw rect -1 -1 2 2
938 relative probe rect rgb (0.0, 0.0, 0.45, 1.0) (0.0, 1.0, 1.0)
939 relative probe rect rgb (0.55, 0.0, 0.45, 1.0) (1.0, 1.0, 1.0)
941 fb draw winsys
942 blit color linear
943 """, product(all_defs,
944 [{'name': '1d',
945 'api': 'gl',
946 'api_version': 3.2}]))
949 # Test framebuffer fetch functionality while rendering into
950 # multiple layers of an array or cubemap framebuffer
951 # simultaneously.
953 gen_execution("""\
954 [require]
955 GL >= ${api_version}
956 GLSL >= 1.50
957 GL_ARB_texture_storage
958 GL_${extension}
960 [vertex shader passthrough]
961 [geometry shader]
962 #version 150
964 layout(triangles) in;
965 layout(triangle_strip, max_vertices=18) out;
967 flat out int glayer;
969 void main()
971 for (int layer = 0; layer < ${layers}; layer++) {
972 for (int i = 0; i < 3; i++) {
973 gl_Position = gl_in[i].gl_Position;
974 gl_Layer = glayer = layer;
975 EmitVertex();
977 EndPrimitive();
981 [fragment shader]
982 #version 150
983 #extension GL_${extension} : enable
985 flat in int glayer;
986 ${decl_frag_data(api_version, layout)}
988 void main()
990 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
991 (glayer == 5 ? vec4(0.0, 0.5, 0.5, 0.0) :
992 glayer == 4 ? vec4(0.5, 0.0, 0.5, 0.0) :
993 glayer == 3 ? vec4(0.0, 0.0, 0.5, 0.0) :
994 glayer == 2 ? vec4(0.5, 0.5, 0.0, 0.0) :
995 glayer == 1 ? vec4(0.0, 0.5, 0.0, 0.0) :
996 vec4(0.5, 0.0, 0.0, 0.0));
999 [test]
1000 texture storage 0 ${target} GL_RGBA8 (${dimensions})
1001 fb tex layered 0
1003 clear color 0.0 0.0 0.5 0.0
1004 clear
1005 ${barrier}
1006 draw rect -1 -1 2 2
1007 ${barrier}
1008 draw rect -1 -1 2 2
1010 <%! expected_colors = ['(1.0, 0.0, 0.5)',
1011 '(0.0, 1.0, 0.5)',
1012 '(1.0, 1.0, 0.5)',
1013 '(0.0, 0.0, 1.0)',
1014 '(1.0, 0.0, 1.0)',
1015 '(0.0, 1.0, 1.0)'] %>
1017 %for z in range(0, layers):
1018 fb tex slice ${target} 0 0 ${z}
1019 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) ${expected_colors[z]}
1020 %endfor
1022 fb draw winsys
1023 blit color linear
1024 """, product(all_defs,
1025 [{'name': 'layered-',
1026 'api': 'gl',
1027 'api_version': 3.2}],
1028 [{'name': '1darray', 'target': '1DArray',
1029 'dimensions': '1 250 4', 'layers': 4},
1030 {'name': '2darray', 'target': '2DArray',
1031 'dimensions': '1 250 250 4', 'layers': 4},
1032 {'name': 'cubemap', 'target': 'Cube',
1033 'dimensions': '1 250 250', 'layers': 6}]))
1035 if __name__ == '__main__':
1036 main()