iris: actually save VBs
[mesa.git] / src / gallium / drivers / iris / iris_state.c
1 /*
2 * Copyright © 2017 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include <stdio.h>
24 #include <errno.h>
25
26 #ifdef HAVE_VALGRIND
27 #include <valgrind.h>
28 #include <memcheck.h>
29 #define VG(x) x
30 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
31 #else
32 #define VG(x)
33 #endif
34
35 #include "pipe/p_defines.h"
36 #include "pipe/p_state.h"
37 #include "pipe/p_context.h"
38 #include "pipe/p_screen.h"
39 #include "util/u_inlines.h"
40 #include "util/u_transfer.h"
41 #include "intel/compiler/brw_compiler.h"
42 #include "intel/common/gen_sample_positions.h"
43 #include "iris_batch.h"
44 #include "iris_context.h"
45 #include "iris_pipe.h"
46 #include "iris_resource.h"
47
48 #define __gen_address_type unsigned
49 #define __gen_user_data void
50
51 static uint64_t
52 __gen_combine_address(void *user_data, void *location,
53 unsigned address, uint32_t delta)
54 {
55 return delta;
56 }
57
58 #define __genxml_cmd_length(cmd) cmd ## _length
59 #define __genxml_cmd_length_bias(cmd) cmd ## _length_bias
60 #define __genxml_cmd_header(cmd) cmd ## _header
61 #define __genxml_cmd_pack(cmd) cmd ## _pack
62
63 #define iris_pack_command(cmd, dst, name) \
64 for (struct cmd name = { __genxml_cmd_header(cmd) }, \
65 *_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \
66 ({ __genxml_cmd_pack(cmd)(NULL, (void *)_dst, &name); \
67 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __genxml_cmd_length(cmd) * 4)); \
68 _dst = NULL; \
69 }))
70
71 #define iris_pack_state(cmd, dst, name) \
72 for (struct cmd name = {}, \
73 *_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \
74 __genxml_cmd_pack(cmd)(NULL, (void *)_dst, &name), \
75 _dst = NULL)
76
77 #define iris_emit_cmd(batch, cmd, name) \
78 iris_require_command_space(batch, 4 * __genxml_cmd_length(cmd)); \
79 iris_pack_command(cmd, batch->cmdbuf.map_next, name)
80
81 #define iris_emit_merge(batch, dwords0, dwords1) \
82 do { \
83 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
84 \
85 iris_require_command_space(batch, ARRAY_SIZE(dwords0)); \
86 uint32_t *dw = batch->cmdbuf.map_next; \
87 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
88 dw[i] = (dwords0)[i] | (dwords1)[i]; \
89 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4)); \
90 } while (0)
91
92 #include "genxml/genX_pack.h"
93 #include "genxml/gen_macros.h"
94
95 #define MOCS_WB (2 << 1)
96
97 UNUSED static void pipe_asserts()
98 {
99 #define PIPE_ASSERT(x) STATIC_ASSERT((int)x)
100
101 /* pipe_logicop happens to match the hardware. */
102 PIPE_ASSERT(PIPE_LOGICOP_CLEAR == LOGICOP_CLEAR);
103 PIPE_ASSERT(PIPE_LOGICOP_NOR == LOGICOP_NOR);
104 PIPE_ASSERT(PIPE_LOGICOP_AND_INVERTED == LOGICOP_AND_INVERTED);
105 PIPE_ASSERT(PIPE_LOGICOP_COPY_INVERTED == LOGICOP_COPY_INVERTED);
106 PIPE_ASSERT(PIPE_LOGICOP_AND_REVERSE == LOGICOP_AND_REVERSE);
107 PIPE_ASSERT(PIPE_LOGICOP_INVERT == LOGICOP_INVERT);
108 PIPE_ASSERT(PIPE_LOGICOP_XOR == LOGICOP_XOR);
109 PIPE_ASSERT(PIPE_LOGICOP_NAND == LOGICOP_NAND);
110 PIPE_ASSERT(PIPE_LOGICOP_AND == LOGICOP_AND);
111 PIPE_ASSERT(PIPE_LOGICOP_EQUIV == LOGICOP_EQUIV);
112 PIPE_ASSERT(PIPE_LOGICOP_NOOP == LOGICOP_NOOP);
113 PIPE_ASSERT(PIPE_LOGICOP_OR_INVERTED == LOGICOP_OR_INVERTED);
114 PIPE_ASSERT(PIPE_LOGICOP_COPY == LOGICOP_COPY);
115 PIPE_ASSERT(PIPE_LOGICOP_OR_REVERSE == LOGICOP_OR_REVERSE);
116 PIPE_ASSERT(PIPE_LOGICOP_OR == LOGICOP_OR);
117 PIPE_ASSERT(PIPE_LOGICOP_SET == LOGICOP_SET);
118
119 /* pipe_blend_func happens to match the hardware. */
120 PIPE_ASSERT(PIPE_BLENDFACTOR_ONE == BLENDFACTOR_ONE);
121 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_COLOR == BLENDFACTOR_SRC_COLOR);
122 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA == BLENDFACTOR_SRC_ALPHA);
123 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_ALPHA == BLENDFACTOR_DST_ALPHA);
124 PIPE_ASSERT(PIPE_BLENDFACTOR_DST_COLOR == BLENDFACTOR_DST_COLOR);
125 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE == BLENDFACTOR_SRC_ALPHA_SATURATE);
126 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_COLOR == BLENDFACTOR_CONST_COLOR);
127 PIPE_ASSERT(PIPE_BLENDFACTOR_CONST_ALPHA == BLENDFACTOR_CONST_ALPHA);
128 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_COLOR == BLENDFACTOR_SRC1_COLOR);
129 PIPE_ASSERT(PIPE_BLENDFACTOR_SRC1_ALPHA == BLENDFACTOR_SRC1_ALPHA);
130 PIPE_ASSERT(PIPE_BLENDFACTOR_ZERO == BLENDFACTOR_ZERO);
131 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_COLOR == BLENDFACTOR_INV_SRC_COLOR);
132 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC_ALPHA == BLENDFACTOR_INV_SRC_ALPHA);
133 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_ALPHA == BLENDFACTOR_INV_DST_ALPHA);
134 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_DST_COLOR == BLENDFACTOR_INV_DST_COLOR);
135 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_COLOR == BLENDFACTOR_INV_CONST_COLOR);
136 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_CONST_ALPHA == BLENDFACTOR_INV_CONST_ALPHA);
137 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_COLOR == BLENDFACTOR_INV_SRC1_COLOR);
138 PIPE_ASSERT(PIPE_BLENDFACTOR_INV_SRC1_ALPHA == BLENDFACTOR_INV_SRC1_ALPHA);
139
140 /* pipe_blend_func happens to match the hardware. */
141 PIPE_ASSERT(PIPE_BLEND_ADD == BLENDFUNCTION_ADD);
142 PIPE_ASSERT(PIPE_BLEND_SUBTRACT == BLENDFUNCTION_SUBTRACT);
143 PIPE_ASSERT(PIPE_BLEND_REVERSE_SUBTRACT == BLENDFUNCTION_REVERSE_SUBTRACT);
144 PIPE_ASSERT(PIPE_BLEND_MIN == BLENDFUNCTION_MIN);
145 PIPE_ASSERT(PIPE_BLEND_MAX == BLENDFUNCTION_MAX);
146
147 /* pipe_stencil_op happens to match the hardware. */
148 PIPE_ASSERT(PIPE_STENCIL_OP_KEEP == STENCILOP_KEEP);
149 PIPE_ASSERT(PIPE_STENCIL_OP_ZERO == STENCILOP_ZERO);
150 PIPE_ASSERT(PIPE_STENCIL_OP_REPLACE == STENCILOP_REPLACE);
151 PIPE_ASSERT(PIPE_STENCIL_OP_INCR == STENCILOP_INCRSAT);
152 PIPE_ASSERT(PIPE_STENCIL_OP_DECR == STENCILOP_DECRSAT);
153 PIPE_ASSERT(PIPE_STENCIL_OP_INCR_WRAP == STENCILOP_INCR);
154 PIPE_ASSERT(PIPE_STENCIL_OP_DECR_WRAP == STENCILOP_DECR);
155 PIPE_ASSERT(PIPE_STENCIL_OP_INVERT == STENCILOP_INVERT);
156 #undef PIPE_ASSERT
157 }
158
159 static unsigned
160 translate_prim_type(enum pipe_prim_type prim, uint8_t verts_per_patch)
161 {
162 assert(prim == PIPE_PRIM_PATCHES || verts_per_patch == 0);
163
164 static const unsigned map[] = {
165 [PIPE_PRIM_POINTS] = _3DPRIM_POINTLIST,
166 [PIPE_PRIM_LINES] = _3DPRIM_LINELIST,
167 [PIPE_PRIM_LINE_LOOP] = _3DPRIM_LINELOOP,
168 [PIPE_PRIM_LINE_STRIP] = _3DPRIM_LINESTRIP,
169 [PIPE_PRIM_TRIANGLES] = _3DPRIM_TRILIST,
170 [PIPE_PRIM_TRIANGLE_STRIP] = _3DPRIM_TRISTRIP,
171 [PIPE_PRIM_TRIANGLE_FAN] = _3DPRIM_TRIFAN,
172 [PIPE_PRIM_QUADS] = _3DPRIM_QUADLIST,
173 [PIPE_PRIM_QUAD_STRIP] = _3DPRIM_QUADSTRIP,
174 [PIPE_PRIM_POLYGON] = _3DPRIM_POLYGON,
175 [PIPE_PRIM_LINES_ADJACENCY] = _3DPRIM_LINELIST_ADJ,
176 [PIPE_PRIM_LINE_STRIP_ADJACENCY] = _3DPRIM_LINESTRIP_ADJ,
177 [PIPE_PRIM_TRIANGLES_ADJACENCY] = _3DPRIM_TRILIST_ADJ,
178 [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY] = _3DPRIM_TRISTRIP_ADJ,
179 [PIPE_PRIM_PATCHES] = _3DPRIM_PATCHLIST_1 - 1,
180 };
181
182 return map[prim] + verts_per_patch;
183 }
184
185 static unsigned
186 translate_compare_func(enum pipe_compare_func pipe_func)
187 {
188 static const unsigned map[] = {
189 [PIPE_FUNC_NEVER] = COMPAREFUNCTION_NEVER,
190 [PIPE_FUNC_LESS] = COMPAREFUNCTION_LESS,
191 [PIPE_FUNC_EQUAL] = COMPAREFUNCTION_EQUAL,
192 [PIPE_FUNC_LEQUAL] = COMPAREFUNCTION_LEQUAL,
193 [PIPE_FUNC_GREATER] = COMPAREFUNCTION_GREATER,
194 [PIPE_FUNC_NOTEQUAL] = COMPAREFUNCTION_NOTEQUAL,
195 [PIPE_FUNC_GEQUAL] = COMPAREFUNCTION_GEQUAL,
196 [PIPE_FUNC_ALWAYS] = COMPAREFUNCTION_ALWAYS,
197 };
198 return map[pipe_func];
199 }
200
201 static unsigned
202 translate_shadow_func(enum pipe_compare_func pipe_func)
203 {
204 /* Gallium specifies the result of shadow comparisons as:
205 *
206 * 1 if ref <op> texel,
207 * 0 otherwise.
208 *
209 * The hardware does:
210 *
211 * 0 if texel <op> ref,
212 * 1 otherwise.
213 *
214 * So we need to flip the operator and also negate.
215 */
216 static const unsigned map[] = {
217 [PIPE_FUNC_NEVER] = PREFILTEROPALWAYS,
218 [PIPE_FUNC_LESS] = PREFILTEROPLEQUAL,
219 [PIPE_FUNC_EQUAL] = PREFILTEROPNOTEQUAL,
220 [PIPE_FUNC_LEQUAL] = PREFILTEROPLESS,
221 [PIPE_FUNC_GREATER] = PREFILTEROPGEQUAL,
222 [PIPE_FUNC_NOTEQUAL] = PREFILTEROPEQUAL,
223 [PIPE_FUNC_GEQUAL] = PREFILTEROPGREATER,
224 [PIPE_FUNC_ALWAYS] = PREFILTEROPNEVER,
225 };
226 return map[pipe_func];
227 }
228
229 static unsigned
230 translate_cull_mode(unsigned pipe_face)
231 {
232 static const unsigned map[4] = {
233 [PIPE_FACE_NONE] = CULLMODE_NONE,
234 [PIPE_FACE_FRONT] = CULLMODE_FRONT,
235 [PIPE_FACE_BACK] = CULLMODE_BACK,
236 [PIPE_FACE_FRONT_AND_BACK] = CULLMODE_BOTH,
237 };
238 return map[pipe_face];
239 }
240
241 static unsigned
242 translate_fill_mode(unsigned pipe_polymode)
243 {
244 static const unsigned map[4] = {
245 [PIPE_POLYGON_MODE_FILL] = FILL_MODE_SOLID,
246 [PIPE_POLYGON_MODE_LINE] = FILL_MODE_WIREFRAME,
247 [PIPE_POLYGON_MODE_POINT] = FILL_MODE_POINT,
248 [PIPE_POLYGON_MODE_FILL_RECTANGLE] = FILL_MODE_SOLID,
249 };
250 return map[pipe_polymode];
251 }
252
253 static void
254 iris_upload_initial_gpu_state(struct iris_context *ice,
255 struct iris_batch *batch)
256 {
257 iris_emit_cmd(batch, GENX(3DSTATE_DRAWING_RECTANGLE), rect) {
258 rect.ClippedDrawingRectangleXMax = UINT16_MAX;
259 rect.ClippedDrawingRectangleYMax = UINT16_MAX;
260 }
261 iris_emit_cmd(batch, GENX(3DSTATE_SAMPLE_PATTERN), pat) {
262 GEN_SAMPLE_POS_1X(pat._1xSample);
263 GEN_SAMPLE_POS_2X(pat._2xSample);
264 GEN_SAMPLE_POS_4X(pat._4xSample);
265 GEN_SAMPLE_POS_8X(pat._8xSample);
266 GEN_SAMPLE_POS_16X(pat._16xSample);
267 }
268 iris_emit_cmd(batch, GENX(3DSTATE_AA_LINE_PARAMETERS), foo);
269 iris_emit_cmd(batch, GENX(3DSTATE_WM_CHROMAKEY), foo);
270 iris_emit_cmd(batch, GENX(3DSTATE_WM_HZ_OP), foo);
271 /* XXX: may need to set an offset for origin-UL framebuffers */
272 iris_emit_cmd(batch, GENX(3DSTATE_POLY_STIPPLE_OFFSET), foo);
273
274 /* Just assign a static partitioning. */
275 for (int i = 0; i <= MESA_SHADER_FRAGMENT; i++) {
276 iris_emit_cmd(batch, GENX(3DSTATE_PUSH_CONSTANT_ALLOC_VS), alloc) {
277 alloc._3DCommandSubOpcode = 18 + i;
278 alloc.ConstantBufferOffset = 6 * i;
279 alloc.ConstantBufferSize = i == MESA_SHADER_FRAGMENT ? 8 : 6;
280 }
281 }
282 }
283
284 static void
285 iris_launch_grid(struct pipe_context *ctx, const struct pipe_grid_info *info)
286 {
287 }
288
289 static void
290 iris_set_blend_color(struct pipe_context *ctx,
291 const struct pipe_blend_color *state)
292 {
293 struct iris_context *ice = (struct iris_context *) ctx;
294
295 memcpy(&ice->state.blend_color, state, sizeof(struct pipe_blend_color));
296 ice->state.dirty |= IRIS_DIRTY_COLOR_CALC_STATE;
297 }
298
299 struct iris_blend_state {
300 uint32_t ps_blend[GENX(3DSTATE_PS_BLEND_length)];
301 uint32_t blend_state[GENX(BLEND_STATE_length)];
302 uint32_t blend_entries[BRW_MAX_DRAW_BUFFERS *
303 GENX(BLEND_STATE_ENTRY_length)];
304 };
305
306 static void *
307 iris_create_blend_state(struct pipe_context *ctx,
308 const struct pipe_blend_state *state)
309 {
310 struct iris_blend_state *cso = malloc(sizeof(struct iris_blend_state));
311
312 iris_pack_state(GENX(BLEND_STATE), cso->blend_state, bs) {
313 bs.AlphaToCoverageEnable = state->alpha_to_coverage;
314 bs.IndependentAlphaBlendEnable = state->independent_blend_enable;
315 bs.AlphaToOneEnable = state->alpha_to_one;
316 bs.AlphaToCoverageDitherEnable = state->alpha_to_coverage;
317 bs.ColorDitherEnable = state->dither;
318 //bs.AlphaTestEnable = <comes from alpha state> :(
319 //bs.AlphaTestFunction = <comes from alpha state> :(
320 }
321
322 iris_pack_command(GENX(3DSTATE_PS_BLEND), cso->ps_blend, pb) {
323 //pb.HasWriteableRT = <comes from somewhere> :(
324 //pb.AlphaTestEnable = <comes from alpha state> :(
325 pb.AlphaToCoverageEnable = state->alpha_to_coverage;
326 pb.IndependentAlphaBlendEnable = state->independent_blend_enable;
327
328 pb.ColorBufferBlendEnable = state->rt[0].blend_enable;
329
330 pb.SourceBlendFactor = state->rt[0].rgb_src_factor;
331 pb.SourceAlphaBlendFactor = state->rt[0].alpha_func;
332 pb.DestinationBlendFactor = state->rt[0].rgb_dst_factor;
333 pb.DestinationAlphaBlendFactor = state->rt[0].alpha_dst_factor;
334 }
335
336 for (int i = 0; i < BRW_MAX_DRAW_BUFFERS; i++) {
337 iris_pack_state(GENX(BLEND_STATE_ENTRY), &cso->blend_entries[i], be) {
338 be.LogicOpEnable = state->logicop_enable;
339 be.LogicOpFunction = state->logicop_func;
340
341 be.PreBlendSourceOnlyClampEnable = false;
342 be.ColorClampRange = COLORCLAMP_RTFORMAT;
343 be.PreBlendColorClampEnable = true;
344 be.PostBlendColorClampEnable = true;
345
346 be.ColorBufferBlendEnable = state->rt[i].blend_enable;
347
348 be.ColorBlendFunction = state->rt[i].rgb_func;
349 be.AlphaBlendFunction = state->rt[i].alpha_func;
350 be.SourceBlendFactor = state->rt[i].rgb_src_factor;
351 be.SourceAlphaBlendFactor = state->rt[i].alpha_func;
352 be.DestinationBlendFactor = state->rt[i].rgb_dst_factor;
353 be.DestinationAlphaBlendFactor = state->rt[i].alpha_dst_factor;
354
355 be.WriteDisableRed = state->rt[i].colormask & PIPE_MASK_R;
356 be.WriteDisableGreen = state->rt[i].colormask & PIPE_MASK_G;
357 be.WriteDisableBlue = state->rt[i].colormask & PIPE_MASK_B;
358 be.WriteDisableAlpha = state->rt[i].colormask & PIPE_MASK_A;
359 }
360 }
361
362 return cso;
363 }
364
365 static void
366 iris_bind_blend_state(struct pipe_context *ctx, void *state)
367 {
368 struct iris_context *ice = (struct iris_context *) ctx;
369 ice->state.cso_blend = state;
370 ice->state.dirty |= IRIS_DIRTY_CC_VIEWPORT;
371 ice->state.dirty |= IRIS_DIRTY_WM_DEPTH_STENCIL;
372 }
373
374 struct iris_depth_stencil_alpha_state {
375 uint32_t wmds[GENX(3DSTATE_WM_DEPTH_STENCIL_length)];
376 uint32_t cc_vp[GENX(CC_VIEWPORT_length)];
377
378 struct pipe_alpha_state alpha; /* to BLEND_STATE, 3DSTATE_PS_BLEND */
379 };
380
381 static void *
382 iris_create_zsa_state(struct pipe_context *ctx,
383 const struct pipe_depth_stencil_alpha_state *state)
384 {
385 struct iris_depth_stencil_alpha_state *cso =
386 malloc(sizeof(struct iris_depth_stencil_alpha_state));
387
388 cso->alpha = state->alpha;
389
390 bool two_sided_stencil = state->stencil[1].enabled;
391
392 /* The state tracker needs to optimize away EQUAL writes for us. */
393 assert(!(state->depth.func == PIPE_FUNC_EQUAL && state->depth.writemask));
394
395 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL), cso->wmds, wmds) {
396 wmds.StencilFailOp = state->stencil[0].fail_op;
397 wmds.StencilPassDepthFailOp = state->stencil[0].zfail_op;
398 wmds.StencilPassDepthPassOp = state->stencil[0].zpass_op;
399 wmds.StencilTestFunction =
400 translate_compare_func(state->stencil[0].func);
401 wmds.BackfaceStencilFailOp = state->stencil[1].fail_op;
402 wmds.BackfaceStencilPassDepthFailOp = state->stencil[1].zfail_op;
403 wmds.BackfaceStencilPassDepthPassOp = state->stencil[1].zpass_op;
404 wmds.BackfaceStencilTestFunction =
405 translate_compare_func(state->stencil[1].func);
406 wmds.DepthTestFunction = translate_compare_func(state->depth.func);
407 wmds.DoubleSidedStencilEnable = two_sided_stencil;
408 wmds.StencilTestEnable = state->stencil[0].enabled;
409 wmds.StencilBufferWriteEnable =
410 state->stencil[0].writemask != 0 ||
411 (two_sided_stencil && state->stencil[1].writemask != 0);
412 wmds.DepthTestEnable = state->depth.enabled;
413 wmds.DepthBufferWriteEnable = state->depth.writemask;
414 wmds.StencilTestMask = state->stencil[0].valuemask;
415 wmds.StencilWriteMask = state->stencil[0].writemask;
416 wmds.BackfaceStencilTestMask = state->stencil[1].valuemask;
417 wmds.BackfaceStencilWriteMask = state->stencil[1].writemask;
418 /* wmds.[Backface]StencilReferenceValue are merged later */
419 }
420
421 iris_pack_state(GENX(CC_VIEWPORT), cso->cc_vp, ccvp) {
422 ccvp.MinimumDepth = state->depth.bounds_min;
423 ccvp.MaximumDepth = state->depth.bounds_max;
424 }
425
426 return cso;
427 }
428
429 static void
430 iris_bind_zsa_state(struct pipe_context *ctx, void *state)
431 {
432 struct iris_context *ice = (struct iris_context *) ctx;
433 struct iris_depth_stencil_alpha_state *old_cso = ice->state.cso_zsa;
434 struct iris_depth_stencil_alpha_state *new_cso = state;
435
436 if (new_cso) {
437 if (!old_cso || old_cso->alpha.ref_value != new_cso->alpha.ref_value) {
438 ice->state.dirty |= IRIS_DIRTY_COLOR_CALC_STATE;
439 }
440 }
441
442 ice->state.cso_zsa = new_cso;
443 ice->state.dirty |= IRIS_DIRTY_CC_VIEWPORT;
444 ice->state.dirty |= IRIS_DIRTY_WM_DEPTH_STENCIL;
445 }
446
447 struct iris_rasterizer_state {
448 uint32_t sf[GENX(3DSTATE_SF_length)];
449 uint32_t clip[GENX(3DSTATE_CLIP_length)];
450 uint32_t raster[GENX(3DSTATE_RASTER_length)];
451 uint32_t wm[GENX(3DSTATE_WM_length)];
452 uint32_t line_stipple[GENX(3DSTATE_LINE_STIPPLE_length)];
453
454 bool flatshade; /* for shader state */
455 bool light_twoside; /* for shader state */
456 bool rasterizer_discard; /* for 3DSTATE_STREAMOUT */
457 bool half_pixel_center; /* for 3DSTATE_MULTISAMPLE */
458 enum pipe_sprite_coord_mode sprite_coord_mode; /* PIPE_SPRITE_* */
459 };
460
461 static void *
462 iris_create_rasterizer_state(struct pipe_context *ctx,
463 const struct pipe_rasterizer_state *state)
464 {
465 struct iris_rasterizer_state *cso =
466 malloc(sizeof(struct iris_rasterizer_state));
467
468 #if 0
469 sprite_coord_mode -> SBE PointSpriteTextureCoordinateOrigin
470 sprite_coord_enable -> SBE PointSpriteTextureCoordinateEnable
471 point_quad_rasterization -> SBE?
472
473 not necessary?
474 {
475 poly_smooth
476 force_persample_interp - ?
477 bottom_edge_rule
478
479 offset_units_unscaled - cap not exposed
480 }
481 #endif
482
483 cso->flatshade = state->flatshade;
484 cso->light_twoside = state->light_twoside;
485 cso->rasterizer_discard = state->rasterizer_discard;
486 // for 3DSTATE_MULTISAMPLE, if we want it.
487 cso->half_pixel_center = state->half_pixel_center;
488
489 iris_pack_command(GENX(3DSTATE_SF), cso->sf, sf) {
490 sf.StatisticsEnable = true;
491 sf.ViewportTransformEnable = true;
492 sf.AALineDistanceMode = AALINEDISTANCE_TRUE;
493 sf.LineEndCapAntialiasingRegionWidth =
494 state->line_smooth ? _10pixels : _05pixels;
495 sf.LastPixelEnable = state->line_last_pixel;
496 sf.LineWidth = state->line_width;
497 sf.SmoothPointEnable = state->point_smooth;
498 sf.PointWidthSource = state->point_size_per_vertex ? Vertex : State;
499 sf.PointWidth = state->point_size;
500
501 if (state->flatshade_first) {
502 sf.TriangleStripListProvokingVertexSelect = 2;
503 sf.TriangleFanProvokingVertexSelect = 2;
504 sf.LineStripListProvokingVertexSelect = 1;
505 } else {
506 sf.TriangleFanProvokingVertexSelect = 1;
507 }
508 }
509
510 /* COMPLETE! */
511 iris_pack_command(GENX(3DSTATE_RASTER), cso->raster, rr) {
512 rr.FrontWinding = state->front_ccw ? CounterClockwise : Clockwise;
513 rr.CullMode = translate_cull_mode(state->cull_face);
514 rr.FrontFaceFillMode = translate_fill_mode(state->fill_front);
515 rr.BackFaceFillMode = translate_fill_mode(state->fill_back);
516 rr.DXMultisampleRasterizationEnable = state->multisample;
517 rr.GlobalDepthOffsetEnableSolid = state->offset_tri;
518 rr.GlobalDepthOffsetEnableWireframe = state->offset_line;
519 rr.GlobalDepthOffsetEnablePoint = state->offset_point;
520 rr.GlobalDepthOffsetConstant = state->offset_units;
521 rr.GlobalDepthOffsetScale = state->offset_scale;
522 rr.GlobalDepthOffsetClamp = state->offset_clamp;
523 rr.SmoothPointEnable = state->point_smooth;
524 rr.AntialiasingEnable = state->line_smooth;
525 rr.ScissorRectangleEnable = state->scissor;
526 rr.ViewportZNearClipTestEnable = state->depth_clip_near;
527 rr.ViewportZFarClipTestEnable = state->depth_clip_far;
528 //rr.ConservativeRasterizationEnable = not yet supported by Gallium...
529 }
530
531 iris_pack_command(GENX(3DSTATE_CLIP), cso->clip, cl) {
532 cl.StatisticsEnable = true;
533 cl.EarlyCullEnable = true;
534 cl.UserClipDistanceClipTestEnableBitmask = state->clip_plane_enable;
535 cl.ForceUserClipDistanceClipTestEnableBitmask = true;
536 cl.APIMode = state->clip_halfz ? APIMODE_D3D : APIMODE_OGL;
537 cl.GuardbandClipTestEnable = true;
538 cl.ClipMode = CLIPMODE_NORMAL;
539 cl.ClipEnable = true;
540 cl.ViewportXYClipTestEnable = state->point_tri_clip;
541 cl.MinimumPointWidth = 0.125;
542 cl.MaximumPointWidth = 255.875;
543 //.NonPerspectiveBarycentricEnable = <comes from FS prog> :(
544 //.ForceZeroRTAIndexEnable = <comes from FB layers being 0>
545
546 if (state->flatshade_first) {
547 cl.TriangleStripListProvokingVertexSelect = 2;
548 cl.TriangleFanProvokingVertexSelect = 2;
549 cl.LineStripListProvokingVertexSelect = 1;
550 } else {
551 cl.TriangleFanProvokingVertexSelect = 1;
552 }
553 }
554
555 iris_pack_command(GENX(3DSTATE_WM), cso->wm, wm) {
556 wm.LineAntialiasingRegionWidth = _10pixels;
557 wm.LineEndCapAntialiasingRegionWidth = _05pixels;
558 wm.PointRasterizationRule = RASTRULE_UPPER_RIGHT;
559 wm.StatisticsEnable = true;
560 wm.LineStippleEnable = state->line_stipple_enable;
561 wm.PolygonStippleEnable = state->poly_stipple_enable;
562 // wm.BarycentricInterpolationMode = <comes from FS program> :(
563 // wm.EarlyDepthStencilControl = <comes from FS program> :(
564 }
565
566 /* Remap from 0..255 back to 1..256 */
567 const unsigned line_stipple_factor = state->line_stipple_factor + 1;
568
569 iris_pack_command(GENX(3DSTATE_LINE_STIPPLE), cso->line_stipple, line) {
570 line.LineStipplePattern = state->line_stipple_pattern;
571 line.LineStippleInverseRepeatCount = 1.0f / line_stipple_factor;
572 line.LineStippleRepeatCount = line_stipple_factor;
573 }
574
575 return cso;
576 }
577
578 static void
579 iris_bind_rasterizer_state(struct pipe_context *ctx, void *state)
580 {
581 struct iris_context *ice = (struct iris_context *) ctx;
582 struct iris_rasterizer_state *old_cso = ice->state.cso_rast;
583 struct iris_rasterizer_state *new_cso = state;
584
585 if (new_cso) {
586 /* Try to avoid re-emitting 3DSTATE_LINE_STIPPLE, it's non-pipelined */
587 if (!old_cso || memcmp(old_cso->line_stipple, new_cso->line_stipple,
588 sizeof(old_cso->line_stipple)) != 0) {
589 ice->state.dirty |= IRIS_DIRTY_LINE_STIPPLE;
590 }
591
592 if (!old_cso ||
593 old_cso->half_pixel_center != new_cso->half_pixel_center) {
594 ice->state.dirty |= IRIS_DIRTY_MULTISAMPLE;
595 }
596 }
597
598 ice->state.cso_rast = new_cso;
599 ice->state.dirty |= IRIS_DIRTY_RASTER;
600 }
601
602 static uint32_t
603 translate_wrap(unsigned pipe_wrap)
604 {
605 static const unsigned map[] = {
606 [PIPE_TEX_WRAP_REPEAT] = TCM_WRAP,
607 [PIPE_TEX_WRAP_CLAMP] = TCM_HALF_BORDER,
608 [PIPE_TEX_WRAP_CLAMP_TO_EDGE] = TCM_CLAMP,
609 [PIPE_TEX_WRAP_CLAMP_TO_BORDER] = TCM_CLAMP_BORDER,
610 [PIPE_TEX_WRAP_MIRROR_REPEAT] = TCM_MIRROR,
611 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE] = TCM_MIRROR_ONCE,
612 [PIPE_TEX_WRAP_MIRROR_CLAMP] = -1, // XXX: ???
613 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER] = -1, // XXX: ???
614 };
615 return map[pipe_wrap];
616 }
617
618 /**
619 * Return true if the given wrap mode requires the border color to exist.
620 */
621 static bool
622 wrap_mode_needs_border_color(unsigned wrap_mode)
623 {
624 return wrap_mode == TCM_CLAMP_BORDER || wrap_mode == TCM_HALF_BORDER;
625 }
626
627 static unsigned
628 translate_mip_filter(enum pipe_tex_mipfilter pipe_mip)
629 {
630 static const unsigned map[] = {
631 [PIPE_TEX_MIPFILTER_NEAREST] = MIPFILTER_NEAREST,
632 [PIPE_TEX_MIPFILTER_LINEAR] = MIPFILTER_LINEAR,
633 [PIPE_TEX_MIPFILTER_NONE] = MIPFILTER_NONE,
634 };
635 return map[pipe_mip];
636 }
637
638 struct iris_sampler_state {
639 struct pipe_sampler_state base;
640
641 bool needs_border_color;
642
643 uint32_t sampler_state[GENX(SAMPLER_STATE_length)];
644 };
645
646 static void *
647 iris_create_sampler_state(struct pipe_context *pctx,
648 const struct pipe_sampler_state *state)
649 {
650 struct iris_sampler_state *cso = CALLOC_STRUCT(iris_sampler_state);
651
652 if (!cso)
653 return NULL;
654
655 STATIC_ASSERT(PIPE_TEX_FILTER_NEAREST == MAPFILTER_NEAREST);
656 STATIC_ASSERT(PIPE_TEX_FILTER_LINEAR == MAPFILTER_LINEAR);
657
658 unsigned wrap_s = translate_wrap(state->wrap_s);
659 unsigned wrap_t = translate_wrap(state->wrap_t);
660 unsigned wrap_r = translate_wrap(state->wrap_r);
661
662 cso->needs_border_color = wrap_mode_needs_border_color(wrap_s) ||
663 wrap_mode_needs_border_color(wrap_t) ||
664 wrap_mode_needs_border_color(wrap_r);
665
666 iris_pack_state(GENX(SAMPLER_STATE), cso->sampler_state, samp) {
667 samp.TCXAddressControlMode = wrap_s;
668 samp.TCYAddressControlMode = wrap_t;
669 samp.TCZAddressControlMode = wrap_r;
670 samp.CubeSurfaceControlMode = state->seamless_cube_map;
671 samp.NonnormalizedCoordinateEnable = !state->normalized_coords;
672 samp.MinModeFilter = state->min_img_filter;
673 samp.MagModeFilter = state->mag_img_filter;
674 samp.MipModeFilter = translate_mip_filter(state->min_mip_filter);
675 samp.MaximumAnisotropy = RATIO21;
676
677 if (state->max_anisotropy >= 2) {
678 if (state->min_img_filter == PIPE_TEX_FILTER_LINEAR) {
679 samp.MinModeFilter = MAPFILTER_ANISOTROPIC;
680 samp.AnisotropicAlgorithm = EWAApproximation;
681 }
682
683 if (state->mag_img_filter == PIPE_TEX_FILTER_LINEAR)
684 samp.MagModeFilter = MAPFILTER_ANISOTROPIC;
685
686 samp.MaximumAnisotropy =
687 MIN2((state->max_anisotropy - 2) / 2, RATIO161);
688 }
689
690 /* Set address rounding bits if not using nearest filtering. */
691 if (state->min_img_filter != PIPE_TEX_FILTER_NEAREST) {
692 samp.UAddressMinFilterRoundingEnable = true;
693 samp.VAddressMinFilterRoundingEnable = true;
694 samp.RAddressMinFilterRoundingEnable = true;
695 }
696
697 if (state->mag_img_filter != PIPE_TEX_FILTER_NEAREST) {
698 samp.UAddressMagFilterRoundingEnable = true;
699 samp.VAddressMagFilterRoundingEnable = true;
700 samp.RAddressMagFilterRoundingEnable = true;
701 }
702
703 if (state->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE)
704 samp.ShadowFunction = translate_shadow_func(state->compare_func);
705
706 const float hw_max_lod = GEN_GEN >= 7 ? 14 : 13;
707
708 samp.LODPreClampMode = CLAMP_MODE_OGL;
709 samp.MinLOD = CLAMP(state->min_lod, 0, hw_max_lod);
710 samp.MaxLOD = CLAMP(state->max_lod, 0, hw_max_lod);
711 samp.TextureLODBias = CLAMP(state->lod_bias, -16, 15);
712
713 //samp.BorderColorPointer = <<comes from elsewhere>>
714 }
715
716 return cso;
717 }
718
719 static void
720 iris_bind_sampler_states(struct pipe_context *ctx,
721 enum pipe_shader_type p_stage,
722 unsigned start, unsigned count,
723 void **states)
724 {
725 struct iris_context *ice = (struct iris_context *) ctx;
726 gl_shader_stage stage = stage_from_pipe(p_stage);
727
728 assert(start + count <= IRIS_MAX_TEXTURE_SAMPLERS);
729
730 for (int i = 0; i < count; i++) {
731 ice->state.samplers[stage][start + i] = states[i];
732 }
733
734 ice->state.dirty |= IRIS_DIRTY_SAMPLER_STATES_VS << stage;
735 }
736
737 struct iris_sampler_view {
738 struct pipe_sampler_view pipe;
739 struct isl_view view;
740 uint32_t surface_state[GENX(RENDER_SURFACE_STATE_length)];
741 };
742
743 /**
744 * Convert an swizzle enumeration (i.e. SWIZZLE_X) to one of the Gen7.5+
745 * "Shader Channel Select" enumerations (i.e. HSW_SCS_RED). The mappings are
746 *
747 * SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, SWIZZLE_ZERO, SWIZZLE_ONE
748 * 0 1 2 3 4 5
749 * 4 5 6 7 0 1
750 * SCS_RED, SCS_GREEN, SCS_BLUE, SCS_ALPHA, SCS_ZERO, SCS_ONE
751 *
752 * which is simply adding 4 then modding by 8 (or anding with 7).
753 *
754 * We then may need to apply workarounds for textureGather hardware bugs.
755 */
756 static enum isl_channel_select
757 pipe_swizzle_to_isl_channel(enum pipe_swizzle swizzle)
758 {
759 return (swizzle + 4) & 7;
760 }
761
762 static struct pipe_sampler_view *
763 iris_create_sampler_view(struct pipe_context *ctx,
764 struct pipe_resource *tex,
765 const struct pipe_sampler_view *tmpl)
766 {
767 struct iris_screen *screen = (struct iris_screen *)ctx->screen;
768 struct iris_resource *itex = (struct iris_resource *) tex;
769 struct iris_sampler_view *isv = calloc(1, sizeof(struct iris_sampler_view));
770
771 if (!isv)
772 return NULL;
773
774 /* initialize base object */
775 isv->pipe = *tmpl;
776 isv->pipe.context = ctx;
777 isv->pipe.texture = NULL;
778 pipe_reference_init(&isv->pipe.reference, 1);
779 pipe_resource_reference(&isv->pipe.texture, tex);
780
781 /* XXX: do we need brw_get_texture_swizzle hacks here? */
782
783 isv->view = (struct isl_view) {
784 .format = iris_isl_format_for_pipe_format(tmpl->format),
785 .base_level = tmpl->u.tex.first_level,
786 .levels = tmpl->u.tex.last_level - tmpl->u.tex.first_level + 1,
787 .base_array_layer = tmpl->u.tex.first_layer,
788 .array_len = tmpl->u.tex.last_layer - tmpl->u.tex.first_layer + 1,
789 .swizzle = (struct isl_swizzle) {
790 .r = pipe_swizzle_to_isl_channel(tmpl->swizzle_r),
791 .g = pipe_swizzle_to_isl_channel(tmpl->swizzle_g),
792 .b = pipe_swizzle_to_isl_channel(tmpl->swizzle_b),
793 .a = pipe_swizzle_to_isl_channel(tmpl->swizzle_a),
794 },
795 .usage = ISL_SURF_USAGE_TEXTURE_BIT,
796 };
797
798 isl_surf_fill_state(&screen->isl_dev, isv->surface_state,
799 .surf = &itex->surf, .view = &isv->view,
800 .mocs = MOCS_WB);
801 // .address = ...
802 // .aux_surf =
803 // .clear_color = clear_color,
804
805 return &isv->pipe;
806 }
807
808 struct iris_surface {
809 struct pipe_surface pipe;
810 struct isl_view view;
811 uint32_t surface_state[GENX(RENDER_SURFACE_STATE_length)];
812 };
813
814 static struct pipe_surface *
815 iris_create_surface(struct pipe_context *ctx,
816 struct pipe_resource *tex,
817 const struct pipe_surface *tmpl)
818 {
819 struct iris_screen *screen = (struct iris_screen *)ctx->screen;
820 struct iris_surface *surf = calloc(1, sizeof(struct iris_surface));
821 struct pipe_surface *psurf = &surf->pipe;
822 struct iris_resource *itex = (struct iris_resource *) tex;
823
824 if (!surf)
825 return NULL;
826
827 pipe_reference_init(&psurf->reference, 1);
828 pipe_resource_reference(&psurf->texture, tex);
829 psurf->context = ctx;
830 psurf->format = tmpl->format;
831 psurf->width = tex->width0;
832 psurf->height = tex->height0;
833 psurf->texture = tex;
834 psurf->u.tex.first_layer = tmpl->u.tex.first_layer;
835 psurf->u.tex.last_layer = tmpl->u.tex.last_layer;
836 psurf->u.tex.level = tmpl->u.tex.level;
837
838 surf->view = (struct isl_view) {
839 .format = iris_isl_format_for_pipe_format(tmpl->format),
840 .base_level = tmpl->u.tex.level,
841 .levels = 1,
842 .base_array_layer = tmpl->u.tex.first_layer,
843 .array_len = tmpl->u.tex.last_layer - tmpl->u.tex.first_layer + 1,
844 .swizzle = ISL_SWIZZLE_IDENTITY,
845 // XXX: DEPTH_BIt, STENCIL_BIT...CUBE_BIT? Other bits?!
846 .usage = ISL_SURF_USAGE_RENDER_TARGET_BIT,
847 };
848
849 isl_surf_fill_state(&screen->isl_dev, surf->surface_state,
850 .surf = &itex->surf, .view = &surf->view,
851 .mocs = MOCS_WB);
852 // .address = ...
853 // .aux_surf =
854 // .clear_color = clear_color,
855
856 return psurf;
857 }
858
859 static void
860 iris_set_sampler_views(struct pipe_context *ctx,
861 enum pipe_shader_type shader,
862 unsigned start, unsigned count,
863 struct pipe_sampler_view **views)
864 {
865 }
866
867 static void
868 iris_set_clip_state(struct pipe_context *ctx,
869 const struct pipe_clip_state *state)
870 {
871 }
872
873 static void
874 iris_set_polygon_stipple(struct pipe_context *ctx,
875 const struct pipe_poly_stipple *state)
876 {
877 struct iris_context *ice = (struct iris_context *) ctx;
878 memcpy(&ice->state.poly_stipple, state, sizeof(*state));
879 ice->state.dirty |= IRIS_DIRTY_POLYGON_STIPPLE;
880 }
881
882 static void
883 iris_set_sample_mask(struct pipe_context *ctx, unsigned sample_mask)
884 {
885 struct iris_context *ice = (struct iris_context *) ctx;
886
887 ice->state.sample_mask = sample_mask;
888 ice->state.dirty |= IRIS_DIRTY_SAMPLE_MASK;
889 }
890
891 static void
892 iris_set_scissor_states(struct pipe_context *ctx,
893 unsigned start_slot,
894 unsigned num_scissors,
895 const struct pipe_scissor_state *state)
896 {
897 struct iris_context *ice = (struct iris_context *) ctx;
898
899 // XXX: start_slot
900 ice->state.num_scissors = num_scissors;
901
902 for (unsigned i = start_slot; i < start_slot + num_scissors; i++) {
903 ice->state.scissors[i] = *state;
904 }
905
906 ice->state.dirty |= IRIS_DIRTY_SCISSOR_RECT;
907 }
908
909 static void
910 iris_set_stencil_ref(struct pipe_context *ctx,
911 const struct pipe_stencil_ref *state)
912 {
913 struct iris_context *ice = (struct iris_context *) ctx;
914 memcpy(&ice->state.stencil_ref, state, sizeof(*state));
915 ice->state.dirty |= IRIS_DIRTY_WM_DEPTH_STENCIL;
916 }
917
918
919 struct iris_viewport_state {
920 uint32_t sf_cl_vp[GENX(SF_CLIP_VIEWPORT_length)];
921 };
922
923 static float
924 extent_from_matrix(const struct pipe_viewport_state *state, int axis)
925 {
926 return fabsf(state->scale[axis]) * state->translate[axis];
927 }
928
929 #if 0
930 static void
931 calculate_guardband_size(uint32_t fb_width, uint32_t fb_height,
932 float m00, float m11, float m30, float m31,
933 float *xmin, float *xmax,
934 float *ymin, float *ymax)
935 {
936 /* According to the "Vertex X,Y Clamping and Quantization" section of the
937 * Strips and Fans documentation:
938 *
939 * "The vertex X and Y screen-space coordinates are also /clamped/ to the
940 * fixed-point "guardband" range supported by the rasterization hardware"
941 *
942 * and
943 *
944 * "In almost all circumstances, if an object’s vertices are actually
945 * modified by this clamping (i.e., had X or Y coordinates outside of
946 * the guardband extent the rendered object will not match the intended
947 * result. Therefore software should take steps to ensure that this does
948 * not happen - e.g., by clipping objects such that they do not exceed
949 * these limits after the Drawing Rectangle is applied."
950 *
951 * I believe the fundamental restriction is that the rasterizer (in
952 * the SF/WM stages) have a limit on the number of pixels that can be
953 * rasterized. We need to ensure any coordinates beyond the rasterizer
954 * limit are handled by the clipper. So effectively that limit becomes
955 * the clipper's guardband size.
956 *
957 * It goes on to say:
958 *
959 * "In addition, in order to be correctly rendered, objects must have a
960 * screenspace bounding box not exceeding 8K in the X or Y direction.
961 * This additional restriction must also be comprehended by software,
962 * i.e., enforced by use of clipping."
963 *
964 * This makes no sense. Gen7+ hardware supports 16K render targets,
965 * and you definitely need to be able to draw polygons that fill the
966 * surface. Our assumption is that the rasterizer was limited to 8K
967 * on Sandybridge, which only supports 8K surfaces, and it was actually
968 * increased to 16K on Ivybridge and later.
969 *
970 * So, limit the guardband to 16K on Gen7+ and 8K on Sandybridge.
971 */
972 const float gb_size = GEN_GEN >= 7 ? 16384.0f : 8192.0f;
973
974 if (m00 != 0 && m11 != 0) {
975 /* First, we compute the screen-space render area */
976 const float ss_ra_xmin = MIN3( 0, m30 + m00, m30 - m00);
977 const float ss_ra_xmax = MAX3( fb_width, m30 + m00, m30 - m00);
978 const float ss_ra_ymin = MIN3( 0, m31 + m11, m31 - m11);
979 const float ss_ra_ymax = MAX3(fb_height, m31 + m11, m31 - m11);
980
981 /* We want the guardband to be centered on that */
982 const float ss_gb_xmin = (ss_ra_xmin + ss_ra_xmax) / 2 - gb_size;
983 const float ss_gb_xmax = (ss_ra_xmin + ss_ra_xmax) / 2 + gb_size;
984 const float ss_gb_ymin = (ss_ra_ymin + ss_ra_ymax) / 2 - gb_size;
985 const float ss_gb_ymax = (ss_ra_ymin + ss_ra_ymax) / 2 + gb_size;
986
987 /* Now we need it in native device coordinates */
988 const float ndc_gb_xmin = (ss_gb_xmin - m30) / m00;
989 const float ndc_gb_xmax = (ss_gb_xmax - m30) / m00;
990 const float ndc_gb_ymin = (ss_gb_ymin - m31) / m11;
991 const float ndc_gb_ymax = (ss_gb_ymax - m31) / m11;
992
993 /* Thanks to Y-flipping and ORIGIN_UPPER_LEFT, the Y coordinates may be
994 * flipped upside-down. X should be fine though.
995 */
996 assert(ndc_gb_xmin <= ndc_gb_xmax);
997 *xmin = ndc_gb_xmin;
998 *xmax = ndc_gb_xmax;
999 *ymin = MIN2(ndc_gb_ymin, ndc_gb_ymax);
1000 *ymax = MAX2(ndc_gb_ymin, ndc_gb_ymax);
1001 } else {
1002 /* The viewport scales to 0, so nothing will be rendered. */
1003 *xmin = 0.0f;
1004 *xmax = 0.0f;
1005 *ymin = 0.0f;
1006 *ymax = 0.0f;
1007 }
1008 }
1009 #endif
1010
1011 static void
1012 iris_set_viewport_states(struct pipe_context *ctx,
1013 unsigned start_slot,
1014 unsigned num_viewports,
1015 const struct pipe_viewport_state *state)
1016 {
1017 struct iris_context *ice = (struct iris_context *) ctx;
1018 struct iris_viewport_state *cso =
1019 malloc(sizeof(struct iris_viewport_state));
1020
1021 for (unsigned i = start_slot; i < start_slot + num_viewports; i++) {
1022 float x_extent = extent_from_matrix(&state[i], 0);
1023 float y_extent = extent_from_matrix(&state[i], 1);
1024
1025 iris_pack_state(GENX(SF_CLIP_VIEWPORT), cso->sf_cl_vp, vp) {
1026 vp.ViewportMatrixElementm00 = state[i].scale[0];
1027 vp.ViewportMatrixElementm11 = state[i].scale[1];
1028 vp.ViewportMatrixElementm22 = state[i].scale[2];
1029 vp.ViewportMatrixElementm30 = state[i].translate[0];
1030 vp.ViewportMatrixElementm31 = state[i].translate[1];
1031 vp.ViewportMatrixElementm32 = state[i].translate[2];
1032 /* XXX: in i965 this is computed based on the drawbuffer size,
1033 * but we don't have that here...
1034 */
1035 vp.XMinClipGuardband = -1.0;
1036 vp.XMaxClipGuardband = 1.0;
1037 vp.YMinClipGuardband = -1.0;
1038 vp.YMaxClipGuardband = 1.0;
1039 vp.XMinViewPort = -x_extent;
1040 vp.XMaxViewPort = x_extent;
1041 vp.YMinViewPort = -y_extent;
1042 vp.YMaxViewPort = y_extent;
1043 }
1044 }
1045
1046 ice->state.cso_vp = cso;
1047 // XXX: start_slot
1048 ice->state.num_viewports = num_viewports;
1049 ice->state.dirty |= IRIS_DIRTY_SF_CL_VIEWPORT;
1050 }
1051
1052 struct iris_depth_state
1053 {
1054 uint32_t depth_buffer[GENX(3DSTATE_DEPTH_BUFFER_length)];
1055 uint32_t hier_depth_buffer[GENX(3DSTATE_HIER_DEPTH_BUFFER_length)];
1056 uint32_t stencil_buffer[GENX(3DSTATE_STENCIL_BUFFER_length)];
1057 };
1058
1059 static void
1060 iris_set_framebuffer_state(struct pipe_context *ctx,
1061 const struct pipe_framebuffer_state *state)
1062 {
1063 struct iris_context *ice = (struct iris_context *) ctx;
1064 struct pipe_framebuffer_state *cso = &ice->state.framebuffer;
1065
1066 if (cso->samples != state->samples) {
1067 ice->state.dirty |= IRIS_DIRTY_MULTISAMPLE;
1068 }
1069
1070 cso->width = state->width;
1071 cso->height = state->height;
1072 cso->layers = state->layers;
1073 cso->samples = state->samples;
1074
1075 unsigned i;
1076 for (i = 0; i < state->nr_cbufs; i++)
1077 pipe_surface_reference(&cso->cbufs[i], state->cbufs[i]);
1078 for (; i < cso->nr_cbufs; i++)
1079 pipe_surface_reference(&cso->cbufs[i], NULL);
1080
1081 cso->nr_cbufs = state->nr_cbufs;
1082
1083 pipe_surface_reference(&cso->zsbuf, state->zsbuf);
1084
1085 struct isl_depth_stencil_hiz_emit_info info = {
1086 .mocs = MOCS_WB,
1087 };
1088
1089 // XXX: depth buffers
1090 }
1091
1092 static void
1093 iris_set_constant_buffer(struct pipe_context *ctx,
1094 enum pipe_shader_type shader, uint index,
1095 const struct pipe_constant_buffer *cb)
1096 {
1097 }
1098
1099
1100 static void
1101 iris_sampler_view_destroy(struct pipe_context *ctx,
1102 struct pipe_sampler_view *state)
1103 {
1104 pipe_resource_reference(&state->texture, NULL);
1105 free(state);
1106 }
1107
1108
1109 static void
1110 iris_surface_destroy(struct pipe_context *ctx, struct pipe_surface *surface)
1111 {
1112 pipe_resource_reference(&surface->texture, NULL);
1113 free(surface);
1114 }
1115
1116 static void
1117 iris_delete_state(struct pipe_context *ctx, void *state)
1118 {
1119 free(state);
1120 }
1121
1122 struct iris_vertex_buffer_state {
1123 uint32_t vertex_buffers[1 + 33 * GENX(VERTEX_BUFFER_STATE_length)];
1124 unsigned length; /* length of 3DSTATE_VERTEX_BUFFERS in DWords */
1125 };
1126
1127 static void
1128 iris_set_vertex_buffers(struct pipe_context *ctx,
1129 unsigned start_slot, unsigned count,
1130 const struct pipe_vertex_buffer *buffers)
1131 {
1132 struct iris_context *ice = (struct iris_context *) ctx;
1133 struct iris_vertex_buffer_state *cso =
1134 malloc(sizeof(struct iris_vertex_buffer_state));
1135
1136 cso->length = 4 * count - 1;
1137
1138 iris_pack_state(GENX(3DSTATE_VERTEX_BUFFERS), cso->vertex_buffers, vb) {
1139 vb.DWordLength = cso->length;
1140 }
1141
1142 /* If there are no buffers, do nothing. We can leave the stale
1143 * 3DSTATE_VERTEX_BUFFERS in place - as long as there are no vertex
1144 * elements that point to them, it should be fine.
1145 */
1146 if (!buffers)
1147 return;
1148
1149 uint32_t *vb_pack_dest = &cso->vertex_buffers[1];
1150
1151 for (unsigned i = 0; i < count; i++) {
1152 assert(!buffers[i].is_user_buffer);
1153
1154 iris_pack_state(GENX(VERTEX_BUFFER_STATE), vb_pack_dest, vb) {
1155 vb.VertexBufferIndex = start_slot + i;
1156 vb.MOCS = MOCS_WB;
1157 vb.AddressModifyEnable = true;
1158 vb.BufferPitch = buffers[i].stride;
1159 //vb.BufferStartingAddress = ro_bo(bo, buffers[i].buffer_offset);
1160 //vb.BufferSize = bo->size;
1161 }
1162
1163 vb_pack_dest += GENX(VERTEX_BUFFER_STATE_length);
1164 }
1165
1166 ice->state.cso_vertex_buffers = cso;
1167 ice->state.dirty |= IRIS_DIRTY_VERTEX_BUFFERS;
1168 }
1169
1170 struct iris_vertex_element_state {
1171 uint32_t vertex_elements[1 + 33 * GENX(VERTEX_ELEMENT_STATE_length)];
1172 uint32_t vf_instancing[GENX(3DSTATE_VF_INSTANCING_length)][33];
1173 unsigned count;
1174 };
1175
1176 static void *
1177 iris_create_vertex_elements(struct pipe_context *ctx,
1178 unsigned count,
1179 const struct pipe_vertex_element *state)
1180 {
1181 struct iris_vertex_element_state *cso =
1182 malloc(sizeof(struct iris_vertex_element_state));
1183
1184 cso->count = count;
1185
1186 /* TODO:
1187 * - create edge flag one
1188 * - create SGV ones
1189 * - if those are necessary, use count + 1/2/3... OR in the length
1190 */
1191 iris_pack_state(GENX(3DSTATE_VERTEX_ELEMENTS), cso->vertex_elements, ve);
1192
1193 uint32_t *ve_pack_dest = &cso->vertex_elements[1];
1194
1195 for (int i = 0; i < count; i++) {
1196 iris_pack_state(GENX(VERTEX_ELEMENT_STATE), ve_pack_dest, ve) {
1197 ve.VertexBufferIndex = state[i].vertex_buffer_index;
1198 ve.Valid = true;
1199 ve.SourceElementOffset = state[i].src_offset;
1200 ve.SourceElementFormat =
1201 iris_isl_format_for_pipe_format(state[i].src_format);
1202 }
1203
1204 iris_pack_state(GENX(3DSTATE_VF_INSTANCING), cso->vf_instancing[i], vi) {
1205 vi.VertexElementIndex = i;
1206 vi.InstancingEnable = state[i].instance_divisor > 0;
1207 vi.InstanceDataStepRate = state[i].instance_divisor;
1208 }
1209
1210 ve_pack_dest += GENX(VERTEX_ELEMENT_STATE_length);
1211 }
1212
1213 return cso;
1214 }
1215
1216 static void
1217 iris_bind_vertex_elements_state(struct pipe_context *ctx, void *state)
1218 {
1219 struct iris_context *ice = (struct iris_context *) ctx;
1220
1221 ice->state.cso_vertex_elements = state;
1222 ice->state.dirty |= IRIS_DIRTY_VERTEX_ELEMENTS;
1223 }
1224
1225 static void *
1226 iris_create_compute_state(struct pipe_context *ctx,
1227 const struct pipe_compute_state *state)
1228 {
1229 return malloc(1);
1230 }
1231
1232 static struct pipe_stream_output_target *
1233 iris_create_stream_output_target(struct pipe_context *ctx,
1234 struct pipe_resource *res,
1235 unsigned buffer_offset,
1236 unsigned buffer_size)
1237 {
1238 struct pipe_stream_output_target *t =
1239 CALLOC_STRUCT(pipe_stream_output_target);
1240 if (!t)
1241 return NULL;
1242
1243 pipe_reference_init(&t->reference, 1);
1244 pipe_resource_reference(&t->buffer, res);
1245 t->buffer_offset = buffer_offset;
1246 t->buffer_size = buffer_size;
1247 return t;
1248 }
1249
1250 static void
1251 iris_stream_output_target_destroy(struct pipe_context *ctx,
1252 struct pipe_stream_output_target *t)
1253 {
1254 pipe_resource_reference(&t->buffer, NULL);
1255 free(t);
1256 }
1257
1258 static void
1259 iris_set_stream_output_targets(struct pipe_context *ctx,
1260 unsigned num_targets,
1261 struct pipe_stream_output_target **targets,
1262 const unsigned *offsets)
1263 {
1264 }
1265
1266 void
1267 iris_upload_render_state(struct iris_context *ice,
1268 struct iris_batch *batch,
1269 const struct pipe_draw_info *draw)
1270 {
1271 const uint64_t dirty = ice->state.dirty;
1272
1273 if (dirty & IRIS_DIRTY_WM_DEPTH_STENCIL) {
1274 struct iris_depth_stencil_alpha_state *cso = ice->state.cso_zsa;
1275 struct pipe_stencil_ref *p_stencil_refs = &ice->state.stencil_ref;
1276
1277 uint32_t stencil_refs[GENX(3DSTATE_WM_DEPTH_STENCIL_length)];
1278 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL), &stencil_refs, wmds) {
1279 wmds.StencilReferenceValue = p_stencil_refs->ref_value[0];
1280 wmds.BackfaceStencilReferenceValue = p_stencil_refs->ref_value[1];
1281 }
1282 iris_emit_merge(batch, cso->wmds, stencil_refs);
1283 }
1284
1285 if (dirty & IRIS_DIRTY_CC_VIEWPORT) {
1286 struct iris_depth_stencil_alpha_state *cso = ice->state.cso_zsa;
1287 iris_emit_cmd(batch, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC), ptr) {
1288 ptr.CCViewportPointer =
1289 iris_emit_state(batch, cso->cc_vp, sizeof(cso->cc_vp), 32);
1290 }
1291 }
1292
1293 if (dirty & IRIS_DIRTY_PS_BLEND) {
1294 struct iris_blend_state *cso = ice->state.cso_blend;
1295 iris_batch_emit(batch, cso->ps_blend, sizeof(cso->ps_blend));
1296 }
1297
1298 if (dirty & IRIS_DIRTY_BLEND_STATE) {
1299 //struct iris_blend_state *cso = ice->state.cso_blend;
1300 // XXX: 3DSTATE_BLEND_STATE_POINTERS - BLEND_STATE
1301 // -> from iris_blend_state (most) + iris_depth_stencil_alpha_state
1302 // (alpha test function/enable) + has writeable RT from ???????
1303 }
1304
1305 if (dirty & IRIS_DIRTY_SF_CL_VIEWPORT) {
1306 struct iris_viewport_state *cso = ice->state.cso_vp;
1307 iris_emit_cmd(batch, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP), ptr) {
1308 ptr.SFClipViewportPointer =
1309 iris_emit_state(batch, cso->sf_cl_vp, sizeof(cso->sf_cl_vp), 64);
1310 }
1311 }
1312
1313 if (dirty & IRIS_DIRTY_CLIP) {
1314 struct iris_rasterizer_state *cso = ice->state.cso_rast;
1315
1316 uint32_t dynamic_clip[GENX(3DSTATE_CLIP_length)];
1317 iris_pack_command(GENX(3DSTATE_CLIP), &dynamic_clip, cl) {
1318 //.NonPerspectiveBarycentricEnable = <comes from FS prog> :(
1319 //.ForceZeroRTAIndexEnable = <comes from FB layers being 0>
1320 // also userclip stuffs...
1321 }
1322 iris_emit_merge(batch, cso->clip, dynamic_clip);
1323 }
1324
1325 if (dirty & IRIS_DIRTY_RASTER) {
1326 struct iris_rasterizer_state *cso = ice->state.cso_rast;
1327 iris_batch_emit(batch, cso->raster, sizeof(cso->raster));
1328 iris_batch_emit(batch, cso->sf, sizeof(cso->sf));
1329 }
1330
1331 if (dirty & IRIS_DIRTY_LINE_STIPPLE) {
1332 struct iris_rasterizer_state *cso = ice->state.cso_rast;
1333 iris_batch_emit(batch, cso->line_stipple, sizeof(cso->line_stipple));
1334 }
1335
1336 if (dirty & IRIS_DIRTY_SCISSOR) {
1337 uint32_t scissor_offset =
1338 iris_emit_state(batch, ice->state.scissors,
1339 sizeof(struct pipe_scissor_state) *
1340 ice->state.num_scissors, 32);
1341
1342 iris_emit_cmd(batch, GENX(3DSTATE_SCISSOR_STATE_POINTERS), ptr) {
1343 ptr.ScissorRectPointer = scissor_offset;
1344 }
1345 }
1346
1347 if (dirty & IRIS_DIRTY_POLYGON_STIPPLE) {
1348 iris_emit_cmd(batch, GENX(3DSTATE_POLY_STIPPLE_PATTERN), poly) {
1349 for (int i = 0; i < 32; i++) {
1350 poly.PatternRow[i] = ice->state.poly_stipple.stipple[i];
1351 }
1352 }
1353 }
1354
1355 if (dirty & IRIS_DIRTY_COLOR_CALC_STATE) {
1356 struct iris_depth_stencil_alpha_state *cso = ice->state.cso_zsa;
1357 uint32_t cc_offset;
1358 void *cc_map =
1359 iris_alloc_state(batch,
1360 sizeof(uint32_t) * GENX(COLOR_CALC_STATE_length),
1361 64, &cc_offset);
1362 iris_pack_state(GENX(COLOR_CALC_STATE), cc_map, cc) {
1363 cc.AlphaTestFormat = ALPHATEST_FLOAT32;
1364 cc.AlphaReferenceValueAsFLOAT32 = cso->alpha.ref_value;
1365 cc.BlendConstantColorRed = ice->state.blend_color.color[0];
1366 cc.BlendConstantColorGreen = ice->state.blend_color.color[1];
1367 cc.BlendConstantColorBlue = ice->state.blend_color.color[2];
1368 cc.BlendConstantColorAlpha = ice->state.blend_color.color[3];
1369 }
1370 iris_emit_cmd(batch, GENX(3DSTATE_CC_STATE_POINTERS), ptr) {
1371 ptr.ColorCalcStatePointer = cc_offset;
1372 ptr.ColorCalcStatePointerValid = true;
1373 }
1374 }
1375
1376 if (dirty & IRIS_DIRTY_VERTEX_BUFFERS) {
1377 struct iris_vertex_buffer_state *cso = ice->state.cso_vertex_buffers;
1378 // XXX: address!!!
1379 iris_batch_emit(batch, cso->vertex_buffers,
1380 sizeof(uint32_t) * cso->length);
1381 }
1382
1383 if (dirty & IRIS_DIRTY_VERTEX_ELEMENTS) {
1384 struct iris_vertex_element_state *cso = ice->state.cso_vertex_elements;
1385 iris_batch_emit(batch, cso->vertex_elements, sizeof(uint32_t) *
1386 (1 + cso->count * GENX(VERTEX_ELEMENT_STATE_length)));
1387 for (int i = 0; i < cso->count; i++) {
1388 iris_batch_emit(batch, cso->vf_instancing[i],
1389 sizeof(cso->vf_instancing[0]));
1390 }
1391 for (int i = 0; i < cso->count; i++) {
1392 /* TODO: vertexid, instanceid support */
1393 iris_emit_cmd(batch, GENX(3DSTATE_VF_SGVS), sgvs);
1394 }
1395 }
1396
1397 if (dirty & IRIS_DIRTY_MULTISAMPLE) {
1398 iris_emit_cmd(batch, GENX(3DSTATE_MULTISAMPLE), ms) {
1399 ms.PixelLocation =
1400 ice->state.cso_rast->half_pixel_center ? CENTER : UL_CORNER;
1401 ms.NumberofMultisamples = ffs(ice->state.framebuffer.samples) - 1;
1402 }
1403 }
1404
1405 if (dirty & IRIS_DIRTY_SAMPLE_MASK) {
1406 iris_emit_cmd(batch, GENX(3DSTATE_SAMPLE_MASK), ms) {
1407 ms.SampleMask = ice->state.sample_mask;
1408 }
1409 }
1410
1411 for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) {
1412 if (!(dirty & (IRIS_DIRTY_SAMPLER_STATES_VS << stage)))
1413 continue;
1414
1415 // XXX: get sampler count from shader; don't emit them all...
1416 const int count = IRIS_MAX_TEXTURE_SAMPLERS;
1417
1418 uint32_t offset;
1419 uint32_t *map = iris_alloc_state(batch,
1420 count * 4 * GENX(SAMPLER_STATE_length),
1421 32, &offset);
1422
1423 for (int i = 0; i < count; i++) {
1424 memcpy(map, ice->state.samplers[stage][i]->sampler_state,
1425 4 * GENX(SAMPLER_STATE_length));
1426 map += GENX(SAMPLER_STATE_length);
1427 }
1428
1429 iris_emit_cmd(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS), ptr) {
1430 ptr._3DCommandSubOpcode = 43 + stage;
1431 ptr.PointertoVSSamplerState = offset;
1432 }
1433 }
1434
1435 if (1) {
1436 iris_emit_cmd(batch, GENX(3DSTATE_VF_TOPOLOGY), topo) {
1437 topo.PrimitiveTopologyType =
1438 translate_prim_type(draw->mode, draw->vertices_per_patch);
1439 }
1440 }
1441
1442 if (1) {
1443 iris_emit_cmd(batch, GENX(3DSTATE_VF), vf) {
1444 vf.IndexedDrawCutIndexEnable = draw->primitive_restart;
1445 vf.CutIndex = draw->restart_index;
1446 }
1447 }
1448
1449 // draw->index_size > 0
1450 if (1) {
1451 struct iris_resource *res = (struct iris_resource *)draw->index.resource;
1452
1453 assert(!draw->has_user_indices);
1454
1455 iris_emit_cmd(batch, GENX(3DSTATE_INDEX_BUFFER), ib) {
1456 ib.IndexFormat = draw->index_size;
1457 ib.MOCS = MOCS_WB;
1458 ib.BufferSize = res->bo->size;
1459 // XXX: gah, addresses :( need two different combine address funcs
1460 // ib.BufferStartingAddress = res->bo;
1461 }
1462
1463 assert(!draw->indirect); // XXX: indirect support
1464
1465 iris_emit_cmd(batch, GENX(3DPRIMITIVE), prim) {
1466 prim.StartInstanceLocation = draw->start_instance;
1467 prim.InstanceCount = draw->instance_count;
1468
1469 // XXX: this is probably bonkers.
1470 prim.StartVertexLocation = draw->start;
1471
1472 if (draw->index_size) {
1473 prim.BaseVertexLocation += draw->index_bias;
1474 } else {
1475 prim.StartVertexLocation += draw->index_bias;
1476 }
1477
1478 //prim.BaseVertexLocation = ...;
1479 }
1480 }
1481 #if 0
1482 l3 configuration
1483
1484 3DSTATE_URB_*
1485 -> TODO
1486
1487 3DSTATE_CONSTANT_* - push constants
1488 -> TODO
1489
1490 Surfaces:
1491 - pull constants
1492 - ubos/ssbos/abos
1493 - images
1494 - textures
1495 - render targets - write and read
1496 3DSTATE_BINDING_TABLE_POINTERS_*
1497 -> TODO
1498
1499 3DSTATE_VS
1500 3DSTATE_HS
1501 3DSTATE_TE
1502 3DSTATE_DS
1503 3DSTATE_GS
1504 3DSTATE_PS_EXTRA
1505 3DSTATE_PS
1506 3DSTATE_STREAMOUT
1507 3DSTATE_SO_BUFFER
1508 3DSTATE_SO_DECL_LIST
1509
1510 3DSTATE_WM
1511 -> iris_raster_state + FS state (barycentric, EDSC)
1512 3DSTATE_SBE
1513 -> iris_raster_state (point sprite texture coordinate origin)
1514 -> bunch of shader state...
1515 3DSTATE_SBE_SWIZ
1516 -> FS state
1517
1518 3DSTATE_DEPTH_BUFFER
1519 3DSTATE_HIER_DEPTH_BUFFER
1520 3DSTATE_STENCIL_BUFFER
1521 3DSTATE_CLEAR_PARAMS
1522 -> iris_framebuffer_state?
1523 #endif
1524 }
1525
1526 static void
1527 iris_bind_state(struct pipe_context *ctx, void *state)
1528 {
1529 }
1530
1531 void
1532 iris_destroy_state(struct iris_context *ice)
1533 {
1534 // XXX: unreference resources/surfaces.
1535 for (unsigned i = 0; i < ice->state.framebuffer.nr_cbufs; i++) {
1536 pipe_surface_reference(&ice->state.framebuffer.cbufs[i], NULL);
1537 }
1538 pipe_surface_reference(&ice->state.framebuffer.zsbuf, NULL);
1539 }
1540
1541 void
1542 iris_init_state_functions(struct pipe_context *ctx)
1543 {
1544 ctx->create_blend_state = iris_create_blend_state;
1545 ctx->create_depth_stencil_alpha_state = iris_create_zsa_state;
1546 ctx->create_rasterizer_state = iris_create_rasterizer_state;
1547 ctx->create_sampler_state = iris_create_sampler_state;
1548 ctx->create_sampler_view = iris_create_sampler_view;
1549 ctx->create_surface = iris_create_surface;
1550 ctx->create_vertex_elements_state = iris_create_vertex_elements;
1551 ctx->create_compute_state = iris_create_compute_state;
1552 ctx->bind_blend_state = iris_bind_blend_state;
1553 ctx->bind_depth_stencil_alpha_state = iris_bind_zsa_state;
1554 ctx->bind_sampler_states = iris_bind_sampler_states;
1555 ctx->bind_rasterizer_state = iris_bind_rasterizer_state;
1556 ctx->bind_vertex_elements_state = iris_bind_vertex_elements_state;
1557 ctx->bind_compute_state = iris_bind_state;
1558 ctx->delete_blend_state = iris_delete_state;
1559 ctx->delete_depth_stencil_alpha_state = iris_delete_state;
1560 ctx->delete_fs_state = iris_delete_state;
1561 ctx->delete_rasterizer_state = iris_delete_state;
1562 ctx->delete_sampler_state = iris_delete_state;
1563 ctx->delete_vertex_elements_state = iris_delete_state;
1564 ctx->delete_compute_state = iris_delete_state;
1565 ctx->delete_tcs_state = iris_delete_state;
1566 ctx->delete_tes_state = iris_delete_state;
1567 ctx->delete_gs_state = iris_delete_state;
1568 ctx->delete_vs_state = iris_delete_state;
1569 ctx->set_blend_color = iris_set_blend_color;
1570 ctx->set_clip_state = iris_set_clip_state;
1571 ctx->set_constant_buffer = iris_set_constant_buffer;
1572 ctx->set_sampler_views = iris_set_sampler_views;
1573 ctx->set_framebuffer_state = iris_set_framebuffer_state;
1574 ctx->set_polygon_stipple = iris_set_polygon_stipple;
1575 ctx->set_sample_mask = iris_set_sample_mask;
1576 ctx->set_scissor_states = iris_set_scissor_states;
1577 ctx->set_stencil_ref = iris_set_stencil_ref;
1578 ctx->set_vertex_buffers = iris_set_vertex_buffers;
1579 ctx->set_viewport_states = iris_set_viewport_states;
1580 ctx->sampler_view_destroy = iris_sampler_view_destroy;
1581 ctx->surface_destroy = iris_surface_destroy;
1582 ctx->draw_vbo = iris_draw_vbo;
1583 ctx->launch_grid = iris_launch_grid;
1584 ctx->create_stream_output_target = iris_create_stream_output_target;
1585 ctx->stream_output_target_destroy = iris_stream_output_target_destroy;
1586 ctx->set_stream_output_targets = iris_set_stream_output_targets;
1587 }