ilo: add pipe_texture_target to ilo_image
[mesa.git] / src / gallium / drivers / ilo / ilo_state.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #ifndef ILO_STATE_H
29 #define ILO_STATE_H
30
31 #include "core/ilo_state_3d.h"
32 #include "pipe/p_state.h"
33 #include "util/u_dynarray.h"
34
35 #include "ilo_common.h"
36
37 /**
38 * States that we track.
39 *
40 * XXX Do we want to count each sampler or vertex buffer as a state? If that
41 * is the case, there are simply not enough bits.
42 *
43 * XXX We want to treat primitive type and depth clear value as states, but
44 * there are not enough bits.
45 */
46 enum ilo_state {
47 ILO_STATE_VB,
48 ILO_STATE_VE,
49 ILO_STATE_IB,
50 ILO_STATE_VS,
51 ILO_STATE_GS,
52 ILO_STATE_SO,
53 ILO_STATE_CLIP,
54 ILO_STATE_VIEWPORT,
55 ILO_STATE_SCISSOR,
56 ILO_STATE_RASTERIZER,
57 ILO_STATE_POLY_STIPPLE,
58 ILO_STATE_SAMPLE_MASK,
59 ILO_STATE_FS,
60 ILO_STATE_DSA,
61 ILO_STATE_STENCIL_REF,
62 ILO_STATE_BLEND,
63 ILO_STATE_BLEND_COLOR,
64 ILO_STATE_FB,
65
66 ILO_STATE_SAMPLER_VS,
67 ILO_STATE_SAMPLER_GS,
68 ILO_STATE_SAMPLER_FS,
69 ILO_STATE_SAMPLER_CS,
70 ILO_STATE_VIEW_VS,
71 ILO_STATE_VIEW_GS,
72 ILO_STATE_VIEW_FS,
73 ILO_STATE_VIEW_CS,
74 ILO_STATE_CBUF,
75 ILO_STATE_RESOURCE,
76
77 ILO_STATE_CS,
78 ILO_STATE_CS_RESOURCE,
79 ILO_STATE_GLOBAL_BINDING,
80
81 ILO_STATE_COUNT,
82 };
83
84 /**
85 * Dirty flags of the states.
86 */
87 enum ilo_dirty_flags {
88 ILO_DIRTY_VB = 1 << ILO_STATE_VB,
89 ILO_DIRTY_VE = 1 << ILO_STATE_VE,
90 ILO_DIRTY_IB = 1 << ILO_STATE_IB,
91 ILO_DIRTY_VS = 1 << ILO_STATE_VS,
92 ILO_DIRTY_GS = 1 << ILO_STATE_GS,
93 ILO_DIRTY_SO = 1 << ILO_STATE_SO,
94 ILO_DIRTY_CLIP = 1 << ILO_STATE_CLIP,
95 ILO_DIRTY_VIEWPORT = 1 << ILO_STATE_VIEWPORT,
96 ILO_DIRTY_SCISSOR = 1 << ILO_STATE_SCISSOR,
97 ILO_DIRTY_RASTERIZER = 1 << ILO_STATE_RASTERIZER,
98 ILO_DIRTY_POLY_STIPPLE = 1 << ILO_STATE_POLY_STIPPLE,
99 ILO_DIRTY_SAMPLE_MASK = 1 << ILO_STATE_SAMPLE_MASK,
100 ILO_DIRTY_FS = 1 << ILO_STATE_FS,
101 ILO_DIRTY_DSA = 1 << ILO_STATE_DSA,
102 ILO_DIRTY_STENCIL_REF = 1 << ILO_STATE_STENCIL_REF,
103 ILO_DIRTY_BLEND = 1 << ILO_STATE_BLEND,
104 ILO_DIRTY_BLEND_COLOR = 1 << ILO_STATE_BLEND_COLOR,
105 ILO_DIRTY_FB = 1 << ILO_STATE_FB,
106 ILO_DIRTY_SAMPLER_VS = 1 << ILO_STATE_SAMPLER_VS,
107 ILO_DIRTY_SAMPLER_GS = 1 << ILO_STATE_SAMPLER_GS,
108 ILO_DIRTY_SAMPLER_FS = 1 << ILO_STATE_SAMPLER_FS,
109 ILO_DIRTY_SAMPLER_CS = 1 << ILO_STATE_SAMPLER_CS,
110 ILO_DIRTY_VIEW_VS = 1 << ILO_STATE_VIEW_VS,
111 ILO_DIRTY_VIEW_GS = 1 << ILO_STATE_VIEW_GS,
112 ILO_DIRTY_VIEW_FS = 1 << ILO_STATE_VIEW_FS,
113 ILO_DIRTY_VIEW_CS = 1 << ILO_STATE_VIEW_CS,
114 ILO_DIRTY_CBUF = 1 << ILO_STATE_CBUF,
115 ILO_DIRTY_RESOURCE = 1 << ILO_STATE_RESOURCE,
116 ILO_DIRTY_CS = 1 << ILO_STATE_CS,
117 ILO_DIRTY_CS_RESOURCE = 1 << ILO_STATE_CS_RESOURCE,
118 ILO_DIRTY_GLOBAL_BINDING = 1 << ILO_STATE_GLOBAL_BINDING,
119 ILO_DIRTY_ALL = 0xffffffff,
120 };
121
122 struct ilo_context;
123
124 struct ilo_global_binding_cso {
125 struct pipe_resource *resource;
126 uint32_t *handle;
127 };
128
129 /*
130 * In theory, we would like a "virtual" bo that serves as the global memory
131 * region. The virtual bo would reserve a region in the GTT aperture, but the
132 * pages of it would come from those of the global bindings.
133 *
134 * The virtual bo would be created in launch_grid(). The global bindings
135 * would be added to the virtual bo. A SURFACE_STATE for the virtual bo would
136 * be created. The handles returned by set_global_binding() would be offsets
137 * into the virtual bo.
138 *
139 * But for now, we will create a SURFACE_STATE for each of the bindings. The
140 * handle of a global binding consists of the offset and the binding table
141 * index.
142 */
143 struct ilo_global_binding {
144 struct util_dynarray bindings;
145 unsigned count;
146 };
147
148 struct ilo_state_vector {
149 const struct pipe_draw_info *draw;
150
151 uint32_t dirty;
152
153 struct ilo_vb_state vb;
154 struct ilo_ve_state *ve;
155 struct ilo_ib_state ib;
156
157 struct ilo_shader_state *vs;
158 struct ilo_shader_state *gs;
159
160 struct ilo_so_state so;
161
162 struct pipe_clip_state clip;
163 struct ilo_viewport_state viewport;
164 struct ilo_scissor_state scissor;
165
166 const struct ilo_rasterizer_state *rasterizer;
167 struct pipe_poly_stipple poly_stipple;
168 unsigned sample_mask;
169
170 struct ilo_shader_state *fs;
171
172 const struct ilo_dsa_state *dsa;
173 struct pipe_stencil_ref stencil_ref;
174 const struct ilo_blend_state *blend;
175 struct pipe_blend_color blend_color;
176 struct ilo_fb_state fb;
177
178 /* shader resources */
179 struct ilo_sampler_state sampler[PIPE_SHADER_TYPES];
180 struct ilo_view_state view[PIPE_SHADER_TYPES];
181 struct ilo_cbuf_state cbuf[PIPE_SHADER_TYPES];
182 struct ilo_resource_state resource;
183
184 /* GPGPU */
185 struct ilo_shader_state *cs;
186 struct ilo_resource_state cs_resource;
187 struct ilo_global_binding global_binding;
188 };
189
190 void
191 ilo_init_state_functions(struct ilo_context *ilo);
192
193 void
194 ilo_finalize_3d_states(struct ilo_context *ilo,
195 const struct pipe_draw_info *draw);
196
197 void
198 ilo_finalize_compute_states(struct ilo_context *ilo);
199
200 void
201 ilo_state_vector_init(const struct ilo_dev *dev,
202 struct ilo_state_vector *vec);
203
204 void
205 ilo_state_vector_cleanup(struct ilo_state_vector *vec);
206
207 void
208 ilo_state_vector_resource_renamed(struct ilo_state_vector *vec,
209 struct pipe_resource *res);
210
211 void
212 ilo_state_vector_dump_dirty(const struct ilo_state_vector *vec);
213
214 #endif /* ILO_STATE_H */