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
43struct pipe_context;
44struct draw_context;
45struct draw_stage;
46struct draw_vertex_shader;
47struct draw_geometry_shader;
48struct draw_tess_ctrl_shader;
49struct draw_tess_eval_shader;
50struct draw_fragment_shader;
51struct tgsi_sampler;
52struct tgsi_image;
53struct tgsi_buffer;
54struct lp_cached_code;
55
56
57/*
58 * structure to contain driver internal information
59 * for stream out support. mapping stores the pointer
60 * to the buffer contents, and internal offset stores
61 * an internal counter to how much of the stream
62 * out buffer is used (in bytes).
63 */
64struct draw_so_target {
65   struct pipe_stream_output_target target;
66   void *mapping;
67   int internal_offset;
68};
69
70bool draw_has_llvm(void);
71
72struct draw_context *draw_create(struct pipe_context *pipe);
73
74#ifdef DRAW_LLVM_AVAILABLE
75struct draw_context *draw_create_with_llvm_context(struct pipe_context *pipe,
76                                                   void *context);
77#endif
78
79struct draw_context *draw_create_no_llvm(struct pipe_context *pipe);
80
81void draw_destroy(struct draw_context *draw);
82
83void draw_flush(struct draw_context *draw);
84
85void draw_set_viewport_states(struct draw_context *draw,
86                              unsigned start_slot,
87                              unsigned num_viewports,
88                              const struct pipe_viewport_state *viewports);
89
90void draw_set_clip_state(struct draw_context *pipe,
91                         const struct pipe_clip_state *clip);
92
93/**
94 * Sets the rasterization state used by the draw module.
95 * The rast_handle is used to pass the driver specific representation
96 * of the rasterization state. It's going to be used when the
97 * draw module sets the state back on the driver itself using the
98 * pipe::bind_rasterizer_state method.
99 *
100 * NOTE: if you're calling this function from within the pipe's
101 * bind_rasterizer_state you should always call it before binding
102 * the actual state - that's because the draw module can try to
103 * bind its own rasterizer state which would reset your newly
104 * set state. i.e. always do
105 * draw_set_rasterizer_state(driver->draw, state->pipe_state, state);
106 * driver->state.raster = state;
107 */
108void draw_set_rasterizer_state(struct draw_context *draw,
109                               const struct pipe_rasterizer_state *raster,
110                               void *rast_handle);
111
112void draw_set_rasterize_stage(struct draw_context *draw,
113                              struct draw_stage *stage);
114
115void draw_wide_point_threshold(struct draw_context *draw, float threshold);
116
117void draw_wide_point_sprites(struct draw_context *draw, boolean draw_sprite);
118
119void draw_wide_line_threshold(struct draw_context *draw, float threshold);
120
121void draw_enable_line_stipple(struct draw_context *draw, boolean enable);
122
123void draw_enable_point_sprites(struct draw_context *draw, boolean enable);
124
125void draw_set_zs_format(struct draw_context *draw, enum pipe_format format);
126
127/* for TGSI constants are 4 * sizeof(float), but for NIR they need to be sizeof(float); */
128void draw_set_constant_buffer_stride(struct draw_context *draw, unsigned num_bytes);
129
130boolean
131draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe);
132
133boolean
134draw_install_aapoint_stage(struct draw_context *draw, struct pipe_context *pipe);
135
136boolean
137draw_install_pstipple_stage(struct draw_context *draw, struct pipe_context *pipe);
138
139
140struct tgsi_shader_info *
141draw_get_shader_info(const struct draw_context *draw);
142
143void
144draw_prepare_shader_outputs(struct draw_context *draw);
145
146int
147draw_find_shader_output(const struct draw_context *draw,
148                        uint semantic_name, uint semantic_index);
149
150boolean
151draw_will_inject_frontface(const struct draw_context *draw);
152
153uint
154draw_num_shader_outputs(const struct draw_context *draw);
155
156uint
157draw_total_vs_outputs(const struct draw_context *draw);
158
159uint
160draw_total_gs_outputs(const struct draw_context *draw);
161
162uint
163draw_total_tcs_outputs(const struct draw_context *draw);
164
165uint
166draw_total_tes_outputs(const struct draw_context *draw);
167
168void
169draw_texture_sampler(struct draw_context *draw,
170                     enum pipe_shader_type shader_type,
171                     struct tgsi_sampler *sampler);
172
173void
174draw_image(struct draw_context *draw,
175           enum pipe_shader_type shader_type,
176           struct tgsi_image *image);
177
178void
179draw_buffer(struct draw_context *draw,
180           enum pipe_shader_type shader_type,
181           struct tgsi_buffer *buffer);
182
183void
184draw_set_sampler_views(struct draw_context *draw,
185                       enum pipe_shader_type shader_stage,
186                       struct pipe_sampler_view **views,
187                       unsigned num);
188void
189draw_set_samplers(struct draw_context *draw,
190                  enum pipe_shader_type shader_stage,
191                  struct pipe_sampler_state **samplers,
192                  unsigned num);
193
194void
195draw_set_images(struct draw_context *draw,
196                enum pipe_shader_type shader_stage,
197                struct pipe_image_view *images,
198                unsigned num);
199
200void
201draw_set_mapped_texture(struct draw_context *draw,
202                        enum pipe_shader_type shader_stage,
203                        unsigned sview_idx,
204                        uint32_t width, uint32_t height, uint32_t depth,
205                        uint32_t first_level, uint32_t last_level,
206                        uint32_t num_samples,
207                        uint32_t sample_stride,
208                        const void *base,
209                        uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
210                        uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
211                        uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
212
213void
214draw_set_mapped_image(struct draw_context *draw,
215                      enum pipe_shader_type shader_stage,
216                      unsigned idx,
217                      uint32_t width, uint32_t height, uint32_t depth,
218                      const void *base_ptr,
219                      uint32_t row_stride,
220                      uint32_t img_stride,
221                      uint32_t num_samples,
222                      uint32_t sample_stride);
223
224/*
225 * Vertex shader functions
226 */
227
228struct draw_vertex_shader *
229draw_create_vertex_shader(struct draw_context *draw,
230                          const struct pipe_shader_state *shader);
231void draw_bind_vertex_shader(struct draw_context *draw,
232                             struct draw_vertex_shader *dvs);
233void draw_delete_vertex_shader(struct draw_context *draw,
234                               struct draw_vertex_shader *dvs);
235void draw_vs_attach_so(struct draw_vertex_shader *dvs,
236                       const struct pipe_stream_output_info *info);
237void draw_vs_reset_so(struct draw_vertex_shader *dvs);
238
239
240/*
241 * Fragment shader functions
242 */
243struct draw_fragment_shader *
244draw_create_fragment_shader(struct draw_context *draw,
245                            const struct pipe_shader_state *shader);
246void draw_bind_fragment_shader(struct draw_context *draw,
247                               struct draw_fragment_shader *dvs);
248void draw_delete_fragment_shader(struct draw_context *draw,
249                                 struct draw_fragment_shader *dvs);
250
251/*
252 * Geometry shader functions
253 */
254struct draw_geometry_shader *
255draw_create_geometry_shader(struct draw_context *draw,
256                            const struct pipe_shader_state *shader);
257void draw_bind_geometry_shader(struct draw_context *draw,
258                               struct draw_geometry_shader *dvs);
259void draw_delete_geometry_shader(struct draw_context *draw,
260                                 struct draw_geometry_shader *dvs);
261
262/*
263 * Tess shader functions
264 */
265struct draw_tess_ctrl_shader *
266draw_create_tess_ctrl_shader(struct draw_context *draw,
267                            const struct pipe_shader_state *shader);
268void draw_bind_tess_ctrl_shader(struct draw_context *draw,
269                                struct draw_tess_ctrl_shader *dvs);
270void draw_delete_tess_ctrl_shader(struct draw_context *draw,
271                                  struct draw_tess_ctrl_shader *dvs);
272struct draw_tess_eval_shader *
273draw_create_tess_eval_shader(struct draw_context *draw,
274                            const struct pipe_shader_state *shader);
275void draw_bind_tess_eval_shader(struct draw_context *draw,
276                                struct draw_tess_eval_shader *dvs);
277void draw_delete_tess_eval_shader(struct draw_context *draw,
278                                  struct draw_tess_eval_shader *dvs);
279void draw_set_tess_state(struct draw_context *draw,
280                         const float default_outer_level[4],
281                         const float default_inner_level[2]);
282
283/*
284 * Vertex data functions
285 */
286
287void draw_set_vertex_buffers(struct draw_context *draw,
288                             unsigned start_slot, unsigned count,
289                             unsigned unbind_num_trailing_slots,
290                             const struct pipe_vertex_buffer *buffers);
291
292void draw_set_vertex_elements(struct draw_context *draw,
293                              unsigned count,
294                              const struct pipe_vertex_element *elements);
295
296void draw_set_indexes(struct draw_context *draw,
297                      const void *elements, unsigned elem_size,
298                      unsigned available_space);
299
300void draw_set_mapped_vertex_buffer(struct draw_context *draw,
301                                   unsigned attr, const void *buffer,
302                                   size_t size);
303
304void
305draw_set_mapped_constant_buffer(struct draw_context *draw,
306                                enum pipe_shader_type shader_type,
307                                unsigned slot,
308                                const void *buffer,
309                                unsigned size);
310
311void
312draw_set_mapped_shader_buffer(struct draw_context *draw,
313                              enum pipe_shader_type shader_type,
314                              unsigned slot,
315                              const void *buffer,
316                              unsigned size);
317
318void
319draw_set_mapped_so_targets(struct draw_context *draw,
320                           int num_targets,
321                           struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS]);
322
323
324/***********************************************************************
325 * draw_pt.c
326 */
327
328void draw_vbo(struct draw_context *draw,
329              const struct pipe_draw_info *info,
330              unsigned drawid_offset,
331              const struct pipe_draw_indirect_info *indirect,
332              const struct pipe_draw_start_count_bias *draws,
333              unsigned num_draws,
334              uint8_t patch_vertices);
335
336
337/*******************************************************************************
338 * Driver backend interface
339 */
340struct vbuf_render;
341void
342draw_set_render(struct draw_context *draw,
343                struct vbuf_render *render);
344
345void
346draw_set_driver_clipping(struct draw_context *draw,
347                         boolean bypass_clip_xy,
348                         boolean bypass_clip_z,
349                         boolean guard_band_xy,
350                         boolean bypass_clip_points);
351
352/*******************************************************************************
353 * Draw statistics
354 */
355void
356draw_collect_pipeline_statistics(struct draw_context *draw,
357                                 boolean enable);
358
359void
360draw_collect_primitives_generated(struct draw_context *draw,
361                                  bool eanble);
362
363/*******************************************************************************
364 * Draw pipeline
365 */
366boolean
367draw_need_pipeline(const struct draw_context *draw,
368                   const struct pipe_rasterizer_state *rasterizer,
369                   enum pipe_prim_type prim);
370
371int
372draw_get_shader_param(enum pipe_shader_type shader, enum pipe_shader_cap param);
373
374int
375draw_get_shader_param_no_llvm(enum pipe_shader_type shader,
376                              enum pipe_shader_cap param);
377
378boolean
379draw_get_option_use_llvm(void);
380
381
382void
383draw_set_disk_cache_callbacks(struct draw_context *draw,
384                              void *data_cookie,
385                              void (*find_shader)(void *cookie,
386                                                  struct lp_cached_code *cache,
387                                                  unsigned char ir_sha1_cache_key[20]),
388                              void (*insert_shader)(void *cookie,
389                                                    struct lp_cached_code *cache,
390                                                    unsigned char ir_sha1_cache_key[20]));
391
392
393#endif /* DRAW_CONTEXT_H */
394