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