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