e4697bc383fd03959af3f96fdf5c95e300ab8506
[mesa.git] / src / gallium / drivers / ilo / core / ilo_state_raster.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2015 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_RASTER_H
29 #define ILO_STATE_RASTER_H
30
31 #include "genhw/genhw.h"
32
33 #include "ilo_core.h"
34 #include "ilo_dev.h"
35
36 enum ilo_state_raster_dirty_bits {
37 ILO_STATE_RASTER_3DSTATE_CLIP = (1 << 0),
38 ILO_STATE_RASTER_3DSTATE_SF = (1 << 1),
39 ILO_STATE_RASTER_3DSTATE_RASTER = (1 << 2),
40 ILO_STATE_RASTER_3DSTATE_MULTISAMPLE = (1 << 3),
41 ILO_STATE_RASTER_3DSTATE_SAMPLE_MASK = (1 << 4),
42 ILO_STATE_RASTER_3DSTATE_WM = (1 << 5),
43 ILO_STATE_RASTER_3DSTATE_WM_HZ_OP = (1 << 6),
44 ILO_STATE_RASTER_3DSTATE_AA_LINE_PARAMETERS = (1 << 7),
45 };
46
47 enum ilo_state_raster_earlyz_op {
48 ILO_STATE_RASTER_EARLYZ_NORMAL,
49 ILO_STATE_RASTER_EARLYZ_DEPTH_CLEAR,
50 ILO_STATE_RASTER_EARLYZ_DEPTH_RESOLVE,
51 ILO_STATE_RASTER_EARLYZ_HIZ_RESOLVE,
52 };
53
54 /**
55 * VUE readback, VertexClipTest, ClipDetermination, and primitive output.
56 */
57 struct ilo_state_raster_clip_info {
58 bool clip_enable;
59 /* CL_INVOCATION_COUNT and CL_PRIMITIVES_COUNT */
60 bool stats_enable;
61
62 uint8_t viewport_count;
63 bool force_rtaindex_zero;
64
65 /* these should be mutually exclusive */
66 uint8_t user_cull_enables;
67 uint8_t user_clip_enables;
68
69 bool gb_test_enable;
70 bool xy_test_enable;
71
72 /* far/near must be enabled together prior to Gen9 */
73 bool z_far_enable;
74 bool z_near_enable;
75 bool z_near_zero;
76 };
77
78 /**
79 * Primitive assembly, viewport transformation, scissoring, MSAA, etc.
80 */
81 struct ilo_state_raster_setup_info {
82 bool cv_is_rectangle;
83
84 bool first_vertex_provoking;
85 bool viewport_transform;
86
87 bool scissor_enable;
88
89 /* MSAA enables for lines and non-lines */
90 bool msaa_enable;
91 bool line_msaa_enable;
92 };
93
94 /**
95 * 3DOBJ_POINT rasterization rules.
96 */
97 struct ilo_state_raster_point_info {
98 /* ignored when msaa_enable is set */
99 bool aa_enable;
100
101 bool programmable_width;
102 };
103
104 /**
105 * 3DOBJ_LINE rasterization rules.
106 */
107 struct ilo_state_raster_line_info {
108 /* ignored when line_msaa_enable is set */
109 bool aa_enable;
110
111 /* ignored when line_msaa_enable or aa_enable is set */
112 bool stipple_enable;
113 bool giq_enable;
114 bool giq_last_pixel;
115 };
116
117 /**
118 * 3DOBJ_TRIANGLE rasterization rules.
119 */
120 struct ilo_state_raster_tri_info {
121 enum gen_front_winding front_winding;
122 enum gen_cull_mode cull_mode;
123 enum gen_fill_mode fill_mode_front;
124 enum gen_fill_mode fill_mode_back;
125
126 enum gen_depth_format depth_offset_format;
127 bool depth_offset_solid;
128 bool depth_offset_wireframe;
129 bool depth_offset_point;
130
131 bool poly_stipple_enable;
132 };
133
134 /**
135 * Scan conversion.
136 */
137 struct ilo_state_raster_scan_info {
138 /* PS_DEPTH_COUNT and PS_INVOCATION_COUNT */
139 bool stats_enable;
140
141 uint8_t sample_count;
142
143 /* pixel location for non-MSAA or 1x-MSAA */
144 enum gen_pixel_location pixloc;
145
146 uint32_t sample_mask;
147
148 /* interpolations */
149 enum gen_zw_interp zw_interp;
150 uint8_t barycentric_interps;
151
152 /* Gen7+ only */
153 enum gen_edsc_mode earlyz_control;
154 enum ilo_state_raster_earlyz_op earlyz_op;
155 bool earlyz_stencil_clear;
156 };
157
158 /**
159 * Raster parameters.
160 */
161 struct ilo_state_raster_params_info {
162 bool any_integer_rt;
163 bool hiz_enable;
164
165 float point_width;
166 float line_width;
167
168 /* const term will be scaled by 'r' */
169 float depth_offset_const;
170 float depth_offset_scale;
171 float depth_offset_clamp;
172 };
173
174 struct ilo_state_raster_info {
175 struct ilo_state_raster_clip_info clip;
176 struct ilo_state_raster_setup_info setup;
177 struct ilo_state_raster_point_info point;
178 struct ilo_state_raster_line_info line;
179 struct ilo_state_raster_tri_info tri;
180 struct ilo_state_raster_scan_info scan;
181
182 struct ilo_state_raster_params_info params;
183 };
184
185 struct ilo_state_raster {
186 uint32_t clip[3];
187 uint32_t sf[3];
188 uint32_t raster[4];
189 uint32_t sample[2];
190 uint32_t wm[3];
191
192 bool line_aa_enable;
193 bool line_giq_enable;
194 };
195
196 struct ilo_state_raster_delta {
197 uint32_t dirty;
198 };
199
200 struct ilo_state_sample_pattern_offset_info {
201 /* in U0.4 */
202 uint8_t x;
203 uint8_t y;
204 };
205
206 struct ilo_state_sample_pattern_info {
207 struct ilo_state_sample_pattern_offset_info pattern_1x[1];
208 struct ilo_state_sample_pattern_offset_info pattern_2x[2];
209 struct ilo_state_sample_pattern_offset_info pattern_4x[4];
210 struct ilo_state_sample_pattern_offset_info pattern_8x[8];
211 struct ilo_state_sample_pattern_offset_info pattern_16x[16];
212 };
213
214 struct ilo_state_sample_pattern {
215 uint8_t pattern_1x[1];
216 uint8_t pattern_2x[2];
217 uint8_t pattern_4x[4];
218 uint8_t pattern_8x[8];
219 uint8_t pattern_16x[16];
220 };
221
222 bool
223 ilo_state_raster_init(struct ilo_state_raster *rs,
224 const struct ilo_dev *dev,
225 const struct ilo_state_raster_info *info);
226
227 bool
228 ilo_state_raster_init_for_rectlist(struct ilo_state_raster *rs,
229 const struct ilo_dev *dev,
230 uint8_t sample_count,
231 enum ilo_state_raster_earlyz_op earlyz_op,
232 bool earlyz_stencil_clear);
233
234 bool
235 ilo_state_raster_set_info(struct ilo_state_raster *rs,
236 const struct ilo_dev *dev,
237 const struct ilo_state_raster_info *info);
238
239 bool
240 ilo_state_raster_set_params(struct ilo_state_raster *rs,
241 const struct ilo_dev *dev,
242 const struct ilo_state_raster_params_info *params);
243
244 void
245 ilo_state_raster_full_delta(const struct ilo_state_raster *rs,
246 const struct ilo_dev *dev,
247 struct ilo_state_raster_delta *delta);
248
249 void
250 ilo_state_raster_get_delta(const struct ilo_state_raster *rs,
251 const struct ilo_dev *dev,
252 const struct ilo_state_raster *old,
253 struct ilo_state_raster_delta *delta);
254
255 bool
256 ilo_state_sample_pattern_init(struct ilo_state_sample_pattern *pattern,
257 const struct ilo_dev *dev,
258 const struct ilo_state_sample_pattern_info *info);
259
260 bool
261 ilo_state_sample_pattern_init_default(struct ilo_state_sample_pattern *pattern,
262 const struct ilo_dev *dev);
263
264 const uint8_t *
265 ilo_state_sample_pattern_get_packed_offsets(const struct ilo_state_sample_pattern *pattern,
266 const struct ilo_dev *dev,
267 uint8_t sample_count);
268
269 void
270 ilo_state_sample_pattern_get_offset(const struct ilo_state_sample_pattern *pattern,
271 const struct ilo_dev *dev,
272 uint8_t sample_count, uint8_t sample_index,
273 uint8_t *x, uint8_t *y);
274
275 #endif /* ILO_STATE_RASTER_H */