2 * Copyright (C) 2014 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
26 * Test that the reinterpretation of the binary contents of an image
27 * as a different compatible format yields predictable results as
28 * specified by the extension.
39 /** Total number of pixels in the window and image. */
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config
.supports_gl_core_version
= 32;
46 config
.window_width
= W
;
47 config
.window_height
= H
;
48 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
49 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
51 PIGLIT_GL_TEST_CONFIG_END
54 init_image(const struct image_info img
,
55 const struct image_format_info
*dst_format
)
57 const unsigned m
= image_num_components(img
.format
);
58 uint32_t pixels
[4 * N
];
61 for (i
= 0; i
< m
* N
; ++i
)
62 pixels
[i
] = encode(img
.format
,
63 get_idx(image_format_scale(img
.format
), i
% m
)
66 if (!upload_image(img
, 0, pixels
))
69 glBindImageTexture(0, get_texture(0), 0, GL_TRUE
, 0,
70 GL_READ_ONLY
, dst_format
->format
);
72 return piglit_check_gl_error(GL_NO_ERROR
);
76 check(const struct grid_info grid
, const struct image_info src_img
,
77 const struct image_info dst_img
)
79 uint32_t pixels_fb
[4 * N
];
80 uint32_t pixels_img
[4 * N
];
82 if (!download_result(grid
, pixels_fb
))
86 * According to the spec, the reinterpretation of the texture
87 * data performed by image loads is equivalent to:
89 * "reading the texel from the source format to scratch
90 * memory according to the process described for GetTexImage
91 * (section 6.1.4), using default pixel storage modes and
92 * <format> and <type> parameters corresponding to the source
93 * format in Table X.3; and [...]
95 glBindTexture(src_img
.target
->target
, get_texture(0));
96 glGetTexImage(src_img
.target
->target
, 0, src_img
.format
->pixel_format
,
97 src_img
.format
->pixel_type
, pixels_img
);
100 * [...] writing the texel from scratch memory to the destination
101 * format according to the process described for
102 * TexSubImage3D (section 3.9.2), using default pixel storage
103 * modes and <format> and <type> parameters corresponding to
104 * the destination format in Table X.3."
106 glTexImage2D(dst_img
.target
->target
, 0, dst_img
.format
->format
,
107 W
, H
, 0, dst_img
.format
->pixel_format
,
108 dst_img
.format
->pixel_type
, pixels_img
);
109 glGetTexImage(dst_img
.target
->target
, 0, grid
.format
->pixel_format
,
110 image_base_type(grid
.format
), pixels_img
);
112 return piglit_check_gl_error(GL_NO_ERROR
) &&
113 check_pixels_v(dst_img
, pixels_fb
, pixels_img
);
117 run_test(const struct image_format_info
*src_format
,
118 const struct image_format_info
*dst_format
)
120 const struct grid_info grid
=
121 grid_info(GL_FRAGMENT_SHADER
,
122 image_base_internal_format(dst_format
), W
, H
);
123 const struct image_info src_img
=
124 image_info(GL_TEXTURE_2D
, src_format
->format
, W
, H
);
125 const struct image_info dst_img
=
126 image_info(GL_TEXTURE_2D
, dst_format
->format
, W
, H
);
127 GLuint prog
= generate_program(
128 grid
, GL_FRAGMENT_SHADER
,
129 concat(image_hunk(dst_img
, ""),
130 hunk("IMAGE_UNIFORM_T img;\n"
132 "GRID_T op(ivec2 idx, GRID_T x) {\n"
133 " return imageLoad(img, IMAGE_ADDR(idx));\n"
135 bool ret
= prog
&& init_fb(grid
) &&
136 init_image(src_img
, dst_format
) &&
137 set_uniform_int(prog
, "img", 0) &&
138 draw_grid(grid
, prog
) &&
139 check(grid
, src_img
, dst_img
);
141 glDeleteProgram(prog
);
146 piglit_init(int argc
, char **argv
)
148 const struct image_format_info
*src_format
, *dst_format
;
149 enum piglit_result status
= PIGLIT_PASS
;
151 piglit_require_extension("GL_ARB_shader_image_load_store");
153 for (src_format
= image_formats_load_store
;
154 src_format
->name
; ++src_format
) {
155 for (dst_format
= image_formats_load_store
;
156 dst_format
->name
; ++dst_format
) {
157 if (dst_format
!= src_format
&&
158 image_compat_format(dst_format
) ==
159 image_compat_format(src_format
)) {
160 subtest(&status
, true,
161 run_test(src_format
, dst_format
),
162 "%s to %s bitcast test",
163 src_format
->name
, dst_format
->name
);
168 piglit_report_result(status
);