1 /**************************************************************************
2 *
3 * Copyright 2007-2008 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #ifndef CSO_CONTEXT_H
30 #define CSO_CONTEXT_H
31
32 #include "pipe/p_context.h"
33 #include "pipe/p_state.h"
34 #include "pipe/p_defines.h"
35 #include "cso_cache.h"
36
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 struct cso_context {
43 struct pipe_context *pipe;
44
45 /* This is equal to either pipe_context::draw_vbo or u_vbuf_draw_vbo. */
46 pipe_draw_func draw_vbo;
47 };
48
49 #define CSO_NO_USER_VERTEX_BUFFERS (1 << 0)
50 #define CSO_NO_64B_VERTEX_BUFFERS (1 << 1)
51 #define CSO_NO_VBUF (1 << 2)
52
53 struct cso_context *
54 cso_create_context(struct pipe_context *pipe, unsigned flags);
55
56 void
57 cso_unbind_context(struct cso_context *ctx);
58
59 void
60 cso_destroy_context(struct cso_context *cso);
61
62 enum pipe_error
63 cso_set_blend(struct cso_context *cso, const struct pipe_blend_state *blend);
64
65 enum pipe_error
66 cso_set_depth_stencil_alpha(struct cso_context *cso,
67 const struct pipe_depth_stencil_alpha_state *dsa);
68
69 enum pipe_error
70 cso_set_rasterizer(struct cso_context *cso,
71 const struct pipe_rasterizer_state *rasterizer);
72
73 void
74 cso_set_samplers(struct cso_context *cso,
75 enum pipe_shader_type shader_stage,
76 unsigned count,
77 const struct pipe_sampler_state **states);
78
79
80 /* Alternate interface to support gallium frontends that like to modify
81 * samplers one at a time:
82 */
83 void
84 cso_single_sampler(struct cso_context *cso, enum pipe_shader_type shader_stage,
85 unsigned idx, const struct pipe_sampler_state *states);
86
87 void
88 cso_single_sampler_done(struct cso_context *cso,
89 enum pipe_shader_type shader_stage);
90
91
92 enum pipe_error
93 cso_set_vertex_elements(struct cso_context *ctx,
94 const struct cso_velems_state *velems);
95
96 void cso_set_vertex_buffers(struct cso_context *ctx,
97 unsigned count,
98 bool take_ownership,
99 const struct pipe_vertex_buffer *buffers);
100
101 void cso_set_stream_outputs(struct cso_context *ctx,
102 unsigned num_targets,
103 struct pipe_stream_output_target **targets,
104 const unsigned *offsets,
105 enum mesa_prim output_prim);
106
107
108 enum cso_unbind_flags {
109 CSO_UNBIND_FS_SAMPLERVIEWS = (1 << 0),
110 CSO_UNBIND_FS_SAMPLERVIEW0 = (1 << 1),
111 CSO_UNBIND_FS_IMAGE0 = (1 << 2),
112 CSO_UNBIND_VS_CONSTANTS = (1 << 3),
113 CSO_UNBIND_FS_CONSTANTS = (1 << 4),
114 };
115
116 /*
117 * We don't provide shader caching in CSO. Most of the time the api provides
118 * object semantics for shaders anyway, and the cases where it doesn't
119 * (eg mesa's internally-generated texenv programs), it will be up to
120 * gallium frontends to implement their own specialized caching.
121 */
122
123 void cso_set_fragment_shader_handle(struct cso_context *ctx, void *handle);
124 void cso_set_vertex_shader_handle(struct cso_context *ctx, void *handle);
125 void cso_set_geometry_shader_handle(struct cso_context *ctx, void *handle);
126 void cso_set_tessctrl_shader_handle(struct cso_context *ctx, void *handle);
127 void cso_set_tesseval_shader_handle(struct cso_context *ctx, void *handle);
128 void cso_set_compute_shader_handle(struct cso_context *ctx, void *handle);
129
130
131 void
132 cso_set_framebuffer(struct cso_context *cso,
133 const struct pipe_framebuffer_state *fb);
134
135 void
136 cso_set_viewport(struct cso_context *cso,
137 const struct pipe_viewport_state *vp);
138
139 void
140 cso_set_viewport_dims(struct cso_context *ctx,
141 float width, float height, bool invert);
142
143 void
144 cso_set_sample_mask(struct cso_context *cso, unsigned stencil_mask);
145
146 void
147 cso_set_min_samples(struct cso_context *cso, unsigned min_samples);
148
149 void
150 cso_set_stencil_ref(struct cso_context *cso,
151 const struct pipe_stencil_ref sr);
152
153 void
154 cso_set_render_condition(struct cso_context *cso,
155 struct pipe_query *query,
156 bool condition,
157 enum pipe_render_cond_flag mode);
158
159 /* gap */
160 #define CSO_BIT_BLEND 0x2
161 #define CSO_BIT_DEPTH_STENCIL_ALPHA 0x4
162 #define CSO_BIT_FRAGMENT_SAMPLERS 0x8
163 /* gap */
164 #define CSO_BIT_FRAGMENT_SHADER 0x20
165 #define CSO_BIT_FRAMEBUFFER 0x40
166 #define CSO_BIT_GEOMETRY_SHADER 0x80
167 #define CSO_BIT_MIN_SAMPLES 0x100
168 #define CSO_BIT_RASTERIZER 0x200
169 #define CSO_BIT_RENDER_CONDITION 0x400
170 #define CSO_BIT_SAMPLE_MASK 0x800
171 #define CSO_BIT_STENCIL_REF 0x1000
172 #define CSO_BIT_STREAM_OUTPUTS 0x2000
173 #define CSO_BIT_TESSCTRL_SHADER 0x4000
174 #define CSO_BIT_TESSEVAL_SHADER 0x8000
175 #define CSO_BIT_VERTEX_ELEMENTS 0x10000
176 #define CSO_BIT_VERTEX_SHADER 0x20000
177 #define CSO_BIT_VIEWPORT 0x40000
178 #define CSO_BIT_PAUSE_QUERIES 0x80000
179
180 #define CSO_BITS_ALL_SHADERS (CSO_BIT_VERTEX_SHADER | \
181 CSO_BIT_FRAGMENT_SHADER | \
182 CSO_BIT_GEOMETRY_SHADER | \
183 CSO_BIT_TESSCTRL_SHADER | \
184 CSO_BIT_TESSEVAL_SHADER)
185
186 #define CSO_BIT_COMPUTE_SHADER (1<<0)
187 #define CSO_BIT_COMPUTE_SAMPLERS (1<<1)
188
189 void
190 cso_save_state(struct cso_context *cso, unsigned state_mask);
191
192 void
193 cso_restore_state(struct cso_context *cso, unsigned unbind);
194
195 void
196 cso_save_compute_state(struct cso_context *cso, unsigned state_mask);
197
198 void
199 cso_restore_compute_state(struct cso_context *cso);
200
201
202 /* Optimized version. */
203 void
204 cso_set_vertex_buffers_and_elements(struct cso_context *ctx,
205 const struct cso_velems_state *velems,
206 unsigned vb_count,
207 bool uses_user_vertex_buffers,
208 const struct pipe_vertex_buffer *vbuffers);
209
210 void
211 cso_draw_arrays_instanced(struct cso_context *cso, unsigned mode,
212 unsigned start, unsigned count,
213 unsigned start_instance, unsigned instance_count);
214
215 void
216 cso_draw_arrays(struct cso_context *cso, unsigned mode, unsigned start, unsigned count);
217
218 /* Inline functions. */
219
220 static ALWAYS_INLINE void
cso_draw_vbo(struct cso_context * cso,const struct pipe_draw_info * info,unsigned drawid_offset,const struct pipe_draw_indirect_info * indirect,const struct pipe_draw_start_count_bias * draws,unsigned num_draws)221 cso_draw_vbo(struct cso_context *cso,
222 const struct pipe_draw_info *info,
223 unsigned drawid_offset,
224 const struct pipe_draw_indirect_info *indirect,
225 const struct pipe_draw_start_count_bias *draws,
226 unsigned num_draws)
227 {
228 /* We can't have both indirect drawing and SO-vertex-count drawing */
229 assert(!indirect ||
230 indirect->buffer == NULL ||
231 indirect->count_from_stream_output == NULL);
232
233 /* We can't have SO-vertex-count drawing with an index buffer */
234 assert(info->index_size == 0 ||
235 !indirect ||
236 indirect->count_from_stream_output == NULL);
237
238 /* Indirect only uses indirect->draw_count, not num_draws. */
239 assert(!indirect || num_draws == 1);
240
241 cso->draw_vbo(cso->pipe, info, drawid_offset, indirect, draws, num_draws);
242 }
243
244 #ifdef __cplusplus
245 }
246 #endif
247
248 #endif
249