3ed3304400557798d6d144a3177bf4daf23e7e1d
[mesa.git] / src / gallium / drivers / ilo / ilo_3d_pipeline.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 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_3D_PIPELINE_H
29 #define ILO_3D_PIPELINE_H
30
31 #include "ilo_common.h"
32 #include "ilo_context.h"
33 #include "ilo_gpe_gen6.h"
34
35 struct pipe_draw_info;
36 struct intel_bo;
37 struct ilo_cp;
38 struct ilo_context;
39
40 enum ilo_3d_pipeline_invalidate_flags {
41 ILO_3D_PIPELINE_INVALIDATE_HW = 1 << 0,
42 ILO_3D_PIPELINE_INVALIDATE_BATCH_BO = 1 << 1,
43 ILO_3D_PIPELINE_INVALIDATE_STATE_BO = 1 << 2,
44 ILO_3D_PIPELINE_INVALIDATE_KERNEL_BO = 1 << 3,
45
46 ILO_3D_PIPELINE_INVALIDATE_ALL = 0xffffffff,
47 };
48
49 enum ilo_3d_pipeline_action {
50 ILO_3D_PIPELINE_DRAW,
51 ILO_3D_PIPELINE_FLUSH,
52 ILO_3D_PIPELINE_WRITE_TIMESTAMP,
53 ILO_3D_PIPELINE_WRITE_DEPTH_COUNT,
54 };
55
56 /**
57 * 3D pipeline.
58 */
59 struct ilo_3d_pipeline {
60 struct ilo_cp *cp;
61 int gen;
62
63 struct ilo_gpe gpe;
64
65 uint32_t invalidate_flags;
66
67 struct intel_bo *workaround_bo;
68
69 uint32_t packed_sample_position_1x;
70 uint32_t packed_sample_position_4x;
71 uint32_t packed_sample_position_8x[2];
72
73 int (*estimate_size)(struct ilo_3d_pipeline *pipeline,
74 enum ilo_3d_pipeline_action action,
75 const void *arg);
76
77 void (*emit_draw)(struct ilo_3d_pipeline *pipeline,
78 const struct ilo_context *ilo,
79 const struct pipe_draw_info *info);
80
81 void (*emit_flush)(struct ilo_3d_pipeline *pipeline);
82
83 void (*emit_write_timestamp)(struct ilo_3d_pipeline *pipeline,
84 struct intel_bo *bo, int index);
85
86 void (*emit_write_depth_count)(struct ilo_3d_pipeline *pipeline,
87 struct intel_bo *bo, int index);
88
89 /**
90 * all GPE functions of all GENs
91 */
92 #define GEN6_EMIT(name) ilo_gpe_gen6_ ## name gen6_ ## name
93 GEN6_EMIT(STATE_BASE_ADDRESS);
94 GEN6_EMIT(STATE_SIP);
95 GEN6_EMIT(PIPELINE_SELECT);
96 GEN6_EMIT(3DSTATE_BINDING_TABLE_POINTERS);
97 GEN6_EMIT(3DSTATE_SAMPLER_STATE_POINTERS);
98 GEN6_EMIT(3DSTATE_URB);
99 GEN6_EMIT(3DSTATE_VERTEX_BUFFERS);
100 GEN6_EMIT(3DSTATE_VERTEX_ELEMENTS);
101 GEN6_EMIT(3DSTATE_INDEX_BUFFER);
102 GEN6_EMIT(3DSTATE_VF_STATISTICS);
103 GEN6_EMIT(3DSTATE_VIEWPORT_STATE_POINTERS);
104 GEN6_EMIT(3DSTATE_CC_STATE_POINTERS);
105 GEN6_EMIT(3DSTATE_SCISSOR_STATE_POINTERS);
106 GEN6_EMIT(3DSTATE_VS);
107 GEN6_EMIT(3DSTATE_GS);
108 GEN6_EMIT(3DSTATE_CLIP);
109 GEN6_EMIT(3DSTATE_SF);
110 GEN6_EMIT(3DSTATE_WM);
111 GEN6_EMIT(3DSTATE_CONSTANT_VS);
112 GEN6_EMIT(3DSTATE_CONSTANT_GS);
113 GEN6_EMIT(3DSTATE_CONSTANT_PS);
114 GEN6_EMIT(3DSTATE_SAMPLE_MASK);
115 GEN6_EMIT(3DSTATE_DRAWING_RECTANGLE);
116 GEN6_EMIT(3DSTATE_DEPTH_BUFFER);
117 GEN6_EMIT(3DSTATE_POLY_STIPPLE_OFFSET);
118 GEN6_EMIT(3DSTATE_POLY_STIPPLE_PATTERN);
119 GEN6_EMIT(3DSTATE_LINE_STIPPLE);
120 GEN6_EMIT(3DSTATE_AA_LINE_PARAMETERS);
121 GEN6_EMIT(3DSTATE_GS_SVB_INDEX);
122 GEN6_EMIT(3DSTATE_MULTISAMPLE);
123 GEN6_EMIT(3DSTATE_STENCIL_BUFFER);
124 GEN6_EMIT(3DSTATE_HIER_DEPTH_BUFFER);
125 GEN6_EMIT(3DSTATE_CLEAR_PARAMS);
126 GEN6_EMIT(PIPE_CONTROL);
127 GEN6_EMIT(3DPRIMITIVE);
128 GEN6_EMIT(INTERFACE_DESCRIPTOR_DATA);
129 GEN6_EMIT(SF_VIEWPORT);
130 GEN6_EMIT(CLIP_VIEWPORT);
131 GEN6_EMIT(CC_VIEWPORT);
132 GEN6_EMIT(COLOR_CALC_STATE);
133 GEN6_EMIT(BLEND_STATE);
134 GEN6_EMIT(DEPTH_STENCIL_STATE);
135 GEN6_EMIT(SCISSOR_RECT);
136 GEN6_EMIT(BINDING_TABLE_STATE);
137 GEN6_EMIT(surf_SURFACE_STATE);
138 GEN6_EMIT(view_SURFACE_STATE);
139 GEN6_EMIT(cbuf_SURFACE_STATE);
140 GEN6_EMIT(so_SURFACE_STATE);
141 GEN6_EMIT(SAMPLER_STATE);
142 GEN6_EMIT(SAMPLER_BORDER_COLOR_STATE);
143 GEN6_EMIT(push_constant_buffer);
144 #undef GEN6_EMIT
145
146 /**
147 * HW states.
148 */
149 struct ilo_3d_pipeline_state {
150 bool has_gen6_wa_pipe_control;
151
152 int reduced_prim;
153 int so_num_vertices, so_max_vertices;
154
155 uint32_t SF_VIEWPORT;
156 uint32_t CLIP_VIEWPORT;
157 uint32_t CC_VIEWPORT;
158
159 uint32_t COLOR_CALC_STATE;
160 uint32_t BLEND_STATE;
161 uint32_t DEPTH_STENCIL_STATE;
162
163 uint32_t SCISSOR_RECT;
164
165 struct {
166 uint32_t BINDING_TABLE_STATE;
167 int BINDING_TABLE_STATE_size;
168 uint32_t SURFACE_STATE[ILO_MAX_VS_SURFACES];
169 uint32_t SAMPLER_STATE;
170 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
171 uint32_t PUSH_CONSTANT_BUFFER;
172 int PUSH_CONSTANT_BUFFER_size;
173 } vs;
174
175 struct {
176 uint32_t BINDING_TABLE_STATE;
177 int BINDING_TABLE_STATE_size;
178 uint32_t SURFACE_STATE[ILO_MAX_GS_SURFACES];
179 bool active;
180 } gs;
181
182 struct {
183 uint32_t BINDING_TABLE_STATE;
184 int BINDING_TABLE_STATE_size;
185 uint32_t SURFACE_STATE[ILO_MAX_WM_SURFACES];
186 uint32_t SAMPLER_STATE;
187 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
188 } wm;
189 } state;
190 };
191
192 struct ilo_3d_pipeline *
193 ilo_3d_pipeline_create(struct ilo_cp *cp, int gen, int gt);
194
195 void
196 ilo_3d_pipeline_destroy(struct ilo_3d_pipeline *pipeline);
197
198
199 static inline void
200 ilo_3d_pipeline_invalidate(struct ilo_3d_pipeline *p, uint32_t flags)
201 {
202 p->invalidate_flags |= flags;
203 }
204
205 /**
206 * Estimate the size of an action.
207 */
208 static inline int
209 ilo_3d_pipeline_estimate_size(struct ilo_3d_pipeline *pipeline,
210 enum ilo_3d_pipeline_action action,
211 const void *arg)
212 {
213 return pipeline->estimate_size(pipeline, action, arg);
214 }
215
216 bool
217 ilo_3d_pipeline_emit_draw(struct ilo_3d_pipeline *p,
218 const struct ilo_context *ilo,
219 const struct pipe_draw_info *info,
220 int *prim_generated, int *prim_emitted);
221
222 void
223 ilo_3d_pipeline_emit_flush(struct ilo_3d_pipeline *p);
224
225 void
226 ilo_3d_pipeline_emit_write_timestamp(struct ilo_3d_pipeline *p,
227 struct intel_bo *bo, int index);
228
229 void
230 ilo_3d_pipeline_emit_write_depth_count(struct ilo_3d_pipeline *p,
231 struct intel_bo *bo, int index);
232
233 void
234 ilo_3d_pipeline_get_sample_position(struct ilo_3d_pipeline *p,
235 unsigned sample_count,
236 unsigned sample_index,
237 float *x, float *y);
238
239 void
240 ilo_3d_pipeline_dump(struct ilo_3d_pipeline *p);
241
242 #endif /* ILO_3D_PIPELINE_H */