blob: 2cd79aabd5aa85b09a666a041da0a31cdceb1386 [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
1187 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0);
1188}
1189
Chia-I Wu302742d2014-08-22 10:28:29 +08001190static void gen6_cc_states(struct intel_cmd *cmd)
1191{
1192 const struct intel_blend_state *blend = cmd->bind.state.blend;
1193 const struct intel_ds_state *ds = cmd->bind.state.ds;
1194 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001195 uint32_t stencil_ref;
1196 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001197
1198 CMD_ASSERT(cmd, 6, 6);
1199
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001200 if (blend) {
1201 blend_pos = gen6_BLEND_STATE(cmd, blend);
1202 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1203 } else {
1204 blend_pos = 0;
1205 memset(blend_color, 0, sizeof(blend_color));
1206 }
1207
1208 if (ds) {
1209 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1210 stencil_ref = ds->cmd_stencil_ref;
1211 } else {
1212 ds_pos = 0;
1213 stencil_ref = 0;
1214 }
1215
1216 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001217
1218 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
1219}
1220
Chia-I Wu1744cca2014-08-22 11:10:17 +08001221static void gen6_viewport_states(struct intel_cmd *cmd)
1222{
1223 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1224 XGL_UINT pos;
1225
1226 if (!viewport)
1227 return;
1228
1229 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1230 viewport->cmd_align);
1231
1232 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
1233 pos + viewport->cmd_clip_offset,
1234 pos,
1235 pos + viewport->cmd_cc_offset);
1236
1237 pos = (viewport->scissor_enable) ?
1238 pos + viewport->cmd_scissor_rect_offset : 0;
1239
1240 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
1241}
1242
Chia-I Wu302742d2014-08-22 10:28:29 +08001243static void gen7_cc_states(struct intel_cmd *cmd)
1244{
1245 const struct intel_blend_state *blend = cmd->bind.state.blend;
1246 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001247 uint32_t stencil_ref;
1248 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001249 XGL_UINT pos;
1250
1251 CMD_ASSERT(cmd, 7, 7.5);
1252
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001253 if (!blend && !ds)
1254 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001255
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001256 if (blend) {
1257 pos = gen6_BLEND_STATE(cmd, blend);
1258 gen7_3dstate_pointer(cmd,
1259 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +08001260
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001261 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1262 } else {
1263 memset(blend_color, 0, sizeof(blend_color));
1264 }
1265
1266 if (ds) {
1267 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1268 gen7_3dstate_pointer(cmd,
1269 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
1270 } else {
1271 stencil_ref = 0;
1272 }
1273
1274 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001275 gen7_3dstate_pointer(cmd,
1276 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
1277}
1278
Chia-I Wu1744cca2014-08-22 11:10:17 +08001279static void gen7_viewport_states(struct intel_cmd *cmd)
1280{
1281 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1282 XGL_UINT pos;
1283
1284 if (!viewport)
1285 return;
1286
1287 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1288 viewport->cmd_align);
1289
1290 gen7_3dstate_pointer(cmd,
1291 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
1292 gen7_3dstate_pointer(cmd,
1293 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
1294 pos + viewport->cmd_cc_offset);
1295 if (viewport->scissor_enable) {
1296 gen7_3dstate_pointer(cmd,
1297 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1298 pos + viewport->cmd_scissor_rect_offset);
1299 }
1300}
1301
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001302static void gen6_pcb(struct intel_cmd *cmd, int subop,
1303 const XGL_PIPELINE_SHADER *sh)
1304{
1305 const uint8_t cmd_len = 5;
1306 const XGL_UINT alignment = 32;
1307 const XGL_UINT max_size =
1308 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
1309 const XGL_UINT max_pcb = 4;
1310 uint32_t pcb[4] = { 0, 0, 0, 0 };
1311 XGL_FLAGS pcb_enables = 0;
1312 XGL_SIZE total_size = 0;
1313 uint32_t dw0;
1314 XGL_UINT i;
1315
1316 for (i = 0; i < sh->linkConstBufferCount; i++) {
1317 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1318 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1319 void *ptr;
1320
1321 if (info->bufferId >= max_pcb ||
1322 pcb_enables & ((1 << info->bufferId)) ||
1323 total_size + info->bufferSize > max_size) {
1324 cmd->result = XGL_ERROR_UNKNOWN;
1325 return;
1326 }
1327 if (!size)
1328 continue;
1329
1330 pcb_enables |= 1 << info->bufferId;
1331 total_size += size;
1332
1333 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1334 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1335 memcpy(ptr, info->pBufferData, info->bufferSize);
1336 cmd_state_advance(cmd, size / sizeof(uint32_t));
1337
1338 pcb[info->bufferId] |= size / alignment - 1;
1339 }
1340
1341 dw0 = GEN6_RENDER_TYPE_RENDER |
1342 GEN6_RENDER_SUBTYPE_3D |
1343 subop |
1344 pcb_enables << 12 |
1345 (cmd_len - 2);
1346
1347 cmd_batch_reserve(cmd, cmd_len);
1348 cmd_batch_write(cmd, dw0);
1349 cmd_batch_write(cmd, pcb[0]);
1350 cmd_batch_write(cmd, pcb[1]);
1351 cmd_batch_write(cmd, pcb[2]);
1352 cmd_batch_write(cmd, pcb[3]);
1353}
1354
1355static void gen7_pcb(struct intel_cmd *cmd, int subop,
1356 const XGL_PIPELINE_SHADER *sh)
1357{
1358 const uint8_t cmd_len = 7;
1359 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1360 GEN6_RENDER_SUBTYPE_3D |
1361 subop |
1362 (cmd_len - 2);
1363 const XGL_UINT alignment = 32;
1364 const XGL_UINT max_size = 2048;
1365 const XGL_UINT max_pcb = 4;
1366 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
1367 uint32_t pcb[4] = { 0, 0, 0, 0 };
1368 XGL_FLAGS pcb_enables = 0;
1369 XGL_SIZE total_size = 0;
1370 XGL_UINT i;
1371
1372 for (i = 0; i < sh->linkConstBufferCount; i++) {
1373 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1374 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1375 void *ptr;
1376
1377 if (info->bufferId >= max_pcb ||
1378 pcb_enables & ((1 << info->bufferId)) ||
1379 total_size + info->bufferSize > max_size) {
1380 cmd->result = XGL_ERROR_UNKNOWN;
1381 return;
1382 }
1383 if (!size)
1384 continue;
1385
1386 pcb_enables |= 1 << info->bufferId;
1387 total_size += size;
1388
1389 pcb_len[info->bufferId] = size / alignment;
1390
1391 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1392 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1393 memcpy(ptr, info->pBufferData, info->bufferSize);
1394 cmd_state_advance(cmd, size / sizeof(uint32_t));
1395 }
1396
1397 /* no holes */
1398 if (!u_is_pow2(pcb_enables + 1)) {
1399 cmd->result = XGL_ERROR_UNKNOWN;
1400 return;
1401 }
1402
1403 cmd_batch_reserve(cmd, cmd_len);
1404 cmd_batch_write(cmd, dw0);
1405 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
1406 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
1407 cmd_batch_write(cmd, pcb[0]);
1408 cmd_batch_write(cmd, pcb[1]);
1409 cmd_batch_write(cmd, pcb[2]);
1410 cmd_batch_write(cmd, pcb[3]);
1411}
1412
Chia-I Wu42a56202014-08-23 16:47:48 +08001413static void emit_ps_resources(struct intel_cmd *cmd,
1414 const struct intel_rmap *rmap)
1415{
1416 const XGL_UINT surface_count = rmap->rt_count +
1417 rmap->resource_count + rmap->uav_count;
1418 uint32_t binding_table[256];
1419 XGL_UINT pos, i;
1420
1421 assert(surface_count <= ARRAY_SIZE(binding_table));
1422
1423 for (i = 0; i < surface_count; i++) {
1424 const struct intel_rmap_slot *slot = &rmap->slots[i];
1425 uint32_t *dw;
1426
1427 switch (slot->path_len) {
1428 case 0:
1429 pos = 0;
1430 break;
1431 case INTEL_RMAP_SLOT_RT:
1432 {
1433 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1434
1435 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1436 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1437
1438 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001439 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001440 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001441 cmd_state_advance(cmd, view->cmd_len);
1442 }
1443 break;
1444 case INTEL_RMAP_SLOT_DYN:
1445 {
1446 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001447 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001448
1449 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1450 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1451
1452 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001453 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001454 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001455 cmd_state_advance(cmd, view->cmd_len);
1456 }
1457 break;
1458 case 1:
1459 default:
1460 /* TODO */
1461 assert(!"no dset support");
1462 break;
1463 }
1464
1465 binding_table[i] = pos << 2;
1466 }
1467
1468 pos = cmd_state_copy(cmd, binding_table, surface_count,
1469 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
1470
1471 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1472 gen7_3dstate_pointer(cmd,
1473 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001474
1475 gen7_3dstate_pointer(cmd,
1476 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1477 gen7_3dstate_pointer(cmd,
1478 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1479 gen7_3dstate_pointer(cmd,
1480 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1481 gen7_3dstate_pointer(cmd,
1482 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1483
1484 gen7_3dstate_pointer(cmd,
1485 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1486 gen7_3dstate_pointer(cmd,
1487 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1488 gen7_3dstate_pointer(cmd,
1489 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1490 gen7_3dstate_pointer(cmd,
1491 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1492 gen7_3dstate_pointer(cmd,
1493 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001494 } else {
1495 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001496 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001497 }
1498}
1499
Chia-I Wu52500102014-08-22 00:46:04 +08001500static void emit_bounded_states(struct intel_cmd *cmd)
1501{
1502 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1503
1504 /* TODO more states */
1505
Chia-I Wu1744cca2014-08-22 11:10:17 +08001506 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001507 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001508 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001509
1510 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1511 &cmd->bind.pipeline.graphics->vs);
1512 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1513 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001514
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001515 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001516 gen7_3DSTATE_SF(cmd);
1517 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001518 gen7_3DSTATE_WM(cmd);
1519 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001520 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001521 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001522 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001523
1524 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1525 &cmd->bind.pipeline.graphics->vs);
1526 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1527 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001528
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001529 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001530 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001531 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001532 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001533
Chia-I Wu42a56202014-08-23 16:47:48 +08001534 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1535
Chia-I Wu8370b402014-08-29 12:28:37 +08001536 cmd_wa_gen6_pre_depth_stall_write(cmd);
1537 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001538 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001539 cmd_batch_reserve(cmd, msaa->cmd_len);
1540 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001541}
1542
1543static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001544 const struct intel_pipe_shader *shader,
1545 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001546{
1547 uint32_t i;
1548 struct intel_cmd_shader *cmdShader;
1549
1550 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001551 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001552 /* shader is already part of pipeline */
1553 return;
1554 }
1555 }
1556
Chia-I Wu338fe642014-08-28 10:43:04 +08001557 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1558 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1559
1560 cmdShader = cmd->bind.shaderCache.shaderArray;
1561
1562 cmd->bind.shaderCache.shaderArray =
1563 icd_alloc(sizeof(*cmdShader) * new_count,
1564 0, XGL_SYSTEM_ALLOC_INTERNAL);
1565 if (cmd->bind.shaderCache.shaderArray == NULL) {
1566 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001567 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1568 return;
1569 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001570
1571 if (cmdShader) {
1572 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1573 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1574 icd_free(cmdShader);
1575 }
1576
1577 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001578 }
1579
Chia-I Wu338fe642014-08-28 10:43:04 +08001580 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001581 cmdShader->shader = shader;
1582 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001583 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001584 cmd->bind.shaderCache.used++;
1585 return;
1586}
1587
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001588static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001589 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001590{
1591 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001592
Chia-I Wu8370b402014-08-29 12:28:37 +08001593 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1594 cmd_wa_gen6_pre_depth_stall_write(cmd);
1595 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1596 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1597 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1598 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001599
1600 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001601 assert(pipeline->cmd_len);
Chia-I Wub08727d2014-08-29 14:54:54 +08001602 cmd_batch_reserve(cmd, pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001603 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001604
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001605 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001606 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001607 }
1608 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001609 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001610 }
1611 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001612 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001613 }
1614 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001615 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001616 }
1617 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001618 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001619 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001620
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001621 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1622 gen7_3DSTATE_GS(cmd);
1623 } else {
1624 gen6_3DSTATE_GS(cmd);
1625 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001626
Chia-I Wu8370b402014-08-29 12:28:37 +08001627 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1628 cmd_wa_gen7_post_command_cs_stall(cmd);
1629 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1630 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001631}
1632
1633static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1634 const struct intel_pipeline *pipeline)
1635{
1636 cmd->bind.pipeline.compute = pipeline;
1637}
1638
1639static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1640 const struct intel_pipeline_delta *delta)
1641{
1642 cmd->bind.pipeline.graphics_delta = delta;
1643}
1644
1645static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1646 const struct intel_pipeline_delta *delta)
1647{
1648 cmd->bind.pipeline.compute_delta = delta;
1649}
1650
1651static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1652 const struct intel_dset *dset,
1653 XGL_UINT slot_offset)
1654{
1655 cmd->bind.dset.graphics = dset;
1656 cmd->bind.dset.graphics_offset = slot_offset;
1657}
1658
1659static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1660 const struct intel_dset *dset,
1661 XGL_UINT slot_offset)
1662{
1663 cmd->bind.dset.compute = dset;
1664 cmd->bind.dset.compute_offset = slot_offset;
1665}
1666
1667static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1668 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1669{
1670 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1671}
1672
1673static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1674 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1675{
1676 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1677}
1678
1679static void cmd_bind_index_data(struct intel_cmd *cmd,
1680 const struct intel_mem *mem,
1681 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1682{
1683 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1684 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1685 } else {
1686 cmd->bind.index.mem = mem;
1687 cmd->bind.index.offset = offset;
1688 cmd->bind.index.type = type;
1689 }
1690}
1691
1692static void cmd_bind_rt(struct intel_cmd *cmd,
1693 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1694 XGL_UINT count)
1695{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001696 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001697 XGL_UINT i;
1698
1699 for (i = 0; i < count; i++) {
1700 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1701 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001702 const struct intel_layout *layout = &rt->img->layout;
1703
1704 if (i == 0) {
1705 width = layout->width0;
1706 height = layout->height0;
1707 } else {
1708 if (width > layout->width0)
1709 width = layout->width0;
1710 if (height > layout->height0)
1711 height = layout->height0;
1712 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001713
1714 cmd->bind.att.rt[i] = rt;
1715 }
1716
1717 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001718
Chia-I Wu8370b402014-08-29 12:28:37 +08001719 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001720 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001721}
1722
1723static void cmd_bind_ds(struct intel_cmd *cmd,
1724 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1725{
1726 const struct intel_ds_view *ds;
1727
1728 if (info) {
1729 cmd->bind.att.ds = intel_ds_view(info->view);
1730 ds = cmd->bind.att.ds;
1731 } else {
1732 /* all zeros */
1733 static const struct intel_ds_view null_ds;
1734 ds = &null_ds;
1735 }
1736
Chia-I Wu8370b402014-08-29 12:28:37 +08001737 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001738 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1739 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1740 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001741
1742 if (cmd_gen(cmd) >= INTEL_GEN(7))
1743 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1744 else
1745 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001746}
1747
1748static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1749 const struct intel_viewport_state *state)
1750{
1751 cmd->bind.state.viewport = state;
1752}
1753
1754static void cmd_bind_raster_state(struct intel_cmd *cmd,
1755 const struct intel_raster_state *state)
1756{
1757 cmd->bind.state.raster = state;
1758}
1759
1760static void cmd_bind_ds_state(struct intel_cmd *cmd,
1761 const struct intel_ds_state *state)
1762{
1763 cmd->bind.state.ds = state;
1764}
1765
1766static void cmd_bind_blend_state(struct intel_cmd *cmd,
1767 const struct intel_blend_state *state)
1768{
1769 cmd->bind.state.blend = state;
1770}
1771
1772static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1773 const struct intel_msaa_state *state)
1774{
1775 cmd->bind.state.msaa = state;
1776}
1777
1778static void cmd_draw(struct intel_cmd *cmd,
1779 XGL_UINT vertex_start,
1780 XGL_UINT vertex_count,
1781 XGL_UINT instance_start,
1782 XGL_UINT instance_count,
1783 bool indexed,
1784 XGL_UINT vertex_base)
1785{
1786 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1787
1788 emit_bounded_states(cmd);
1789
1790 if (indexed) {
1791 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1792 cmd->result = XGL_ERROR_UNKNOWN;
1793
1794 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1795 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1796 p->primitive_restart_index);
1797 } else {
1798 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1799 cmd->bind.index.offset, cmd->bind.index.type,
1800 p->primitive_restart);
1801 }
1802 } else {
1803 assert(!vertex_base);
1804 }
1805
1806 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1807 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1808 vertex_start, instance_count, instance_start, vertex_base);
1809 } else {
1810 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1811 vertex_start, instance_count, instance_start, vertex_base);
1812 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001813
Chia-I Wu707a29e2014-08-27 12:51:47 +08001814 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001815 /* need to re-emit all workarounds */
1816 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001817}
1818
Chia-I Wub2755562014-08-20 13:38:52 +08001819XGL_VOID XGLAPI intelCmdBindPipeline(
1820 XGL_CMD_BUFFER cmdBuffer,
1821 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1822 XGL_PIPELINE pipeline)
1823{
1824 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1825
1826 switch (pipelineBindPoint) {
1827 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001828 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001829 break;
1830 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001831 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001832 break;
1833 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001834 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001835 break;
1836 }
1837}
1838
1839XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1840 XGL_CMD_BUFFER cmdBuffer,
1841 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1842 XGL_PIPELINE_DELTA delta)
1843{
1844 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1845
1846 switch (pipelineBindPoint) {
1847 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001848 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001849 break;
1850 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001851 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001852 break;
1853 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001854 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001855 break;
1856 }
1857}
1858
1859XGL_VOID XGLAPI intelCmdBindStateObject(
1860 XGL_CMD_BUFFER cmdBuffer,
1861 XGL_STATE_BIND_POINT stateBindPoint,
1862 XGL_STATE_OBJECT state)
1863{
1864 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1865
1866 switch (stateBindPoint) {
1867 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001868 cmd_bind_viewport_state(cmd,
1869 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001870 break;
1871 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001872 cmd_bind_raster_state(cmd,
1873 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001874 break;
1875 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001876 cmd_bind_ds_state(cmd,
1877 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001878 break;
1879 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001880 cmd_bind_blend_state(cmd,
1881 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001882 break;
1883 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001884 cmd_bind_msaa_state(cmd,
1885 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001886 break;
1887 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001888 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001889 break;
1890 }
1891}
1892
1893XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1894 XGL_CMD_BUFFER cmdBuffer,
1895 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1896 XGL_UINT index,
1897 XGL_DESCRIPTOR_SET descriptorSet,
1898 XGL_UINT slotOffset)
1899{
1900 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1901 struct intel_dset *dset = intel_dset(descriptorSet);
1902
1903 assert(!index);
1904
1905 switch (pipelineBindPoint) {
1906 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001907 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001908 break;
1909 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001910 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001911 break;
1912 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001913 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001914 break;
1915 }
1916}
1917
1918XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1919 XGL_CMD_BUFFER cmdBuffer,
1920 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1921 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1922{
1923 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1924
1925 switch (pipelineBindPoint) {
1926 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001927 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001928 break;
1929 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001930 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001931 break;
1932 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001933 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001934 break;
1935 }
1936}
1937
1938XGL_VOID XGLAPI intelCmdBindIndexData(
1939 XGL_CMD_BUFFER cmdBuffer,
1940 XGL_GPU_MEMORY mem_,
1941 XGL_GPU_SIZE offset,
1942 XGL_INDEX_TYPE indexType)
1943{
1944 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1945 struct intel_mem *mem = intel_mem(mem_);
1946
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001947 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001948}
1949
1950XGL_VOID XGLAPI intelCmdBindAttachments(
1951 XGL_CMD_BUFFER cmdBuffer,
1952 XGL_UINT colorAttachmentCount,
1953 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1954 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1955{
1956 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001957
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001958 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1959 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001960}
1961
1962XGL_VOID XGLAPI intelCmdDraw(
1963 XGL_CMD_BUFFER cmdBuffer,
1964 XGL_UINT firstVertex,
1965 XGL_UINT vertexCount,
1966 XGL_UINT firstInstance,
1967 XGL_UINT instanceCount)
1968{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001969 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001970
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001971 cmd_draw(cmd, firstVertex, vertexCount,
1972 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08001973}
1974
1975XGL_VOID XGLAPI intelCmdDrawIndexed(
1976 XGL_CMD_BUFFER cmdBuffer,
1977 XGL_UINT firstIndex,
1978 XGL_UINT indexCount,
1979 XGL_INT vertexOffset,
1980 XGL_UINT firstInstance,
1981 XGL_UINT instanceCount)
1982{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001983 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001984
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001985 cmd_draw(cmd, firstIndex, indexCount,
1986 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001987}
1988
1989XGL_VOID XGLAPI intelCmdDrawIndirect(
1990 XGL_CMD_BUFFER cmdBuffer,
1991 XGL_GPU_MEMORY mem,
1992 XGL_GPU_SIZE offset,
1993 XGL_UINT32 count,
1994 XGL_UINT32 stride)
1995{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001996 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1997
1998 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001999}
2000
2001XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2002 XGL_CMD_BUFFER cmdBuffer,
2003 XGL_GPU_MEMORY mem,
2004 XGL_GPU_SIZE offset,
2005 XGL_UINT32 count,
2006 XGL_UINT32 stride)
2007{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002008 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2009
2010 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002011}
2012
2013XGL_VOID XGLAPI intelCmdDispatch(
2014 XGL_CMD_BUFFER cmdBuffer,
2015 XGL_UINT x,
2016 XGL_UINT y,
2017 XGL_UINT z)
2018{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002019 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2020
2021 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002022}
2023
2024XGL_VOID XGLAPI intelCmdDispatchIndirect(
2025 XGL_CMD_BUFFER cmdBuffer,
2026 XGL_GPU_MEMORY mem,
2027 XGL_GPU_SIZE offset)
2028{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002029 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2030
2031 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002032}