perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / generated_tests / gen_shader_framebuffer_fetch_tests.py
blobb64f5837322ad6833477dfbaab579ff5852bd741
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 import sys
26 from textwrap import dedent
28 from mako.template import Template
29 from mako import exceptions
31 from modules import utils
34 def product(ps, *qss):
35 """
36 Generate the cartesian product of a number of lists of dictionaries.
38 Generate a sequence with every possible combination of elements of
39 the specified lists of dictionaries. Each element of the result
40 will be the union of some combination of dictionaries from the
41 lists given as argument. The 'name' attribute of each dictionary
42 given as input is concatenated with the names of other
43 dictionaries part of the same combination to give the 'name'
44 attribute of the result.
45 """
46 for q in (product(*qss) if qss else [{}]):
47 for p in ps:
48 r = dict(p, **q)
49 r['name'] = ''.join(s['name'] for s in (p, q) if s.get('name'))
50 yield r
53 def gen(src, tests):
54 """
55 Expand a source template for the provided list of test definitions.
57 Generate a test script for each element of the 'tests' iterable,
58 each of them should be a dictionary of definitions that will be
59 used as environment to render the source template.
61 The 'path' attribute of each dictionary gives the filename each
62 test will be written to.
63 """
64 template = Template(dedent(src))
66 for t in tests:
67 print(t['path'])
68 utils.safe_makedirs(os.path.dirname(t['path']))
69 with open(t['path'], 'w') as f:
70 try:
71 f.write(template.render(**t))
72 except:
73 print(exceptions.text_error_template().render(), file=sys.stderr)
74 raise
77 def gen_execution(src, tests):
78 """
79 Generate a shader runner test for each element of the 'tests'
80 iterable.
81 """
82 return gen(src,
83 (dict(t, path = os.path.join(
84 'spec', t['extension'], 'execution', t['api'],
85 t['name'] + '.shader_test')) for t in tests))
88 def gen_compiler(src, tests):
89 """
90 Generate a GLSL parser test for each element of the 'tests'
91 iterable.
92 """
93 return gen(src,
94 (dict(t, path = os.path.join(
95 'spec', t['extension'], 'compiler', t['api'],
96 t['name'] + '.' + t['shader_stage'])) for t in tests))
100 # Common test definitions independent of the framebuffer fetch
101 # extension.
103 common_defs = [{# Allocate and bind a framebuffer object of the given
104 # format and number of samples.
105 'bind_fb': lambda fmt, samples = 0:
106 'fb ms {0} 250 250 {1}'.format(fmt, samples) if samples > 0 else
107 ('texture storage 0 2D {0} (1 250 250)\n'
108 'fb tex 2d 0').format(fmt) if fmt[-1] == 'I' else
109 ('texture rgbw 0 (250, 250) {0}\n'
110 'fb tex 2d 0').format(fmt),
112 # Resolve the contents of a framebuffer previously
113 # allocated with 'bind_fb' of the given format and
114 # samples into a newly allocated single-sample
115 # framebuffer.
116 'resolve_fb': lambda fmt, samples:
117 '' if samples == 0 else
118 ('texture storage 0 2D {0} (1 250 250)\n'
119 'fb draw tex 2d 0\n'
120 'blit color nearest\n'
121 'fb read tex 2d 0\n').format(fmt) if fmt[-1] == 'I' else
122 ('texture rgbw 0 (250, 250) {0}\n'
123 'fb draw tex 2d 0\n'
124 'blit color linear\n'
125 'fb read tex 2d 0').format(fmt),
127 # Blit the contents of the current read framebuffer
128 # into the window system framebuffer. XXX - Requires
129 # GL(ES) 3.0+ since glBlitFramebuffer doesn't exist on
130 # earlier API versions.
131 'display_fb': lambda api_version:
132 '' if api_version < 3.0 else
133 ('fb draw winsys\n'
134 'blit color linear'),
136 # Declare a fragment color array set up for
137 # framebuffer fetch with the specified number of
138 # elements (n=0 indicates a single scalar output).
140 # The fragment color array can be accessed using the
141 # 'frag_data' and 'last_frag_data' macros defined
142 # below to make sure the generated test is valid
143 # irrespective of the GLSL version.
144 'decl_frag_data': lambda api_version, layout, n = 0, \
145 t = 'vec4', p = 'mediump':
146 '' if api_version < 3.0 and not layout and t == 'vec4' \
147 and p == 'mediump' else
148 layout + ' ' + p + ' ' + t + ' gl_LastFragData[gl_MaxDrawBuffers];' \
149 if api_version < 3.0 else
150 layout + ' inout ' + p + ' ' + t + ' fcolor;' if n == 0 else
151 layout + ' inout ' + p + ' ' + t + ' fcolor[{0}];'.format(n),
153 'frag_data': lambda api_version, i = -1:
154 'gl_FragData[{0}]'.format(max(0, i)) if api_version < 3.0 else
155 'fcolor[{0}]'.format(i) if i >= 0 else
156 'fcolor',
158 'last_frag_data': lambda api_version, i = -1:
159 'gl_LastFragData[{0}]'.format(max(0, i)) if api_version < 3.0 else
160 'fcolor[{0}]'.format(i) if i >= 0 else
161 'fcolor'}]
165 # Common test definitions for all supported extensions.
167 all_defs = list(product(common_defs,
168 [{'extension': 'EXT_shader_framebuffer_fetch',
169 'layout': '',
170 'barrier': ''},
171 {'extension': 'EXT_shader_framebuffer_fetch_non_coherent',
172 'layout': 'layout(noncoherent)',
173 'barrier': 'fbfetch barrier'}]))
176 def main():
177 """Main function."""
180 # Test that the GL(ES) 2 gl_LastFragData built-in is not defined
181 # in more recent GLSL versions.
183 gen_compiler("""\
185 * [config]
186 * expect_result: fail
187 * glsl_version: 3.0 es
188 * require_extensions: GL_${extension}
189 * [end config]
191 #version 300 es
192 #extension GL_${extension} : enable
194 out highp vec4 color;
196 void main()
198 color = gl_LastFragData[0];
200 """, product(all_defs,
201 [{'name': 'negative-gl_LastFragData',
202 'api': 'gles3',
203 'shader_stage': 'frag'}]))
206 # Test that the GL(ES) 2 gl_LastFragData built-in is read-only.
207 # From the EXT_shader_framebuffer_fetch extension: "[...] fragment
208 # shaders should use the read-only input array gl_LastFragData."
210 gen_compiler("""\
212 * [config]
213 * expect_result: fail
214 * glsl_version: 1.0 es
215 * require_extensions: GL_${extension}
216 * [end config]
218 #version 100
219 #extension GL_${extension} : enable
221 void main()
223 gl_LastFragData[0] = vec4(1.0);
225 """, product(all_defs,
226 [{'name': 'negative-gl_LastFragData-write',
227 'api': 'gles2',
228 'shader_stage': 'frag'}]))
231 # Test framebuffer fetch output declarations with invalid layout
232 # qualifiers. From the EXT_shader_framebuffer_fetch extension:
234 # "It is an error to declare an inout fragment output not
235 # qualified with layout(noncoherent) if the
236 # GL_EXT_shader_framebuffer_fetch extension hasn't been enabled."
238 # "The ability to use the inout and layout(noncoherent) qualifiers
239 # at global scope in a fragment shader are optional and can be
240 # enabled by
241 # #extension GL_EXT_shader_framebuffer_fetch_non_coherent : <behavior>"
243 gen_compiler("""\
245 * [config]
246 * expect_result: fail
247 * glsl_version: ${3.0 if api_version >= 3.0 else 1.0} es
248 * require_extensions: GL_${extension}
249 * [end config]
251 #version ${'300 es' if api_version >= 3.0 else '100'}
252 #extension GL_${extension} : enable
254 ${decl_frag_data(api_version, '' if layout else 'layout(noncoherent)')}
256 void main()
258 ${last_frag_data(api_version)};
260 """, product(all_defs,
261 [{'name': 'negative-output-layout',
262 'shader_stage': 'frag'}],
263 [{'api': 'gles2', 'api_version': 2.0},
264 {'api': 'gles3', 'api_version': 3.0}]))
267 # Test that GL(ES) 3+ user-defined inout arrays are not accepted
268 # in earlier GLSL versions.
270 gen_compiler("""\
272 * [config]
273 * expect_result: fail
274 * glsl_version: 1.0 es
275 * require_extensions: GL_${extension}
276 * [end config]
278 #version 100
279 #extension GL_${extension} : enable
281 inout highp vec4 color;
283 void main()
285 color += vec4(0.5);
287 """, product(all_defs,
288 [{'name': 'negative-inout-fragment-output',
289 'api': 'gles2',
290 'shader_stage': 'frag'}]))
293 # Test that redeclaring an existing built-in fragment output as
294 # 'inout' leads to an error.
296 gen_compiler("""\
298 * [config]
299 * expect_result: fail
300 * glsl_version: 3.0 es
301 * require_extensions: GL_${extension}
302 * [end config]
304 #version 300 es
305 #extension GL_${extension} : enable
307 inout highp float gl_FragDepth;
309 void main()
311 gl_FragDepth += 0.5;
313 """, product(all_defs,
314 [{'name': 'negative-inout-gl_FragDepth',
315 'api': 'gles3',
316 'shader_stage': 'frag'}]))
319 # Test that vertex shader interface variables cannot be declared
320 # 'inout'.
322 gen_compiler("""\
324 * [config]
325 * expect_result: fail
326 * glsl_version: 3.0 es
327 * require_extensions: GL_${extension}
328 * [end config]
330 #version 300 es
331 #extension GL_${extension} : enable
333 inout highp vec4 vcolor;
335 void main()
338 """, product(all_defs,
339 [{'name': 'negative-inout-vertex-output',
340 'api': 'gles3',
341 'shader_stage': 'vert'}]))
344 # Test basic framebuffer fetch functionality.
346 gen_execution("""\
347 [require]
348 GL ES >= ${api_version}
349 GLSL ES >= ${3.0 if api_version >= 3.0 else 1.0}
350 %if samples > 0:
351 INT GL_MAX_SAMPLES >= ${samples}
352 %endif
353 GL_${extension}
355 [vertex shader passthrough]
357 [fragment shader]
358 #version ${'300 es' if api_version >= 3.0 else '100'}
359 #extension GL_${extension} : enable
361 ${decl_frag_data(api_version, layout)}
363 void main()
365 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
366 vec4(0.5, 0.0, 0.0, 0.0);
369 [test]
370 ${bind_fb('GL_RGBA8', samples)}
372 clear color 0.0 0.0 1.0 0.0
373 clear
374 ${barrier}
375 draw rect -1 -1 2 2
376 ${barrier}
377 draw rect -1 -1 2 2
379 ${resolve_fb('GL_RGBA8', samples)}
381 relative probe rect rgb (0, 0.0, 1.0, 1.0) (1.0, 0.0, 1.0)
383 ${display_fb(api_version)}
384 """, product(all_defs,
385 [{'name': 'simple-'}],
386 [{'name': 'ss', 'api': 'gles2', 'api_version': 2.0, 'samples': 0},
387 {'name': 'ss', 'api': 'gles3', 'api_version': 3.0, 'samples': 0},
388 {'name': 'ms2', 'api': 'gles3', 'api_version': 3.0, 'samples': 2},
389 {'name': 'ms8', 'api': 'gles3', 'api_version': 3.0, 'samples': 8},
390 {'name': 'ms16', 'api': 'gles3', 'api_version': 3.0, 'samples': 16}]))
393 # Test read-back from a framebuffer with non-uniform contents
394 # rendered during a previous draw call.
396 gen_execution("""\
397 [require]
398 GL ES >= ${api_version}
399 GLSL ES >= ${3.0 if api_version >= 3.0 else 1.0}
400 %if samples > 0:
401 INT GL_MAX_SAMPLES >= ${samples}
402 %endif
403 GL_${extension}
405 [vertex shader]
406 #version ${'300 es' if api_version >= 3.0 else '100'}
408 ${'in' if api_version >= 3.0 else 'attribute'} highp vec4 vertex;
409 ${'out' if api_version >= 3.0 else 'varying'} highp vec4 vcolor;
411 void main()
413 gl_Position = vertex;
414 // Transform the vertex coordinates so that the R and G
415 // components of the vertex color range between 0.0 and 1.0.
416 vcolor = vec4((1.0 + vertex.x) / 2.0,
417 (1.0 + vertex.y) / 2.0, 0.0, 1.0);
420 [fragment shader]
421 #version ${'300 es' if api_version >= 3.0 else '100'}
422 #extension GL_${extension} : enable
424 ${'in' if api_version >= 3.0 else 'varying'} highp vec4 vcolor;
425 ${decl_frag_data(api_version, layout, p=precision)}
427 void main()
429 // The condition makes sure that the else branch is
430 // taken for the top and right quadrants during the second
431 // overdraw.
432 if (${last_frag_data(api_version)}.x <= 0.5 &&
433 ${last_frag_data(api_version)}.y <= 0.5) {
434 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
435 vcolor;
436 } else {
437 // Will give a solid color as result different for
438 // each quadrant, assuming that the first branch was
439 // taken during the first pass.
440 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
441 vec4((vcolor.x >= 0.5 ? 1.0 : 0.0) - vcolor.x,
442 (vcolor.y >= 0.5 ? 1.0 : 0.0) - vcolor.y,
443 0, 0);
447 [test]
448 ${bind_fb('GL_RGBA8', samples)}
450 clear color 0.0 0.0 1.0 0.0
451 clear
452 ${barrier}
453 draw rect -1 -1 2 2
454 ${barrier}
455 draw rect -1 -1 2 2
457 ${resolve_fb('GL_RGBA8', samples)}
459 relative probe rect rgb (0.55, 0.0, 0.45, 0.45) (1.0, 0.0, 1.0)
460 relative probe rect rgb (0.0, 0.55, 0.45, 0.45) (0.0, 1.0, 1.0)
461 relative probe rect rgb (0.55, 0.55, 0.45, 0.45) (1.0, 1.0, 1.0)
463 ${display_fb(api_version)}
464 """, product(all_defs,
465 [{'name': 'nonuniform-'}],
466 [{'name': 'ss', 'api': 'gles2', 'api_version': 2.0,
467 'samples': 0, 'precision': 'mediump'},
468 {'name': 'ss-redecl-highp', 'api': 'gles2',
469 'api_version': 2.0, 'samples': 0, 'precision': 'highp'},
470 {'name': 'ss-redecl-lowp', 'api': 'gles2',
471 'api_version': 2.0, 'samples': 0, 'precision': 'lowp'},
472 {'name': 'ss', 'api': 'gles3', 'api_version': 3.0,
473 'samples': 0, 'precision': 'mediump'},
474 {'name': 'ms2', 'api': 'gles3', 'api_version': 3.0,
475 'samples': 2, 'precision': 'mediump'},
476 {'name': 'ms8', 'api': 'gles3', 'api_version': 3.0,
477 'samples': 8, 'precision': 'mediump'},
478 {'name': 'ms16', 'api': 'gles3', 'api_version': 3.0,
479 'samples': 16, 'precision': 'mediump'}]))
482 # Test basic framebuffer fetch functionality in combination with
483 # texturing.
485 gen_execution("""\
486 [require]
487 GL ES >= ${api_version}
488 GLSL ES >= 3.00
489 GL_${extension}
491 [vertex shader passthrough]
493 [fragment shader]
494 #version 300 es
495 #extension GL_${extension} : enable
497 uniform sampler2D s;
498 ${decl_frag_data(api_version, layout)}
500 void main()
502 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
503 texelFetch(s, ivec2(gl_FragCoord), 0) / 4.0;
506 [test]
507 ${bind_fb('GL_RGBA8')}
509 texture rgbw 1 (250, 250) GL_RGBA8
510 uniform int s 1
512 clear color 0.5 0.0 0.0 0.0
513 clear
514 ${barrier}
515 draw rect -1 -1 2 2
516 ${barrier}
517 draw rect -1 -1 2 2
519 relative probe rect rgb (0.0, 0.0, 0.45, 0.45) (1.0, 0.0, 0.0)
520 relative probe rect rgb (0.55, 0.0, 0.45, 0.45) (0.5, 0.5, 0.0)
521 relative probe rect rgb (0.0, 0.55, 0.45, 0.45) (0.5, 0.0, 0.5)
522 relative probe rect rgb (0.55, 0.55, 0.45, 0.45) (1.0, 0.5, 0.5)
524 ${display_fb(api_version)}
525 """, product(all_defs,
526 [{'name': 'texture',
527 'api': 'gles3',
528 'api_version': 3.0}]))
531 # Test non-uniform fragment discard dependent on the result read
532 # back from the framebuffer. The EXT_shader_framebuffer_fetch
533 # multisample test will be skipped if the implementation doesn't
534 # claim to support per-sample discard.
536 gen_execution("""\
537 [require]
538 GL ES >= ${api_version}
539 GLSL ES >= 3.00
540 GL_${extension}
541 %if samples > 0:
542 INT GL_MAX_SAMPLES >= ${samples}
543 %endif
544 INT GL_FRAGMENT_SHADER_DISCARDS_SAMPLES_EXT >= ${1 if samples else 0}
546 [vertex shader]
547 #version 300 es
549 in highp vec4 vertex;
550 out highp vec4 vcolor;
552 void main()
554 gl_Position = vertex;
555 // Transform the vertex coordinates so that the R and G
556 // components of the vertex color range between 0.0 and 1.0.
557 vcolor = vec4((1.0 + vertex.x) / 2.0,
558 (1.0 + vertex.y) / 2.0, 0.0, 1.0);
561 [fragment shader]
562 #version 300 es
563 #extension GL_${extension} : enable
565 in highp vec4 vcolor;
566 ${decl_frag_data(api_version, layout)}
568 void main()
570 // The condition makes sure that the discard branch is
571 // taken for the top and right quadrants during the second
572 // overdraw.
573 if (${last_frag_data(api_version)}.x <= 0.45 &&
574 ${last_frag_data(api_version)}.y < 0.45)
575 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
576 vec4(vcolor.x >= 0.5 ? 0.5 : 0.1,
577 vcolor.y >= 0.5 ? 0.5 : 0.1,
578 0.0, 0.0);
579 else
580 discard;
583 [test]
584 ${bind_fb('GL_RGBA8', samples)}
586 clear color 0.0 0.0 1.0 0.0
587 clear
588 ${barrier}
589 draw rect -1 -1 2 2
590 ${barrier}
591 draw rect -1 -1 2 2
593 ${resolve_fb('GL_RGBA8', samples)}
595 relative probe rect rgb (0.0, 0.0, 0.45, 0.45) (0.2, 0.2, 1.0)
596 relative probe rect rgb (0.55, 0.0, 0.45, 0.45) (0.5, 0.1, 1.0)
597 relative probe rect rgb (0.0, 0.55, 0.45, 0.45) (0.1, 0.5, 1.0)
598 relative probe rect rgb (0.55, 0.55, 0.45, 0.45) (0.5, 0.5, 1.0)
600 ${display_fb(api_version)}
601 """, product(all_defs,
602 [{'name': 'discard-',
603 'api': 'gles3',
604 'api_version': 3.0}],
605 [{'name': 'ss', 'samples': 0},
606 {'name': 'ms8', 'samples': 8}]))
609 # Test read-back from an integer framebuffer with non-uniform
610 # contents rendered during a previous draw call. Similar to the
611 # "nonuniform" test above but using an integer framebuffer.
613 gen_execution("""\
614 [require]
615 GL ES >= ${api_version}
616 GLSL ES >= 3.00
617 GL_${extension}
618 %if samples > 0:
619 INT GL_MAX_SAMPLES >= ${samples}
620 %endif
622 [vertex shader]
623 #version 300 es
625 in highp vec4 vertex;
626 out highp vec4 vcolor;
628 void main()
630 gl_Position = vertex;
631 // Transform the vertex coordinates so that the R and G
632 // components of the vertex color range between 0.0 and 1.0.
633 vcolor = vec4((1.0 + vertex.x) / 2.0,
634 (1.0 + vertex.y) / 2.0, 0.0, 1.0);
637 [fragment shader]
638 #version 300 es
639 #extension GL_${extension} : enable
640 #define SCALE 100
642 in highp vec4 vcolor;
643 ${decl_frag_data(api_version, layout, t='ivec4')}
645 void main()
647 if (${last_frag_data(api_version)}.x <= SCALE / 2 &&
648 ${last_frag_data(api_version)}.y <= SCALE / 2)
649 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
650 ivec4(vcolor * float(SCALE));
651 else
652 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
653 ivec4((vcolor.x >= 0.5 ? SCALE : 0)
654 - int(vcolor.x * float(SCALE)),
655 (vcolor.y >= 0.5 ? SCALE : 0)
656 - int(vcolor.y * float(SCALE)),
657 0, 0);
660 [test]
661 ${bind_fb('GL_RGBA8I', samples)}
663 clear color 0 0 1 0
664 clear
665 ${barrier}
666 draw rect -1 -1 2 2
667 ${barrier}
668 draw rect -1 -1 2 2
670 ${resolve_fb('GL_RGBA8I', samples)}
672 relative probe rect rgba int (0.55, 0.0, 0.45, 0.45) (100, 0, 127, 100)
673 relative probe rect rgba int (0.0, 0.55, 0.45, 0.45) (0, 100, 127, 100)
674 relative probe rect rgba int (0.55, 0.55, 0.45, 0.45) (100, 100, 127, 100)
675 """, product(all_defs,
676 [{'name': 'integer-', 'api': 'gles3'}],
677 [{'name': 'ss', 'samples': 0, 'api_version': 3.0},
678 {'name': 'ms2', 'samples': 2, 'api_version': 3.1},
679 {'name': 'ms8', 'samples': 8, 'api_version': 3.1}]))
682 # Test framebuffer fetch functionality in combination with
683 # multiple render targets.
685 gen_execution("""\
686 [require]
687 GL ES >= ${api_version}
688 GLSL ES >= ${3.0 if api_version >= 3.0 else 1.0}
689 GL_${extension}
691 [vertex shader passthrough]
693 [fragment shader]
694 #version ${'300 es' if api_version >= 3.0 else '100'}
695 #extension GL_${extension} : enable
697 ${decl_frag_data(api_version, layout, 4)}
699 void main()
701 ${frag_data(api_version, 0)} = ${last_frag_data(api_version, 0)} +
702 vec4(0.5, 0.0, 0.0, 0.0);
703 ${frag_data(api_version, 1)} = ${last_frag_data(api_version, 1)} +
704 vec4(0.0, 0.5, 0.0, 0.0);
705 ${frag_data(api_version, 2)} = ${last_frag_data(api_version, 2)} +
706 vec4(0.5, 0.5, 0.0, 0.0);
707 ${frag_data(api_version, 3)} = ${last_frag_data(api_version, 3)} +
708 vec4(0.0, 0.0, 0.5, 0.0);
711 [test]
712 texture rgbw 0 (250, 250) GL_RGBA8
713 texture rgbw 1 (250, 250) GL_RGBA8
714 texture rgbw 2 (250, 250) GL_RGBA8
715 texture rgbw 3 (250, 250) GL_RGBA8
716 fb tex 2d 0 1 2 3
718 clear color 0.0 0.0 0.5 0.0
719 clear
720 ${barrier}
721 draw rect -1 -1 2 2
722 ${barrier}
723 draw rect -1 -1 2 2
725 fb tex 2d 0
726 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) (1.0, 0.0, 0.5)
728 fb tex 2d 1
729 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) (0.0, 1.0, 0.5)
731 fb tex 2d 2
732 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) (1.0, 1.0, 0.5)
734 fb tex 2d 3
735 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) (0.0, 0.0, 1.0)
737 ${display_fb(api_version)}
738 """, product(all_defs,
739 [{'name': 'mrt'}],
740 [{'api': 'gles2', 'api_version': 2.0},
741 {'api': 'gles3', 'api_version': 3.0}]))
744 # Test framebuffer fetch functionality with multiple assignments
745 # of the fragment color input-output.
747 gen_execution("""\
748 [require]
749 GL ES >= ${api_version}
750 GLSL ES >= 3.00
751 GL_${extension}
753 [vertex shader]
754 #version 300 es
756 in vec4 vertex;
757 out vec4 vcolor;
759 void main()
761 gl_Position = vertex;
762 // Transform the vertex coordinates so that the R and G
763 // components of the vertex color range between 0.0 and 1.0.
764 vcolor = vec4((1.0 + vertex.x) / 2.0,
765 (1.0 + vertex.y) / 2.0, 0.0, 1.0);
768 [fragment shader]
769 #version 300 es
770 #extension GL_${extension} : enable
772 in highp vec4 vcolor;
773 ${decl_frag_data(api_version, layout)}
775 void main()
777 // The conditional assignment will be executed for the top
778 // and right quadrants.
779 if (vcolor.x >= 0.5 || vcolor.y >= 0.5)
780 ${frag_data(api_version)} += vec4(0.5, 0, 0, 0);
782 ${frag_data(api_version)} += vec4(0.0, 0.5, 0, 0);
785 [test]
786 ${bind_fb('GL_RGBA8')}
788 clear color 0.0 0.0 1.0 0.0
789 clear
790 ${barrier}
791 draw rect -1 -1 2 2
792 ${barrier}
793 draw rect -1 -1 2 2
795 relative probe rect rgb (0.0, 0.0, 0.45, 0.45) (0.0, 1.0, 1.0)
796 relative probe rect rgb (0.55, 0.0, 0.45, 0.45) (1.0, 1.0, 1.0)
797 relative probe rect rgb (0.0, 0.55, 0.45, 0.45) (1.0, 1.0, 1.0)
798 relative probe rect rgb (0.55, 0.55, 0.45, 0.45) (1.0, 1.0, 1.0)
800 ${display_fb(api_version)}
801 """, product(all_defs,
802 [{'name': 'overwrite',
803 'api': 'gles3',
804 'api_version': 3.0}]))
807 # Test framebuffer fetch functionality on individual slices of a
808 # texture render target with multiple layers or mipmap levels.
810 gen_execution("""\
811 [require]
812 GL ES >= ${api_version}
813 GLSL ES >= 3.00
814 GL_${extension}
816 [vertex shader passthrough]
818 [fragment shader]
819 #version 300 es
820 #extension GL_${extension} : enable
822 ${decl_frag_data(api_version, layout)}
823 uniform highp vec4 ucolor;
825 void main()
827 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
828 ucolor;
831 [test]
832 %if target == 'Cube':
833 texture storage 0 ${target} GL_RGBA8 (${levels} 250 250)
834 %else:
835 texture storage 0 ${target} GL_RGBA8 (${levels} 250 250 ${layers})
836 %endif
838 <%! blend_colors = ['0.5 0.0 0.0 0.0',
839 '0.0 0.5 0.0 0.0',
840 '0.5 0.5 0.0 0.0',
841 '0.0 0.0 0.5 0.0'] %>
843 %for l in range(0, levels):
844 %for z in range(0, layers):
845 fb tex slice ${target} 0 ${l} ${z}
846 uniform vec4 ucolor ${blend_colors[(l + z) % 4]}
847 clear color 0.0 0.0 0.5 0.0
848 clear
849 ${barrier}
850 draw rect -1 -1 2 2
851 ${barrier}
852 draw rect -1 -1 2 2
854 %endfor
855 %endfor
857 <%! expected_colors = ['(1.0, 0.0, 0.5)',
858 '(0.0, 1.0, 0.5)',
859 '(1.0, 1.0, 0.5)',
860 '(0.0, 0.0, 1.0)'] %>
862 %for l in range(0, levels):
863 %for z in range(0, layers):
864 fb tex slice ${target} 0 ${l} ${z}
865 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) ${expected_colors[(l + z) % 4]}
867 %endfor
868 %endfor
870 ${display_fb(api_version)}
871 """, product(all_defs,
872 [{'name': 'single-slice-',
873 'api': 'gles3',
874 'api_version': 3.0}],
875 [{'name': '2darray', 'target': '2DArray',
876 'levels': 1, 'layers': 4},
877 {'name': '2darray-mipmap', 'target': '2DArray',
878 'levels': 4, 'layers': 1},
879 {'name': '3d', 'target': '3D',
880 'levels': 1, 'layers': 4},
881 {'name': 'cubemap', 'target': 'Cube',
882 'levels': 1, 'layers': 6}]))
885 # Test framebuffer fetch functionality on a 1D framebuffer.
887 gen_execution("""\
888 [require]
889 GL >= ${api_version}
890 GLSL >= 1.50
891 GL_ARB_texture_storage
892 GL_${extension}
894 [vertex shader]
895 #version 150
897 in vec4 vertex;
898 out vec4 vcolor;
900 void main()
902 gl_Position = vertex;
903 // Transform the vertex coordinates so that the R
904 // component of the vertex color ranges between 0.0 and 1.0.
905 vcolor = vec4((1.0 + vertex.x) / 2.0, 0.7, 0.0, 1.0);
908 [fragment shader]
909 #version 150
910 #extension GL_${extension} : enable
912 in vec4 vcolor;
913 ${decl_frag_data(api_version, layout)}
915 void main()
917 // The else branch will be executed during the second
918 // overdraw.
919 if (${last_frag_data(api_version)}.x <= 0.5 &&
920 ${last_frag_data(api_version)}.y <= 0.5) {
921 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
922 vcolor;
923 } else {
924 // Will give a solid color as result different for
925 // each half, assuming that the first branch was taken
926 // during the first pass.
927 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
928 vec4((vcolor.x >= 0.5 ? 1.0 : 0.0) - vcolor.x,
929 (vcolor.y >= 0.5 ? 1.0 : 0.0) - vcolor.y, 0, 0);
933 [test]
934 texture storage 0 1D GL_RGBA8 (1 250)
935 fb tex slice 1D 0 0 0
937 clear color 0.0 0.0 1.0 0.0
938 clear
939 ${barrier}
940 draw rect -1 -1 2 2
941 ${barrier}
942 draw rect -1 -1 2 2
944 relative probe rect rgb (0.0, 0.0, 0.45, 1.0) (0.0, 1.0, 1.0)
945 relative probe rect rgb (0.55, 0.0, 0.45, 1.0) (1.0, 1.0, 1.0)
947 fb draw winsys
948 blit color linear
949 """, product(all_defs,
950 [{'name': '1d',
951 'api': 'gl',
952 'api_version': 3.2}]))
955 # Test framebuffer fetch functionality while rendering into
956 # multiple layers of an array or cubemap framebuffer
957 # simultaneously.
959 gen_execution("""\
960 [require]
961 GL >= ${api_version}
962 GLSL >= 1.50
963 GL_ARB_texture_storage
964 GL_${extension}
966 [vertex shader passthrough]
967 [geometry shader]
968 #version 150
970 layout(triangles) in;
971 layout(triangle_strip, max_vertices=18) out;
973 flat out int glayer;
975 void main()
977 for (int layer = 0; layer < ${layers}; layer++) {
978 for (int i = 0; i < 3; i++) {
979 gl_Position = gl_in[i].gl_Position;
980 gl_Layer = glayer = layer;
981 EmitVertex();
983 EndPrimitive();
987 [fragment shader]
988 #version 150
989 #extension GL_${extension} : enable
991 flat in int glayer;
992 ${decl_frag_data(api_version, layout)}
994 void main()
996 ${frag_data(api_version)} = ${last_frag_data(api_version)} +
997 (glayer == 5 ? vec4(0.0, 0.5, 0.5, 0.0) :
998 glayer == 4 ? vec4(0.5, 0.0, 0.5, 0.0) :
999 glayer == 3 ? vec4(0.0, 0.0, 0.5, 0.0) :
1000 glayer == 2 ? vec4(0.5, 0.5, 0.0, 0.0) :
1001 glayer == 1 ? vec4(0.0, 0.5, 0.0, 0.0) :
1002 vec4(0.5, 0.0, 0.0, 0.0));
1005 [test]
1006 texture storage 0 ${target} GL_RGBA8 (${dimensions})
1007 fb tex layered 0
1009 clear color 0.0 0.0 0.5 0.0
1010 clear
1011 ${barrier}
1012 draw rect -1 -1 2 2
1013 ${barrier}
1014 draw rect -1 -1 2 2
1016 <%! expected_colors = ['(1.0, 0.0, 0.5)',
1017 '(0.0, 1.0, 0.5)',
1018 '(1.0, 1.0, 0.5)',
1019 '(0.0, 0.0, 1.0)',
1020 '(1.0, 0.0, 1.0)',
1021 '(0.0, 1.0, 1.0)'] %>
1023 %for z in range(0, layers):
1024 fb tex slice ${target} 0 0 ${z}
1025 relative probe rect rgb (0.0, 0.0, 1.0, 1.0) ${expected_colors[z]}
1026 %endfor
1028 fb draw winsys
1029 blit color linear
1030 """, product(all_defs,
1031 [{'name': 'layered-',
1032 'api': 'gl',
1033 'api_version': 3.2}],
1034 [{'name': '1darray', 'target': '1DArray',
1035 'dimensions': '1 250 4', 'layers': 4},
1036 {'name': '2darray', 'target': '2DArray',
1037 'dimensions': '1 250 250 4', 'layers': 4},
1038 {'name': 'cubemap', 'target': 'Cube',
1039 'dimensions': '1 250 250', 'layers': 6}]))
1041 if __name__ == '__main__':
1042 main()