• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
3  Intel funded Tungsten Graphics to
4  develop this 3D driver.
5 
6  Permission is hereby granted, free of charge, to any person obtaining
7  a 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, sublicense, 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
16  portions of the Software.
17 
18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 
26  **********************************************************************/
27  /*
28   * Authors:
29   *   Keith Whitwell <keithw@vmware.com>
30   */
31 
32 #ifndef BRW_DEFINES_H
33 #define BRW_DEFINES_H
34 
35 #include "util/macros.h"
36 
37 #define INTEL_MASK(high, low) (((1u<<((high)-(low)+1))-1)<<(low))
38 /* Using the GNU statement expression extension */
39 #define SET_FIELD(value, field)                                         \
40    ({                                                                   \
41       uint32_t fieldval = (uint32_t)(value) << field ## _SHIFT;         \
42       assert((fieldval & ~ field ## _MASK) == 0);                       \
43       fieldval & field ## _MASK;                                        \
44    })
45 
46 #define GET_BITS(data, high, low) ((data & INTEL_MASK((high), (low))) >> (low))
47 #define GET_FIELD(word, field) (((word)  & field ## _MASK) >> field ## _SHIFT)
48 
49 /**
50  * For use with masked MMIO registers where the upper 16 bits control which
51  * of the lower bits are committed to the register.
52  */
53 #define REG_MASK(value) ((value) << 16)
54 
55 /* 3D state:
56  */
57 #define CMD_3D_PRIM                                 0x7b00 /* 3DPRIMITIVE */
58 /* DW0 */
59 # define GFX4_3DPRIM_TOPOLOGY_TYPE_SHIFT            10
60 # define GFX4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL (0 << 15)
61 # define GFX4_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM     (1 << 15)
62 # define GFX7_3DPRIM_INDIRECT_PARAMETER_ENABLE      (1 << 10)
63 # define GFX7_3DPRIM_PREDICATE_ENABLE               (1 << 8)
64 /* DW1 */
65 # define GFX7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL (0 << 8)
66 # define GFX7_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM     (1 << 8)
67 
68 #define BRW_ANISORATIO_2     0
69 #define BRW_ANISORATIO_4     1
70 #define BRW_ANISORATIO_6     2
71 #define BRW_ANISORATIO_8     3
72 #define BRW_ANISORATIO_10    4
73 #define BRW_ANISORATIO_12    5
74 #define BRW_ANISORATIO_14    6
75 #define BRW_ANISORATIO_16    7
76 
77 #define BRW_BLENDFACTOR_ONE                 0x1
78 #define BRW_BLENDFACTOR_SRC_COLOR           0x2
79 #define BRW_BLENDFACTOR_SRC_ALPHA           0x3
80 #define BRW_BLENDFACTOR_DST_ALPHA           0x4
81 #define BRW_BLENDFACTOR_DST_COLOR           0x5
82 #define BRW_BLENDFACTOR_SRC_ALPHA_SATURATE  0x6
83 #define BRW_BLENDFACTOR_CONST_COLOR         0x7
84 #define BRW_BLENDFACTOR_CONST_ALPHA         0x8
85 #define BRW_BLENDFACTOR_SRC1_COLOR          0x9
86 #define BRW_BLENDFACTOR_SRC1_ALPHA          0x0A
87 #define BRW_BLENDFACTOR_ZERO                0x11
88 #define BRW_BLENDFACTOR_INV_SRC_COLOR       0x12
89 #define BRW_BLENDFACTOR_INV_SRC_ALPHA       0x13
90 #define BRW_BLENDFACTOR_INV_DST_ALPHA       0x14
91 #define BRW_BLENDFACTOR_INV_DST_COLOR       0x15
92 #define BRW_BLENDFACTOR_INV_CONST_COLOR     0x17
93 #define BRW_BLENDFACTOR_INV_CONST_ALPHA     0x18
94 #define BRW_BLENDFACTOR_INV_SRC1_COLOR      0x19
95 #define BRW_BLENDFACTOR_INV_SRC1_ALPHA      0x1A
96 
97 #define BRW_BLENDFUNCTION_ADD               0
98 #define BRW_BLENDFUNCTION_SUBTRACT          1
99 #define BRW_BLENDFUNCTION_REVERSE_SUBTRACT  2
100 #define BRW_BLENDFUNCTION_MIN               3
101 #define BRW_BLENDFUNCTION_MAX               4
102 
103 #define BRW_ALPHATEST_FORMAT_UNORM8         0
104 #define BRW_ALPHATEST_FORMAT_FLOAT32        1
105 
106 #define BRW_CHROMAKEY_KILL_ON_ANY_MATCH  0
107 #define BRW_CHROMAKEY_REPLACE_BLACK      1
108 
109 #define BRW_CLIP_API_OGL     0
110 #define BRW_CLIP_API_DX      1
111 
112 #define BRW_CLIP_NDCSPACE     0
113 #define BRW_CLIP_SCREENSPACE  1
114 
115 #define BRW_COMPAREFUNCTION_ALWAYS       0
116 #define BRW_COMPAREFUNCTION_NEVER        1
117 #define BRW_COMPAREFUNCTION_LESS         2
118 #define BRW_COMPAREFUNCTION_EQUAL        3
119 #define BRW_COMPAREFUNCTION_LEQUAL       4
120 #define BRW_COMPAREFUNCTION_GREATER      5
121 #define BRW_COMPAREFUNCTION_NOTEQUAL     6
122 #define BRW_COMPAREFUNCTION_GEQUAL       7
123 
124 #define BRW_COVERAGE_PIXELS_HALF     0
125 #define BRW_COVERAGE_PIXELS_1        1
126 #define BRW_COVERAGE_PIXELS_2        2
127 #define BRW_COVERAGE_PIXELS_4        3
128 
129 #define BRW_CULLMODE_BOTH        0
130 #define BRW_CULLMODE_NONE        1
131 #define BRW_CULLMODE_FRONT       2
132 #define BRW_CULLMODE_BACK        3
133 
134 #define BRW_DEFAULTCOLOR_R8G8B8A8_UNORM      0
135 #define BRW_DEFAULTCOLOR_R32G32B32A32_FLOAT  1
136 
137 #define BRW_DEPTHFORMAT_D32_FLOAT_S8X24_UINT     0
138 #define BRW_DEPTHFORMAT_D32_FLOAT                1
139 #define BRW_DEPTHFORMAT_D24_UNORM_S8_UINT        2
140 #define BRW_DEPTHFORMAT_D24_UNORM_X8_UINT        3 /* GFX5 */
141 #define BRW_DEPTHFORMAT_D16_UNORM                5
142 
143 #define BRW_FLOATING_POINT_IEEE_754        0
144 #define BRW_FLOATING_POINT_NON_IEEE_754    1
145 
146 #define BRW_FRONTWINDING_CW      0
147 #define BRW_FRONTWINDING_CCW     1
148 
149 #define BRW_CUT_INDEX_ENABLE     (1 << 10)
150 
151 #define BRW_INDEX_BYTE     0
152 #define BRW_INDEX_WORD     1
153 #define BRW_INDEX_DWORD    2
154 
155 #define BRW_LOGICOPFUNCTION_CLEAR            0
156 #define BRW_LOGICOPFUNCTION_NOR              1
157 #define BRW_LOGICOPFUNCTION_AND_INVERTED     2
158 #define BRW_LOGICOPFUNCTION_COPY_INVERTED    3
159 #define BRW_LOGICOPFUNCTION_AND_REVERSE      4
160 #define BRW_LOGICOPFUNCTION_INVERT           5
161 #define BRW_LOGICOPFUNCTION_XOR              6
162 #define BRW_LOGICOPFUNCTION_NAND             7
163 #define BRW_LOGICOPFUNCTION_AND              8
164 #define BRW_LOGICOPFUNCTION_EQUIV            9
165 #define BRW_LOGICOPFUNCTION_NOOP             10
166 #define BRW_LOGICOPFUNCTION_OR_INVERTED      11
167 #define BRW_LOGICOPFUNCTION_COPY             12
168 #define BRW_LOGICOPFUNCTION_OR_REVERSE       13
169 #define BRW_LOGICOPFUNCTION_OR               14
170 #define BRW_LOGICOPFUNCTION_SET              15
171 
172 #define BRW_MAPFILTER_NEAREST        0x0
173 #define BRW_MAPFILTER_LINEAR         0x1
174 #define BRW_MAPFILTER_ANISOTROPIC    0x2
175 
176 #define BRW_MIPFILTER_NONE        0
177 #define BRW_MIPFILTER_NEAREST     1
178 #define BRW_MIPFILTER_LINEAR      3
179 
180 #define BRW_ADDRESS_ROUNDING_ENABLE_U_MAG	0x20
181 #define BRW_ADDRESS_ROUNDING_ENABLE_U_MIN	0x10
182 #define BRW_ADDRESS_ROUNDING_ENABLE_V_MAG	0x08
183 #define BRW_ADDRESS_ROUNDING_ENABLE_V_MIN	0x04
184 #define BRW_ADDRESS_ROUNDING_ENABLE_R_MAG	0x02
185 #define BRW_ADDRESS_ROUNDING_ENABLE_R_MIN	0x01
186 
187 #define BRW_PREFILTER_ALWAYS     0x0
188 #define BRW_PREFILTER_NEVER      0x1
189 #define BRW_PREFILTER_LESS       0x2
190 #define BRW_PREFILTER_EQUAL      0x3
191 #define BRW_PREFILTER_LEQUAL     0x4
192 #define BRW_PREFILTER_GREATER    0x5
193 #define BRW_PREFILTER_NOTEQUAL   0x6
194 #define BRW_PREFILTER_GEQUAL     0x7
195 
196 #define BRW_PROVOKING_VERTEX_0    0
197 #define BRW_PROVOKING_VERTEX_1    1
198 #define BRW_PROVOKING_VERTEX_2    2
199 
200 #define BRW_RASTRULE_UPPER_LEFT  0
201 #define BRW_RASTRULE_UPPER_RIGHT 1
202 /* These are listed as "Reserved, but not seen as useful"
203  * in Intel documentation (page 212, "Point Rasterization Rule",
204  * section 7.4 "SF Pipeline State Summary", of document
205  * "Intel® 965 Express Chipset Family and Intel® G35 Express
206  * Chipset Graphics Controller Programmer's Reference Manual,
207  * Volume 2: 3D/Media", Revision 1.0b as of January 2008,
208  * available at
209  *     https://01.org/linuxgraphics/documentation/hardware-specification-prms
210  * at the time of this writing).
211  *
212  * These appear to be supported on at least some
213  * i965-family devices, and the BRW_RASTRULE_LOWER_RIGHT
214  * is useful when using OpenGL to render to a FBO
215  * (which has the pixel coordinate Y orientation inverted
216  * with respect to the normal OpenGL pixel coordinate system).
217  */
218 #define BRW_RASTRULE_LOWER_LEFT  2
219 #define BRW_RASTRULE_LOWER_RIGHT 3
220 
221 #define BRW_RENDERTARGET_CLAMPRANGE_UNORM    0
222 #define BRW_RENDERTARGET_CLAMPRANGE_SNORM    1
223 #define BRW_RENDERTARGET_CLAMPRANGE_FORMAT   2
224 
225 #define BRW_STENCILOP_KEEP               0
226 #define BRW_STENCILOP_ZERO               1
227 #define BRW_STENCILOP_REPLACE            2
228 #define BRW_STENCILOP_INCRSAT            3
229 #define BRW_STENCILOP_DECRSAT            4
230 #define BRW_STENCILOP_INCR               5
231 #define BRW_STENCILOP_DECR               6
232 #define BRW_STENCILOP_INVERT             7
233 
234 /* Surface state DW0 */
235 #define GFX8_SURFACE_IS_ARRAY                       (1 << 28)
236 #define GFX8_SURFACE_VALIGN_4                       (1 << 16)
237 #define GFX8_SURFACE_VALIGN_8                       (2 << 16)
238 #define GFX8_SURFACE_VALIGN_16                      (3 << 16)
239 #define GFX8_SURFACE_HALIGN_4                       (1 << 14)
240 #define GFX8_SURFACE_HALIGN_8                       (2 << 14)
241 #define GFX8_SURFACE_HALIGN_16                      (3 << 14)
242 #define GFX8_SURFACE_TILING_NONE                    (0 << 12)
243 #define GFX8_SURFACE_TILING_W                       (1 << 12)
244 #define GFX8_SURFACE_TILING_X                       (2 << 12)
245 #define GFX8_SURFACE_TILING_Y                       (3 << 12)
246 #define GFX8_SURFACE_SAMPLER_L2_BYPASS_DISABLE      (1 << 9)
247 #define BRW_SURFACE_RC_READ_WRITE	(1 << 8)
248 #define BRW_SURFACE_MIPLAYOUT_SHIFT	10
249 #define BRW_SURFACE_MIPMAPLAYOUT_BELOW   0
250 #define BRW_SURFACE_MIPMAPLAYOUT_RIGHT   1
251 #define BRW_SURFACE_CUBEFACE_ENABLES	0x3f
252 #define BRW_SURFACE_BLEND_ENABLED	(1 << 13)
253 #define BRW_SURFACE_WRITEDISABLE_B_SHIFT	14
254 #define BRW_SURFACE_WRITEDISABLE_G_SHIFT	15
255 #define BRW_SURFACE_WRITEDISABLE_R_SHIFT	16
256 #define BRW_SURFACE_WRITEDISABLE_A_SHIFT	17
257 
258 #define GFX9_SURFACE_ASTC_HDR_FORMAT_BIT                 0x100
259 
260 #define BRW_SURFACE_FORMAT_SHIFT	18
261 #define BRW_SURFACE_FORMAT_MASK		INTEL_MASK(26, 18)
262 
263 #define BRW_SURFACERETURNFORMAT_FLOAT32  0
264 #define BRW_SURFACERETURNFORMAT_S1       1
265 
266 #define BRW_SURFACE_TYPE_SHIFT		29
267 #define BRW_SURFACE_TYPE_MASK		INTEL_MASK(31, 29)
268 #define BRW_SURFACE_1D      0
269 #define BRW_SURFACE_2D      1
270 #define BRW_SURFACE_3D      2
271 #define BRW_SURFACE_CUBE    3
272 #define BRW_SURFACE_BUFFER  4
273 #define BRW_SURFACE_NULL    7
274 
275 #define GFX7_SURFACE_IS_ARRAY           (1 << 28)
276 #define GFX7_SURFACE_VALIGN_2           (0 << 16)
277 #define GFX7_SURFACE_VALIGN_4           (1 << 16)
278 #define GFX7_SURFACE_HALIGN_4           (0 << 15)
279 #define GFX7_SURFACE_HALIGN_8           (1 << 15)
280 #define GFX7_SURFACE_TILING_NONE        (0 << 13)
281 #define GFX7_SURFACE_TILING_X           (2 << 13)
282 #define GFX7_SURFACE_TILING_Y           (3 << 13)
283 #define GFX7_SURFACE_ARYSPC_FULL	(0 << 10)
284 #define GFX7_SURFACE_ARYSPC_LOD0	(1 << 10)
285 
286 /* Surface state DW1 */
287 #define GFX8_SURFACE_MOCS_SHIFT         24
288 #define GFX8_SURFACE_MOCS_MASK          INTEL_MASK(30, 24)
289 #define GFX8_SURFACE_QPITCH_SHIFT       0
290 #define GFX8_SURFACE_QPITCH_MASK        INTEL_MASK(14, 0)
291 
292 /* Surface state DW2 */
293 #define BRW_SURFACE_HEIGHT_SHIFT	19
294 #define BRW_SURFACE_HEIGHT_MASK		INTEL_MASK(31, 19)
295 #define BRW_SURFACE_WIDTH_SHIFT		6
296 #define BRW_SURFACE_WIDTH_MASK		INTEL_MASK(18, 6)
297 #define BRW_SURFACE_LOD_SHIFT		2
298 #define BRW_SURFACE_LOD_MASK		INTEL_MASK(5, 2)
299 #define GFX7_SURFACE_HEIGHT_SHIFT       16
300 #define GFX7_SURFACE_HEIGHT_MASK        INTEL_MASK(29, 16)
301 #define GFX7_SURFACE_WIDTH_SHIFT        0
302 #define GFX7_SURFACE_WIDTH_MASK         INTEL_MASK(13, 0)
303 
304 /* Surface state DW3 */
305 #define BRW_SURFACE_DEPTH_SHIFT		21
306 #define BRW_SURFACE_DEPTH_MASK		INTEL_MASK(31, 21)
307 #define BRW_SURFACE_PITCH_SHIFT		3
308 #define BRW_SURFACE_PITCH_MASK		INTEL_MASK(19, 3)
309 #define BRW_SURFACE_TILED		(1 << 1)
310 #define BRW_SURFACE_TILED_Y		(1 << 0)
311 #define HSW_SURFACE_IS_INTEGER_FORMAT   (1 << 18)
312 
313 /* Surface state DW4 */
314 #define BRW_SURFACE_MIN_LOD_SHIFT	28
315 #define BRW_SURFACE_MIN_LOD_MASK	INTEL_MASK(31, 28)
316 #define BRW_SURFACE_MIN_ARRAY_ELEMENT_SHIFT	17
317 #define BRW_SURFACE_MIN_ARRAY_ELEMENT_MASK	INTEL_MASK(27, 17)
318 #define BRW_SURFACE_RENDER_TARGET_VIEW_EXTENT_SHIFT	8
319 #define BRW_SURFACE_RENDER_TARGET_VIEW_EXTENT_MASK	INTEL_MASK(16, 8)
320 #define BRW_SURFACE_MULTISAMPLECOUNT_1  (0 << 4)
321 #define BRW_SURFACE_MULTISAMPLECOUNT_4  (2 << 4)
322 #define GFX7_SURFACE_MULTISAMPLECOUNT_1         (0 << 3)
323 #define GFX8_SURFACE_MULTISAMPLECOUNT_2         (1 << 3)
324 #define GFX7_SURFACE_MULTISAMPLECOUNT_4         (2 << 3)
325 #define GFX7_SURFACE_MULTISAMPLECOUNT_8         (3 << 3)
326 #define GFX8_SURFACE_MULTISAMPLECOUNT_16        (4 << 3)
327 #define GFX7_SURFACE_MSFMT_MSS                  (0 << 6)
328 #define GFX7_SURFACE_MSFMT_DEPTH_STENCIL        (1 << 6)
329 #define GFX7_SURFACE_MIN_ARRAY_ELEMENT_SHIFT	18
330 #define GFX7_SURFACE_MIN_ARRAY_ELEMENT_MASK     INTEL_MASK(28, 18)
331 #define GFX7_SURFACE_RENDER_TARGET_VIEW_EXTENT_SHIFT	7
332 #define GFX7_SURFACE_RENDER_TARGET_VIEW_EXTENT_MASK   INTEL_MASK(17, 7)
333 
334 /* Surface state DW5 */
335 #define BRW_SURFACE_X_OFFSET_SHIFT		25
336 #define BRW_SURFACE_X_OFFSET_MASK		INTEL_MASK(31, 25)
337 #define BRW_SURFACE_VERTICAL_ALIGN_ENABLE	(1 << 24)
338 #define BRW_SURFACE_Y_OFFSET_SHIFT		20
339 #define BRW_SURFACE_Y_OFFSET_MASK		INTEL_MASK(23, 20)
340 #define GFX7_SURFACE_MIN_LOD_SHIFT              4
341 #define GFX7_SURFACE_MIN_LOD_MASK               INTEL_MASK(7, 4)
342 #define GFX8_SURFACE_Y_OFFSET_SHIFT		21
343 #define GFX8_SURFACE_Y_OFFSET_MASK		INTEL_MASK(23, 21)
344 
345 #define GFX7_SURFACE_MOCS_SHIFT                 16
346 #define GFX7_SURFACE_MOCS_MASK                  INTEL_MASK(19, 16)
347 
348 #define GFX9_SURFACE_MIP_TAIL_START_LOD_SHIFT      8
349 #define GFX9_SURFACE_MIP_TAIL_START_LOD_MASK       INTEL_MASK(11, 8)
350 
351 /* Surface state DW6 */
352 #define GFX7_SURFACE_MCS_ENABLE                 (1 << 0)
353 #define GFX7_SURFACE_MCS_PITCH_SHIFT            3
354 #define GFX7_SURFACE_MCS_PITCH_MASK             INTEL_MASK(11, 3)
355 #define GFX8_SURFACE_AUX_QPITCH_SHIFT           16
356 #define GFX8_SURFACE_AUX_QPITCH_MASK            INTEL_MASK(30, 16)
357 #define GFX8_SURFACE_AUX_PITCH_SHIFT            3
358 #define GFX8_SURFACE_AUX_PITCH_MASK             INTEL_MASK(11, 3)
359 #define GFX8_SURFACE_AUX_MODE_MASK              INTEL_MASK(2, 0)
360 
361 #define GFX8_SURFACE_AUX_MODE_NONE              0
362 #define GFX8_SURFACE_AUX_MODE_MCS               1
363 #define GFX8_SURFACE_AUX_MODE_APPEND            2
364 #define GFX8_SURFACE_AUX_MODE_HIZ               3
365 #define GFX9_SURFACE_AUX_MODE_CCS_E             5
366 
367 /* Surface state DW7 */
368 #define GFX9_SURFACE_RT_COMPRESSION_SHIFT       30
369 #define GFX9_SURFACE_RT_COMPRESSION_MASK        INTEL_MASK(30, 30)
370 #define GFX7_SURFACE_CLEAR_COLOR_SHIFT		28
371 #define GFX7_SURFACE_SCS_R_SHIFT                25
372 #define GFX7_SURFACE_SCS_R_MASK                 INTEL_MASK(27, 25)
373 #define GFX7_SURFACE_SCS_G_SHIFT                22
374 #define GFX7_SURFACE_SCS_G_MASK                 INTEL_MASK(24, 22)
375 #define GFX7_SURFACE_SCS_B_SHIFT                19
376 #define GFX7_SURFACE_SCS_B_MASK                 INTEL_MASK(21, 19)
377 #define GFX7_SURFACE_SCS_A_SHIFT                16
378 #define GFX7_SURFACE_SCS_A_MASK                 INTEL_MASK(18, 16)
379 
380 /* The actual swizzle values/what channel to use */
381 #define HSW_SCS_ZERO                     0
382 #define HSW_SCS_ONE                      1
383 #define HSW_SCS_RED                      4
384 #define HSW_SCS_GREEN                    5
385 #define HSW_SCS_BLUE                     6
386 #define HSW_SCS_ALPHA                    7
387 
388 /* SAMPLER_STATE DW0 */
389 #define BRW_SAMPLER_DISABLE                     (1 << 31)
390 #define BRW_SAMPLER_LOD_PRECLAMP_ENABLE         (1 << 28)
391 #define GFX6_SAMPLER_MIN_MAG_NOT_EQUAL          (1 << 27) /* Gfx6 only */
392 #define BRW_SAMPLER_BASE_MIPLEVEL_MASK          INTEL_MASK(26, 22)
393 #define BRW_SAMPLER_BASE_MIPLEVEL_SHIFT         22
394 #define BRW_SAMPLER_MIP_FILTER_MASK             INTEL_MASK(21, 20)
395 #define BRW_SAMPLER_MIP_FILTER_SHIFT            20
396 #define BRW_SAMPLER_MAG_FILTER_MASK             INTEL_MASK(19, 17)
397 #define BRW_SAMPLER_MAG_FILTER_SHIFT            17
398 #define BRW_SAMPLER_MIN_FILTER_MASK             INTEL_MASK(16, 14)
399 #define BRW_SAMPLER_MIN_FILTER_SHIFT            14
400 #define GFX4_SAMPLER_LOD_BIAS_MASK              INTEL_MASK(13, 3)
401 #define GFX4_SAMPLER_LOD_BIAS_SHIFT             3
402 #define GFX4_SAMPLER_SHADOW_FUNCTION_MASK       INTEL_MASK(2, 0)
403 #define GFX4_SAMPLER_SHADOW_FUNCTION_SHIFT      0
404 
405 #define GFX7_SAMPLER_LOD_BIAS_MASK              INTEL_MASK(13, 1)
406 #define GFX7_SAMPLER_LOD_BIAS_SHIFT             1
407 #define GFX7_SAMPLER_EWA_ANISOTROPIC_ALGORITHM  (1 << 0)
408 
409 /* SAMPLER_STATE DW1 */
410 #define GFX4_SAMPLER_MIN_LOD_MASK               INTEL_MASK(31, 22)
411 #define GFX4_SAMPLER_MIN_LOD_SHIFT              22
412 #define GFX4_SAMPLER_MAX_LOD_MASK               INTEL_MASK(21, 12)
413 #define GFX4_SAMPLER_MAX_LOD_SHIFT              12
414 #define GFX4_SAMPLER_CUBE_CONTROL_OVERRIDE      (1 << 9)
415 /* Wrap modes are in DW1 on Gfx4-6 and DW3 on Gfx7+ */
416 #define BRW_SAMPLER_TCX_WRAP_MODE_MASK          INTEL_MASK(8, 6)
417 #define BRW_SAMPLER_TCX_WRAP_MODE_SHIFT         6
418 #define BRW_SAMPLER_TCY_WRAP_MODE_MASK          INTEL_MASK(5, 3)
419 #define BRW_SAMPLER_TCY_WRAP_MODE_SHIFT         3
420 #define BRW_SAMPLER_TCZ_WRAP_MODE_MASK          INTEL_MASK(2, 0)
421 #define BRW_SAMPLER_TCZ_WRAP_MODE_SHIFT         0
422 
423 #define GFX7_SAMPLER_MIN_LOD_MASK               INTEL_MASK(31, 20)
424 #define GFX7_SAMPLER_MIN_LOD_SHIFT              20
425 #define GFX7_SAMPLER_MAX_LOD_MASK               INTEL_MASK(19, 8)
426 #define GFX7_SAMPLER_MAX_LOD_SHIFT              8
427 #define GFX7_SAMPLER_SHADOW_FUNCTION_MASK       INTEL_MASK(3, 1)
428 #define GFX7_SAMPLER_SHADOW_FUNCTION_SHIFT      1
429 #define GFX7_SAMPLER_CUBE_CONTROL_OVERRIDE      (1 << 0)
430 
431 /* SAMPLER_STATE DW2 - border color pointer */
432 
433 /* SAMPLER_STATE DW3 */
434 #define BRW_SAMPLER_MAX_ANISOTROPY_MASK         INTEL_MASK(21, 19)
435 #define BRW_SAMPLER_MAX_ANISOTROPY_SHIFT        19
436 #define BRW_SAMPLER_ADDRESS_ROUNDING_MASK       INTEL_MASK(18, 13)
437 #define BRW_SAMPLER_ADDRESS_ROUNDING_SHIFT      13
438 #define GFX7_SAMPLER_NON_NORMALIZED_COORDINATES (1 << 10)
439 /* Gfx7+ wrap modes reuse the same BRW_SAMPLER_TC*_WRAP_MODE enums. */
440 #define GFX6_SAMPLER_NON_NORMALIZED_COORDINATES (1 << 0)
441 
442 enum brw_wrap_mode {
443    BRW_TEXCOORDMODE_WRAP         = 0,
444    BRW_TEXCOORDMODE_MIRROR       = 1,
445    BRW_TEXCOORDMODE_CLAMP        = 2,
446    BRW_TEXCOORDMODE_CUBE         = 3,
447    BRW_TEXCOORDMODE_CLAMP_BORDER = 4,
448    BRW_TEXCOORDMODE_MIRROR_ONCE  = 5,
449    GFX8_TEXCOORDMODE_HALF_BORDER = 6,
450 };
451 
452 #define BRW_THREAD_PRIORITY_NORMAL   0
453 #define BRW_THREAD_PRIORITY_HIGH     1
454 
455 #define BRW_TILEWALK_XMAJOR                 0
456 #define BRW_TILEWALK_YMAJOR                 1
457 
458 #define BRW_VERTEX_SUBPIXEL_PRECISION_8BITS  0
459 #define BRW_VERTEX_SUBPIXEL_PRECISION_4BITS  1
460 
461 
462 #define CMD_URB_FENCE                 0x6000
463 #define CMD_CS_URB_STATE              0x6001
464 #define CMD_CONST_BUFFER              0x6002
465 
466 #define CMD_STATE_BASE_ADDRESS        0x6101
467 #define CMD_STATE_SIP                 0x6102
468 #define CMD_PIPELINE_SELECT_965       0x6104
469 #define CMD_PIPELINE_SELECT_GM45      0x6904
470 
471 #define _3DSTATE_PIPELINED_POINTERS		0x7800
472 #define _3DSTATE_BINDING_TABLE_POINTERS		0x7801
473 # define GFX6_BINDING_TABLE_MODIFY_VS	(1 << 8)
474 # define GFX6_BINDING_TABLE_MODIFY_GS	(1 << 9)
475 # define GFX6_BINDING_TABLE_MODIFY_PS	(1 << 12)
476 
477 #define _3DSTATE_BINDING_TABLE_POINTERS_VS	0x7826 /* GFX7+ */
478 #define _3DSTATE_BINDING_TABLE_POINTERS_HS	0x7827 /* GFX7+ */
479 #define _3DSTATE_BINDING_TABLE_POINTERS_DS	0x7828 /* GFX7+ */
480 #define _3DSTATE_BINDING_TABLE_POINTERS_GS	0x7829 /* GFX7+ */
481 #define _3DSTATE_BINDING_TABLE_POINTERS_PS	0x782A /* GFX7+ */
482 
483 #define _3DSTATE_SAMPLER_STATE_POINTERS		0x7802 /* GFX6+ */
484 # define PS_SAMPLER_STATE_CHANGE				(1 << 12)
485 # define GS_SAMPLER_STATE_CHANGE				(1 << 9)
486 # define VS_SAMPLER_STATE_CHANGE				(1 << 8)
487 /* DW1: VS */
488 /* DW2: GS */
489 /* DW3: PS */
490 
491 #define _3DSTATE_SAMPLER_STATE_POINTERS_VS	0x782B /* GFX7+ */
492 #define _3DSTATE_SAMPLER_STATE_POINTERS_HS	0x782C /* GFX7+ */
493 #define _3DSTATE_SAMPLER_STATE_POINTERS_DS	0x782D /* GFX7+ */
494 #define _3DSTATE_SAMPLER_STATE_POINTERS_GS	0x782E /* GFX7+ */
495 #define _3DSTATE_SAMPLER_STATE_POINTERS_PS	0x782F /* GFX7+ */
496 
497 #define _3DSTATE_VERTEX_BUFFERS       0x7808
498 # define BRW_VB0_INDEX_SHIFT		27
499 # define GFX6_VB0_INDEX_SHIFT		26
500 # define BRW_VB0_ACCESS_VERTEXDATA	(0 << 26)
501 # define BRW_VB0_ACCESS_INSTANCEDATA	(1 << 26)
502 # define GFX6_VB0_ACCESS_VERTEXDATA	(0 << 20)
503 # define GFX6_VB0_ACCESS_INSTANCEDATA	(1 << 20)
504 # define GFX7_VB0_ADDRESS_MODIFYENABLE  (1 << 14)
505 # define BRW_VB0_PITCH_SHIFT		0
506 
507 #define _3DSTATE_VERTEX_ELEMENTS      0x7809
508 # define BRW_VE0_INDEX_SHIFT		27
509 # define GFX6_VE0_INDEX_SHIFT		26
510 # define BRW_VE0_FORMAT_SHIFT		16
511 # define BRW_VE0_VALID			(1 << 26)
512 # define GFX6_VE0_VALID			(1 << 25)
513 # define GFX6_VE0_EDGE_FLAG_ENABLE	(1 << 15)
514 # define BRW_VE0_SRC_OFFSET_SHIFT	0
515 # define BRW_VE1_COMPONENT_NOSTORE	0
516 # define BRW_VE1_COMPONENT_STORE_SRC	1
517 # define BRW_VE1_COMPONENT_STORE_0	2
518 # define BRW_VE1_COMPONENT_STORE_1_FLT	3
519 # define BRW_VE1_COMPONENT_STORE_1_INT	4
520 # define BRW_VE1_COMPONENT_STORE_VID	5
521 # define BRW_VE1_COMPONENT_STORE_IID	6
522 # define BRW_VE1_COMPONENT_STORE_PID	7
523 # define BRW_VE1_COMPONENT_0_SHIFT	28
524 # define BRW_VE1_COMPONENT_1_SHIFT	24
525 # define BRW_VE1_COMPONENT_2_SHIFT	20
526 # define BRW_VE1_COMPONENT_3_SHIFT	16
527 # define BRW_VE1_DST_OFFSET_SHIFT	0
528 
529 #define CMD_INDEX_BUFFER              0x780a
530 #define GFX4_3DSTATE_VF_STATISTICS		0x780b
531 #define GM45_3DSTATE_VF_STATISTICS		0x680b
532 #define _3DSTATE_CC_STATE_POINTERS		0x780e /* GFX6+ */
533 #define _3DSTATE_BLEND_STATE_POINTERS		0x7824 /* GFX7+ */
534 #define _3DSTATE_DEPTH_STENCIL_STATE_POINTERS	0x7825 /* GFX7+ */
535 
536 #define _3DSTATE_URB				0x7805 /* GFX6 */
537 # define GFX6_URB_VS_SIZE_SHIFT				16
538 # define GFX6_URB_VS_ENTRIES_SHIFT			0
539 # define GFX6_URB_GS_ENTRIES_SHIFT			8
540 # define GFX6_URB_GS_SIZE_SHIFT				0
541 
542 #define _3DSTATE_VF                             0x780c /* GFX7.5+ */
543 #define HSW_CUT_INDEX_ENABLE                            (1 << 8)
544 
545 #define _3DSTATE_VF_INSTANCING                  0x7849 /* GFX8+ */
546 # define GFX8_VF_INSTANCING_ENABLE                      (1 << 8)
547 
548 #define _3DSTATE_VF_SGVS                        0x784a /* GFX8+ */
549 # define GFX8_SGVS_ENABLE_INSTANCE_ID                   (1 << 31)
550 # define GFX8_SGVS_INSTANCE_ID_COMPONENT_SHIFT          29
551 # define GFX8_SGVS_INSTANCE_ID_ELEMENT_OFFSET_SHIFT     16
552 # define GFX8_SGVS_ENABLE_VERTEX_ID                     (1 << 15)
553 # define GFX8_SGVS_VERTEX_ID_COMPONENT_SHIFT            13
554 # define GFX8_SGVS_VERTEX_ID_ELEMENT_OFFSET_SHIFT       0
555 
556 #define _3DSTATE_VF_TOPOLOGY                    0x784b /* GFX8+ */
557 
558 #define _3DSTATE_WM_CHROMAKEY			0x784c /* GFX8+ */
559 
560 #define _3DSTATE_URB_VS                         0x7830 /* GFX7+ */
561 #define _3DSTATE_URB_HS                         0x7831 /* GFX7+ */
562 #define _3DSTATE_URB_DS                         0x7832 /* GFX7+ */
563 #define _3DSTATE_URB_GS                         0x7833 /* GFX7+ */
564 # define GFX7_URB_ENTRY_SIZE_SHIFT                      16
565 # define GFX7_URB_STARTING_ADDRESS_SHIFT                25
566 
567 #define _3DSTATE_PUSH_CONSTANT_ALLOC_VS         0x7912 /* GFX7+ */
568 #define _3DSTATE_PUSH_CONSTANT_ALLOC_HS         0x7913 /* GFX7+ */
569 #define _3DSTATE_PUSH_CONSTANT_ALLOC_DS         0x7914 /* GFX7+ */
570 #define _3DSTATE_PUSH_CONSTANT_ALLOC_GS         0x7915 /* GFX7+ */
571 #define _3DSTATE_PUSH_CONSTANT_ALLOC_PS         0x7916 /* GFX7+ */
572 # define GFX7_PUSH_CONSTANT_BUFFER_OFFSET_SHIFT         16
573 
574 #define _3DSTATE_VIEWPORT_STATE_POINTERS	0x780d /* GFX6+ */
575 # define GFX6_CC_VIEWPORT_MODIFY			(1 << 12)
576 # define GFX6_SF_VIEWPORT_MODIFY			(1 << 11)
577 # define GFX6_CLIP_VIEWPORT_MODIFY			(1 << 10)
578 # define GFX6_NUM_VIEWPORTS				16
579 
580 #define _3DSTATE_VIEWPORT_STATE_POINTERS_CC	0x7823 /* GFX7+ */
581 #define _3DSTATE_VIEWPORT_STATE_POINTERS_SF_CL	0x7821 /* GFX7+ */
582 
583 #define _3DSTATE_SCISSOR_STATE_POINTERS		0x780f /* GFX6+ */
584 
585 #define _3DSTATE_VS				0x7810 /* GFX6+ */
586 /* DW2 */
587 # define GFX6_VS_SPF_MODE				(1 << 31)
588 # define GFX6_VS_VECTOR_MASK_ENABLE			(1 << 30)
589 # define GFX6_VS_SAMPLER_COUNT_SHIFT			27
590 # define GFX6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT	18
591 # define GFX6_VS_FLOATING_POINT_MODE_IEEE_754		(0 << 16)
592 # define GFX6_VS_FLOATING_POINT_MODE_ALT		(1 << 16)
593 # define HSW_VS_UAV_ACCESS_ENABLE                       (1 << 12)
594 /* DW4 */
595 # define GFX6_VS_DISPATCH_START_GRF_SHIFT		20
596 # define GFX6_VS_URB_READ_LENGTH_SHIFT			11
597 # define GFX6_VS_URB_ENTRY_READ_OFFSET_SHIFT		4
598 /* DW5 */
599 # define GFX6_VS_MAX_THREADS_SHIFT			25
600 # define HSW_VS_MAX_THREADS_SHIFT			23
601 # define GFX6_VS_STATISTICS_ENABLE			(1 << 10)
602 # define GFX6_VS_CACHE_DISABLE				(1 << 1)
603 # define GFX6_VS_ENABLE					(1 << 0)
604 /* Gfx8+ DW7 */
605 # define GFX8_VS_SIMD8_ENABLE                           (1 << 2)
606 /* Gfx8+ DW8 */
607 # define GFX8_VS_URB_ENTRY_OUTPUT_OFFSET_SHIFT          21
608 # define GFX8_VS_URB_OUTPUT_LENGTH_SHIFT                16
609 # define GFX8_VS_USER_CLIP_DISTANCE_SHIFT               8
610 
611 #define _3DSTATE_GS		      		0x7811 /* GFX6+ */
612 /* DW2 */
613 # define GFX6_GS_SPF_MODE				(1 << 31)
614 # define GFX6_GS_VECTOR_MASK_ENABLE			(1 << 30)
615 # define GFX6_GS_SAMPLER_COUNT_SHIFT			27
616 # define GFX6_GS_BINDING_TABLE_ENTRY_COUNT_SHIFT	18
617 # define GFX6_GS_FLOATING_POINT_MODE_IEEE_754		(0 << 16)
618 # define GFX6_GS_FLOATING_POINT_MODE_ALT		(1 << 16)
619 # define HSW_GS_UAV_ACCESS_ENABLE       		(1 << 12)
620 /* DW4 */
621 # define GFX7_GS_OUTPUT_VERTEX_SIZE_SHIFT		23
622 # define GFX7_GS_OUTPUT_TOPOLOGY_SHIFT			17
623 # define GFX6_GS_URB_READ_LENGTH_SHIFT			11
624 # define GFX7_GS_INCLUDE_VERTEX_HANDLES		        (1 << 10)
625 # define GFX6_GS_URB_ENTRY_READ_OFFSET_SHIFT		4
626 # define GFX6_GS_DISPATCH_START_GRF_SHIFT		0
627 /* DW5 */
628 # define GFX6_GS_MAX_THREADS_SHIFT			25
629 # define HSW_GS_MAX_THREADS_SHIFT			24
630 # define IVB_GS_CONTROL_DATA_FORMAT_SHIFT		24
631 # define GFX7_GS_CONTROL_DATA_FORMAT_GSCTL_CUT		0
632 # define GFX7_GS_CONTROL_DATA_FORMAT_GSCTL_SID		1
633 # define GFX7_GS_CONTROL_DATA_HEADER_SIZE_SHIFT		20
634 # define GFX7_GS_INSTANCE_CONTROL_SHIFT			15
635 # define GFX7_GS_DISPATCH_MODE_SHIFT                    11
636 # define GFX7_GS_DISPATCH_MODE_MASK                     INTEL_MASK(12, 11)
637 # define GFX6_GS_STATISTICS_ENABLE			(1 << 10)
638 # define GFX6_GS_SO_STATISTICS_ENABLE			(1 << 9)
639 # define GFX6_GS_RENDERING_ENABLE			(1 << 8)
640 # define GFX7_GS_INCLUDE_PRIMITIVE_ID			(1 << 4)
641 # define GFX7_GS_REORDER_TRAILING			(1 << 2)
642 # define GFX7_GS_ENABLE					(1 << 0)
643 /* DW6 */
644 # define HSW_GS_CONTROL_DATA_FORMAT_SHIFT		31
645 # define GFX6_GS_REORDER				(1 << 30)
646 # define GFX6_GS_DISCARD_ADJACENCY			(1 << 29)
647 # define GFX6_GS_SVBI_PAYLOAD_ENABLE			(1 << 28)
648 # define GFX6_GS_SVBI_POSTINCREMENT_ENABLE		(1 << 27)
649 # define GFX6_GS_SVBI_POSTINCREMENT_VALUE_SHIFT		16
650 # define GFX6_GS_SVBI_POSTINCREMENT_VALUE_MASK		INTEL_MASK(25, 16)
651 # define GFX6_GS_ENABLE					(1 << 15)
652 
653 /* Gfx8+ DW8 */
654 # define GFX8_GS_STATIC_OUTPUT                          (1 << 30)
655 # define GFX8_GS_STATIC_VERTEX_COUNT_SHIFT              16
656 # define GFX8_GS_STATIC_VERTEX_COUNT_MASK               INTEL_MASK(26, 16)
657 
658 /* Gfx8+ DW9 */
659 # define GFX8_GS_URB_ENTRY_OUTPUT_OFFSET_SHIFT          21
660 # define GFX8_GS_URB_OUTPUT_LENGTH_SHIFT                16
661 # define GFX8_GS_USER_CLIP_DISTANCE_SHIFT               8
662 
663 # define BRW_GS_EDGE_INDICATOR_0			(1 << 8)
664 # define BRW_GS_EDGE_INDICATOR_1			(1 << 9)
665 
666 #define _3DSTATE_HS                             0x781B /* GFX7+ */
667 /* DW1 */
668 # define GFX7_HS_SAMPLER_COUNT_MASK                     INTEL_MASK(29, 27)
669 # define GFX7_HS_SAMPLER_COUNT_SHIFT                    27
670 # define GFX7_HS_BINDING_TABLE_ENTRY_COUNT_MASK         INTEL_MASK(25, 18)
671 # define GFX7_HS_BINDING_TABLE_ENTRY_COUNT_SHIFT        18
672 # define GFX7_HS_FLOATING_POINT_MODE_IEEE_754           (0 << 16)
673 # define GFX7_HS_FLOATING_POINT_MODE_ALT                (1 << 16)
674 # define GFX7_HS_MAX_THREADS_SHIFT                      0
675 /* DW2 */
676 # define GFX7_HS_ENABLE                                 (1 << 31)
677 # define GFX7_HS_STATISTICS_ENABLE                      (1 << 29)
678 # define GFX8_HS_MAX_THREADS_SHIFT                      8
679 # define GFX7_HS_INSTANCE_COUNT_MASK                    INTEL_MASK(3, 0)
680 # define GFX7_HS_INSTANCE_COUNT_SHIFT                   0
681 /* DW5 */
682 # define GFX7_HS_SINGLE_PROGRAM_FLOW                    (1 << 27)
683 # define GFX7_HS_VECTOR_MASK_ENABLE                     (1 << 26)
684 # define HSW_HS_ACCESSES_UAV                            (1 << 25)
685 # define GFX7_HS_INCLUDE_VERTEX_HANDLES                 (1 << 24)
686 # define GFX7_HS_DISPATCH_START_GRF_MASK                INTEL_MASK(23, 19)
687 # define GFX7_HS_DISPATCH_START_GRF_SHIFT               19
688 # define GFX7_HS_URB_READ_LENGTH_MASK                   INTEL_MASK(16, 11)
689 # define GFX7_HS_URB_READ_LENGTH_SHIFT                  11
690 # define GFX7_HS_URB_ENTRY_READ_OFFSET_MASK             INTEL_MASK(9, 4)
691 # define GFX7_HS_URB_ENTRY_READ_OFFSET_SHIFT            4
692 
693 #define _3DSTATE_TE                             0x781C /* GFX7+ */
694 /* DW1 */
695 # define GFX7_TE_PARTITIONING_SHIFT                     12
696 # define GFX7_TE_OUTPUT_TOPOLOGY_SHIFT                  8
697 # define GFX7_TE_DOMAIN_SHIFT                           4
698 //# define GFX7_TE_MODE_SW                                (1 << 1)
699 # define GFX7_TE_ENABLE                                 (1 << 0)
700 
701 #define _3DSTATE_DS                             0x781D /* GFX7+ */
702 /* DW2 */
703 # define GFX7_DS_SINGLE_DOMAIN_POINT_DISPATCH           (1 << 31)
704 # define GFX7_DS_VECTOR_MASK_ENABLE                     (1 << 30)
705 # define GFX7_DS_SAMPLER_COUNT_MASK                     INTEL_MASK(29, 27)
706 # define GFX7_DS_SAMPLER_COUNT_SHIFT                    27
707 # define GFX7_DS_BINDING_TABLE_ENTRY_COUNT_MASK         INTEL_MASK(25, 18)
708 # define GFX7_DS_BINDING_TABLE_ENTRY_COUNT_SHIFT        18
709 # define GFX7_DS_FLOATING_POINT_MODE_IEEE_754           (0 << 16)
710 # define GFX7_DS_FLOATING_POINT_MODE_ALT                (1 << 16)
711 # define HSW_DS_ACCESSES_UAV                            (1 << 14)
712 /* DW4 */
713 # define GFX7_DS_DISPATCH_START_GRF_MASK                INTEL_MASK(24, 20)
714 # define GFX7_DS_DISPATCH_START_GRF_SHIFT               20
715 # define GFX7_DS_URB_READ_LENGTH_MASK                   INTEL_MASK(17, 11)
716 # define GFX7_DS_URB_READ_LENGTH_SHIFT                  11
717 # define GFX7_DS_URB_ENTRY_READ_OFFSET_MASK             INTEL_MASK(9, 4)
718 # define GFX7_DS_URB_ENTRY_READ_OFFSET_SHIFT            4
719 /* DW5 */
720 # define GFX7_DS_MAX_THREADS_SHIFT                      25
721 # define HSW_DS_MAX_THREADS_SHIFT                       21
722 # define GFX7_DS_STATISTICS_ENABLE                      (1 << 10)
723 # define GFX7_DS_SIMD8_DISPATCH_ENABLE                  (1 << 3)
724 # define GFX7_DS_COMPUTE_W_COORDINATE_ENABLE            (1 << 2)
725 # define GFX7_DS_CACHE_DISABLE                          (1 << 1)
726 # define GFX7_DS_ENABLE                                 (1 << 0)
727 /* Gfx8+ DW8 */
728 # define GFX8_DS_URB_ENTRY_OUTPUT_OFFSET_MASK           INTEL_MASK(26, 21)
729 # define GFX8_DS_URB_ENTRY_OUTPUT_OFFSET_SHIFT          21
730 # define GFX8_DS_URB_OUTPUT_LENGTH_MASK                 INTEL_MASK(20, 16)
731 # define GFX8_DS_URB_OUTPUT_LENGTH_SHIFT                16
732 # define GFX8_DS_USER_CLIP_DISTANCE_MASK                INTEL_MASK(15, 8)
733 # define GFX8_DS_USER_CLIP_DISTANCE_SHIFT               8
734 # define GFX8_DS_USER_CULL_DISTANCE_MASK                INTEL_MASK(7, 0)
735 # define GFX8_DS_USER_CULL_DISTANCE_SHIFT               0
736 
737 
738 #define _3DSTATE_CLIP				0x7812 /* GFX6+ */
739 /* DW1 */
740 # define GFX7_CLIP_WINDING_CW                           (0 << 20)
741 # define GFX7_CLIP_WINDING_CCW                          (1 << 20)
742 # define GFX7_CLIP_VERTEX_SUBPIXEL_PRECISION_8          (0 << 19)
743 # define GFX7_CLIP_VERTEX_SUBPIXEL_PRECISION_4          (1 << 19)
744 # define GFX7_CLIP_EARLY_CULL                           (1 << 18)
745 # define GFX8_CLIP_FORCE_USER_CLIP_DISTANCE_BITMASK     (1 << 17)
746 # define GFX7_CLIP_CULLMODE_BOTH                        (0 << 16)
747 # define GFX7_CLIP_CULLMODE_NONE                        (1 << 16)
748 # define GFX7_CLIP_CULLMODE_FRONT                       (2 << 16)
749 # define GFX7_CLIP_CULLMODE_BACK                        (3 << 16)
750 # define GFX6_CLIP_STATISTICS_ENABLE			(1 << 10)
751 /**
752  * Just does cheap culling based on the clip distance.  Bits must be
753  * disjoint with USER_CLIP_CLIP_DISTANCE bits.
754  */
755 # define GFX6_USER_CLIP_CULL_DISTANCES_SHIFT		0
756 /* DW2 */
757 # define GFX6_CLIP_ENABLE				(1 << 31)
758 # define GFX6_CLIP_API_OGL				(0 << 30)
759 # define GFX6_CLIP_API_D3D				(1 << 30)
760 # define GFX6_CLIP_XY_TEST				(1 << 28)
761 # define GFX6_CLIP_Z_TEST				(1 << 27)
762 # define GFX6_CLIP_GB_TEST				(1 << 26)
763 /** 8-bit field of which user clip distances to clip aganist. */
764 # define GFX6_USER_CLIP_CLIP_DISTANCES_SHIFT		16
765 # define GFX6_CLIP_MODE_NORMAL				(0 << 13)
766 # define GFX6_CLIP_MODE_REJECT_ALL			(3 << 13)
767 # define GFX6_CLIP_MODE_ACCEPT_ALL			(4 << 13)
768 # define GFX6_CLIP_PERSPECTIVE_DIVIDE_DISABLE		(1 << 9)
769 # define GFX6_CLIP_NON_PERSPECTIVE_BARYCENTRIC_ENABLE	(1 << 8)
770 # define GFX6_CLIP_TRI_PROVOKE_SHIFT			4
771 # define GFX6_CLIP_LINE_PROVOKE_SHIFT			2
772 # define GFX6_CLIP_TRIFAN_PROVOKE_SHIFT			0
773 /* DW3 */
774 # define GFX6_CLIP_MIN_POINT_WIDTH_SHIFT		17
775 # define GFX6_CLIP_MAX_POINT_WIDTH_SHIFT		6
776 # define GFX6_CLIP_FORCE_ZERO_RTAINDEX			(1 << 5)
777 # define GFX6_CLIP_MAX_VP_INDEX_MASK			INTEL_MASK(3, 0)
778 
779 #define _3DSTATE_SF				0x7813 /* GFX6+ */
780 /* DW1 (for gfx6) */
781 # define GFX6_SF_NUM_OUTPUTS_SHIFT			22
782 # define GFX6_SF_SWIZZLE_ENABLE				(1 << 21)
783 # define GFX6_SF_POINT_SPRITE_UPPERLEFT			(0 << 20)
784 # define GFX6_SF_POINT_SPRITE_LOWERLEFT			(1 << 20)
785 # define GFX9_SF_LINE_WIDTH_SHIFT			12 /* U11.7 */
786 # define GFX6_SF_URB_ENTRY_READ_LENGTH_SHIFT		11
787 # define GFX6_SF_URB_ENTRY_READ_OFFSET_SHIFT		4
788 /* DW2 */
789 # define GFX6_SF_LEGACY_GLOBAL_DEPTH_BIAS		(1 << 11)
790 # define GFX6_SF_STATISTICS_ENABLE			(1 << 10)
791 # define GFX6_SF_GLOBAL_DEPTH_OFFSET_SOLID		(1 << 9)
792 # define GFX6_SF_GLOBAL_DEPTH_OFFSET_WIREFRAME		(1 << 8)
793 # define GFX6_SF_GLOBAL_DEPTH_OFFSET_POINT		(1 << 7)
794 # define GFX6_SF_FRONT_SOLID				(0 << 5)
795 # define GFX6_SF_FRONT_WIREFRAME			(1 << 5)
796 # define GFX6_SF_FRONT_POINT				(2 << 5)
797 # define GFX6_SF_BACK_SOLID				(0 << 3)
798 # define GFX6_SF_BACK_WIREFRAME				(1 << 3)
799 # define GFX6_SF_BACK_POINT				(2 << 3)
800 # define GFX6_SF_VIEWPORT_TRANSFORM_ENABLE		(1 << 1)
801 # define GFX6_SF_WINDING_CCW				(1 << 0)
802 /* DW3 */
803 # define GFX6_SF_LINE_AA_ENABLE				(1 << 31)
804 # define GFX6_SF_CULL_BOTH				(0 << 29)
805 # define GFX6_SF_CULL_NONE				(1 << 29)
806 # define GFX6_SF_CULL_FRONT				(2 << 29)
807 # define GFX6_SF_CULL_BACK				(3 << 29)
808 # define GFX6_SF_LINE_WIDTH_SHIFT			18 /* U3.7 */
809 # define GFX6_SF_LINE_END_CAP_WIDTH_0_5			(0 << 16)
810 # define GFX6_SF_LINE_END_CAP_WIDTH_1_0			(1 << 16)
811 # define GFX6_SF_LINE_END_CAP_WIDTH_2_0			(2 << 16)
812 # define GFX6_SF_LINE_END_CAP_WIDTH_4_0			(3 << 16)
813 # define GFX6_SF_SCISSOR_ENABLE				(1 << 11)
814 # define GFX6_SF_MSRAST_OFF_PIXEL			(0 << 8)
815 # define GFX6_SF_MSRAST_OFF_PATTERN			(1 << 8)
816 # define GFX6_SF_MSRAST_ON_PIXEL			(2 << 8)
817 # define GFX6_SF_MSRAST_ON_PATTERN			(3 << 8)
818 /* DW4 */
819 # define GFX6_SF_TRI_PROVOKE_SHIFT			29
820 # define GFX6_SF_LINE_PROVOKE_SHIFT			27
821 # define GFX6_SF_TRIFAN_PROVOKE_SHIFT			25
822 # define GFX6_SF_LINE_AA_MODE_MANHATTAN			(0 << 14)
823 # define GFX6_SF_LINE_AA_MODE_TRUE			(1 << 14)
824 # define GFX6_SF_VERTEX_SUBPIXEL_8BITS			(0 << 12)
825 # define GFX6_SF_VERTEX_SUBPIXEL_4BITS			(1 << 12)
826 # define GFX6_SF_USE_STATE_POINT_WIDTH			(1 << 11)
827 # define GFX6_SF_POINT_WIDTH_SHIFT			0 /* U8.3 */
828 /* DW5: depth offset constant */
829 /* DW6: depth offset scale */
830 /* DW7: depth offset clamp */
831 /* DW8 */
832 # define ATTRIBUTE_1_OVERRIDE_W				(1 << 31)
833 # define ATTRIBUTE_1_OVERRIDE_Z				(1 << 30)
834 # define ATTRIBUTE_1_OVERRIDE_Y				(1 << 29)
835 # define ATTRIBUTE_1_OVERRIDE_X				(1 << 28)
836 # define ATTRIBUTE_1_CONST_SOURCE_SHIFT			25
837 # define ATTRIBUTE_1_SWIZZLE_SHIFT			22
838 # define ATTRIBUTE_1_SOURCE_SHIFT			16
839 # define ATTRIBUTE_0_OVERRIDE_W				(1 << 15)
840 # define ATTRIBUTE_0_OVERRIDE_Z				(1 << 14)
841 # define ATTRIBUTE_0_OVERRIDE_Y				(1 << 13)
842 # define ATTRIBUTE_0_OVERRIDE_X				(1 << 12)
843 # define ATTRIBUTE_0_CONST_SOURCE_SHIFT			9
844 #  define ATTRIBUTE_CONST_0000				0
845 #  define ATTRIBUTE_CONST_0001_FLOAT			1
846 #  define ATTRIBUTE_CONST_1111_FLOAT			2
847 #  define ATTRIBUTE_CONST_PRIM_ID			3
848 # define ATTRIBUTE_0_SWIZZLE_SHIFT			6
849 # define ATTRIBUTE_0_SOURCE_SHIFT			0
850 
851 # define ATTRIBUTE_SWIZZLE_INPUTATTR                    0
852 # define ATTRIBUTE_SWIZZLE_INPUTATTR_FACING             1
853 # define ATTRIBUTE_SWIZZLE_INPUTATTR_W                  2
854 # define ATTRIBUTE_SWIZZLE_INPUTATTR_FACING_W           3
855 # define ATTRIBUTE_SWIZZLE_SHIFT                        6
856 
857 /* DW16: Point sprite texture coordinate enables */
858 /* DW17: Constant interpolation enables */
859 /* DW18: attr 0-7 wrap shortest enables */
860 /* DW19: attr 8-16 wrap shortest enables */
861 
862 /* On GFX7, many fields of 3DSTATE_SF were split out into a new command:
863  * 3DSTATE_SBE.  The remaining fields live in different DWords, but retain
864  * the same bit-offset.  The only new field:
865  */
866 /* GFX7/DW1: */
867 # define GFX7_SF_DEPTH_BUFFER_SURFACE_FORMAT_SHIFT	12
868 /* GFX7/DW2: */
869 # define HSW_SF_LINE_STIPPLE_ENABLE			(1 << 14)
870 
871 # define GFX8_SF_SMOOTH_POINT_ENABLE                    (1 << 13)
872 
873 #define _3DSTATE_SBE				0x781F /* GFX7+ */
874 /* DW1 */
875 # define GFX8_SBE_FORCE_URB_ENTRY_READ_LENGTH           (1 << 29)
876 # define GFX8_SBE_FORCE_URB_ENTRY_READ_OFFSET           (1 << 28)
877 # define GFX7_SBE_SWIZZLE_CONTROL_MODE			(1 << 28)
878 # define GFX7_SBE_NUM_OUTPUTS_SHIFT			22
879 # define GFX7_SBE_SWIZZLE_ENABLE			(1 << 21)
880 # define GFX7_SBE_POINT_SPRITE_LOWERLEFT		(1 << 20)
881 # define GFX7_SBE_URB_ENTRY_READ_LENGTH_SHIFT		11
882 # define GFX7_SBE_URB_ENTRY_READ_OFFSET_SHIFT		4
883 # define GFX8_SBE_URB_ENTRY_READ_OFFSET_SHIFT		5
884 /* DW2-9: Attribute setup (same as DW8-15 of gfx6 _3DSTATE_SF) */
885 /* DW10: Point sprite texture coordinate enables */
886 /* DW11: Constant interpolation enables */
887 /* DW12: attr 0-7 wrap shortest enables */
888 /* DW13: attr 8-16 wrap shortest enables */
889 
890 /* DW4-5: Attribute active components (gfx9) */
891 #define GFX9_SBE_ACTIVE_COMPONENT_NONE			0
892 #define GFX9_SBE_ACTIVE_COMPONENT_XY			1
893 #define GFX9_SBE_ACTIVE_COMPONENT_XYZ			2
894 #define GFX9_SBE_ACTIVE_COMPONENT_XYZW			3
895 
896 #define _3DSTATE_SBE_SWIZ                       0x7851 /* GFX8+ */
897 
898 #define _3DSTATE_RASTER                         0x7850 /* GFX8+ */
899 /* DW1 */
900 # define GFX9_RASTER_VIEWPORT_Z_FAR_CLIP_TEST_ENABLE    (1 << 26)
901 # define GFX9_RASTER_CONSERVATIVE_RASTERIZATION_ENABLE  (1 << 24)
902 # define GFX8_RASTER_FRONT_WINDING_CCW                  (1 << 21)
903 # define GFX8_RASTER_CULL_BOTH                          (0 << 16)
904 # define GFX8_RASTER_CULL_NONE                          (1 << 16)
905 # define GFX8_RASTER_CULL_FRONT                         (2 << 16)
906 # define GFX8_RASTER_CULL_BACK                          (3 << 16)
907 # define GFX8_RASTER_SMOOTH_POINT_ENABLE                (1 << 13)
908 # define GFX8_RASTER_API_MULTISAMPLE_ENABLE             (1 << 12)
909 # define GFX8_RASTER_LINE_AA_ENABLE                     (1 << 2)
910 # define GFX8_RASTER_SCISSOR_ENABLE                     (1 << 1)
911 # define GFX8_RASTER_VIEWPORT_Z_CLIP_TEST_ENABLE        (1 << 0)
912 # define GFX9_RASTER_VIEWPORT_Z_NEAR_CLIP_TEST_ENABLE   (1 << 0)
913 
914 /* Gfx8 BLEND_STATE */
915 /* DW0 */
916 #define GFX8_BLEND_ALPHA_TO_COVERAGE_ENABLE             (1 << 31)
917 #define GFX8_BLEND_INDEPENDENT_ALPHA_BLEND_ENABLE       (1 << 30)
918 #define GFX8_BLEND_ALPHA_TO_ONE_ENABLE                  (1 << 29)
919 #define GFX8_BLEND_ALPHA_TO_COVERAGE_DITHER_ENABLE      (1 << 28)
920 #define GFX8_BLEND_ALPHA_TEST_ENABLE                    (1 << 27)
921 #define GFX8_BLEND_ALPHA_TEST_FUNCTION_MASK             INTEL_MASK(26, 24)
922 #define GFX8_BLEND_ALPHA_TEST_FUNCTION_SHIFT            24
923 #define GFX8_BLEND_COLOR_DITHER_ENABLE                  (1 << 23)
924 #define GFX8_BLEND_X_DITHER_OFFSET_MASK                 INTEL_MASK(22, 21)
925 #define GFX8_BLEND_X_DITHER_OFFSET_SHIFT                21
926 #define GFX8_BLEND_Y_DITHER_OFFSET_MASK                 INTEL_MASK(20, 19)
927 #define GFX8_BLEND_Y_DITHER_OFFSET_SHIFT                19
928 /* DW1 + 2n */
929 #define GFX8_BLEND_COLOR_BUFFER_BLEND_ENABLE            (1 << 31)
930 #define GFX8_BLEND_SRC_BLEND_FACTOR_MASK                INTEL_MASK(30, 26)
931 #define GFX8_BLEND_SRC_BLEND_FACTOR_SHIFT               26
932 #define GFX8_BLEND_DST_BLEND_FACTOR_MASK                INTEL_MASK(25, 21)
933 #define GFX8_BLEND_DST_BLEND_FACTOR_SHIFT               21
934 #define GFX8_BLEND_COLOR_BLEND_FUNCTION_MASK            INTEL_MASK(20, 18)
935 #define GFX8_BLEND_COLOR_BLEND_FUNCTION_SHIFT           18
936 #define GFX8_BLEND_SRC_ALPHA_BLEND_FACTOR_MASK          INTEL_MASK(17, 13)
937 #define GFX8_BLEND_SRC_ALPHA_BLEND_FACTOR_SHIFT         13
938 #define GFX8_BLEND_DST_ALPHA_BLEND_FACTOR_MASK          INTEL_MASK(12, 8)
939 #define GFX8_BLEND_DST_ALPHA_BLEND_FACTOR_SHIFT         8
940 #define GFX8_BLEND_ALPHA_BLEND_FUNCTION_MASK            INTEL_MASK(7, 5)
941 #define GFX8_BLEND_ALPHA_BLEND_FUNCTION_SHIFT           5
942 #define GFX8_BLEND_WRITE_DISABLE_ALPHA                  (1 << 3)
943 #define GFX8_BLEND_WRITE_DISABLE_RED                    (1 << 2)
944 #define GFX8_BLEND_WRITE_DISABLE_GREEN                  (1 << 1)
945 #define GFX8_BLEND_WRITE_DISABLE_BLUE                   (1 << 0)
946 /* DW1 + 2n + 1 */
947 #define GFX8_BLEND_LOGIC_OP_ENABLE                      (1 << 31)
948 #define GFX8_BLEND_LOGIC_OP_FUNCTION_MASK               INTEL_MASK(30, 27)
949 #define GFX8_BLEND_LOGIC_OP_FUNCTION_SHIFT              27
950 #define GFX8_BLEND_PRE_BLEND_SRC_ONLY_CLAMP_ENABLE      (1 << 4)
951 #define GFX8_BLEND_COLOR_CLAMP_RANGE_RTFORMAT           (2 << 2)
952 #define GFX8_BLEND_PRE_BLEND_COLOR_CLAMP_ENABLE         (1 << 1)
953 #define GFX8_BLEND_POST_BLEND_COLOR_CLAMP_ENABLE        (1 << 0)
954 
955 #define _3DSTATE_WM_HZ_OP                       0x7852 /* GFX8+ */
956 /* DW1 */
957 # define GFX8_WM_HZ_STENCIL_CLEAR                       (1 << 31)
958 # define GFX8_WM_HZ_DEPTH_CLEAR                         (1 << 30)
959 # define GFX8_WM_HZ_DEPTH_RESOLVE                       (1 << 28)
960 # define GFX8_WM_HZ_HIZ_RESOLVE                         (1 << 27)
961 # define GFX8_WM_HZ_PIXEL_OFFSET_ENABLE                 (1 << 26)
962 # define GFX8_WM_HZ_FULL_SURFACE_DEPTH_CLEAR            (1 << 25)
963 # define GFX8_WM_HZ_STENCIL_CLEAR_VALUE_MASK            INTEL_MASK(23, 16)
964 # define GFX8_WM_HZ_STENCIL_CLEAR_VALUE_SHIFT           16
965 # define GFX8_WM_HZ_NUM_SAMPLES_MASK                    INTEL_MASK(15, 13)
966 # define GFX8_WM_HZ_NUM_SAMPLES_SHIFT                   13
967 /* DW2 */
968 # define GFX8_WM_HZ_CLEAR_RECTANGLE_Y_MIN_MASK          INTEL_MASK(31, 16)
969 # define GFX8_WM_HZ_CLEAR_RECTANGLE_Y_MIN_SHIFT         16
970 # define GFX8_WM_HZ_CLEAR_RECTANGLE_X_MIN_MASK          INTEL_MASK(15, 0)
971 # define GFX8_WM_HZ_CLEAR_RECTANGLE_X_MIN_SHIFT         0
972 /* DW3 */
973 # define GFX8_WM_HZ_CLEAR_RECTANGLE_Y_MAX_MASK          INTEL_MASK(31, 16)
974 # define GFX8_WM_HZ_CLEAR_RECTANGLE_Y_MAX_SHIFT         16
975 # define GFX8_WM_HZ_CLEAR_RECTANGLE_X_MAX_MASK          INTEL_MASK(15, 0)
976 # define GFX8_WM_HZ_CLEAR_RECTANGLE_X_MAX_SHIFT         0
977 /* DW4 */
978 # define GFX8_WM_HZ_SAMPLE_MASK_MASK                    INTEL_MASK(15, 0)
979 # define GFX8_WM_HZ_SAMPLE_MASK_SHIFT                   0
980 
981 
982 #define _3DSTATE_PS_BLEND                       0x784D /* GFX8+ */
983 /* DW1 */
984 # define GFX8_PS_BLEND_ALPHA_TO_COVERAGE_ENABLE         (1 << 31)
985 # define GFX8_PS_BLEND_HAS_WRITEABLE_RT                 (1 << 30)
986 # define GFX8_PS_BLEND_COLOR_BUFFER_BLEND_ENABLE        (1 << 29)
987 # define GFX8_PS_BLEND_SRC_ALPHA_BLEND_FACTOR_MASK      INTEL_MASK(28, 24)
988 # define GFX8_PS_BLEND_SRC_ALPHA_BLEND_FACTOR_SHIFT     24
989 # define GFX8_PS_BLEND_DST_ALPHA_BLEND_FACTOR_MASK      INTEL_MASK(23, 19)
990 # define GFX8_PS_BLEND_DST_ALPHA_BLEND_FACTOR_SHIFT     19
991 # define GFX8_PS_BLEND_SRC_BLEND_FACTOR_MASK            INTEL_MASK(18, 14)
992 # define GFX8_PS_BLEND_SRC_BLEND_FACTOR_SHIFT           14
993 # define GFX8_PS_BLEND_DST_BLEND_FACTOR_MASK            INTEL_MASK(13, 9)
994 # define GFX8_PS_BLEND_DST_BLEND_FACTOR_SHIFT           9
995 # define GFX8_PS_BLEND_ALPHA_TEST_ENABLE                (1 << 8)
996 # define GFX8_PS_BLEND_INDEPENDENT_ALPHA_BLEND_ENABLE   (1 << 7)
997 
998 #define _3DSTATE_WM_DEPTH_STENCIL               0x784E /* GFX8+ */
999 /* DW1 */
1000 # define GFX8_WM_DS_STENCIL_FAIL_OP_SHIFT               29
1001 # define GFX8_WM_DS_Z_FAIL_OP_SHIFT                     26
1002 # define GFX8_WM_DS_Z_PASS_OP_SHIFT                     23
1003 # define GFX8_WM_DS_BF_STENCIL_FUNC_SHIFT               20
1004 # define GFX8_WM_DS_BF_STENCIL_FAIL_OP_SHIFT            17
1005 # define GFX8_WM_DS_BF_Z_FAIL_OP_SHIFT                  14
1006 # define GFX8_WM_DS_BF_Z_PASS_OP_SHIFT                  11
1007 # define GFX8_WM_DS_STENCIL_FUNC_SHIFT                  8
1008 # define GFX8_WM_DS_DEPTH_FUNC_SHIFT                    5
1009 # define GFX8_WM_DS_DOUBLE_SIDED_STENCIL_ENABLE         (1 << 4)
1010 # define GFX8_WM_DS_STENCIL_TEST_ENABLE                 (1 << 3)
1011 # define GFX8_WM_DS_STENCIL_BUFFER_WRITE_ENABLE         (1 << 2)
1012 # define GFX8_WM_DS_DEPTH_TEST_ENABLE                   (1 << 1)
1013 # define GFX8_WM_DS_DEPTH_BUFFER_WRITE_ENABLE           (1 << 0)
1014 /* DW2 */
1015 # define GFX8_WM_DS_STENCIL_TEST_MASK_MASK              INTEL_MASK(31, 24)
1016 # define GFX8_WM_DS_STENCIL_TEST_MASK_SHIFT             24
1017 # define GFX8_WM_DS_STENCIL_WRITE_MASK_MASK             INTEL_MASK(23, 16)
1018 # define GFX8_WM_DS_STENCIL_WRITE_MASK_SHIFT            16
1019 # define GFX8_WM_DS_BF_STENCIL_TEST_MASK_MASK           INTEL_MASK(15, 8)
1020 # define GFX8_WM_DS_BF_STENCIL_TEST_MASK_SHIFT          8
1021 # define GFX8_WM_DS_BF_STENCIL_WRITE_MASK_MASK          INTEL_MASK(7, 0)
1022 # define GFX8_WM_DS_BF_STENCIL_WRITE_MASK_SHIFT         0
1023 /* DW3 */
1024 # define GFX9_WM_DS_STENCIL_REF_MASK                    INTEL_MASK(15, 8)
1025 # define GFX9_WM_DS_STENCIL_REF_SHIFT                   8
1026 # define GFX9_WM_DS_BF_STENCIL_REF_MASK                 INTEL_MASK(7, 0)
1027 # define GFX9_WM_DS_BF_STENCIL_REF_SHIFT                0
1028 
1029 enum brw_pixel_shader_coverage_mask_mode {
1030    BRW_PSICMS_OFF     = 0, /* PS does not use input coverage masks. */
1031    BRW_PSICMS_NORMAL  = 1, /* Input Coverage masks based on outer conservatism
1032                             * and factors in SAMPLE_MASK.  If Pixel is
1033                             * conservatively covered, all samples are enabled.
1034                             */
1035 
1036    BRW_PSICMS_INNER   = 2, /* Input Coverage masks based on inner conservatism
1037                             * and factors in SAMPLE_MASK.  If Pixel is
1038                             * conservatively *FULLY* covered, all samples are
1039                             * enabled.
1040                             */
1041    BRW_PCICMS_DEPTH   = 3,
1042 };
1043 
1044 #define _3DSTATE_PS_EXTRA                       0x784F /* GFX8+ */
1045 /* DW1 */
1046 # define GFX8_PSX_PIXEL_SHADER_VALID                    (1 << 31)
1047 # define GFX8_PSX_PIXEL_SHADER_NO_RT_WRITE              (1 << 30)
1048 # define GFX8_PSX_OMASK_TO_RENDER_TARGET                (1 << 29)
1049 # define GFX8_PSX_KILL_ENABLE                           (1 << 28)
1050 # define GFX8_PSX_COMPUTED_DEPTH_MODE_SHIFT             26
1051 # define GFX8_PSX_FORCE_COMPUTED_DEPTH                  (1 << 25)
1052 # define GFX8_PSX_USES_SOURCE_DEPTH                     (1 << 24)
1053 # define GFX8_PSX_USES_SOURCE_W                         (1 << 23)
1054 # define GFX8_PSX_ATTRIBUTE_ENABLE                      (1 << 8)
1055 # define GFX8_PSX_SHADER_DISABLES_ALPHA_TO_COVERAGE     (1 << 7)
1056 # define GFX8_PSX_SHADER_IS_PER_SAMPLE                  (1 << 6)
1057 # define GFX9_PSX_SHADER_COMPUTES_STENCIL               (1 << 5)
1058 # define GFX9_PSX_SHADER_PULLS_BARY                     (1 << 3)
1059 # define GFX8_PSX_SHADER_HAS_UAV                        (1 << 2)
1060 # define GFX8_PSX_SHADER_USES_INPUT_COVERAGE_MASK       (1 << 1)
1061 # define GFX9_PSX_SHADER_NORMAL_COVERAGE_MASK_SHIFT     0
1062 
1063 #define _3DSTATE_WM				0x7814 /* GFX6+ */
1064 /* DW1: kernel pointer */
1065 /* DW2 */
1066 # define GFX6_WM_SPF_MODE				(1 << 31)
1067 # define GFX6_WM_VECTOR_MASK_ENABLE			(1 << 30)
1068 # define GFX6_WM_SAMPLER_COUNT_SHIFT			27
1069 # define GFX6_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT	18
1070 # define GFX6_WM_FLOATING_POINT_MODE_IEEE_754		(0 << 16)
1071 # define GFX6_WM_FLOATING_POINT_MODE_ALT		(1 << 16)
1072 /* DW3: scratch space */
1073 /* DW4 */
1074 # define GFX6_WM_STATISTICS_ENABLE			(1 << 31)
1075 # define GFX6_WM_DEPTH_CLEAR				(1 << 30)
1076 # define GFX6_WM_DEPTH_RESOLVE				(1 << 28)
1077 # define GFX6_WM_HIERARCHICAL_DEPTH_RESOLVE		(1 << 27)
1078 # define GFX6_WM_DISPATCH_START_GRF_SHIFT_0		16
1079 # define GFX6_WM_DISPATCH_START_GRF_SHIFT_1		8
1080 # define GFX6_WM_DISPATCH_START_GRF_SHIFT_2		0
1081 /* DW5 */
1082 # define GFX6_WM_MAX_THREADS_SHIFT			25
1083 # define GFX6_WM_KILL_ENABLE				(1 << 22)
1084 # define GFX6_WM_COMPUTED_DEPTH				(1 << 21)
1085 # define GFX6_WM_USES_SOURCE_DEPTH			(1 << 20)
1086 # define GFX6_WM_DISPATCH_ENABLE			(1 << 19)
1087 # define GFX6_WM_LINE_END_CAP_AA_WIDTH_0_5		(0 << 16)
1088 # define GFX6_WM_LINE_END_CAP_AA_WIDTH_1_0		(1 << 16)
1089 # define GFX6_WM_LINE_END_CAP_AA_WIDTH_2_0		(2 << 16)
1090 # define GFX6_WM_LINE_END_CAP_AA_WIDTH_4_0		(3 << 16)
1091 # define GFX6_WM_LINE_AA_WIDTH_0_5			(0 << 14)
1092 # define GFX6_WM_LINE_AA_WIDTH_1_0			(1 << 14)
1093 # define GFX6_WM_LINE_AA_WIDTH_2_0			(2 << 14)
1094 # define GFX6_WM_LINE_AA_WIDTH_4_0			(3 << 14)
1095 # define GFX6_WM_POLYGON_STIPPLE_ENABLE			(1 << 13)
1096 # define GFX6_WM_LINE_STIPPLE_ENABLE			(1 << 11)
1097 # define GFX6_WM_OMASK_TO_RENDER_TARGET			(1 << 9)
1098 # define GFX6_WM_USES_SOURCE_W				(1 << 8)
1099 # define GFX6_WM_DUAL_SOURCE_BLEND_ENABLE		(1 << 7)
1100 # define GFX6_WM_32_DISPATCH_ENABLE			(1 << 2)
1101 # define GFX6_WM_16_DISPATCH_ENABLE			(1 << 1)
1102 # define GFX6_WM_8_DISPATCH_ENABLE			(1 << 0)
1103 /* DW6 */
1104 # define GFX6_WM_NUM_SF_OUTPUTS_SHIFT			20
1105 # define GFX6_WM_POSOFFSET_NONE				(0 << 18)
1106 # define GFX6_WM_POSOFFSET_CENTROID			(2 << 18)
1107 # define GFX6_WM_POSOFFSET_SAMPLE			(3 << 18)
1108 # define GFX6_WM_POSITION_ZW_PIXEL			(0 << 16)
1109 # define GFX6_WM_POSITION_ZW_CENTROID			(2 << 16)
1110 # define GFX6_WM_POSITION_ZW_SAMPLE			(3 << 16)
1111 # define GFX6_WM_NONPERSPECTIVE_SAMPLE_BARYCENTRIC	(1 << 15)
1112 # define GFX6_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC	(1 << 14)
1113 # define GFX6_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC	(1 << 13)
1114 # define GFX6_WM_PERSPECTIVE_SAMPLE_BARYCENTRIC		(1 << 12)
1115 # define GFX6_WM_PERSPECTIVE_CENTROID_BARYCENTRIC	(1 << 11)
1116 # define GFX6_WM_PERSPECTIVE_PIXEL_BARYCENTRIC		(1 << 10)
1117 # define GFX6_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT   10
1118 # define GFX6_WM_POINT_RASTRULE_UPPER_RIGHT		(1 << 9)
1119 # define GFX6_WM_MSRAST_OFF_PIXEL			(0 << 1)
1120 # define GFX6_WM_MSRAST_OFF_PATTERN			(1 << 1)
1121 # define GFX6_WM_MSRAST_ON_PIXEL			(2 << 1)
1122 # define GFX6_WM_MSRAST_ON_PATTERN			(3 << 1)
1123 # define GFX6_WM_MSDISPMODE_PERSAMPLE			(0 << 0)
1124 # define GFX6_WM_MSDISPMODE_PERPIXEL			(1 << 0)
1125 /* DW7: kernel 1 pointer */
1126 /* DW8: kernel 2 pointer */
1127 
1128 #define _3DSTATE_CONSTANT_VS		      0x7815 /* GFX6+ */
1129 #define _3DSTATE_CONSTANT_GS		      0x7816 /* GFX6+ */
1130 #define _3DSTATE_CONSTANT_PS		      0x7817 /* GFX6+ */
1131 # define GFX6_CONSTANT_BUFFER_3_ENABLE			(1 << 15)
1132 # define GFX6_CONSTANT_BUFFER_2_ENABLE			(1 << 14)
1133 # define GFX6_CONSTANT_BUFFER_1_ENABLE			(1 << 13)
1134 # define GFX6_CONSTANT_BUFFER_0_ENABLE			(1 << 12)
1135 
1136 #define _3DSTATE_CONSTANT_HS                  0x7819 /* GFX7+ */
1137 #define _3DSTATE_CONSTANT_DS                  0x781A /* GFX7+ */
1138 
1139 #define _3DSTATE_STREAMOUT                    0x781e /* GFX7+ */
1140 /* DW1 */
1141 # define SO_FUNCTION_ENABLE				(1 << 31)
1142 # define SO_RENDERING_DISABLE				(1 << 30)
1143 /* This selects which incoming rendering stream goes down the pipeline.  The
1144  * rendering stream is 0 if not defined by special cases in the GS state.
1145  */
1146 # define SO_RENDER_STREAM_SELECT_SHIFT			27
1147 # define SO_RENDER_STREAM_SELECT_MASK			INTEL_MASK(28, 27)
1148 /* Controls reordering of TRISTRIP_* elements in stream output (not rendering).
1149  */
1150 # define SO_REORDER_TRAILING				(1 << 26)
1151 /* Controls SO_NUM_PRIMS_WRITTEN_* and SO_PRIM_STORAGE_* */
1152 # define SO_STATISTICS_ENABLE				(1 << 25)
1153 # define SO_BUFFER_ENABLE(n)				(1 << (8 + (n)))
1154 /* DW2 */
1155 # define SO_STREAM_3_VERTEX_READ_OFFSET_SHIFT		29
1156 # define SO_STREAM_3_VERTEX_READ_OFFSET_MASK		INTEL_MASK(29, 29)
1157 # define SO_STREAM_3_VERTEX_READ_LENGTH_SHIFT		24
1158 # define SO_STREAM_3_VERTEX_READ_LENGTH_MASK		INTEL_MASK(28, 24)
1159 # define SO_STREAM_2_VERTEX_READ_OFFSET_SHIFT		21
1160 # define SO_STREAM_2_VERTEX_READ_OFFSET_MASK		INTEL_MASK(21, 21)
1161 # define SO_STREAM_2_VERTEX_READ_LENGTH_SHIFT		16
1162 # define SO_STREAM_2_VERTEX_READ_LENGTH_MASK		INTEL_MASK(20, 16)
1163 # define SO_STREAM_1_VERTEX_READ_OFFSET_SHIFT		13
1164 # define SO_STREAM_1_VERTEX_READ_OFFSET_MASK		INTEL_MASK(13, 13)
1165 # define SO_STREAM_1_VERTEX_READ_LENGTH_SHIFT		8
1166 # define SO_STREAM_1_VERTEX_READ_LENGTH_MASK		INTEL_MASK(12, 8)
1167 # define SO_STREAM_0_VERTEX_READ_OFFSET_SHIFT		5
1168 # define SO_STREAM_0_VERTEX_READ_OFFSET_MASK		INTEL_MASK(5, 5)
1169 # define SO_STREAM_0_VERTEX_READ_LENGTH_SHIFT		0
1170 # define SO_STREAM_0_VERTEX_READ_LENGTH_MASK		INTEL_MASK(4, 0)
1171 
1172 /* 3DSTATE_WM for Gfx7 */
1173 /* DW1 */
1174 # define GFX7_WM_STATISTICS_ENABLE			(1 << 31)
1175 # define GFX7_WM_DEPTH_CLEAR				(1 << 30)
1176 # define GFX7_WM_DISPATCH_ENABLE			(1 << 29)
1177 # define GFX7_WM_DEPTH_RESOLVE				(1 << 28)
1178 # define GFX7_WM_HIERARCHICAL_DEPTH_RESOLVE		(1 << 27)
1179 # define GFX7_WM_KILL_ENABLE				(1 << 25)
1180 # define GFX7_WM_COMPUTED_DEPTH_MODE_SHIFT              23
1181 # define GFX7_WM_USES_SOURCE_DEPTH			(1 << 20)
1182 # define GFX7_WM_EARLY_DS_CONTROL_NORMAL                (0 << 21)
1183 # define GFX7_WM_EARLY_DS_CONTROL_PSEXEC                (1 << 21)
1184 # define GFX7_WM_EARLY_DS_CONTROL_PREPS                 (2 << 21)
1185 # define GFX7_WM_USES_SOURCE_W			        (1 << 19)
1186 # define GFX7_WM_POSITION_ZW_PIXEL			(0 << 17)
1187 # define GFX7_WM_POSITION_ZW_CENTROID			(2 << 17)
1188 # define GFX7_WM_POSITION_ZW_SAMPLE			(3 << 17)
1189 # define GFX7_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT   11
1190 # define GFX7_WM_USES_INPUT_COVERAGE_MASK	        (1 << 10)
1191 # define GFX7_WM_LINE_END_CAP_AA_WIDTH_0_5		(0 << 8)
1192 # define GFX7_WM_LINE_END_CAP_AA_WIDTH_1_0		(1 << 8)
1193 # define GFX7_WM_LINE_END_CAP_AA_WIDTH_2_0		(2 << 8)
1194 # define GFX7_WM_LINE_END_CAP_AA_WIDTH_4_0		(3 << 8)
1195 # define GFX7_WM_LINE_AA_WIDTH_0_5			(0 << 6)
1196 # define GFX7_WM_LINE_AA_WIDTH_1_0			(1 << 6)
1197 # define GFX7_WM_LINE_AA_WIDTH_2_0			(2 << 6)
1198 # define GFX7_WM_LINE_AA_WIDTH_4_0			(3 << 6)
1199 # define GFX7_WM_POLYGON_STIPPLE_ENABLE			(1 << 4)
1200 # define GFX7_WM_LINE_STIPPLE_ENABLE			(1 << 3)
1201 # define GFX7_WM_POINT_RASTRULE_UPPER_RIGHT		(1 << 2)
1202 # define GFX7_WM_MSRAST_OFF_PIXEL			(0 << 0)
1203 # define GFX7_WM_MSRAST_OFF_PATTERN			(1 << 0)
1204 # define GFX7_WM_MSRAST_ON_PIXEL			(2 << 0)
1205 # define GFX7_WM_MSRAST_ON_PATTERN			(3 << 0)
1206 /* DW2 */
1207 # define GFX7_WM_MSDISPMODE_PERSAMPLE			(0 << 31)
1208 # define GFX7_WM_MSDISPMODE_PERPIXEL			(1 << 31)
1209 # define HSW_WM_UAV_ONLY                                (1 << 30)
1210 
1211 #define _3DSTATE_PS				0x7820 /* GFX7+ */
1212 /* DW1: kernel pointer */
1213 /* DW2 */
1214 # define GFX7_PS_SPF_MODE				(1 << 31)
1215 # define GFX7_PS_VECTOR_MASK_ENABLE			(1 << 30)
1216 # define GFX7_PS_SAMPLER_COUNT_SHIFT			27
1217 # define GFX7_PS_SAMPLER_COUNT_MASK                     INTEL_MASK(29, 27)
1218 # define GFX7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT	18
1219 # define GFX7_PS_FLOATING_POINT_MODE_IEEE_754		(0 << 16)
1220 # define GFX7_PS_FLOATING_POINT_MODE_ALT		(1 << 16)
1221 /* DW3: scratch space */
1222 /* DW4 */
1223 # define IVB_PS_MAX_THREADS_SHIFT			24
1224 # define HSW_PS_MAX_THREADS_SHIFT			23
1225 # define HSW_PS_SAMPLE_MASK_SHIFT		        12
1226 # define HSW_PS_SAMPLE_MASK_MASK			INTEL_MASK(19, 12)
1227 # define GFX7_PS_PUSH_CONSTANT_ENABLE		        (1 << 11)
1228 # define GFX7_PS_ATTRIBUTE_ENABLE		        (1 << 10)
1229 # define GFX7_PS_OMASK_TO_RENDER_TARGET			(1 << 9)
1230 # define GFX7_PS_RENDER_TARGET_FAST_CLEAR_ENABLE	(1 << 8)
1231 # define GFX7_PS_DUAL_SOURCE_BLEND_ENABLE		(1 << 7)
1232 # define GFX7_PS_RENDER_TARGET_RESOLVE_ENABLE		(1 << 6)
1233 # define GFX9_PS_RENDER_TARGET_RESOLVE_FULL             (3 << 6)
1234 # define HSW_PS_UAV_ACCESS_ENABLE			(1 << 5)
1235 # define GFX7_PS_POSOFFSET_NONE				(0 << 3)
1236 # define GFX7_PS_POSOFFSET_CENTROID			(2 << 3)
1237 # define GFX7_PS_POSOFFSET_SAMPLE			(3 << 3)
1238 # define GFX7_PS_32_DISPATCH_ENABLE			(1 << 2)
1239 # define GFX7_PS_16_DISPATCH_ENABLE			(1 << 1)
1240 # define GFX7_PS_8_DISPATCH_ENABLE			(1 << 0)
1241 /* DW5 */
1242 # define GFX7_PS_DISPATCH_START_GRF_SHIFT_0		16
1243 # define GFX7_PS_DISPATCH_START_GRF_SHIFT_1		8
1244 # define GFX7_PS_DISPATCH_START_GRF_SHIFT_2		0
1245 /* DW6: kernel 1 pointer */
1246 /* DW7: kernel 2 pointer */
1247 
1248 #define _3DSTATE_SAMPLE_MASK			0x7818 /* GFX6+ */
1249 
1250 #define _3DSTATE_DRAWING_RECTANGLE		0x7900
1251 #define _3DSTATE_BLEND_CONSTANT_COLOR		0x7901
1252 #define _3DSTATE_CHROMA_KEY			0x7904
1253 #define _3DSTATE_DEPTH_BUFFER			0x7905 /* GFX4-6 */
1254 #define _3DSTATE_POLY_STIPPLE_OFFSET		0x7906
1255 #define _3DSTATE_POLY_STIPPLE_PATTERN		0x7907
1256 #define _3DSTATE_LINE_STIPPLE_PATTERN		0x7908
1257 #define _3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP	0x7909
1258 #define _3DSTATE_AA_LINE_PARAMETERS		0x790a /* G45+ */
1259 
1260 #define _3DSTATE_GS_SVB_INDEX			0x790b /* CTG+ */
1261 /* DW1 */
1262 # define SVB_INDEX_SHIFT				29
1263 # define SVB_LOAD_INTERNAL_VERTEX_COUNT			(1 << 0) /* SNB+ */
1264 /* DW2: SVB index */
1265 /* DW3: SVB maximum index */
1266 
1267 #define _3DSTATE_MULTISAMPLE			0x790d /* GFX6+ */
1268 #define GFX8_3DSTATE_MULTISAMPLE		0x780d /* GFX8+ */
1269 /* DW1 */
1270 # define MS_PIXEL_LOCATION_CENTER			(0 << 4)
1271 # define MS_PIXEL_LOCATION_UPPER_LEFT			(1 << 4)
1272 # define MS_NUMSAMPLES_1				(0 << 1)
1273 # define MS_NUMSAMPLES_2				(1 << 1)
1274 # define MS_NUMSAMPLES_4				(2 << 1)
1275 # define MS_NUMSAMPLES_8				(3 << 1)
1276 # define MS_NUMSAMPLES_16				(4 << 1)
1277 
1278 #define _3DSTATE_SAMPLE_PATTERN                 0x791c
1279 
1280 #define _3DSTATE_STENCIL_BUFFER			0x790e /* ILK, SNB */
1281 #define _3DSTATE_HIER_DEPTH_BUFFER		0x790f /* ILK, SNB */
1282 
1283 #define GFX7_3DSTATE_CLEAR_PARAMS		0x7804
1284 #define GFX7_3DSTATE_DEPTH_BUFFER		0x7805
1285 #define GFX7_3DSTATE_STENCIL_BUFFER		0x7806
1286 # define HSW_STENCIL_ENABLED                            (1 << 31)
1287 #define GFX7_3DSTATE_HIER_DEPTH_BUFFER		0x7807
1288 
1289 #define _3DSTATE_CLEAR_PARAMS			0x7910 /* ILK, SNB */
1290 # define GFX5_DEPTH_CLEAR_VALID				(1 << 15)
1291 /* DW1: depth clear value */
1292 /* DW2 */
1293 # define GFX7_DEPTH_CLEAR_VALID				(1 << 0)
1294 
1295 #define _3DSTATE_SO_DECL_LIST			0x7917 /* GFX7+ */
1296 /* DW1 */
1297 # define SO_STREAM_TO_BUFFER_SELECTS_3_SHIFT		12
1298 # define SO_STREAM_TO_BUFFER_SELECTS_3_MASK		INTEL_MASK(15, 12)
1299 # define SO_STREAM_TO_BUFFER_SELECTS_2_SHIFT		8
1300 # define SO_STREAM_TO_BUFFER_SELECTS_2_MASK		INTEL_MASK(11, 8)
1301 # define SO_STREAM_TO_BUFFER_SELECTS_1_SHIFT		4
1302 # define SO_STREAM_TO_BUFFER_SELECTS_1_MASK		INTEL_MASK(7, 4)
1303 # define SO_STREAM_TO_BUFFER_SELECTS_0_SHIFT		0
1304 # define SO_STREAM_TO_BUFFER_SELECTS_0_MASK		INTEL_MASK(3, 0)
1305 /* DW2 */
1306 # define SO_NUM_ENTRIES_3_SHIFT				24
1307 # define SO_NUM_ENTRIES_3_MASK				INTEL_MASK(31, 24)
1308 # define SO_NUM_ENTRIES_2_SHIFT				16
1309 # define SO_NUM_ENTRIES_2_MASK				INTEL_MASK(23, 16)
1310 # define SO_NUM_ENTRIES_1_SHIFT				8
1311 # define SO_NUM_ENTRIES_1_MASK				INTEL_MASK(15, 8)
1312 # define SO_NUM_ENTRIES_0_SHIFT				0
1313 # define SO_NUM_ENTRIES_0_MASK				INTEL_MASK(7, 0)
1314 
1315 /* SO_DECL DW0 */
1316 # define SO_DECL_OUTPUT_BUFFER_SLOT_SHIFT		12
1317 # define SO_DECL_OUTPUT_BUFFER_SLOT_MASK		INTEL_MASK(13, 12)
1318 # define SO_DECL_HOLE_FLAG				(1 << 11)
1319 # define SO_DECL_REGISTER_INDEX_SHIFT			4
1320 # define SO_DECL_REGISTER_INDEX_MASK			INTEL_MASK(9, 4)
1321 # define SO_DECL_COMPONENT_MASK_SHIFT			0
1322 # define SO_DECL_COMPONENT_MASK_MASK			INTEL_MASK(3, 0)
1323 
1324 #define _3DSTATE_SO_BUFFER                    0x7918 /* GFX7+ */
1325 /* DW1 */
1326 # define GFX8_SO_BUFFER_ENABLE                          (1 << 31)
1327 # define SO_BUFFER_INDEX_SHIFT				29
1328 # define SO_BUFFER_INDEX_MASK				INTEL_MASK(30, 29)
1329 # define GFX8_SO_BUFFER_OFFSET_WRITE_ENABLE             (1 << 21)
1330 # define GFX8_SO_BUFFER_OFFSET_ADDRESS_ENABLE           (1 << 20)
1331 # define SO_BUFFER_PITCH_SHIFT				0
1332 # define SO_BUFFER_PITCH_MASK				INTEL_MASK(11, 0)
1333 /* DW2: start address */
1334 /* DW3: end address. */
1335 
1336 #define _3DSTATE_3D_MODE                     0x791e
1337 # define SLICE_HASHING_TABLE_ENABLE          (1 << 6)
1338 # define SLICE_HASHING_TABLE_ENABLE_MASK     REG_MASK(1 << 6)
1339 
1340 #define _3DSTATE_SLICE_TABLE_STATE_POINTERS  0x7920
1341 
1342 #define CMD_MI_FLUSH                  0x0200
1343 
1344 # define BLT_X_SHIFT					0
1345 # define BLT_X_MASK					INTEL_MASK(15, 0)
1346 # define BLT_Y_SHIFT					16
1347 # define BLT_Y_MASK					INTEL_MASK(31, 16)
1348 
1349 #define GFX5_MI_REPORT_PERF_COUNT ((0x26 << 23) | (3 - 2))
1350 /* DW0 */
1351 # define GFX5_MI_COUNTER_SET_0      (0 << 6)
1352 # define GFX5_MI_COUNTER_SET_1      (1 << 6)
1353 /* DW1 */
1354 # define MI_COUNTER_ADDRESS_GTT     (1 << 0)
1355 /* DW2: a user-defined report ID (written to the buffer but can be anything) */
1356 
1357 #define GFX6_MI_REPORT_PERF_COUNT ((0x28 << 23) | (3 - 2))
1358 
1359 #define GFX8_MI_REPORT_PERF_COUNT ((0x28 << 23) | (4 - 2))
1360 
1361 /* Maximum number of entries that can be addressed using a binding table
1362  * pointer of type SURFTYPE_BUFFER
1363  */
1364 #define BRW_MAX_NUM_BUFFER_ENTRIES	(1 << 27)
1365 
1366 #define MEDIA_VFE_STATE                         0x7000
1367 /* GFX7 DW2, GFX8+ DW3 */
1368 # define MEDIA_VFE_STATE_MAX_THREADS_SHIFT      16
1369 # define MEDIA_VFE_STATE_MAX_THREADS_MASK       INTEL_MASK(31, 16)
1370 # define MEDIA_VFE_STATE_URB_ENTRIES_SHIFT      8
1371 # define MEDIA_VFE_STATE_URB_ENTRIES_MASK       INTEL_MASK(15, 8)
1372 # define MEDIA_VFE_STATE_RESET_GTW_TIMER_SHIFT  7
1373 # define MEDIA_VFE_STATE_RESET_GTW_TIMER_MASK   INTEL_MASK(7, 7)
1374 # define MEDIA_VFE_STATE_BYPASS_GTW_SHIFT       6
1375 # define MEDIA_VFE_STATE_BYPASS_GTW_MASK        INTEL_MASK(6, 6)
1376 # define GFX7_MEDIA_VFE_STATE_GPGPU_MODE_SHIFT  2
1377 # define GFX7_MEDIA_VFE_STATE_GPGPU_MODE_MASK   INTEL_MASK(2, 2)
1378 /* GFX7 DW4, GFX8+ DW5 */
1379 # define MEDIA_VFE_STATE_URB_ALLOC_SHIFT        16
1380 # define MEDIA_VFE_STATE_URB_ALLOC_MASK         INTEL_MASK(31, 16)
1381 # define MEDIA_VFE_STATE_CURBE_ALLOC_SHIFT      0
1382 # define MEDIA_VFE_STATE_CURBE_ALLOC_MASK       INTEL_MASK(15, 0)
1383 
1384 #define MEDIA_CURBE_LOAD                        0x7001
1385 #define MEDIA_INTERFACE_DESCRIPTOR_LOAD         0x7002
1386 /* GFX7 DW4, GFX8+ DW5 */
1387 # define MEDIA_CURBE_READ_LENGTH_SHIFT          16
1388 # define MEDIA_CURBE_READ_LENGTH_MASK           INTEL_MASK(31, 16)
1389 # define MEDIA_CURBE_READ_OFFSET_SHIFT          0
1390 # define MEDIA_CURBE_READ_OFFSET_MASK           INTEL_MASK(15, 0)
1391 /* GFX7 DW5, GFX8+ DW6 */
1392 # define MEDIA_BARRIER_ENABLE_SHIFT             21
1393 # define MEDIA_BARRIER_ENABLE_MASK              INTEL_MASK(21, 21)
1394 # define MEDIA_SHARED_LOCAL_MEMORY_SIZE_SHIFT   16
1395 # define MEDIA_SHARED_LOCAL_MEMORY_SIZE_MASK    INTEL_MASK(20, 16)
1396 # define MEDIA_GPGPU_THREAD_COUNT_SHIFT         0
1397 # define MEDIA_GPGPU_THREAD_COUNT_MASK          INTEL_MASK(7, 0)
1398 # define GFX8_MEDIA_GPGPU_THREAD_COUNT_SHIFT    0
1399 # define GFX8_MEDIA_GPGPU_THREAD_COUNT_MASK     INTEL_MASK(9, 0)
1400 /* GFX7 DW6, GFX8+ DW7 */
1401 # define CROSS_THREAD_READ_LENGTH_SHIFT         0
1402 # define CROSS_THREAD_READ_LENGTH_MASK          INTEL_MASK(7, 0)
1403 #define MEDIA_STATE_FLUSH                       0x7004
1404 #define GPGPU_WALKER                            0x7105
1405 /* GFX7 DW0 */
1406 # define GFX7_GPGPU_INDIRECT_PARAMETER_ENABLE   (1 << 10)
1407 # define GFX7_GPGPU_PREDICATE_ENABLE            (1 << 8)
1408 /* GFX8+ DW2 */
1409 # define GPGPU_WALKER_INDIRECT_LENGTH_SHIFT     0
1410 # define GPGPU_WALKER_INDIRECT_LENGTH_MASK      INTEL_MASK(15, 0)
1411 /* GFX7 DW2, GFX8+ DW4 */
1412 # define GPGPU_WALKER_SIMD_SIZE_SHIFT           30
1413 # define GPGPU_WALKER_SIMD_SIZE_MASK            INTEL_MASK(31, 30)
1414 # define GPGPU_WALKER_THREAD_DEPTH_MAX_SHIFT    16
1415 # define GPGPU_WALKER_THREAD_DEPTH_MAX_MASK     INTEL_MASK(21, 16)
1416 # define GPGPU_WALKER_THREAD_HEIGHT_MAX_SHIFT   8
1417 # define GPGPU_WALKER_THREAD_HEIGHT_MAX_MASK    INTEL_MASK(31, 8)
1418 # define GPGPU_WALKER_THREAD_WIDTH_MAX_SHIFT    0
1419 # define GPGPU_WALKER_THREAD_WIDTH_MAX_MASK     INTEL_MASK(5, 0)
1420 
1421 #define CMD_MI				(0x0 << 29)
1422 #define CMD_2D				(0x2 << 29)
1423 #define CMD_3D				(0x3 << 29)
1424 
1425 #define MI_NOOP				(CMD_MI | 0)
1426 
1427 #define MI_BATCH_BUFFER_END		(CMD_MI | 0xA << 23)
1428 
1429 #define MI_FLUSH			(CMD_MI | (4 << 23))
1430 #define FLUSH_MAP_CACHE				(1 << 0)
1431 #define INHIBIT_FLUSH_RENDER_CACHE		(1 << 2)
1432 
1433 #define MI_STORE_DATA_IMM		(CMD_MI | (0x20 << 23))
1434 #define MI_LOAD_REGISTER_IMM		(CMD_MI | (0x22 << 23))
1435 #define MI_LOAD_REGISTER_REG		(CMD_MI | (0x2A << 23))
1436 
1437 #define MI_FLUSH_DW			(CMD_MI | (0x26 << 23))
1438 
1439 #define MI_STORE_REGISTER_MEM		(CMD_MI | (0x24 << 23))
1440 # define MI_STORE_REGISTER_MEM_USE_GGTT		(1 << 22)
1441 # define MI_STORE_REGISTER_MEM_PREDICATE	(1 << 21)
1442 
1443 /* Load a value from memory into a register.  Only available on Gfx7+. */
1444 #define GFX7_MI_LOAD_REGISTER_MEM	(CMD_MI | (0x29 << 23))
1445 # define MI_LOAD_REGISTER_MEM_USE_GGTT		(1 << 22)
1446 
1447 /* Manipulate the predicate bit based on some register values. Only on Gfx7+ */
1448 #define GFX7_MI_PREDICATE		(CMD_MI | (0xC << 23))
1449 # define MI_PREDICATE_LOADOP_KEEP		(0 << 6)
1450 # define MI_PREDICATE_LOADOP_LOAD		(2 << 6)
1451 # define MI_PREDICATE_LOADOP_LOADINV		(3 << 6)
1452 # define MI_PREDICATE_COMBINEOP_SET		(0 << 3)
1453 # define MI_PREDICATE_COMBINEOP_AND		(1 << 3)
1454 # define MI_PREDICATE_COMBINEOP_OR		(2 << 3)
1455 # define MI_PREDICATE_COMBINEOP_XOR		(3 << 3)
1456 # define MI_PREDICATE_COMPAREOP_TRUE		(0 << 0)
1457 # define MI_PREDICATE_COMPAREOP_FALSE		(1 << 0)
1458 # define MI_PREDICATE_COMPAREOP_SRCS_EQUAL	(2 << 0)
1459 # define MI_PREDICATE_COMPAREOP_DELTAS_EQUAL	(3 << 0)
1460 
1461 #define HSW_MI_MATH			(CMD_MI | (0x1a << 23))
1462 
1463 #define MI_MATH_ALU2(opcode, operand1, operand2) \
1464    ( ((MI_MATH_OPCODE_##opcode) << 20) | ((MI_MATH_OPERAND_##operand1) << 10) | \
1465      ((MI_MATH_OPERAND_##operand2) << 0) )
1466 
1467 #define MI_MATH_ALU1(opcode, operand1) \
1468    ( ((MI_MATH_OPCODE_##opcode) << 20) | ((MI_MATH_OPERAND_##operand1) << 10) )
1469 
1470 #define MI_MATH_ALU0(opcode) \
1471    ( ((MI_MATH_OPCODE_##opcode) << 20) )
1472 
1473 #define MI_MATH_OPCODE_NOOP      0x000
1474 #define MI_MATH_OPCODE_LOAD      0x080
1475 #define MI_MATH_OPCODE_LOADINV   0x480
1476 #define MI_MATH_OPCODE_LOAD0     0x081
1477 #define MI_MATH_OPCODE_LOAD1     0x481
1478 #define MI_MATH_OPCODE_ADD       0x100
1479 #define MI_MATH_OPCODE_SUB       0x101
1480 #define MI_MATH_OPCODE_AND       0x102
1481 #define MI_MATH_OPCODE_OR        0x103
1482 #define MI_MATH_OPCODE_XOR       0x104
1483 #define MI_MATH_OPCODE_STORE     0x180
1484 #define MI_MATH_OPCODE_STOREINV  0x580
1485 
1486 #define MI_MATH_OPERAND_R0   0x00
1487 #define MI_MATH_OPERAND_R1   0x01
1488 #define MI_MATH_OPERAND_R2   0x02
1489 #define MI_MATH_OPERAND_R3   0x03
1490 #define MI_MATH_OPERAND_R4   0x04
1491 #define MI_MATH_OPERAND_SRCA 0x20
1492 #define MI_MATH_OPERAND_SRCB 0x21
1493 #define MI_MATH_OPERAND_ACCU 0x31
1494 #define MI_MATH_OPERAND_ZF   0x32
1495 #define MI_MATH_OPERAND_CF   0x33
1496 
1497 #define XY_SETUP_BLT_CMD		(CMD_2D | (0x01 << 22))
1498 
1499 #define XY_COLOR_BLT_CMD		(CMD_2D | (0x50 << 22))
1500 
1501 #define XY_SRC_COPY_BLT_CMD             (CMD_2D | (0x53 << 22))
1502 
1503 #define XY_FAST_COPY_BLT_CMD             (CMD_2D | (0x42 << 22))
1504 
1505 #define XY_TEXT_IMMEDIATE_BLIT_CMD	(CMD_2D | (0x31 << 22))
1506 # define XY_TEXT_BYTE_PACKED		(1 << 16)
1507 
1508 /* BR00 */
1509 #define XY_BLT_WRITE_ALPHA	(1 << 21)
1510 #define XY_BLT_WRITE_RGB	(1 << 20)
1511 #define XY_SRC_TILED		(1 << 15)
1512 #define XY_DST_TILED		(1 << 11)
1513 
1514 /* BR00 */
1515 #define XY_FAST_SRC_TILED_64K        (3 << 20)
1516 #define XY_FAST_SRC_TILED_Y          (2 << 20)
1517 #define XY_FAST_SRC_TILED_X          (1 << 20)
1518 
1519 #define XY_FAST_DST_TILED_64K        (3 << 13)
1520 #define XY_FAST_DST_TILED_Y          (2 << 13)
1521 #define XY_FAST_DST_TILED_X          (1 << 13)
1522 
1523 /* BR13 */
1524 #define BR13_8			(0x0 << 24)
1525 #define BR13_565		(0x1 << 24)
1526 #define BR13_8888		(0x3 << 24)
1527 #define BR13_16161616		(0x4 << 24)
1528 #define BR13_32323232		(0x5 << 24)
1529 
1530 #define GFX6_SO_PRIM_STORAGE_NEEDED     0x2280
1531 #define GFX7_SO_PRIM_STORAGE_NEEDED(n)  (0x5240 + (n) * 8)
1532 
1533 #define GFX6_SO_NUM_PRIMS_WRITTEN       0x2288
1534 #define GFX7_SO_NUM_PRIMS_WRITTEN(n)    (0x5200 + (n) * 8)
1535 
1536 #define GFX7_SO_WRITE_OFFSET(n)         (0x5280 + (n) * 4)
1537 
1538 #define TIMESTAMP                       0x2358
1539 
1540 #define BCS_SWCTRL                      0x22200
1541 # define BCS_SWCTRL_SRC_Y               (1 << 0)
1542 # define BCS_SWCTRL_DST_Y               (1 << 1)
1543 
1544 #define OACONTROL                       0x2360
1545 # define OACONTROL_COUNTER_SELECT_SHIFT  2
1546 # define OACONTROL_ENABLE_COUNTERS       (1 << 0)
1547 
1548 /* Auto-Draw / Indirect Registers */
1549 #define GFX7_3DPRIM_END_OFFSET          0x2420
1550 #define GFX7_3DPRIM_START_VERTEX        0x2430
1551 #define GFX7_3DPRIM_VERTEX_COUNT        0x2434
1552 #define GFX7_3DPRIM_INSTANCE_COUNT      0x2438
1553 #define GFX7_3DPRIM_START_INSTANCE      0x243C
1554 #define GFX7_3DPRIM_BASE_VERTEX         0x2440
1555 
1556 /* Auto-Compute / Indirect Registers */
1557 #define GFX7_GPGPU_DISPATCHDIMX         0x2500
1558 #define GFX7_GPGPU_DISPATCHDIMY         0x2504
1559 #define GFX7_GPGPU_DISPATCHDIMZ         0x2508
1560 
1561 #define GFX7_CACHE_MODE_0               0x7000
1562 #define GFX7_CACHE_MODE_1               0x7004
1563 # define GFX9_FLOAT_BLEND_OPTIMIZATION_ENABLE (1 << 4)
1564 # define GFX9_MSC_RAW_HAZARD_AVOIDANCE_BIT    (1 << 9)
1565 # define GFX8_HIZ_NP_PMA_FIX_ENABLE        (1 << 11)
1566 # define GFX8_HIZ_NP_EARLY_Z_FAILS_DISABLE (1 << 13)
1567 # define GFX9_PARTIAL_RESOLVE_DISABLE_IN_VC (1 << 1)
1568 # define GFX8_HIZ_PMA_MASK_BITS \
1569    REG_MASK(GFX8_HIZ_NP_PMA_FIX_ENABLE | GFX8_HIZ_NP_EARLY_Z_FAILS_DISABLE)
1570 # define GFX11_DISABLE_REPACKING_FOR_COMPRESSION (1 << 15)
1571 
1572 #define GFX7_GT_MODE                    0x7008
1573 # define GFX9_SUBSLICE_HASHING_8x8      (0 << 8)
1574 # define GFX9_SUBSLICE_HASHING_16x4     (1 << 8)
1575 # define GFX9_SUBSLICE_HASHING_8x4      (2 << 8)
1576 # define GFX9_SUBSLICE_HASHING_16x16    (3 << 8)
1577 # define GFX9_SUBSLICE_HASHING_MASK_BITS REG_MASK(3 << 8)
1578 # define GFX9_SLICE_HASHING_NORMAL      (0 << 11)
1579 # define GFX9_SLICE_HASHING_DISABLED    (1 << 11)
1580 # define GFX9_SLICE_HASHING_32x16       (2 << 11)
1581 # define GFX9_SLICE_HASHING_32x32       (3 << 11)
1582 # define GFX9_SLICE_HASHING_MASK_BITS REG_MASK(3 << 11)
1583 
1584 /* Predicate registers */
1585 #define MI_PREDICATE_SRC0               0x2400
1586 #define MI_PREDICATE_SRC1               0x2408
1587 #define MI_PREDICATE_DATA               0x2410
1588 #define MI_PREDICATE_RESULT             0x2418
1589 #define MI_PREDICATE_RESULT_1           0x241C
1590 #define MI_PREDICATE_RESULT_2           0x2214
1591 
1592 #define HSW_CS_GPR(n) (0x2600 + (n) * 8)
1593 
1594 /* L3 cache control registers. */
1595 #define GFX7_L3SQCREG1                     0xb010
1596 /* L3SQ general and high priority credit initialization. */
1597 # define IVB_L3SQCREG1_SQGHPCI_DEFAULT     0x00730000
1598 # define VLV_L3SQCREG1_SQGHPCI_DEFAULT     0x00d30000
1599 # define HSW_L3SQCREG1_SQGHPCI_DEFAULT     0x00610000
1600 # define GFX7_L3SQCREG1_CONV_DC_UC         (1 << 24)
1601 # define GFX7_L3SQCREG1_CONV_IS_UC         (1 << 25)
1602 # define GFX7_L3SQCREG1_CONV_C_UC          (1 << 26)
1603 # define GFX7_L3SQCREG1_CONV_T_UC          (1 << 27)
1604 
1605 #define GFX7_L3CNTLREG2                    0xb020
1606 # define GFX7_L3CNTLREG2_SLM_ENABLE        (1 << 0)
1607 # define GFX7_L3CNTLREG2_URB_ALLOC_SHIFT   1
1608 # define GFX7_L3CNTLREG2_URB_ALLOC_MASK    INTEL_MASK(6, 1)
1609 # define GFX7_L3CNTLREG2_URB_LOW_BW        (1 << 7)
1610 # define GFX7_L3CNTLREG2_ALL_ALLOC_SHIFT   8
1611 # define GFX7_L3CNTLREG2_ALL_ALLOC_MASK    INTEL_MASK(13, 8)
1612 # define GFX7_L3CNTLREG2_RO_ALLOC_SHIFT    14
1613 # define GFX7_L3CNTLREG2_RO_ALLOC_MASK     INTEL_MASK(19, 14)
1614 # define GFX7_L3CNTLREG2_RO_LOW_BW         (1 << 20)
1615 # define GFX7_L3CNTLREG2_DC_ALLOC_SHIFT    21
1616 # define GFX7_L3CNTLREG2_DC_ALLOC_MASK     INTEL_MASK(26, 21)
1617 # define GFX7_L3CNTLREG2_DC_LOW_BW         (1 << 27)
1618 
1619 #define GFX7_L3CNTLREG3                    0xb024
1620 # define GFX7_L3CNTLREG3_IS_ALLOC_SHIFT    1
1621 # define GFX7_L3CNTLREG3_IS_ALLOC_MASK     INTEL_MASK(6, 1)
1622 # define GFX7_L3CNTLREG3_IS_LOW_BW         (1 << 7)
1623 # define GFX7_L3CNTLREG3_C_ALLOC_SHIFT     8
1624 # define GFX7_L3CNTLREG3_C_ALLOC_MASK      INTEL_MASK(13, 8)
1625 # define GFX7_L3CNTLREG3_C_LOW_BW          (1 << 14)
1626 # define GFX7_L3CNTLREG3_T_ALLOC_SHIFT     15
1627 # define GFX7_L3CNTLREG3_T_ALLOC_MASK      INTEL_MASK(20, 15)
1628 # define GFX7_L3CNTLREG3_T_LOW_BW          (1 << 21)
1629 
1630 #define HSW_SCRATCH1                       0xb038
1631 #define HSW_SCRATCH1_L3_ATOMIC_DISABLE     (1 << 27)
1632 
1633 #define HSW_ROW_CHICKEN3                   0xe49c
1634 #define HSW_ROW_CHICKEN3_L3_ATOMIC_DISABLE (1 << 6)
1635 
1636 #define GFX8_L3CNTLREG                     0x7034
1637 # define GFX8_L3CNTLREG_SLM_ENABLE         (1 << 0)
1638 # define GFX8_L3CNTLREG_URB_ALLOC_SHIFT    1
1639 # define GFX8_L3CNTLREG_URB_ALLOC_MASK     INTEL_MASK(7, 1)
1640 # define GFX8_L3CNTLREG_RO_ALLOC_SHIFT     11
1641 # define GFX8_L3CNTLREG_RO_ALLOC_MASK      INTEL_MASK(17, 11)
1642 # define GFX8_L3CNTLREG_DC_ALLOC_SHIFT     18
1643 # define GFX8_L3CNTLREG_DC_ALLOC_MASK      INTEL_MASK(24, 18)
1644 # define GFX8_L3CNTLREG_ALL_ALLOC_SHIFT    25
1645 # define GFX8_L3CNTLREG_ALL_ALLOC_MASK     INTEL_MASK(31, 25)
1646 # define GFX8_L3CNTLREG_EDBC_NO_HANG       (1 << 9)
1647 # define GFX11_L3CNTLREG_USE_FULL_WAYS     (1 << 10)
1648 
1649 #define GFX10_CACHE_MODE_SS            0x0e420
1650 #define GFX10_FLOAT_BLEND_OPTIMIZATION_ENABLE (1 << 4)
1651 
1652 #define INSTPM                             0x20c0
1653 # define INSTPM_CONSTANT_BUFFER_ADDRESS_OFFSET_DISABLE (1 << 6)
1654 
1655 #define CS_DEBUG_MODE2                     0x20d8 /* Gfx9+ */
1656 # define CSDBG2_CONSTANT_BUFFER_ADDRESS_OFFSET_DISABLE (1 << 4)
1657 
1658 #define SLICE_COMMON_ECO_CHICKEN1          0x731c /* Gfx9+ */
1659 # define GLK_SCEC_BARRIER_MODE_GPGPU       (0 << 7)
1660 # define GLK_SCEC_BARRIER_MODE_3D_HULL     (1 << 7)
1661 # define GLK_SCEC_BARRIER_MODE_MASK        REG_MASK(1 << 7)
1662 # define GFX11_STATE_CACHE_REDIRECT_TO_CS_SECTION_ENABLE (1 << 11)
1663 
1664 #define HALF_SLICE_CHICKEN7                0xE194
1665 # define TEXEL_OFFSET_FIX_ENABLE           (1 << 1)
1666 # define TEXEL_OFFSET_FIX_MASK             REG_MASK(1 << 1)
1667 
1668 #define GFX11_SAMPLER_MODE                                  0xE18C
1669 # define HEADERLESS_MESSAGE_FOR_PREEMPTABLE_CONTEXTS        (1 << 5)
1670 # define HEADERLESS_MESSAGE_FOR_PREEMPTABLE_CONTEXTS_MASK   REG_MASK(1 << 5)
1671 
1672 #define CS_CHICKEN1                        0x2580 /* Gfx9+ */
1673 # define GFX9_REPLAY_MODE_MIDBUFFER             (0 << 0)
1674 # define GFX9_REPLAY_MODE_MIDOBJECT             (1 << 0)
1675 # define GFX9_REPLAY_MODE_MASK                  REG_MASK(1 << 0)
1676 
1677 #endif
1678