2 * Copyright (C) 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 /** @file copy-image-formats.c
26 * A simple test verifying we can make use of the additional OpenGL ES 3.1
27 * image formats provided by the GL_NV_image_formats extension. The
28 * normalized 16 bits format provided by this extension are subject to the
29 * condition that GL_EXT_texture_norm16 or equivalent is available.
32 #include "piglit-util-gl.h"
34 const struct image_format
{
35 /** Format name as specified by GLSL. */
41 /** Pixel transfer format (e.g. as specified for glGetTexImage()). */
44 /** Pixel transfer type (e.g. as specified for glGetTexImage()). */
47 { "rg32f", GL_RG32F
, GL_RG
, GL_FLOAT
},
48 { "rg16f", GL_RG16F
, GL_RG
, GL_HALF_FLOAT
},
49 { "r11f_g11f_b10f", GL_R11F_G11F_B10F
, GL_RGB
, GL_UNSIGNED_INT_10F_11F_11F_REV
},
50 { "r16f", GL_R16F
, GL_RED
, GL_HALF_FLOAT
},
51 { "rgb10_a2ui", GL_RGB10_A2UI
, GL_RGBA_INTEGER
, GL_UNSIGNED_INT_2_10_10_10_REV
},
52 { "rg32ui", GL_RG32UI
, GL_RG_INTEGER
, GL_UNSIGNED_INT
},
53 { "rg16ui", GL_RG16UI
, GL_RG_INTEGER
, GL_UNSIGNED_SHORT
},
54 { "rg8ui", GL_RG8UI
, GL_RG_INTEGER
, GL_UNSIGNED_BYTE
},
55 { "r16ui", GL_R16UI
, GL_RED_INTEGER
, GL_UNSIGNED_SHORT
},
56 { "r8ui", GL_R8UI
, GL_RED_INTEGER
, GL_UNSIGNED_BYTE
},
57 { "rg32i", GL_RG32I
, GL_RG_INTEGER
, GL_INT
},
58 { "rg16i", GL_RG16I
, GL_RG_INTEGER
, GL_SHORT
},
59 { "rg8i", GL_RG8I
, GL_RG_INTEGER
, GL_BYTE
},
60 { "r16i", GL_R16I
, GL_RED_INTEGER
, GL_SHORT
},
61 { "r8i", GL_R8I
, GL_RED_INTEGER
, GL_BYTE
},
62 { "rgba16", GL_RGBA16
, GL_RGBA
, GL_UNSIGNED_SHORT
},
63 { "rgb10_a2", GL_RGB10_A2
, GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
},
64 { "rg16", GL_RG16
, GL_RG
, GL_UNSIGNED_SHORT
},
65 { "rg8", GL_RG8
, GL_RG
, GL_UNSIGNED_BYTE
},
66 { "r16", GL_R16
, GL_RED
, GL_UNSIGNED_SHORT
},
67 { "r8", GL_R8
, GL_RED
, GL_UNSIGNED_BYTE
},
68 { "rgba16_snorm", GL_RGBA16_SNORM
, GL_RGBA
, GL_SHORT
},
69 { "rg16_snorm", GL_RG16_SNORM
, GL_RG
, GL_SHORT
},
70 { "rg8_snorm", GL_RG8_SNORM
, GL_RG
, GL_BYTE
},
71 { "r16_snorm", GL_R16_SNORM
, GL_RED
, GL_SHORT
},
72 { "r8_snorm", GL_R8_SNORM
, GL_RED
, GL_BYTE
},
75 static struct piglit_subtest tests
[ARRAY_SIZE(image_formats
) + 1];
76 static struct piglit_gl_test_config
* piglit_config
;
77 static enum piglit_result
run_test(void *);
79 PIGLIT_GL_TEST_CONFIG_BEGIN
81 piglit_config
= &config
;
83 for (unsigned i
= 0; i
< ARRAY_SIZE(image_formats
); ++i
) {
86 asprintf(name
, "copy-%s", image_formats
[i
].name
);
87 tests
[i
].name
= *name
;
88 tests
[i
].option
= image_formats
[i
].name
;
89 tests
[i
].subtest_func
= run_test
;
90 tests
[i
].data
= (void *)&image_formats
[i
];
92 config
.subtests
= tests
;
94 config
.supports_gl_es_version
= 31;
96 PIGLIT_GL_TEST_CONFIG_END
102 glsl_image_type_name(GLenum format
)
107 case GL_R11F_G11F_B10F
:
119 case GL_RGBA16_SNORM_EXT
:
120 case GL_RG16_SNORM_EXT
:
122 case GL_R16_SNORM_EXT
:
142 assert("Unsupported format");
148 glsl_type_name(GLenum format
)
153 case GL_R11F_G11F_B10F
:
165 case GL_RGBA16_SNORM_EXT
:
166 case GL_RG16_SNORM_EXT
:
168 case GL_R16_SNORM_EXT
:
178 return "highp uvec4";
185 return "highp ivec4";
188 assert("Unsupported format");
194 format_is_norm16(GLenum format
)
200 case GL_RGBA16_SNORM_EXT
:
201 case GL_RG16_SNORM_EXT
:
202 case GL_R16_SNORM_EXT
:
210 static enum piglit_result
211 run_test(void * data
)
213 struct image_format
* image_format
= (struct image_format
*)data
;
214 GLuint src
, dst
, prog
;
217 glGenTextures(1, &src
);
218 glBindTexture(GL_TEXTURE_2D
, src
);
219 glTexStorage2D(GL_TEXTURE_2D
, 1, image_format
->format
, WIDTH
, HEIGHT
);
220 glBindImageTexture(0, src
, 0, GL_FALSE
, 0,
221 GL_READ_ONLY
, image_format
->format
);
223 if (format_is_norm16(image_format
->format
)) {
224 if (!piglit_is_extension_supported("GL_EXT_texture_norm16")) {
225 piglit_check_gl_error(GL_INVALID_VALUE
);
229 piglit_check_gl_error(GL_NO_ERROR
);
231 glGenTextures(1, &dst
);
232 glBindTexture(GL_TEXTURE_2D
, dst
);
233 glTexStorage2D(GL_TEXTURE_2D
, 1, image_format
->format
, WIDTH
, HEIGHT
);
234 glBindImageTexture(0, dst
, 0, GL_FALSE
, 0,
235 GL_WRITE_ONLY
, image_format
->format
);
236 piglit_check_gl_error(GL_NO_ERROR
);
239 if (asprintf(&fs_source
,
241 "#extension GL_NV_image_formats : require\n"
243 "layout(%s) readonly uniform highp %s2D img_src;\n"
244 "layout(%s) writeonly uniform highp %s2D img_dst;\n"
247 " %s v = imageLoad(img_src, ivec2(gl_FragCoord));\n"
248 " imageStore(img_dst, ivec2(gl_FragCoord), v);\n"
251 glsl_image_type_name(image_format
->format
),
253 glsl_image_type_name(image_format
->format
),
254 glsl_type_name(image_format
->format
)) < 0)
257 prog
= piglit_build_simple_program(
260 "in vec4 piglit_vertex;\n"
262 " gl_Position = piglit_vertex;\n"
269 piglit_draw_rect(-1, -1, 1, 1);
275 piglit_init(int argc
, char **argv
)
277 enum piglit_result status
= PIGLIT_PASS
;
279 piglit_require_extension("GL_NV_image_formats");
281 status
= piglit_run_selected_subtests(
283 piglit_config
->selected_subtests
,
284 piglit_config
->num_selected_subtests
,
287 piglit_report_result(status
);