blob: 37395ad55b0422e1bca850a4b329cee5e30eb58b [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 Wu270b1e82014-08-25 15:53:39 +080099
100 CMD_ASSERT(cmd, 6, 7.5);
101
102 assert(bo_offset % 8 == 0);
103
104 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
105 /*
106 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
107 *
108 * "1 of the following must also be set (when CS stall is set):
109 *
110 * * Depth Cache Flush Enable ([0] of DW1)
111 * * Stall at Pixel Scoreboard ([1] of DW1)
112 * * Depth Stall ([13] of DW1)
113 * * Post-Sync Operation ([13] of DW1)
114 * * Render Target Cache Flush Enable ([12] of DW1)
115 * * Notify Enable ([8] of DW1)"
116 *
117 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
118 *
119 * "One of the following must also be set (when CS stall is set):
120 *
121 * * Render Target Cache Flush Enable ([12] of DW1)
122 * * Depth Cache Flush Enable ([0] of DW1)
123 * * Stall at Pixel Scoreboard ([1] of DW1)
124 * * Depth Stall ([13] of DW1)
125 * * Post-Sync Operation ([13] of DW1)"
126 */
127 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
128 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
129 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
130 GEN6_PIPE_CONTROL_DEPTH_STALL;
131
132 /* post-sync op */
133 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
134 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
135 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
136
137 if (cmd_gen(cmd) == INTEL_GEN(6))
138 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
139
140 assert(dw1 & bit_test);
141 }
142
143 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
144 /*
145 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
146 *
147 * "Following bits must be clear (when Depth Stall is set):
148 *
149 * * Render Target Cache Flush Enable ([12] of DW1)
150 * * Depth Cache Flush Enable ([0] of DW1)"
151 */
152 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
153 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
154 }
155
156 /*
157 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
158 *
159 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
160 * and PIPE_CONTROL are not supported."
161 *
162 * The kernel will add the mapping automatically (when write domain is
163 * INTEL_DOMAIN_INSTRUCTION).
164 */
165 if (cmd_gen(cmd) == INTEL_GEN(6) && bo)
166 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
167
168 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) bo);
169 cmd_batch_write(cmd, dw0);
170 cmd_batch_write(cmd, dw1);
Chia-I Wu32a22462014-08-26 14:13:46 +0800171 if (bo) {
172 cmd_batch_reloc(cmd, bo_offset, bo, INTEL_RELOC_GGTT |
173 INTEL_RELOC_WRITE);
174 } else {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800175 cmd_batch_write(cmd, 0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800176 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 cmd_batch_write(cmd, 0);
178 cmd_batch_write(cmd, 0);
179}
180
Chia-I Wu254db422014-08-21 11:54:29 +0800181static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
182{
183 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
184 bool supported;
185
186 CMD_ASSERT(cmd, 6, 7.5);
187
188 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
189 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
190
191 switch (p->prim_type) {
192 case GEN6_3DPRIM_POINTLIST:
193 case GEN6_3DPRIM_LINELIST:
194 case GEN6_3DPRIM_LINESTRIP:
195 case GEN6_3DPRIM_TRILIST:
196 case GEN6_3DPRIM_TRISTRIP:
197 supported = true;
198 break;
199 default:
200 supported = false;
201 break;
202 }
203
204 if (!supported)
205 return false;
206
207 switch (cmd->bind.index.type) {
208 case XGL_INDEX_8:
209 supported = (p->primitive_restart_index != 0xffu);
210 break;
211 case XGL_INDEX_16:
212 supported = (p->primitive_restart_index != 0xffffu);
213 break;
214 case XGL_INDEX_32:
215 supported = (p->primitive_restart_index != 0xffffffffu);
216 break;
217 default:
218 supported = false;
219 break;
220 }
221
222 return supported;
223}
224
Chia-I Wu59c097e2014-08-21 10:51:07 +0800225static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800226 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800227 XGL_GPU_SIZE offset,
228 XGL_INDEX_TYPE type,
229 bool enable_cut_index)
230{
231 const uint8_t cmd_len = 3;
232 uint32_t dw0, end_offset;
233 unsigned offset_align;
234
235 CMD_ASSERT(cmd, 6, 7.5);
236
Chia-I Wu426072d2014-08-26 14:31:55 +0800237 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238
239 /* the bit is moved to 3DSTATE_VF */
240 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
241 assert(!enable_cut_index);
242 if (enable_cut_index)
243 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
244
245 switch (type) {
246 case XGL_INDEX_8:
247 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
248 offset_align = 1;
249 break;
250 case XGL_INDEX_16:
251 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
252 offset_align = 2;
253 break;
254 case XGL_INDEX_32:
255 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
256 offset_align = 4;
257 break;
258 default:
259 cmd->result = XGL_ERROR_INVALID_VALUE;
260 return;
261 break;
262 }
263
264 if (offset % offset_align) {
265 cmd->result = XGL_ERROR_INVALID_VALUE;
266 return;
267 }
268
269 /* aligned and inclusive */
270 end_offset = mem->size - (mem->size % offset_align) - 1;
271
Chia-I Wu2de65d02014-08-25 10:02:53 +0800272 cmd_batch_reserve_reloc(cmd, cmd_len, 2);
Chia-I Wue24c3292014-08-21 14:05:23 +0800273 cmd_batch_write(cmd, dw0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800274 cmd_batch_reloc(cmd, offset, mem->bo, 0);
275 cmd_batch_reloc(cmd, end_offset, mem->bo, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800276}
277
Chia-I Wu62a7f252014-08-29 11:31:16 +0800278static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
279 bool enable_cut_index,
280 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800281{
282 const uint8_t cmd_len = 2;
283 uint32_t dw0;
284
285 CMD_ASSERT(cmd, 7.5, 7.5);
286
Chia-I Wu426072d2014-08-26 14:31:55 +0800287 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800288 if (enable_cut_index)
289 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
290
Chia-I Wue24c3292014-08-21 14:05:23 +0800291 cmd_batch_reserve(cmd, cmd_len);
292 cmd_batch_write(cmd, dw0);
293 cmd_batch_write(cmd, cut_index);
Chia-I Wu254db422014-08-21 11:54:29 +0800294}
295
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800296static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
297{
298 const uint8_t cmd_len = 7;
299 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
300
301 CMD_ASSERT(cmd, 6, 6);
302
303 assert(cmd->bind.gs.shader == NULL);
304
305 cmd_batch_reserve(cmd, cmd_len);
306 cmd_batch_write(cmd, dw0);
307 cmd_batch_write(cmd, 0);
308 cmd_batch_write(cmd, 0);
309 cmd_batch_write(cmd, 0);
310 cmd_batch_write(cmd, 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT);
311 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
312 cmd_batch_write(cmd, 0);
313}
314
Chia-I Wu62a7f252014-08-29 11:31:16 +0800315static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
316{
317 const uint8_t cmd_len = 7;
318 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
319
320 CMD_ASSERT(cmd, 7, 7.5);
321
322 assert(cmd->bind.gs.shader == NULL);
323
324 cmd_batch_reserve(cmd, cmd_len);
325 cmd_batch_write(cmd, dw0);
326 cmd_batch_write(cmd, 0);
327 cmd_batch_write(cmd, 0);
328 cmd_batch_write(cmd, 0);
329 cmd_batch_write(cmd, 0);
330 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
331 cmd_batch_write(cmd, 0);
332}
333
Chia-I Wud88e02d2014-08-25 10:56:13 +0800334static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
335 XGL_UINT width, XGL_UINT height)
336{
337 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800338 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800339 (cmd_len - 2);
340
341 CMD_ASSERT(cmd, 6, 7.5);
342
343 cmd_batch_reserve(cmd, cmd_len);
344 cmd_batch_write(cmd, dw0);
345 if (width && height) {
346 cmd_batch_write(cmd, 0);
347 cmd_batch_write(cmd, (height - 1) << 16 |
348 (width - 1));
349 } else {
350 cmd_batch_write(cmd, 1);
351 cmd_batch_write(cmd, 0);
352 }
353 cmd_batch_write(cmd, 0);
354}
355
Chia-I Wu8016a172014-08-29 18:31:32 +0800356static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
357 uint32_t body[6])
358{
359 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
360 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
361 const struct intel_raster_state *raster = cmd->bind.state.raster;
362 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
363 uint32_t dw1, dw2, dw3;
364 int point_width;
365
366 CMD_ASSERT(cmd, 6, 7.5);
367
368 dw1 = GEN7_SF_DW1_STATISTICS |
369 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
370 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
371 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
372 GEN7_SF_DW1_VIEWPORT_ENABLE |
373 raster->cmd_sf_fill;
374
375 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
376 int format;
377
378 switch (pipeline->db_format.channelFormat) {
379 case XGL_CH_FMT_R16:
380 format = GEN6_ZFORMAT_D16_UNORM;
381 break;
382 case XGL_CH_FMT_R32:
383 case XGL_CH_FMT_R32G8:
384 format = GEN6_ZFORMAT_D32_FLOAT;
385 break;
386 default:
387 assert(!"unknown depth format");
388 format = 0;
389 break;
390 }
391
392 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
393 }
394
395 dw2 = raster->cmd_sf_cull;
396
397 if (msaa->sample_count > 1) {
398 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
399 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
400 } else {
401 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
402 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
403 }
404
405 if (viewport->scissor_enable)
406 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
407
408 /* in U8.3 */
409 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
410 point_width = U_CLAMP(point_width, 1, 2047);
411
412 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
413 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
414 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
415 GEN7_SF_DW3_SUBPIXEL_8BITS |
416 GEN7_SF_DW3_USE_POINT_WIDTH |
417 point_width;
418
419 body[0] = dw1;
420 body[1] = dw2;
421 body[2] = dw3;
422 body[3] = raster->cmd_depth_offset_const;
423 body[4] = raster->cmd_depth_offset_scale;
424 body[5] = raster->cmd_depth_offset_clamp;
425}
426
427static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
428 uint32_t body[13])
429{
430 const struct intel_shader *vs =
431 intel_shader(cmd->bind.pipeline.graphics->vs.shader);
432 const struct intel_shader *fs =
433 intel_shader(cmd->bind.pipeline.graphics->fs.shader);
434 XGL_UINT attr_skip, attr_count;
435 XGL_UINT vue_offset, vue_len;
436 XGL_UINT i;
437 uint32_t dw1;
438
439 CMD_ASSERT(cmd, 6, 7.5);
440
441 /* VS outputs VUE header and position additionally */
442 assert(vs->out_count >= 2);
443 attr_skip = 2;
444 attr_count = vs->out_count - attr_skip;
445 assert(fs->in_count == attr_count);
446 assert(fs->in_count <= 32);
447
448 vue_offset = attr_skip / 2;
449 vue_len = (attr_count + 1) / 2;
450 if (!vue_len)
451 vue_len = 1;
452
453 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
454 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
455 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
456
457 body[0] = dw1;
458
459 for (i = 0; i < 8; i++) {
460 uint16_t hi, lo;
461
462 /* no attr swizzles */
463 if (i * 2 + 1 < fs->in_count) {
464 hi = i * 2 + 1;
465 lo = i * 2;
466 } else if (i * 2 < fs->in_count) {
467 hi = 0;
468 lo = i * 2;
469 } else {
470 hi = 0;
471 lo = 0;
472 }
473
474 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
475 }
476
477 body[9] = 0; /* point sprite enables */
478 body[10] = 0; /* constant interpolation enables */
479 body[11] = 0; /* WrapShortest enables */
480 body[12] = 0;
481}
482
483static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
484{
485 const uint8_t cmd_len = 20;
486 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
487 (cmd_len - 2);
488 uint32_t sf[6];
489 uint32_t sbe[13];
490
491 CMD_ASSERT(cmd, 6, 6);
492
493 gen7_fill_3DSTATE_SF_body(cmd, sf);
494 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
495
496 cmd_batch_reserve(cmd, cmd_len);
497 cmd_batch_write(cmd, dw0);
498 cmd_batch_write(cmd, sbe[0]);
499 cmd_batch_write_n(cmd, sf, 6);
500 cmd_batch_write_n(cmd, &sbe[1], 12);
501}
502
503static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
504{
505 const uint8_t cmd_len = 7;
506 uint32_t dw[7];
507
508 CMD_ASSERT(cmd, 7, 7.5);
509
510 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
511 (cmd_len - 2);
512 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
513
514 cmd_batch_reserve(cmd, cmd_len);
515 cmd_batch_write_n(cmd, dw, cmd_len);
516}
517
518static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
519{
520 const uint8_t cmd_len = 14;
521 uint32_t dw[14];
522
523 CMD_ASSERT(cmd, 7, 7.5);
524
525 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
526 (cmd_len - 2);
527 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
528
529 cmd_batch_reserve(cmd, cmd_len);
530 cmd_batch_write_n(cmd, dw, cmd_len);
531}
532
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800533static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
534{
535 const uint8_t cmd_len = 4;
536 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
537 (cmd_len - 2);
538 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
539 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
540 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
541 const struct intel_raster_state *raster = cmd->bind.state.raster;
542 uint32_t dw1, dw2, dw3;
543
544 CMD_ASSERT(cmd, 6, 7.5);
545
546 dw1 = GEN6_CLIP_DW1_STATISTICS;
547 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
548 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
549 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
550 raster->cmd_clip_cull;
551 }
552
553 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
554 GEN6_CLIP_DW2_XY_TEST_ENABLE |
555 GEN6_CLIP_DW2_APIMODE_OGL |
556 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
557 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
558 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
559
560 if (pipeline->rasterizerDiscardEnable)
561 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
562 else
563 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
564
565 if (pipeline->depthClipEnable)
566 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
567
568 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
569 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
570 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
571 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
572
573 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
574 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
575 (viewport->viewport_count - 1);
576
577 cmd_batch_reserve(cmd, cmd_len);
578 cmd_batch_write(cmd, dw0);
579 cmd_batch_write(cmd, dw1);
580 cmd_batch_write(cmd, dw2);
581 cmd_batch_write(cmd, dw3);
582}
583
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800584static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
585{
586 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
587 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
588 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
589 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
590 const uint8_t cmd_len = 9;
591 uint32_t dw0, dw2, dw4, dw5, dw6;
592
593 CMD_ASSERT(cmd, 6, 6);
594
595 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
596
597 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
598 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
599
600 dw4 = GEN6_WM_DW4_STATISTICS |
601 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
602 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
603 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
604
605 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
606 GEN6_WM_DW5_PS_ENABLE |
607 GEN6_WM_DW5_8_PIXEL_DISPATCH;
608
609 if (fs->uses & INTEL_SHADER_USE_KILL ||
610 pipeline->cb_state.alphaToCoverageEnable)
611 dw5 |= GEN6_WM_DW5_PS_KILL;
612
613 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
614 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
615 if (fs->uses & INTEL_SHADER_USE_DEPTH)
616 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
617 if (fs->uses & INTEL_SHADER_USE_W)
618 dw5 |= GEN6_WM_DW5_PS_USE_W;
619
620 if (pipeline->cb_state.dualSourceBlendEnable)
621 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
622
623 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
624 GEN6_WM_DW6_POSOFFSET_NONE |
625 GEN6_WM_DW6_ZW_INTERP_PIXEL |
626 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
627 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
628
629 if (msaa->sample_count > 1) {
630 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
631 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
632 } else {
633 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
634 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
635 }
636
637 cmd_batch_reserve(cmd, cmd_len);
638 cmd_batch_write(cmd, dw0);
639 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
640 cmd_batch_write(cmd, dw2);
641 cmd_batch_write(cmd, 0); /* scratch */
642 cmd_batch_write(cmd, dw4);
643 cmd_batch_write(cmd, dw5);
644 cmd_batch_write(cmd, dw6);
645 cmd_batch_write(cmd, 0); /* kernel 1 */
646 cmd_batch_write(cmd, 0); /* kernel 2 */
647}
648
649static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
650{
651 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
652 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
653 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
654 const uint8_t cmd_len = 3;
655 uint32_t dw0, dw1, dw2;
656
657 CMD_ASSERT(cmd, 7, 7.5);
658
659 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
660
661 dw1 = GEN7_WM_DW1_STATISTICS |
662 GEN7_WM_DW1_PS_ENABLE |
663 GEN7_WM_DW1_ZW_INTERP_PIXEL |
664 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
665 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
666
667 if (fs->uses & INTEL_SHADER_USE_KILL ||
668 pipeline->cb_state.alphaToCoverageEnable)
669 dw1 |= GEN7_WM_DW1_PS_KILL;
670
671 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
672 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
673 if (fs->uses & INTEL_SHADER_USE_DEPTH)
674 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
675 if (fs->uses & INTEL_SHADER_USE_W)
676 dw1 |= GEN7_WM_DW1_PS_USE_W;
677
678 dw2 = 0;
679
680 if (msaa->sample_count > 1) {
681 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
682 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
683 } else {
684 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
685 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
686 }
687
688 cmd_batch_reserve(cmd, cmd_len);
689 cmd_batch_write(cmd, dw0);
690 cmd_batch_write(cmd, dw1);
691 cmd_batch_write(cmd, dw2);
692}
693
694static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
695{
696 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
697 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
698 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
699 const uint8_t cmd_len = 8;
700 uint32_t dw0, dw2, dw4, dw5;
701
702 CMD_ASSERT(cmd, 7, 7.5);
703
704 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
705
706 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
707 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
708
709 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
710 GEN7_PS_DW4_8_PIXEL_DISPATCH;
711
712 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
713 const int max_threads =
714 (cmd->dev->gpu->gt == 3) ? 408 :
715 (cmd->dev->gpu->gt == 2) ? 204 : 102;
716 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
717 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
718 } else {
719 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
720 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
721 }
722
723 if (pipeline->fs.linkConstBufferCount)
724 dw4 |= GEN7_PS_DW4_PUSH_CONSTANT_ENABLE;
725
726 if (fs->in_count)
727 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
728
729 if (pipeline->cb_state.dualSourceBlendEnable)
730 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
731
732 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
733 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
734 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
735
736 cmd_batch_reserve(cmd, cmd_len);
737 cmd_batch_write(cmd, dw0);
738 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
739 cmd_batch_write(cmd, dw2);
740 cmd_batch_write(cmd, 0); /* scratch */
741 cmd_batch_write(cmd, dw4);
742 cmd_batch_write(cmd, dw5);
743 cmd_batch_write(cmd, 0); /* kernel 1 */
744 cmd_batch_write(cmd, 0); /* kernel 2 */
745}
746
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800747static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
748 const struct intel_ds_view *view)
749{
750 const uint8_t cmd_len = 7;
751 uint32_t dw0;
752
753 CMD_ASSERT(cmd, 6, 7.5);
754
755 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800756 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
757 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800758 dw0 |= (cmd_len - 2);
759
Chia-I Wu2de65d02014-08-25 10:02:53 +0800760 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800761 cmd_batch_write(cmd, dw0);
762 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600763 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800764 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800765 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600766 } else {
767 cmd_batch_write(cmd, 0);
768 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800769 cmd_batch_write(cmd, view->cmd[2]);
770 cmd_batch_write(cmd, view->cmd[3]);
771 cmd_batch_write(cmd, view->cmd[4]);
772 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800773}
774
775static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
776 const struct intel_ds_view *view)
777{
778 const uint8_t cmd_len = 3;
779 uint32_t dw0;
780
781 CMD_ASSERT(cmd, 6, 7.5);
782
783 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800784 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
785 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800786 dw0 |= (cmd_len - 2);
787
Chia-I Wu2de65d02014-08-25 10:02:53 +0800788 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800789 cmd_batch_write(cmd, dw0);
790 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600791 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800792 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800793 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600794 } else {
795 cmd_batch_write(cmd, 0);
796 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797}
798
799static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
800 const struct intel_ds_view *view)
801{
802 const uint8_t cmd_len = 3;
803 uint32_t dw0;
804
805 CMD_ASSERT(cmd, 6, 7.5);
806
807 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800808 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
809 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810 dw0 |= (cmd_len - 2);
811
Chia-I Wu2de65d02014-08-25 10:02:53 +0800812 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800813 cmd_batch_write(cmd, dw0);
814 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600815 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800816 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800817 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600818 } else {
819 cmd_batch_write(cmd, 0);
820 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800821}
822
Chia-I Wuf8231032014-08-25 10:44:45 +0800823static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
824 uint32_t clear_val)
825{
826 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800827 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800828 GEN6_CLEAR_PARAMS_DW0_VALID |
829 (cmd_len - 2);
830
831 CMD_ASSERT(cmd, 6, 6);
832
833 cmd_batch_reserve(cmd, cmd_len);
834 cmd_batch_write(cmd, dw0);
835 cmd_batch_write(cmd, clear_val);
836}
837
838static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
839 uint32_t clear_val)
840{
841 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800842 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800843 (cmd_len - 2);
844
845 CMD_ASSERT(cmd, 7, 7.5);
846
847 cmd_batch_reserve(cmd, cmd_len);
848 cmd_batch_write(cmd, dw0);
849 cmd_batch_write(cmd, clear_val);
850 cmd_batch_write(cmd, 1);
851}
852
Chia-I Wu302742d2014-08-22 10:28:29 +0800853static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
854 XGL_UINT blend_pos,
855 XGL_UINT ds_pos,
856 XGL_UINT cc_pos)
857{
858 const uint8_t cmd_len = 4;
859 uint32_t dw0;
860
861 CMD_ASSERT(cmd, 6, 6);
862
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800864 (cmd_len - 2);
865
866 cmd_batch_reserve(cmd, cmd_len);
867 cmd_batch_write(cmd, dw0);
868 cmd_batch_write(cmd, (blend_pos << 2) | 1);
869 cmd_batch_write(cmd, (ds_pos << 2) | 1);
870 cmd_batch_write(cmd, (cc_pos << 2) | 1);
871}
872
Chia-I Wu1744cca2014-08-22 11:10:17 +0800873static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
874 XGL_UINT clip_pos,
875 XGL_UINT sf_pos,
876 XGL_UINT cc_pos)
877{
878 const uint8_t cmd_len = 4;
879 uint32_t dw0;
880
881 CMD_ASSERT(cmd, 6, 6);
882
Chia-I Wu426072d2014-08-26 14:31:55 +0800883 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800884 GEN6_PTR_VP_DW0_CLIP_CHANGED |
885 GEN6_PTR_VP_DW0_SF_CHANGED |
886 GEN6_PTR_VP_DW0_CC_CHANGED |
887 (cmd_len - 2);
888
889 cmd_batch_reserve(cmd, cmd_len);
890 cmd_batch_write(cmd, dw0);
891 cmd_batch_write(cmd, clip_pos << 2);
892 cmd_batch_write(cmd, sf_pos << 2);
893 cmd_batch_write(cmd, cc_pos << 2);
894}
895
896static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
897 XGL_UINT scissor_pos)
898{
899 const uint8_t cmd_len = 2;
900 uint32_t dw0;
901
902 CMD_ASSERT(cmd, 6, 6);
903
Chia-I Wu426072d2014-08-26 14:31:55 +0800904 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800905 (cmd_len - 2);
906
907 cmd_batch_reserve(cmd, cmd_len);
908 cmd_batch_write(cmd, dw0);
909 cmd_batch_write(cmd, scissor_pos << 2);
910}
911
Chia-I Wu42a56202014-08-23 16:47:48 +0800912static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
913 XGL_UINT vs_pos,
914 XGL_UINT gs_pos,
915 XGL_UINT ps_pos)
916{
917 const uint8_t cmd_len = 4;
918 uint32_t dw0;
919
920 CMD_ASSERT(cmd, 6, 6);
921
Chia-I Wu426072d2014-08-26 14:31:55 +0800922 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800923 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
924 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
925 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
926 (cmd_len - 2);
927
928 cmd_batch_reserve(cmd, cmd_len);
929 cmd_batch_write(cmd, dw0);
930 cmd_batch_write(cmd, vs_pos << 2);
931 cmd_batch_write(cmd, gs_pos << 2);
932 cmd_batch_write(cmd, ps_pos << 2);
933}
934
Chia-I Wu257e75e2014-08-29 14:06:35 +0800935static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
936 XGL_UINT vs_pos,
937 XGL_UINT gs_pos,
938 XGL_UINT ps_pos)
939{
940 const uint8_t cmd_len = 4;
941 uint32_t dw0;
942
943 CMD_ASSERT(cmd, 6, 6);
944
945 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
946 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
947 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
948 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
949 (cmd_len - 2);
950
951 cmd_batch_reserve(cmd, cmd_len);
952 cmd_batch_write(cmd, dw0);
953 cmd_batch_write(cmd, vs_pos << 2);
954 cmd_batch_write(cmd, gs_pos << 2);
955 cmd_batch_write(cmd, ps_pos << 2);
956}
957
Chia-I Wu302742d2014-08-22 10:28:29 +0800958static void gen7_3dstate_pointer(struct intel_cmd *cmd,
959 int subop, XGL_UINT pos)
960{
961 const uint8_t cmd_len = 2;
962 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
963 GEN6_RENDER_SUBTYPE_3D |
964 subop | (cmd_len - 2);
965
966 cmd_batch_reserve(cmd, cmd_len);
967 cmd_batch_write(cmd, dw0);
968 cmd_batch_write(cmd, pos << 2);
969}
970
971static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
972 const struct intel_blend_state *state)
973{
974 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
975 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
976
977 CMD_ASSERT(cmd, 6, 7.5);
978 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
979
980 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
981}
982
983static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
984 const struct intel_ds_state *state)
985{
986 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
987 const uint8_t cmd_len = 3;
988
989 CMD_ASSERT(cmd, 6, 7.5);
990 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
991
992 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
993}
994
995static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
996 uint32_t stencil_ref,
997 const uint32_t blend_color[4])
998{
999 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
1000 const uint8_t cmd_len = 6;
1001 XGL_UINT pos;
1002 uint32_t *dw;
1003
1004 CMD_ASSERT(cmd, 6, 7.5);
1005
1006 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
1007 dw[0] = stencil_ref;
1008 dw[1] = 0;
1009 dw[2] = blend_color[0];
1010 dw[3] = blend_color[1];
1011 dw[4] = blend_color[2];
1012 dw[5] = blend_color[3];
1013 cmd_state_advance(cmd, cmd_len);
1014
1015 return pos;
1016}
1017
Chia-I Wu8370b402014-08-29 12:28:37 +08001018static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001019{
Chia-I Wu8370b402014-08-29 12:28:37 +08001020 CMD_ASSERT(cmd, 6, 7.5);
1021
Chia-I Wu707a29e2014-08-27 12:51:47 +08001022 if (!cmd->bind.draw_count)
1023 return;
1024
Chia-I Wu8370b402014-08-29 12:28:37 +08001025 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001026 return;
1027
Chia-I Wu8370b402014-08-29 12:28:37 +08001028 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001029
1030 /*
1031 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1032 *
1033 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1034 * pipe-control with a post-sync op and no write-cache flushes."
1035 *
1036 * The workaround below necessitates this workaround.
1037 */
1038 gen6_PIPE_CONTROL(cmd,
1039 GEN6_PIPE_CONTROL_CS_STALL |
1040 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1041 NULL, 0);
1042
Chia-I Wu8370b402014-08-29 12:28:37 +08001043 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, cmd->scratch_bo, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001044}
1045
Chia-I Wu8370b402014-08-29 12:28:37 +08001046static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001047{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001048 CMD_ASSERT(cmd, 6, 7.5);
1049
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001050 if (!cmd->bind.draw_count)
1051 return;
1052
Chia-I Wu8370b402014-08-29 12:28:37 +08001053 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL, NULL, 0);
1054}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001055
Chia-I Wu8370b402014-08-29 12:28:37 +08001056static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1057{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001058 CMD_ASSERT(cmd, 7, 7.5);
1059
Chia-I Wu8370b402014-08-29 12:28:37 +08001060 if (!cmd->bind.draw_count)
1061 return;
1062
1063 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001064
1065 gen6_PIPE_CONTROL(cmd,
1066 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
1067 cmd->scratch_bo, 0);
1068}
1069
Chia-I Wu8370b402014-08-29 12:28:37 +08001070static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1071{
1072 CMD_ASSERT(cmd, 7, 7.5);
1073
1074 if (!cmd->bind.draw_count)
1075 return;
1076
1077 /*
1078 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1079 *
1080 * "One of the following must also be set (when CS stall is set):
1081 *
1082 * * Render Target Cache Flush Enable ([12] of DW1)
1083 * * Depth Cache Flush Enable ([0] of DW1)
1084 * * Stall at Pixel Scoreboard ([1] of DW1)
1085 * * Depth Stall ([13] of DW1)
1086 * * Post-Sync Operation ([13] of DW1)"
1087 */
1088 gen6_PIPE_CONTROL(cmd,
1089 GEN6_PIPE_CONTROL_CS_STALL |
1090 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1091 NULL, 0);
1092}
1093
1094static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1095{
1096 CMD_ASSERT(cmd, 7, 7.5);
1097
1098 if (!cmd->bind.draw_count)
1099 return;
1100
1101 cmd_wa_gen6_pre_depth_stall_write(cmd);
1102
1103 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
1104}
1105
1106static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1107{
1108 CMD_ASSERT(cmd, 6, 7.5);
1109
1110 if (!cmd->bind.draw_count)
1111 return;
1112
1113 /*
1114 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1115 *
1116 * "Driver must guarentee that all the caches in the depth pipe are
1117 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1118 * requires driver to send a PIPE_CONTROL with a CS stall along with
1119 * a Depth Flush prior to this command."
1120 *
1121 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1122 *
1123 * "Driver must ierarchi that all the caches in the depth pipe are
1124 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1125 * requires driver to send a PIPE_CONTROL with a CS stall along with
1126 * a Depth Flush prior to this command.
1127 */
1128 gen6_PIPE_CONTROL(cmd,
1129 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1130 GEN6_PIPE_CONTROL_CS_STALL,
1131 0, 0);
1132}
1133
1134static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1135{
1136 CMD_ASSERT(cmd, 6, 7.5);
1137
1138 if (!cmd->bind.draw_count)
1139 return;
1140
1141 /*
1142 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1143 *
1144 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1145 * and a post sync operation prior to the group of depth
1146 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1147 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1148 *
1149 * This workaround satifies all the conditions.
1150 */
1151 cmd_wa_gen6_pre_depth_stall_write(cmd);
1152
1153 /*
1154 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1155 *
1156 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1157 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1158 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1159 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1160 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1161 * Depth Flush Bit set, followed by another pipelined depth stall
1162 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1163 * guarantee that the pipeline from WM onwards is already flushed
1164 * (e.g., via a preceding MI_FLUSH)."
1165 */
1166 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
1167 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
1168 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
1169}
1170
Chia-I Wu525c6602014-08-27 10:22:34 +08001171void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1172{
1173 if (!cmd->bind.draw_count)
1174 return;
1175
1176 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1177
Chia-I Wu8370b402014-08-29 12:28:37 +08001178 /*
1179 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1180 *
1181 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1182 * PIPE_CONTROL with any non-zero post-sync-op is required."
1183 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001184 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001185 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001186
Chia-I Wu092279a2014-08-30 19:05:30 +08001187 /*
1188 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1189 *
1190 * "One of the following must also be set (when CS stall is set):
1191 *
1192 * * Render Target Cache Flush Enable ([12] of DW1)
1193 * * Depth Cache Flush Enable ([0] of DW1)
1194 * * Stall at Pixel Scoreboard ([1] of DW1)
1195 * * Depth Stall ([13] of DW1)
1196 * * Post-Sync Operation ([13] of DW1)"
1197 */
1198 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1199 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1200 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1201 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1202 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1203 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1204
Chia-I Wu525c6602014-08-27 10:22:34 +08001205 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0);
1206}
1207
Chia-I Wu302742d2014-08-22 10:28:29 +08001208static void gen6_cc_states(struct intel_cmd *cmd)
1209{
1210 const struct intel_blend_state *blend = cmd->bind.state.blend;
1211 const struct intel_ds_state *ds = cmd->bind.state.ds;
1212 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001213 uint32_t stencil_ref;
1214 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001215
1216 CMD_ASSERT(cmd, 6, 6);
1217
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001218 if (blend) {
1219 blend_pos = gen6_BLEND_STATE(cmd, blend);
1220 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1221 } else {
1222 blend_pos = 0;
1223 memset(blend_color, 0, sizeof(blend_color));
1224 }
1225
1226 if (ds) {
1227 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1228 stencil_ref = ds->cmd_stencil_ref;
1229 } else {
1230 ds_pos = 0;
1231 stencil_ref = 0;
1232 }
1233
1234 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001235
1236 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
1237}
1238
Chia-I Wu1744cca2014-08-22 11:10:17 +08001239static void gen6_viewport_states(struct intel_cmd *cmd)
1240{
1241 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1242 XGL_UINT pos;
1243
1244 if (!viewport)
1245 return;
1246
1247 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1248 viewport->cmd_align);
1249
1250 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
1251 pos + viewport->cmd_clip_offset,
1252 pos,
1253 pos + viewport->cmd_cc_offset);
1254
1255 pos = (viewport->scissor_enable) ?
1256 pos + viewport->cmd_scissor_rect_offset : 0;
1257
1258 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
1259}
1260
Chia-I Wu302742d2014-08-22 10:28:29 +08001261static void gen7_cc_states(struct intel_cmd *cmd)
1262{
1263 const struct intel_blend_state *blend = cmd->bind.state.blend;
1264 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001265 uint32_t stencil_ref;
1266 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001267 XGL_UINT pos;
1268
1269 CMD_ASSERT(cmd, 7, 7.5);
1270
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001271 if (!blend && !ds)
1272 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001273
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001274 if (blend) {
1275 pos = gen6_BLEND_STATE(cmd, blend);
1276 gen7_3dstate_pointer(cmd,
1277 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +08001278
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001279 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1280 } else {
1281 memset(blend_color, 0, sizeof(blend_color));
1282 }
1283
1284 if (ds) {
1285 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1286 gen7_3dstate_pointer(cmd,
1287 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
1288 } else {
1289 stencil_ref = 0;
1290 }
1291
1292 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001293 gen7_3dstate_pointer(cmd,
1294 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
1295}
1296
Chia-I Wu1744cca2014-08-22 11:10:17 +08001297static void gen7_viewport_states(struct intel_cmd *cmd)
1298{
1299 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1300 XGL_UINT pos;
1301
1302 if (!viewport)
1303 return;
1304
1305 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1306 viewport->cmd_align);
1307
1308 gen7_3dstate_pointer(cmd,
1309 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
1310 gen7_3dstate_pointer(cmd,
1311 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
1312 pos + viewport->cmd_cc_offset);
1313 if (viewport->scissor_enable) {
1314 gen7_3dstate_pointer(cmd,
1315 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1316 pos + viewport->cmd_scissor_rect_offset);
1317 }
1318}
1319
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001320static void gen6_pcb(struct intel_cmd *cmd, int subop,
1321 const XGL_PIPELINE_SHADER *sh)
1322{
1323 const uint8_t cmd_len = 5;
1324 const XGL_UINT alignment = 32;
1325 const XGL_UINT max_size =
1326 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
1327 const XGL_UINT max_pcb = 4;
1328 uint32_t pcb[4] = { 0, 0, 0, 0 };
1329 XGL_FLAGS pcb_enables = 0;
1330 XGL_SIZE total_size = 0;
1331 uint32_t dw0;
1332 XGL_UINT i;
1333
1334 for (i = 0; i < sh->linkConstBufferCount; i++) {
1335 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1336 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1337 void *ptr;
1338
1339 if (info->bufferId >= max_pcb ||
1340 pcb_enables & ((1 << info->bufferId)) ||
1341 total_size + info->bufferSize > max_size) {
1342 cmd->result = XGL_ERROR_UNKNOWN;
1343 return;
1344 }
1345 if (!size)
1346 continue;
1347
1348 pcb_enables |= 1 << info->bufferId;
1349 total_size += size;
1350
1351 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1352 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1353 memcpy(ptr, info->pBufferData, info->bufferSize);
1354 cmd_state_advance(cmd, size / sizeof(uint32_t));
1355
1356 pcb[info->bufferId] |= size / alignment - 1;
1357 }
1358
1359 dw0 = GEN6_RENDER_TYPE_RENDER |
1360 GEN6_RENDER_SUBTYPE_3D |
1361 subop |
1362 pcb_enables << 12 |
1363 (cmd_len - 2);
1364
1365 cmd_batch_reserve(cmd, cmd_len);
1366 cmd_batch_write(cmd, dw0);
1367 cmd_batch_write(cmd, pcb[0]);
1368 cmd_batch_write(cmd, pcb[1]);
1369 cmd_batch_write(cmd, pcb[2]);
1370 cmd_batch_write(cmd, pcb[3]);
1371}
1372
1373static void gen7_pcb(struct intel_cmd *cmd, int subop,
1374 const XGL_PIPELINE_SHADER *sh)
1375{
1376 const uint8_t cmd_len = 7;
1377 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1378 GEN6_RENDER_SUBTYPE_3D |
1379 subop |
1380 (cmd_len - 2);
1381 const XGL_UINT alignment = 32;
1382 const XGL_UINT max_size = 2048;
1383 const XGL_UINT max_pcb = 4;
1384 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
1385 uint32_t pcb[4] = { 0, 0, 0, 0 };
1386 XGL_FLAGS pcb_enables = 0;
1387 XGL_SIZE total_size = 0;
1388 XGL_UINT i;
1389
1390 for (i = 0; i < sh->linkConstBufferCount; i++) {
1391 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1392 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1393 void *ptr;
1394
1395 if (info->bufferId >= max_pcb ||
1396 pcb_enables & ((1 << info->bufferId)) ||
1397 total_size + info->bufferSize > max_size) {
1398 cmd->result = XGL_ERROR_UNKNOWN;
1399 return;
1400 }
1401 if (!size)
1402 continue;
1403
1404 pcb_enables |= 1 << info->bufferId;
1405 total_size += size;
1406
1407 pcb_len[info->bufferId] = size / alignment;
1408
1409 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1410 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1411 memcpy(ptr, info->pBufferData, info->bufferSize);
1412 cmd_state_advance(cmd, size / sizeof(uint32_t));
1413 }
1414
1415 /* no holes */
1416 if (!u_is_pow2(pcb_enables + 1)) {
1417 cmd->result = XGL_ERROR_UNKNOWN;
1418 return;
1419 }
1420
1421 cmd_batch_reserve(cmd, cmd_len);
1422 cmd_batch_write(cmd, dw0);
1423 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
1424 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
1425 cmd_batch_write(cmd, pcb[0]);
1426 cmd_batch_write(cmd, pcb[1]);
1427 cmd_batch_write(cmd, pcb[2]);
1428 cmd_batch_write(cmd, pcb[3]);
1429}
1430
Chia-I Wu42a56202014-08-23 16:47:48 +08001431static void emit_ps_resources(struct intel_cmd *cmd,
1432 const struct intel_rmap *rmap)
1433{
1434 const XGL_UINT surface_count = rmap->rt_count +
1435 rmap->resource_count + rmap->uav_count;
1436 uint32_t binding_table[256];
1437 XGL_UINT pos, i;
1438
1439 assert(surface_count <= ARRAY_SIZE(binding_table));
1440
1441 for (i = 0; i < surface_count; i++) {
1442 const struct intel_rmap_slot *slot = &rmap->slots[i];
1443 uint32_t *dw;
1444
1445 switch (slot->path_len) {
1446 case 0:
1447 pos = 0;
1448 break;
1449 case INTEL_RMAP_SLOT_RT:
1450 {
1451 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1452
1453 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1454 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1455
1456 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001457 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001458 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001459 cmd_state_advance(cmd, view->cmd_len);
1460 }
1461 break;
1462 case INTEL_RMAP_SLOT_DYN:
1463 {
1464 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001465 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001466
1467 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1468 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1469
1470 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001471 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001472 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001473 cmd_state_advance(cmd, view->cmd_len);
1474 }
1475 break;
1476 case 1:
1477 default:
1478 /* TODO */
1479 assert(!"no dset support");
1480 break;
1481 }
1482
1483 binding_table[i] = pos << 2;
1484 }
1485
1486 pos = cmd_state_copy(cmd, binding_table, surface_count,
1487 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
1488
1489 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1490 gen7_3dstate_pointer(cmd,
1491 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001492
1493 gen7_3dstate_pointer(cmd,
1494 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1495 gen7_3dstate_pointer(cmd,
1496 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1497 gen7_3dstate_pointer(cmd,
1498 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1499 gen7_3dstate_pointer(cmd,
1500 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1501
1502 gen7_3dstate_pointer(cmd,
1503 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1504 gen7_3dstate_pointer(cmd,
1505 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1506 gen7_3dstate_pointer(cmd,
1507 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1508 gen7_3dstate_pointer(cmd,
1509 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1510 gen7_3dstate_pointer(cmd,
1511 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001512 } else {
1513 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001514 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001515 }
1516}
1517
Chia-I Wu52500102014-08-22 00:46:04 +08001518static void emit_bounded_states(struct intel_cmd *cmd)
1519{
1520 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1521
1522 /* TODO more states */
1523
Chia-I Wu1744cca2014-08-22 11:10:17 +08001524 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001525 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001526 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001527
1528 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1529 &cmd->bind.pipeline.graphics->vs);
1530 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1531 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001532
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001533 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001534 gen7_3DSTATE_SF(cmd);
1535 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001536 gen7_3DSTATE_WM(cmd);
1537 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001538 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001539 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001540 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001541
1542 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1543 &cmd->bind.pipeline.graphics->vs);
1544 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1545 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001546
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001547 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001548 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001549 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001550 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001551
Chia-I Wu42a56202014-08-23 16:47:48 +08001552 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1553
Chia-I Wu8370b402014-08-29 12:28:37 +08001554 cmd_wa_gen6_pre_depth_stall_write(cmd);
1555 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001556 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001557 cmd_batch_reserve(cmd, msaa->cmd_len);
1558 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001559}
1560
1561static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001562 const struct intel_pipe_shader *shader,
1563 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001564{
1565 uint32_t i;
1566 struct intel_cmd_shader *cmdShader;
1567
1568 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001569 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001570 /* shader is already part of pipeline */
1571 return;
1572 }
1573 }
1574
Chia-I Wu338fe642014-08-28 10:43:04 +08001575 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1576 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1577
1578 cmdShader = cmd->bind.shaderCache.shaderArray;
1579
1580 cmd->bind.shaderCache.shaderArray =
1581 icd_alloc(sizeof(*cmdShader) * new_count,
1582 0, XGL_SYSTEM_ALLOC_INTERNAL);
1583 if (cmd->bind.shaderCache.shaderArray == NULL) {
1584 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001585 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1586 return;
1587 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001588
1589 if (cmdShader) {
1590 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1591 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1592 icd_free(cmdShader);
1593 }
1594
1595 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001596 }
1597
Chia-I Wu338fe642014-08-28 10:43:04 +08001598 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001599 cmdShader->shader = shader;
1600 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001601 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001602 cmd->bind.shaderCache.used++;
1603 return;
1604}
1605
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001606static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001607 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001608{
1609 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001610
Chia-I Wu8370b402014-08-29 12:28:37 +08001611 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1612 cmd_wa_gen6_pre_depth_stall_write(cmd);
1613 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1614 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1615 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1616 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001617
1618 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001619 assert(pipeline->cmd_len);
Chia-I Wub08727d2014-08-29 14:54:54 +08001620 cmd_batch_reserve(cmd, pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001621 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001622
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001623 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001624 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001625 }
1626 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001627 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001628 }
1629 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001630 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001631 }
1632 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001633 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001634 }
1635 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001636 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001637 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001638
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001639 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1640 gen7_3DSTATE_GS(cmd);
1641 } else {
1642 gen6_3DSTATE_GS(cmd);
1643 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001644
Chia-I Wu8370b402014-08-29 12:28:37 +08001645 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1646 cmd_wa_gen7_post_command_cs_stall(cmd);
1647 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1648 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001649}
1650
1651static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1652 const struct intel_pipeline *pipeline)
1653{
1654 cmd->bind.pipeline.compute = pipeline;
1655}
1656
1657static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1658 const struct intel_pipeline_delta *delta)
1659{
1660 cmd->bind.pipeline.graphics_delta = delta;
1661}
1662
1663static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1664 const struct intel_pipeline_delta *delta)
1665{
1666 cmd->bind.pipeline.compute_delta = delta;
1667}
1668
1669static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1670 const struct intel_dset *dset,
1671 XGL_UINT slot_offset)
1672{
1673 cmd->bind.dset.graphics = dset;
1674 cmd->bind.dset.graphics_offset = slot_offset;
1675}
1676
1677static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1678 const struct intel_dset *dset,
1679 XGL_UINT slot_offset)
1680{
1681 cmd->bind.dset.compute = dset;
1682 cmd->bind.dset.compute_offset = slot_offset;
1683}
1684
1685static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1686 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1687{
1688 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1689}
1690
1691static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1692 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1693{
1694 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1695}
1696
1697static void cmd_bind_index_data(struct intel_cmd *cmd,
1698 const struct intel_mem *mem,
1699 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1700{
1701 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1702 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1703 } else {
1704 cmd->bind.index.mem = mem;
1705 cmd->bind.index.offset = offset;
1706 cmd->bind.index.type = type;
1707 }
1708}
1709
1710static void cmd_bind_rt(struct intel_cmd *cmd,
1711 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1712 XGL_UINT count)
1713{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001714 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001715 XGL_UINT i;
1716
1717 for (i = 0; i < count; i++) {
1718 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1719 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001720 const struct intel_layout *layout = &rt->img->layout;
1721
1722 if (i == 0) {
1723 width = layout->width0;
1724 height = layout->height0;
1725 } else {
1726 if (width > layout->width0)
1727 width = layout->width0;
1728 if (height > layout->height0)
1729 height = layout->height0;
1730 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001731
1732 cmd->bind.att.rt[i] = rt;
1733 }
1734
1735 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001736
Chia-I Wu8370b402014-08-29 12:28:37 +08001737 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001738 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001739}
1740
1741static void cmd_bind_ds(struct intel_cmd *cmd,
1742 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1743{
1744 const struct intel_ds_view *ds;
1745
1746 if (info) {
1747 cmd->bind.att.ds = intel_ds_view(info->view);
1748 ds = cmd->bind.att.ds;
1749 } else {
1750 /* all zeros */
1751 static const struct intel_ds_view null_ds;
1752 ds = &null_ds;
1753 }
1754
Chia-I Wu8370b402014-08-29 12:28:37 +08001755 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001756 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1757 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1758 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001759
1760 if (cmd_gen(cmd) >= INTEL_GEN(7))
1761 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1762 else
1763 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001764}
1765
1766static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1767 const struct intel_viewport_state *state)
1768{
1769 cmd->bind.state.viewport = state;
1770}
1771
1772static void cmd_bind_raster_state(struct intel_cmd *cmd,
1773 const struct intel_raster_state *state)
1774{
1775 cmd->bind.state.raster = state;
1776}
1777
1778static void cmd_bind_ds_state(struct intel_cmd *cmd,
1779 const struct intel_ds_state *state)
1780{
1781 cmd->bind.state.ds = state;
1782}
1783
1784static void cmd_bind_blend_state(struct intel_cmd *cmd,
1785 const struct intel_blend_state *state)
1786{
1787 cmd->bind.state.blend = state;
1788}
1789
1790static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1791 const struct intel_msaa_state *state)
1792{
1793 cmd->bind.state.msaa = state;
1794}
1795
1796static void cmd_draw(struct intel_cmd *cmd,
1797 XGL_UINT vertex_start,
1798 XGL_UINT vertex_count,
1799 XGL_UINT instance_start,
1800 XGL_UINT instance_count,
1801 bool indexed,
1802 XGL_UINT vertex_base)
1803{
1804 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1805
1806 emit_bounded_states(cmd);
1807
1808 if (indexed) {
1809 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1810 cmd->result = XGL_ERROR_UNKNOWN;
1811
1812 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1813 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1814 p->primitive_restart_index);
1815 } else {
1816 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1817 cmd->bind.index.offset, cmd->bind.index.type,
1818 p->primitive_restart);
1819 }
1820 } else {
1821 assert(!vertex_base);
1822 }
1823
1824 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1825 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1826 vertex_start, instance_count, instance_start, vertex_base);
1827 } else {
1828 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1829 vertex_start, instance_count, instance_start, vertex_base);
1830 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001831
Chia-I Wu707a29e2014-08-27 12:51:47 +08001832 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001833 /* need to re-emit all workarounds */
1834 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001835}
1836
Chia-I Wub2755562014-08-20 13:38:52 +08001837XGL_VOID XGLAPI intelCmdBindPipeline(
1838 XGL_CMD_BUFFER cmdBuffer,
1839 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1840 XGL_PIPELINE pipeline)
1841{
1842 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1843
1844 switch (pipelineBindPoint) {
1845 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001846 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001847 break;
1848 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001849 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001850 break;
1851 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001852 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001853 break;
1854 }
1855}
1856
1857XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1858 XGL_CMD_BUFFER cmdBuffer,
1859 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1860 XGL_PIPELINE_DELTA delta)
1861{
1862 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1863
1864 switch (pipelineBindPoint) {
1865 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001866 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001867 break;
1868 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001869 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001870 break;
1871 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001872 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001873 break;
1874 }
1875}
1876
1877XGL_VOID XGLAPI intelCmdBindStateObject(
1878 XGL_CMD_BUFFER cmdBuffer,
1879 XGL_STATE_BIND_POINT stateBindPoint,
1880 XGL_STATE_OBJECT state)
1881{
1882 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1883
1884 switch (stateBindPoint) {
1885 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001886 cmd_bind_viewport_state(cmd,
1887 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001888 break;
1889 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001890 cmd_bind_raster_state(cmd,
1891 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001892 break;
1893 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001894 cmd_bind_ds_state(cmd,
1895 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001896 break;
1897 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001898 cmd_bind_blend_state(cmd,
1899 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001900 break;
1901 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001902 cmd_bind_msaa_state(cmd,
1903 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001904 break;
1905 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001906 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001907 break;
1908 }
1909}
1910
1911XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1912 XGL_CMD_BUFFER cmdBuffer,
1913 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1914 XGL_UINT index,
1915 XGL_DESCRIPTOR_SET descriptorSet,
1916 XGL_UINT slotOffset)
1917{
1918 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1919 struct intel_dset *dset = intel_dset(descriptorSet);
1920
1921 assert(!index);
1922
1923 switch (pipelineBindPoint) {
1924 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001925 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001926 break;
1927 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001928 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001929 break;
1930 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001931 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001932 break;
1933 }
1934}
1935
1936XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1937 XGL_CMD_BUFFER cmdBuffer,
1938 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1939 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1940{
1941 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1942
1943 switch (pipelineBindPoint) {
1944 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001945 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001946 break;
1947 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001948 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001949 break;
1950 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001951 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001952 break;
1953 }
1954}
1955
1956XGL_VOID XGLAPI intelCmdBindIndexData(
1957 XGL_CMD_BUFFER cmdBuffer,
1958 XGL_GPU_MEMORY mem_,
1959 XGL_GPU_SIZE offset,
1960 XGL_INDEX_TYPE indexType)
1961{
1962 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1963 struct intel_mem *mem = intel_mem(mem_);
1964
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001965 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001966}
1967
1968XGL_VOID XGLAPI intelCmdBindAttachments(
1969 XGL_CMD_BUFFER cmdBuffer,
1970 XGL_UINT colorAttachmentCount,
1971 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1972 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1973{
1974 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001975
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001976 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1977 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001978}
1979
1980XGL_VOID XGLAPI intelCmdDraw(
1981 XGL_CMD_BUFFER cmdBuffer,
1982 XGL_UINT firstVertex,
1983 XGL_UINT vertexCount,
1984 XGL_UINT firstInstance,
1985 XGL_UINT instanceCount)
1986{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001987 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001988
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001989 cmd_draw(cmd, firstVertex, vertexCount,
1990 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08001991}
1992
1993XGL_VOID XGLAPI intelCmdDrawIndexed(
1994 XGL_CMD_BUFFER cmdBuffer,
1995 XGL_UINT firstIndex,
1996 XGL_UINT indexCount,
1997 XGL_INT vertexOffset,
1998 XGL_UINT firstInstance,
1999 XGL_UINT instanceCount)
2000{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002001 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002002
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002003 cmd_draw(cmd, firstIndex, indexCount,
2004 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002005}
2006
2007XGL_VOID XGLAPI intelCmdDrawIndirect(
2008 XGL_CMD_BUFFER cmdBuffer,
2009 XGL_GPU_MEMORY mem,
2010 XGL_GPU_SIZE offset,
2011 XGL_UINT32 count,
2012 XGL_UINT32 stride)
2013{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002014 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2015
2016 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002017}
2018
2019XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2020 XGL_CMD_BUFFER cmdBuffer,
2021 XGL_GPU_MEMORY mem,
2022 XGL_GPU_SIZE offset,
2023 XGL_UINT32 count,
2024 XGL_UINT32 stride)
2025{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002026 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2027
2028 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002029}
2030
2031XGL_VOID XGLAPI intelCmdDispatch(
2032 XGL_CMD_BUFFER cmdBuffer,
2033 XGL_UINT x,
2034 XGL_UINT y,
2035 XGL_UINT z)
2036{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002037 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2038
2039 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002040}
2041
2042XGL_VOID XGLAPI intelCmdDispatchIndirect(
2043 XGL_CMD_BUFFER cmdBuffer,
2044 XGL_GPU_MEMORY mem,
2045 XGL_GPU_SIZE offset)
2046{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002047 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2048
2049 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002050}