9291bf449a2c5a97a7d824f425a5aa4b5cfdf827
[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
275 static void
276 iris_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
277 {
278 }
279
280 static void
281 iris_launch_grid(struct pipe_context *ctx, const struct pipe_grid_info *info)
282 {
283 }
284
285 static void
286 iris_set_blend_color(struct pipe_context *ctx,
287 const struct pipe_blend_color *state)
288 {
289 struct iris_context *ice = (struct iris_context *) ctx;
290
291 memcpy(&ice->state.blend_color, state, sizeof(struct pipe_blend_color));
292 ice->state.dirty |= IRIS_DIRTY_COLOR_CALC_STATE;
293 }
294
295 struct iris_blend_state {
296 uint32_t ps_blend[GENX(3DSTATE_PS_BLEND_length)];
297 uint32_t blend_state[GENX(BLEND_STATE_length)];
298 uint32_t blend_entries[BRW_MAX_DRAW_BUFFERS *
299 GENX(BLEND_STATE_ENTRY_length)];
300 };
301
302 static void *
303 iris_create_blend_state(struct pipe_context *ctx,
304 const struct pipe_blend_state *state)
305 {
306 struct iris_blend_state *cso = malloc(sizeof(struct iris_blend_state));
307
308 iris_pack_state(GENX(BLEND_STATE), cso->blend_state, bs) {
309 bs.AlphaToCoverageEnable = state->alpha_to_coverage;
310 bs.IndependentAlphaBlendEnable = state->independent_blend_enable;
311 bs.AlphaToOneEnable = state->alpha_to_one;
312 bs.AlphaToCoverageDitherEnable = state->alpha_to_coverage;
313 bs.ColorDitherEnable = state->dither;
314 //bs.AlphaTestEnable = <comes from alpha state> :(
315 //bs.AlphaTestFunction = <comes from alpha state> :(
316 }
317
318 iris_pack_command(GENX(3DSTATE_PS_BLEND), cso->ps_blend, pb) {
319 //pb.HasWriteableRT = <comes from somewhere> :(
320 //pb.AlphaTestEnable = <comes from alpha state> :(
321 pb.AlphaToCoverageEnable = state->alpha_to_coverage;
322 pb.IndependentAlphaBlendEnable = state->independent_blend_enable;
323
324 pb.ColorBufferBlendEnable = state->rt[0].blend_enable;
325
326 pb.SourceBlendFactor = state->rt[0].rgb_src_factor;
327 pb.SourceAlphaBlendFactor = state->rt[0].alpha_func;
328 pb.DestinationBlendFactor = state->rt[0].rgb_dst_factor;
329 pb.DestinationAlphaBlendFactor = state->rt[0].alpha_dst_factor;
330 }
331
332 for (int i = 0; i < BRW_MAX_DRAW_BUFFERS; i++) {
333 iris_pack_state(GENX(BLEND_STATE_ENTRY), &cso->blend_entries[i], be) {
334 be.LogicOpEnable = state->logicop_enable;
335 be.LogicOpFunction = state->logicop_func;
336
337 be.PreBlendSourceOnlyClampEnable = false;
338 be.ColorClampRange = COLORCLAMP_RTFORMAT;
339 be.PreBlendColorClampEnable = true;
340 be.PostBlendColorClampEnable = true;
341
342 be.ColorBufferBlendEnable = state->rt[i].blend_enable;
343
344 be.ColorBlendFunction = state->rt[i].rgb_func;
345 be.AlphaBlendFunction = state->rt[i].alpha_func;
346 be.SourceBlendFactor = state->rt[i].rgb_src_factor;
347 be.SourceAlphaBlendFactor = state->rt[i].alpha_func;
348 be.DestinationBlendFactor = state->rt[i].rgb_dst_factor;
349 be.DestinationAlphaBlendFactor = state->rt[i].alpha_dst_factor;
350
351 be.WriteDisableRed = state->rt[i].colormask & PIPE_MASK_R;
352 be.WriteDisableGreen = state->rt[i].colormask & PIPE_MASK_G;
353 be.WriteDisableBlue = state->rt[i].colormask & PIPE_MASK_B;
354 be.WriteDisableAlpha = state->rt[i].colormask & PIPE_MASK_A;
355 }
356 }
357
358 return cso;
359 }
360
361 static void
362 iris_bind_blend_state(struct pipe_context *ctx, void *state)
363 {
364 struct iris_context *ice = (struct iris_context *) ctx;
365 ice->state.cso_blend = state;
366 ice->state.dirty |= IRIS_DIRTY_CC_VIEWPORT;
367 ice->state.dirty |= IRIS_DIRTY_WM_DEPTH_STENCIL;
368 }
369
370 struct iris_depth_stencil_alpha_state {
371 uint32_t wmds[GENX(3DSTATE_WM_DEPTH_STENCIL_length)];
372 uint32_t cc_vp[GENX(CC_VIEWPORT_length)];
373
374 struct pipe_alpha_state alpha; /* to BLEND_STATE, 3DSTATE_PS_BLEND */
375 };
376
377 static void *
378 iris_create_zsa_state(struct pipe_context *ctx,
379 const struct pipe_depth_stencil_alpha_state *state)
380 {
381 struct iris_depth_stencil_alpha_state *cso =
382 malloc(sizeof(struct iris_depth_stencil_alpha_state));
383
384 cso->alpha = state->alpha;
385
386 bool two_sided_stencil = state->stencil[1].enabled;
387
388 /* The state tracker needs to optimize away EQUAL writes for us. */
389 assert(!(state->depth.func == PIPE_FUNC_EQUAL && state->depth.writemask));
390
391 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL), cso->wmds, wmds) {
392 wmds.StencilFailOp = state->stencil[0].fail_op;
393 wmds.StencilPassDepthFailOp = state->stencil[0].zfail_op;
394 wmds.StencilPassDepthPassOp = state->stencil[0].zpass_op;
395 wmds.StencilTestFunction =
396 translate_compare_func(state->stencil[0].func);
397 wmds.BackfaceStencilFailOp = state->stencil[1].fail_op;
398 wmds.BackfaceStencilPassDepthFailOp = state->stencil[1].zfail_op;
399 wmds.BackfaceStencilPassDepthPassOp = state->stencil[1].zpass_op;
400 wmds.BackfaceStencilTestFunction =
401 translate_compare_func(state->stencil[1].func);
402 wmds.DepthTestFunction = translate_compare_func(state->depth.func);
403 wmds.DoubleSidedStencilEnable = two_sided_stencil;
404 wmds.StencilTestEnable = state->stencil[0].enabled;
405 wmds.StencilBufferWriteEnable =
406 state->stencil[0].writemask != 0 ||
407 (two_sided_stencil && state->stencil[1].writemask != 0);
408 wmds.DepthTestEnable = state->depth.enabled;
409 wmds.DepthBufferWriteEnable = state->depth.writemask;
410 wmds.StencilTestMask = state->stencil[0].valuemask;
411 wmds.StencilWriteMask = state->stencil[0].writemask;
412 wmds.BackfaceStencilTestMask = state->stencil[1].valuemask;
413 wmds.BackfaceStencilWriteMask = state->stencil[1].writemask;
414 /* wmds.[Backface]StencilReferenceValue are merged later */
415 }
416
417 iris_pack_state(GENX(CC_VIEWPORT), cso->cc_vp, ccvp) {
418 ccvp.MinimumDepth = state->depth.bounds_min;
419 ccvp.MaximumDepth = state->depth.bounds_max;
420 }
421
422 return cso;
423 }
424
425 static void
426 iris_bind_zsa_state(struct pipe_context *ctx, void *state)
427 {
428 struct iris_context *ice = (struct iris_context *) ctx;
429 struct iris_depth_stencil_alpha_state *old_cso = ice->state.cso_zsa;
430 struct iris_depth_stencil_alpha_state *new_cso = state;
431
432 if (new_cso) {
433 if (!old_cso || old_cso->alpha.ref_value != new_cso->alpha.ref_value) {
434 ice->state.dirty |= IRIS_DIRTY_COLOR_CALC_STATE;
435 }
436 }
437
438 ice->state.cso_zsa = new_cso;
439 ice->state.dirty |= IRIS_DIRTY_CC_VIEWPORT;
440 ice->state.dirty |= IRIS_DIRTY_WM_DEPTH_STENCIL;
441 }
442
443 struct iris_rasterizer_state {
444 uint32_t sf[GENX(3DSTATE_SF_length)];
445 uint32_t clip[GENX(3DSTATE_CLIP_length)];
446 uint32_t raster[GENX(3DSTATE_RASTER_length)];
447 uint32_t wm[GENX(3DSTATE_WM_length)];
448
449 bool flatshade; /* for shader state */
450 bool light_twoside; /* for shader state */
451 bool rasterizer_discard; /* for 3DSTATE_STREAMOUT */
452 bool half_pixel_center; /* for 3DSTATE_MULTISAMPLE */
453 enum pipe_sprite_coord_mode sprite_coord_mode; /* PIPE_SPRITE_* */
454
455 uint8_t line_stipple_factor;
456 uint16_t line_stipple_pattern;
457 };
458
459 static void *
460 iris_create_rasterizer_state(struct pipe_context *ctx,
461 const struct pipe_rasterizer_state *state)
462 {
463 struct iris_rasterizer_state *cso =
464 malloc(sizeof(struct iris_rasterizer_state));
465
466 #if 0
467 sprite_coord_mode -> SBE PointSpriteTextureCoordinateOrigin
468 sprite_coord_enable -> SBE PointSpriteTextureCoordinateEnable
469 point_quad_rasterization -> SBE?
470
471 not necessary?
472 {
473 poly_smooth
474 force_persample_interp - ?
475 bottom_edge_rule
476
477 offset_units_unscaled - cap not exposed
478 }
479
480 unsigned line_stipple_factor:8; /**< [1..256] actually */
481 unsigned line_stipple_pattern:16;
482 #endif
483
484 cso->flatshade = state->flatshade;
485 cso->light_twoside = state->light_twoside;
486 cso->rasterizer_discard = state->rasterizer_discard;
487 cso->line_stipple_factor = state->line_stipple_factor;
488 cso->line_stipple_pattern = state->line_stipple_pattern;
489 // for 3DSTATE_MULTISAMPLE, if we want it.
490 cso->half_pixel_center = state->half_pixel_center;
491
492 iris_pack_command(GENX(3DSTATE_SF), cso->sf, sf) {
493 sf.StatisticsEnable = true;
494 sf.ViewportTransformEnable = true;
495 sf.AALineDistanceMode = AALINEDISTANCE_TRUE;
496 sf.LineEndCapAntialiasingRegionWidth =
497 state->line_smooth ? _10pixels : _05pixels;
498 sf.LastPixelEnable = state->line_last_pixel;
499 sf.LineWidth = state->line_width;
500 sf.SmoothPointEnable = state->point_smooth;
501 sf.PointWidthSource = state->point_size_per_vertex ? Vertex : State;
502 sf.PointWidth = state->point_size;
503
504 if (state->flatshade_first) {
505 sf.TriangleStripListProvokingVertexSelect = 2;
506 sf.TriangleFanProvokingVertexSelect = 2;
507 sf.LineStripListProvokingVertexSelect = 1;
508 } else {
509 sf.TriangleFanProvokingVertexSelect = 1;
510 }
511 }
512
513 /* COMPLETE! */
514 iris_pack_command(GENX(3DSTATE_RASTER), cso->raster, rr) {
515 rr.FrontWinding = state->front_ccw ? CounterClockwise : Clockwise;
516 rr.CullMode = translate_cull_mode(state->cull_face);
517 rr.FrontFaceFillMode = translate_fill_mode(state->fill_front);
518 rr.BackFaceFillMode = translate_fill_mode(state->fill_back);
519 rr.DXMultisampleRasterizationEnable = state->multisample;
520 rr.GlobalDepthOffsetEnableSolid = state->offset_tri;
521 rr.GlobalDepthOffsetEnableWireframe = state->offset_line;
522 rr.GlobalDepthOffsetEnablePoint = state->offset_point;
523 rr.GlobalDepthOffsetConstant = state->offset_units;
524 rr.GlobalDepthOffsetScale = state->offset_scale;
525 rr.GlobalDepthOffsetClamp = state->offset_clamp;
526 rr.SmoothPointEnable = state->point_smooth;
527 rr.AntialiasingEnable = state->line_smooth;
528 rr.ScissorRectangleEnable = state->scissor;
529 rr.ViewportZNearClipTestEnable = state->depth_clip_near;
530 rr.ViewportZFarClipTestEnable = state->depth_clip_far;
531 //rr.ConservativeRasterizationEnable = not yet supported by Gallium...
532 }
533
534 iris_pack_command(GENX(3DSTATE_CLIP), cso->clip, cl) {
535 cl.StatisticsEnable = true;
536 cl.EarlyCullEnable = true;
537 cl.UserClipDistanceClipTestEnableBitmask = state->clip_plane_enable;
538 cl.ForceUserClipDistanceClipTestEnableBitmask = true;
539 cl.APIMode = state->clip_halfz ? APIMODE_D3D : APIMODE_OGL;
540 cl.GuardbandClipTestEnable = true;
541 cl.ClipMode = CLIPMODE_NORMAL;
542 cl.ClipEnable = true;
543 cl.ViewportXYClipTestEnable = state->point_tri_clip;
544 cl.MinimumPointWidth = 0.125;
545 cl.MaximumPointWidth = 255.875;
546 //.NonPerspectiveBarycentricEnable = <comes from FS prog> :(
547 //.ForceZeroRTAIndexEnable = <comes from FB layers being 0>
548
549 if (state->flatshade_first) {
550 cl.TriangleStripListProvokingVertexSelect = 2;
551 cl.TriangleFanProvokingVertexSelect = 2;
552 cl.LineStripListProvokingVertexSelect = 1;
553 } else {
554 cl.TriangleFanProvokingVertexSelect = 1;
555 }
556 }
557
558 iris_pack_command(GENX(3DSTATE_WM), cso->wm, wm) {
559 wm.LineAntialiasingRegionWidth = _10pixels;
560 wm.LineEndCapAntialiasingRegionWidth = _05pixels;
561 wm.PointRasterizationRule = RASTRULE_UPPER_RIGHT;
562 wm.StatisticsEnable = true;
563 wm.LineStippleEnable = state->line_stipple_enable;
564 wm.PolygonStippleEnable = state->poly_stipple_enable;
565 // wm.BarycentricInterpolationMode = <comes from FS program> :(
566 // wm.EarlyDepthStencilControl = <comes from FS program> :(
567 }
568
569 return cso;
570 }
571
572 static void
573 iris_bind_rasterizer_state(struct pipe_context *ctx, void *state)
574 {
575 struct iris_context *ice = (struct iris_context *) ctx;
576 struct iris_rasterizer_state *old_cso = ice->state.cso_rast;
577 struct iris_rasterizer_state *new_cso = state;
578
579 if (new_cso) {
580 /* Try to avoid re-emitting 3DSTATE_LINE_STIPPLE, it's non-pipelined */
581 if (!old_cso ||
582 old_cso->line_stipple_factor != new_cso->line_stipple_factor ||
583 old_cso->line_stipple_pattern != new_cso->line_stipple_pattern) {
584 ice->state.dirty |= IRIS_DIRTY_LINE_STIPPLE;
585 }
586
587 if (!old_cso ||
588 old_cso->half_pixel_center != new_cso->half_pixel_center) {
589 ice->state.dirty |= IRIS_DIRTY_MULTISAMPLE;
590 }
591 }
592
593 ice->state.cso_rast = new_cso;
594 ice->state.dirty |= IRIS_DIRTY_RASTER;
595 }
596
597 static uint32_t
598 translate_wrap(unsigned pipe_wrap)
599 {
600 static const unsigned map[] = {
601 [PIPE_TEX_WRAP_REPEAT] = TCM_WRAP,
602 [PIPE_TEX_WRAP_CLAMP] = TCM_HALF_BORDER,
603 [PIPE_TEX_WRAP_CLAMP_TO_EDGE] = TCM_CLAMP,
604 [PIPE_TEX_WRAP_CLAMP_TO_BORDER] = TCM_CLAMP_BORDER,
605 [PIPE_TEX_WRAP_MIRROR_REPEAT] = TCM_MIRROR,
606 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE] = TCM_MIRROR_ONCE,
607 [PIPE_TEX_WRAP_MIRROR_CLAMP] = -1, // XXX: ???
608 [PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER] = -1, // XXX: ???
609 };
610 return map[pipe_wrap];
611 }
612
613 /**
614 * Return true if the given wrap mode requires the border color to exist.
615 */
616 static bool
617 wrap_mode_needs_border_color(unsigned wrap_mode)
618 {
619 return wrap_mode == TCM_CLAMP_BORDER || wrap_mode == TCM_HALF_BORDER;
620 }
621
622 static unsigned
623 translate_mip_filter(enum pipe_tex_mipfilter pipe_mip)
624 {
625 static const unsigned map[] = {
626 [PIPE_TEX_MIPFILTER_NEAREST] = MIPFILTER_NEAREST,
627 [PIPE_TEX_MIPFILTER_LINEAR] = MIPFILTER_LINEAR,
628 [PIPE_TEX_MIPFILTER_NONE] = MIPFILTER_NONE,
629 };
630 return map[pipe_mip];
631 }
632
633 struct iris_sampler_state {
634 struct pipe_sampler_state base;
635
636 bool needs_border_color;
637
638 uint32_t sampler_state[GENX(SAMPLER_STATE_length)];
639 };
640
641 static void *
642 iris_create_sampler_state(struct pipe_context *pctx,
643 const struct pipe_sampler_state *state)
644 {
645 struct iris_sampler_state *cso = CALLOC_STRUCT(iris_sampler_state);
646
647 if (!cso)
648 return NULL;
649
650 STATIC_ASSERT(PIPE_TEX_FILTER_NEAREST == MAPFILTER_NEAREST);
651 STATIC_ASSERT(PIPE_TEX_FILTER_LINEAR == MAPFILTER_LINEAR);
652
653 unsigned wrap_s = translate_wrap(state->wrap_s);
654 unsigned wrap_t = translate_wrap(state->wrap_t);
655 unsigned wrap_r = translate_wrap(state->wrap_r);
656
657 cso->needs_border_color = wrap_mode_needs_border_color(wrap_s) ||
658 wrap_mode_needs_border_color(wrap_t) ||
659 wrap_mode_needs_border_color(wrap_r);
660
661 iris_pack_state(GENX(SAMPLER_STATE), cso->sampler_state, samp) {
662 samp.TCXAddressControlMode = wrap_s;
663 samp.TCYAddressControlMode = wrap_t;
664 samp.TCZAddressControlMode = wrap_r;
665 samp.CubeSurfaceControlMode = state->seamless_cube_map;
666 samp.NonnormalizedCoordinateEnable = !state->normalized_coords;
667 samp.MinModeFilter = state->min_img_filter;
668 samp.MagModeFilter = state->mag_img_filter;
669 samp.MipModeFilter = translate_mip_filter(state->min_mip_filter);
670 samp.MaximumAnisotropy = RATIO21;
671
672 if (state->max_anisotropy >= 2) {
673 if (state->min_img_filter == PIPE_TEX_FILTER_LINEAR) {
674 samp.MinModeFilter = MAPFILTER_ANISOTROPIC;
675 samp.AnisotropicAlgorithm = EWAApproximation;
676 }
677
678 if (state->mag_img_filter == PIPE_TEX_FILTER_LINEAR)
679 samp.MagModeFilter = MAPFILTER_ANISOTROPIC;
680
681 samp.MaximumAnisotropy =
682 MIN2((state->max_anisotropy - 2) / 2, RATIO161);
683 }
684
685 /* Set address rounding bits if not using nearest filtering. */
686 if (state->min_img_filter != PIPE_TEX_FILTER_NEAREST) {
687 samp.UAddressMinFilterRoundingEnable = true;
688 samp.VAddressMinFilterRoundingEnable = true;
689 samp.RAddressMinFilterRoundingEnable = true;
690 }
691
692 if (state->mag_img_filter != PIPE_TEX_FILTER_NEAREST) {
693 samp.UAddressMagFilterRoundingEnable = true;
694 samp.VAddressMagFilterRoundingEnable = true;
695 samp.RAddressMagFilterRoundingEnable = true;
696 }
697
698 if (state->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE)
699 samp.ShadowFunction = translate_shadow_func(state->compare_func);
700
701 const float hw_max_lod = GEN_GEN >= 7 ? 14 : 13;
702
703 samp.LODPreClampMode = CLAMP_MODE_OGL;
704 samp.MinLOD = CLAMP(state->min_lod, 0, hw_max_lod);
705 samp.MaxLOD = CLAMP(state->max_lod, 0, hw_max_lod);
706 samp.TextureLODBias = CLAMP(state->lod_bias, -16, 15);
707
708 //samp.BorderColorPointer = <<comes from elsewhere>>
709 }
710
711 return cso;
712 }
713
714 static void
715 iris_bind_sampler_states(struct pipe_context *ctx,
716 enum pipe_shader_type p_stage,
717 unsigned start, unsigned count,
718 void **states)
719 {
720 struct iris_context *ice = (struct iris_context *) ctx;
721 gl_shader_stage stage = stage_from_pipe(p_stage);
722
723 assert(start + count <= IRIS_MAX_TEXTURE_SAMPLERS);
724
725 for (int i = 0; i < count; i++) {
726 ice->state.samplers[stage][start + i] = states[i];
727 }
728
729 ice->state.dirty |= IRIS_DIRTY_SAMPLER_STATES_VS << stage;
730 }
731
732 struct iris_sampler_view {
733 struct pipe_sampler_view pipe;
734 struct isl_view view;
735 uint32_t surface_state[GENX(RENDER_SURFACE_STATE_length)];
736 };
737
738 /**
739 * Convert an swizzle enumeration (i.e. SWIZZLE_X) to one of the Gen7.5+
740 * "Shader Channel Select" enumerations (i.e. HSW_SCS_RED). The mappings are
741 *
742 * SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, SWIZZLE_ZERO, SWIZZLE_ONE
743 * 0 1 2 3 4 5
744 * 4 5 6 7 0 1
745 * SCS_RED, SCS_GREEN, SCS_BLUE, SCS_ALPHA, SCS_ZERO, SCS_ONE
746 *
747 * which is simply adding 4 then modding by 8 (or anding with 7).
748 *
749 * We then may need to apply workarounds for textureGather hardware bugs.
750 */
751 static enum isl_channel_select
752 pipe_swizzle_to_isl_channel(enum pipe_swizzle swizzle)
753 {
754 return (swizzle + 4) & 7;
755 }
756
757 static struct pipe_sampler_view *
758 iris_create_sampler_view(struct pipe_context *ctx,
759 struct pipe_resource *tex,
760 const struct pipe_sampler_view *tmpl)
761 {
762 struct iris_screen *screen = (struct iris_screen *)ctx->screen;
763 struct iris_resource *itex = (struct iris_resource *) tex;
764 struct iris_sampler_view *isv = calloc(1, sizeof(struct iris_sampler_view));
765
766 if (!isv)
767 return NULL;
768
769 /* initialize base object */
770 isv->pipe = *tmpl;
771 isv->pipe.context = ctx;
772 isv->pipe.texture = NULL;
773 pipe_reference_init(&isv->pipe.reference, 1);
774 pipe_resource_reference(&isv->pipe.texture, tex);
775
776 /* XXX: do we need brw_get_texture_swizzle hacks here? */
777
778 isv->view = (struct isl_view) {
779 .format = iris_isl_format_for_pipe_format(tmpl->format),
780 .base_level = tmpl->u.tex.first_level,
781 .levels = tmpl->u.tex.last_level - tmpl->u.tex.first_level + 1,
782 .base_array_layer = tmpl->u.tex.first_layer,
783 .array_len = tmpl->u.tex.last_layer - tmpl->u.tex.first_layer + 1,
784 .swizzle = (struct isl_swizzle) {
785 .r = pipe_swizzle_to_isl_channel(tmpl->swizzle_r),
786 .g = pipe_swizzle_to_isl_channel(tmpl->swizzle_g),
787 .b = pipe_swizzle_to_isl_channel(tmpl->swizzle_b),
788 .a = pipe_swizzle_to_isl_channel(tmpl->swizzle_a),
789 },
790 .usage = ISL_SURF_USAGE_TEXTURE_BIT,
791 };
792
793 isl_surf_fill_state(&screen->isl_dev, isv->surface_state,
794 .surf = &itex->surf, .view = &isv->view,
795 .mocs = MOCS_WB);
796 // .address = ...
797 // .aux_surf =
798 // .clear_color = clear_color,
799
800 return &isv->pipe;
801 }
802
803 struct iris_surface {
804 struct pipe_surface pipe;
805 struct isl_view view;
806 uint32_t surface_state[GENX(RENDER_SURFACE_STATE_length)];
807 };
808
809 static struct pipe_surface *
810 iris_create_surface(struct pipe_context *ctx,
811 struct pipe_resource *tex,
812 const struct pipe_surface *tmpl)
813 {
814 struct iris_screen *screen = (struct iris_screen *)ctx->screen;
815 struct iris_surface *surf = calloc(1, sizeof(struct iris_surface));
816 struct pipe_surface *psurf = &surf->pipe;
817 struct iris_resource *itex = (struct iris_resource *) tex;
818
819 if (!surf)
820 return NULL;
821
822 pipe_reference_init(&psurf->reference, 1);
823 pipe_resource_reference(&psurf->texture, tex);
824 psurf->context = ctx;
825 psurf->format = tmpl->format;
826 psurf->width = tex->width0;
827 psurf->height = tex->height0;
828 psurf->texture = tex;
829 psurf->u.tex.first_layer = tmpl->u.tex.first_layer;
830 psurf->u.tex.last_layer = tmpl->u.tex.last_layer;
831 psurf->u.tex.level = tmpl->u.tex.level;
832
833 surf->view = (struct isl_view) {
834 .format = iris_isl_format_for_pipe_format(tmpl->format),
835 .base_level = tmpl->u.tex.level,
836 .levels = 1,
837 .base_array_layer = tmpl->u.tex.first_layer,
838 .array_len = tmpl->u.tex.last_layer - tmpl->u.tex.first_layer + 1,
839 .swizzle = ISL_SWIZZLE_IDENTITY,
840 // XXX: DEPTH_BIt, STENCIL_BIT...CUBE_BIT? Other bits?!
841 .usage = ISL_SURF_USAGE_RENDER_TARGET_BIT,
842 };
843
844 isl_surf_fill_state(&screen->isl_dev, surf->surface_state,
845 .surf = &itex->surf, .view = &surf->view,
846 .mocs = MOCS_WB);
847 // .address = ...
848 // .aux_surf =
849 // .clear_color = clear_color,
850
851 return psurf;
852 }
853
854 static void
855 iris_set_sampler_views(struct pipe_context *ctx,
856 enum pipe_shader_type shader,
857 unsigned start, unsigned count,
858 struct pipe_sampler_view **views)
859 {
860 }
861
862 static void
863 iris_set_clip_state(struct pipe_context *ctx,
864 const struct pipe_clip_state *state)
865 {
866 }
867
868 static void
869 iris_set_polygon_stipple(struct pipe_context *ctx,
870 const struct pipe_poly_stipple *state)
871 {
872 struct iris_context *ice = (struct iris_context *) ctx;
873 memcpy(&ice->state.poly_stipple, state, sizeof(*state));
874 ice->state.dirty |= IRIS_DIRTY_POLYGON_STIPPLE;
875 }
876
877 static void
878 iris_set_sample_mask(struct pipe_context *ctx, unsigned sample_mask)
879 {
880 struct iris_context *ice = (struct iris_context *) ctx;
881
882 ice->state.sample_mask = sample_mask;
883 ice->state.dirty |= IRIS_DIRTY_SAMPLE_MASK;
884 }
885
886 static void
887 iris_set_scissor_states(struct pipe_context *ctx,
888 unsigned start_slot,
889 unsigned num_scissors,
890 const struct pipe_scissor_state *state)
891 {
892 struct iris_context *ice = (struct iris_context *) ctx;
893
894 // XXX: start_slot
895 ice->state.num_scissors = num_scissors;
896
897 for (unsigned i = start_slot; i < start_slot + num_scissors; i++) {
898 ice->state.scissors[i] = *state;
899 }
900
901 ice->state.dirty |= IRIS_DIRTY_SCISSOR_RECT;
902 }
903
904 static void
905 iris_set_stencil_ref(struct pipe_context *ctx,
906 const struct pipe_stencil_ref *state)
907 {
908 struct iris_context *ice = (struct iris_context *) ctx;
909 memcpy(&ice->state.stencil_ref, state, sizeof(*state));
910 ice->state.dirty |= IRIS_DIRTY_WM_DEPTH_STENCIL;
911 }
912
913
914 struct iris_viewport_state {
915 uint32_t sf_cl_vp[GENX(SF_CLIP_VIEWPORT_length)];
916 };
917
918 static float
919 extent_from_matrix(const struct pipe_viewport_state *state, int axis)
920 {
921 return fabsf(state->scale[axis]) * state->translate[axis];
922 }
923
924 #if 0
925 static void
926 calculate_guardband_size(uint32_t fb_width, uint32_t fb_height,
927 float m00, float m11, float m30, float m31,
928 float *xmin, float *xmax,
929 float *ymin, float *ymax)
930 {
931 /* According to the "Vertex X,Y Clamping and Quantization" section of the
932 * Strips and Fans documentation:
933 *
934 * "The vertex X and Y screen-space coordinates are also /clamped/ to the
935 * fixed-point "guardband" range supported by the rasterization hardware"
936 *
937 * and
938 *
939 * "In almost all circumstances, if an object’s vertices are actually
940 * modified by this clamping (i.e., had X or Y coordinates outside of
941 * the guardband extent the rendered object will not match the intended
942 * result. Therefore software should take steps to ensure that this does
943 * not happen - e.g., by clipping objects such that they do not exceed
944 * these limits after the Drawing Rectangle is applied."
945 *
946 * I believe the fundamental restriction is that the rasterizer (in
947 * the SF/WM stages) have a limit on the number of pixels that can be
948 * rasterized. We need to ensure any coordinates beyond the rasterizer
949 * limit are handled by the clipper. So effectively that limit becomes
950 * the clipper's guardband size.
951 *
952 * It goes on to say:
953 *
954 * "In addition, in order to be correctly rendered, objects must have a
955 * screenspace bounding box not exceeding 8K in the X or Y direction.
956 * This additional restriction must also be comprehended by software,
957 * i.e., enforced by use of clipping."
958 *
959 * This makes no sense. Gen7+ hardware supports 16K render targets,
960 * and you definitely need to be able to draw polygons that fill the
961 * surface. Our assumption is that the rasterizer was limited to 8K
962 * on Sandybridge, which only supports 8K surfaces, and it was actually
963 * increased to 16K on Ivybridge and later.
964 *
965 * So, limit the guardband to 16K on Gen7+ and 8K on Sandybridge.
966 */
967 const float gb_size = GEN_GEN >= 7 ? 16384.0f : 8192.0f;
968
969 if (m00 != 0 && m11 != 0) {
970 /* First, we compute the screen-space render area */
971 const float ss_ra_xmin = MIN3( 0, m30 + m00, m30 - m00);
972 const float ss_ra_xmax = MAX3( fb_width, m30 + m00, m30 - m00);
973 const float ss_ra_ymin = MIN3( 0, m31 + m11, m31 - m11);
974 const float ss_ra_ymax = MAX3(fb_height, m31 + m11, m31 - m11);
975
976 /* We want the guardband to be centered on that */
977 const float ss_gb_xmin = (ss_ra_xmin + ss_ra_xmax) / 2 - gb_size;
978 const float ss_gb_xmax = (ss_ra_xmin + ss_ra_xmax) / 2 + gb_size;
979 const float ss_gb_ymin = (ss_ra_ymin + ss_ra_ymax) / 2 - gb_size;
980 const float ss_gb_ymax = (ss_ra_ymin + ss_ra_ymax) / 2 + gb_size;
981
982 /* Now we need it in native device coordinates */
983 const float ndc_gb_xmin = (ss_gb_xmin - m30) / m00;
984 const float ndc_gb_xmax = (ss_gb_xmax - m30) / m00;
985 const float ndc_gb_ymin = (ss_gb_ymin - m31) / m11;
986 const float ndc_gb_ymax = (ss_gb_ymax - m31) / m11;
987
988 /* Thanks to Y-flipping and ORIGIN_UPPER_LEFT, the Y coordinates may be
989 * flipped upside-down. X should be fine though.
990 */
991 assert(ndc_gb_xmin <= ndc_gb_xmax);
992 *xmin = ndc_gb_xmin;
993 *xmax = ndc_gb_xmax;
994 *ymin = MIN2(ndc_gb_ymin, ndc_gb_ymax);
995 *ymax = MAX2(ndc_gb_ymin, ndc_gb_ymax);
996 } else {
997 /* The viewport scales to 0, so nothing will be rendered. */
998 *xmin = 0.0f;
999 *xmax = 0.0f;
1000 *ymin = 0.0f;
1001 *ymax = 0.0f;
1002 }
1003 }
1004 #endif
1005
1006 static void
1007 iris_set_viewport_states(struct pipe_context *ctx,
1008 unsigned start_slot,
1009 unsigned num_viewports,
1010 const struct pipe_viewport_state *state)
1011 {
1012 struct iris_context *ice = (struct iris_context *) ctx;
1013 struct iris_viewport_state *cso =
1014 malloc(sizeof(struct iris_viewport_state));
1015
1016 for (unsigned i = start_slot; i < start_slot + num_viewports; i++) {
1017 float x_extent = extent_from_matrix(&state[i], 0);
1018 float y_extent = extent_from_matrix(&state[i], 1);
1019
1020 iris_pack_state(GENX(SF_CLIP_VIEWPORT), cso->sf_cl_vp, vp) {
1021 vp.ViewportMatrixElementm00 = state[i].scale[0];
1022 vp.ViewportMatrixElementm11 = state[i].scale[1];
1023 vp.ViewportMatrixElementm22 = state[i].scale[2];
1024 vp.ViewportMatrixElementm30 = state[i].translate[0];
1025 vp.ViewportMatrixElementm31 = state[i].translate[1];
1026 vp.ViewportMatrixElementm32 = state[i].translate[2];
1027 /* XXX: in i965 this is computed based on the drawbuffer size,
1028 * but we don't have that here...
1029 */
1030 vp.XMinClipGuardband = -1.0;
1031 vp.XMaxClipGuardband = 1.0;
1032 vp.YMinClipGuardband = -1.0;
1033 vp.YMaxClipGuardband = 1.0;
1034 vp.XMinViewPort = -x_extent;
1035 vp.XMaxViewPort = x_extent;
1036 vp.YMinViewPort = -y_extent;
1037 vp.YMaxViewPort = y_extent;
1038 }
1039 }
1040
1041 ice->state.cso_vp = cso;
1042 // XXX: start_slot
1043 ice->state.num_viewports = num_viewports;
1044 ice->state.dirty |= IRIS_DIRTY_SF_CL_VIEWPORT;
1045 }
1046
1047 struct iris_depth_state
1048 {
1049 uint32_t depth_buffer[GENX(3DSTATE_DEPTH_BUFFER_length)];
1050 uint32_t hier_depth_buffer[GENX(3DSTATE_HIER_DEPTH_BUFFER_length)];
1051 uint32_t stencil_buffer[GENX(3DSTATE_STENCIL_BUFFER_length)];
1052 };
1053
1054 static void
1055 iris_set_framebuffer_state(struct pipe_context *ctx,
1056 const struct pipe_framebuffer_state *state)
1057 {
1058 struct iris_context *ice = (struct iris_context *) ctx;
1059 struct pipe_framebuffer_state *cso = &ice->state.framebuffer;
1060
1061 if (cso->samples != state->samples) {
1062 ice->state.dirty |= IRIS_DIRTY_MULTISAMPLE;
1063 }
1064
1065 cso->width = state->width;
1066 cso->height = state->height;
1067 cso->layers = state->layers;
1068 cso->samples = state->samples;
1069
1070 unsigned i;
1071 for (i = 0; i < state->nr_cbufs; i++)
1072 pipe_surface_reference(&cso->cbufs[i], state->cbufs[i]);
1073 for (; i < cso->nr_cbufs; i++)
1074 pipe_surface_reference(&cso->cbufs[i], NULL);
1075
1076 cso->nr_cbufs = state->nr_cbufs;
1077
1078 pipe_surface_reference(&cso->zsbuf, state->zsbuf);
1079
1080 struct isl_depth_stencil_hiz_emit_info info = {
1081 .mocs = MOCS_WB,
1082 };
1083
1084 // XXX: depth buffers
1085 }
1086
1087 static void
1088 iris_set_constant_buffer(struct pipe_context *ctx,
1089 enum pipe_shader_type shader, uint index,
1090 const struct pipe_constant_buffer *cb)
1091 {
1092 }
1093
1094
1095 static void
1096 iris_sampler_view_destroy(struct pipe_context *ctx,
1097 struct pipe_sampler_view *state)
1098 {
1099 pipe_resource_reference(&state->texture, NULL);
1100 free(state);
1101 }
1102
1103
1104 static void
1105 iris_surface_destroy(struct pipe_context *ctx, struct pipe_surface *surface)
1106 {
1107 pipe_resource_reference(&surface->texture, NULL);
1108 free(surface);
1109 }
1110
1111 static void
1112 iris_delete_state(struct pipe_context *ctx, void *state)
1113 {
1114 free(state);
1115 }
1116
1117 struct iris_vertex_buffer_state {
1118 uint32_t vertex_buffers[1 + 33 * GENX(VERTEX_BUFFER_STATE_length)];
1119 unsigned length; /* length of 3DSTATE_VERTEX_BUFFERS in DWords */
1120 };
1121
1122 static void
1123 iris_set_vertex_buffers(struct pipe_context *ctx,
1124 unsigned start_slot, unsigned count,
1125 const struct pipe_vertex_buffer *buffers)
1126 {
1127 struct iris_context *ice = (struct iris_context *) ctx;
1128 struct iris_vertex_buffer_state *cso =
1129 malloc(sizeof(struct iris_vertex_buffer_state));
1130
1131 cso->length = 4 * count - 1;
1132
1133 iris_pack_state(GENX(3DSTATE_VERTEX_BUFFERS), cso->vertex_buffers, vb) {
1134 vb.DWordLength = cso->length;
1135 }
1136
1137 /* If there are no buffers, do nothing. We can leave the stale
1138 * 3DSTATE_VERTEX_BUFFERS in place - as long as there are no vertex
1139 * elements that point to them, it should be fine.
1140 */
1141 if (!buffers)
1142 return;
1143
1144 uint32_t *vb_pack_dest = &cso->vertex_buffers[1];
1145
1146 for (unsigned i = 0; i < count; i++) {
1147 assert(!buffers[i].is_user_buffer);
1148
1149 iris_pack_state(GENX(VERTEX_BUFFER_STATE), vb_pack_dest, vb) {
1150 vb.VertexBufferIndex = start_slot + i;
1151 vb.MOCS = MOCS_WB;
1152 vb.AddressModifyEnable = true;
1153 vb.BufferPitch = buffers[i].stride;
1154 //vb.BufferStartingAddress = ro_bo(bo, buffers[i].buffer_offset);
1155 //vb.BufferSize = bo->size;
1156 }
1157
1158 vb_pack_dest += GENX(VERTEX_BUFFER_STATE_length);
1159 }
1160
1161 ice->state.dirty |= IRIS_DIRTY_VERTEX_BUFFERS;
1162 }
1163
1164 struct iris_vertex_element_state {
1165 uint32_t vertex_elements[1 + 33 * GENX(VERTEX_ELEMENT_STATE_length)];
1166 uint32_t vf_instancing[GENX(3DSTATE_VF_INSTANCING_length)][33];
1167 unsigned count;
1168 };
1169
1170 static void *
1171 iris_create_vertex_elements(struct pipe_context *ctx,
1172 unsigned count,
1173 const struct pipe_vertex_element *state)
1174 {
1175 struct iris_vertex_element_state *cso =
1176 malloc(sizeof(struct iris_vertex_element_state));
1177
1178 cso->count = count;
1179
1180 /* TODO:
1181 * - create edge flag one
1182 * - create SGV ones
1183 * - if those are necessary, use count + 1/2/3... OR in the length
1184 */
1185 iris_pack_state(GENX(3DSTATE_VERTEX_ELEMENTS), cso->vertex_elements, ve);
1186
1187 uint32_t *ve_pack_dest = &cso->vertex_elements[1];
1188
1189 for (int i = 0; i < count; i++) {
1190 iris_pack_state(GENX(VERTEX_ELEMENT_STATE), ve_pack_dest, ve) {
1191 ve.VertexBufferIndex = state[i].vertex_buffer_index;
1192 ve.Valid = true;
1193 ve.SourceElementOffset = state[i].src_offset;
1194 ve.SourceElementFormat =
1195 iris_isl_format_for_pipe_format(state[i].src_format);
1196 }
1197
1198 iris_pack_state(GENX(3DSTATE_VF_INSTANCING), cso->vf_instancing[i], vi) {
1199 vi.VertexElementIndex = i;
1200 vi.InstancingEnable = state[i].instance_divisor > 0;
1201 vi.InstanceDataStepRate = state[i].instance_divisor;
1202 }
1203
1204 ve_pack_dest += GENX(VERTEX_ELEMENT_STATE_length);
1205 }
1206
1207 return cso;
1208 }
1209
1210 static void
1211 iris_bind_vertex_elements_state(struct pipe_context *ctx, void *state)
1212 {
1213 struct iris_context *ice = (struct iris_context *) ctx;
1214
1215 ice->state.cso_vertex_elements = state;
1216 ice->state.dirty |= IRIS_DIRTY_VERTEX_ELEMENTS;
1217 }
1218
1219 static void *
1220 iris_create_compute_state(struct pipe_context *ctx,
1221 const struct pipe_compute_state *state)
1222 {
1223 return malloc(1);
1224 }
1225
1226 static struct pipe_stream_output_target *
1227 iris_create_stream_output_target(struct pipe_context *ctx,
1228 struct pipe_resource *res,
1229 unsigned buffer_offset,
1230 unsigned buffer_size)
1231 {
1232 struct pipe_stream_output_target *t =
1233 CALLOC_STRUCT(pipe_stream_output_target);
1234 if (!t)
1235 return NULL;
1236
1237 pipe_reference_init(&t->reference, 1);
1238 pipe_resource_reference(&t->buffer, res);
1239 t->buffer_offset = buffer_offset;
1240 t->buffer_size = buffer_size;
1241 return t;
1242 }
1243
1244 static void
1245 iris_stream_output_target_destroy(struct pipe_context *ctx,
1246 struct pipe_stream_output_target *t)
1247 {
1248 pipe_resource_reference(&t->buffer, NULL);
1249 free(t);
1250 }
1251
1252 static void
1253 iris_set_stream_output_targets(struct pipe_context *ctx,
1254 unsigned num_targets,
1255 struct pipe_stream_output_target **targets,
1256 const unsigned *offsets)
1257 {
1258 }
1259
1260 void
1261 iris_upload_render_state(struct iris_context *ice,
1262 struct iris_batch *batch,
1263 struct pipe_draw_info *draw)
1264 {
1265 const uint64_t dirty = ice->state.dirty;
1266
1267 if (dirty & IRIS_DIRTY_WM_DEPTH_STENCIL) {
1268 struct iris_depth_stencil_alpha_state *cso = ice->state.cso_zsa;
1269 struct pipe_stencil_ref *p_stencil_refs = &ice->state.stencil_ref;
1270
1271 uint32_t stencil_refs[GENX(3DSTATE_WM_DEPTH_STENCIL_length)];
1272 iris_pack_command(GENX(3DSTATE_WM_DEPTH_STENCIL), &stencil_refs, wmds) {
1273 wmds.StencilReferenceValue = p_stencil_refs->ref_value[0];
1274 wmds.BackfaceStencilReferenceValue = p_stencil_refs->ref_value[1];
1275 }
1276 iris_emit_merge(batch, cso->wmds, stencil_refs);
1277 }
1278
1279 if (dirty & IRIS_DIRTY_CC_VIEWPORT) {
1280 struct iris_depth_stencil_alpha_state *cso = ice->state.cso_zsa;
1281 iris_emit_cmd(batch, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC), ptr) {
1282 ptr.CCViewportPointer =
1283 iris_emit_state(batch, cso->cc_vp, sizeof(cso->cc_vp), 32);
1284 }
1285 }
1286
1287 if (dirty & IRIS_DIRTY_PS_BLEND) {
1288 struct iris_blend_state *cso = ice->state.cso_blend;
1289 iris_batch_emit(batch, cso->ps_blend, sizeof(cso->ps_blend));
1290 }
1291
1292 if (dirty & IRIS_DIRTY_BLEND_STATE) {
1293 //struct iris_blend_state *cso = ice->state.cso_blend;
1294 // XXX: 3DSTATE_BLEND_STATE_POINTERS - BLEND_STATE
1295 // -> from iris_blend_state (most) + iris_depth_stencil_alpha_state
1296 // (alpha test function/enable) + has writeable RT from ???????
1297 }
1298
1299 if (dirty & IRIS_DIRTY_SF_CL_VIEWPORT) {
1300 struct iris_viewport_state *cso = ice->state.cso_vp;
1301 iris_emit_cmd(batch, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP), ptr) {
1302 ptr.SFClipViewportPointer =
1303 iris_emit_state(batch, cso->sf_cl_vp, sizeof(cso->sf_cl_vp), 64);
1304 }
1305 }
1306
1307 if (dirty & IRIS_DIRTY_CLIP) {
1308 struct iris_rasterizer_state *cso = ice->state.cso_rast;
1309
1310 uint32_t dynamic_clip[GENX(3DSTATE_CLIP_length)];
1311 iris_pack_command(GENX(3DSTATE_CLIP), &dynamic_clip, cl) {
1312 //.NonPerspectiveBarycentricEnable = <comes from FS prog> :(
1313 //.ForceZeroRTAIndexEnable = <comes from FB layers being 0>
1314 // also userclip stuffs...
1315 }
1316 iris_emit_merge(batch, cso->clip, dynamic_clip);
1317 }
1318
1319 if (dirty & IRIS_DIRTY_RASTER) {
1320 struct iris_rasterizer_state *cso = ice->state.cso_rast;
1321 iris_batch_emit(batch, cso->raster, sizeof(cso->raster));
1322 iris_batch_emit(batch, cso->sf, sizeof(cso->sf));
1323 }
1324
1325 if (dirty & IRIS_DIRTY_SCISSOR) {
1326 uint32_t scissor_offset =
1327 iris_emit_state(batch, ice->state.scissors,
1328 sizeof(struct pipe_scissor_state) *
1329 ice->state.num_scissors, 32);
1330
1331 iris_emit_cmd(batch, GENX(3DSTATE_SCISSOR_STATE_POINTERS), ptr) {
1332 ptr.ScissorRectPointer = scissor_offset;
1333 }
1334 }
1335
1336 if (dirty & IRIS_DIRTY_POLYGON_STIPPLE) {
1337 iris_emit_cmd(batch, GENX(3DSTATE_POLY_STIPPLE_PATTERN), poly) {
1338 for (int i = 0; i < 32; i++) {
1339 poly.PatternRow[i] = ice->state.poly_stipple.stipple[i];
1340 }
1341 }
1342 }
1343
1344 if (dirty & IRIS_DIRTY_LINE_STIPPLE) {
1345 struct iris_rasterizer_state *cso = ice->state.cso_rast;
1346 iris_emit_cmd(batch, GENX(3DSTATE_LINE_STIPPLE), line) {
1347 line.LineStipplePattern = cso->line_stipple_pattern;
1348 line.LineStippleInverseRepeatCount = 1.0f / cso->line_stipple_factor;
1349 line.LineStippleRepeatCount = cso->line_stipple_factor;
1350 }
1351 }
1352
1353 if (dirty & IRIS_DIRTY_COLOR_CALC_STATE) {
1354 struct iris_depth_stencil_alpha_state *cso = ice->state.cso_zsa;
1355 uint32_t cc_offset;
1356 void *cc_map =
1357 iris_alloc_state(batch,
1358 sizeof(uint32_t) * GENX(COLOR_CALC_STATE_length),
1359 64, &cc_offset);
1360 iris_pack_state(GENX(COLOR_CALC_STATE), cc_map, cc) {
1361 cc.AlphaTestFormat = ALPHATEST_FLOAT32;
1362 cc.AlphaReferenceValueAsFLOAT32 = cso->alpha.ref_value;
1363 cc.BlendConstantColorRed = ice->state.blend_color.color[0];
1364 cc.BlendConstantColorGreen = ice->state.blend_color.color[1];
1365 cc.BlendConstantColorBlue = ice->state.blend_color.color[2];
1366 cc.BlendConstantColorAlpha = ice->state.blend_color.color[3];
1367 }
1368 iris_emit_cmd(batch, GENX(3DSTATE_CC_STATE_POINTERS), ptr) {
1369 ptr.ColorCalcStatePointer = cc_offset;
1370 ptr.ColorCalcStatePointerValid = true;
1371 }
1372 }
1373
1374 if (dirty & IRIS_DIRTY_VERTEX_BUFFERS) {
1375 struct iris_vertex_buffer_state *cso = ice->state.cso_vertex_buffers;
1376 // XXX: address!!!
1377 iris_batch_emit(batch, cso->vertex_buffers,
1378 sizeof(uint32_t) * cso->length);
1379 }
1380
1381 if (dirty & IRIS_DIRTY_VERTEX_ELEMENTS) {
1382 struct iris_vertex_element_state *cso = ice->state.cso_vertex_elements;
1383 iris_batch_emit(batch, cso->vertex_elements, sizeof(uint32_t) *
1384 (1 + cso->count * GENX(VERTEX_ELEMENT_STATE_length)));
1385 for (int i = 0; i < cso->count; i++) {
1386 iris_batch_emit(batch, cso->vf_instancing[i],
1387 sizeof(cso->vf_instancing[0]));
1388 }
1389 for (int i = 0; i < cso->count; i++) {
1390 /* TODO: vertexid, instanceid support */
1391 iris_emit_cmd(batch, GENX(3DSTATE_VF_SGVS), sgvs);
1392 }
1393 }
1394
1395 if (dirty & IRIS_DIRTY_MULTISAMPLE) {
1396 iris_emit_cmd(batch, GENX(3DSTATE_MULTISAMPLE), ms) {
1397 ms.PixelLocation =
1398 ice->state.cso_rast->half_pixel_center ? CENTER : UL_CORNER;
1399 ms.NumberofMultisamples = ffs(ice->state.framebuffer.samples) - 1;
1400 }
1401 }
1402
1403 if (dirty & IRIS_DIRTY_SAMPLE_MASK) {
1404 iris_emit_cmd(batch, GENX(3DSTATE_SAMPLE_MASK), ms) {
1405 ms.SampleMask = ice->state.sample_mask;
1406 }
1407 }
1408
1409 for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) {
1410 if (!(dirty & (IRIS_DIRTY_SAMPLER_STATES_VS << stage)))
1411 continue;
1412
1413 // XXX: get sampler count from shader; don't emit them all...
1414 const int count = IRIS_MAX_TEXTURE_SAMPLERS;
1415
1416 uint32_t offset;
1417 uint32_t *map = iris_alloc_state(batch,
1418 count * 4 * GENX(SAMPLER_STATE_length),
1419 32, &offset);
1420
1421 for (int i = 0; i < count; i++) {
1422 memcpy(map, ice->state.samplers[stage][i]->sampler_state,
1423 4 * GENX(SAMPLER_STATE_length));
1424 map += GENX(SAMPLER_STATE_length);
1425 }
1426
1427 iris_emit_cmd(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS), ptr) {
1428 ptr._3DCommandSubOpcode = 43 + stage;
1429 ptr.PointertoVSSamplerState = offset;
1430 }
1431 }
1432
1433 if (1) {
1434 iris_emit_cmd(batch, GENX(3DSTATE_VF_TOPOLOGY), topo) {
1435 topo.PrimitiveTopologyType =
1436 translate_prim_type(draw->mode, draw->vertices_per_patch);
1437 }
1438 }
1439
1440 if (1) {
1441 iris_emit_cmd(batch, GENX(3DSTATE_VF), vf) {
1442 vf.IndexedDrawCutIndexEnable = draw->primitive_restart;
1443 vf.CutIndex = draw->restart_index;
1444 }
1445 }
1446
1447 // draw->index_size > 0
1448 if (1) {
1449 struct iris_resource *res = (struct iris_resource *)draw->index.resource;
1450
1451 assert(!draw->has_user_indices);
1452
1453 iris_emit_cmd(batch, GENX(3DSTATE_INDEX_BUFFER), ib) {
1454 ib.IndexFormat = draw->index_size;
1455 ib.MOCS = MOCS_WB;
1456 ib.BufferSize = res->bo->size;
1457 // XXX: gah, addresses :( need two different combine address funcs
1458 // ib.BufferStartingAddress = res->bo;
1459 }
1460
1461 assert(!draw->indirect); // XXX: indirect support
1462
1463 iris_emit_cmd(batch, GENX(3DPRIMITIVE), prim) {
1464 prim.StartInstanceLocation = draw->start_instance;
1465 prim.InstanceCount = draw->instance_count;
1466
1467 // XXX: this is probably bonkers.
1468 prim.StartVertexLocation = draw->start;
1469
1470 if (draw->index_size) {
1471 prim.BaseVertexLocation += draw->index_bias;
1472 } else {
1473 prim.StartVertexLocation += draw->index_bias;
1474 }
1475
1476 //prim.BaseVertexLocation = ...;
1477 }
1478 }
1479 #if 0
1480 l3 configuration
1481
1482 3DSTATE_PUSH_CONSTANT_ALLOC_*
1483 3DSTATE_URB_*
1484 -> TODO
1485
1486 3DSTATE_CONSTANT_* - push constants
1487 -> TODO
1488
1489 Surfaces:
1490 - pull constants
1491 - ubos/ssbos/abos
1492 - images
1493 - textures
1494 - render targets - write and read
1495 3DSTATE_BINDING_TABLE_POINTERS_*
1496 -> TODO
1497
1498 3DSTATE_VS
1499 3DSTATE_HS
1500 3DSTATE_TE
1501 3DSTATE_DS
1502 3DSTATE_GS
1503 3DSTATE_PS_EXTRA
1504 3DSTATE_PS
1505 3DSTATE_STREAMOUT
1506 3DSTATE_SO_BUFFER
1507 3DSTATE_SO_DECL_LIST
1508
1509 3DSTATE_WM
1510 -> iris_raster_state + FS state (barycentric, EDSC)
1511 3DSTATE_SBE
1512 -> iris_raster_state (point sprite texture coordinate origin)
1513 -> bunch of shader state...
1514 3DSTATE_SBE_SWIZ
1515 -> FS state
1516
1517 3DSTATE_DEPTH_BUFFER
1518 3DSTATE_HIER_DEPTH_BUFFER
1519 3DSTATE_STENCIL_BUFFER
1520 3DSTATE_CLEAR_PARAMS
1521 -> iris_framebuffer_state?
1522 #endif
1523 }
1524
1525 static void
1526 iris_bind_state(struct pipe_context *ctx, void *state)
1527 {
1528 }
1529
1530 void
1531 iris_destroy_state(struct iris_context *ice)
1532 {
1533 // XXX: unreference resources/surfaces.
1534 for (unsigned i = 0; i < ice->state.framebuffer.nr_cbufs; i++) {
1535 pipe_surface_reference(&ice->state.framebuffer.cbufs[i], NULL);
1536 }
1537 pipe_surface_reference(&ice->state.framebuffer.zsbuf, NULL);
1538 }
1539
1540 void
1541 iris_init_state_functions(struct pipe_context *ctx)
1542 {
1543 ctx->create_blend_state = iris_create_blend_state;
1544 ctx->create_depth_stencil_alpha_state = iris_create_zsa_state;
1545 ctx->create_rasterizer_state = iris_create_rasterizer_state;
1546 ctx->create_sampler_state = iris_create_sampler_state;
1547 ctx->create_sampler_view = iris_create_sampler_view;
1548 ctx->create_surface = iris_create_surface;
1549 ctx->create_vertex_elements_state = iris_create_vertex_elements;
1550 ctx->create_compute_state = iris_create_compute_state;
1551 ctx->bind_blend_state = iris_bind_blend_state;
1552 ctx->bind_depth_stencil_alpha_state = iris_bind_zsa_state;
1553 ctx->bind_sampler_states = iris_bind_sampler_states;
1554 ctx->bind_fs_state = iris_bind_state;
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->bind_tcs_state = iris_bind_state;
1559 ctx->bind_tes_state = iris_bind_state;
1560 ctx->bind_gs_state = iris_bind_state;
1561 ctx->bind_vs_state = iris_bind_state;
1562 ctx->delete_blend_state = iris_delete_state;
1563 ctx->delete_depth_stencil_alpha_state = iris_delete_state;
1564 ctx->delete_fs_state = iris_delete_state;
1565 ctx->delete_rasterizer_state = iris_delete_state;
1566 ctx->delete_sampler_state = iris_delete_state;
1567 ctx->delete_vertex_elements_state = iris_delete_state;
1568 ctx->delete_compute_state = iris_delete_state;
1569 ctx->delete_tcs_state = iris_delete_state;
1570 ctx->delete_tes_state = iris_delete_state;
1571 ctx->delete_gs_state = iris_delete_state;
1572 ctx->delete_vs_state = iris_delete_state;
1573 ctx->set_blend_color = iris_set_blend_color;
1574 ctx->set_clip_state = iris_set_clip_state;
1575 ctx->set_constant_buffer = iris_set_constant_buffer;
1576 ctx->set_sampler_views = iris_set_sampler_views;
1577 ctx->set_framebuffer_state = iris_set_framebuffer_state;
1578 ctx->set_polygon_stipple = iris_set_polygon_stipple;
1579 ctx->set_sample_mask = iris_set_sample_mask;
1580 ctx->set_scissor_states = iris_set_scissor_states;
1581 ctx->set_stencil_ref = iris_set_stencil_ref;
1582 ctx->set_vertex_buffers = iris_set_vertex_buffers;
1583 ctx->set_viewport_states = iris_set_viewport_states;
1584 ctx->sampler_view_destroy = iris_sampler_view_destroy;
1585 ctx->surface_destroy = iris_surface_destroy;
1586 ctx->draw_vbo = iris_draw_vbo;
1587 ctx->launch_grid = iris_launch_grid;
1588 ctx->create_stream_output_target = iris_create_stream_output_target;
1589 ctx->stream_output_target_destroy = iris_stream_output_target_destroy;
1590 ctx->set_stream_output_targets = iris_set_stream_output_targets;
1591 }