blob: 378dc29ac48dad542da4b23edbe1cb850a9a93f1 [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,
Chia-I Wud6d079d2014-08-31 13:14:21 +080094 struct intel_bo *bo, uint32_t bo_offset,
95 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +080096{
97 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +080098 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +080099 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800100 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800101
102 CMD_ASSERT(cmd, 6, 7.5);
103
104 assert(bo_offset % 8 == 0);
105
106 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
107 /*
108 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
109 *
110 * "1 of the following must also be set (when CS stall is set):
111 *
112 * * Depth Cache Flush Enable ([0] of DW1)
113 * * Stall at Pixel Scoreboard ([1] of DW1)
114 * * Depth Stall ([13] of DW1)
115 * * Post-Sync Operation ([13] of DW1)
116 * * Render Target Cache Flush Enable ([12] of DW1)
117 * * Notify Enable ([8] of DW1)"
118 *
119 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
120 *
121 * "One of the following must also be set (when CS stall is set):
122 *
123 * * Render Target Cache Flush Enable ([12] of DW1)
124 * * Depth Cache Flush Enable ([0] of DW1)
125 * * Stall at Pixel Scoreboard ([1] of DW1)
126 * * Depth Stall ([13] of DW1)
127 * * Post-Sync Operation ([13] of DW1)"
128 */
129 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
130 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
131 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
132 GEN6_PIPE_CONTROL_DEPTH_STALL;
133
134 /* post-sync op */
135 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
136 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
137 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
138
139 if (cmd_gen(cmd) == INTEL_GEN(6))
140 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
141
142 assert(dw1 & bit_test);
143 }
144
145 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
146 /*
147 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
148 *
149 * "Following bits must be clear (when Depth Stall is set):
150 *
151 * * Render Target Cache Flush Enable ([12] of DW1)
152 * * Depth Cache Flush Enable ([0] of DW1)"
153 */
154 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
155 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
156 }
157
158 /*
159 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
160 *
161 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
162 * and PIPE_CONTROL are not supported."
163 *
164 * The kernel will add the mapping automatically (when write domain is
165 * INTEL_DOMAIN_INSTRUCTION).
166 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800167 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800168 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800169 reloc_flags |= INTEL_RELOC_GGTT;
170 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800171
172 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) bo);
173 cmd_batch_write(cmd, dw0);
174 cmd_batch_write(cmd, dw1);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800175 if (bo)
176 cmd_batch_reloc(cmd, bo_offset, bo, reloc_flags);
177 else
Chia-I Wu270b1e82014-08-25 15:53:39 +0800178 cmd_batch_write(cmd, 0);
Chia-I Wud6d079d2014-08-31 13:14:21 +0800179 cmd_batch_write(cmd, (uint32_t) imm);
180 cmd_batch_write(cmd, (uint32_t) (imm >> 32));
Chia-I Wu270b1e82014-08-25 15:53:39 +0800181}
182
Chia-I Wu254db422014-08-21 11:54:29 +0800183static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
184{
185 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
186 bool supported;
187
188 CMD_ASSERT(cmd, 6, 7.5);
189
190 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
191 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
192
193 switch (p->prim_type) {
194 case GEN6_3DPRIM_POINTLIST:
195 case GEN6_3DPRIM_LINELIST:
196 case GEN6_3DPRIM_LINESTRIP:
197 case GEN6_3DPRIM_TRILIST:
198 case GEN6_3DPRIM_TRISTRIP:
199 supported = true;
200 break;
201 default:
202 supported = false;
203 break;
204 }
205
206 if (!supported)
207 return false;
208
209 switch (cmd->bind.index.type) {
210 case XGL_INDEX_8:
211 supported = (p->primitive_restart_index != 0xffu);
212 break;
213 case XGL_INDEX_16:
214 supported = (p->primitive_restart_index != 0xffffu);
215 break;
216 case XGL_INDEX_32:
217 supported = (p->primitive_restart_index != 0xffffffffu);
218 break;
219 default:
220 supported = false;
221 break;
222 }
223
224 return supported;
225}
226
Chia-I Wu59c097e2014-08-21 10:51:07 +0800227static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800228 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800229 XGL_GPU_SIZE offset,
230 XGL_INDEX_TYPE type,
231 bool enable_cut_index)
232{
233 const uint8_t cmd_len = 3;
234 uint32_t dw0, end_offset;
235 unsigned offset_align;
236
237 CMD_ASSERT(cmd, 6, 7.5);
238
Chia-I Wu426072d2014-08-26 14:31:55 +0800239 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800240
241 /* the bit is moved to 3DSTATE_VF */
242 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
243 assert(!enable_cut_index);
244 if (enable_cut_index)
245 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
246
247 switch (type) {
248 case XGL_INDEX_8:
249 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
250 offset_align = 1;
251 break;
252 case XGL_INDEX_16:
253 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
254 offset_align = 2;
255 break;
256 case XGL_INDEX_32:
257 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
258 offset_align = 4;
259 break;
260 default:
261 cmd->result = XGL_ERROR_INVALID_VALUE;
262 return;
263 break;
264 }
265
266 if (offset % offset_align) {
267 cmd->result = XGL_ERROR_INVALID_VALUE;
268 return;
269 }
270
271 /* aligned and inclusive */
272 end_offset = mem->size - (mem->size % offset_align) - 1;
273
Chia-I Wu2de65d02014-08-25 10:02:53 +0800274 cmd_batch_reserve_reloc(cmd, cmd_len, 2);
Chia-I Wue24c3292014-08-21 14:05:23 +0800275 cmd_batch_write(cmd, dw0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800276 cmd_batch_reloc(cmd, offset, mem->bo, 0);
277 cmd_batch_reloc(cmd, end_offset, mem->bo, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800278}
279
Chia-I Wu62a7f252014-08-29 11:31:16 +0800280static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
281 bool enable_cut_index,
282 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800283{
284 const uint8_t cmd_len = 2;
285 uint32_t dw0;
286
287 CMD_ASSERT(cmd, 7.5, 7.5);
288
Chia-I Wu426072d2014-08-26 14:31:55 +0800289 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800290 if (enable_cut_index)
291 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
292
Chia-I Wue24c3292014-08-21 14:05:23 +0800293 cmd_batch_reserve(cmd, cmd_len);
294 cmd_batch_write(cmd, dw0);
295 cmd_batch_write(cmd, cut_index);
Chia-I Wu254db422014-08-21 11:54:29 +0800296}
297
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800298static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
299{
300 const uint8_t cmd_len = 7;
301 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
302
303 CMD_ASSERT(cmd, 6, 6);
304
305 assert(cmd->bind.gs.shader == NULL);
306
307 cmd_batch_reserve(cmd, cmd_len);
308 cmd_batch_write(cmd, dw0);
309 cmd_batch_write(cmd, 0);
310 cmd_batch_write(cmd, 0);
311 cmd_batch_write(cmd, 0);
312 cmd_batch_write(cmd, 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT);
313 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
314 cmd_batch_write(cmd, 0);
315}
316
Chia-I Wu62a7f252014-08-29 11:31:16 +0800317static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
318{
319 const uint8_t cmd_len = 7;
320 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
321
322 CMD_ASSERT(cmd, 7, 7.5);
323
324 assert(cmd->bind.gs.shader == NULL);
325
326 cmd_batch_reserve(cmd, cmd_len);
327 cmd_batch_write(cmd, dw0);
328 cmd_batch_write(cmd, 0);
329 cmd_batch_write(cmd, 0);
330 cmd_batch_write(cmd, 0);
331 cmd_batch_write(cmd, 0);
332 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
333 cmd_batch_write(cmd, 0);
334}
335
Chia-I Wud88e02d2014-08-25 10:56:13 +0800336static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
337 XGL_UINT width, XGL_UINT height)
338{
339 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800340 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800341 (cmd_len - 2);
342
343 CMD_ASSERT(cmd, 6, 7.5);
344
345 cmd_batch_reserve(cmd, cmd_len);
346 cmd_batch_write(cmd, dw0);
347 if (width && height) {
348 cmd_batch_write(cmd, 0);
349 cmd_batch_write(cmd, (height - 1) << 16 |
350 (width - 1));
351 } else {
352 cmd_batch_write(cmd, 1);
353 cmd_batch_write(cmd, 0);
354 }
355 cmd_batch_write(cmd, 0);
356}
357
Chia-I Wu8016a172014-08-29 18:31:32 +0800358static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
359 uint32_t body[6])
360{
361 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
362 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
363 const struct intel_raster_state *raster = cmd->bind.state.raster;
364 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
365 uint32_t dw1, dw2, dw3;
366 int point_width;
367
368 CMD_ASSERT(cmd, 6, 7.5);
369
370 dw1 = GEN7_SF_DW1_STATISTICS |
371 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
372 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
373 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
374 GEN7_SF_DW1_VIEWPORT_ENABLE |
375 raster->cmd_sf_fill;
376
377 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
378 int format;
379
380 switch (pipeline->db_format.channelFormat) {
381 case XGL_CH_FMT_R16:
382 format = GEN6_ZFORMAT_D16_UNORM;
383 break;
384 case XGL_CH_FMT_R32:
385 case XGL_CH_FMT_R32G8:
386 format = GEN6_ZFORMAT_D32_FLOAT;
387 break;
388 default:
389 assert(!"unknown depth format");
390 format = 0;
391 break;
392 }
393
394 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
395 }
396
397 dw2 = raster->cmd_sf_cull;
398
399 if (msaa->sample_count > 1) {
400 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
401 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
402 } else {
403 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
404 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
405 }
406
407 if (viewport->scissor_enable)
408 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
409
410 /* in U8.3 */
411 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
412 point_width = U_CLAMP(point_width, 1, 2047);
413
414 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
415 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
416 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
417 GEN7_SF_DW3_SUBPIXEL_8BITS |
418 GEN7_SF_DW3_USE_POINT_WIDTH |
419 point_width;
420
421 body[0] = dw1;
422 body[1] = dw2;
423 body[2] = dw3;
424 body[3] = raster->cmd_depth_offset_const;
425 body[4] = raster->cmd_depth_offset_scale;
426 body[5] = raster->cmd_depth_offset_clamp;
427}
428
429static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
430 uint32_t body[13])
431{
432 const struct intel_shader *vs =
433 intel_shader(cmd->bind.pipeline.graphics->vs.shader);
434 const struct intel_shader *fs =
435 intel_shader(cmd->bind.pipeline.graphics->fs.shader);
436 XGL_UINT attr_skip, attr_count;
437 XGL_UINT vue_offset, vue_len;
438 XGL_UINT i;
439 uint32_t dw1;
440
441 CMD_ASSERT(cmd, 6, 7.5);
442
443 /* VS outputs VUE header and position additionally */
444 assert(vs->out_count >= 2);
445 attr_skip = 2;
446 attr_count = vs->out_count - attr_skip;
447 assert(fs->in_count == attr_count);
448 assert(fs->in_count <= 32);
449
450 vue_offset = attr_skip / 2;
451 vue_len = (attr_count + 1) / 2;
452 if (!vue_len)
453 vue_len = 1;
454
455 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
456 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
457 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
458
459 body[0] = dw1;
460
461 for (i = 0; i < 8; i++) {
462 uint16_t hi, lo;
463
464 /* no attr swizzles */
465 if (i * 2 + 1 < fs->in_count) {
466 hi = i * 2 + 1;
467 lo = i * 2;
468 } else if (i * 2 < fs->in_count) {
469 hi = 0;
470 lo = i * 2;
471 } else {
472 hi = 0;
473 lo = 0;
474 }
475
476 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
477 }
478
479 body[9] = 0; /* point sprite enables */
480 body[10] = 0; /* constant interpolation enables */
481 body[11] = 0; /* WrapShortest enables */
482 body[12] = 0;
483}
484
485static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
486{
487 const uint8_t cmd_len = 20;
488 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
489 (cmd_len - 2);
490 uint32_t sf[6];
491 uint32_t sbe[13];
492
493 CMD_ASSERT(cmd, 6, 6);
494
495 gen7_fill_3DSTATE_SF_body(cmd, sf);
496 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
497
498 cmd_batch_reserve(cmd, cmd_len);
499 cmd_batch_write(cmd, dw0);
500 cmd_batch_write(cmd, sbe[0]);
501 cmd_batch_write_n(cmd, sf, 6);
502 cmd_batch_write_n(cmd, &sbe[1], 12);
503}
504
505static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
506{
507 const uint8_t cmd_len = 7;
508 uint32_t dw[7];
509
510 CMD_ASSERT(cmd, 7, 7.5);
511
512 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
513 (cmd_len - 2);
514 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
515
516 cmd_batch_reserve(cmd, cmd_len);
517 cmd_batch_write_n(cmd, dw, cmd_len);
518}
519
520static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
521{
522 const uint8_t cmd_len = 14;
523 uint32_t dw[14];
524
525 CMD_ASSERT(cmd, 7, 7.5);
526
527 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
528 (cmd_len - 2);
529 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
530
531 cmd_batch_reserve(cmd, cmd_len);
532 cmd_batch_write_n(cmd, dw, cmd_len);
533}
534
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800535static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
536{
537 const uint8_t cmd_len = 4;
538 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
539 (cmd_len - 2);
540 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
541 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
542 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
543 const struct intel_raster_state *raster = cmd->bind.state.raster;
544 uint32_t dw1, dw2, dw3;
545
546 CMD_ASSERT(cmd, 6, 7.5);
547
548 dw1 = GEN6_CLIP_DW1_STATISTICS;
549 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
550 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
551 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
552 raster->cmd_clip_cull;
553 }
554
555 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
556 GEN6_CLIP_DW2_XY_TEST_ENABLE |
557 GEN6_CLIP_DW2_APIMODE_OGL |
558 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
559 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
560 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
561
562 if (pipeline->rasterizerDiscardEnable)
563 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
564 else
565 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
566
567 if (pipeline->depthClipEnable)
568 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
569
570 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
571 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
572 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
573 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
574
575 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
576 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
577 (viewport->viewport_count - 1);
578
579 cmd_batch_reserve(cmd, cmd_len);
580 cmd_batch_write(cmd, dw0);
581 cmd_batch_write(cmd, dw1);
582 cmd_batch_write(cmd, dw2);
583 cmd_batch_write(cmd, dw3);
584}
585
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800586static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
587{
588 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
589 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
590 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
591 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
592 const uint8_t cmd_len = 9;
593 uint32_t dw0, dw2, dw4, dw5, dw6;
594
595 CMD_ASSERT(cmd, 6, 6);
596
597 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
598
599 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
600 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
601
602 dw4 = GEN6_WM_DW4_STATISTICS |
603 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
604 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
605 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
606
607 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
608 GEN6_WM_DW5_PS_ENABLE |
609 GEN6_WM_DW5_8_PIXEL_DISPATCH;
610
611 if (fs->uses & INTEL_SHADER_USE_KILL ||
612 pipeline->cb_state.alphaToCoverageEnable)
613 dw5 |= GEN6_WM_DW5_PS_KILL;
614
615 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
616 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
617 if (fs->uses & INTEL_SHADER_USE_DEPTH)
618 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
619 if (fs->uses & INTEL_SHADER_USE_W)
620 dw5 |= GEN6_WM_DW5_PS_USE_W;
621
622 if (pipeline->cb_state.dualSourceBlendEnable)
623 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
624
625 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
626 GEN6_WM_DW6_POSOFFSET_NONE |
627 GEN6_WM_DW6_ZW_INTERP_PIXEL |
628 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
629 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
630
631 if (msaa->sample_count > 1) {
632 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
633 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
634 } else {
635 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
636 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
637 }
638
639 cmd_batch_reserve(cmd, cmd_len);
640 cmd_batch_write(cmd, dw0);
641 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
642 cmd_batch_write(cmd, dw2);
643 cmd_batch_write(cmd, 0); /* scratch */
644 cmd_batch_write(cmd, dw4);
645 cmd_batch_write(cmd, dw5);
646 cmd_batch_write(cmd, dw6);
647 cmd_batch_write(cmd, 0); /* kernel 1 */
648 cmd_batch_write(cmd, 0); /* kernel 2 */
649}
650
651static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
652{
653 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
654 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
655 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
656 const uint8_t cmd_len = 3;
657 uint32_t dw0, dw1, dw2;
658
659 CMD_ASSERT(cmd, 7, 7.5);
660
661 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
662
663 dw1 = GEN7_WM_DW1_STATISTICS |
664 GEN7_WM_DW1_PS_ENABLE |
665 GEN7_WM_DW1_ZW_INTERP_PIXEL |
666 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
667 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
668
669 if (fs->uses & INTEL_SHADER_USE_KILL ||
670 pipeline->cb_state.alphaToCoverageEnable)
671 dw1 |= GEN7_WM_DW1_PS_KILL;
672
673 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
674 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
675 if (fs->uses & INTEL_SHADER_USE_DEPTH)
676 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
677 if (fs->uses & INTEL_SHADER_USE_W)
678 dw1 |= GEN7_WM_DW1_PS_USE_W;
679
680 dw2 = 0;
681
682 if (msaa->sample_count > 1) {
683 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
684 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
685 } else {
686 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
687 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
688 }
689
690 cmd_batch_reserve(cmd, cmd_len);
691 cmd_batch_write(cmd, dw0);
692 cmd_batch_write(cmd, dw1);
693 cmd_batch_write(cmd, dw2);
694}
695
696static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
697{
698 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
699 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
700 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
701 const uint8_t cmd_len = 8;
702 uint32_t dw0, dw2, dw4, dw5;
703
704 CMD_ASSERT(cmd, 7, 7.5);
705
706 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
707
708 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
709 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
710
711 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
712 GEN7_PS_DW4_8_PIXEL_DISPATCH;
713
714 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
715 const int max_threads =
716 (cmd->dev->gpu->gt == 3) ? 408 :
717 (cmd->dev->gpu->gt == 2) ? 204 : 102;
718 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
719 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
720 } else {
721 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
722 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
723 }
724
725 if (pipeline->fs.linkConstBufferCount)
726 dw4 |= GEN7_PS_DW4_PUSH_CONSTANT_ENABLE;
727
728 if (fs->in_count)
729 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
730
731 if (pipeline->cb_state.dualSourceBlendEnable)
732 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
733
734 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
735 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
736 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
737
738 cmd_batch_reserve(cmd, cmd_len);
739 cmd_batch_write(cmd, dw0);
740 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
741 cmd_batch_write(cmd, dw2);
742 cmd_batch_write(cmd, 0); /* scratch */
743 cmd_batch_write(cmd, dw4);
744 cmd_batch_write(cmd, dw5);
745 cmd_batch_write(cmd, 0); /* kernel 1 */
746 cmd_batch_write(cmd, 0); /* kernel 2 */
747}
748
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800749static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
750 const struct intel_ds_view *view)
751{
752 const uint8_t cmd_len = 7;
753 uint32_t dw0;
754
755 CMD_ASSERT(cmd, 6, 7.5);
756
757 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800758 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
759 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800760 dw0 |= (cmd_len - 2);
761
Chia-I Wu2de65d02014-08-25 10:02:53 +0800762 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800763 cmd_batch_write(cmd, dw0);
764 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600765 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800766 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800767 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600768 } else {
769 cmd_batch_write(cmd, 0);
770 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800771 cmd_batch_write(cmd, view->cmd[2]);
772 cmd_batch_write(cmd, view->cmd[3]);
773 cmd_batch_write(cmd, view->cmd[4]);
774 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800775}
776
777static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
778 const struct intel_ds_view *view)
779{
780 const uint8_t cmd_len = 3;
781 uint32_t dw0;
782
783 CMD_ASSERT(cmd, 6, 7.5);
784
785 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800786 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
787 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800788 dw0 |= (cmd_len - 2);
789
Chia-I Wu2de65d02014-08-25 10:02:53 +0800790 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800791 cmd_batch_write(cmd, dw0);
792 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600793 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800794 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800795 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600796 } else {
797 cmd_batch_write(cmd, 0);
798 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800799}
800
801static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
802 const struct intel_ds_view *view)
803{
804 const uint8_t cmd_len = 3;
805 uint32_t dw0;
806
807 CMD_ASSERT(cmd, 6, 7.5);
808
809 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800810 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
811 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800812 dw0 |= (cmd_len - 2);
813
Chia-I Wu2de65d02014-08-25 10:02:53 +0800814 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800815 cmd_batch_write(cmd, dw0);
816 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600817 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800818 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800819 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600820 } else {
821 cmd_batch_write(cmd, 0);
822 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800823}
824
Chia-I Wuf8231032014-08-25 10:44:45 +0800825static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
826 uint32_t clear_val)
827{
828 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800829 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800830 GEN6_CLEAR_PARAMS_DW0_VALID |
831 (cmd_len - 2);
832
833 CMD_ASSERT(cmd, 6, 6);
834
835 cmd_batch_reserve(cmd, cmd_len);
836 cmd_batch_write(cmd, dw0);
837 cmd_batch_write(cmd, clear_val);
838}
839
840static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
841 uint32_t clear_val)
842{
843 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800844 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800845 (cmd_len - 2);
846
847 CMD_ASSERT(cmd, 7, 7.5);
848
849 cmd_batch_reserve(cmd, cmd_len);
850 cmd_batch_write(cmd, dw0);
851 cmd_batch_write(cmd, clear_val);
852 cmd_batch_write(cmd, 1);
853}
854
Chia-I Wu302742d2014-08-22 10:28:29 +0800855static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
856 XGL_UINT blend_pos,
857 XGL_UINT ds_pos,
858 XGL_UINT cc_pos)
859{
860 const uint8_t cmd_len = 4;
861 uint32_t dw0;
862
863 CMD_ASSERT(cmd, 6, 6);
864
Chia-I Wu426072d2014-08-26 14:31:55 +0800865 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800866 (cmd_len - 2);
867
868 cmd_batch_reserve(cmd, cmd_len);
869 cmd_batch_write(cmd, dw0);
870 cmd_batch_write(cmd, (blend_pos << 2) | 1);
871 cmd_batch_write(cmd, (ds_pos << 2) | 1);
872 cmd_batch_write(cmd, (cc_pos << 2) | 1);
873}
874
Chia-I Wu1744cca2014-08-22 11:10:17 +0800875static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
876 XGL_UINT clip_pos,
877 XGL_UINT sf_pos,
878 XGL_UINT cc_pos)
879{
880 const uint8_t cmd_len = 4;
881 uint32_t dw0;
882
883 CMD_ASSERT(cmd, 6, 6);
884
Chia-I Wu426072d2014-08-26 14:31:55 +0800885 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800886 GEN6_PTR_VP_DW0_CLIP_CHANGED |
887 GEN6_PTR_VP_DW0_SF_CHANGED |
888 GEN6_PTR_VP_DW0_CC_CHANGED |
889 (cmd_len - 2);
890
891 cmd_batch_reserve(cmd, cmd_len);
892 cmd_batch_write(cmd, dw0);
893 cmd_batch_write(cmd, clip_pos << 2);
894 cmd_batch_write(cmd, sf_pos << 2);
895 cmd_batch_write(cmd, cc_pos << 2);
896}
897
898static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
899 XGL_UINT scissor_pos)
900{
901 const uint8_t cmd_len = 2;
902 uint32_t dw0;
903
904 CMD_ASSERT(cmd, 6, 6);
905
Chia-I Wu426072d2014-08-26 14:31:55 +0800906 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800907 (cmd_len - 2);
908
909 cmd_batch_reserve(cmd, cmd_len);
910 cmd_batch_write(cmd, dw0);
911 cmd_batch_write(cmd, scissor_pos << 2);
912}
913
Chia-I Wu42a56202014-08-23 16:47:48 +0800914static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
915 XGL_UINT vs_pos,
916 XGL_UINT gs_pos,
917 XGL_UINT ps_pos)
918{
919 const uint8_t cmd_len = 4;
920 uint32_t dw0;
921
922 CMD_ASSERT(cmd, 6, 6);
923
Chia-I Wu426072d2014-08-26 14:31:55 +0800924 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800925 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
926 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
927 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
928 (cmd_len - 2);
929
930 cmd_batch_reserve(cmd, cmd_len);
931 cmd_batch_write(cmd, dw0);
932 cmd_batch_write(cmd, vs_pos << 2);
933 cmd_batch_write(cmd, gs_pos << 2);
934 cmd_batch_write(cmd, ps_pos << 2);
935}
936
Chia-I Wu257e75e2014-08-29 14:06:35 +0800937static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
938 XGL_UINT vs_pos,
939 XGL_UINT gs_pos,
940 XGL_UINT ps_pos)
941{
942 const uint8_t cmd_len = 4;
943 uint32_t dw0;
944
945 CMD_ASSERT(cmd, 6, 6);
946
947 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
948 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
949 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
950 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
951 (cmd_len - 2);
952
953 cmd_batch_reserve(cmd, cmd_len);
954 cmd_batch_write(cmd, dw0);
955 cmd_batch_write(cmd, vs_pos << 2);
956 cmd_batch_write(cmd, gs_pos << 2);
957 cmd_batch_write(cmd, ps_pos << 2);
958}
959
Chia-I Wu302742d2014-08-22 10:28:29 +0800960static void gen7_3dstate_pointer(struct intel_cmd *cmd,
961 int subop, XGL_UINT pos)
962{
963 const uint8_t cmd_len = 2;
964 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
965 GEN6_RENDER_SUBTYPE_3D |
966 subop | (cmd_len - 2);
967
968 cmd_batch_reserve(cmd, cmd_len);
969 cmd_batch_write(cmd, dw0);
970 cmd_batch_write(cmd, pos << 2);
971}
972
973static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
974 const struct intel_blend_state *state)
975{
976 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
977 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
978
979 CMD_ASSERT(cmd, 6, 7.5);
980 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
981
982 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
983}
984
985static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
986 const struct intel_ds_state *state)
987{
988 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
989 const uint8_t cmd_len = 3;
990
991 CMD_ASSERT(cmd, 6, 7.5);
992 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
993
994 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
995}
996
997static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
998 uint32_t stencil_ref,
999 const uint32_t blend_color[4])
1000{
1001 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
1002 const uint8_t cmd_len = 6;
1003 XGL_UINT pos;
1004 uint32_t *dw;
1005
1006 CMD_ASSERT(cmd, 6, 7.5);
1007
1008 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
1009 dw[0] = stencil_ref;
1010 dw[1] = 0;
1011 dw[2] = blend_color[0];
1012 dw[3] = blend_color[1];
1013 dw[4] = blend_color[2];
1014 dw[5] = blend_color[3];
1015 cmd_state_advance(cmd, cmd_len);
1016
1017 return pos;
1018}
1019
Chia-I Wu8370b402014-08-29 12:28:37 +08001020static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001021{
Chia-I Wu8370b402014-08-29 12:28:37 +08001022 CMD_ASSERT(cmd, 6, 7.5);
1023
Chia-I Wu707a29e2014-08-27 12:51:47 +08001024 if (!cmd->bind.draw_count)
1025 return;
1026
Chia-I Wu8370b402014-08-29 12:28:37 +08001027 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001028 return;
1029
Chia-I Wu8370b402014-08-29 12:28:37 +08001030 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001031
1032 /*
1033 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1034 *
1035 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1036 * pipe-control with a post-sync op and no write-cache flushes."
1037 *
1038 * The workaround below necessitates this workaround.
1039 */
1040 gen6_PIPE_CONTROL(cmd,
1041 GEN6_PIPE_CONTROL_CS_STALL |
1042 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001043 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001044
Chia-I Wud6d079d2014-08-31 13:14:21 +08001045 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1046 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001047}
1048
Chia-I Wu8370b402014-08-29 12:28:37 +08001049static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001050{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001051 CMD_ASSERT(cmd, 6, 7.5);
1052
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001053 if (!cmd->bind.draw_count)
1054 return;
1055
Chia-I Wud6d079d2014-08-31 13:14:21 +08001056 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1057 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001058}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001059
Chia-I Wu8370b402014-08-29 12:28:37 +08001060static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1061{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001062 CMD_ASSERT(cmd, 7, 7.5);
1063
Chia-I Wu8370b402014-08-29 12:28:37 +08001064 if (!cmd->bind.draw_count)
1065 return;
1066
1067 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001068
1069 gen6_PIPE_CONTROL(cmd,
1070 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001071 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001072}
1073
Chia-I Wu8370b402014-08-29 12:28:37 +08001074static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1075{
1076 CMD_ASSERT(cmd, 7, 7.5);
1077
1078 if (!cmd->bind.draw_count)
1079 return;
1080
1081 /*
1082 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1083 *
1084 * "One of the following must also be set (when CS stall is set):
1085 *
1086 * * Render Target Cache Flush Enable ([12] of DW1)
1087 * * Depth Cache Flush Enable ([0] of DW1)
1088 * * Stall at Pixel Scoreboard ([1] of DW1)
1089 * * Depth Stall ([13] of DW1)
1090 * * Post-Sync Operation ([13] of DW1)"
1091 */
1092 gen6_PIPE_CONTROL(cmd,
1093 GEN6_PIPE_CONTROL_CS_STALL |
1094 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001095 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001096}
1097
1098static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1099{
1100 CMD_ASSERT(cmd, 7, 7.5);
1101
1102 if (!cmd->bind.draw_count)
1103 return;
1104
1105 cmd_wa_gen6_pre_depth_stall_write(cmd);
1106
Chia-I Wud6d079d2014-08-31 13:14:21 +08001107 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001108}
1109
1110static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1111{
1112 CMD_ASSERT(cmd, 6, 7.5);
1113
1114 if (!cmd->bind.draw_count)
1115 return;
1116
1117 /*
1118 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1119 *
1120 * "Driver must guarentee that all the caches in the depth pipe are
1121 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1122 * requires driver to send a PIPE_CONTROL with a CS stall along with
1123 * a Depth Flush prior to this command."
1124 *
1125 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1126 *
1127 * "Driver must ierarchi that all the caches in the depth pipe are
1128 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1129 * requires driver to send a PIPE_CONTROL with a CS stall along with
1130 * a Depth Flush prior to this command.
1131 */
1132 gen6_PIPE_CONTROL(cmd,
1133 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1134 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001135 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001136}
1137
1138static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1139{
1140 CMD_ASSERT(cmd, 6, 7.5);
1141
1142 if (!cmd->bind.draw_count)
1143 return;
1144
1145 /*
1146 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1147 *
1148 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1149 * and a post sync operation prior to the group of depth
1150 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1151 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1152 *
1153 * This workaround satifies all the conditions.
1154 */
1155 cmd_wa_gen6_pre_depth_stall_write(cmd);
1156
1157 /*
1158 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1159 *
1160 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1161 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1162 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1163 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1164 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1165 * Depth Flush Bit set, followed by another pipelined depth stall
1166 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1167 * guarantee that the pipeline from WM onwards is already flushed
1168 * (e.g., via a preceding MI_FLUSH)."
1169 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001170 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1171 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1172 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001173}
1174
Chia-I Wu525c6602014-08-27 10:22:34 +08001175void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1176{
1177 if (!cmd->bind.draw_count)
1178 return;
1179
1180 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1181
Chia-I Wu8370b402014-08-29 12:28:37 +08001182 /*
1183 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1184 *
1185 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1186 * PIPE_CONTROL with any non-zero post-sync-op is required."
1187 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001188 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001189 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001190
Chia-I Wu092279a2014-08-30 19:05:30 +08001191 /*
1192 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1193 *
1194 * "One of the following must also be set (when CS stall is set):
1195 *
1196 * * Render Target Cache Flush Enable ([12] of DW1)
1197 * * Depth Cache Flush Enable ([0] of DW1)
1198 * * Stall at Pixel Scoreboard ([1] of DW1)
1199 * * Depth Stall ([13] of DW1)
1200 * * Post-Sync Operation ([13] of DW1)"
1201 */
1202 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1203 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1204 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1205 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1206 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1207 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1208
Chia-I Wud6d079d2014-08-31 13:14:21 +08001209 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001210}
1211
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001212void cmd_batch_depth_count(struct intel_cmd *cmd,
1213 struct intel_bo *bo,
1214 XGL_GPU_SIZE offset)
1215{
1216 cmd_wa_gen6_pre_depth_stall_write(cmd);
1217
1218 gen6_PIPE_CONTROL(cmd,
1219 GEN6_PIPE_CONTROL_DEPTH_STALL |
1220 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001221 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001222}
1223
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001224void cmd_batch_timestamp(struct intel_cmd *cmd,
1225 struct intel_bo *bo,
1226 XGL_GPU_SIZE offset)
1227{
1228 /* need any WA or stall? */
1229 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1230}
1231
1232void cmd_batch_immediate(struct intel_cmd *cmd,
1233 struct intel_bo *bo,
1234 XGL_GPU_SIZE offset,
1235 uint64_t val)
1236{
1237 /* need any WA or stall? */
1238 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1239}
1240
Chia-I Wu302742d2014-08-22 10:28:29 +08001241static void gen6_cc_states(struct intel_cmd *cmd)
1242{
1243 const struct intel_blend_state *blend = cmd->bind.state.blend;
1244 const struct intel_ds_state *ds = cmd->bind.state.ds;
1245 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001246 uint32_t stencil_ref;
1247 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001248
1249 CMD_ASSERT(cmd, 6, 6);
1250
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001251 if (blend) {
1252 blend_pos = gen6_BLEND_STATE(cmd, blend);
1253 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1254 } else {
1255 blend_pos = 0;
1256 memset(blend_color, 0, sizeof(blend_color));
1257 }
1258
1259 if (ds) {
1260 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1261 stencil_ref = ds->cmd_stencil_ref;
1262 } else {
1263 ds_pos = 0;
1264 stencil_ref = 0;
1265 }
1266
1267 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001268
1269 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
1270}
1271
Chia-I Wu1744cca2014-08-22 11:10:17 +08001272static void gen6_viewport_states(struct intel_cmd *cmd)
1273{
1274 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1275 XGL_UINT pos;
1276
1277 if (!viewport)
1278 return;
1279
1280 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1281 viewport->cmd_align);
1282
1283 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
1284 pos + viewport->cmd_clip_offset,
1285 pos,
1286 pos + viewport->cmd_cc_offset);
1287
1288 pos = (viewport->scissor_enable) ?
1289 pos + viewport->cmd_scissor_rect_offset : 0;
1290
1291 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
1292}
1293
Chia-I Wu302742d2014-08-22 10:28:29 +08001294static void gen7_cc_states(struct intel_cmd *cmd)
1295{
1296 const struct intel_blend_state *blend = cmd->bind.state.blend;
1297 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001298 uint32_t stencil_ref;
1299 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001300 XGL_UINT pos;
1301
1302 CMD_ASSERT(cmd, 7, 7.5);
1303
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001304 if (!blend && !ds)
1305 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001306
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001307 if (blend) {
1308 pos = gen6_BLEND_STATE(cmd, blend);
1309 gen7_3dstate_pointer(cmd,
1310 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +08001311
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001312 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1313 } else {
1314 memset(blend_color, 0, sizeof(blend_color));
1315 }
1316
1317 if (ds) {
1318 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1319 gen7_3dstate_pointer(cmd,
1320 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
1321 } else {
1322 stencil_ref = 0;
1323 }
1324
1325 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001326 gen7_3dstate_pointer(cmd,
1327 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
1328}
1329
Chia-I Wu1744cca2014-08-22 11:10:17 +08001330static void gen7_viewport_states(struct intel_cmd *cmd)
1331{
1332 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1333 XGL_UINT pos;
1334
1335 if (!viewport)
1336 return;
1337
1338 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1339 viewport->cmd_align);
1340
1341 gen7_3dstate_pointer(cmd,
1342 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
1343 gen7_3dstate_pointer(cmd,
1344 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
1345 pos + viewport->cmd_cc_offset);
1346 if (viewport->scissor_enable) {
1347 gen7_3dstate_pointer(cmd,
1348 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1349 pos + viewport->cmd_scissor_rect_offset);
1350 }
1351}
1352
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001353static void gen6_pcb(struct intel_cmd *cmd, int subop,
1354 const XGL_PIPELINE_SHADER *sh)
1355{
1356 const uint8_t cmd_len = 5;
1357 const XGL_UINT alignment = 32;
1358 const XGL_UINT max_size =
1359 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
1360 const XGL_UINT max_pcb = 4;
1361 uint32_t pcb[4] = { 0, 0, 0, 0 };
1362 XGL_FLAGS pcb_enables = 0;
1363 XGL_SIZE total_size = 0;
1364 uint32_t dw0;
1365 XGL_UINT i;
1366
1367 for (i = 0; i < sh->linkConstBufferCount; i++) {
1368 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1369 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1370 void *ptr;
1371
1372 if (info->bufferId >= max_pcb ||
1373 pcb_enables & ((1 << info->bufferId)) ||
1374 total_size + info->bufferSize > max_size) {
1375 cmd->result = XGL_ERROR_UNKNOWN;
1376 return;
1377 }
1378 if (!size)
1379 continue;
1380
1381 pcb_enables |= 1 << info->bufferId;
1382 total_size += size;
1383
1384 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1385 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1386 memcpy(ptr, info->pBufferData, info->bufferSize);
1387 cmd_state_advance(cmd, size / sizeof(uint32_t));
1388
1389 pcb[info->bufferId] |= size / alignment - 1;
1390 }
1391
1392 dw0 = GEN6_RENDER_TYPE_RENDER |
1393 GEN6_RENDER_SUBTYPE_3D |
1394 subop |
1395 pcb_enables << 12 |
1396 (cmd_len - 2);
1397
1398 cmd_batch_reserve(cmd, cmd_len);
1399 cmd_batch_write(cmd, dw0);
1400 cmd_batch_write(cmd, pcb[0]);
1401 cmd_batch_write(cmd, pcb[1]);
1402 cmd_batch_write(cmd, pcb[2]);
1403 cmd_batch_write(cmd, pcb[3]);
1404}
1405
1406static void gen7_pcb(struct intel_cmd *cmd, int subop,
1407 const XGL_PIPELINE_SHADER *sh)
1408{
1409 const uint8_t cmd_len = 7;
1410 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1411 GEN6_RENDER_SUBTYPE_3D |
1412 subop |
1413 (cmd_len - 2);
1414 const XGL_UINT alignment = 32;
1415 const XGL_UINT max_size = 2048;
1416 const XGL_UINT max_pcb = 4;
1417 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
1418 uint32_t pcb[4] = { 0, 0, 0, 0 };
1419 XGL_FLAGS pcb_enables = 0;
1420 XGL_SIZE total_size = 0;
1421 XGL_UINT i;
1422
1423 for (i = 0; i < sh->linkConstBufferCount; i++) {
1424 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1425 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1426 void *ptr;
1427
1428 if (info->bufferId >= max_pcb ||
1429 pcb_enables & ((1 << info->bufferId)) ||
1430 total_size + info->bufferSize > max_size) {
1431 cmd->result = XGL_ERROR_UNKNOWN;
1432 return;
1433 }
1434 if (!size)
1435 continue;
1436
1437 pcb_enables |= 1 << info->bufferId;
1438 total_size += size;
1439
1440 pcb_len[info->bufferId] = size / alignment;
1441
1442 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1443 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1444 memcpy(ptr, info->pBufferData, info->bufferSize);
1445 cmd_state_advance(cmd, size / sizeof(uint32_t));
1446 }
1447
1448 /* no holes */
1449 if (!u_is_pow2(pcb_enables + 1)) {
1450 cmd->result = XGL_ERROR_UNKNOWN;
1451 return;
1452 }
1453
1454 cmd_batch_reserve(cmd, cmd_len);
1455 cmd_batch_write(cmd, dw0);
1456 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
1457 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
1458 cmd_batch_write(cmd, pcb[0]);
1459 cmd_batch_write(cmd, pcb[1]);
1460 cmd_batch_write(cmd, pcb[2]);
1461 cmd_batch_write(cmd, pcb[3]);
1462}
1463
Chia-I Wu42a56202014-08-23 16:47:48 +08001464static void emit_ps_resources(struct intel_cmd *cmd,
1465 const struct intel_rmap *rmap)
1466{
1467 const XGL_UINT surface_count = rmap->rt_count +
1468 rmap->resource_count + rmap->uav_count;
1469 uint32_t binding_table[256];
1470 XGL_UINT pos, i;
1471
1472 assert(surface_count <= ARRAY_SIZE(binding_table));
1473
1474 for (i = 0; i < surface_count; i++) {
1475 const struct intel_rmap_slot *slot = &rmap->slots[i];
1476 uint32_t *dw;
1477
1478 switch (slot->path_len) {
1479 case 0:
1480 pos = 0;
1481 break;
1482 case INTEL_RMAP_SLOT_RT:
1483 {
1484 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1485
1486 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1487 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1488
1489 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001490 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001491 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001492 cmd_state_advance(cmd, view->cmd_len);
1493 }
1494 break;
1495 case INTEL_RMAP_SLOT_DYN:
1496 {
1497 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001498 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001499
1500 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1501 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1502
1503 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001504 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001505 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001506 cmd_state_advance(cmd, view->cmd_len);
1507 }
1508 break;
1509 case 1:
1510 default:
1511 /* TODO */
1512 assert(!"no dset support");
1513 break;
1514 }
1515
1516 binding_table[i] = pos << 2;
1517 }
1518
1519 pos = cmd_state_copy(cmd, binding_table, surface_count,
1520 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
1521
1522 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1523 gen7_3dstate_pointer(cmd,
1524 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001525
1526 gen7_3dstate_pointer(cmd,
1527 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1528 gen7_3dstate_pointer(cmd,
1529 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1530 gen7_3dstate_pointer(cmd,
1531 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1532 gen7_3dstate_pointer(cmd,
1533 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1534
1535 gen7_3dstate_pointer(cmd,
1536 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1537 gen7_3dstate_pointer(cmd,
1538 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1539 gen7_3dstate_pointer(cmd,
1540 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1541 gen7_3dstate_pointer(cmd,
1542 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1543 gen7_3dstate_pointer(cmd,
1544 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001545 } else {
1546 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001547 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001548 }
1549}
1550
Chia-I Wu52500102014-08-22 00:46:04 +08001551static void emit_bounded_states(struct intel_cmd *cmd)
1552{
1553 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1554
1555 /* TODO more states */
1556
Chia-I Wu1744cca2014-08-22 11:10:17 +08001557 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001558 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001559 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001560
1561 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1562 &cmd->bind.pipeline.graphics->vs);
1563 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1564 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001565
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001566 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001567 gen7_3DSTATE_SF(cmd);
1568 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001569 gen7_3DSTATE_WM(cmd);
1570 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001571 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001572 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001573 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001574
1575 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1576 &cmd->bind.pipeline.graphics->vs);
1577 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1578 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001579
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001580 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001581 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001582 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001583 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001584
Chia-I Wu42a56202014-08-23 16:47:48 +08001585 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1586
Chia-I Wu8370b402014-08-29 12:28:37 +08001587 cmd_wa_gen6_pre_depth_stall_write(cmd);
1588 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001589 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001590 cmd_batch_reserve(cmd, msaa->cmd_len);
1591 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001592}
1593
1594static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001595 const struct intel_pipe_shader *shader,
1596 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001597{
1598 uint32_t i;
1599 struct intel_cmd_shader *cmdShader;
1600
1601 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001602 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001603 /* shader is already part of pipeline */
1604 return;
1605 }
1606 }
1607
Chia-I Wu338fe642014-08-28 10:43:04 +08001608 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1609 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1610
1611 cmdShader = cmd->bind.shaderCache.shaderArray;
1612
1613 cmd->bind.shaderCache.shaderArray =
1614 icd_alloc(sizeof(*cmdShader) * new_count,
1615 0, XGL_SYSTEM_ALLOC_INTERNAL);
1616 if (cmd->bind.shaderCache.shaderArray == NULL) {
1617 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001618 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1619 return;
1620 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001621
1622 if (cmdShader) {
1623 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1624 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1625 icd_free(cmdShader);
1626 }
1627
1628 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001629 }
1630
Chia-I Wu338fe642014-08-28 10:43:04 +08001631 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001632 cmdShader->shader = shader;
1633 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001634 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001635 cmd->bind.shaderCache.used++;
1636 return;
1637}
1638
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001639static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001640 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001641{
1642 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001643
Chia-I Wu8370b402014-08-29 12:28:37 +08001644 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1645 cmd_wa_gen6_pre_depth_stall_write(cmd);
1646 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1647 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1648 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1649 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001650
1651 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001652 assert(pipeline->cmd_len);
Chia-I Wub08727d2014-08-29 14:54:54 +08001653 cmd_batch_reserve(cmd, pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001654 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001655
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001656 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001657 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001658 }
1659 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001660 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001661 }
1662 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001663 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001664 }
1665 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001666 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001667 }
1668 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001669 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001670 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001671
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001672 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1673 gen7_3DSTATE_GS(cmd);
1674 } else {
1675 gen6_3DSTATE_GS(cmd);
1676 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001677
Chia-I Wu8370b402014-08-29 12:28:37 +08001678 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1679 cmd_wa_gen7_post_command_cs_stall(cmd);
1680 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1681 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001682}
1683
1684static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1685 const struct intel_pipeline *pipeline)
1686{
1687 cmd->bind.pipeline.compute = pipeline;
1688}
1689
1690static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1691 const struct intel_pipeline_delta *delta)
1692{
1693 cmd->bind.pipeline.graphics_delta = delta;
1694}
1695
1696static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1697 const struct intel_pipeline_delta *delta)
1698{
1699 cmd->bind.pipeline.compute_delta = delta;
1700}
1701
1702static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1703 const struct intel_dset *dset,
1704 XGL_UINT slot_offset)
1705{
1706 cmd->bind.dset.graphics = dset;
1707 cmd->bind.dset.graphics_offset = slot_offset;
1708}
1709
1710static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1711 const struct intel_dset *dset,
1712 XGL_UINT slot_offset)
1713{
1714 cmd->bind.dset.compute = dset;
1715 cmd->bind.dset.compute_offset = slot_offset;
1716}
1717
1718static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1719 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1720{
1721 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1722}
1723
1724static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1725 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1726{
1727 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1728}
1729
1730static void cmd_bind_index_data(struct intel_cmd *cmd,
1731 const struct intel_mem *mem,
1732 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1733{
1734 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1735 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1736 } else {
1737 cmd->bind.index.mem = mem;
1738 cmd->bind.index.offset = offset;
1739 cmd->bind.index.type = type;
1740 }
1741}
1742
1743static void cmd_bind_rt(struct intel_cmd *cmd,
1744 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1745 XGL_UINT count)
1746{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001747 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001748 XGL_UINT i;
1749
1750 for (i = 0; i < count; i++) {
1751 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1752 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001753 const struct intel_layout *layout = &rt->img->layout;
1754
1755 if (i == 0) {
1756 width = layout->width0;
1757 height = layout->height0;
1758 } else {
1759 if (width > layout->width0)
1760 width = layout->width0;
1761 if (height > layout->height0)
1762 height = layout->height0;
1763 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001764
1765 cmd->bind.att.rt[i] = rt;
1766 }
1767
1768 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001769
Chia-I Wu8370b402014-08-29 12:28:37 +08001770 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001771 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001772}
1773
1774static void cmd_bind_ds(struct intel_cmd *cmd,
1775 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1776{
1777 const struct intel_ds_view *ds;
1778
1779 if (info) {
1780 cmd->bind.att.ds = intel_ds_view(info->view);
1781 ds = cmd->bind.att.ds;
1782 } else {
1783 /* all zeros */
1784 static const struct intel_ds_view null_ds;
1785 ds = &null_ds;
1786 }
1787
Chia-I Wu8370b402014-08-29 12:28:37 +08001788 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001789 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1790 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1791 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001792
1793 if (cmd_gen(cmd) >= INTEL_GEN(7))
1794 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1795 else
1796 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001797}
1798
1799static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1800 const struct intel_viewport_state *state)
1801{
1802 cmd->bind.state.viewport = state;
1803}
1804
1805static void cmd_bind_raster_state(struct intel_cmd *cmd,
1806 const struct intel_raster_state *state)
1807{
1808 cmd->bind.state.raster = state;
1809}
1810
1811static void cmd_bind_ds_state(struct intel_cmd *cmd,
1812 const struct intel_ds_state *state)
1813{
1814 cmd->bind.state.ds = state;
1815}
1816
1817static void cmd_bind_blend_state(struct intel_cmd *cmd,
1818 const struct intel_blend_state *state)
1819{
1820 cmd->bind.state.blend = state;
1821}
1822
1823static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1824 const struct intel_msaa_state *state)
1825{
1826 cmd->bind.state.msaa = state;
1827}
1828
1829static void cmd_draw(struct intel_cmd *cmd,
1830 XGL_UINT vertex_start,
1831 XGL_UINT vertex_count,
1832 XGL_UINT instance_start,
1833 XGL_UINT instance_count,
1834 bool indexed,
1835 XGL_UINT vertex_base)
1836{
1837 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1838
1839 emit_bounded_states(cmd);
1840
1841 if (indexed) {
1842 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1843 cmd->result = XGL_ERROR_UNKNOWN;
1844
1845 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1846 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1847 p->primitive_restart_index);
1848 } else {
1849 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1850 cmd->bind.index.offset, cmd->bind.index.type,
1851 p->primitive_restart);
1852 }
1853 } else {
1854 assert(!vertex_base);
1855 }
1856
1857 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1858 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1859 vertex_start, instance_count, instance_start, vertex_base);
1860 } else {
1861 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1862 vertex_start, instance_count, instance_start, vertex_base);
1863 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001864
Chia-I Wu707a29e2014-08-27 12:51:47 +08001865 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001866 /* need to re-emit all workarounds */
1867 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001868}
1869
Chia-I Wub2755562014-08-20 13:38:52 +08001870XGL_VOID XGLAPI intelCmdBindPipeline(
1871 XGL_CMD_BUFFER cmdBuffer,
1872 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1873 XGL_PIPELINE pipeline)
1874{
1875 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1876
1877 switch (pipelineBindPoint) {
1878 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001879 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001880 break;
1881 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001882 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001883 break;
1884 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001885 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001886 break;
1887 }
1888}
1889
1890XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1891 XGL_CMD_BUFFER cmdBuffer,
1892 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1893 XGL_PIPELINE_DELTA delta)
1894{
1895 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1896
1897 switch (pipelineBindPoint) {
1898 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001899 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001900 break;
1901 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001902 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001903 break;
1904 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001905 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001906 break;
1907 }
1908}
1909
1910XGL_VOID XGLAPI intelCmdBindStateObject(
1911 XGL_CMD_BUFFER cmdBuffer,
1912 XGL_STATE_BIND_POINT stateBindPoint,
1913 XGL_STATE_OBJECT state)
1914{
1915 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1916
1917 switch (stateBindPoint) {
1918 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001919 cmd_bind_viewport_state(cmd,
1920 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001921 break;
1922 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001923 cmd_bind_raster_state(cmd,
1924 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001925 break;
1926 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001927 cmd_bind_ds_state(cmd,
1928 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001929 break;
1930 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001931 cmd_bind_blend_state(cmd,
1932 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001933 break;
1934 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001935 cmd_bind_msaa_state(cmd,
1936 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001937 break;
1938 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001939 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001940 break;
1941 }
1942}
1943
1944XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1945 XGL_CMD_BUFFER cmdBuffer,
1946 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1947 XGL_UINT index,
1948 XGL_DESCRIPTOR_SET descriptorSet,
1949 XGL_UINT slotOffset)
1950{
1951 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1952 struct intel_dset *dset = intel_dset(descriptorSet);
1953
1954 assert(!index);
1955
1956 switch (pipelineBindPoint) {
1957 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001958 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001959 break;
1960 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001961 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001962 break;
1963 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001964 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001965 break;
1966 }
1967}
1968
1969XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1970 XGL_CMD_BUFFER cmdBuffer,
1971 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1972 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1973{
1974 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1975
1976 switch (pipelineBindPoint) {
1977 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001978 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001979 break;
1980 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001981 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001982 break;
1983 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001984 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001985 break;
1986 }
1987}
1988
1989XGL_VOID XGLAPI intelCmdBindIndexData(
1990 XGL_CMD_BUFFER cmdBuffer,
1991 XGL_GPU_MEMORY mem_,
1992 XGL_GPU_SIZE offset,
1993 XGL_INDEX_TYPE indexType)
1994{
1995 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1996 struct intel_mem *mem = intel_mem(mem_);
1997
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001998 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001999}
2000
2001XGL_VOID XGLAPI intelCmdBindAttachments(
2002 XGL_CMD_BUFFER cmdBuffer,
2003 XGL_UINT colorAttachmentCount,
2004 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
2005 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
2006{
2007 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08002008
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002009 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
2010 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08002011}
2012
2013XGL_VOID XGLAPI intelCmdDraw(
2014 XGL_CMD_BUFFER cmdBuffer,
2015 XGL_UINT firstVertex,
2016 XGL_UINT vertexCount,
2017 XGL_UINT firstInstance,
2018 XGL_UINT instanceCount)
2019{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002020 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002021
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002022 cmd_draw(cmd, firstVertex, vertexCount,
2023 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08002024}
2025
2026XGL_VOID XGLAPI intelCmdDrawIndexed(
2027 XGL_CMD_BUFFER cmdBuffer,
2028 XGL_UINT firstIndex,
2029 XGL_UINT indexCount,
2030 XGL_INT vertexOffset,
2031 XGL_UINT firstInstance,
2032 XGL_UINT instanceCount)
2033{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002034 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002035
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002036 cmd_draw(cmd, firstIndex, indexCount,
2037 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002038}
2039
2040XGL_VOID XGLAPI intelCmdDrawIndirect(
2041 XGL_CMD_BUFFER cmdBuffer,
2042 XGL_GPU_MEMORY mem,
2043 XGL_GPU_SIZE offset,
2044 XGL_UINT32 count,
2045 XGL_UINT32 stride)
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}
2051
2052XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2053 XGL_CMD_BUFFER cmdBuffer,
2054 XGL_GPU_MEMORY mem,
2055 XGL_GPU_SIZE offset,
2056 XGL_UINT32 count,
2057 XGL_UINT32 stride)
2058{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002059 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2060
2061 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002062}
2063
2064XGL_VOID XGLAPI intelCmdDispatch(
2065 XGL_CMD_BUFFER cmdBuffer,
2066 XGL_UINT x,
2067 XGL_UINT y,
2068 XGL_UINT z)
2069{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002070 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2071
2072 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002073}
2074
2075XGL_VOID XGLAPI intelCmdDispatchIndirect(
2076 XGL_CMD_BUFFER cmdBuffer,
2077 XGL_GPU_MEMORY mem,
2078 XGL_GPU_SIZE offset)
2079{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002080 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2081
2082 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002083}