ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_shader_image_load_store / image.h
blobd712f93370bb7a66ede5fe62eac3243814b70e64
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 /** @file image.h
26 * Common image format, target and shader stage metadata.
29 #ifndef __PIGLIT_ARB_SHADER_IMAGE_LOAD_STORE_IMAGE_H__
30 #define __PIGLIT_ARB_SHADER_IMAGE_LOAD_STORE_IMAGE_H__
32 #include "piglit-util-gl.h"
34 /**
35 * Image color value.
37 struct image_datum {
38 double x;
39 double y;
40 double z;
41 double w;
44 /**
45 * Size of an image.
47 * Note that most tests treat images as a 4-dimensional array of
48 * pixels with no specific semantics attached to each dimension
49 * (e.g. the x dimension will be the number of samples for multisample
50 * images but the horizontal coordinate for 2D textures). This is a
51 * deliberate decision that greatly reduces the amount of duplication,
52 * as in many cases you can just run the same test in a loop for all
53 * image targets.
55 * Unused dimensions equal 1 by convention.
57 struct image_extent {
58 unsigned x;
59 unsigned y;
60 unsigned z;
61 unsigned w;
64 #define get_idx(v, i) \
65 ((i) == 0 ? (v).x : \
66 (i) == 1 ? (v).y : \
67 (i) == 2 ? (v).z : \
68 (i) == 3 ? (v).w : 0)
70 #define set_idx(v, i, a) \
71 (*((i) == 0 ? &(v).x : \
72 (i) == 1 ? &(v).y : \
73 (i) == 2 ? &(v).z : \
74 (i) == 3 ? &(v).w : NULL)) = (a)
76 #define product(v) ((v).x * (v).y * (v).z * (v).w)
78 /**
79 * Get a two-dimensional image_extent with the same number of elements
80 * as the argument, where each dimension is reasonably close to the
81 * square root of the total number of elements, e.g. for use as grid
82 * invocation size.
84 struct image_extent
85 image_optimal_extent(struct image_extent ext);
87 struct image_format_info {
88 /** Format name as specified by GLSL. */
89 const char *name;
91 /** Format enum. */
92 GLenum format;
94 /** Pixel transfer format (e.g. as specified for glGetTexImage()). */
95 GLenum pixel_format;
97 /** Pixel transfer type (e.g. as specified for glGetTexImage()). */
98 GLenum pixel_type;
100 /** Number of storage bits for each component. */
101 unsigned bits[4];
105 * Image formats supported by image load and store built-ins.
107 extern const struct image_format_info image_formats_load_store[];
110 * Image formats supported by image atomic built-ins.
112 extern const struct image_format_info image_formats_atomic[];
115 * Get information for the specified image format.
117 const struct image_format_info *
118 get_image_format(GLenum format);
121 * Get the logical base format as seen by the shader (either GL_RGBA
122 * or GL_RGBA_INTEGER).
124 GLenum
125 image_base_format(const struct image_format_info *format);
128 * Get the logical component type as seen by the shader.
130 GLenum
131 image_base_type(const struct image_format_info *format);
134 * Get the logical internal format as seen by the shader.
136 GLenum
137 image_base_internal_format(const struct image_format_info *format);
140 * Get the GLSL component data type for an image format.
142 const char *
143 image_scalar_type_name(const struct image_format_info *format);
146 * Get the GLSL vector data type for an image format.
148 const char *
149 image_vector_type_name(const struct image_format_info *format);
152 * Get the GLSL image type prefix for an image format ("i", "u" or
153 * "").
155 const char *
156 image_type_name(const struct image_format_info *format);
159 * Get the size in bits of one pixel in the specified format.
161 unsigned int
162 image_pixel_size(const struct image_format_info *format);
165 * Get a compatible unsigned integer format of the same size.
167 GLenum
168 image_compat_format(const struct image_format_info *format);
171 * Get the number of color components representable in an image format.
173 unsigned
174 image_num_components(const struct image_format_info *format);
177 * Get an arbitrary per-component test scale used to make sure that we
178 * exercise a significant portion of the representable range without
179 * overflowing it.
181 struct image_datum
182 image_format_scale(const struct image_format_info *format);
185 * Get the per-component error tolerance for an image format.
187 struct image_datum
188 image_format_epsilon(const struct image_format_info *format);
191 * Convert \a x to the base data type of the specified image format.
193 uint32_t
194 encode(const struct image_format_info *format, double x);
197 * Convert \a x from the base data type of the specified image format.
199 double
200 decode(const struct image_format_info *format, uint32_t x);
202 struct image_target_info {
203 /** Target name and GLSL image type suffix. */
204 const char *name;
206 /** Target enum. */
207 GLenum target;
209 /** Vector type used as address argument for this target. */
210 const char *addr_type_name;
214 * Get all image targets supported by the implementation.
216 const struct image_target_info *
217 image_targets(void);
220 * Get information for the specified target.
222 const struct image_target_info *
223 get_image_target(GLenum t);
226 * Get the maximum supported dimensions for the specified target.
228 struct image_extent
229 image_target_limits(const struct image_target_info *target);
232 * Get the maximum supported number of samples for the specified
233 * target.
235 unsigned
236 image_target_samples(const struct image_target_info *target);
239 * Get reasonable dimensions for an image of type \a target intended
240 * to be in one-to-one mapping to a two-dimensional grid of dimensions
241 * \a w and \a h.
243 struct image_extent
244 image_extent_for_target(const struct image_target_info *target,
245 unsigned w, unsigned h);
248 * Get the target type for a single layer of the specified image
249 * target.
251 GLenum
252 image_layer_target(const struct image_target_info *target);
255 * Get the number of dimensions of an image target that are minified
256 * in higher mipmap levels.
258 unsigned
259 image_target_mipmapping_dimensions(const struct image_target_info *target);
261 struct image_stage_info {
262 /** Shader stage name. */
263 const char *name;
265 /** Target enum. */
266 GLenum stage;
268 /** Value used in bit sets for this shader stage. */
269 GLbitfield bit;
273 * Get all shader stages in pipeline order regardless of whether they
274 * support image access.
276 const struct image_stage_info *
277 known_image_stages(void);
280 * Get all shader stages that support image access in pipeline order.
282 const struct image_stage_info *
283 image_stages(void);
286 * Get information for the specified stage, or NULL if the specified
287 * stage doesn't support images.
289 const struct image_stage_info *
290 get_image_stage(GLenum s);
293 * Get the maximum number of supported image uniforms from the
294 * specified stage.
296 unsigned
297 image_stage_max_images(const struct image_stage_info *stage);
300 * Get the maximum sum of image uniforms from all shaders.
302 unsigned
303 max_combined_images(void);
306 * Get the maximum number of independent image units.
308 unsigned
309 max_image_units(void);
311 struct image_info {
312 /** Texture target of this image object. */
313 const struct image_target_info *target;
315 /** Format of this image object. */
316 const struct image_format_info *format;
318 /** Dimensions of this image object. */
319 struct image_extent size;
321 /** Error tolerance for this image object. */
322 struct image_datum epsilon;
326 * Construct an image_info object.
328 static inline struct image_info
329 image_info(GLenum target, GLenum format, unsigned w, unsigned h)
331 const struct image_target_info *t = get_image_target(target);
332 const struct image_format_info *f = get_image_format(format);
333 const struct image_info img = {
334 t, f,
335 image_extent_for_target(t, w, h),
336 image_format_epsilon(f)
339 return img;
343 * Set the dimensions of an image.
345 static inline struct image_info
346 set_image_size(struct image_info img,
347 unsigned x, unsigned y, unsigned z, unsigned w)
349 const struct image_extent size = { x, y, z, w };
350 img.size = size;
351 return img;
355 * Get the number of layers of an image.
357 unsigned
358 image_num_layers(const struct image_info img);
361 * Get the maximum number of mipmap levels for an image.
363 unsigned
364 image_num_levels(const struct image_info img);
367 * Get the dimensions of the specified mipmap level of an image.
369 struct image_extent
370 image_level_size(const struct image_info img, unsigned l);
373 * Get the offset in texels of the specified mipmap level of an
374 * image.
376 static inline unsigned
377 image_level_offset(const struct image_info img, unsigned l)
379 return (l == 0 ? 0 :
380 image_level_offset(img, l - 1) +
381 product(image_level_size(img, l - 1)));
385 * Construct an image_info object for mipmap level \a l of the
386 * specified base image.
388 static inline struct image_info
389 image_info_for_level(struct image_info img, unsigned l)
391 const struct image_info level_img = {
392 img.target, img.format,
393 image_level_size(img, l),
394 img.epsilon
397 return level_img;
400 #endif