blob: 66120730ede876a0042db913cb9fb94957ca163e [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
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600298
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800299static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
300{
301 const uint8_t cmd_len = 7;
302 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
303
304 CMD_ASSERT(cmd, 6, 6);
305
306 assert(cmd->bind.gs.shader == NULL);
307
308 cmd_batch_reserve(cmd, cmd_len);
309 cmd_batch_write(cmd, dw0);
310 cmd_batch_write(cmd, 0);
311 cmd_batch_write(cmd, 0);
312 cmd_batch_write(cmd, 0);
313 cmd_batch_write(cmd, 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT);
314 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
315 cmd_batch_write(cmd, 0);
316}
317
Chia-I Wu62a7f252014-08-29 11:31:16 +0800318static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
319{
320 const uint8_t cmd_len = 7;
321 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
322
323 CMD_ASSERT(cmd, 7, 7.5);
324
325 assert(cmd->bind.gs.shader == NULL);
326
327 cmd_batch_reserve(cmd, cmd_len);
328 cmd_batch_write(cmd, dw0);
329 cmd_batch_write(cmd, 0);
330 cmd_batch_write(cmd, 0);
331 cmd_batch_write(cmd, 0);
332 cmd_batch_write(cmd, 0);
333 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
334 cmd_batch_write(cmd, 0);
335}
336
Chia-I Wud88e02d2014-08-25 10:56:13 +0800337static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
338 XGL_UINT width, XGL_UINT height)
339{
340 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800341 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800342 (cmd_len - 2);
343
344 CMD_ASSERT(cmd, 6, 7.5);
345
346 cmd_batch_reserve(cmd, cmd_len);
347 cmd_batch_write(cmd, dw0);
348 if (width && height) {
349 cmd_batch_write(cmd, 0);
350 cmd_batch_write(cmd, (height - 1) << 16 |
351 (width - 1));
352 } else {
353 cmd_batch_write(cmd, 1);
354 cmd_batch_write(cmd, 0);
355 }
356 cmd_batch_write(cmd, 0);
357}
358
Chia-I Wu8016a172014-08-29 18:31:32 +0800359static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
360 uint32_t body[6])
361{
362 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
363 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
364 const struct intel_raster_state *raster = cmd->bind.state.raster;
365 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
366 uint32_t dw1, dw2, dw3;
367 int point_width;
368
369 CMD_ASSERT(cmd, 6, 7.5);
370
371 dw1 = GEN7_SF_DW1_STATISTICS |
372 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
373 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
374 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
375 GEN7_SF_DW1_VIEWPORT_ENABLE |
376 raster->cmd_sf_fill;
377
378 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
379 int format;
380
381 switch (pipeline->db_format.channelFormat) {
382 case XGL_CH_FMT_R16:
383 format = GEN6_ZFORMAT_D16_UNORM;
384 break;
385 case XGL_CH_FMT_R32:
386 case XGL_CH_FMT_R32G8:
387 format = GEN6_ZFORMAT_D32_FLOAT;
388 break;
389 default:
390 assert(!"unknown depth format");
391 format = 0;
392 break;
393 }
394
395 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
396 }
397
398 dw2 = raster->cmd_sf_cull;
399
400 if (msaa->sample_count > 1) {
401 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
402 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
403 } else {
404 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
405 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
406 }
407
408 if (viewport->scissor_enable)
409 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
410
411 /* in U8.3 */
412 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
413 point_width = U_CLAMP(point_width, 1, 2047);
414
415 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
416 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
417 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
418 GEN7_SF_DW3_SUBPIXEL_8BITS |
419 GEN7_SF_DW3_USE_POINT_WIDTH |
420 point_width;
421
422 body[0] = dw1;
423 body[1] = dw2;
424 body[2] = dw3;
425 body[3] = raster->cmd_depth_offset_const;
426 body[4] = raster->cmd_depth_offset_scale;
427 body[5] = raster->cmd_depth_offset_clamp;
428}
429
430static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
431 uint32_t body[13])
432{
433 const struct intel_shader *vs =
434 intel_shader(cmd->bind.pipeline.graphics->vs.shader);
435 const struct intel_shader *fs =
436 intel_shader(cmd->bind.pipeline.graphics->fs.shader);
437 XGL_UINT attr_skip, attr_count;
438 XGL_UINT vue_offset, vue_len;
439 XGL_UINT i;
440 uint32_t dw1;
441
442 CMD_ASSERT(cmd, 6, 7.5);
443
444 /* VS outputs VUE header and position additionally */
445 assert(vs->out_count >= 2);
446 attr_skip = 2;
447 attr_count = vs->out_count - attr_skip;
448 assert(fs->in_count == attr_count);
449 assert(fs->in_count <= 32);
450
451 vue_offset = attr_skip / 2;
452 vue_len = (attr_count + 1) / 2;
453 if (!vue_len)
454 vue_len = 1;
455
456 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
457 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
458 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
459
460 body[0] = dw1;
461
462 for (i = 0; i < 8; i++) {
463 uint16_t hi, lo;
464
465 /* no attr swizzles */
466 if (i * 2 + 1 < fs->in_count) {
467 hi = i * 2 + 1;
468 lo = i * 2;
469 } else if (i * 2 < fs->in_count) {
470 hi = 0;
471 lo = i * 2;
472 } else {
473 hi = 0;
474 lo = 0;
475 }
476
477 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
478 }
479
480 body[9] = 0; /* point sprite enables */
481 body[10] = 0; /* constant interpolation enables */
482 body[11] = 0; /* WrapShortest enables */
483 body[12] = 0;
484}
485
486static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
487{
488 const uint8_t cmd_len = 20;
489 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
490 (cmd_len - 2);
491 uint32_t sf[6];
492 uint32_t sbe[13];
493
494 CMD_ASSERT(cmd, 6, 6);
495
496 gen7_fill_3DSTATE_SF_body(cmd, sf);
497 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
498
499 cmd_batch_reserve(cmd, cmd_len);
500 cmd_batch_write(cmd, dw0);
501 cmd_batch_write(cmd, sbe[0]);
502 cmd_batch_write_n(cmd, sf, 6);
503 cmd_batch_write_n(cmd, &sbe[1], 12);
504}
505
506static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
507{
508 const uint8_t cmd_len = 7;
509 uint32_t dw[7];
510
511 CMD_ASSERT(cmd, 7, 7.5);
512
513 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
514 (cmd_len - 2);
515 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
516
517 cmd_batch_reserve(cmd, cmd_len);
518 cmd_batch_write_n(cmd, dw, cmd_len);
519}
520
521static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
522{
523 const uint8_t cmd_len = 14;
524 uint32_t dw[14];
525
526 CMD_ASSERT(cmd, 7, 7.5);
527
528 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
529 (cmd_len - 2);
530 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
531
532 cmd_batch_reserve(cmd, cmd_len);
533 cmd_batch_write_n(cmd, dw, cmd_len);
534}
535
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800536static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
537{
538 const uint8_t cmd_len = 4;
539 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
540 (cmd_len - 2);
541 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
542 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
543 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
544 const struct intel_raster_state *raster = cmd->bind.state.raster;
545 uint32_t dw1, dw2, dw3;
546
547 CMD_ASSERT(cmd, 6, 7.5);
548
549 dw1 = GEN6_CLIP_DW1_STATISTICS;
550 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
551 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
552 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
553 raster->cmd_clip_cull;
554 }
555
556 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
557 GEN6_CLIP_DW2_XY_TEST_ENABLE |
558 GEN6_CLIP_DW2_APIMODE_OGL |
559 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
560 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
561 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
562
563 if (pipeline->rasterizerDiscardEnable)
564 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
565 else
566 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
567
568 if (pipeline->depthClipEnable)
569 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
570
571 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
572 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
573 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
574 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
575
576 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
577 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
578 (viewport->viewport_count - 1);
579
580 cmd_batch_reserve(cmd, cmd_len);
581 cmd_batch_write(cmd, dw0);
582 cmd_batch_write(cmd, dw1);
583 cmd_batch_write(cmd, dw2);
584 cmd_batch_write(cmd, dw3);
585}
586
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800587static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
588{
589 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
590 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
591 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
592 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
593 const uint8_t cmd_len = 9;
594 uint32_t dw0, dw2, dw4, dw5, dw6;
595
596 CMD_ASSERT(cmd, 6, 6);
597
598 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
599
600 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
601 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
602
603 dw4 = GEN6_WM_DW4_STATISTICS |
604 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
605 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
606 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
607
608 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
609 GEN6_WM_DW5_PS_ENABLE |
610 GEN6_WM_DW5_8_PIXEL_DISPATCH;
611
612 if (fs->uses & INTEL_SHADER_USE_KILL ||
613 pipeline->cb_state.alphaToCoverageEnable)
614 dw5 |= GEN6_WM_DW5_PS_KILL;
615
616 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
617 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
618 if (fs->uses & INTEL_SHADER_USE_DEPTH)
619 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
620 if (fs->uses & INTEL_SHADER_USE_W)
621 dw5 |= GEN6_WM_DW5_PS_USE_W;
622
623 if (pipeline->cb_state.dualSourceBlendEnable)
624 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
625
626 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
627 GEN6_WM_DW6_POSOFFSET_NONE |
628 GEN6_WM_DW6_ZW_INTERP_PIXEL |
629 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
630 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
631
632 if (msaa->sample_count > 1) {
633 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
634 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
635 } else {
636 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
637 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
638 }
639
640 cmd_batch_reserve(cmd, cmd_len);
641 cmd_batch_write(cmd, dw0);
642 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
643 cmd_batch_write(cmd, dw2);
644 cmd_batch_write(cmd, 0); /* scratch */
645 cmd_batch_write(cmd, dw4);
646 cmd_batch_write(cmd, dw5);
647 cmd_batch_write(cmd, dw6);
648 cmd_batch_write(cmd, 0); /* kernel 1 */
649 cmd_batch_write(cmd, 0); /* kernel 2 */
650}
651
652static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
653{
654 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
655 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
656 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
657 const uint8_t cmd_len = 3;
658 uint32_t dw0, dw1, dw2;
659
660 CMD_ASSERT(cmd, 7, 7.5);
661
662 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
663
664 dw1 = GEN7_WM_DW1_STATISTICS |
665 GEN7_WM_DW1_PS_ENABLE |
666 GEN7_WM_DW1_ZW_INTERP_PIXEL |
667 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
668 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
669
670 if (fs->uses & INTEL_SHADER_USE_KILL ||
671 pipeline->cb_state.alphaToCoverageEnable)
672 dw1 |= GEN7_WM_DW1_PS_KILL;
673
674 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
675 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
676 if (fs->uses & INTEL_SHADER_USE_DEPTH)
677 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
678 if (fs->uses & INTEL_SHADER_USE_W)
679 dw1 |= GEN7_WM_DW1_PS_USE_W;
680
681 dw2 = 0;
682
683 if (msaa->sample_count > 1) {
684 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
685 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
686 } else {
687 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
688 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
689 }
690
691 cmd_batch_reserve(cmd, cmd_len);
692 cmd_batch_write(cmd, dw0);
693 cmd_batch_write(cmd, dw1);
694 cmd_batch_write(cmd, dw2);
695}
696
697static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
698{
699 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
700 const struct intel_shader *fs = intel_shader(pipeline->fs.shader);
701 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
702 const uint8_t cmd_len = 8;
703 uint32_t dw0, dw2, dw4, dw5;
704
705 CMD_ASSERT(cmd, 7, 7.5);
706
707 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
708
709 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
710 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
711
712 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
713 GEN7_PS_DW4_8_PIXEL_DISPATCH;
714
715 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
716 const int max_threads =
717 (cmd->dev->gpu->gt == 3) ? 408 :
718 (cmd->dev->gpu->gt == 2) ? 204 : 102;
719 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
720 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
721 } else {
722 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
723 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
724 }
725
726 if (pipeline->fs.linkConstBufferCount)
727 dw4 |= GEN7_PS_DW4_PUSH_CONSTANT_ENABLE;
728
729 if (fs->in_count)
730 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
731
732 if (pipeline->cb_state.dualSourceBlendEnable)
733 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
734
735 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
736 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
737 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
738
739 cmd_batch_reserve(cmd, cmd_len);
740 cmd_batch_write(cmd, dw0);
741 cmd_batch_write(cmd, cmd->bind.fs.kernel_pos << 2);
742 cmd_batch_write(cmd, dw2);
743 cmd_batch_write(cmd, 0); /* scratch */
744 cmd_batch_write(cmd, dw4);
745 cmd_batch_write(cmd, dw5);
746 cmd_batch_write(cmd, 0); /* kernel 1 */
747 cmd_batch_write(cmd, 0); /* kernel 2 */
748}
749
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800750static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
751 const struct intel_ds_view *view)
752{
753 const uint8_t cmd_len = 7;
754 uint32_t dw0;
755
756 CMD_ASSERT(cmd, 6, 7.5);
757
758 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800759 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
760 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800761 dw0 |= (cmd_len - 2);
762
Chia-I Wu2de65d02014-08-25 10:02:53 +0800763 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800764 cmd_batch_write(cmd, dw0);
765 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600766 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800767 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800768 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600769 } else {
770 cmd_batch_write(cmd, 0);
771 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800772 cmd_batch_write(cmd, view->cmd[2]);
773 cmd_batch_write(cmd, view->cmd[3]);
774 cmd_batch_write(cmd, view->cmd[4]);
775 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800776}
777
778static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
779 const struct intel_ds_view *view)
780{
781 const uint8_t cmd_len = 3;
782 uint32_t dw0;
783
784 CMD_ASSERT(cmd, 6, 7.5);
785
786 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800787 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
788 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800789 dw0 |= (cmd_len - 2);
790
Chia-I Wu2de65d02014-08-25 10:02:53 +0800791 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800792 cmd_batch_write(cmd, dw0);
793 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600794 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800795 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800796 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600797 } else {
798 cmd_batch_write(cmd, 0);
799 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800800}
801
802static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
803 const struct intel_ds_view *view)
804{
805 const uint8_t cmd_len = 3;
806 uint32_t dw0;
807
808 CMD_ASSERT(cmd, 6, 7.5);
809
810 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800811 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
812 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800813 dw0 |= (cmd_len - 2);
814
Chia-I Wu2de65d02014-08-25 10:02:53 +0800815 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800816 cmd_batch_write(cmd, dw0);
817 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600818 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800819 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800820 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600821 } else {
822 cmd_batch_write(cmd, 0);
823 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800824}
825
Chia-I Wuf8231032014-08-25 10:44:45 +0800826static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
827 uint32_t clear_val)
828{
829 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800830 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800831 GEN6_CLEAR_PARAMS_DW0_VALID |
832 (cmd_len - 2);
833
834 CMD_ASSERT(cmd, 6, 6);
835
836 cmd_batch_reserve(cmd, cmd_len);
837 cmd_batch_write(cmd, dw0);
838 cmd_batch_write(cmd, clear_val);
839}
840
841static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
842 uint32_t clear_val)
843{
844 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800845 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800846 (cmd_len - 2);
847
848 CMD_ASSERT(cmd, 7, 7.5);
849
850 cmd_batch_reserve(cmd, cmd_len);
851 cmd_batch_write(cmd, dw0);
852 cmd_batch_write(cmd, clear_val);
853 cmd_batch_write(cmd, 1);
854}
855
Chia-I Wu302742d2014-08-22 10:28:29 +0800856static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
857 XGL_UINT blend_pos,
858 XGL_UINT ds_pos,
859 XGL_UINT cc_pos)
860{
861 const uint8_t cmd_len = 4;
862 uint32_t dw0;
863
864 CMD_ASSERT(cmd, 6, 6);
865
Chia-I Wu426072d2014-08-26 14:31:55 +0800866 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800867 (cmd_len - 2);
868
869 cmd_batch_reserve(cmd, cmd_len);
870 cmd_batch_write(cmd, dw0);
871 cmd_batch_write(cmd, (blend_pos << 2) | 1);
872 cmd_batch_write(cmd, (ds_pos << 2) | 1);
873 cmd_batch_write(cmd, (cc_pos << 2) | 1);
874}
875
Chia-I Wu1744cca2014-08-22 11:10:17 +0800876static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
877 XGL_UINT clip_pos,
878 XGL_UINT sf_pos,
879 XGL_UINT cc_pos)
880{
881 const uint8_t cmd_len = 4;
882 uint32_t dw0;
883
884 CMD_ASSERT(cmd, 6, 6);
885
Chia-I Wu426072d2014-08-26 14:31:55 +0800886 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800887 GEN6_PTR_VP_DW0_CLIP_CHANGED |
888 GEN6_PTR_VP_DW0_SF_CHANGED |
889 GEN6_PTR_VP_DW0_CC_CHANGED |
890 (cmd_len - 2);
891
892 cmd_batch_reserve(cmd, cmd_len);
893 cmd_batch_write(cmd, dw0);
894 cmd_batch_write(cmd, clip_pos << 2);
895 cmd_batch_write(cmd, sf_pos << 2);
896 cmd_batch_write(cmd, cc_pos << 2);
897}
898
899static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
900 XGL_UINT scissor_pos)
901{
902 const uint8_t cmd_len = 2;
903 uint32_t dw0;
904
905 CMD_ASSERT(cmd, 6, 6);
906
Chia-I Wu426072d2014-08-26 14:31:55 +0800907 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800908 (cmd_len - 2);
909
910 cmd_batch_reserve(cmd, cmd_len);
911 cmd_batch_write(cmd, dw0);
912 cmd_batch_write(cmd, scissor_pos << 2);
913}
914
Chia-I Wu42a56202014-08-23 16:47:48 +0800915static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
916 XGL_UINT vs_pos,
917 XGL_UINT gs_pos,
918 XGL_UINT ps_pos)
919{
920 const uint8_t cmd_len = 4;
921 uint32_t dw0;
922
923 CMD_ASSERT(cmd, 6, 6);
924
Chia-I Wu426072d2014-08-26 14:31:55 +0800925 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800926 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
927 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
928 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
929 (cmd_len - 2);
930
931 cmd_batch_reserve(cmd, cmd_len);
932 cmd_batch_write(cmd, dw0);
933 cmd_batch_write(cmd, vs_pos << 2);
934 cmd_batch_write(cmd, gs_pos << 2);
935 cmd_batch_write(cmd, ps_pos << 2);
936}
937
Chia-I Wu257e75e2014-08-29 14:06:35 +0800938static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
939 XGL_UINT vs_pos,
940 XGL_UINT gs_pos,
941 XGL_UINT ps_pos)
942{
943 const uint8_t cmd_len = 4;
944 uint32_t dw0;
945
946 CMD_ASSERT(cmd, 6, 6);
947
948 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
949 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
950 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
951 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
952 (cmd_len - 2);
953
954 cmd_batch_reserve(cmd, cmd_len);
955 cmd_batch_write(cmd, dw0);
956 cmd_batch_write(cmd, vs_pos << 2);
957 cmd_batch_write(cmd, gs_pos << 2);
958 cmd_batch_write(cmd, ps_pos << 2);
959}
960
Chia-I Wu302742d2014-08-22 10:28:29 +0800961static void gen7_3dstate_pointer(struct intel_cmd *cmd,
962 int subop, XGL_UINT pos)
963{
964 const uint8_t cmd_len = 2;
965 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
966 GEN6_RENDER_SUBTYPE_3D |
967 subop | (cmd_len - 2);
968
969 cmd_batch_reserve(cmd, cmd_len);
970 cmd_batch_write(cmd, dw0);
971 cmd_batch_write(cmd, pos << 2);
972}
973
974static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
975 const struct intel_blend_state *state)
976{
977 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
978 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
979
980 CMD_ASSERT(cmd, 6, 7.5);
981 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
982
983 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
984}
985
986static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
987 const struct intel_ds_state *state)
988{
989 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
990 const uint8_t cmd_len = 3;
991
992 CMD_ASSERT(cmd, 6, 7.5);
993 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
994
995 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
996}
997
998static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
999 uint32_t stencil_ref,
1000 const uint32_t blend_color[4])
1001{
1002 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
1003 const uint8_t cmd_len = 6;
1004 XGL_UINT pos;
1005 uint32_t *dw;
1006
1007 CMD_ASSERT(cmd, 6, 7.5);
1008
1009 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
1010 dw[0] = stencil_ref;
1011 dw[1] = 0;
1012 dw[2] = blend_color[0];
1013 dw[3] = blend_color[1];
1014 dw[4] = blend_color[2];
1015 dw[5] = blend_color[3];
1016 cmd_state_advance(cmd, cmd_len);
1017
1018 return pos;
1019}
1020
Chia-I Wu8370b402014-08-29 12:28:37 +08001021static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001022{
Chia-I Wu8370b402014-08-29 12:28:37 +08001023 CMD_ASSERT(cmd, 6, 7.5);
1024
Chia-I Wu707a29e2014-08-27 12:51:47 +08001025 if (!cmd->bind.draw_count)
1026 return;
1027
Chia-I Wu8370b402014-08-29 12:28:37 +08001028 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001029 return;
1030
Chia-I Wu8370b402014-08-29 12:28:37 +08001031 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001032
1033 /*
1034 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1035 *
1036 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1037 * pipe-control with a post-sync op and no write-cache flushes."
1038 *
1039 * The workaround below necessitates this workaround.
1040 */
1041 gen6_PIPE_CONTROL(cmd,
1042 GEN6_PIPE_CONTROL_CS_STALL |
1043 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001044 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001045
Chia-I Wud6d079d2014-08-31 13:14:21 +08001046 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1047 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001048}
1049
Chia-I Wu8370b402014-08-29 12:28:37 +08001050static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001051{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001052 CMD_ASSERT(cmd, 6, 7.5);
1053
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001054 if (!cmd->bind.draw_count)
1055 return;
1056
Chia-I Wud6d079d2014-08-31 13:14:21 +08001057 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1058 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001059}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001060
Chia-I Wu8370b402014-08-29 12:28:37 +08001061static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1062{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001063 CMD_ASSERT(cmd, 7, 7.5);
1064
Chia-I Wu8370b402014-08-29 12:28:37 +08001065 if (!cmd->bind.draw_count)
1066 return;
1067
1068 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001069
1070 gen6_PIPE_CONTROL(cmd,
1071 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001072 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001073}
1074
Chia-I Wu8370b402014-08-29 12:28:37 +08001075static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1076{
1077 CMD_ASSERT(cmd, 7, 7.5);
1078
1079 if (!cmd->bind.draw_count)
1080 return;
1081
1082 /*
1083 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1084 *
1085 * "One of the following must also be set (when CS stall is set):
1086 *
1087 * * Render Target Cache Flush Enable ([12] of DW1)
1088 * * Depth Cache Flush Enable ([0] of DW1)
1089 * * Stall at Pixel Scoreboard ([1] of DW1)
1090 * * Depth Stall ([13] of DW1)
1091 * * Post-Sync Operation ([13] of DW1)"
1092 */
1093 gen6_PIPE_CONTROL(cmd,
1094 GEN6_PIPE_CONTROL_CS_STALL |
1095 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001096 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001097}
1098
1099static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1100{
1101 CMD_ASSERT(cmd, 7, 7.5);
1102
1103 if (!cmd->bind.draw_count)
1104 return;
1105
1106 cmd_wa_gen6_pre_depth_stall_write(cmd);
1107
Chia-I Wud6d079d2014-08-31 13:14:21 +08001108 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001109}
1110
1111static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1112{
1113 CMD_ASSERT(cmd, 6, 7.5);
1114
1115 if (!cmd->bind.draw_count)
1116 return;
1117
1118 /*
1119 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1120 *
1121 * "Driver must guarentee that all the caches in the depth pipe are
1122 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1123 * requires driver to send a PIPE_CONTROL with a CS stall along with
1124 * a Depth Flush prior to this command."
1125 *
1126 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1127 *
1128 * "Driver must ierarchi that all the caches in the depth pipe are
1129 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1130 * requires driver to send a PIPE_CONTROL with a CS stall along with
1131 * a Depth Flush prior to this command.
1132 */
1133 gen6_PIPE_CONTROL(cmd,
1134 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1135 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001136 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001137}
1138
1139static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1140{
1141 CMD_ASSERT(cmd, 6, 7.5);
1142
1143 if (!cmd->bind.draw_count)
1144 return;
1145
1146 /*
1147 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1148 *
1149 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1150 * and a post sync operation prior to the group of depth
1151 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1152 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1153 *
1154 * This workaround satifies all the conditions.
1155 */
1156 cmd_wa_gen6_pre_depth_stall_write(cmd);
1157
1158 /*
1159 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1160 *
1161 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1162 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1163 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1164 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1165 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1166 * Depth Flush Bit set, followed by another pipelined depth stall
1167 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1168 * guarantee that the pipeline from WM onwards is already flushed
1169 * (e.g., via a preceding MI_FLUSH)."
1170 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001171 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1172 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1173 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001174}
1175
Chia-I Wu525c6602014-08-27 10:22:34 +08001176void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1177{
1178 if (!cmd->bind.draw_count)
1179 return;
1180
1181 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1182
Chia-I Wu8370b402014-08-29 12:28:37 +08001183 /*
1184 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1185 *
1186 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1187 * PIPE_CONTROL with any non-zero post-sync-op is required."
1188 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001189 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001190 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001191
Chia-I Wu092279a2014-08-30 19:05:30 +08001192 /*
1193 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1194 *
1195 * "One of the following must also be set (when CS stall is set):
1196 *
1197 * * Render Target Cache Flush Enable ([12] of DW1)
1198 * * Depth Cache Flush Enable ([0] of DW1)
1199 * * Stall at Pixel Scoreboard ([1] of DW1)
1200 * * Depth Stall ([13] of DW1)
1201 * * Post-Sync Operation ([13] of DW1)"
1202 */
1203 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1204 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1205 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1206 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1207 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1208 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1209
Chia-I Wud6d079d2014-08-31 13:14:21 +08001210 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001211}
1212
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001213void cmd_batch_depth_count(struct intel_cmd *cmd,
1214 struct intel_bo *bo,
1215 XGL_GPU_SIZE offset)
1216{
1217 cmd_wa_gen6_pre_depth_stall_write(cmd);
1218
1219 gen6_PIPE_CONTROL(cmd,
1220 GEN6_PIPE_CONTROL_DEPTH_STALL |
1221 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001222 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001223}
1224
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001225void cmd_batch_timestamp(struct intel_cmd *cmd,
1226 struct intel_bo *bo,
1227 XGL_GPU_SIZE offset)
1228{
1229 /* need any WA or stall? */
1230 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1231}
1232
1233void cmd_batch_immediate(struct intel_cmd *cmd,
1234 struct intel_bo *bo,
1235 XGL_GPU_SIZE offset,
1236 uint64_t val)
1237{
1238 /* need any WA or stall? */
1239 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1240}
1241
Chia-I Wu302742d2014-08-22 10:28:29 +08001242static void gen6_cc_states(struct intel_cmd *cmd)
1243{
1244 const struct intel_blend_state *blend = cmd->bind.state.blend;
1245 const struct intel_ds_state *ds = cmd->bind.state.ds;
1246 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001247 uint32_t stencil_ref;
1248 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001249
1250 CMD_ASSERT(cmd, 6, 6);
1251
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001252 if (blend) {
1253 blend_pos = gen6_BLEND_STATE(cmd, blend);
1254 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1255 } else {
1256 blend_pos = 0;
1257 memset(blend_color, 0, sizeof(blend_color));
1258 }
1259
1260 if (ds) {
1261 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1262 stencil_ref = ds->cmd_stencil_ref;
1263 } else {
1264 ds_pos = 0;
1265 stencil_ref = 0;
1266 }
1267
1268 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001269
1270 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
1271}
1272
Chia-I Wu1744cca2014-08-22 11:10:17 +08001273static void gen6_viewport_states(struct intel_cmd *cmd)
1274{
1275 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1276 XGL_UINT pos;
1277
1278 if (!viewport)
1279 return;
1280
1281 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1282 viewport->cmd_align);
1283
1284 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
1285 pos + viewport->cmd_clip_offset,
1286 pos,
1287 pos + viewport->cmd_cc_offset);
1288
1289 pos = (viewport->scissor_enable) ?
1290 pos + viewport->cmd_scissor_rect_offset : 0;
1291
1292 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
1293}
1294
Chia-I Wu302742d2014-08-22 10:28:29 +08001295static void gen7_cc_states(struct intel_cmd *cmd)
1296{
1297 const struct intel_blend_state *blend = cmd->bind.state.blend;
1298 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001299 uint32_t stencil_ref;
1300 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001301 XGL_UINT pos;
1302
1303 CMD_ASSERT(cmd, 7, 7.5);
1304
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001305 if (!blend && !ds)
1306 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001307
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001308 if (blend) {
1309 pos = gen6_BLEND_STATE(cmd, blend);
1310 gen7_3dstate_pointer(cmd,
1311 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +08001312
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001313 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1314 } else {
1315 memset(blend_color, 0, sizeof(blend_color));
1316 }
1317
1318 if (ds) {
1319 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
1320 gen7_3dstate_pointer(cmd,
1321 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
1322 } else {
1323 stencil_ref = 0;
1324 }
1325
1326 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001327 gen7_3dstate_pointer(cmd,
1328 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
1329}
1330
Chia-I Wu1744cca2014-08-22 11:10:17 +08001331static void gen7_viewport_states(struct intel_cmd *cmd)
1332{
1333 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
1334 XGL_UINT pos;
1335
1336 if (!viewport)
1337 return;
1338
1339 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
1340 viewport->cmd_align);
1341
1342 gen7_3dstate_pointer(cmd,
1343 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
1344 gen7_3dstate_pointer(cmd,
1345 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
1346 pos + viewport->cmd_cc_offset);
1347 if (viewport->scissor_enable) {
1348 gen7_3dstate_pointer(cmd,
1349 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1350 pos + viewport->cmd_scissor_rect_offset);
1351 }
1352}
1353
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001354static void gen6_pcb(struct intel_cmd *cmd, int subop,
1355 const XGL_PIPELINE_SHADER *sh)
1356{
1357 const uint8_t cmd_len = 5;
1358 const XGL_UINT alignment = 32;
1359 const XGL_UINT max_size =
1360 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
1361 const XGL_UINT max_pcb = 4;
1362 uint32_t pcb[4] = { 0, 0, 0, 0 };
1363 XGL_FLAGS pcb_enables = 0;
1364 XGL_SIZE total_size = 0;
1365 uint32_t dw0;
1366 XGL_UINT i;
1367
1368 for (i = 0; i < sh->linkConstBufferCount; i++) {
1369 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1370 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1371 void *ptr;
1372
1373 if (info->bufferId >= max_pcb ||
1374 pcb_enables & ((1 << info->bufferId)) ||
1375 total_size + info->bufferSize > max_size) {
1376 cmd->result = XGL_ERROR_UNKNOWN;
1377 return;
1378 }
1379 if (!size)
1380 continue;
1381
1382 pcb_enables |= 1 << info->bufferId;
1383 total_size += size;
1384
1385 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1386 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1387 memcpy(ptr, info->pBufferData, info->bufferSize);
1388 cmd_state_advance(cmd, size / sizeof(uint32_t));
1389
1390 pcb[info->bufferId] |= size / alignment - 1;
1391 }
1392
1393 dw0 = GEN6_RENDER_TYPE_RENDER |
1394 GEN6_RENDER_SUBTYPE_3D |
1395 subop |
1396 pcb_enables << 12 |
1397 (cmd_len - 2);
1398
1399 cmd_batch_reserve(cmd, cmd_len);
1400 cmd_batch_write(cmd, dw0);
1401 cmd_batch_write(cmd, pcb[0]);
1402 cmd_batch_write(cmd, pcb[1]);
1403 cmd_batch_write(cmd, pcb[2]);
1404 cmd_batch_write(cmd, pcb[3]);
1405}
1406
1407static void gen7_pcb(struct intel_cmd *cmd, int subop,
1408 const XGL_PIPELINE_SHADER *sh)
1409{
1410 const uint8_t cmd_len = 7;
1411 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1412 GEN6_RENDER_SUBTYPE_3D |
1413 subop |
1414 (cmd_len - 2);
1415 const XGL_UINT alignment = 32;
1416 const XGL_UINT max_size = 2048;
1417 const XGL_UINT max_pcb = 4;
1418 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
1419 uint32_t pcb[4] = { 0, 0, 0, 0 };
1420 XGL_FLAGS pcb_enables = 0;
1421 XGL_SIZE total_size = 0;
1422 XGL_UINT i;
1423
1424 for (i = 0; i < sh->linkConstBufferCount; i++) {
1425 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
1426 const XGL_SIZE size = u_align(info->bufferSize, alignment);
1427 void *ptr;
1428
1429 if (info->bufferId >= max_pcb ||
1430 pcb_enables & ((1 << info->bufferId)) ||
1431 total_size + info->bufferSize > max_size) {
1432 cmd->result = XGL_ERROR_UNKNOWN;
1433 return;
1434 }
1435 if (!size)
1436 continue;
1437
1438 pcb_enables |= 1 << info->bufferId;
1439 total_size += size;
1440
1441 pcb_len[info->bufferId] = size / alignment;
1442
1443 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1444 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1445 memcpy(ptr, info->pBufferData, info->bufferSize);
1446 cmd_state_advance(cmd, size / sizeof(uint32_t));
1447 }
1448
1449 /* no holes */
1450 if (!u_is_pow2(pcb_enables + 1)) {
1451 cmd->result = XGL_ERROR_UNKNOWN;
1452 return;
1453 }
1454
1455 cmd_batch_reserve(cmd, cmd_len);
1456 cmd_batch_write(cmd, dw0);
1457 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
1458 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
1459 cmd_batch_write(cmd, pcb[0]);
1460 cmd_batch_write(cmd, pcb[1]);
1461 cmd_batch_write(cmd, pcb[2]);
1462 cmd_batch_write(cmd, pcb[3]);
1463}
1464
Chia-I Wu42a56202014-08-23 16:47:48 +08001465static void emit_ps_resources(struct intel_cmd *cmd,
1466 const struct intel_rmap *rmap)
1467{
1468 const XGL_UINT surface_count = rmap->rt_count +
1469 rmap->resource_count + rmap->uav_count;
1470 uint32_t binding_table[256];
1471 XGL_UINT pos, i;
1472
1473 assert(surface_count <= ARRAY_SIZE(binding_table));
1474
1475 for (i = 0; i < surface_count; i++) {
1476 const struct intel_rmap_slot *slot = &rmap->slots[i];
1477 uint32_t *dw;
1478
1479 switch (slot->path_len) {
1480 case 0:
1481 pos = 0;
1482 break;
1483 case INTEL_RMAP_SLOT_RT:
1484 {
1485 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1486
1487 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1488 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1489
1490 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001491 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001492 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001493 cmd_state_advance(cmd, view->cmd_len);
1494 }
1495 break;
1496 case INTEL_RMAP_SLOT_DYN:
1497 {
1498 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001499 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001500
1501 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1502 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1503
1504 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001505 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001506 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001507 cmd_state_advance(cmd, view->cmd_len);
1508 }
1509 break;
1510 case 1:
1511 default:
1512 /* TODO */
1513 assert(!"no dset support");
1514 break;
1515 }
1516
1517 binding_table[i] = pos << 2;
1518 }
1519
1520 pos = cmd_state_copy(cmd, binding_table, surface_count,
1521 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
1522
1523 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1524 gen7_3dstate_pointer(cmd,
1525 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001526
1527 gen7_3dstate_pointer(cmd,
1528 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1529 gen7_3dstate_pointer(cmd,
1530 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1531 gen7_3dstate_pointer(cmd,
1532 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1533 gen7_3dstate_pointer(cmd,
1534 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1535
1536 gen7_3dstate_pointer(cmd,
1537 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1538 gen7_3dstate_pointer(cmd,
1539 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1540 gen7_3dstate_pointer(cmd,
1541 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1542 gen7_3dstate_pointer(cmd,
1543 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1544 gen7_3dstate_pointer(cmd,
1545 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001546 } else {
1547 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001548 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001549 }
1550}
1551
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001552// TODO: These should probably be generated
1553/* DW2 */
1554# define GEN6_VS_SPF_MODE (1 << 31)
1555# define GEN6_VS_VECTOR_MASK_ENABLE (1 << 30)
1556# define GEN6_VS_SAMPLER_COUNT_SHIFT 27
1557# define GEN6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT 18
1558# define GEN6_VS_FLOATING_POINT_MODE_IEEE_754 (0 << 16)
1559# define GEN6_VS_FLOATING_POINT_MODE_ALT (1 << 16)
1560
1561static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1562{
1563 const uint8_t cmd_len = GEN6_3DSTATE_VS__SIZE;
1564 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
1565 uint32_t dw2, dw4, dw5;
1566
1567 CMD_ASSERT(cmd, 6, 7.5);
1568
1569 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
1570 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
1571 *
1572 * [DevSNB] A pipeline flush must be programmed prior to a 3DSTATE_VS
1573 * command that causes the VS Function Enable to toggle. Pipeline
1574 * flush can be executed by sending a PIPE_CONTROL command with CS
1575 * stall bit set and a post sync operation.
1576 *
1577 * Although we don't disable the VS during normal drawing, BLORP sometimes
1578 * disables it. To be safe, do the flush here just in case.
1579 */
1580 cmd_wa_gen6_pre_depth_stall_write(cmd);
1581
1582 if (cmd->bind.vs.shader == NULL) {
1583 cmd_batch_reserve(cmd, cmd_len);
1584 cmd_batch_write(cmd, dw0);
1585 cmd_batch_write(cmd, 0);
1586 cmd_batch_write(cmd, 0);
1587 cmd_batch_write(cmd, 0);
1588 cmd_batch_write(cmd, 0);
1589 cmd_batch_write(cmd, 0);
1590 return;
1591 }
1592
1593 /*
1594 * Most of this is know at pipeline create EXCEPT the kernel address,
1595 * so that's why this is in cmd_pipeline vs. pipeline.
1596 */
1597 dw2 = (u_align(cmd->bind.vs.shader->sampler_count, 4) / 4) << GEN6_VS_SAMPLER_COUNT_SHIFT;
1598 dw4 = (1 << GEN6_VS_DW4_URB_GRF_START__SHIFT) |
1599 (cmd->bind.vs.shader->urb_read_length << GEN6_VS_DW4_URB_READ_LEN__SHIFT) |
1600 (0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT);
1601
1602 dw5 = GEN6_VS_DW5_STATISTICS |
1603 GEN6_VS_DW5_VS_ENABLE;
1604 if (cmd_gen(cmd) == INTEL_GEN(7.5)) {
1605 dw5 |= ((cmd->dev->gpu->max_vs_threads-1) << GEN75_VS_DW5_MAX_THREADS__SHIFT);
1606 } else {
1607 dw5 |= ((cmd->dev->gpu->max_vs_threads-1) << GEN6_VS_DW5_MAX_THREADS__SHIFT);
1608 }
1609
1610 cmd_batch_reserve(cmd, cmd_len);
1611 cmd_batch_write(cmd, dw0);
1612 cmd_batch_write(cmd, cmd->bind.vs.kernel_pos);
1613 cmd_batch_write(cmd, dw2);
1614 cmd_batch_write(cmd, 0); /* scratch */
1615 cmd_batch_write(cmd, dw4);
1616 cmd_batch_write(cmd, dw5);
1617}
1618
Chia-I Wu52500102014-08-22 00:46:04 +08001619static void emit_bounded_states(struct intel_cmd *cmd)
1620{
1621 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1622
1623 /* TODO more states */
1624
Chia-I Wu1744cca2014-08-22 11:10:17 +08001625 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001626 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001627 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001628
1629 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1630 &cmd->bind.pipeline.graphics->vs);
1631 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1632 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001633
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001634 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001635 gen7_3DSTATE_SF(cmd);
1636 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001637 gen7_3DSTATE_WM(cmd);
1638 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001639 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001640 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001641 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001642
1643 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1644 &cmd->bind.pipeline.graphics->vs);
1645 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1646 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001647
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001648 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001649 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001650 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001651 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001652
Chia-I Wu42a56202014-08-23 16:47:48 +08001653 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1654
Chia-I Wu8370b402014-08-29 12:28:37 +08001655 cmd_wa_gen6_pre_depth_stall_write(cmd);
1656 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001657 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001658 cmd_batch_reserve(cmd, msaa->cmd_len);
1659 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001660
1661 gen6_3DSTATE_VS(cmd);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001662}
1663
1664static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001665 const struct intel_pipe_shader *shader,
1666 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001667{
1668 uint32_t i;
1669 struct intel_cmd_shader *cmdShader;
1670
1671 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001672 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001673 /* shader is already part of pipeline */
1674 return;
1675 }
1676 }
1677
Chia-I Wu338fe642014-08-28 10:43:04 +08001678 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1679 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1680
1681 cmdShader = cmd->bind.shaderCache.shaderArray;
1682
1683 cmd->bind.shaderCache.shaderArray =
1684 icd_alloc(sizeof(*cmdShader) * new_count,
1685 0, XGL_SYSTEM_ALLOC_INTERNAL);
1686 if (cmd->bind.shaderCache.shaderArray == NULL) {
1687 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001688 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1689 return;
1690 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001691
1692 if (cmdShader) {
1693 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1694 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1695 icd_free(cmdShader);
1696 }
1697
1698 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001699 }
1700
Chia-I Wu338fe642014-08-28 10:43:04 +08001701 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001702 cmdShader->shader = shader;
1703 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001704 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001705 cmd->bind.shaderCache.used++;
1706 return;
1707}
1708
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001709static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001710 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001711{
1712 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001713
Chia-I Wu8370b402014-08-29 12:28:37 +08001714 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1715 cmd_wa_gen6_pre_depth_stall_write(cmd);
1716 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1717 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1718 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1719 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001720
1721 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001722 assert(pipeline->cmd_len);
Chia-I Wub08727d2014-08-29 14:54:54 +08001723 cmd_batch_reserve(cmd, pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001724 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001725
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001726 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001727 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001728 }
1729 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001730 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001731 }
1732 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001733 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001734 }
1735 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001736 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001737 }
1738 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001739 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001740 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001741
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001742 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1743 gen7_3DSTATE_GS(cmd);
1744 } else {
1745 gen6_3DSTATE_GS(cmd);
1746 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001747
Chia-I Wu8370b402014-08-29 12:28:37 +08001748 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1749 cmd_wa_gen7_post_command_cs_stall(cmd);
1750 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1751 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001752}
1753
1754static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1755 const struct intel_pipeline *pipeline)
1756{
1757 cmd->bind.pipeline.compute = pipeline;
1758}
1759
1760static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1761 const struct intel_pipeline_delta *delta)
1762{
1763 cmd->bind.pipeline.graphics_delta = delta;
1764}
1765
1766static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1767 const struct intel_pipeline_delta *delta)
1768{
1769 cmd->bind.pipeline.compute_delta = delta;
1770}
1771
1772static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1773 const struct intel_dset *dset,
1774 XGL_UINT slot_offset)
1775{
1776 cmd->bind.dset.graphics = dset;
1777 cmd->bind.dset.graphics_offset = slot_offset;
1778}
1779
1780static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1781 const struct intel_dset *dset,
1782 XGL_UINT slot_offset)
1783{
1784 cmd->bind.dset.compute = dset;
1785 cmd->bind.dset.compute_offset = slot_offset;
1786}
1787
1788static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1789 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1790{
1791 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1792}
1793
1794static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1795 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1796{
1797 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1798}
1799
1800static void cmd_bind_index_data(struct intel_cmd *cmd,
1801 const struct intel_mem *mem,
1802 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1803{
1804 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1805 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1806 } else {
1807 cmd->bind.index.mem = mem;
1808 cmd->bind.index.offset = offset;
1809 cmd->bind.index.type = type;
1810 }
1811}
1812
1813static void cmd_bind_rt(struct intel_cmd *cmd,
1814 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1815 XGL_UINT count)
1816{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001817 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001818 XGL_UINT i;
1819
1820 for (i = 0; i < count; i++) {
1821 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1822 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001823 const struct intel_layout *layout = &rt->img->layout;
1824
1825 if (i == 0) {
1826 width = layout->width0;
1827 height = layout->height0;
1828 } else {
1829 if (width > layout->width0)
1830 width = layout->width0;
1831 if (height > layout->height0)
1832 height = layout->height0;
1833 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001834
1835 cmd->bind.att.rt[i] = rt;
1836 }
1837
1838 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001839
Chia-I Wu8370b402014-08-29 12:28:37 +08001840 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001841 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001842}
1843
1844static void cmd_bind_ds(struct intel_cmd *cmd,
1845 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1846{
1847 const struct intel_ds_view *ds;
1848
1849 if (info) {
1850 cmd->bind.att.ds = intel_ds_view(info->view);
1851 ds = cmd->bind.att.ds;
1852 } else {
1853 /* all zeros */
1854 static const struct intel_ds_view null_ds;
1855 ds = &null_ds;
1856 }
1857
Chia-I Wu8370b402014-08-29 12:28:37 +08001858 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001859 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1860 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1861 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001862
1863 if (cmd_gen(cmd) >= INTEL_GEN(7))
1864 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1865 else
1866 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001867}
1868
1869static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1870 const struct intel_viewport_state *state)
1871{
1872 cmd->bind.state.viewport = state;
1873}
1874
1875static void cmd_bind_raster_state(struct intel_cmd *cmd,
1876 const struct intel_raster_state *state)
1877{
1878 cmd->bind.state.raster = state;
1879}
1880
1881static void cmd_bind_ds_state(struct intel_cmd *cmd,
1882 const struct intel_ds_state *state)
1883{
1884 cmd->bind.state.ds = state;
1885}
1886
1887static void cmd_bind_blend_state(struct intel_cmd *cmd,
1888 const struct intel_blend_state *state)
1889{
1890 cmd->bind.state.blend = state;
1891}
1892
1893static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1894 const struct intel_msaa_state *state)
1895{
1896 cmd->bind.state.msaa = state;
1897}
1898
1899static void cmd_draw(struct intel_cmd *cmd,
1900 XGL_UINT vertex_start,
1901 XGL_UINT vertex_count,
1902 XGL_UINT instance_start,
1903 XGL_UINT instance_count,
1904 bool indexed,
1905 XGL_UINT vertex_base)
1906{
1907 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1908
1909 emit_bounded_states(cmd);
1910
1911 if (indexed) {
1912 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1913 cmd->result = XGL_ERROR_UNKNOWN;
1914
1915 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1916 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1917 p->primitive_restart_index);
1918 } else {
1919 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1920 cmd->bind.index.offset, cmd->bind.index.type,
1921 p->primitive_restart);
1922 }
1923 } else {
1924 assert(!vertex_base);
1925 }
1926
1927 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1928 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1929 vertex_start, instance_count, instance_start, vertex_base);
1930 } else {
1931 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1932 vertex_start, instance_count, instance_start, vertex_base);
1933 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001934
Chia-I Wu707a29e2014-08-27 12:51:47 +08001935 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001936 /* need to re-emit all workarounds */
1937 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001938}
1939
Chia-I Wub2755562014-08-20 13:38:52 +08001940XGL_VOID XGLAPI intelCmdBindPipeline(
1941 XGL_CMD_BUFFER cmdBuffer,
1942 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1943 XGL_PIPELINE pipeline)
1944{
1945 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1946
1947 switch (pipelineBindPoint) {
1948 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001949 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001950 break;
1951 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001952 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001953 break;
1954 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001955 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001956 break;
1957 }
1958}
1959
1960XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1961 XGL_CMD_BUFFER cmdBuffer,
1962 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1963 XGL_PIPELINE_DELTA delta)
1964{
1965 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1966
1967 switch (pipelineBindPoint) {
1968 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001969 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001970 break;
1971 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001972 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001973 break;
1974 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001975 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001976 break;
1977 }
1978}
1979
1980XGL_VOID XGLAPI intelCmdBindStateObject(
1981 XGL_CMD_BUFFER cmdBuffer,
1982 XGL_STATE_BIND_POINT stateBindPoint,
1983 XGL_STATE_OBJECT state)
1984{
1985 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1986
1987 switch (stateBindPoint) {
1988 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001989 cmd_bind_viewport_state(cmd,
1990 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001991 break;
1992 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001993 cmd_bind_raster_state(cmd,
1994 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001995 break;
1996 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001997 cmd_bind_ds_state(cmd,
1998 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001999 break;
2000 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002001 cmd_bind_blend_state(cmd,
2002 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002003 break;
2004 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002005 cmd_bind_msaa_state(cmd,
2006 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002007 break;
2008 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002009 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002010 break;
2011 }
2012}
2013
2014XGL_VOID XGLAPI intelCmdBindDescriptorSet(
2015 XGL_CMD_BUFFER cmdBuffer,
2016 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2017 XGL_UINT index,
2018 XGL_DESCRIPTOR_SET descriptorSet,
2019 XGL_UINT slotOffset)
2020{
2021 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2022 struct intel_dset *dset = intel_dset(descriptorSet);
2023
2024 assert(!index);
2025
2026 switch (pipelineBindPoint) {
2027 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002028 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002029 break;
2030 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002031 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002032 break;
2033 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002034 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002035 break;
2036 }
2037}
2038
2039XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
2040 XGL_CMD_BUFFER cmdBuffer,
2041 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2042 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
2043{
2044 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2045
2046 switch (pipelineBindPoint) {
2047 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002048 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002049 break;
2050 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002051 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002052 break;
2053 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002054 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002055 break;
2056 }
2057}
2058
2059XGL_VOID XGLAPI intelCmdBindIndexData(
2060 XGL_CMD_BUFFER cmdBuffer,
2061 XGL_GPU_MEMORY mem_,
2062 XGL_GPU_SIZE offset,
2063 XGL_INDEX_TYPE indexType)
2064{
2065 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2066 struct intel_mem *mem = intel_mem(mem_);
2067
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002068 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08002069}
2070
2071XGL_VOID XGLAPI intelCmdBindAttachments(
2072 XGL_CMD_BUFFER cmdBuffer,
2073 XGL_UINT colorAttachmentCount,
2074 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
2075 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
2076{
2077 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08002078
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002079 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
2080 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08002081}
2082
2083XGL_VOID XGLAPI intelCmdDraw(
2084 XGL_CMD_BUFFER cmdBuffer,
2085 XGL_UINT firstVertex,
2086 XGL_UINT vertexCount,
2087 XGL_UINT firstInstance,
2088 XGL_UINT instanceCount)
2089{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002090 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002091
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002092 cmd_draw(cmd, firstVertex, vertexCount,
2093 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08002094}
2095
2096XGL_VOID XGLAPI intelCmdDrawIndexed(
2097 XGL_CMD_BUFFER cmdBuffer,
2098 XGL_UINT firstIndex,
2099 XGL_UINT indexCount,
2100 XGL_INT vertexOffset,
2101 XGL_UINT firstInstance,
2102 XGL_UINT instanceCount)
2103{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002104 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002105
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002106 cmd_draw(cmd, firstIndex, indexCount,
2107 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002108}
2109
2110XGL_VOID XGLAPI intelCmdDrawIndirect(
2111 XGL_CMD_BUFFER cmdBuffer,
2112 XGL_GPU_MEMORY mem,
2113 XGL_GPU_SIZE offset,
2114 XGL_UINT32 count,
2115 XGL_UINT32 stride)
2116{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002117 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2118
2119 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002120}
2121
2122XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2123 XGL_CMD_BUFFER cmdBuffer,
2124 XGL_GPU_MEMORY mem,
2125 XGL_GPU_SIZE offset,
2126 XGL_UINT32 count,
2127 XGL_UINT32 stride)
2128{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002129 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2130
2131 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002132}
2133
2134XGL_VOID XGLAPI intelCmdDispatch(
2135 XGL_CMD_BUFFER cmdBuffer,
2136 XGL_UINT x,
2137 XGL_UINT y,
2138 XGL_UINT z)
2139{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002140 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2141
2142 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002143}
2144
2145XGL_VOID XGLAPI intelCmdDispatchIndirect(
2146 XGL_CMD_BUFFER cmdBuffer,
2147 XGL_GPU_MEMORY mem,
2148 XGL_GPU_SIZE offset)
2149{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002150 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2151
2152 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002153}