blob: 6460f94dd919ce5f09e857ecb5bb2d1681fa0e0a [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
Chia-I Wu9f039862014-08-20 15:39:56 +080025#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080026#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080027#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080028#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080029#include "pipeline.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080030#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080031#include "state.h"
32#include "view.h"
33#include "cmd_priv.h"
34
Chia-I Wu59c097e2014-08-21 10:51:07 +080035static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080036 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080037 uint32_t vertex_count,
38 uint32_t vertex_start,
39 uint32_t instance_count,
40 uint32_t instance_start,
41 uint32_t vertex_base)
42{
43 const uint8_t cmd_len = 6;
44 uint32_t dw0;
45
46 CMD_ASSERT(cmd, 6, 6);
47
Chia-I Wu426072d2014-08-26 14:31:55 +080048 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080049 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080050 (cmd_len - 2);
51
52 if (indexed)
53 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
54
Chia-I Wue24c3292014-08-21 14:05:23 +080055 cmd_batch_reserve(cmd, cmd_len);
56 cmd_batch_write(cmd, dw0);
57 cmd_batch_write(cmd, vertex_count);
58 cmd_batch_write(cmd, vertex_start);
59 cmd_batch_write(cmd, instance_count);
60 cmd_batch_write(cmd, instance_start);
61 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080062}
63
64static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080065 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080066 uint32_t vertex_count,
67 uint32_t vertex_start,
68 uint32_t instance_count,
69 uint32_t instance_start,
70 uint32_t vertex_base)
71{
72 const uint8_t cmd_len = 7;
73 uint32_t dw0, dw1;
74
75 CMD_ASSERT(cmd, 7, 7.5);
76
Chia-I Wu426072d2014-08-26 14:31:55 +080077 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080078 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080079
80 if (indexed)
81 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
82
Chia-I Wue24c3292014-08-21 14:05:23 +080083 cmd_batch_reserve(cmd, cmd_len);
84 cmd_batch_write(cmd, dw0);
85 cmd_batch_write(cmd, dw1);
86 cmd_batch_write(cmd, vertex_count);
87 cmd_batch_write(cmd, vertex_start);
88 cmd_batch_write(cmd, instance_count);
89 cmd_batch_write(cmd, instance_start);
90 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080091}
92
Chia-I Wu270b1e82014-08-25 15:53:39 +080093static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
94 struct intel_bo *bo, uint32_t bo_offset)
95{
96 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +080097 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +080098 (cmd_len - 2);
Chia-I Wu270b1e82014-08-25 15:53:39 +080099
100 CMD_ASSERT(cmd, 6, 7.5);
101
102 assert(bo_offset % 8 == 0);
103
104 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
105 /*
106 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
107 *
108 * "1 of the following must also be set (when CS stall is set):
109 *
110 * * Depth Cache Flush Enable ([0] of DW1)
111 * * Stall at Pixel Scoreboard ([1] of DW1)
112 * * Depth Stall ([13] of DW1)
113 * * Post-Sync Operation ([13] of DW1)
114 * * Render Target Cache Flush Enable ([12] of DW1)
115 * * Notify Enable ([8] of DW1)"
116 *
117 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
118 *
119 * "One of the following must also be set (when CS stall is set):
120 *
121 * * Render Target Cache Flush Enable ([12] of DW1)
122 * * Depth Cache Flush Enable ([0] of DW1)
123 * * Stall at Pixel Scoreboard ([1] of DW1)
124 * * Depth Stall ([13] of DW1)
125 * * Post-Sync Operation ([13] of DW1)"
126 */
127 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
128 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
129 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
130 GEN6_PIPE_CONTROL_DEPTH_STALL;
131
132 /* post-sync op */
133 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
134 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
135 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
136
137 if (cmd_gen(cmd) == INTEL_GEN(6))
138 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
139
140 assert(dw1 & bit_test);
141 }
142
143 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
144 /*
145 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
146 *
147 * "Following bits must be clear (when Depth Stall is set):
148 *
149 * * Render Target Cache Flush Enable ([12] of DW1)
150 * * Depth Cache Flush Enable ([0] of DW1)"
151 */
152 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
153 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
154 }
155
156 /*
157 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
158 *
159 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
160 * and PIPE_CONTROL are not supported."
161 *
162 * The kernel will add the mapping automatically (when write domain is
163 * INTEL_DOMAIN_INSTRUCTION).
164 */
165 if (cmd_gen(cmd) == INTEL_GEN(6) && bo)
166 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
167
168 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) bo);
169 cmd_batch_write(cmd, dw0);
170 cmd_batch_write(cmd, dw1);
Chia-I Wu32a22462014-08-26 14:13:46 +0800171 if (bo) {
172 cmd_batch_reloc(cmd, bo_offset, bo, INTEL_RELOC_GGTT |
173 INTEL_RELOC_WRITE);
174 } else {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800175 cmd_batch_write(cmd, 0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800176 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 cmd_batch_write(cmd, 0);
178 cmd_batch_write(cmd, 0);
179}
180
Chia-I Wu254db422014-08-21 11:54:29 +0800181static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
182{
183 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
184 bool supported;
185
186 CMD_ASSERT(cmd, 6, 7.5);
187
188 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
189 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
190
191 switch (p->prim_type) {
192 case GEN6_3DPRIM_POINTLIST:
193 case GEN6_3DPRIM_LINELIST:
194 case GEN6_3DPRIM_LINESTRIP:
195 case GEN6_3DPRIM_TRILIST:
196 case GEN6_3DPRIM_TRISTRIP:
197 supported = true;
198 break;
199 default:
200 supported = false;
201 break;
202 }
203
204 if (!supported)
205 return false;
206
207 switch (cmd->bind.index.type) {
208 case XGL_INDEX_8:
209 supported = (p->primitive_restart_index != 0xffu);
210 break;
211 case XGL_INDEX_16:
212 supported = (p->primitive_restart_index != 0xffffu);
213 break;
214 case XGL_INDEX_32:
215 supported = (p->primitive_restart_index != 0xffffffffu);
216 break;
217 default:
218 supported = false;
219 break;
220 }
221
222 return supported;
223}
224
Chia-I Wu59c097e2014-08-21 10:51:07 +0800225static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800226 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800227 XGL_GPU_SIZE offset,
228 XGL_INDEX_TYPE type,
229 bool enable_cut_index)
230{
231 const uint8_t cmd_len = 3;
232 uint32_t dw0, end_offset;
233 unsigned offset_align;
234
235 CMD_ASSERT(cmd, 6, 7.5);
236
Chia-I Wu426072d2014-08-26 14:31:55 +0800237 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238
239 /* the bit is moved to 3DSTATE_VF */
240 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
241 assert(!enable_cut_index);
242 if (enable_cut_index)
243 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
244
245 switch (type) {
246 case XGL_INDEX_8:
247 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
248 offset_align = 1;
249 break;
250 case XGL_INDEX_16:
251 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
252 offset_align = 2;
253 break;
254 case XGL_INDEX_32:
255 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
256 offset_align = 4;
257 break;
258 default:
259 cmd->result = XGL_ERROR_INVALID_VALUE;
260 return;
261 break;
262 }
263
264 if (offset % offset_align) {
265 cmd->result = XGL_ERROR_INVALID_VALUE;
266 return;
267 }
268
269 /* aligned and inclusive */
270 end_offset = mem->size - (mem->size % offset_align) - 1;
271
Chia-I Wu2de65d02014-08-25 10:02:53 +0800272 cmd_batch_reserve_reloc(cmd, cmd_len, 2);
Chia-I Wue24c3292014-08-21 14:05:23 +0800273 cmd_batch_write(cmd, dw0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800274 cmd_batch_reloc(cmd, offset, mem->bo, 0);
275 cmd_batch_reloc(cmd, end_offset, mem->bo, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800276}
277
Chia-I Wu62a7f252014-08-29 11:31:16 +0800278static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
279 bool enable_cut_index,
280 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800281{
282 const uint8_t cmd_len = 2;
283 uint32_t dw0;
284
285 CMD_ASSERT(cmd, 7.5, 7.5);
286
Chia-I Wu426072d2014-08-26 14:31:55 +0800287 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800288 if (enable_cut_index)
289 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
290
Chia-I Wue24c3292014-08-21 14:05:23 +0800291 cmd_batch_reserve(cmd, cmd_len);
292 cmd_batch_write(cmd, dw0);
293 cmd_batch_write(cmd, cut_index);
Chia-I Wu254db422014-08-21 11:54:29 +0800294}
295
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800296static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
297{
298 const uint8_t cmd_len = 7;
299 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
300
301 CMD_ASSERT(cmd, 6, 6);
302
303 assert(cmd->bind.gs.shader == NULL);
304
305 cmd_batch_reserve(cmd, cmd_len);
306 cmd_batch_write(cmd, dw0);
307 cmd_batch_write(cmd, 0);
308 cmd_batch_write(cmd, 0);
309 cmd_batch_write(cmd, 0);
310 cmd_batch_write(cmd, 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT);
311 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
312 cmd_batch_write(cmd, 0);
313}
314
Chia-I Wu62a7f252014-08-29 11:31:16 +0800315static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
316{
317 const uint8_t cmd_len = 7;
318 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
319
320 CMD_ASSERT(cmd, 7, 7.5);
321
322 assert(cmd->bind.gs.shader == NULL);
323
324 cmd_batch_reserve(cmd, cmd_len);
325 cmd_batch_write(cmd, dw0);
326 cmd_batch_write(cmd, 0);
327 cmd_batch_write(cmd, 0);
328 cmd_batch_write(cmd, 0);
329 cmd_batch_write(cmd, 0);
330 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
331 cmd_batch_write(cmd, 0);
332}
333
Chia-I Wud88e02d2014-08-25 10:56:13 +0800334static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
335 XGL_UINT width, XGL_UINT height)
336{
337 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800338 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800339 (cmd_len - 2);
340
341 CMD_ASSERT(cmd, 6, 7.5);
342
343 cmd_batch_reserve(cmd, cmd_len);
344 cmd_batch_write(cmd, dw0);
345 if (width && height) {
346 cmd_batch_write(cmd, 0);
347 cmd_batch_write(cmd, (height - 1) << 16 |
348 (width - 1));
349 } else {
350 cmd_batch_write(cmd, 1);
351 cmd_batch_write(cmd, 0);
352 }
353 cmd_batch_write(cmd, 0);
354}
355
Chia-I Wu8016a172014-08-29 18:31:32 +0800356static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
357 uint32_t body[6])
358{
359 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
360 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
361 const struct intel_raster_state *raster = cmd->bind.state.raster;
362 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
363 uint32_t dw1, dw2, dw3;
364 int point_width;
365
366 CMD_ASSERT(cmd, 6, 7.5);
367
368 dw1 = GEN7_SF_DW1_STATISTICS |
369 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
370 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
371 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
372 GEN7_SF_DW1_VIEWPORT_ENABLE |
373 raster->cmd_sf_fill;
374
375 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
376 int format;
377
378 switch (pipeline->db_format.channelFormat) {
379 case XGL_CH_FMT_R16:
380 format = GEN6_ZFORMAT_D16_UNORM;
381 break;
382 case XGL_CH_FMT_R32:
383 case XGL_CH_FMT_R32G8:
384 format = GEN6_ZFORMAT_D32_FLOAT;
385 break;
386 default:
387 assert(!"unknown depth format");
388 format = 0;
389 break;
390 }
391
392 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
393 }
394
395 dw2 = raster->cmd_sf_cull;
396
397 if (msaa->sample_count > 1) {
398 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
399 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
400 } else {
401 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
402 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
403 }
404
405 if (viewport->scissor_enable)
406 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
407
408 /* in U8.3 */
409 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
410 point_width = U_CLAMP(point_width, 1, 2047);
411
412 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
413 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
414 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
415 GEN7_SF_DW3_SUBPIXEL_8BITS |
416 GEN7_SF_DW3_USE_POINT_WIDTH |
417 point_width;
418
419 body[0] = dw1;
420 body[1] = dw2;
421 body[2] = dw3;
422 body[3] = raster->cmd_depth_offset_const;
423 body[4] = raster->cmd_depth_offset_scale;
424 body[5] = raster->cmd_depth_offset_clamp;
425}
426
427static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
428 uint32_t body[13])
429{
430 const struct intel_shader *vs =
431 intel_shader(cmd->bind.pipeline.graphics->vs.shader);
432 const struct intel_shader *fs =
433 intel_shader(cmd->bind.pipeline.graphics->fs.shader);
434 XGL_UINT attr_skip, attr_count;
435 XGL_UINT vue_offset, vue_len;
436 XGL_UINT i;
437 uint32_t dw1;
438
439 CMD_ASSERT(cmd, 6, 7.5);
440
441 /* VS outputs VUE header and position additionally */
442 assert(vs->out_count >= 2);
443 attr_skip = 2;
444 attr_count = vs->out_count - attr_skip;
445 assert(fs->in_count == attr_count);
446 assert(fs->in_count <= 32);
447
448 vue_offset = attr_skip / 2;
449 vue_len = (attr_count + 1) / 2;
450 if (!vue_len)
451 vue_len = 1;
452
453 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
454 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
455 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
456
457 body[0] = dw1;
458
459 for (i = 0; i < 8; i++) {
460 uint16_t hi, lo;
461
462 /* no attr swizzles */
463 if (i * 2 + 1 < fs->in_count) {
464 hi = i * 2 + 1;
465 lo = i * 2;
466 } else if (i * 2 < fs->in_count) {
467 hi = 0;
468 lo = i * 2;
469 } else {
470 hi = 0;
471 lo = 0;
472 }
473
474 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
475 }
476
477 body[9] = 0; /* point sprite enables */
478 body[10] = 0; /* constant interpolation enables */
479 body[11] = 0; /* WrapShortest enables */
480 body[12] = 0;
481}
482
483static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
484{
485 const uint8_t cmd_len = 20;
486 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
487 (cmd_len - 2);
488 uint32_t sf[6];
489 uint32_t sbe[13];
490
491 CMD_ASSERT(cmd, 6, 6);
492
493 gen7_fill_3DSTATE_SF_body(cmd, sf);
494 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
495
496 cmd_batch_reserve(cmd, cmd_len);
497 cmd_batch_write(cmd, dw0);
498 cmd_batch_write(cmd, sbe[0]);
499 cmd_batch_write_n(cmd, sf, 6);
500 cmd_batch_write_n(cmd, &sbe[1], 12);
501}
502
503static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
504{
505 const uint8_t cmd_len = 7;
506 uint32_t dw[7];
507
508 CMD_ASSERT(cmd, 7, 7.5);
509
510 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
511 (cmd_len - 2);
512 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
513
514 cmd_batch_reserve(cmd, cmd_len);
515 cmd_batch_write_n(cmd, dw, cmd_len);
516}
517
518static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
519{
520 const uint8_t cmd_len = 14;
521 uint32_t dw[14];
522
523 CMD_ASSERT(cmd, 7, 7.5);
524
525 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
526 (cmd_len - 2);
527 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
528
529 cmd_batch_reserve(cmd, cmd_len);
530 cmd_batch_write_n(cmd, dw, cmd_len);
531}
532
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800533static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
534{
535 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
536 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
537 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
538 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
539 const uint8_t cmd_len = 9;
540 uint32_t dw0, dw2, dw4, dw5, dw6;
541
542 CMD_ASSERT(cmd, 6, 6);
543
544 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
545
546 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
547 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
548
549 dw4 = GEN6_WM_DW4_STATISTICS |
550 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
551 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
552 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
553
554 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
555 GEN6_WM_DW5_PS_ENABLE |
556 GEN6_WM_DW5_8_PIXEL_DISPATCH;
557
558 if (fs->uses & INTEL_SHADER_USE_KILL ||
559 pipeline->cb_state.alphaToCoverageEnable)
560 dw5 |= GEN6_WM_DW5_PS_KILL;
561
562 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
563 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
564 if (fs->uses & INTEL_SHADER_USE_DEPTH)
565 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
566 if (fs->uses & INTEL_SHADER_USE_W)
567 dw5 |= GEN6_WM_DW5_PS_USE_W;
568
569 if (pipeline->cb_state.dualSourceBlendEnable)
570 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
571
572 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
573 GEN6_WM_DW6_POSOFFSET_NONE |
574 GEN6_WM_DW6_ZW_INTERP_PIXEL |
575 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
576 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
577
578 if (msaa->sample_count > 1) {
579 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
580 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
581 } else {
582 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
583 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
584 }
585
586 cmd_batch_reserve(cmd, cmd_len);
587 cmd_batch_write(cmd, dw0);
588 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
589 cmd_batch_write(cmd, dw2);
590 cmd_batch_write(cmd, 0); /* scratch */
591 cmd_batch_write(cmd, dw4);
592 cmd_batch_write(cmd, dw5);
593 cmd_batch_write(cmd, dw6);
594 cmd_batch_write(cmd, 0); /* kernel 1 */
595 cmd_batch_write(cmd, 0); /* kernel 2 */
596}
597
598static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
599{
600 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
601 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
602 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
603 const uint8_t cmd_len = 3;
604 uint32_t dw0, dw1, dw2;
605
606 CMD_ASSERT(cmd, 7, 7.5);
607
608 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
609
610 dw1 = GEN7_WM_DW1_STATISTICS |
611 GEN7_WM_DW1_PS_ENABLE |
612 GEN7_WM_DW1_ZW_INTERP_PIXEL |
613 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
614 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
615
616 if (fs->uses & INTEL_SHADER_USE_KILL ||
617 pipeline->cb_state.alphaToCoverageEnable)
618 dw1 |= GEN7_WM_DW1_PS_KILL;
619
620 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
621 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
622 if (fs->uses & INTEL_SHADER_USE_DEPTH)
623 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
624 if (fs->uses & INTEL_SHADER_USE_W)
625 dw1 |= GEN7_WM_DW1_PS_USE_W;
626
627 dw2 = 0;
628
629 if (msaa->sample_count > 1) {
630 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
631 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
632 } else {
633 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
634 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
635 }
636
637 cmd_batch_reserve(cmd, cmd_len);
638 cmd_batch_write(cmd, dw0);
639 cmd_batch_write(cmd, dw1);
640 cmd_batch_write(cmd, dw2);
641}
642
643static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
644{
645 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
646 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
647 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
648 const uint8_t cmd_len = 8;
649 uint32_t dw0, dw2, dw4, dw5;
650
651 CMD_ASSERT(cmd, 7, 7.5);
652
653 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
654
655 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
656 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
657
658 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
659 GEN7_PS_DW4_8_PIXEL_DISPATCH;
660
661 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
662 const int max_threads =
663 (cmd->dev->gpu->gt == 3) ? 408 :
664 (cmd->dev->gpu->gt == 2) ? 204 : 102;
665 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
666 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
667 } else {
668 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
669 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
670 }
671
672 if (pipeline->fs.linkConstBufferCount)
673 dw4 |= GEN7_PS_DW4_PUSH_CONSTANT_ENABLE;
674
675 if (fs->in_count)
676 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
677
678 if (pipeline->cb_state.dualSourceBlendEnable)
679 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
680
681 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
682 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
683 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
684
685 cmd_batch_reserve(cmd, cmd_len);
686 cmd_batch_write(cmd, dw0);
687 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
688 cmd_batch_write(cmd, dw2);
689 cmd_batch_write(cmd, 0); /* scratch */
690 cmd_batch_write(cmd, dw4);
691 cmd_batch_write(cmd, dw5);
692 cmd_batch_write(cmd, 0); /* kernel 1 */
693 cmd_batch_write(cmd, 0); /* kernel 2 */
694}
695
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800696static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
697 const struct intel_ds_view *view)
698{
699 const uint8_t cmd_len = 7;
700 uint32_t dw0;
701
702 CMD_ASSERT(cmd, 6, 7.5);
703
704 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800705 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
706 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800707 dw0 |= (cmd_len - 2);
708
Chia-I Wu2de65d02014-08-25 10:02:53 +0800709 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800710 cmd_batch_write(cmd, dw0);
711 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600712 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800713 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800714 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600715 } else {
716 cmd_batch_write(cmd, 0);
717 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800718 cmd_batch_write(cmd, view->cmd[2]);
719 cmd_batch_write(cmd, view->cmd[3]);
720 cmd_batch_write(cmd, view->cmd[4]);
721 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800722}
723
724static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
725 const struct intel_ds_view *view)
726{
727 const uint8_t cmd_len = 3;
728 uint32_t dw0;
729
730 CMD_ASSERT(cmd, 6, 7.5);
731
732 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800733 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
734 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800735 dw0 |= (cmd_len - 2);
736
Chia-I Wu2de65d02014-08-25 10:02:53 +0800737 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800738 cmd_batch_write(cmd, dw0);
739 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600740 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800741 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800742 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600743 } else {
744 cmd_batch_write(cmd, 0);
745 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800746}
747
748static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
749 const struct intel_ds_view *view)
750{
751 const uint8_t cmd_len = 3;
752 uint32_t dw0;
753
754 CMD_ASSERT(cmd, 6, 7.5);
755
756 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800757 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
758 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800759 dw0 |= (cmd_len - 2);
760
Chia-I Wu2de65d02014-08-25 10:02:53 +0800761 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800762 cmd_batch_write(cmd, dw0);
763 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600764 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800765 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800766 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600767 } else {
768 cmd_batch_write(cmd, 0);
769 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800770}
771
Chia-I Wuf8231032014-08-25 10:44:45 +0800772static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
773 uint32_t clear_val)
774{
775 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800776 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800777 GEN6_CLEAR_PARAMS_DW0_VALID |
778 (cmd_len - 2);
779
780 CMD_ASSERT(cmd, 6, 6);
781
782 cmd_batch_reserve(cmd, cmd_len);
783 cmd_batch_write(cmd, dw0);
784 cmd_batch_write(cmd, clear_val);
785}
786
787static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
788 uint32_t clear_val)
789{
790 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800791 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800792 (cmd_len - 2);
793
794 CMD_ASSERT(cmd, 7, 7.5);
795
796 cmd_batch_reserve(cmd, cmd_len);
797 cmd_batch_write(cmd, dw0);
798 cmd_batch_write(cmd, clear_val);
799 cmd_batch_write(cmd, 1);
800}
801
Chia-I Wu302742d2014-08-22 10:28:29 +0800802static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
803 XGL_UINT blend_pos,
804 XGL_UINT ds_pos,
805 XGL_UINT cc_pos)
806{
807 const uint8_t cmd_len = 4;
808 uint32_t dw0;
809
810 CMD_ASSERT(cmd, 6, 6);
811
Chia-I Wu426072d2014-08-26 14:31:55 +0800812 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800813 (cmd_len - 2);
814
815 cmd_batch_reserve(cmd, cmd_len);
816 cmd_batch_write(cmd, dw0);
817 cmd_batch_write(cmd, (blend_pos << 2) | 1);
818 cmd_batch_write(cmd, (ds_pos << 2) | 1);
819 cmd_batch_write(cmd, (cc_pos << 2) | 1);
820}
821
Chia-I Wu1744cca2014-08-22 11:10:17 +0800822static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
823 XGL_UINT clip_pos,
824 XGL_UINT sf_pos,
825 XGL_UINT cc_pos)
826{
827 const uint8_t cmd_len = 4;
828 uint32_t dw0;
829
830 CMD_ASSERT(cmd, 6, 6);
831
Chia-I Wu426072d2014-08-26 14:31:55 +0800832 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800833 GEN6_PTR_VP_DW0_CLIP_CHANGED |
834 GEN6_PTR_VP_DW0_SF_CHANGED |
835 GEN6_PTR_VP_DW0_CC_CHANGED |
836 (cmd_len - 2);
837
838 cmd_batch_reserve(cmd, cmd_len);
839 cmd_batch_write(cmd, dw0);
840 cmd_batch_write(cmd, clip_pos << 2);
841 cmd_batch_write(cmd, sf_pos << 2);
842 cmd_batch_write(cmd, cc_pos << 2);
843}
844
845static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
846 XGL_UINT scissor_pos)
847{
848 const uint8_t cmd_len = 2;
849 uint32_t dw0;
850
851 CMD_ASSERT(cmd, 6, 6);
852
Chia-I Wu426072d2014-08-26 14:31:55 +0800853 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800854 (cmd_len - 2);
855
856 cmd_batch_reserve(cmd, cmd_len);
857 cmd_batch_write(cmd, dw0);
858 cmd_batch_write(cmd, scissor_pos << 2);
859}
860
Chia-I Wu42a56202014-08-23 16:47:48 +0800861static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
862 XGL_UINT vs_pos,
863 XGL_UINT gs_pos,
864 XGL_UINT ps_pos)
865{
866 const uint8_t cmd_len = 4;
867 uint32_t dw0;
868
869 CMD_ASSERT(cmd, 6, 6);
870
Chia-I Wu426072d2014-08-26 14:31:55 +0800871 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800872 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
873 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
874 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
875 (cmd_len - 2);
876
877 cmd_batch_reserve(cmd, cmd_len);
878 cmd_batch_write(cmd, dw0);
879 cmd_batch_write(cmd, vs_pos << 2);
880 cmd_batch_write(cmd, gs_pos << 2);
881 cmd_batch_write(cmd, ps_pos << 2);
882}
883
Chia-I Wu257e75e2014-08-29 14:06:35 +0800884static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
885 XGL_UINT vs_pos,
886 XGL_UINT gs_pos,
887 XGL_UINT ps_pos)
888{
889 const uint8_t cmd_len = 4;
890 uint32_t dw0;
891
892 CMD_ASSERT(cmd, 6, 6);
893
894 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
895 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
896 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
897 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
898 (cmd_len - 2);
899
900 cmd_batch_reserve(cmd, cmd_len);
901 cmd_batch_write(cmd, dw0);
902 cmd_batch_write(cmd, vs_pos << 2);
903 cmd_batch_write(cmd, gs_pos << 2);
904 cmd_batch_write(cmd, ps_pos << 2);
905}
906
Chia-I Wu302742d2014-08-22 10:28:29 +0800907static void gen7_3dstate_pointer(struct intel_cmd *cmd,
908 int subop, XGL_UINT pos)
909{
910 const uint8_t cmd_len = 2;
911 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
912 GEN6_RENDER_SUBTYPE_3D |
913 subop | (cmd_len - 2);
914
915 cmd_batch_reserve(cmd, cmd_len);
916 cmd_batch_write(cmd, dw0);
917 cmd_batch_write(cmd, pos << 2);
918}
919
920static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
921 const struct intel_blend_state *state)
922{
923 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
924 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
925
926 CMD_ASSERT(cmd, 6, 7.5);
927 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
928
929 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
930}
931
932static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
933 const struct intel_ds_state *state)
934{
935 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
936 const uint8_t cmd_len = 3;
937
938 CMD_ASSERT(cmd, 6, 7.5);
939 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
940
941 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
942}
943
944static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
945 uint32_t stencil_ref,
946 const uint32_t blend_color[4])
947{
948 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
949 const uint8_t cmd_len = 6;
950 XGL_UINT pos;
951 uint32_t *dw;
952
953 CMD_ASSERT(cmd, 6, 7.5);
954
955 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
956 dw[0] = stencil_ref;
957 dw[1] = 0;
958 dw[2] = blend_color[0];
959 dw[3] = blend_color[1];
960 dw[4] = blend_color[2];
961 dw[5] = blend_color[3];
962 cmd_state_advance(cmd, cmd_len);
963
964 return pos;
965}
966
Chia-I Wu8370b402014-08-29 12:28:37 +0800967static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +0800968{
Chia-I Wu8370b402014-08-29 12:28:37 +0800969 CMD_ASSERT(cmd, 6, 7.5);
970
Chia-I Wu707a29e2014-08-27 12:51:47 +0800971 if (!cmd->bind.draw_count)
972 return;
973
Chia-I Wu8370b402014-08-29 12:28:37 +0800974 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +0800975 return;
976
Chia-I Wu8370b402014-08-29 12:28:37 +0800977 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +0800978
979 /*
980 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
981 *
982 * "Pipe-control with CS-stall bit set must be sent BEFORE the
983 * pipe-control with a post-sync op and no write-cache flushes."
984 *
985 * The workaround below necessitates this workaround.
986 */
987 gen6_PIPE_CONTROL(cmd,
988 GEN6_PIPE_CONTROL_CS_STALL |
989 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
990 NULL, 0);
991
Chia-I Wu8370b402014-08-29 12:28:37 +0800992 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, cmd->scratch_bo, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +0800993}
994
Chia-I Wu8370b402014-08-29 12:28:37 +0800995static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -0600996{
Chia-I Wu48c283d2014-08-25 23:13:46 +0800997 CMD_ASSERT(cmd, 6, 7.5);
998
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800999 if (!cmd->bind.draw_count)
1000 return;
1001
Chia-I Wu8370b402014-08-29 12:28:37 +08001002 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL, NULL, 0);
1003}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001004
Chia-I Wu8370b402014-08-29 12:28:37 +08001005static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1006{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001007 CMD_ASSERT(cmd, 7, 7.5);
1008
Chia-I Wu8370b402014-08-29 12:28:37 +08001009 if (!cmd->bind.draw_count)
1010 return;
1011
1012 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001013
1014 gen6_PIPE_CONTROL(cmd,
1015 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
1016 cmd->scratch_bo, 0);
1017}
1018
Chia-I Wu8370b402014-08-29 12:28:37 +08001019static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1020{
1021 CMD_ASSERT(cmd, 7, 7.5);
1022
1023 if (!cmd->bind.draw_count)
1024 return;
1025
1026 /*
1027 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1028 *
1029 * "One of the following must also be set (when CS stall is set):
1030 *
1031 * * Render Target Cache Flush Enable ([12] of DW1)
1032 * * Depth Cache Flush Enable ([0] of DW1)
1033 * * Stall at Pixel Scoreboard ([1] of DW1)
1034 * * Depth Stall ([13] of DW1)
1035 * * Post-Sync Operation ([13] of DW1)"
1036 */
1037 gen6_PIPE_CONTROL(cmd,
1038 GEN6_PIPE_CONTROL_CS_STALL |
1039 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1040 NULL, 0);
1041}
1042
1043static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1044{
1045 CMD_ASSERT(cmd, 7, 7.5);
1046
1047 if (!cmd->bind.draw_count)
1048 return;
1049
1050 cmd_wa_gen6_pre_depth_stall_write(cmd);
1051
1052 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
1053}
1054
1055static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1056{
1057 CMD_ASSERT(cmd, 6, 7.5);
1058
1059 if (!cmd->bind.draw_count)
1060 return;
1061
1062 /*
1063 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1064 *
1065 * "Driver must guarentee that all the caches in the depth pipe are
1066 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1067 * requires driver to send a PIPE_CONTROL with a CS stall along with
1068 * a Depth Flush prior to this command."
1069 *
1070 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1071 *
1072 * "Driver must ierarchi that all the caches in the depth pipe are
1073 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1074 * requires driver to send a PIPE_CONTROL with a CS stall along with
1075 * a Depth Flush prior to this command.
1076 */
1077 gen6_PIPE_CONTROL(cmd,
1078 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1079 GEN6_PIPE_CONTROL_CS_STALL,
1080 0, 0);
1081}
1082
1083static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1084{
1085 CMD_ASSERT(cmd, 6, 7.5);
1086
1087 if (!cmd->bind.draw_count)
1088 return;
1089
1090 /*
1091 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1092 *
1093 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1094 * and a post sync operation prior to the group of depth
1095 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1096 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1097 *
1098 * This workaround satifies all the conditions.
1099 */
1100 cmd_wa_gen6_pre_depth_stall_write(cmd);
1101
1102 /*
1103 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1104 *
1105 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1106 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1107 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1108 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1109 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1110 * Depth Flush Bit set, followed by another pipelined depth stall
1111 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1112 * guarantee that the pipeline from WM onwards is already flushed
1113 * (e.g., via a preceding MI_FLUSH)."
1114 */
1115 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
1116 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
1117 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
1118}
1119
Chia-I Wu525c6602014-08-27 10:22:34 +08001120void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1121{
1122 if (!cmd->bind.draw_count)
1123 return;
1124
1125 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1126
Chia-I Wu8370b402014-08-29 12:28:37 +08001127 /*
1128 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1129 *
1130 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1131 * PIPE_CONTROL with any non-zero post-sync-op is required."
1132 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001133 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001134 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001135
1136 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0);
1137}
1138
Chia-I Wu302742d2014-08-22 10:28:29 +08001139static void gen6_cc_states(struct intel_cmd *cmd)
1140{
1141 const struct intel_blend_state *blend = cmd->bind.state.blend;
1142 const struct intel_ds_state *ds = cmd->bind.state.ds;
1143 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001144 uint32_t stencil_ref;
1145 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001146
1147 CMD_ASSERT(cmd, 6, 6);
1148
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001149 if (blend) {
1150 blend_pos = gen6_BLEND_STATE(cmd, blend);
1151 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1152 } else {
1153 blend_pos = 0;
1154 memset(blend_color, 0, sizeof(blend_color));
1155 }
1156
1157 if (ds) {
1158 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1159 stencil_ref = ds->cmd_stencil_ref;
1160 } else {
1161 ds_pos = 0;
1162 stencil_ref = 0;
1163 }
1164
1165 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001166
1167 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
1168}
1169
Chia-I Wu1744cca2014-08-22 11:10:17 +08001170static void gen6_viewport_states(struct intel_cmd *cmd)
1171{
1172 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1173 XGL_UINT pos;
1174
1175 if (!viewport)
1176 return;
1177
1178 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1179 viewport->cmd_align);
1180
1181 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
1182 pos + viewport->cmd_clip_offset,
1183 pos,
1184 pos + viewport->cmd_cc_offset);
1185
1186 pos = (viewport->scissor_enable) ?
1187 pos + viewport->cmd_scissor_rect_offset : 0;
1188
1189 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
1190}
1191
Chia-I Wu302742d2014-08-22 10:28:29 +08001192static void gen7_cc_states(struct intel_cmd *cmd)
1193{
1194 const struct intel_blend_state *blend = cmd->bind.state.blend;
1195 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001196 uint32_t stencil_ref;
1197 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001198 XGL_UINT pos;
1199
1200 CMD_ASSERT(cmd, 7, 7.5);
1201
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001202 if (!blend && !ds)
1203 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001204
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001205 if (blend) {
1206 pos = gen6_BLEND_STATE(cmd, blend);
1207 gen7_3dstate_pointer(cmd,
1208 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +08001209
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001210 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1211 } else {
1212 memset(blend_color, 0, sizeof(blend_color));
1213 }
1214
1215 if (ds) {
1216 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1217 gen7_3dstate_pointer(cmd,
1218 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
1219 } else {
1220 stencil_ref = 0;
1221 }
1222
1223 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001224 gen7_3dstate_pointer(cmd,
1225 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
1226}
1227
Chia-I Wu1744cca2014-08-22 11:10:17 +08001228static void gen7_viewport_states(struct intel_cmd *cmd)
1229{
1230 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1231 XGL_UINT pos;
1232
1233 if (!viewport)
1234 return;
1235
1236 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1237 viewport->cmd_align);
1238
1239 gen7_3dstate_pointer(cmd,
1240 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
1241 gen7_3dstate_pointer(cmd,
1242 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
1243 pos + viewport->cmd_cc_offset);
1244 if (viewport->scissor_enable) {
1245 gen7_3dstate_pointer(cmd,
1246 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1247 pos + viewport->cmd_scissor_rect_offset);
1248 }
1249}
1250
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001251static void gen6_pcb(struct intel_cmd *cmd, int subop,
1252 const XGL_PIPELINE_SHADER *sh)
1253{
1254 const uint8_t cmd_len = 5;
1255 const XGL_UINT alignment = 32;
1256 const XGL_UINT max_size =
1257 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
1258 const XGL_UINT max_pcb = 4;
1259 uint32_t pcb[4] = { 0, 0, 0, 0 };
1260 XGL_FLAGS pcb_enables = 0;
1261 XGL_SIZE total_size = 0;
1262 uint32_t dw0;
1263 XGL_UINT i;
1264
1265 for (i = 0; i < sh->linkConstBufferCount; i++) {
1266 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1267 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1268 void *ptr;
1269
1270 if (info->bufferId >= max_pcb ||
1271 pcb_enables & ((1 << info->bufferId)) ||
1272 total_size + info->bufferSize > max_size) {
1273 cmd->result = XGL_ERROR_UNKNOWN;
1274 return;
1275 }
1276 if (!size)
1277 continue;
1278
1279 pcb_enables |= 1 << info->bufferId;
1280 total_size += size;
1281
1282 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1283 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1284 memcpy(ptr, info->pBufferData, info->bufferSize);
1285 cmd_state_advance(cmd, size / sizeof(uint32_t));
1286
1287 pcb[info->bufferId] |= size / alignment - 1;
1288 }
1289
1290 dw0 = GEN6_RENDER_TYPE_RENDER |
1291 GEN6_RENDER_SUBTYPE_3D |
1292 subop |
1293 pcb_enables << 12 |
1294 (cmd_len - 2);
1295
1296 cmd_batch_reserve(cmd, cmd_len);
1297 cmd_batch_write(cmd, dw0);
1298 cmd_batch_write(cmd, pcb[0]);
1299 cmd_batch_write(cmd, pcb[1]);
1300 cmd_batch_write(cmd, pcb[2]);
1301 cmd_batch_write(cmd, pcb[3]);
1302}
1303
1304static void gen7_pcb(struct intel_cmd *cmd, int subop,
1305 const XGL_PIPELINE_SHADER *sh)
1306{
1307 const uint8_t cmd_len = 7;
1308 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1309 GEN6_RENDER_SUBTYPE_3D |
1310 subop |
1311 (cmd_len - 2);
1312 const XGL_UINT alignment = 32;
1313 const XGL_UINT max_size = 2048;
1314 const XGL_UINT max_pcb = 4;
1315 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
1316 uint32_t pcb[4] = { 0, 0, 0, 0 };
1317 XGL_FLAGS pcb_enables = 0;
1318 XGL_SIZE total_size = 0;
1319 XGL_UINT i;
1320
1321 for (i = 0; i < sh->linkConstBufferCount; i++) {
1322 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1323 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1324 void *ptr;
1325
1326 if (info->bufferId >= max_pcb ||
1327 pcb_enables & ((1 << info->bufferId)) ||
1328 total_size + info->bufferSize > max_size) {
1329 cmd->result = XGL_ERROR_UNKNOWN;
1330 return;
1331 }
1332 if (!size)
1333 continue;
1334
1335 pcb_enables |= 1 << info->bufferId;
1336 total_size += size;
1337
1338 pcb_len[info->bufferId] = size / alignment;
1339
1340 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1341 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1342 memcpy(ptr, info->pBufferData, info->bufferSize);
1343 cmd_state_advance(cmd, size / sizeof(uint32_t));
1344 }
1345
1346 /* no holes */
1347 if (!u_is_pow2(pcb_enables + 1)) {
1348 cmd->result = XGL_ERROR_UNKNOWN;
1349 return;
1350 }
1351
1352 cmd_batch_reserve(cmd, cmd_len);
1353 cmd_batch_write(cmd, dw0);
1354 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
1355 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
1356 cmd_batch_write(cmd, pcb[0]);
1357 cmd_batch_write(cmd, pcb[1]);
1358 cmd_batch_write(cmd, pcb[2]);
1359 cmd_batch_write(cmd, pcb[3]);
1360}
1361
Chia-I Wu42a56202014-08-23 16:47:48 +08001362static void emit_ps_resources(struct intel_cmd *cmd,
1363 const struct intel_rmap *rmap)
1364{
1365 const XGL_UINT surface_count = rmap->rt_count +
1366 rmap->resource_count + rmap->uav_count;
1367 uint32_t binding_table[256];
1368 XGL_UINT pos, i;
1369
1370 assert(surface_count <= ARRAY_SIZE(binding_table));
1371
1372 for (i = 0; i < surface_count; i++) {
1373 const struct intel_rmap_slot *slot = &rmap->slots[i];
1374 uint32_t *dw;
1375
1376 switch (slot->path_len) {
1377 case 0:
1378 pos = 0;
1379 break;
1380 case INTEL_RMAP_SLOT_RT:
1381 {
1382 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1383
1384 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1385 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1386
1387 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001388 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001389 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001390 cmd_state_advance(cmd, view->cmd_len);
1391 }
1392 break;
1393 case INTEL_RMAP_SLOT_DYN:
1394 {
1395 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001396 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001397
1398 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1399 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1400
1401 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001402 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001403 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001404 cmd_state_advance(cmd, view->cmd_len);
1405 }
1406 break;
1407 case 1:
1408 default:
1409 /* TODO */
1410 assert(!"no dset support");
1411 break;
1412 }
1413
1414 binding_table[i] = pos << 2;
1415 }
1416
1417 pos = cmd_state_copy(cmd, binding_table, surface_count,
1418 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
1419
1420 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1421 gen7_3dstate_pointer(cmd,
1422 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001423
1424 gen7_3dstate_pointer(cmd,
1425 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1426 gen7_3dstate_pointer(cmd,
1427 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1428 gen7_3dstate_pointer(cmd,
1429 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1430 gen7_3dstate_pointer(cmd,
1431 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1432
1433 gen7_3dstate_pointer(cmd,
1434 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1435 gen7_3dstate_pointer(cmd,
1436 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1437 gen7_3dstate_pointer(cmd,
1438 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1439 gen7_3dstate_pointer(cmd,
1440 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1441 gen7_3dstate_pointer(cmd,
1442 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001443 } else {
1444 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001445 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001446 }
1447}
1448
Chia-I Wu52500102014-08-22 00:46:04 +08001449static void emit_bounded_states(struct intel_cmd *cmd)
1450{
1451 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1452
1453 /* TODO more states */
1454
Chia-I Wu1744cca2014-08-22 11:10:17 +08001455 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001456 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001457 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001458
1459 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1460 &cmd->bind.pipeline.graphics->vs);
1461 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1462 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001463
Chia-I Wu8016a172014-08-29 18:31:32 +08001464 gen7_3DSTATE_SF(cmd);
1465 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001466 gen7_3DSTATE_WM(cmd);
1467 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001468 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001469 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001470 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001471
1472 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1473 &cmd->bind.pipeline.graphics->vs);
1474 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1475 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001476
Chia-I Wu8016a172014-08-29 18:31:32 +08001477 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001478 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001479 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001480
Chia-I Wu42a56202014-08-23 16:47:48 +08001481 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1482
Chia-I Wu8370b402014-08-29 12:28:37 +08001483 cmd_wa_gen6_pre_depth_stall_write(cmd);
1484 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001485 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001486 cmd_batch_reserve(cmd, msaa->cmd_len);
1487 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001488}
1489
1490static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001491 const struct intel_pipe_shader *shader,
1492 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001493{
1494 uint32_t i;
1495 struct intel_cmd_shader *cmdShader;
1496
1497 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001498 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001499 /* shader is already part of pipeline */
1500 return;
1501 }
1502 }
1503
Chia-I Wu338fe642014-08-28 10:43:04 +08001504 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1505 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1506
1507 cmdShader = cmd->bind.shaderCache.shaderArray;
1508
1509 cmd->bind.shaderCache.shaderArray =
1510 icd_alloc(sizeof(*cmdShader) * new_count,
1511 0, XGL_SYSTEM_ALLOC_INTERNAL);
1512 if (cmd->bind.shaderCache.shaderArray == NULL) {
1513 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001514 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1515 return;
1516 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001517
1518 if (cmdShader) {
1519 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1520 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1521 icd_free(cmdShader);
1522 }
1523
1524 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001525 }
1526
Chia-I Wu338fe642014-08-28 10:43:04 +08001527 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001528 cmdShader->shader = shader;
1529 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001530 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001531 cmd->bind.shaderCache.used++;
1532 return;
1533}
1534
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001535static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001536 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001537{
1538 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001539
Chia-I Wu8370b402014-08-29 12:28:37 +08001540 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1541 cmd_wa_gen6_pre_depth_stall_write(cmd);
1542 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1543 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1544 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1545 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001546
1547 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001548 assert(pipeline->cmd_len);
Chia-I Wub08727d2014-08-29 14:54:54 +08001549 cmd_batch_reserve(cmd, pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001550 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001551
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001552 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001553 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001554 }
1555 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001556 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001557 }
1558 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001559 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001560 }
1561 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001562 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001563 }
1564 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001565 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001566 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001567
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001568 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1569 gen7_3DSTATE_GS(cmd);
1570 } else {
1571 gen6_3DSTATE_GS(cmd);
1572 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001573
Chia-I Wu8370b402014-08-29 12:28:37 +08001574 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1575 cmd_wa_gen7_post_command_cs_stall(cmd);
1576 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1577 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001578}
1579
1580static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1581 const struct intel_pipeline *pipeline)
1582{
1583 cmd->bind.pipeline.compute = pipeline;
1584}
1585
1586static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1587 const struct intel_pipeline_delta *delta)
1588{
1589 cmd->bind.pipeline.graphics_delta = delta;
1590}
1591
1592static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1593 const struct intel_pipeline_delta *delta)
1594{
1595 cmd->bind.pipeline.compute_delta = delta;
1596}
1597
1598static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1599 const struct intel_dset *dset,
1600 XGL_UINT slot_offset)
1601{
1602 cmd->bind.dset.graphics = dset;
1603 cmd->bind.dset.graphics_offset = slot_offset;
1604}
1605
1606static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1607 const struct intel_dset *dset,
1608 XGL_UINT slot_offset)
1609{
1610 cmd->bind.dset.compute = dset;
1611 cmd->bind.dset.compute_offset = slot_offset;
1612}
1613
1614static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1615 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1616{
1617 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1618}
1619
1620static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1621 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1622{
1623 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1624}
1625
1626static void cmd_bind_index_data(struct intel_cmd *cmd,
1627 const struct intel_mem *mem,
1628 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1629{
1630 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1631 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1632 } else {
1633 cmd->bind.index.mem = mem;
1634 cmd->bind.index.offset = offset;
1635 cmd->bind.index.type = type;
1636 }
1637}
1638
1639static void cmd_bind_rt(struct intel_cmd *cmd,
1640 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1641 XGL_UINT count)
1642{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001643 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001644 XGL_UINT i;
1645
1646 for (i = 0; i < count; i++) {
1647 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1648 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001649 const struct intel_layout *layout = &rt->img->layout;
1650
1651 if (i == 0) {
1652 width = layout->width0;
1653 height = layout->height0;
1654 } else {
1655 if (width > layout->width0)
1656 width = layout->width0;
1657 if (height > layout->height0)
1658 height = layout->height0;
1659 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001660
1661 cmd->bind.att.rt[i] = rt;
1662 }
1663
1664 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001665
Chia-I Wu8370b402014-08-29 12:28:37 +08001666 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001667 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001668}
1669
1670static void cmd_bind_ds(struct intel_cmd *cmd,
1671 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1672{
1673 const struct intel_ds_view *ds;
1674
1675 if (info) {
1676 cmd->bind.att.ds = intel_ds_view(info->view);
1677 ds = cmd->bind.att.ds;
1678 } else {
1679 /* all zeros */
1680 static const struct intel_ds_view null_ds;
1681 ds = &null_ds;
1682 }
1683
Chia-I Wu8370b402014-08-29 12:28:37 +08001684 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001685 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1686 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1687 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001688
1689 if (cmd_gen(cmd) >= INTEL_GEN(7))
1690 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1691 else
1692 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001693}
1694
1695static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1696 const struct intel_viewport_state *state)
1697{
1698 cmd->bind.state.viewport = state;
1699}
1700
1701static void cmd_bind_raster_state(struct intel_cmd *cmd,
1702 const struct intel_raster_state *state)
1703{
1704 cmd->bind.state.raster = state;
1705}
1706
1707static void cmd_bind_ds_state(struct intel_cmd *cmd,
1708 const struct intel_ds_state *state)
1709{
1710 cmd->bind.state.ds = state;
1711}
1712
1713static void cmd_bind_blend_state(struct intel_cmd *cmd,
1714 const struct intel_blend_state *state)
1715{
1716 cmd->bind.state.blend = state;
1717}
1718
1719static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1720 const struct intel_msaa_state *state)
1721{
1722 cmd->bind.state.msaa = state;
1723}
1724
1725static void cmd_draw(struct intel_cmd *cmd,
1726 XGL_UINT vertex_start,
1727 XGL_UINT vertex_count,
1728 XGL_UINT instance_start,
1729 XGL_UINT instance_count,
1730 bool indexed,
1731 XGL_UINT vertex_base)
1732{
1733 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1734
1735 emit_bounded_states(cmd);
1736
1737 if (indexed) {
1738 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1739 cmd->result = XGL_ERROR_UNKNOWN;
1740
1741 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1742 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1743 p->primitive_restart_index);
1744 } else {
1745 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1746 cmd->bind.index.offset, cmd->bind.index.type,
1747 p->primitive_restart);
1748 }
1749 } else {
1750 assert(!vertex_base);
1751 }
1752
1753 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1754 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1755 vertex_start, instance_count, instance_start, vertex_base);
1756 } else {
1757 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1758 vertex_start, instance_count, instance_start, vertex_base);
1759 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001760
Chia-I Wu707a29e2014-08-27 12:51:47 +08001761 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001762 /* need to re-emit all workarounds */
1763 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001764}
1765
Chia-I Wub2755562014-08-20 13:38:52 +08001766XGL_VOID XGLAPI intelCmdBindPipeline(
1767 XGL_CMD_BUFFER cmdBuffer,
1768 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1769 XGL_PIPELINE pipeline)
1770{
1771 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1772
1773 switch (pipelineBindPoint) {
1774 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001775 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001776 break;
1777 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001778 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001779 break;
1780 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001781 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001782 break;
1783 }
1784}
1785
1786XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1787 XGL_CMD_BUFFER cmdBuffer,
1788 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1789 XGL_PIPELINE_DELTA delta)
1790{
1791 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1792
1793 switch (pipelineBindPoint) {
1794 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001795 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001796 break;
1797 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001798 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001799 break;
1800 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001801 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001802 break;
1803 }
1804}
1805
1806XGL_VOID XGLAPI intelCmdBindStateObject(
1807 XGL_CMD_BUFFER cmdBuffer,
1808 XGL_STATE_BIND_POINT stateBindPoint,
1809 XGL_STATE_OBJECT state)
1810{
1811 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1812
1813 switch (stateBindPoint) {
1814 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001815 cmd_bind_viewport_state(cmd,
1816 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001817 break;
1818 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001819 cmd_bind_raster_state(cmd,
1820 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001821 break;
1822 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001823 cmd_bind_ds_state(cmd,
1824 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001825 break;
1826 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001827 cmd_bind_blend_state(cmd,
1828 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001829 break;
1830 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001831 cmd_bind_msaa_state(cmd,
1832 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001833 break;
1834 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001835 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001836 break;
1837 }
1838}
1839
1840XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1841 XGL_CMD_BUFFER cmdBuffer,
1842 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1843 XGL_UINT index,
1844 XGL_DESCRIPTOR_SET descriptorSet,
1845 XGL_UINT slotOffset)
1846{
1847 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1848 struct intel_dset *dset = intel_dset(descriptorSet);
1849
1850 assert(!index);
1851
1852 switch (pipelineBindPoint) {
1853 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001854 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001855 break;
1856 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001857 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001858 break;
1859 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001860 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001861 break;
1862 }
1863}
1864
1865XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1866 XGL_CMD_BUFFER cmdBuffer,
1867 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1868 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1869{
1870 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1871
1872 switch (pipelineBindPoint) {
1873 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001874 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001875 break;
1876 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001877 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001878 break;
1879 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001880 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001881 break;
1882 }
1883}
1884
1885XGL_VOID XGLAPI intelCmdBindIndexData(
1886 XGL_CMD_BUFFER cmdBuffer,
1887 XGL_GPU_MEMORY mem_,
1888 XGL_GPU_SIZE offset,
1889 XGL_INDEX_TYPE indexType)
1890{
1891 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1892 struct intel_mem *mem = intel_mem(mem_);
1893
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001894 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001895}
1896
1897XGL_VOID XGLAPI intelCmdBindAttachments(
1898 XGL_CMD_BUFFER cmdBuffer,
1899 XGL_UINT colorAttachmentCount,
1900 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1901 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1902{
1903 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001904
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001905 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1906 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001907}
1908
1909XGL_VOID XGLAPI intelCmdDraw(
1910 XGL_CMD_BUFFER cmdBuffer,
1911 XGL_UINT firstVertex,
1912 XGL_UINT vertexCount,
1913 XGL_UINT firstInstance,
1914 XGL_UINT instanceCount)
1915{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001916 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001917
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001918 cmd_draw(cmd, firstVertex, vertexCount,
1919 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08001920}
1921
1922XGL_VOID XGLAPI intelCmdDrawIndexed(
1923 XGL_CMD_BUFFER cmdBuffer,
1924 XGL_UINT firstIndex,
1925 XGL_UINT indexCount,
1926 XGL_INT vertexOffset,
1927 XGL_UINT firstInstance,
1928 XGL_UINT instanceCount)
1929{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001930 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001931
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001932 cmd_draw(cmd, firstIndex, indexCount,
1933 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001934}
1935
1936XGL_VOID XGLAPI intelCmdDrawIndirect(
1937 XGL_CMD_BUFFER cmdBuffer,
1938 XGL_GPU_MEMORY mem,
1939 XGL_GPU_SIZE offset,
1940 XGL_UINT32 count,
1941 XGL_UINT32 stride)
1942{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001943 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1944
1945 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001946}
1947
1948XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
1949 XGL_CMD_BUFFER cmdBuffer,
1950 XGL_GPU_MEMORY mem,
1951 XGL_GPU_SIZE offset,
1952 XGL_UINT32 count,
1953 XGL_UINT32 stride)
1954{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001955 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1956
1957 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001958}
1959
1960XGL_VOID XGLAPI intelCmdDispatch(
1961 XGL_CMD_BUFFER cmdBuffer,
1962 XGL_UINT x,
1963 XGL_UINT y,
1964 XGL_UINT z)
1965{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001966 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1967
1968 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001969}
1970
1971XGL_VOID XGLAPI intelCmdDispatchIndirect(
1972 XGL_CMD_BUFFER cmdBuffer,
1973 XGL_GPU_MEMORY mem,
1974 XGL_GPU_SIZE offset)
1975{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001976 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1977
1978 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001979}