xref: /aosp_15_r20/external/mesa3d/src/gallium/auxiliary/cso_cache/cso_context.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 
106 
107 enum cso_unbind_flags {
108    CSO_UNBIND_FS_SAMPLERVIEWS = (1 << 0),
109    CSO_UNBIND_FS_SAMPLERVIEW0 = (1 << 1),
110    CSO_UNBIND_FS_IMAGE0 = (1 << 2),
111    CSO_UNBIND_VS_CONSTANTS = (1 << 3),
112    CSO_UNBIND_FS_CONSTANTS = (1 << 4),
113 };
114 
115 /*
116  * We don't provide shader caching in CSO.  Most of the time the api provides
117  * object semantics for shaders anyway, and the cases where it doesn't
118  * (eg mesa's internally-generated texenv programs), it will be up to
119  * gallium frontends to implement their own specialized caching.
120  */
121 
122 void cso_set_fragment_shader_handle(struct cso_context *ctx, void *handle);
123 void cso_set_vertex_shader_handle(struct cso_context *ctx, void *handle);
124 void cso_set_geometry_shader_handle(struct cso_context *ctx, void *handle);
125 void cso_set_tessctrl_shader_handle(struct cso_context *ctx, void *handle);
126 void cso_set_tesseval_shader_handle(struct cso_context *ctx, void *handle);
127 void cso_set_compute_shader_handle(struct cso_context *ctx, void *handle);
128 
129 
130 void
131 cso_set_framebuffer(struct cso_context *cso,
132                     const struct pipe_framebuffer_state *fb);
133 
134 void
135 cso_set_viewport(struct cso_context *cso,
136                  const struct pipe_viewport_state *vp);
137 
138 void
139 cso_set_viewport_dims(struct cso_context *ctx,
140                       float width, float height, bool invert);
141 
142 void
143 cso_set_sample_mask(struct cso_context *cso, unsigned stencil_mask);
144 
145 void
146 cso_set_min_samples(struct cso_context *cso, unsigned min_samples);
147 
148 void
149 cso_set_stencil_ref(struct cso_context *cso,
150                     const struct pipe_stencil_ref sr);
151 
152 void
153 cso_set_render_condition(struct cso_context *cso,
154                          struct pipe_query *query,
155                          bool condition,
156                          enum pipe_render_cond_flag mode);
157 
158 /* gap */
159 #define CSO_BIT_BLEND                     0x2
160 #define CSO_BIT_DEPTH_STENCIL_ALPHA       0x4
161 #define CSO_BIT_FRAGMENT_SAMPLERS         0x8
162 /* gap */
163 #define CSO_BIT_FRAGMENT_SHADER          0x20
164 #define CSO_BIT_FRAMEBUFFER              0x40
165 #define CSO_BIT_GEOMETRY_SHADER          0x80
166 #define CSO_BIT_MIN_SAMPLES             0x100
167 #define CSO_BIT_RASTERIZER              0x200
168 #define CSO_BIT_RENDER_CONDITION        0x400
169 #define CSO_BIT_SAMPLE_MASK             0x800
170 #define CSO_BIT_STENCIL_REF            0x1000
171 #define CSO_BIT_STREAM_OUTPUTS         0x2000
172 #define CSO_BIT_TESSCTRL_SHADER        0x4000
173 #define CSO_BIT_TESSEVAL_SHADER        0x8000
174 #define CSO_BIT_VERTEX_ELEMENTS       0x10000
175 #define CSO_BIT_VERTEX_SHADER         0x20000
176 #define CSO_BIT_VIEWPORT              0x40000
177 #define CSO_BIT_PAUSE_QUERIES         0x80000
178 
179 #define CSO_BITS_ALL_SHADERS (CSO_BIT_VERTEX_SHADER | \
180                               CSO_BIT_FRAGMENT_SHADER | \
181                               CSO_BIT_GEOMETRY_SHADER | \
182                               CSO_BIT_TESSCTRL_SHADER | \
183                               CSO_BIT_TESSEVAL_SHADER)
184 
185 #define CSO_BIT_COMPUTE_SHADER   (1<<0)
186 #define CSO_BIT_COMPUTE_SAMPLERS (1<<1)
187 
188 void
189 cso_save_state(struct cso_context *cso, unsigned state_mask);
190 
191 void
192 cso_restore_state(struct cso_context *cso, unsigned unbind);
193 
194 void
195 cso_save_compute_state(struct cso_context *cso, unsigned state_mask);
196 
197 void
198 cso_restore_compute_state(struct cso_context *cso);
199 
200 
201 /* Optimized version. */
202 void
203 cso_set_vertex_buffers_and_elements(struct cso_context *ctx,
204                                     const struct cso_velems_state *velems,
205                                     unsigned vb_count,
206                                     bool uses_user_vertex_buffers,
207                                     const struct pipe_vertex_buffer *vbuffers);
208 
209 void
210 cso_draw_arrays_instanced(struct cso_context *cso, unsigned mode,
211                           unsigned start, unsigned count,
212                           unsigned start_instance, unsigned instance_count);
213 
214 void
215 cso_draw_arrays(struct cso_context *cso, unsigned mode, unsigned start, unsigned count);
216 
217 /* Inline functions. */
218 
219 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)220 cso_draw_vbo(struct cso_context *cso,
221              const struct pipe_draw_info *info,
222              unsigned drawid_offset,
223              const struct pipe_draw_indirect_info *indirect,
224              const struct pipe_draw_start_count_bias *draws,
225              unsigned num_draws)
226 {
227    /* We can't have both indirect drawing and SO-vertex-count drawing */
228    assert(!indirect ||
229           indirect->buffer == NULL ||
230           indirect->count_from_stream_output == NULL);
231 
232    /* We can't have SO-vertex-count drawing with an index buffer */
233    assert(info->index_size == 0 ||
234           !indirect ||
235           indirect->count_from_stream_output == NULL);
236 
237    /* Indirect only uses indirect->draw_count, not num_draws. */
238    assert(!indirect || num_draws == 1);
239 
240    cso->draw_vbo(cso->pipe, info, drawid_offset, indirect, draws, num_draws);
241 }
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 
247 #endif
248