summaryrefslogtreecommitdiff
path: root/generated_tests/gen_shader_image_nv_image_formats_tests.py
blob: e8826defbedd48a48ca92075c00939bbab6a1a3f (plain)
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
# coding=utf-8
#
# Copyright (C) 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.

"""Generate a set of tests to verify that formats added by the
 NV_image_formats extension for GLES 3.1 are properly accepted by the GLSL
 compiler.

 This also verifies that 16bits normalized formats are not accepted unless
 EXT_texture_norm16 is available.

 This program outputs, to stdout, the name of each file it generates.
"""

import os.path
from textwrap import dedent

from mako.template import Template

from modules import utils

def gen_header(status, norm16):
    """
    Generate a GLSL program header.

    Generate header code for ARB_shader_image_load_store GLSL parser
    tests that are expected to give status as result.
    """

    if norm16:
        norm16_require = "GL_EXT_texture_norm16"
    else:
        norm16_require = "!GL_EXT_texture_norm16"

    return dedent("""
        /*
         * [config]
         * expect_result: {0}
         * glsl_version: 3.10 es
         * require_extensions: GL_NV_image_formats {1}
         * [end config]
         */
        #version 310 es
        #extension GL_NV_image_formats : require
    """.format(status, norm16_require))


def gen(name, src, tests):
    """
    Expand a source template for the provided list of test definitions.

    Generate a GLSL parser test for each of the elements 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 file name of each test will be the concatenation of the 'name'
    argument with the 'name' item from the respective test dictionary.
    """
    template = Template(dedent(src))

    for t in product([{'name': name}], tests):
        filename = os.path.join('spec',
                                'nv_image_formats',
                                'compiler',
                                '{0}.{1}'.format(t['name'],
                                                 t['shader_stage']))
        print(filename)

        dirname = os.path.dirname(filename)
        utils.safe_makedirs(dirname)

        with open(filename, 'w') as f:
            f.write(template.render(header=gen_header, **t))


shader_stages = [
    {'shader_stage': 'frag'},
    {'shader_stage': 'vert'}
]


image_types = [
    {
        'name': '2d',
        'image_type': 'image2D',
    },
    {
        'name': '3d',
        'image_type': 'image3D',
    },
    {
        'name': '2d-array',
        'image_type': 'image2DArray',
    },
    {
        'name': 'cube',
        'image_type': 'imageCube',
    }
]


def product(ps, *qss):
    """
    Generate the cartesian product of a number of lists of dictionaries.

    Each generated element will be the union of some combination of
    elements from the iterable arguments.  The resulting value of each
    'name' item will be the concatenation of names of the respective
    element combination separated with dashes.
    """
    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 main():
    """Main function."""


    #
    # Test image formats accepted with NV_image_formats &
    # EXT_texture_norm16.
    #
    gen('declarations-with-norm16', """
        ${header('pass', True)}

        layout(rg32f) readonly uniform highp ${image_type} img_rg32f;
        layout(rg16f) readonly uniform highp ${image_type} img_rg16f;
        layout(r16f) readonly uniform highp ${image_type} img_r16f;
        layout(r11f_g11f_b10f) readonly uniform highp ${image_type} img_r11g11b10f;

        layout(rgba16) readonly uniform highp ${image_type} img_rgba16_unorm;
        layout(rgb10_a2) readonly uniform highp ${image_type} img_rgb10_a2_unorm;
        layout(rg16) readonly uniform highp ${image_type} img_rg16_unorm;
        layout(rg8) readonly uniform highp ${image_type} img_rg8_unorm;
        layout(r16) readonly uniform highp ${image_type} img_r16_unorm;
        layout(r8) readonly uniform highp ${image_type} img_r8_unorm;

        layout(rgba16_snorm) readonly uniform highp ${image_type} img_rgba16_snorm;
        layout(rg16_snorm) readonly uniform highp ${image_type} img_rg16_snorm;
        layout(rg8_snorm) readonly uniform highp ${image_type} img_rg8_snorm;
        layout(r16_snorm) readonly uniform highp ${image_type} img_r16_snorm;
        layout(r8_snorm) readonly uniform highp ${image_type} img_r8_snorm;

        layout(rgb10_a2ui) readonly uniform highp u${image_type} img_rgb10_a2ui;
        layout(rg32ui) readonly uniform highp u${image_type} img_rg32ui;
        layout(rg16ui) readonly uniform highp u${image_type} img_rg16ui;
        layout(rg8ui) readonly uniform highp u${image_type} img_rg8ui;
        layout(r16ui) readonly uniform highp u${image_type} img_r16ui;
        layout(r8ui) readonly uniform highp u${image_type} img_r8ui;

        layout(rg32i) readonly uniform highp i${image_type} img_rg32i;
        layout(rg16i) readonly uniform highp i${image_type} img_rg16i;
        layout(rg8i) readonly uniform highp i${image_type} img_rg8i;
        layout(r16i) readonly uniform highp i${image_type} img_r16i;
        layout(r8i) readonly uniform highp i${image_type} img_r8i;

        void main()
        {
        }
    """, product(image_types, shader_stages))


    #
    # Test image formats accepted with only NV_image_formats.
    #
    gen('declarations-without-norm16', """
        ${header('pass', False)}

        layout(rg32f) readonly uniform highp ${image_type} img_rg32f;
        layout(rg16f) readonly uniform highp ${image_type} img_rg16f;
        layout(r16f) readonly uniform highp ${image_type} img_r16f;
        layout(r11f_g11f_b10f) readonly uniform highp ${image_type} img_r11g11b10f;

        layout(rgb10_a2) readonly uniform highp ${image_type} img_rgb10_a2_unorm;
        layout(rg8) readonly uniform highp ${image_type} img_rg8_unorm;
        layout(r8) readonly uniform highp ${image_type} img_r8_unorm;

        layout(rg8_snorm) readonly uniform highp ${image_type} img_rg8_snorm;
        layout(r8_snorm) readonly uniform highp ${image_type} img_r8_snorm;

        layout(rgb10_a2ui) readonly uniform highp u${image_type} img_rgb10_a2ui;
        layout(rg32ui) readonly uniform highp u${image_type} img_rg32ui;
        layout(rg16ui) readonly uniform highp u${image_type} img_rg16ui;
        layout(rg8ui) readonly uniform highp u${image_type} img_rg8ui;
        layout(r16ui) readonly uniform highp u${image_type} img_r16ui;
        layout(r8ui) readonly uniform highp u${image_type} img_r8ui;

        layout(rg32i) readonly uniform highp i${image_type} img_rg32i;
        layout(rg16i) readonly uniform highp i${image_type} img_rg16i;
        layout(rg8i) readonly uniform highp i${image_type} img_rg8i;
        layout(r16i) readonly uniform highp i${image_type} img_r16i;
        layout(r8i) readonly uniform highp i${image_type} img_r8i;

        void main()
        {
        }
    """, product(image_types, shader_stages))


    #
    # Test image formats forbidden without EXT_texture_norm16.
    #
    gen('declaration-disallow-rgba16-unorm', """
        ${header('fail', False)}

        layout(rgba16) readonly uniform highp ${image_type} img_rgba16;

        void main()
        {
        }
    """, product(image_types, shader_stages))


    gen('declaration-disallow-rg16-unorm', """
        ${header('fail', False)}

        layout(rg16) readonly uniform highp ${image_type} img_rg16;

        void main()
        {
        }
    """, product(image_types, shader_stages))


    gen('declaration-disallow-r16-unorm', """
        ${header('fail', False)}

        layout(r16) readonly uniform highp ${image_type} img_r16;

        void main()
        {
        }
    """, product(image_types, shader_stages))


    gen('declaration-disallow-rgba16-snorm', """
        ${header('fail', False)}

        layout(rgba16_snorm) readonly uniform highp ${image_type} img_rgba16_snorm;

        void main()
        {
        }
    """, product(image_types, shader_stages))


    gen('declaration-disallow-rg16-snorm', """
        ${header('fail', False)}

        layout(rg16_snorm) readonly uniform highp ${image_type} img_rg16_snorm;

        void main()
        {
        }
    """, product(image_types, shader_stages))


    gen('declaration-disallow-r16-snorm', """
        ${header('fail', False)}

        layout(r16_snorm) readonly uniform highp ${image_type} img_r16_snorm;

        void main()
        {
        }
    """, product(image_types, shader_stages))

if __name__ == '__main__':
    main()