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