blob: 1fe8c68ea813513a3cc463cbeab505c24b00334e [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 Wu302742d2014-08-22 10:28:29 +08001224static void gen6_cc_states(struct intel_cmd *cmd)
1225{
1226 const struct intel_blend_state *blend = cmd->bind.state.blend;
1227 const struct intel_ds_state *ds = cmd->bind.state.ds;
1228 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001229 uint32_t stencil_ref;
1230 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001231
1232 CMD_ASSERT(cmd, 6, 6);
1233
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001234 if (blend) {
1235 blend_pos = gen6_BLEND_STATE(cmd, blend);
1236 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1237 } else {
1238 blend_pos = 0;
1239 memset(blend_color, 0, sizeof(blend_color));
1240 }
1241
1242 if (ds) {
1243 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1244 stencil_ref = ds->cmd_stencil_ref;
1245 } else {
1246 ds_pos = 0;
1247 stencil_ref = 0;
1248 }
1249
1250 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001251
1252 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
1253}
1254
Chia-I Wu1744cca2014-08-22 11:10:17 +08001255static void gen6_viewport_states(struct intel_cmd *cmd)
1256{
1257 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1258 XGL_UINT pos;
1259
1260 if (!viewport)
1261 return;
1262
1263 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1264 viewport->cmd_align);
1265
1266 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
1267 pos + viewport->cmd_clip_offset,
1268 pos,
1269 pos + viewport->cmd_cc_offset);
1270
1271 pos = (viewport->scissor_enable) ?
1272 pos + viewport->cmd_scissor_rect_offset : 0;
1273
1274 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
1275}
1276
Chia-I Wu302742d2014-08-22 10:28:29 +08001277static void gen7_cc_states(struct intel_cmd *cmd)
1278{
1279 const struct intel_blend_state *blend = cmd->bind.state.blend;
1280 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001281 uint32_t stencil_ref;
1282 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001283 XGL_UINT pos;
1284
1285 CMD_ASSERT(cmd, 7, 7.5);
1286
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001287 if (!blend && !ds)
1288 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001289
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001290 if (blend) {
1291 pos = gen6_BLEND_STATE(cmd, blend);
1292 gen7_3dstate_pointer(cmd,
1293 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +08001294
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001295 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1296 } else {
1297 memset(blend_color, 0, sizeof(blend_color));
1298 }
1299
1300 if (ds) {
1301 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1302 gen7_3dstate_pointer(cmd,
1303 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
1304 } else {
1305 stencil_ref = 0;
1306 }
1307
1308 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001309 gen7_3dstate_pointer(cmd,
1310 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
1311}
1312
Chia-I Wu1744cca2014-08-22 11:10:17 +08001313static void gen7_viewport_states(struct intel_cmd *cmd)
1314{
1315 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1316 XGL_UINT pos;
1317
1318 if (!viewport)
1319 return;
1320
1321 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1322 viewport->cmd_align);
1323
1324 gen7_3dstate_pointer(cmd,
1325 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
1326 gen7_3dstate_pointer(cmd,
1327 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
1328 pos + viewport->cmd_cc_offset);
1329 if (viewport->scissor_enable) {
1330 gen7_3dstate_pointer(cmd,
1331 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1332 pos + viewport->cmd_scissor_rect_offset);
1333 }
1334}
1335
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001336static void gen6_pcb(struct intel_cmd *cmd, int subop,
1337 const XGL_PIPELINE_SHADER *sh)
1338{
1339 const uint8_t cmd_len = 5;
1340 const XGL_UINT alignment = 32;
1341 const XGL_UINT max_size =
1342 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
1343 const XGL_UINT max_pcb = 4;
1344 uint32_t pcb[4] = { 0, 0, 0, 0 };
1345 XGL_FLAGS pcb_enables = 0;
1346 XGL_SIZE total_size = 0;
1347 uint32_t dw0;
1348 XGL_UINT i;
1349
1350 for (i = 0; i < sh->linkConstBufferCount; i++) {
1351 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1352 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1353 void *ptr;
1354
1355 if (info->bufferId >= max_pcb ||
1356 pcb_enables & ((1 << info->bufferId)) ||
1357 total_size + info->bufferSize > max_size) {
1358 cmd->result = XGL_ERROR_UNKNOWN;
1359 return;
1360 }
1361 if (!size)
1362 continue;
1363
1364 pcb_enables |= 1 << info->bufferId;
1365 total_size += size;
1366
1367 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1368 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1369 memcpy(ptr, info->pBufferData, info->bufferSize);
1370 cmd_state_advance(cmd, size / sizeof(uint32_t));
1371
1372 pcb[info->bufferId] |= size / alignment - 1;
1373 }
1374
1375 dw0 = GEN6_RENDER_TYPE_RENDER |
1376 GEN6_RENDER_SUBTYPE_3D |
1377 subop |
1378 pcb_enables << 12 |
1379 (cmd_len - 2);
1380
1381 cmd_batch_reserve(cmd, cmd_len);
1382 cmd_batch_write(cmd, dw0);
1383 cmd_batch_write(cmd, pcb[0]);
1384 cmd_batch_write(cmd, pcb[1]);
1385 cmd_batch_write(cmd, pcb[2]);
1386 cmd_batch_write(cmd, pcb[3]);
1387}
1388
1389static void gen7_pcb(struct intel_cmd *cmd, int subop,
1390 const XGL_PIPELINE_SHADER *sh)
1391{
1392 const uint8_t cmd_len = 7;
1393 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1394 GEN6_RENDER_SUBTYPE_3D |
1395 subop |
1396 (cmd_len - 2);
1397 const XGL_UINT alignment = 32;
1398 const XGL_UINT max_size = 2048;
1399 const XGL_UINT max_pcb = 4;
1400 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
1401 uint32_t pcb[4] = { 0, 0, 0, 0 };
1402 XGL_FLAGS pcb_enables = 0;
1403 XGL_SIZE total_size = 0;
1404 XGL_UINT i;
1405
1406 for (i = 0; i < sh->linkConstBufferCount; i++) {
1407 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1408 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1409 void *ptr;
1410
1411 if (info->bufferId >= max_pcb ||
1412 pcb_enables & ((1 << info->bufferId)) ||
1413 total_size + info->bufferSize > max_size) {
1414 cmd->result = XGL_ERROR_UNKNOWN;
1415 return;
1416 }
1417 if (!size)
1418 continue;
1419
1420 pcb_enables |= 1 << info->bufferId;
1421 total_size += size;
1422
1423 pcb_len[info->bufferId] = size / alignment;
1424
1425 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1426 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1427 memcpy(ptr, info->pBufferData, info->bufferSize);
1428 cmd_state_advance(cmd, size / sizeof(uint32_t));
1429 }
1430
1431 /* no holes */
1432 if (!u_is_pow2(pcb_enables + 1)) {
1433 cmd->result = XGL_ERROR_UNKNOWN;
1434 return;
1435 }
1436
1437 cmd_batch_reserve(cmd, cmd_len);
1438 cmd_batch_write(cmd, dw0);
1439 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
1440 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
1441 cmd_batch_write(cmd, pcb[0]);
1442 cmd_batch_write(cmd, pcb[1]);
1443 cmd_batch_write(cmd, pcb[2]);
1444 cmd_batch_write(cmd, pcb[3]);
1445}
1446
Chia-I Wu42a56202014-08-23 16:47:48 +08001447static void emit_ps_resources(struct intel_cmd *cmd,
1448 const struct intel_rmap *rmap)
1449{
1450 const XGL_UINT surface_count = rmap->rt_count +
1451 rmap->resource_count + rmap->uav_count;
1452 uint32_t binding_table[256];
1453 XGL_UINT pos, i;
1454
1455 assert(surface_count <= ARRAY_SIZE(binding_table));
1456
1457 for (i = 0; i < surface_count; i++) {
1458 const struct intel_rmap_slot *slot = &rmap->slots[i];
1459 uint32_t *dw;
1460
1461 switch (slot->path_len) {
1462 case 0:
1463 pos = 0;
1464 break;
1465 case INTEL_RMAP_SLOT_RT:
1466 {
1467 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1468
1469 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1470 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1471
1472 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001473 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001474 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001475 cmd_state_advance(cmd, view->cmd_len);
1476 }
1477 break;
1478 case INTEL_RMAP_SLOT_DYN:
1479 {
1480 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001481 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001482
1483 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1484 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1485
1486 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001487 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001488 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001489 cmd_state_advance(cmd, view->cmd_len);
1490 }
1491 break;
1492 case 1:
1493 default:
1494 /* TODO */
1495 assert(!"no dset support");
1496 break;
1497 }
1498
1499 binding_table[i] = pos << 2;
1500 }
1501
1502 pos = cmd_state_copy(cmd, binding_table, surface_count,
1503 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
1504
1505 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1506 gen7_3dstate_pointer(cmd,
1507 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001508
1509 gen7_3dstate_pointer(cmd,
1510 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1511 gen7_3dstate_pointer(cmd,
1512 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1513 gen7_3dstate_pointer(cmd,
1514 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1515 gen7_3dstate_pointer(cmd,
1516 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1517
1518 gen7_3dstate_pointer(cmd,
1519 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1520 gen7_3dstate_pointer(cmd,
1521 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1522 gen7_3dstate_pointer(cmd,
1523 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1524 gen7_3dstate_pointer(cmd,
1525 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1526 gen7_3dstate_pointer(cmd,
1527 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001528 } else {
1529 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001530 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001531 }
1532}
1533
Chia-I Wu52500102014-08-22 00:46:04 +08001534static void emit_bounded_states(struct intel_cmd *cmd)
1535{
1536 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1537
1538 /* TODO more states */
1539
Chia-I Wu1744cca2014-08-22 11:10:17 +08001540 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001541 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001542 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001543
1544 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1545 &cmd->bind.pipeline.graphics->vs);
1546 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1547 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001548
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001549 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001550 gen7_3DSTATE_SF(cmd);
1551 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001552 gen7_3DSTATE_WM(cmd);
1553 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001554 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001555 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001556 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001557
1558 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1559 &cmd->bind.pipeline.graphics->vs);
1560 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1561 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001562
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001563 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001564 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001565 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001566 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001567
Chia-I Wu42a56202014-08-23 16:47:48 +08001568 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1569
Chia-I Wu8370b402014-08-29 12:28:37 +08001570 cmd_wa_gen6_pre_depth_stall_write(cmd);
1571 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001572 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001573 cmd_batch_reserve(cmd, msaa->cmd_len);
1574 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001575}
1576
1577static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001578 const struct intel_pipe_shader *shader,
1579 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001580{
1581 uint32_t i;
1582 struct intel_cmd_shader *cmdShader;
1583
1584 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001585 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001586 /* shader is already part of pipeline */
1587 return;
1588 }
1589 }
1590
Chia-I Wu338fe642014-08-28 10:43:04 +08001591 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1592 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1593
1594 cmdShader = cmd->bind.shaderCache.shaderArray;
1595
1596 cmd->bind.shaderCache.shaderArray =
1597 icd_alloc(sizeof(*cmdShader) * new_count,
1598 0, XGL_SYSTEM_ALLOC_INTERNAL);
1599 if (cmd->bind.shaderCache.shaderArray == NULL) {
1600 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001601 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1602 return;
1603 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001604
1605 if (cmdShader) {
1606 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1607 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1608 icd_free(cmdShader);
1609 }
1610
1611 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001612 }
1613
Chia-I Wu338fe642014-08-28 10:43:04 +08001614 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001615 cmdShader->shader = shader;
1616 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001617 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001618 cmd->bind.shaderCache.used++;
1619 return;
1620}
1621
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001622static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001623 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001624{
1625 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001626
Chia-I Wu8370b402014-08-29 12:28:37 +08001627 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1628 cmd_wa_gen6_pre_depth_stall_write(cmd);
1629 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1630 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1631 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1632 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001633
1634 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001635 assert(pipeline->cmd_len);
Chia-I Wub08727d2014-08-29 14:54:54 +08001636 cmd_batch_reserve(cmd, pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001637 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001638
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001639 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001640 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001641 }
1642 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001643 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001644 }
1645 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001646 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001647 }
1648 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001649 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001650 }
1651 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001652 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001653 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001654
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001655 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1656 gen7_3DSTATE_GS(cmd);
1657 } else {
1658 gen6_3DSTATE_GS(cmd);
1659 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001660
Chia-I Wu8370b402014-08-29 12:28:37 +08001661 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1662 cmd_wa_gen7_post_command_cs_stall(cmd);
1663 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1664 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001665}
1666
1667static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1668 const struct intel_pipeline *pipeline)
1669{
1670 cmd->bind.pipeline.compute = pipeline;
1671}
1672
1673static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1674 const struct intel_pipeline_delta *delta)
1675{
1676 cmd->bind.pipeline.graphics_delta = delta;
1677}
1678
1679static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1680 const struct intel_pipeline_delta *delta)
1681{
1682 cmd->bind.pipeline.compute_delta = delta;
1683}
1684
1685static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1686 const struct intel_dset *dset,
1687 XGL_UINT slot_offset)
1688{
1689 cmd->bind.dset.graphics = dset;
1690 cmd->bind.dset.graphics_offset = slot_offset;
1691}
1692
1693static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1694 const struct intel_dset *dset,
1695 XGL_UINT slot_offset)
1696{
1697 cmd->bind.dset.compute = dset;
1698 cmd->bind.dset.compute_offset = slot_offset;
1699}
1700
1701static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1702 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1703{
1704 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1705}
1706
1707static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1708 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1709{
1710 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1711}
1712
1713static void cmd_bind_index_data(struct intel_cmd *cmd,
1714 const struct intel_mem *mem,
1715 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1716{
1717 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1718 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1719 } else {
1720 cmd->bind.index.mem = mem;
1721 cmd->bind.index.offset = offset;
1722 cmd->bind.index.type = type;
1723 }
1724}
1725
1726static void cmd_bind_rt(struct intel_cmd *cmd,
1727 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1728 XGL_UINT count)
1729{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001730 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001731 XGL_UINT i;
1732
1733 for (i = 0; i < count; i++) {
1734 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1735 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001736 const struct intel_layout *layout = &rt->img->layout;
1737
1738 if (i == 0) {
1739 width = layout->width0;
1740 height = layout->height0;
1741 } else {
1742 if (width > layout->width0)
1743 width = layout->width0;
1744 if (height > layout->height0)
1745 height = layout->height0;
1746 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001747
1748 cmd->bind.att.rt[i] = rt;
1749 }
1750
1751 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001752
Chia-I Wu8370b402014-08-29 12:28:37 +08001753 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001754 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001755}
1756
1757static void cmd_bind_ds(struct intel_cmd *cmd,
1758 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1759{
1760 const struct intel_ds_view *ds;
1761
1762 if (info) {
1763 cmd->bind.att.ds = intel_ds_view(info->view);
1764 ds = cmd->bind.att.ds;
1765 } else {
1766 /* all zeros */
1767 static const struct intel_ds_view null_ds;
1768 ds = &null_ds;
1769 }
1770
Chia-I Wu8370b402014-08-29 12:28:37 +08001771 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001772 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1773 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1774 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001775
1776 if (cmd_gen(cmd) >= INTEL_GEN(7))
1777 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1778 else
1779 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001780}
1781
1782static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1783 const struct intel_viewport_state *state)
1784{
1785 cmd->bind.state.viewport = state;
1786}
1787
1788static void cmd_bind_raster_state(struct intel_cmd *cmd,
1789 const struct intel_raster_state *state)
1790{
1791 cmd->bind.state.raster = state;
1792}
1793
1794static void cmd_bind_ds_state(struct intel_cmd *cmd,
1795 const struct intel_ds_state *state)
1796{
1797 cmd->bind.state.ds = state;
1798}
1799
1800static void cmd_bind_blend_state(struct intel_cmd *cmd,
1801 const struct intel_blend_state *state)
1802{
1803 cmd->bind.state.blend = state;
1804}
1805
1806static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1807 const struct intel_msaa_state *state)
1808{
1809 cmd->bind.state.msaa = state;
1810}
1811
1812static void cmd_draw(struct intel_cmd *cmd,
1813 XGL_UINT vertex_start,
1814 XGL_UINT vertex_count,
1815 XGL_UINT instance_start,
1816 XGL_UINT instance_count,
1817 bool indexed,
1818 XGL_UINT vertex_base)
1819{
1820 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1821
1822 emit_bounded_states(cmd);
1823
1824 if (indexed) {
1825 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1826 cmd->result = XGL_ERROR_UNKNOWN;
1827
1828 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1829 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1830 p->primitive_restart_index);
1831 } else {
1832 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1833 cmd->bind.index.offset, cmd->bind.index.type,
1834 p->primitive_restart);
1835 }
1836 } else {
1837 assert(!vertex_base);
1838 }
1839
1840 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1841 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1842 vertex_start, instance_count, instance_start, vertex_base);
1843 } else {
1844 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1845 vertex_start, instance_count, instance_start, vertex_base);
1846 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001847
Chia-I Wu707a29e2014-08-27 12:51:47 +08001848 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001849 /* need to re-emit all workarounds */
1850 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001851}
1852
Chia-I Wub2755562014-08-20 13:38:52 +08001853XGL_VOID XGLAPI intelCmdBindPipeline(
1854 XGL_CMD_BUFFER cmdBuffer,
1855 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1856 XGL_PIPELINE pipeline)
1857{
1858 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1859
1860 switch (pipelineBindPoint) {
1861 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001862 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001863 break;
1864 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001865 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001866 break;
1867 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001868 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001869 break;
1870 }
1871}
1872
1873XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1874 XGL_CMD_BUFFER cmdBuffer,
1875 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1876 XGL_PIPELINE_DELTA delta)
1877{
1878 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1879
1880 switch (pipelineBindPoint) {
1881 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001882 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001883 break;
1884 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001885 cmd_bind_graphics_delta(cmd, delta);
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 intelCmdBindStateObject(
1894 XGL_CMD_BUFFER cmdBuffer,
1895 XGL_STATE_BIND_POINT stateBindPoint,
1896 XGL_STATE_OBJECT state)
1897{
1898 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1899
1900 switch (stateBindPoint) {
1901 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001902 cmd_bind_viewport_state(cmd,
1903 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001904 break;
1905 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001906 cmd_bind_raster_state(cmd,
1907 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001908 break;
1909 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001910 cmd_bind_ds_state(cmd,
1911 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001912 break;
1913 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001914 cmd_bind_blend_state(cmd,
1915 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001916 break;
1917 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001918 cmd_bind_msaa_state(cmd,
1919 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001920 break;
1921 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001922 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001923 break;
1924 }
1925}
1926
1927XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1928 XGL_CMD_BUFFER cmdBuffer,
1929 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1930 XGL_UINT index,
1931 XGL_DESCRIPTOR_SET descriptorSet,
1932 XGL_UINT slotOffset)
1933{
1934 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1935 struct intel_dset *dset = intel_dset(descriptorSet);
1936
1937 assert(!index);
1938
1939 switch (pipelineBindPoint) {
1940 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001941 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001942 break;
1943 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001944 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001945 break;
1946 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001947 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001948 break;
1949 }
1950}
1951
1952XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1953 XGL_CMD_BUFFER cmdBuffer,
1954 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1955 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1956{
1957 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1958
1959 switch (pipelineBindPoint) {
1960 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001961 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001962 break;
1963 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001964 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001965 break;
1966 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001967 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001968 break;
1969 }
1970}
1971
1972XGL_VOID XGLAPI intelCmdBindIndexData(
1973 XGL_CMD_BUFFER cmdBuffer,
1974 XGL_GPU_MEMORY mem_,
1975 XGL_GPU_SIZE offset,
1976 XGL_INDEX_TYPE indexType)
1977{
1978 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1979 struct intel_mem *mem = intel_mem(mem_);
1980
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001981 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001982}
1983
1984XGL_VOID XGLAPI intelCmdBindAttachments(
1985 XGL_CMD_BUFFER cmdBuffer,
1986 XGL_UINT colorAttachmentCount,
1987 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1988 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1989{
1990 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001991
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001992 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1993 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001994}
1995
1996XGL_VOID XGLAPI intelCmdDraw(
1997 XGL_CMD_BUFFER cmdBuffer,
1998 XGL_UINT firstVertex,
1999 XGL_UINT vertexCount,
2000 XGL_UINT firstInstance,
2001 XGL_UINT instanceCount)
2002{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002003 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002004
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002005 cmd_draw(cmd, firstVertex, vertexCount,
2006 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08002007}
2008
2009XGL_VOID XGLAPI intelCmdDrawIndexed(
2010 XGL_CMD_BUFFER cmdBuffer,
2011 XGL_UINT firstIndex,
2012 XGL_UINT indexCount,
2013 XGL_INT vertexOffset,
2014 XGL_UINT firstInstance,
2015 XGL_UINT instanceCount)
2016{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002017 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002018
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002019 cmd_draw(cmd, firstIndex, indexCount,
2020 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002021}
2022
2023XGL_VOID XGLAPI intelCmdDrawIndirect(
2024 XGL_CMD_BUFFER cmdBuffer,
2025 XGL_GPU_MEMORY mem,
2026 XGL_GPU_SIZE offset,
2027 XGL_UINT32 count,
2028 XGL_UINT32 stride)
2029{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002030 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2031
2032 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002033}
2034
2035XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2036 XGL_CMD_BUFFER cmdBuffer,
2037 XGL_GPU_MEMORY mem,
2038 XGL_GPU_SIZE offset,
2039 XGL_UINT32 count,
2040 XGL_UINT32 stride)
2041{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002042 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2043
2044 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002045}
2046
2047XGL_VOID XGLAPI intelCmdDispatch(
2048 XGL_CMD_BUFFER cmdBuffer,
2049 XGL_UINT x,
2050 XGL_UINT y,
2051 XGL_UINT z)
2052{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002053 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2054
2055 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002056}
2057
2058XGL_VOID XGLAPI intelCmdDispatchIndirect(
2059 XGL_CMD_BUFFER cmdBuffer,
2060 XGL_GPU_MEMORY mem,
2061 XGL_GPU_SIZE offset)
2062{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002063 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2064
2065 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002066}