blob: 6850081c97196829d4d9ed66ee6e5b30f484b71a [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
Chia-I Wu9f039862014-08-20 15:39:56 +080025#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080026#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080027#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080028#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080029#include "pipeline.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080030#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080031#include "state.h"
32#include "view.h"
33#include "cmd_priv.h"
34
Chia-I Wu59c097e2014-08-21 10:51:07 +080035static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080036 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080037 uint32_t vertex_count,
38 uint32_t vertex_start,
39 uint32_t instance_count,
40 uint32_t instance_start,
41 uint32_t vertex_base)
42{
43 const uint8_t cmd_len = 6;
44 uint32_t dw0;
45
46 CMD_ASSERT(cmd, 6, 6);
47
Chia-I Wu426072d2014-08-26 14:31:55 +080048 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080049 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080050 (cmd_len - 2);
51
52 if (indexed)
53 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
54
Chia-I Wue24c3292014-08-21 14:05:23 +080055 cmd_batch_reserve(cmd, cmd_len);
56 cmd_batch_write(cmd, dw0);
57 cmd_batch_write(cmd, vertex_count);
58 cmd_batch_write(cmd, vertex_start);
59 cmd_batch_write(cmd, instance_count);
60 cmd_batch_write(cmd, instance_start);
61 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080062}
63
64static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080065 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080066 uint32_t vertex_count,
67 uint32_t vertex_start,
68 uint32_t instance_count,
69 uint32_t instance_start,
70 uint32_t vertex_base)
71{
72 const uint8_t cmd_len = 7;
73 uint32_t dw0, dw1;
74
75 CMD_ASSERT(cmd, 7, 7.5);
76
Chia-I Wu426072d2014-08-26 14:31:55 +080077 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080078 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080079
80 if (indexed)
81 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
82
Chia-I Wue24c3292014-08-21 14:05:23 +080083 cmd_batch_reserve(cmd, cmd_len);
84 cmd_batch_write(cmd, dw0);
85 cmd_batch_write(cmd, dw1);
86 cmd_batch_write(cmd, vertex_count);
87 cmd_batch_write(cmd, vertex_start);
88 cmd_batch_write(cmd, instance_count);
89 cmd_batch_write(cmd, instance_start);
90 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080091}
92
Chia-I Wu270b1e82014-08-25 15:53:39 +080093static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
94 struct intel_bo *bo, uint32_t bo_offset)
95{
96 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +080097 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +080098 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +080099 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100
101 CMD_ASSERT(cmd, 6, 7.5);
102
103 assert(bo_offset % 8 == 0);
104
105 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
106 /*
107 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
108 *
109 * "1 of the following must also be set (when CS stall is set):
110 *
111 * * Depth Cache Flush Enable ([0] of DW1)
112 * * Stall at Pixel Scoreboard ([1] of DW1)
113 * * Depth Stall ([13] of DW1)
114 * * Post-Sync Operation ([13] of DW1)
115 * * Render Target Cache Flush Enable ([12] of DW1)
116 * * Notify Enable ([8] of DW1)"
117 *
118 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
119 *
120 * "One of the following must also be set (when CS stall is set):
121 *
122 * * Render Target Cache Flush Enable ([12] of DW1)
123 * * Depth Cache Flush Enable ([0] of DW1)
124 * * Stall at Pixel Scoreboard ([1] of DW1)
125 * * Depth Stall ([13] of DW1)
126 * * Post-Sync Operation ([13] of DW1)"
127 */
128 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
129 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
130 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
131 GEN6_PIPE_CONTROL_DEPTH_STALL;
132
133 /* post-sync op */
134 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
135 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
136 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
137
138 if (cmd_gen(cmd) == INTEL_GEN(6))
139 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
140
141 assert(dw1 & bit_test);
142 }
143
144 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
145 /*
146 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
147 *
148 * "Following bits must be clear (when Depth Stall is set):
149 *
150 * * Render Target Cache Flush Enable ([12] of DW1)
151 * * Depth Cache Flush Enable ([0] of DW1)"
152 */
153 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
154 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
155 }
156
157 /*
158 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
159 *
160 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
161 * and PIPE_CONTROL are not supported."
162 *
163 * The kernel will add the mapping automatically (when write domain is
164 * INTEL_DOMAIN_INSTRUCTION).
165 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800166 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800167 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800168 reloc_flags |= INTEL_RELOC_GGTT;
169 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800170
171 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) bo);
172 cmd_batch_write(cmd, dw0);
173 cmd_batch_write(cmd, dw1);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800174 if (bo)
175 cmd_batch_reloc(cmd, bo_offset, bo, reloc_flags);
176 else
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 cmd_batch_write(cmd, 0);
178 cmd_batch_write(cmd, 0);
179 cmd_batch_write(cmd, 0);
180}
181
Chia-I Wu254db422014-08-21 11:54:29 +0800182static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
183{
184 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
185 bool supported;
186
187 CMD_ASSERT(cmd, 6, 7.5);
188
189 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
190 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
191
192 switch (p->prim_type) {
193 case GEN6_3DPRIM_POINTLIST:
194 case GEN6_3DPRIM_LINELIST:
195 case GEN6_3DPRIM_LINESTRIP:
196 case GEN6_3DPRIM_TRILIST:
197 case GEN6_3DPRIM_TRISTRIP:
198 supported = true;
199 break;
200 default:
201 supported = false;
202 break;
203 }
204
205 if (!supported)
206 return false;
207
208 switch (cmd->bind.index.type) {
209 case XGL_INDEX_8:
210 supported = (p->primitive_restart_index != 0xffu);
211 break;
212 case XGL_INDEX_16:
213 supported = (p->primitive_restart_index != 0xffffu);
214 break;
215 case XGL_INDEX_32:
216 supported = (p->primitive_restart_index != 0xffffffffu);
217 break;
218 default:
219 supported = false;
220 break;
221 }
222
223 return supported;
224}
225
Chia-I Wu59c097e2014-08-21 10:51:07 +0800226static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800227 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800228 XGL_GPU_SIZE offset,
229 XGL_INDEX_TYPE type,
230 bool enable_cut_index)
231{
232 const uint8_t cmd_len = 3;
233 uint32_t dw0, end_offset;
234 unsigned offset_align;
235
236 CMD_ASSERT(cmd, 6, 7.5);
237
Chia-I Wu426072d2014-08-26 14:31:55 +0800238 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239
240 /* the bit is moved to 3DSTATE_VF */
241 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
242 assert(!enable_cut_index);
243 if (enable_cut_index)
244 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
245
246 switch (type) {
247 case XGL_INDEX_8:
248 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
249 offset_align = 1;
250 break;
251 case XGL_INDEX_16:
252 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
253 offset_align = 2;
254 break;
255 case XGL_INDEX_32:
256 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
257 offset_align = 4;
258 break;
259 default:
260 cmd->result = XGL_ERROR_INVALID_VALUE;
261 return;
262 break;
263 }
264
265 if (offset % offset_align) {
266 cmd->result = XGL_ERROR_INVALID_VALUE;
267 return;
268 }
269
270 /* aligned and inclusive */
271 end_offset = mem->size - (mem->size % offset_align) - 1;
272
Chia-I Wu2de65d02014-08-25 10:02:53 +0800273 cmd_batch_reserve_reloc(cmd, cmd_len, 2);
Chia-I Wue24c3292014-08-21 14:05:23 +0800274 cmd_batch_write(cmd, dw0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800275 cmd_batch_reloc(cmd, offset, mem->bo, 0);
276 cmd_batch_reloc(cmd, end_offset, mem->bo, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800277}
278
Chia-I Wu62a7f252014-08-29 11:31:16 +0800279static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
280 bool enable_cut_index,
281 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800282{
283 const uint8_t cmd_len = 2;
284 uint32_t dw0;
285
286 CMD_ASSERT(cmd, 7.5, 7.5);
287
Chia-I Wu426072d2014-08-26 14:31:55 +0800288 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800289 if (enable_cut_index)
290 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
291
Chia-I Wue24c3292014-08-21 14:05:23 +0800292 cmd_batch_reserve(cmd, cmd_len);
293 cmd_batch_write(cmd, dw0);
294 cmd_batch_write(cmd, cut_index);
Chia-I Wu254db422014-08-21 11:54:29 +0800295}
296
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800297static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
298{
299 const uint8_t cmd_len = 7;
300 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
301
302 CMD_ASSERT(cmd, 6, 6);
303
304 assert(cmd->bind.gs.shader == NULL);
305
306 cmd_batch_reserve(cmd, cmd_len);
307 cmd_batch_write(cmd, dw0);
308 cmd_batch_write(cmd, 0);
309 cmd_batch_write(cmd, 0);
310 cmd_batch_write(cmd, 0);
311 cmd_batch_write(cmd, 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT);
312 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
313 cmd_batch_write(cmd, 0);
314}
315
Chia-I Wu62a7f252014-08-29 11:31:16 +0800316static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
317{
318 const uint8_t cmd_len = 7;
319 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
320
321 CMD_ASSERT(cmd, 7, 7.5);
322
323 assert(cmd->bind.gs.shader == NULL);
324
325 cmd_batch_reserve(cmd, cmd_len);
326 cmd_batch_write(cmd, dw0);
327 cmd_batch_write(cmd, 0);
328 cmd_batch_write(cmd, 0);
329 cmd_batch_write(cmd, 0);
330 cmd_batch_write(cmd, 0);
331 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
332 cmd_batch_write(cmd, 0);
333}
334
Chia-I Wud88e02d2014-08-25 10:56:13 +0800335static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
336 XGL_UINT width, XGL_UINT height)
337{
338 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800339 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800340 (cmd_len - 2);
341
342 CMD_ASSERT(cmd, 6, 7.5);
343
344 cmd_batch_reserve(cmd, cmd_len);
345 cmd_batch_write(cmd, dw0);
346 if (width && height) {
347 cmd_batch_write(cmd, 0);
348 cmd_batch_write(cmd, (height - 1) << 16 |
349 (width - 1));
350 } else {
351 cmd_batch_write(cmd, 1);
352 cmd_batch_write(cmd, 0);
353 }
354 cmd_batch_write(cmd, 0);
355}
356
Chia-I Wu8016a172014-08-29 18:31:32 +0800357static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
358 uint32_t body[6])
359{
360 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
361 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
362 const struct intel_raster_state *raster = cmd->bind.state.raster;
363 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
364 uint32_t dw1, dw2, dw3;
365 int point_width;
366
367 CMD_ASSERT(cmd, 6, 7.5);
368
369 dw1 = GEN7_SF_DW1_STATISTICS |
370 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
371 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
372 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
373 GEN7_SF_DW1_VIEWPORT_ENABLE |
374 raster->cmd_sf_fill;
375
376 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
377 int format;
378
379 switch (pipeline->db_format.channelFormat) {
380 case XGL_CH_FMT_R16:
381 format = GEN6_ZFORMAT_D16_UNORM;
382 break;
383 case XGL_CH_FMT_R32:
384 case XGL_CH_FMT_R32G8:
385 format = GEN6_ZFORMAT_D32_FLOAT;
386 break;
387 default:
388 assert(!"unknown depth format");
389 format = 0;
390 break;
391 }
392
393 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
394 }
395
396 dw2 = raster->cmd_sf_cull;
397
398 if (msaa->sample_count > 1) {
399 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
400 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
401 } else {
402 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
403 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
404 }
405
406 if (viewport->scissor_enable)
407 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
408
409 /* in U8.3 */
410 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
411 point_width = U_CLAMP(point_width, 1, 2047);
412
413 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
414 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
415 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
416 GEN7_SF_DW3_SUBPIXEL_8BITS |
417 GEN7_SF_DW3_USE_POINT_WIDTH |
418 point_width;
419
420 body[0] = dw1;
421 body[1] = dw2;
422 body[2] = dw3;
423 body[3] = raster->cmd_depth_offset_const;
424 body[4] = raster->cmd_depth_offset_scale;
425 body[5] = raster->cmd_depth_offset_clamp;
426}
427
428static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
429 uint32_t body[13])
430{
431 const struct intel_shader *vs =
432 intel_shader(cmd->bind.pipeline.graphics->vs.shader);
433 const struct intel_shader *fs =
434 intel_shader(cmd->bind.pipeline.graphics->fs.shader);
435 XGL_UINT attr_skip, attr_count;
436 XGL_UINT vue_offset, vue_len;
437 XGL_UINT i;
438 uint32_t dw1;
439
440 CMD_ASSERT(cmd, 6, 7.5);
441
442 /* VS outputs VUE header and position additionally */
443 assert(vs->out_count >= 2);
444 attr_skip = 2;
445 attr_count = vs->out_count - attr_skip;
446 assert(fs->in_count == attr_count);
447 assert(fs->in_count <= 32);
448
449 vue_offset = attr_skip / 2;
450 vue_len = (attr_count + 1) / 2;
451 if (!vue_len)
452 vue_len = 1;
453
454 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
455 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
456 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
457
458 body[0] = dw1;
459
460 for (i = 0; i < 8; i++) {
461 uint16_t hi, lo;
462
463 /* no attr swizzles */
464 if (i * 2 + 1 < fs->in_count) {
465 hi = i * 2 + 1;
466 lo = i * 2;
467 } else if (i * 2 < fs->in_count) {
468 hi = 0;
469 lo = i * 2;
470 } else {
471 hi = 0;
472 lo = 0;
473 }
474
475 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
476 }
477
478 body[9] = 0; /* point sprite enables */
479 body[10] = 0; /* constant interpolation enables */
480 body[11] = 0; /* WrapShortest enables */
481 body[12] = 0;
482}
483
484static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
485{
486 const uint8_t cmd_len = 20;
487 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
488 (cmd_len - 2);
489 uint32_t sf[6];
490 uint32_t sbe[13];
491
492 CMD_ASSERT(cmd, 6, 6);
493
494 gen7_fill_3DSTATE_SF_body(cmd, sf);
495 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
496
497 cmd_batch_reserve(cmd, cmd_len);
498 cmd_batch_write(cmd, dw0);
499 cmd_batch_write(cmd, sbe[0]);
500 cmd_batch_write_n(cmd, sf, 6);
501 cmd_batch_write_n(cmd, &sbe[1], 12);
502}
503
504static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
505{
506 const uint8_t cmd_len = 7;
507 uint32_t dw[7];
508
509 CMD_ASSERT(cmd, 7, 7.5);
510
511 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
512 (cmd_len - 2);
513 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
514
515 cmd_batch_reserve(cmd, cmd_len);
516 cmd_batch_write_n(cmd, dw, cmd_len);
517}
518
519static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
520{
521 const uint8_t cmd_len = 14;
522 uint32_t dw[14];
523
524 CMD_ASSERT(cmd, 7, 7.5);
525
526 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
527 (cmd_len - 2);
528 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
529
530 cmd_batch_reserve(cmd, cmd_len);
531 cmd_batch_write_n(cmd, dw, cmd_len);
532}
533
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800534static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
535{
536 const uint8_t cmd_len = 4;
537 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
538 (cmd_len - 2);
539 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
540 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
541 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
542 const struct intel_raster_state *raster = cmd->bind.state.raster;
543 uint32_t dw1, dw2, dw3;
544
545 CMD_ASSERT(cmd, 6, 7.5);
546
547 dw1 = GEN6_CLIP_DW1_STATISTICS;
548 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
549 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
550 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
551 raster->cmd_clip_cull;
552 }
553
554 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
555 GEN6_CLIP_DW2_XY_TEST_ENABLE |
556 GEN6_CLIP_DW2_APIMODE_OGL |
557 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
558 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
559 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
560
561 if (pipeline->rasterizerDiscardEnable)
562 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
563 else
564 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
565
566 if (pipeline->depthClipEnable)
567 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
568
569 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
570 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
571 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
572 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
573
574 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
575 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
576 (viewport->viewport_count - 1);
577
578 cmd_batch_reserve(cmd, cmd_len);
579 cmd_batch_write(cmd, dw0);
580 cmd_batch_write(cmd, dw1);
581 cmd_batch_write(cmd, dw2);
582 cmd_batch_write(cmd, dw3);
583}
584
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800585static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
586{
587 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
588 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
589 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
590 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
591 const uint8_t cmd_len = 9;
592 uint32_t dw0, dw2, dw4, dw5, dw6;
593
594 CMD_ASSERT(cmd, 6, 6);
595
596 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
597
598 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
599 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
600
601 dw4 = GEN6_WM_DW4_STATISTICS |
602 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
603 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
604 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
605
606 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
607 GEN6_WM_DW5_PS_ENABLE |
608 GEN6_WM_DW5_8_PIXEL_DISPATCH;
609
610 if (fs->uses & INTEL_SHADER_USE_KILL ||
611 pipeline->cb_state.alphaToCoverageEnable)
612 dw5 |= GEN6_WM_DW5_PS_KILL;
613
614 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
615 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
616 if (fs->uses & INTEL_SHADER_USE_DEPTH)
617 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
618 if (fs->uses & INTEL_SHADER_USE_W)
619 dw5 |= GEN6_WM_DW5_PS_USE_W;
620
621 if (pipeline->cb_state.dualSourceBlendEnable)
622 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
623
624 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
625 GEN6_WM_DW6_POSOFFSET_NONE |
626 GEN6_WM_DW6_ZW_INTERP_PIXEL |
627 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
628 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
629
630 if (msaa->sample_count > 1) {
631 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
632 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
633 } else {
634 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
635 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
636 }
637
638 cmd_batch_reserve(cmd, cmd_len);
639 cmd_batch_write(cmd, dw0);
640 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
641 cmd_batch_write(cmd, dw2);
642 cmd_batch_write(cmd, 0); /* scratch */
643 cmd_batch_write(cmd, dw4);
644 cmd_batch_write(cmd, dw5);
645 cmd_batch_write(cmd, dw6);
646 cmd_batch_write(cmd, 0); /* kernel 1 */
647 cmd_batch_write(cmd, 0); /* kernel 2 */
648}
649
650static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
651{
652 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
653 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
654 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
655 const uint8_t cmd_len = 3;
656 uint32_t dw0, dw1, dw2;
657
658 CMD_ASSERT(cmd, 7, 7.5);
659
660 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
661
662 dw1 = GEN7_WM_DW1_STATISTICS |
663 GEN7_WM_DW1_PS_ENABLE |
664 GEN7_WM_DW1_ZW_INTERP_PIXEL |
665 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
666 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
667
668 if (fs->uses & INTEL_SHADER_USE_KILL ||
669 pipeline->cb_state.alphaToCoverageEnable)
670 dw1 |= GEN7_WM_DW1_PS_KILL;
671
672 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
673 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
674 if (fs->uses & INTEL_SHADER_USE_DEPTH)
675 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
676 if (fs->uses & INTEL_SHADER_USE_W)
677 dw1 |= GEN7_WM_DW1_PS_USE_W;
678
679 dw2 = 0;
680
681 if (msaa->sample_count > 1) {
682 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
683 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
684 } else {
685 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
686 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
687 }
688
689 cmd_batch_reserve(cmd, cmd_len);
690 cmd_batch_write(cmd, dw0);
691 cmd_batch_write(cmd, dw1);
692 cmd_batch_write(cmd, dw2);
693}
694
695static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
696{
697 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
698 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
699 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
700 const uint8_t cmd_len = 8;
701 uint32_t dw0, dw2, dw4, dw5;
702
703 CMD_ASSERT(cmd, 7, 7.5);
704
705 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
706
707 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
708 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
709
710 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
711 GEN7_PS_DW4_8_PIXEL_DISPATCH;
712
713 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
714 const int max_threads =
715 (cmd->dev->gpu->gt == 3) ? 408 :
716 (cmd->dev->gpu->gt == 2) ? 204 : 102;
717 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
718 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
719 } else {
720 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
721 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
722 }
723
724 if (pipeline->fs.linkConstBufferCount)
725 dw4 |= GEN7_PS_DW4_PUSH_CONSTANT_ENABLE;
726
727 if (fs->in_count)
728 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
729
730 if (pipeline->cb_state.dualSourceBlendEnable)
731 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
732
733 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
734 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
735 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
736
737 cmd_batch_reserve(cmd, cmd_len);
738 cmd_batch_write(cmd, dw0);
739 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
740 cmd_batch_write(cmd, dw2);
741 cmd_batch_write(cmd, 0); /* scratch */
742 cmd_batch_write(cmd, dw4);
743 cmd_batch_write(cmd, dw5);
744 cmd_batch_write(cmd, 0); /* kernel 1 */
745 cmd_batch_write(cmd, 0); /* kernel 2 */
746}
747
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800748static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
749 const struct intel_ds_view *view)
750{
751 const uint8_t cmd_len = 7;
752 uint32_t dw0;
753
754 CMD_ASSERT(cmd, 6, 7.5);
755
756 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800757 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
758 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800759 dw0 |= (cmd_len - 2);
760
Chia-I Wu2de65d02014-08-25 10:02:53 +0800761 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800762 cmd_batch_write(cmd, dw0);
763 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600764 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800765 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800766 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600767 } else {
768 cmd_batch_write(cmd, 0);
769 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800770 cmd_batch_write(cmd, view->cmd[2]);
771 cmd_batch_write(cmd, view->cmd[3]);
772 cmd_batch_write(cmd, view->cmd[4]);
773 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800774}
775
776static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
777 const struct intel_ds_view *view)
778{
779 const uint8_t cmd_len = 3;
780 uint32_t dw0;
781
782 CMD_ASSERT(cmd, 6, 7.5);
783
784 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800785 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
786 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800787 dw0 |= (cmd_len - 2);
788
Chia-I Wu2de65d02014-08-25 10:02:53 +0800789 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800790 cmd_batch_write(cmd, dw0);
791 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600792 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800793 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800794 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600795 } else {
796 cmd_batch_write(cmd, 0);
797 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800798}
799
800static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
801 const struct intel_ds_view *view)
802{
803 const uint8_t cmd_len = 3;
804 uint32_t dw0;
805
806 CMD_ASSERT(cmd, 6, 7.5);
807
808 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800809 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
810 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800811 dw0 |= (cmd_len - 2);
812
Chia-I Wu2de65d02014-08-25 10:02:53 +0800813 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800814 cmd_batch_write(cmd, dw0);
815 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600816 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800817 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800818 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600819 } else {
820 cmd_batch_write(cmd, 0);
821 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800822}
823
Chia-I Wuf8231032014-08-25 10:44:45 +0800824static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
825 uint32_t clear_val)
826{
827 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800828 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800829 GEN6_CLEAR_PARAMS_DW0_VALID |
830 (cmd_len - 2);
831
832 CMD_ASSERT(cmd, 6, 6);
833
834 cmd_batch_reserve(cmd, cmd_len);
835 cmd_batch_write(cmd, dw0);
836 cmd_batch_write(cmd, clear_val);
837}
838
839static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
840 uint32_t clear_val)
841{
842 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800843 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800844 (cmd_len - 2);
845
846 CMD_ASSERT(cmd, 7, 7.5);
847
848 cmd_batch_reserve(cmd, cmd_len);
849 cmd_batch_write(cmd, dw0);
850 cmd_batch_write(cmd, clear_val);
851 cmd_batch_write(cmd, 1);
852}
853
Chia-I Wu302742d2014-08-22 10:28:29 +0800854static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
855 XGL_UINT blend_pos,
856 XGL_UINT ds_pos,
857 XGL_UINT cc_pos)
858{
859 const uint8_t cmd_len = 4;
860 uint32_t dw0;
861
862 CMD_ASSERT(cmd, 6, 6);
863
Chia-I Wu426072d2014-08-26 14:31:55 +0800864 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800865 (cmd_len - 2);
866
867 cmd_batch_reserve(cmd, cmd_len);
868 cmd_batch_write(cmd, dw0);
869 cmd_batch_write(cmd, (blend_pos << 2) | 1);
870 cmd_batch_write(cmd, (ds_pos << 2) | 1);
871 cmd_batch_write(cmd, (cc_pos << 2) | 1);
872}
873
Chia-I Wu1744cca2014-08-22 11:10:17 +0800874static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
875 XGL_UINT clip_pos,
876 XGL_UINT sf_pos,
877 XGL_UINT cc_pos)
878{
879 const uint8_t cmd_len = 4;
880 uint32_t dw0;
881
882 CMD_ASSERT(cmd, 6, 6);
883
Chia-I Wu426072d2014-08-26 14:31:55 +0800884 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800885 GEN6_PTR_VP_DW0_CLIP_CHANGED |
886 GEN6_PTR_VP_DW0_SF_CHANGED |
887 GEN6_PTR_VP_DW0_CC_CHANGED |
888 (cmd_len - 2);
889
890 cmd_batch_reserve(cmd, cmd_len);
891 cmd_batch_write(cmd, dw0);
892 cmd_batch_write(cmd, clip_pos << 2);
893 cmd_batch_write(cmd, sf_pos << 2);
894 cmd_batch_write(cmd, cc_pos << 2);
895}
896
897static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
898 XGL_UINT scissor_pos)
899{
900 const uint8_t cmd_len = 2;
901 uint32_t dw0;
902
903 CMD_ASSERT(cmd, 6, 6);
904
Chia-I Wu426072d2014-08-26 14:31:55 +0800905 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800906 (cmd_len - 2);
907
908 cmd_batch_reserve(cmd, cmd_len);
909 cmd_batch_write(cmd, dw0);
910 cmd_batch_write(cmd, scissor_pos << 2);
911}
912
Chia-I Wu42a56202014-08-23 16:47:48 +0800913static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
914 XGL_UINT vs_pos,
915 XGL_UINT gs_pos,
916 XGL_UINT ps_pos)
917{
918 const uint8_t cmd_len = 4;
919 uint32_t dw0;
920
921 CMD_ASSERT(cmd, 6, 6);
922
Chia-I Wu426072d2014-08-26 14:31:55 +0800923 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800924 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
925 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
926 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
927 (cmd_len - 2);
928
929 cmd_batch_reserve(cmd, cmd_len);
930 cmd_batch_write(cmd, dw0);
931 cmd_batch_write(cmd, vs_pos << 2);
932 cmd_batch_write(cmd, gs_pos << 2);
933 cmd_batch_write(cmd, ps_pos << 2);
934}
935
Chia-I Wu257e75e2014-08-29 14:06:35 +0800936static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
937 XGL_UINT vs_pos,
938 XGL_UINT gs_pos,
939 XGL_UINT ps_pos)
940{
941 const uint8_t cmd_len = 4;
942 uint32_t dw0;
943
944 CMD_ASSERT(cmd, 6, 6);
945
946 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
947 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
948 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
949 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
950 (cmd_len - 2);
951
952 cmd_batch_reserve(cmd, cmd_len);
953 cmd_batch_write(cmd, dw0);
954 cmd_batch_write(cmd, vs_pos << 2);
955 cmd_batch_write(cmd, gs_pos << 2);
956 cmd_batch_write(cmd, ps_pos << 2);
957}
958
Chia-I Wu302742d2014-08-22 10:28:29 +0800959static void gen7_3dstate_pointer(struct intel_cmd *cmd,
960 int subop, XGL_UINT pos)
961{
962 const uint8_t cmd_len = 2;
963 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
964 GEN6_RENDER_SUBTYPE_3D |
965 subop | (cmd_len - 2);
966
967 cmd_batch_reserve(cmd, cmd_len);
968 cmd_batch_write(cmd, dw0);
969 cmd_batch_write(cmd, pos << 2);
970}
971
972static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
973 const struct intel_blend_state *state)
974{
975 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
976 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
977
978 CMD_ASSERT(cmd, 6, 7.5);
979 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
980
981 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
982}
983
984static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
985 const struct intel_ds_state *state)
986{
987 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
988 const uint8_t cmd_len = 3;
989
990 CMD_ASSERT(cmd, 6, 7.5);
991 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
992
993 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
994}
995
996static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
997 uint32_t stencil_ref,
998 const uint32_t blend_color[4])
999{
1000 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
1001 const uint8_t cmd_len = 6;
1002 XGL_UINT pos;
1003 uint32_t *dw;
1004
1005 CMD_ASSERT(cmd, 6, 7.5);
1006
1007 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
1008 dw[0] = stencil_ref;
1009 dw[1] = 0;
1010 dw[2] = blend_color[0];
1011 dw[3] = blend_color[1];
1012 dw[4] = blend_color[2];
1013 dw[5] = blend_color[3];
1014 cmd_state_advance(cmd, cmd_len);
1015
1016 return pos;
1017}
1018
Chia-I Wu8370b402014-08-29 12:28:37 +08001019static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001020{
Chia-I Wu8370b402014-08-29 12:28:37 +08001021 CMD_ASSERT(cmd, 6, 7.5);
1022
Chia-I Wu707a29e2014-08-27 12:51:47 +08001023 if (!cmd->bind.draw_count)
1024 return;
1025
Chia-I Wu8370b402014-08-29 12:28:37 +08001026 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001027 return;
1028
Chia-I Wu8370b402014-08-29 12:28:37 +08001029 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001030
1031 /*
1032 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1033 *
1034 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1035 * pipe-control with a post-sync op and no write-cache flushes."
1036 *
1037 * The workaround below necessitates this workaround.
1038 */
1039 gen6_PIPE_CONTROL(cmd,
1040 GEN6_PIPE_CONTROL_CS_STALL |
1041 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1042 NULL, 0);
1043
Chia-I Wu8370b402014-08-29 12:28:37 +08001044 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, cmd->scratch_bo, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001045}
1046
Chia-I Wu8370b402014-08-29 12:28:37 +08001047static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001048{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001049 CMD_ASSERT(cmd, 6, 7.5);
1050
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001051 if (!cmd->bind.draw_count)
1052 return;
1053
Chia-I Wu8370b402014-08-29 12:28:37 +08001054 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL, NULL, 0);
1055}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001056
Chia-I Wu8370b402014-08-29 12:28:37 +08001057static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1058{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001059 CMD_ASSERT(cmd, 7, 7.5);
1060
Chia-I Wu8370b402014-08-29 12:28:37 +08001061 if (!cmd->bind.draw_count)
1062 return;
1063
1064 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001065
1066 gen6_PIPE_CONTROL(cmd,
1067 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
1068 cmd->scratch_bo, 0);
1069}
1070
Chia-I Wu8370b402014-08-29 12:28:37 +08001071static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1072{
1073 CMD_ASSERT(cmd, 7, 7.5);
1074
1075 if (!cmd->bind.draw_count)
1076 return;
1077
1078 /*
1079 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1080 *
1081 * "One of the following must also be set (when CS stall is set):
1082 *
1083 * * Render Target Cache Flush Enable ([12] of DW1)
1084 * * Depth Cache Flush Enable ([0] of DW1)
1085 * * Stall at Pixel Scoreboard ([1] of DW1)
1086 * * Depth Stall ([13] of DW1)
1087 * * Post-Sync Operation ([13] of DW1)"
1088 */
1089 gen6_PIPE_CONTROL(cmd,
1090 GEN6_PIPE_CONTROL_CS_STALL |
1091 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1092 NULL, 0);
1093}
1094
1095static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1096{
1097 CMD_ASSERT(cmd, 7, 7.5);
1098
1099 if (!cmd->bind.draw_count)
1100 return;
1101
1102 cmd_wa_gen6_pre_depth_stall_write(cmd);
1103
1104 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
1105}
1106
1107static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1108{
1109 CMD_ASSERT(cmd, 6, 7.5);
1110
1111 if (!cmd->bind.draw_count)
1112 return;
1113
1114 /*
1115 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1116 *
1117 * "Driver must guarentee that all the caches in the depth pipe are
1118 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1119 * requires driver to send a PIPE_CONTROL with a CS stall along with
1120 * a Depth Flush prior to this command."
1121 *
1122 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1123 *
1124 * "Driver must ierarchi that all the caches in the depth pipe are
1125 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1126 * requires driver to send a PIPE_CONTROL with a CS stall along with
1127 * a Depth Flush prior to this command.
1128 */
1129 gen6_PIPE_CONTROL(cmd,
1130 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1131 GEN6_PIPE_CONTROL_CS_STALL,
1132 0, 0);
1133}
1134
1135static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1136{
1137 CMD_ASSERT(cmd, 6, 7.5);
1138
1139 if (!cmd->bind.draw_count)
1140 return;
1141
1142 /*
1143 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1144 *
1145 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1146 * and a post sync operation prior to the group of depth
1147 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1148 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1149 *
1150 * This workaround satifies all the conditions.
1151 */
1152 cmd_wa_gen6_pre_depth_stall_write(cmd);
1153
1154 /*
1155 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1156 *
1157 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1158 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1159 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1160 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1161 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1162 * Depth Flush Bit set, followed by another pipelined depth stall
1163 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1164 * guarantee that the pipeline from WM onwards is already flushed
1165 * (e.g., via a preceding MI_FLUSH)."
1166 */
1167 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
1168 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
1169 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
1170}
1171
Chia-I Wu525c6602014-08-27 10:22:34 +08001172void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1173{
1174 if (!cmd->bind.draw_count)
1175 return;
1176
1177 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1178
Chia-I Wu8370b402014-08-29 12:28:37 +08001179 /*
1180 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1181 *
1182 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1183 * PIPE_CONTROL with any non-zero post-sync-op is required."
1184 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001185 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001186 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001187
Chia-I Wu092279a2014-08-30 19:05:30 +08001188 /*
1189 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1190 *
1191 * "One of the following must also be set (when CS stall is set):
1192 *
1193 * * Render Target Cache Flush Enable ([12] of DW1)
1194 * * Depth Cache Flush Enable ([0] of DW1)
1195 * * Stall at Pixel Scoreboard ([1] of DW1)
1196 * * Depth Stall ([13] of DW1)
1197 * * Post-Sync Operation ([13] of DW1)"
1198 */
1199 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1200 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1201 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1202 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1203 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1204 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1205
Chia-I Wu525c6602014-08-27 10:22:34 +08001206 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0);
1207}
1208
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001209void cmd_batch_depth_count(struct intel_cmd *cmd,
1210 struct intel_bo *bo,
1211 XGL_GPU_SIZE offset)
1212{
1213 cmd_wa_gen6_pre_depth_stall_write(cmd);
1214
1215 gen6_PIPE_CONTROL(cmd,
1216 GEN6_PIPE_CONTROL_DEPTH_STALL |
1217 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
1218 bo, offset);
1219}
1220
Chia-I Wu302742d2014-08-22 10:28:29 +08001221static void gen6_cc_states(struct intel_cmd *cmd)
1222{
1223 const struct intel_blend_state *blend = cmd->bind.state.blend;
1224 const struct intel_ds_state *ds = cmd->bind.state.ds;
1225 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001226 uint32_t stencil_ref;
1227 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001228
1229 CMD_ASSERT(cmd, 6, 6);
1230
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001231 if (blend) {
1232 blend_pos = gen6_BLEND_STATE(cmd, blend);
1233 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1234 } else {
1235 blend_pos = 0;
1236 memset(blend_color, 0, sizeof(blend_color));
1237 }
1238
1239 if (ds) {
1240 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1241 stencil_ref = ds->cmd_stencil_ref;
1242 } else {
1243 ds_pos = 0;
1244 stencil_ref = 0;
1245 }
1246
1247 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001248
1249 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
1250}
1251
Chia-I Wu1744cca2014-08-22 11:10:17 +08001252static void gen6_viewport_states(struct intel_cmd *cmd)
1253{
1254 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1255 XGL_UINT pos;
1256
1257 if (!viewport)
1258 return;
1259
1260 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1261 viewport->cmd_align);
1262
1263 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
1264 pos + viewport->cmd_clip_offset,
1265 pos,
1266 pos + viewport->cmd_cc_offset);
1267
1268 pos = (viewport->scissor_enable) ?
1269 pos + viewport->cmd_scissor_rect_offset : 0;
1270
1271 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
1272}
1273
Chia-I Wu302742d2014-08-22 10:28:29 +08001274static void gen7_cc_states(struct intel_cmd *cmd)
1275{
1276 const struct intel_blend_state *blend = cmd->bind.state.blend;
1277 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001278 uint32_t stencil_ref;
1279 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001280 XGL_UINT pos;
1281
1282 CMD_ASSERT(cmd, 7, 7.5);
1283
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001284 if (!blend && !ds)
1285 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001286
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001287 if (blend) {
1288 pos = gen6_BLEND_STATE(cmd, blend);
1289 gen7_3dstate_pointer(cmd,
1290 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +08001291
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001292 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1293 } else {
1294 memset(blend_color, 0, sizeof(blend_color));
1295 }
1296
1297 if (ds) {
1298 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1299 gen7_3dstate_pointer(cmd,
1300 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
1301 } else {
1302 stencil_ref = 0;
1303 }
1304
1305 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001306 gen7_3dstate_pointer(cmd,
1307 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
1308}
1309
Chia-I Wu1744cca2014-08-22 11:10:17 +08001310static void gen7_viewport_states(struct intel_cmd *cmd)
1311{
1312 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1313 XGL_UINT pos;
1314
1315 if (!viewport)
1316 return;
1317
1318 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1319 viewport->cmd_align);
1320
1321 gen7_3dstate_pointer(cmd,
1322 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
1323 gen7_3dstate_pointer(cmd,
1324 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
1325 pos + viewport->cmd_cc_offset);
1326 if (viewport->scissor_enable) {
1327 gen7_3dstate_pointer(cmd,
1328 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1329 pos + viewport->cmd_scissor_rect_offset);
1330 }
1331}
1332
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001333static void gen6_pcb(struct intel_cmd *cmd, int subop,
1334 const XGL_PIPELINE_SHADER *sh)
1335{
1336 const uint8_t cmd_len = 5;
1337 const XGL_UINT alignment = 32;
1338 const XGL_UINT max_size =
1339 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
1340 const XGL_UINT max_pcb = 4;
1341 uint32_t pcb[4] = { 0, 0, 0, 0 };
1342 XGL_FLAGS pcb_enables = 0;
1343 XGL_SIZE total_size = 0;
1344 uint32_t dw0;
1345 XGL_UINT i;
1346
1347 for (i = 0; i < sh->linkConstBufferCount; i++) {
1348 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1349 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1350 void *ptr;
1351
1352 if (info->bufferId >= max_pcb ||
1353 pcb_enables & ((1 << info->bufferId)) ||
1354 total_size + info->bufferSize > max_size) {
1355 cmd->result = XGL_ERROR_UNKNOWN;
1356 return;
1357 }
1358 if (!size)
1359 continue;
1360
1361 pcb_enables |= 1 << info->bufferId;
1362 total_size += size;
1363
1364 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1365 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1366 memcpy(ptr, info->pBufferData, info->bufferSize);
1367 cmd_state_advance(cmd, size / sizeof(uint32_t));
1368
1369 pcb[info->bufferId] |= size / alignment - 1;
1370 }
1371
1372 dw0 = GEN6_RENDER_TYPE_RENDER |
1373 GEN6_RENDER_SUBTYPE_3D |
1374 subop |
1375 pcb_enables << 12 |
1376 (cmd_len - 2);
1377
1378 cmd_batch_reserve(cmd, cmd_len);
1379 cmd_batch_write(cmd, dw0);
1380 cmd_batch_write(cmd, pcb[0]);
1381 cmd_batch_write(cmd, pcb[1]);
1382 cmd_batch_write(cmd, pcb[2]);
1383 cmd_batch_write(cmd, pcb[3]);
1384}
1385
1386static void gen7_pcb(struct intel_cmd *cmd, int subop,
1387 const XGL_PIPELINE_SHADER *sh)
1388{
1389 const uint8_t cmd_len = 7;
1390 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1391 GEN6_RENDER_SUBTYPE_3D |
1392 subop |
1393 (cmd_len - 2);
1394 const XGL_UINT alignment = 32;
1395 const XGL_UINT max_size = 2048;
1396 const XGL_UINT max_pcb = 4;
1397 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
1398 uint32_t pcb[4] = { 0, 0, 0, 0 };
1399 XGL_FLAGS pcb_enables = 0;
1400 XGL_SIZE total_size = 0;
1401 XGL_UINT i;
1402
1403 for (i = 0; i < sh->linkConstBufferCount; i++) {
1404 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1405 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1406 void *ptr;
1407
1408 if (info->bufferId >= max_pcb ||
1409 pcb_enables & ((1 << info->bufferId)) ||
1410 total_size + info->bufferSize > max_size) {
1411 cmd->result = XGL_ERROR_UNKNOWN;
1412 return;
1413 }
1414 if (!size)
1415 continue;
1416
1417 pcb_enables |= 1 << info->bufferId;
1418 total_size += size;
1419
1420 pcb_len[info->bufferId] = size / alignment;
1421
1422 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1423 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1424 memcpy(ptr, info->pBufferData, info->bufferSize);
1425 cmd_state_advance(cmd, size / sizeof(uint32_t));
1426 }
1427
1428 /* no holes */
1429 if (!u_is_pow2(pcb_enables + 1)) {
1430 cmd->result = XGL_ERROR_UNKNOWN;
1431 return;
1432 }
1433
1434 cmd_batch_reserve(cmd, cmd_len);
1435 cmd_batch_write(cmd, dw0);
1436 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
1437 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
1438 cmd_batch_write(cmd, pcb[0]);
1439 cmd_batch_write(cmd, pcb[1]);
1440 cmd_batch_write(cmd, pcb[2]);
1441 cmd_batch_write(cmd, pcb[3]);
1442}
1443
Chia-I Wu42a56202014-08-23 16:47:48 +08001444static void emit_ps_resources(struct intel_cmd *cmd,
1445 const struct intel_rmap *rmap)
1446{
1447 const XGL_UINT surface_count = rmap->rt_count +
1448 rmap->resource_count + rmap->uav_count;
1449 uint32_t binding_table[256];
1450 XGL_UINT pos, i;
1451
1452 assert(surface_count <= ARRAY_SIZE(binding_table));
1453
1454 for (i = 0; i < surface_count; i++) {
1455 const struct intel_rmap_slot *slot = &rmap->slots[i];
1456 uint32_t *dw;
1457
1458 switch (slot->path_len) {
1459 case 0:
1460 pos = 0;
1461 break;
1462 case INTEL_RMAP_SLOT_RT:
1463 {
1464 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1465
1466 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1467 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1468
1469 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001470 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001471 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001472 cmd_state_advance(cmd, view->cmd_len);
1473 }
1474 break;
1475 case INTEL_RMAP_SLOT_DYN:
1476 {
1477 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001478 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001479
1480 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1481 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1482
1483 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001484 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001485 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001486 cmd_state_advance(cmd, view->cmd_len);
1487 }
1488 break;
1489 case 1:
1490 default:
1491 /* TODO */
1492 assert(!"no dset support");
1493 break;
1494 }
1495
1496 binding_table[i] = pos << 2;
1497 }
1498
1499 pos = cmd_state_copy(cmd, binding_table, surface_count,
1500 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
1501
1502 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1503 gen7_3dstate_pointer(cmd,
1504 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001505
1506 gen7_3dstate_pointer(cmd,
1507 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1508 gen7_3dstate_pointer(cmd,
1509 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1510 gen7_3dstate_pointer(cmd,
1511 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1512 gen7_3dstate_pointer(cmd,
1513 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1514
1515 gen7_3dstate_pointer(cmd,
1516 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1517 gen7_3dstate_pointer(cmd,
1518 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1519 gen7_3dstate_pointer(cmd,
1520 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1521 gen7_3dstate_pointer(cmd,
1522 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1523 gen7_3dstate_pointer(cmd,
1524 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001525 } else {
1526 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001527 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001528 }
1529}
1530
Chia-I Wu52500102014-08-22 00:46:04 +08001531static void emit_bounded_states(struct intel_cmd *cmd)
1532{
1533 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1534
1535 /* TODO more states */
1536
Chia-I Wu1744cca2014-08-22 11:10:17 +08001537 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001538 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001539 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001540
1541 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1542 &cmd->bind.pipeline.graphics->vs);
1543 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1544 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001545
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001546 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001547 gen7_3DSTATE_SF(cmd);
1548 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001549 gen7_3DSTATE_WM(cmd);
1550 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001551 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001552 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001553 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001554
1555 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1556 &cmd->bind.pipeline.graphics->vs);
1557 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1558 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001559
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001560 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001561 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001562 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001563 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001564
Chia-I Wu42a56202014-08-23 16:47:48 +08001565 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1566
Chia-I Wu8370b402014-08-29 12:28:37 +08001567 cmd_wa_gen6_pre_depth_stall_write(cmd);
1568 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001569 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001570 cmd_batch_reserve(cmd, msaa->cmd_len);
1571 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001572}
1573
1574static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001575 const struct intel_pipe_shader *shader,
1576 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001577{
1578 uint32_t i;
1579 struct intel_cmd_shader *cmdShader;
1580
1581 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001582 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001583 /* shader is already part of pipeline */
1584 return;
1585 }
1586 }
1587
Chia-I Wu338fe642014-08-28 10:43:04 +08001588 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1589 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1590
1591 cmdShader = cmd->bind.shaderCache.shaderArray;
1592
1593 cmd->bind.shaderCache.shaderArray =
1594 icd_alloc(sizeof(*cmdShader) * new_count,
1595 0, XGL_SYSTEM_ALLOC_INTERNAL);
1596 if (cmd->bind.shaderCache.shaderArray == NULL) {
1597 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001598 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1599 return;
1600 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001601
1602 if (cmdShader) {
1603 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1604 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1605 icd_free(cmdShader);
1606 }
1607
1608 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001609 }
1610
Chia-I Wu338fe642014-08-28 10:43:04 +08001611 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001612 cmdShader->shader = shader;
1613 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001614 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001615 cmd->bind.shaderCache.used++;
1616 return;
1617}
1618
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001619static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001620 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001621{
1622 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001623
Chia-I Wu8370b402014-08-29 12:28:37 +08001624 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1625 cmd_wa_gen6_pre_depth_stall_write(cmd);
1626 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1627 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1628 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1629 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001630
1631 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001632 assert(pipeline->cmd_len);
Chia-I Wub08727d2014-08-29 14:54:54 +08001633 cmd_batch_reserve(cmd, pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001634 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001635
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001636 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001637 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001638 }
1639 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001640 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001641 }
1642 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001643 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001644 }
1645 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001646 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001647 }
1648 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001649 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001650 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001651
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001652 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1653 gen7_3DSTATE_GS(cmd);
1654 } else {
1655 gen6_3DSTATE_GS(cmd);
1656 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001657
Chia-I Wu8370b402014-08-29 12:28:37 +08001658 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1659 cmd_wa_gen7_post_command_cs_stall(cmd);
1660 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1661 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001662}
1663
1664static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1665 const struct intel_pipeline *pipeline)
1666{
1667 cmd->bind.pipeline.compute = pipeline;
1668}
1669
1670static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1671 const struct intel_pipeline_delta *delta)
1672{
1673 cmd->bind.pipeline.graphics_delta = delta;
1674}
1675
1676static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1677 const struct intel_pipeline_delta *delta)
1678{
1679 cmd->bind.pipeline.compute_delta = delta;
1680}
1681
1682static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1683 const struct intel_dset *dset,
1684 XGL_UINT slot_offset)
1685{
1686 cmd->bind.dset.graphics = dset;
1687 cmd->bind.dset.graphics_offset = slot_offset;
1688}
1689
1690static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1691 const struct intel_dset *dset,
1692 XGL_UINT slot_offset)
1693{
1694 cmd->bind.dset.compute = dset;
1695 cmd->bind.dset.compute_offset = slot_offset;
1696}
1697
1698static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1699 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1700{
1701 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1702}
1703
1704static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1705 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1706{
1707 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1708}
1709
1710static void cmd_bind_index_data(struct intel_cmd *cmd,
1711 const struct intel_mem *mem,
1712 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1713{
1714 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1715 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1716 } else {
1717 cmd->bind.index.mem = mem;
1718 cmd->bind.index.offset = offset;
1719 cmd->bind.index.type = type;
1720 }
1721}
1722
1723static void cmd_bind_rt(struct intel_cmd *cmd,
1724 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1725 XGL_UINT count)
1726{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001727 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001728 XGL_UINT i;
1729
1730 for (i = 0; i < count; i++) {
1731 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1732 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001733 const struct intel_layout *layout = &rt->img->layout;
1734
1735 if (i == 0) {
1736 width = layout->width0;
1737 height = layout->height0;
1738 } else {
1739 if (width > layout->width0)
1740 width = layout->width0;
1741 if (height > layout->height0)
1742 height = layout->height0;
1743 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001744
1745 cmd->bind.att.rt[i] = rt;
1746 }
1747
1748 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001749
Chia-I Wu8370b402014-08-29 12:28:37 +08001750 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001751 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001752}
1753
1754static void cmd_bind_ds(struct intel_cmd *cmd,
1755 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1756{
1757 const struct intel_ds_view *ds;
1758
1759 if (info) {
1760 cmd->bind.att.ds = intel_ds_view(info->view);
1761 ds = cmd->bind.att.ds;
1762 } else {
1763 /* all zeros */
1764 static const struct intel_ds_view null_ds;
1765 ds = &null_ds;
1766 }
1767
Chia-I Wu8370b402014-08-29 12:28:37 +08001768 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001769 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1770 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1771 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001772
1773 if (cmd_gen(cmd) >= INTEL_GEN(7))
1774 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1775 else
1776 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001777}
1778
1779static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1780 const struct intel_viewport_state *state)
1781{
1782 cmd->bind.state.viewport = state;
1783}
1784
1785static void cmd_bind_raster_state(struct intel_cmd *cmd,
1786 const struct intel_raster_state *state)
1787{
1788 cmd->bind.state.raster = state;
1789}
1790
1791static void cmd_bind_ds_state(struct intel_cmd *cmd,
1792 const struct intel_ds_state *state)
1793{
1794 cmd->bind.state.ds = state;
1795}
1796
1797static void cmd_bind_blend_state(struct intel_cmd *cmd,
1798 const struct intel_blend_state *state)
1799{
1800 cmd->bind.state.blend = state;
1801}
1802
1803static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1804 const struct intel_msaa_state *state)
1805{
1806 cmd->bind.state.msaa = state;
1807}
1808
1809static void cmd_draw(struct intel_cmd *cmd,
1810 XGL_UINT vertex_start,
1811 XGL_UINT vertex_count,
1812 XGL_UINT instance_start,
1813 XGL_UINT instance_count,
1814 bool indexed,
1815 XGL_UINT vertex_base)
1816{
1817 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1818
1819 emit_bounded_states(cmd);
1820
1821 if (indexed) {
1822 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1823 cmd->result = XGL_ERROR_UNKNOWN;
1824
1825 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1826 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1827 p->primitive_restart_index);
1828 } else {
1829 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1830 cmd->bind.index.offset, cmd->bind.index.type,
1831 p->primitive_restart);
1832 }
1833 } else {
1834 assert(!vertex_base);
1835 }
1836
1837 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1838 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1839 vertex_start, instance_count, instance_start, vertex_base);
1840 } else {
1841 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1842 vertex_start, instance_count, instance_start, vertex_base);
1843 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001844
Chia-I Wu707a29e2014-08-27 12:51:47 +08001845 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001846 /* need to re-emit all workarounds */
1847 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001848}
1849
Chia-I Wub2755562014-08-20 13:38:52 +08001850XGL_VOID XGLAPI intelCmdBindPipeline(
1851 XGL_CMD_BUFFER cmdBuffer,
1852 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1853 XGL_PIPELINE pipeline)
1854{
1855 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1856
1857 switch (pipelineBindPoint) {
1858 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001859 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001860 break;
1861 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001862 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001863 break;
1864 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001865 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001866 break;
1867 }
1868}
1869
1870XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1871 XGL_CMD_BUFFER cmdBuffer,
1872 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1873 XGL_PIPELINE_DELTA delta)
1874{
1875 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1876
1877 switch (pipelineBindPoint) {
1878 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001879 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001880 break;
1881 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001882 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001883 break;
1884 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001885 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001886 break;
1887 }
1888}
1889
1890XGL_VOID XGLAPI intelCmdBindStateObject(
1891 XGL_CMD_BUFFER cmdBuffer,
1892 XGL_STATE_BIND_POINT stateBindPoint,
1893 XGL_STATE_OBJECT state)
1894{
1895 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1896
1897 switch (stateBindPoint) {
1898 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001899 cmd_bind_viewport_state(cmd,
1900 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001901 break;
1902 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001903 cmd_bind_raster_state(cmd,
1904 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001905 break;
1906 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001907 cmd_bind_ds_state(cmd,
1908 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001909 break;
1910 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001911 cmd_bind_blend_state(cmd,
1912 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001913 break;
1914 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001915 cmd_bind_msaa_state(cmd,
1916 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001917 break;
1918 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001919 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001920 break;
1921 }
1922}
1923
1924XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1925 XGL_CMD_BUFFER cmdBuffer,
1926 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1927 XGL_UINT index,
1928 XGL_DESCRIPTOR_SET descriptorSet,
1929 XGL_UINT slotOffset)
1930{
1931 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1932 struct intel_dset *dset = intel_dset(descriptorSet);
1933
1934 assert(!index);
1935
1936 switch (pipelineBindPoint) {
1937 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001938 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001939 break;
1940 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001941 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001942 break;
1943 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001944 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001945 break;
1946 }
1947}
1948
1949XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1950 XGL_CMD_BUFFER cmdBuffer,
1951 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1952 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1953{
1954 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1955
1956 switch (pipelineBindPoint) {
1957 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001958 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001959 break;
1960 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001961 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001962 break;
1963 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001964 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001965 break;
1966 }
1967}
1968
1969XGL_VOID XGLAPI intelCmdBindIndexData(
1970 XGL_CMD_BUFFER cmdBuffer,
1971 XGL_GPU_MEMORY mem_,
1972 XGL_GPU_SIZE offset,
1973 XGL_INDEX_TYPE indexType)
1974{
1975 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1976 struct intel_mem *mem = intel_mem(mem_);
1977
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001978 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001979}
1980
1981XGL_VOID XGLAPI intelCmdBindAttachments(
1982 XGL_CMD_BUFFER cmdBuffer,
1983 XGL_UINT colorAttachmentCount,
1984 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1985 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1986{
1987 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001988
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001989 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1990 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001991}
1992
1993XGL_VOID XGLAPI intelCmdDraw(
1994 XGL_CMD_BUFFER cmdBuffer,
1995 XGL_UINT firstVertex,
1996 XGL_UINT vertexCount,
1997 XGL_UINT firstInstance,
1998 XGL_UINT instanceCount)
1999{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002000 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002001
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002002 cmd_draw(cmd, firstVertex, vertexCount,
2003 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08002004}
2005
2006XGL_VOID XGLAPI intelCmdDrawIndexed(
2007 XGL_CMD_BUFFER cmdBuffer,
2008 XGL_UINT firstIndex,
2009 XGL_UINT indexCount,
2010 XGL_INT vertexOffset,
2011 XGL_UINT firstInstance,
2012 XGL_UINT instanceCount)
2013{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002014 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002015
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002016 cmd_draw(cmd, firstIndex, indexCount,
2017 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002018}
2019
2020XGL_VOID XGLAPI intelCmdDrawIndirect(
2021 XGL_CMD_BUFFER cmdBuffer,
2022 XGL_GPU_MEMORY mem,
2023 XGL_GPU_SIZE offset,
2024 XGL_UINT32 count,
2025 XGL_UINT32 stride)
2026{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002027 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2028
2029 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002030}
2031
2032XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2033 XGL_CMD_BUFFER cmdBuffer,
2034 XGL_GPU_MEMORY mem,
2035 XGL_GPU_SIZE offset,
2036 XGL_UINT32 count,
2037 XGL_UINT32 stride)
2038{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002039 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2040
2041 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002042}
2043
2044XGL_VOID XGLAPI intelCmdDispatch(
2045 XGL_CMD_BUFFER cmdBuffer,
2046 XGL_UINT x,
2047 XGL_UINT y,
2048 XGL_UINT z)
2049{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002050 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2051
2052 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002053}
2054
2055XGL_VOID XGLAPI intelCmdDispatchIndirect(
2056 XGL_CMD_BUFFER cmdBuffer,
2057 XGL_GPU_MEMORY mem,
2058 XGL_GPU_SIZE offset)
2059{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002060 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2061
2062 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002063}