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 * 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"
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
55 * Unused dimensions equal 1 by convention.
64 #define get_idx(v, i) \
70 #define set_idx(v, i, a) \
71 (*((i) == 0 ? &(v).x : \
74 (i) == 3 ? &(v).w : NULL)) = (a)
76 #define product(v) ((v).x * (v).y * (v).z * (v).w)
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
85 image_optimal_extent(struct image_extent ext
);
87 struct image_format_info
{
88 /** Format name as specified by GLSL. */
94 /** Pixel transfer format (e.g. as specified for glGetTexImage()). */
97 /** Pixel transfer type (e.g. as specified for glGetTexImage()). */
100 /** Number of storage bits for each component. */
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).
125 image_base_format(const struct image_format_info
*format
);
128 * Get the logical component type as seen by the shader.
131 image_base_type(const struct image_format_info
*format
);
134 * Get the logical internal format as seen by the shader.
137 image_base_internal_format(const struct image_format_info
*format
);
140 * Get the GLSL component data type for an image format.
143 image_scalar_type_name(const struct image_format_info
*format
);
146 * Get the GLSL vector data type for an image format.
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
156 image_type_name(const struct image_format_info
*format
);
159 * Get the size in bits of one pixel in the specified format.
162 image_pixel_size(const struct image_format_info
*format
);
165 * Get a compatible unsigned integer format of the same size.
168 image_compat_format(const struct image_format_info
*format
);
171 * Get the number of color components representable in an image format.
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
182 image_format_scale(const struct image_format_info
*format
);
185 * Get the per-component error tolerance for an image format.
188 image_format_epsilon(const struct image_format_info
*format
);
191 * Convert \a x to the base data type of the specified image format.
194 encode(const struct image_format_info
*format
, double x
);
197 * Convert \a x from the base data type of the specified image format.
200 decode(const struct image_format_info
*format
, uint32_t x
);
202 struct image_target_info
{
203 /** Target name and GLSL image type suffix. */
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
*
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.
229 image_target_limits(const struct image_target_info
*target
);
232 * Get the maximum supported number of samples for the specified
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
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
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.
259 image_target_mipmapping_dimensions(const struct image_target_info
*target
);
261 struct image_stage_info
{
262 /** Shader stage name. */
268 /** Value used in bit sets for this shader stage. */
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
*
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
297 image_stage_max_images(const struct image_stage_info
*stage
);
300 * Get the maximum sum of image uniforms from all shaders.
303 max_combined_images(void);
306 * Get the maximum number of independent image units.
309 max_image_units(void);
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
= {
335 image_extent_for_target(t
, w
, h
),
336 image_format_epsilon(f
)
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
};
355 * Get the number of layers of an image.
358 image_num_layers(const struct image_info img
);
361 * Get the maximum number of mipmap levels for an image.
364 image_num_levels(const struct image_info img
);
367 * Get the dimensions of the specified mipmap level of an image.
370 image_level_size(const struct image_info img
, unsigned l
);
373 * Get the offset in texels of the specified mipmap level of an
376 static inline unsigned
377 image_level_offset(const struct image_info img
, unsigned l
)
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
),