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 * Utility code for running a grid of shader invocations abstracting
27 * out the details of the specific shader stage it's run on.
30 #ifndef __PIGLIT_ARB_SHADER_IMAGE_LOAD_STORE_GRID_H__
31 #define __PIGLIT_ARB_SHADER_IMAGE_LOAD_STORE_GRID_H__
36 /** Bitfield of shader stages present in the pipeline
37 * (GL_*_SHADER_BIT). */
40 /** Data type used to hold the values that are passed down
41 * through the pipeline. */
42 const struct image_format_info
*format
;
44 /** Size of the two-dimensional grid. */
45 struct image_extent size
;
49 * Construct a grid_info object.
51 static inline struct grid_info
52 grid_info(GLenum stage
, GLenum format
, unsigned w
, unsigned h
)
54 const struct grid_info grid
= {
55 get_image_stage(stage
)->bit
,
56 get_image_format(format
),
63 static inline struct grid_info
64 set_grid_size(struct grid_info grid
, unsigned x
, unsigned y
)
66 const struct image_extent size
= { x
, y
, 1, 1 };
72 * Construct an image_info structure with the same dimensions and
73 * format as the specified grid.
75 static inline struct image_info
76 image_info_for_grid(const struct grid_info grid
)
78 const struct image_info img
= {
79 get_image_target(GL_TEXTURE_2D
),
80 grid
.format
, grid
.size
,
81 image_format_epsilon(grid
.format
)
88 * Concatenate a variable number of strings into a newly allocated
89 * buffer. Note that concat() assumes ownership of the provided
90 * arguments and that the argument list must be NULL-terminated.
93 concat(char *hunk0
, ...);
102 * Generate preprocessor defines containing geometry and data type
103 * information for a shader image object.
106 image_hunk(const struct image_info img
, const char *prefix
);
109 * Generate a shader program containing all the required stages to run
110 * the provided shader source from \a grid. A series of (GLenum, char *)
111 * pairs should follow as variadic arguments, where the GLenum
112 * argument specifies an additional shader stage (GL_*_SHADER) and the
113 * string specifies a fragment of GLSL code to be included in the same
114 * shader stage. Note that generate_program() takes ownership of the
115 * provided argument strings.
117 * Each fragment should define a GLSL function with prototype
118 * "GRID_T op(ivec2 idx, GRID_T x)", where \a idx is the
119 * two-dimensional coordinate of a particular shader invocation within
120 * the grid and \a x is the result of the last invocation of op() from
121 * a previous shader stage at the same grid coordinate. Zero is
122 * passed as argument to the topmost invocation of op() in the chain.
124 * The final result from the chain of op() calls is written as
125 * fragment color to the framebuffer, or written to the read-back
126 * buffer when running a compute shader.
128 * The generated program will typically be passed as argument to
129 * draw_grid() in order to launch the grid.
132 generate_program(const struct grid_info grid
, ...);
135 * Launch a grid of shader invocations of the specified size.
136 * Depending on the specified shader stages an array of triangles,
137 * points or patches will be drawn or a compute grid will be
141 draw_grid(const struct grid_info grid
, GLuint prog
);
144 * Generate vertex arrays intended to be used to launch a grid of
145 * shader invocations using the specified origin (\a x, \a y), spacing
146 * (\a dx, \a dy) and dimensions (\a nx, \a ny). This is done
147 * internally by draw_grid(), but it could be useful on its own for
148 * applications that require more control.
151 generate_grid_arrays(GLuint
*vao
, GLuint
*vbo
,
152 float x
, float y
, float dx
, float dy
,
153 unsigned nx
, unsigned ny
);