Merge remote-tracking branch 'public/master' into vulkan
[mesa.git] / src / gallium / auxiliary / draw / draw_context.h
1
2 /**************************************************************************
3 *
4 * Copyright 2007 VMware, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 /**
30 * \brief Public interface into the drawing module.
31 */
32
33 /* Authors: Keith Whitwell <keithw@vmware.com>
34 */
35
36
37 #ifndef DRAW_CONTEXT_H
38 #define DRAW_CONTEXT_H
39
40
41 #include "pipe/p_state.h"
42 #include "tgsi/tgsi_exec.h"
43
44 struct pipe_context;
45 struct draw_context;
46 struct draw_stage;
47 struct draw_vertex_shader;
48 struct draw_geometry_shader;
49 struct draw_fragment_shader;
50 struct tgsi_sampler;
51 struct tgsi_image;
52 struct tgsi_buffer;
53
54 /*
55 * structure to contain driver internal information
56 * for stream out support. mapping stores the pointer
57 * to the buffer contents, and internal offset stores
58 * an internal counter to how much of the stream
59 * out buffer is used (in bytes).
60 */
61 struct draw_so_target {
62 struct pipe_stream_output_target target;
63 void *mapping;
64 int internal_offset;
65 };
66
67 struct draw_context *draw_create( struct pipe_context *pipe );
68
69 #if HAVE_LLVM
70 struct draw_context *draw_create_with_llvm_context(struct pipe_context *pipe,
71 void *context);
72 #endif
73
74 struct draw_context *draw_create_no_llvm(struct pipe_context *pipe);
75
76 void draw_destroy( struct draw_context *draw );
77
78 void draw_flush(struct draw_context *draw);
79
80 void draw_set_viewport_states( struct draw_context *draw,
81 unsigned start_slot,
82 unsigned num_viewports,
83 const struct pipe_viewport_state *viewports );
84
85 void draw_set_clip_state( struct draw_context *pipe,
86 const struct pipe_clip_state *clip );
87
88 /**
89 * Sets the rasterization state used by the draw module.
90 * The rast_handle is used to pass the driver specific representation
91 * of the rasterization state. It's going to be used when the
92 * draw module sets the state back on the driver itself using the
93 * pipe::bind_rasterizer_state method.
94 *
95 * NOTE: if you're calling this function from within the pipe's
96 * bind_rasterizer_state you should always call it before binding
97 * the actual state - that's because the draw module can try to
98 * bind its own rasterizer state which would reset your newly
99 * set state. i.e. always do
100 * draw_set_rasterizer_state(driver->draw, state->pipe_state, state);
101 * driver->state.raster = state;
102 */
103 void draw_set_rasterizer_state( struct draw_context *draw,
104 const struct pipe_rasterizer_state *raster,
105 void *rast_handle );
106
107 void draw_set_rasterize_stage( struct draw_context *draw,
108 struct draw_stage *stage );
109
110 void draw_wide_point_threshold(struct draw_context *draw, float threshold);
111
112 void draw_wide_point_sprites(struct draw_context *draw, boolean draw_sprite);
113
114 void draw_wide_line_threshold(struct draw_context *draw, float threshold);
115
116 void draw_enable_line_stipple(struct draw_context *draw, boolean enable);
117
118 void draw_enable_point_sprites(struct draw_context *draw, boolean enable);
119
120 void draw_set_zs_format(struct draw_context *draw, enum pipe_format format);
121
122 boolean
123 draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe);
124
125 boolean
126 draw_install_aapoint_stage(struct draw_context *draw, struct pipe_context *pipe);
127
128 boolean
129 draw_install_pstipple_stage(struct draw_context *draw, struct pipe_context *pipe);
130
131
132 struct tgsi_shader_info *
133 draw_get_shader_info(const struct draw_context *draw);
134
135 void
136 draw_prepare_shader_outputs(struct draw_context *draw);
137
138 int
139 draw_find_shader_output(const struct draw_context *draw,
140 uint semantic_name, uint semantic_index);
141
142 boolean
143 draw_will_inject_frontface(const struct draw_context *draw);
144
145 uint
146 draw_num_shader_outputs(const struct draw_context *draw);
147
148 uint
149 draw_total_vs_outputs(const struct draw_context *draw);
150
151 uint
152 draw_total_gs_outputs(const struct draw_context *draw);
153
154 void
155 draw_texture_sampler(struct draw_context *draw,
156 uint shader_type,
157 struct tgsi_sampler *sampler);
158
159 void
160 draw_image(struct draw_context *draw,
161 uint shader_type,
162 struct tgsi_image *image);
163
164 void
165 draw_buffer(struct draw_context *draw,
166 uint shader_type,
167 struct tgsi_buffer *buffer);
168
169 void
170 draw_set_sampler_views(struct draw_context *draw,
171 unsigned shader_stage,
172 struct pipe_sampler_view **views,
173 unsigned num);
174 void
175 draw_set_samplers(struct draw_context *draw,
176 unsigned shader_stage,
177 struct pipe_sampler_state **samplers,
178 unsigned num);
179
180 void
181 draw_set_mapped_texture(struct draw_context *draw,
182 unsigned shader_stage,
183 unsigned sview_idx,
184 uint32_t width, uint32_t height, uint32_t depth,
185 uint32_t first_level, uint32_t last_level,
186 const void *base,
187 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
188 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
189 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
190
191
192 /*
193 * Vertex shader functions
194 */
195
196 struct draw_vertex_shader *
197 draw_create_vertex_shader(struct draw_context *draw,
198 const struct pipe_shader_state *shader);
199 void draw_bind_vertex_shader(struct draw_context *draw,
200 struct draw_vertex_shader *dvs);
201 void draw_delete_vertex_shader(struct draw_context *draw,
202 struct draw_vertex_shader *dvs);
203 void draw_vs_attach_so(struct draw_vertex_shader *dvs,
204 const struct pipe_stream_output_info *info);
205 void draw_vs_reset_so(struct draw_vertex_shader *dvs);
206
207
208 /*
209 * Fragment shader functions
210 */
211 struct draw_fragment_shader *
212 draw_create_fragment_shader(struct draw_context *draw,
213 const struct pipe_shader_state *shader);
214 void draw_bind_fragment_shader(struct draw_context *draw,
215 struct draw_fragment_shader *dvs);
216 void draw_delete_fragment_shader(struct draw_context *draw,
217 struct draw_fragment_shader *dvs);
218
219 /*
220 * Geometry shader functions
221 */
222 struct draw_geometry_shader *
223 draw_create_geometry_shader(struct draw_context *draw,
224 const struct pipe_shader_state *shader);
225 void draw_bind_geometry_shader(struct draw_context *draw,
226 struct draw_geometry_shader *dvs);
227 void draw_delete_geometry_shader(struct draw_context *draw,
228 struct draw_geometry_shader *dvs);
229
230
231 /*
232 * Vertex data functions
233 */
234
235 void draw_set_vertex_buffers(struct draw_context *draw,
236 unsigned start_slot, unsigned count,
237 const struct pipe_vertex_buffer *buffers);
238
239 void draw_set_vertex_elements(struct draw_context *draw,
240 unsigned count,
241 const struct pipe_vertex_element *elements);
242
243 void draw_set_indexes(struct draw_context *draw,
244 const void *elements, unsigned elem_size,
245 unsigned available_space);
246
247 void draw_set_mapped_vertex_buffer(struct draw_context *draw,
248 unsigned attr, const void *buffer,
249 size_t size);
250
251 void
252 draw_set_mapped_constant_buffer(struct draw_context *draw,
253 unsigned shader_type,
254 unsigned slot,
255 const void *buffer,
256 unsigned size);
257
258 void
259 draw_set_mapped_so_targets(struct draw_context *draw,
260 int num_targets,
261 struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS]);
262
263
264 /***********************************************************************
265 * draw_pt.c
266 */
267
268 void draw_vbo(struct draw_context *draw,
269 const struct pipe_draw_info *info);
270
271
272 /*******************************************************************************
273 * Driver backend interface
274 */
275 struct vbuf_render;
276 void draw_set_render( struct draw_context *draw,
277 struct vbuf_render *render );
278
279 void draw_set_driver_clipping( struct draw_context *draw,
280 boolean bypass_clip_xy,
281 boolean bypass_clip_z,
282 boolean guard_band_xy,
283 boolean bypass_clip_points);
284
285 void draw_set_force_passthrough( struct draw_context *draw,
286 boolean enable );
287
288
289 /*******************************************************************************
290 * Draw statistics
291 */
292 void draw_collect_pipeline_statistics(struct draw_context *draw,
293 boolean enable);
294
295 /*******************************************************************************
296 * Draw pipeline
297 */
298 boolean draw_need_pipeline(const struct draw_context *draw,
299 const struct pipe_rasterizer_state *rasterizer,
300 unsigned prim );
301
302 int
303 draw_get_shader_param(unsigned shader, enum pipe_shader_cap param);
304
305 int
306 draw_get_shader_param_no_llvm(unsigned shader, enum pipe_shader_cap param);
307
308 boolean
309 draw_get_option_use_llvm(void);
310
311 #endif /* DRAW_CONTEXT_H */