blob: 9fd7efc100da57455e33a331d72d7f01fceed9bc [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 Wub2755562014-08-20 13:38:52 +080030#include "state.h"
31#include "view.h"
32#include "cmd_priv.h"
33
Chia-I Wu59c097e2014-08-21 10:51:07 +080034static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080035 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080036 uint32_t vertex_count,
37 uint32_t vertex_start,
38 uint32_t instance_count,
39 uint32_t instance_start,
40 uint32_t vertex_base)
41{
42 const uint8_t cmd_len = 6;
43 uint32_t dw0;
44
45 CMD_ASSERT(cmd, 6, 6);
46
Chia-I Wu426072d2014-08-26 14:31:55 +080047 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080048 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080049 (cmd_len - 2);
50
51 if (indexed)
52 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
53
Chia-I Wue24c3292014-08-21 14:05:23 +080054 cmd_batch_reserve(cmd, cmd_len);
55 cmd_batch_write(cmd, dw0);
56 cmd_batch_write(cmd, vertex_count);
57 cmd_batch_write(cmd, vertex_start);
58 cmd_batch_write(cmd, instance_count);
59 cmd_batch_write(cmd, instance_start);
60 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080061}
62
63static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080064 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080065 uint32_t vertex_count,
66 uint32_t vertex_start,
67 uint32_t instance_count,
68 uint32_t instance_start,
69 uint32_t vertex_base)
70{
71 const uint8_t cmd_len = 7;
72 uint32_t dw0, dw1;
73
74 CMD_ASSERT(cmd, 7, 7.5);
75
Chia-I Wu426072d2014-08-26 14:31:55 +080076 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080077 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080078
79 if (indexed)
80 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
81
Chia-I Wue24c3292014-08-21 14:05:23 +080082 cmd_batch_reserve(cmd, cmd_len);
83 cmd_batch_write(cmd, dw0);
84 cmd_batch_write(cmd, dw1);
85 cmd_batch_write(cmd, vertex_count);
86 cmd_batch_write(cmd, vertex_start);
87 cmd_batch_write(cmd, instance_count);
88 cmd_batch_write(cmd, instance_start);
89 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080090}
91
Chia-I Wu270b1e82014-08-25 15:53:39 +080092static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
93 struct intel_bo *bo, uint32_t bo_offset)
94{
95 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +080096 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +080097 (cmd_len - 2);
Chia-I Wu270b1e82014-08-25 15:53:39 +080098
99 CMD_ASSERT(cmd, 6, 7.5);
100
101 assert(bo_offset % 8 == 0);
102
103 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
104 /*
105 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
106 *
107 * "1 of the following must also be set (when CS stall is set):
108 *
109 * * Depth Cache Flush Enable ([0] of DW1)
110 * * Stall at Pixel Scoreboard ([1] of DW1)
111 * * Depth Stall ([13] of DW1)
112 * * Post-Sync Operation ([13] of DW1)
113 * * Render Target Cache Flush Enable ([12] of DW1)
114 * * Notify Enable ([8] of DW1)"
115 *
116 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
117 *
118 * "One of the following must also be set (when CS stall is set):
119 *
120 * * Render Target Cache Flush Enable ([12] of DW1)
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)"
125 */
126 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
127 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
128 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
129 GEN6_PIPE_CONTROL_DEPTH_STALL;
130
131 /* post-sync op */
132 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
133 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
134 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
135
136 if (cmd_gen(cmd) == INTEL_GEN(6))
137 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
138
139 assert(dw1 & bit_test);
140 }
141
142 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
143 /*
144 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
145 *
146 * "Following bits must be clear (when Depth Stall is set):
147 *
148 * * Render Target Cache Flush Enable ([12] of DW1)
149 * * Depth Cache Flush Enable ([0] of DW1)"
150 */
151 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
152 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
153 }
154
155 /*
156 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
157 *
158 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
159 * and PIPE_CONTROL are not supported."
160 *
161 * The kernel will add the mapping automatically (when write domain is
162 * INTEL_DOMAIN_INSTRUCTION).
163 */
164 if (cmd_gen(cmd) == INTEL_GEN(6) && bo)
165 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
166
167 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) bo);
168 cmd_batch_write(cmd, dw0);
169 cmd_batch_write(cmd, dw1);
Chia-I Wu32a22462014-08-26 14:13:46 +0800170 if (bo) {
171 cmd_batch_reloc(cmd, bo_offset, bo, INTEL_RELOC_GGTT |
172 INTEL_RELOC_WRITE);
173 } else {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800174 cmd_batch_write(cmd, 0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800175 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800176 cmd_batch_write(cmd, 0);
177 cmd_batch_write(cmd, 0);
178}
179
Chia-I Wu254db422014-08-21 11:54:29 +0800180static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
181{
182 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
183 bool supported;
184
185 CMD_ASSERT(cmd, 6, 7.5);
186
187 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
188 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
189
190 switch (p->prim_type) {
191 case GEN6_3DPRIM_POINTLIST:
192 case GEN6_3DPRIM_LINELIST:
193 case GEN6_3DPRIM_LINESTRIP:
194 case GEN6_3DPRIM_TRILIST:
195 case GEN6_3DPRIM_TRISTRIP:
196 supported = true;
197 break;
198 default:
199 supported = false;
200 break;
201 }
202
203 if (!supported)
204 return false;
205
206 switch (cmd->bind.index.type) {
207 case XGL_INDEX_8:
208 supported = (p->primitive_restart_index != 0xffu);
209 break;
210 case XGL_INDEX_16:
211 supported = (p->primitive_restart_index != 0xffffu);
212 break;
213 case XGL_INDEX_32:
214 supported = (p->primitive_restart_index != 0xffffffffu);
215 break;
216 default:
217 supported = false;
218 break;
219 }
220
221 return supported;
222}
223
Chia-I Wu59c097e2014-08-21 10:51:07 +0800224static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800225 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800226 XGL_GPU_SIZE offset,
227 XGL_INDEX_TYPE type,
228 bool enable_cut_index)
229{
230 const uint8_t cmd_len = 3;
231 uint32_t dw0, end_offset;
232 unsigned offset_align;
233
234 CMD_ASSERT(cmd, 6, 7.5);
235
Chia-I Wu426072d2014-08-26 14:31:55 +0800236 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800237
238 /* the bit is moved to 3DSTATE_VF */
239 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
240 assert(!enable_cut_index);
241 if (enable_cut_index)
242 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
243
244 switch (type) {
245 case XGL_INDEX_8:
246 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
247 offset_align = 1;
248 break;
249 case XGL_INDEX_16:
250 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
251 offset_align = 2;
252 break;
253 case XGL_INDEX_32:
254 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
255 offset_align = 4;
256 break;
257 default:
258 cmd->result = XGL_ERROR_INVALID_VALUE;
259 return;
260 break;
261 }
262
263 if (offset % offset_align) {
264 cmd->result = XGL_ERROR_INVALID_VALUE;
265 return;
266 }
267
268 /* aligned and inclusive */
269 end_offset = mem->size - (mem->size % offset_align) - 1;
270
Chia-I Wu2de65d02014-08-25 10:02:53 +0800271 cmd_batch_reserve_reloc(cmd, cmd_len, 2);
Chia-I Wue24c3292014-08-21 14:05:23 +0800272 cmd_batch_write(cmd, dw0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800273 cmd_batch_reloc(cmd, offset, mem->bo, 0);
274 cmd_batch_reloc(cmd, end_offset, mem->bo, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800275}
276
Chia-I Wu62a7f252014-08-29 11:31:16 +0800277static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
278 bool enable_cut_index,
279 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800280{
281 const uint8_t cmd_len = 2;
282 uint32_t dw0;
283
284 CMD_ASSERT(cmd, 7.5, 7.5);
285
Chia-I Wu426072d2014-08-26 14:31:55 +0800286 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800287 if (enable_cut_index)
288 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
289
Chia-I Wue24c3292014-08-21 14:05:23 +0800290 cmd_batch_reserve(cmd, cmd_len);
291 cmd_batch_write(cmd, dw0);
292 cmd_batch_write(cmd, cut_index);
Chia-I Wu254db422014-08-21 11:54:29 +0800293}
294
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800295static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
296{
297 const uint8_t cmd_len = 7;
298 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
299
300 CMD_ASSERT(cmd, 6, 6);
301
302 assert(cmd->bind.gs.shader == NULL);
303
304 cmd_batch_reserve(cmd, cmd_len);
305 cmd_batch_write(cmd, dw0);
306 cmd_batch_write(cmd, 0);
307 cmd_batch_write(cmd, 0);
308 cmd_batch_write(cmd, 0);
309 cmd_batch_write(cmd, 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT);
310 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
311 cmd_batch_write(cmd, 0);
312}
313
Chia-I Wu62a7f252014-08-29 11:31:16 +0800314static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
315{
316 const uint8_t cmd_len = 7;
317 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
318
319 CMD_ASSERT(cmd, 7, 7.5);
320
321 assert(cmd->bind.gs.shader == NULL);
322
323 cmd_batch_reserve(cmd, cmd_len);
324 cmd_batch_write(cmd, dw0);
325 cmd_batch_write(cmd, 0);
326 cmd_batch_write(cmd, 0);
327 cmd_batch_write(cmd, 0);
328 cmd_batch_write(cmd, 0);
329 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
330 cmd_batch_write(cmd, 0);
331}
332
Chia-I Wud88e02d2014-08-25 10:56:13 +0800333static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
334 XGL_UINT width, XGL_UINT height)
335{
336 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800337 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800338 (cmd_len - 2);
339
340 CMD_ASSERT(cmd, 6, 7.5);
341
342 cmd_batch_reserve(cmd, cmd_len);
343 cmd_batch_write(cmd, dw0);
344 if (width && height) {
345 cmd_batch_write(cmd, 0);
346 cmd_batch_write(cmd, (height - 1) << 16 |
347 (width - 1));
348 } else {
349 cmd_batch_write(cmd, 1);
350 cmd_batch_write(cmd, 0);
351 }
352 cmd_batch_write(cmd, 0);
353}
354
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800355static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
356 const struct intel_ds_view *view)
357{
358 const uint8_t cmd_len = 7;
359 uint32_t dw0;
360
361 CMD_ASSERT(cmd, 6, 7.5);
362
363 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800364 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
365 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800366 dw0 |= (cmd_len - 2);
367
Chia-I Wu2de65d02014-08-25 10:02:53 +0800368 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800369 cmd_batch_write(cmd, dw0);
370 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600371 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800372 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800373 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600374 } else {
375 cmd_batch_write(cmd, 0);
376 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800377 cmd_batch_write(cmd, view->cmd[2]);
378 cmd_batch_write(cmd, view->cmd[3]);
379 cmd_batch_write(cmd, view->cmd[4]);
380 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800381}
382
383static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
384 const struct intel_ds_view *view)
385{
386 const uint8_t cmd_len = 3;
387 uint32_t dw0;
388
389 CMD_ASSERT(cmd, 6, 7.5);
390
391 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800392 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
393 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800394 dw0 |= (cmd_len - 2);
395
Chia-I Wu2de65d02014-08-25 10:02:53 +0800396 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800397 cmd_batch_write(cmd, dw0);
398 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600399 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800400 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800401 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600402 } else {
403 cmd_batch_write(cmd, 0);
404 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800405}
406
407static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
408 const struct intel_ds_view *view)
409{
410 const uint8_t cmd_len = 3;
411 uint32_t dw0;
412
413 CMD_ASSERT(cmd, 6, 7.5);
414
415 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800416 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
417 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800418 dw0 |= (cmd_len - 2);
419
Chia-I Wu2de65d02014-08-25 10:02:53 +0800420 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800421 cmd_batch_write(cmd, dw0);
422 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600423 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800424 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800425 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600426 } else {
427 cmd_batch_write(cmd, 0);
428 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800429}
430
Chia-I Wuf8231032014-08-25 10:44:45 +0800431static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
432 uint32_t clear_val)
433{
434 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800435 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800436 GEN6_CLEAR_PARAMS_DW0_VALID |
437 (cmd_len - 2);
438
439 CMD_ASSERT(cmd, 6, 6);
440
441 cmd_batch_reserve(cmd, cmd_len);
442 cmd_batch_write(cmd, dw0);
443 cmd_batch_write(cmd, clear_val);
444}
445
446static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
447 uint32_t clear_val)
448{
449 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800450 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800451 (cmd_len - 2);
452
453 CMD_ASSERT(cmd, 7, 7.5);
454
455 cmd_batch_reserve(cmd, cmd_len);
456 cmd_batch_write(cmd, dw0);
457 cmd_batch_write(cmd, clear_val);
458 cmd_batch_write(cmd, 1);
459}
460
Chia-I Wu302742d2014-08-22 10:28:29 +0800461static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
462 XGL_UINT blend_pos,
463 XGL_UINT ds_pos,
464 XGL_UINT cc_pos)
465{
466 const uint8_t cmd_len = 4;
467 uint32_t dw0;
468
469 CMD_ASSERT(cmd, 6, 6);
470
Chia-I Wu426072d2014-08-26 14:31:55 +0800471 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800472 (cmd_len - 2);
473
474 cmd_batch_reserve(cmd, cmd_len);
475 cmd_batch_write(cmd, dw0);
476 cmd_batch_write(cmd, (blend_pos << 2) | 1);
477 cmd_batch_write(cmd, (ds_pos << 2) | 1);
478 cmd_batch_write(cmd, (cc_pos << 2) | 1);
479}
480
Chia-I Wu1744cca2014-08-22 11:10:17 +0800481static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
482 XGL_UINT clip_pos,
483 XGL_UINT sf_pos,
484 XGL_UINT cc_pos)
485{
486 const uint8_t cmd_len = 4;
487 uint32_t dw0;
488
489 CMD_ASSERT(cmd, 6, 6);
490
Chia-I Wu426072d2014-08-26 14:31:55 +0800491 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800492 GEN6_PTR_VP_DW0_CLIP_CHANGED |
493 GEN6_PTR_VP_DW0_SF_CHANGED |
494 GEN6_PTR_VP_DW0_CC_CHANGED |
495 (cmd_len - 2);
496
497 cmd_batch_reserve(cmd, cmd_len);
498 cmd_batch_write(cmd, dw0);
499 cmd_batch_write(cmd, clip_pos << 2);
500 cmd_batch_write(cmd, sf_pos << 2);
501 cmd_batch_write(cmd, cc_pos << 2);
502}
503
504static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
505 XGL_UINT scissor_pos)
506{
507 const uint8_t cmd_len = 2;
508 uint32_t dw0;
509
510 CMD_ASSERT(cmd, 6, 6);
511
Chia-I Wu426072d2014-08-26 14:31:55 +0800512 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800513 (cmd_len - 2);
514
515 cmd_batch_reserve(cmd, cmd_len);
516 cmd_batch_write(cmd, dw0);
517 cmd_batch_write(cmd, scissor_pos << 2);
518}
519
Chia-I Wu42a56202014-08-23 16:47:48 +0800520static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
521 XGL_UINT vs_pos,
522 XGL_UINT gs_pos,
523 XGL_UINT ps_pos)
524{
525 const uint8_t cmd_len = 4;
526 uint32_t dw0;
527
528 CMD_ASSERT(cmd, 6, 6);
529
Chia-I Wu426072d2014-08-26 14:31:55 +0800530 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800531 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
532 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
533 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
534 (cmd_len - 2);
535
536 cmd_batch_reserve(cmd, cmd_len);
537 cmd_batch_write(cmd, dw0);
538 cmd_batch_write(cmd, vs_pos << 2);
539 cmd_batch_write(cmd, gs_pos << 2);
540 cmd_batch_write(cmd, ps_pos << 2);
541}
542
Chia-I Wu257e75e2014-08-29 14:06:35 +0800543static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
544 XGL_UINT vs_pos,
545 XGL_UINT gs_pos,
546 XGL_UINT ps_pos)
547{
548 const uint8_t cmd_len = 4;
549 uint32_t dw0;
550
551 CMD_ASSERT(cmd, 6, 6);
552
553 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
554 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
555 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
556 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
557 (cmd_len - 2);
558
559 cmd_batch_reserve(cmd, cmd_len);
560 cmd_batch_write(cmd, dw0);
561 cmd_batch_write(cmd, vs_pos << 2);
562 cmd_batch_write(cmd, gs_pos << 2);
563 cmd_batch_write(cmd, ps_pos << 2);
564}
565
Chia-I Wu302742d2014-08-22 10:28:29 +0800566static void gen7_3dstate_pointer(struct intel_cmd *cmd,
567 int subop, XGL_UINT pos)
568{
569 const uint8_t cmd_len = 2;
570 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
571 GEN6_RENDER_SUBTYPE_3D |
572 subop | (cmd_len - 2);
573
574 cmd_batch_reserve(cmd, cmd_len);
575 cmd_batch_write(cmd, dw0);
576 cmd_batch_write(cmd, pos << 2);
577}
578
579static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
580 const struct intel_blend_state *state)
581{
582 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
583 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
584
585 CMD_ASSERT(cmd, 6, 7.5);
586 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
587
588 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
589}
590
591static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
592 const struct intel_ds_state *state)
593{
594 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
595 const uint8_t cmd_len = 3;
596
597 CMD_ASSERT(cmd, 6, 7.5);
598 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
599
600 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
601}
602
603static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
604 uint32_t stencil_ref,
605 const uint32_t blend_color[4])
606{
607 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
608 const uint8_t cmd_len = 6;
609 XGL_UINT pos;
610 uint32_t *dw;
611
612 CMD_ASSERT(cmd, 6, 7.5);
613
614 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
615 dw[0] = stencil_ref;
616 dw[1] = 0;
617 dw[2] = blend_color[0];
618 dw[3] = blend_color[1];
619 dw[4] = blend_color[2];
620 dw[5] = blend_color[3];
621 cmd_state_advance(cmd, cmd_len);
622
623 return pos;
624}
625
Chia-I Wu8370b402014-08-29 12:28:37 +0800626static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +0800627{
Chia-I Wu8370b402014-08-29 12:28:37 +0800628 CMD_ASSERT(cmd, 6, 7.5);
629
Chia-I Wu707a29e2014-08-27 12:51:47 +0800630 if (!cmd->bind.draw_count)
631 return;
632
Chia-I Wu8370b402014-08-29 12:28:37 +0800633 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +0800634 return;
635
Chia-I Wu8370b402014-08-29 12:28:37 +0800636 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +0800637
638 /*
639 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
640 *
641 * "Pipe-control with CS-stall bit set must be sent BEFORE the
642 * pipe-control with a post-sync op and no write-cache flushes."
643 *
644 * The workaround below necessitates this workaround.
645 */
646 gen6_PIPE_CONTROL(cmd,
647 GEN6_PIPE_CONTROL_CS_STALL |
648 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
649 NULL, 0);
650
Chia-I Wu8370b402014-08-29 12:28:37 +0800651 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, cmd->scratch_bo, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +0800652}
653
Chia-I Wu8370b402014-08-29 12:28:37 +0800654static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -0600655{
Chia-I Wu48c283d2014-08-25 23:13:46 +0800656 CMD_ASSERT(cmd, 6, 7.5);
657
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800658 if (!cmd->bind.draw_count)
659 return;
660
Chia-I Wu8370b402014-08-29 12:28:37 +0800661 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL, NULL, 0);
662}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800663
Chia-I Wu8370b402014-08-29 12:28:37 +0800664static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
665{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800666 CMD_ASSERT(cmd, 7, 7.5);
667
Chia-I Wu8370b402014-08-29 12:28:37 +0800668 if (!cmd->bind.draw_count)
669 return;
670
671 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800672
673 gen6_PIPE_CONTROL(cmd,
674 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
675 cmd->scratch_bo, 0);
676}
677
Chia-I Wu8370b402014-08-29 12:28:37 +0800678static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
679{
680 CMD_ASSERT(cmd, 7, 7.5);
681
682 if (!cmd->bind.draw_count)
683 return;
684
685 /*
686 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
687 *
688 * "One of the following must also be set (when CS stall is set):
689 *
690 * * Render Target Cache Flush Enable ([12] of DW1)
691 * * Depth Cache Flush Enable ([0] of DW1)
692 * * Stall at Pixel Scoreboard ([1] of DW1)
693 * * Depth Stall ([13] of DW1)
694 * * Post-Sync Operation ([13] of DW1)"
695 */
696 gen6_PIPE_CONTROL(cmd,
697 GEN6_PIPE_CONTROL_CS_STALL |
698 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
699 NULL, 0);
700}
701
702static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
703{
704 CMD_ASSERT(cmd, 7, 7.5);
705
706 if (!cmd->bind.draw_count)
707 return;
708
709 cmd_wa_gen6_pre_depth_stall_write(cmd);
710
711 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
712}
713
714static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
715{
716 CMD_ASSERT(cmd, 6, 7.5);
717
718 if (!cmd->bind.draw_count)
719 return;
720
721 /*
722 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
723 *
724 * "Driver must guarentee that all the caches in the depth pipe are
725 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
726 * requires driver to send a PIPE_CONTROL with a CS stall along with
727 * a Depth Flush prior to this command."
728 *
729 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
730 *
731 * "Driver must ierarchi that all the caches in the depth pipe are
732 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
733 * requires driver to send a PIPE_CONTROL with a CS stall along with
734 * a Depth Flush prior to this command.
735 */
736 gen6_PIPE_CONTROL(cmd,
737 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
738 GEN6_PIPE_CONTROL_CS_STALL,
739 0, 0);
740}
741
742static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
743{
744 CMD_ASSERT(cmd, 6, 7.5);
745
746 if (!cmd->bind.draw_count)
747 return;
748
749 /*
750 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
751 *
752 * "Driver must send a least one PIPE_CONTROL command with CS Stall
753 * and a post sync operation prior to the group of depth
754 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
755 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
756 *
757 * This workaround satifies all the conditions.
758 */
759 cmd_wa_gen6_pre_depth_stall_write(cmd);
760
761 /*
762 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
763 *
764 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
765 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
766 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
767 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
768 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
769 * Depth Flush Bit set, followed by another pipelined depth stall
770 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
771 * guarantee that the pipeline from WM onwards is already flushed
772 * (e.g., via a preceding MI_FLUSH)."
773 */
774 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
775 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
776 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
777}
778
Chia-I Wu525c6602014-08-27 10:22:34 +0800779void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
780{
781 if (!cmd->bind.draw_count)
782 return;
783
784 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
785
Chia-I Wu8370b402014-08-29 12:28:37 +0800786 /*
787 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
788 *
789 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
790 * PIPE_CONTROL with any non-zero post-sync-op is required."
791 */
Chia-I Wu525c6602014-08-27 10:22:34 +0800792 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +0800793 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +0800794
795 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0);
796}
797
Chia-I Wu302742d2014-08-22 10:28:29 +0800798static void gen6_cc_states(struct intel_cmd *cmd)
799{
800 const struct intel_blend_state *blend = cmd->bind.state.blend;
801 const struct intel_ds_state *ds = cmd->bind.state.ds;
802 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800803 uint32_t stencil_ref;
804 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800805
806 CMD_ASSERT(cmd, 6, 6);
807
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800808 if (blend) {
809 blend_pos = gen6_BLEND_STATE(cmd, blend);
810 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
811 } else {
812 blend_pos = 0;
813 memset(blend_color, 0, sizeof(blend_color));
814 }
815
816 if (ds) {
817 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
818 stencil_ref = ds->cmd_stencil_ref;
819 } else {
820 ds_pos = 0;
821 stencil_ref = 0;
822 }
823
824 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800825
826 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
827}
828
Chia-I Wu1744cca2014-08-22 11:10:17 +0800829static void gen6_viewport_states(struct intel_cmd *cmd)
830{
831 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
832 XGL_UINT pos;
833
834 if (!viewport)
835 return;
836
837 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
838 viewport->cmd_align);
839
840 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
841 pos + viewport->cmd_clip_offset,
842 pos,
843 pos + viewport->cmd_cc_offset);
844
845 pos = (viewport->scissor_enable) ?
846 pos + viewport->cmd_scissor_rect_offset : 0;
847
848 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
849}
850
Chia-I Wu302742d2014-08-22 10:28:29 +0800851static void gen7_cc_states(struct intel_cmd *cmd)
852{
853 const struct intel_blend_state *blend = cmd->bind.state.blend;
854 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800855 uint32_t stencil_ref;
856 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800857 XGL_UINT pos;
858
859 CMD_ASSERT(cmd, 7, 7.5);
860
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800861 if (!blend && !ds)
862 return;
Chia-I Wu302742d2014-08-22 10:28:29 +0800863
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800864 if (blend) {
865 pos = gen6_BLEND_STATE(cmd, blend);
866 gen7_3dstate_pointer(cmd,
867 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +0800868
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800869 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
870 } else {
871 memset(blend_color, 0, sizeof(blend_color));
872 }
873
874 if (ds) {
875 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
876 gen7_3dstate_pointer(cmd,
877 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
878 } else {
879 stencil_ref = 0;
880 }
881
882 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800883 gen7_3dstate_pointer(cmd,
884 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
885}
886
Chia-I Wu1744cca2014-08-22 11:10:17 +0800887static void gen7_viewport_states(struct intel_cmd *cmd)
888{
889 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
890 XGL_UINT pos;
891
892 if (!viewport)
893 return;
894
895 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
896 viewport->cmd_align);
897
898 gen7_3dstate_pointer(cmd,
899 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
900 gen7_3dstate_pointer(cmd,
901 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
902 pos + viewport->cmd_cc_offset);
903 if (viewport->scissor_enable) {
904 gen7_3dstate_pointer(cmd,
905 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
906 pos + viewport->cmd_scissor_rect_offset);
907 }
908}
909
Chia-I Wu7fd5cac2014-08-27 13:19:29 +0800910static void gen6_pcb(struct intel_cmd *cmd, int subop,
911 const XGL_PIPELINE_SHADER *sh)
912{
913 const uint8_t cmd_len = 5;
914 const XGL_UINT alignment = 32;
915 const XGL_UINT max_size =
916 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
917 const XGL_UINT max_pcb = 4;
918 uint32_t pcb[4] = { 0, 0, 0, 0 };
919 XGL_FLAGS pcb_enables = 0;
920 XGL_SIZE total_size = 0;
921 uint32_t dw0;
922 XGL_UINT i;
923
924 for (i = 0; i < sh->linkConstBufferCount; i++) {
925 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
926 const XGL_SIZE size = u_align(info->bufferSize, alignment);
927 void *ptr;
928
929 if (info->bufferId >= max_pcb ||
930 pcb_enables & ((1 << info->bufferId)) ||
931 total_size + info->bufferSize > max_size) {
932 cmd->result = XGL_ERROR_UNKNOWN;
933 return;
934 }
935 if (!size)
936 continue;
937
938 pcb_enables |= 1 << info->bufferId;
939 total_size += size;
940
941 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
942 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
943 memcpy(ptr, info->pBufferData, info->bufferSize);
944 cmd_state_advance(cmd, size / sizeof(uint32_t));
945
946 pcb[info->bufferId] |= size / alignment - 1;
947 }
948
949 dw0 = GEN6_RENDER_TYPE_RENDER |
950 GEN6_RENDER_SUBTYPE_3D |
951 subop |
952 pcb_enables << 12 |
953 (cmd_len - 2);
954
955 cmd_batch_reserve(cmd, cmd_len);
956 cmd_batch_write(cmd, dw0);
957 cmd_batch_write(cmd, pcb[0]);
958 cmd_batch_write(cmd, pcb[1]);
959 cmd_batch_write(cmd, pcb[2]);
960 cmd_batch_write(cmd, pcb[3]);
961}
962
963static void gen7_pcb(struct intel_cmd *cmd, int subop,
964 const XGL_PIPELINE_SHADER *sh)
965{
966 const uint8_t cmd_len = 7;
967 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
968 GEN6_RENDER_SUBTYPE_3D |
969 subop |
970 (cmd_len - 2);
971 const XGL_UINT alignment = 32;
972 const XGL_UINT max_size = 2048;
973 const XGL_UINT max_pcb = 4;
974 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
975 uint32_t pcb[4] = { 0, 0, 0, 0 };
976 XGL_FLAGS pcb_enables = 0;
977 XGL_SIZE total_size = 0;
978 XGL_UINT i;
979
980 for (i = 0; i < sh->linkConstBufferCount; i++) {
981 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
982 const XGL_SIZE size = u_align(info->bufferSize, alignment);
983 void *ptr;
984
985 if (info->bufferId >= max_pcb ||
986 pcb_enables & ((1 << info->bufferId)) ||
987 total_size + info->bufferSize > max_size) {
988 cmd->result = XGL_ERROR_UNKNOWN;
989 return;
990 }
991 if (!size)
992 continue;
993
994 pcb_enables |= 1 << info->bufferId;
995 total_size += size;
996
997 pcb_len[info->bufferId] = size / alignment;
998
999 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
1000 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
1001 memcpy(ptr, info->pBufferData, info->bufferSize);
1002 cmd_state_advance(cmd, size / sizeof(uint32_t));
1003 }
1004
1005 /* no holes */
1006 if (!u_is_pow2(pcb_enables + 1)) {
1007 cmd->result = XGL_ERROR_UNKNOWN;
1008 return;
1009 }
1010
1011 cmd_batch_reserve(cmd, cmd_len);
1012 cmd_batch_write(cmd, dw0);
1013 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
1014 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
1015 cmd_batch_write(cmd, pcb[0]);
1016 cmd_batch_write(cmd, pcb[1]);
1017 cmd_batch_write(cmd, pcb[2]);
1018 cmd_batch_write(cmd, pcb[3]);
1019}
1020
Chia-I Wu42a56202014-08-23 16:47:48 +08001021static void emit_ps_resources(struct intel_cmd *cmd,
1022 const struct intel_rmap *rmap)
1023{
1024 const XGL_UINT surface_count = rmap->rt_count +
1025 rmap->resource_count + rmap->uav_count;
1026 uint32_t binding_table[256];
1027 XGL_UINT pos, i;
1028
1029 assert(surface_count <= ARRAY_SIZE(binding_table));
1030
1031 for (i = 0; i < surface_count; i++) {
1032 const struct intel_rmap_slot *slot = &rmap->slots[i];
1033 uint32_t *dw;
1034
1035 switch (slot->path_len) {
1036 case 0:
1037 pos = 0;
1038 break;
1039 case INTEL_RMAP_SLOT_RT:
1040 {
1041 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1042
1043 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1044 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1045
1046 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001047 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001048 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001049 cmd_state_advance(cmd, view->cmd_len);
1050 }
1051 break;
1052 case INTEL_RMAP_SLOT_DYN:
1053 {
1054 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001055 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001056
1057 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1058 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1059
1060 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001061 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001062 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001063 cmd_state_advance(cmd, view->cmd_len);
1064 }
1065 break;
1066 case 1:
1067 default:
1068 /* TODO */
1069 assert(!"no dset support");
1070 break;
1071 }
1072
1073 binding_table[i] = pos << 2;
1074 }
1075
1076 pos = cmd_state_copy(cmd, binding_table, surface_count,
1077 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
1078
1079 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1080 gen7_3dstate_pointer(cmd,
1081 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001082
1083 gen7_3dstate_pointer(cmd,
1084 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1085 gen7_3dstate_pointer(cmd,
1086 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1087 gen7_3dstate_pointer(cmd,
1088 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1089 gen7_3dstate_pointer(cmd,
1090 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1091
1092 gen7_3dstate_pointer(cmd,
1093 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1094 gen7_3dstate_pointer(cmd,
1095 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1096 gen7_3dstate_pointer(cmd,
1097 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1098 gen7_3dstate_pointer(cmd,
1099 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1100 gen7_3dstate_pointer(cmd,
1101 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001102 } else {
1103 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001104 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001105 }
1106}
1107
Chia-I Wu52500102014-08-22 00:46:04 +08001108static void emit_bounded_states(struct intel_cmd *cmd)
1109{
1110 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1111
1112 /* TODO more states */
1113
Chia-I Wu1744cca2014-08-22 11:10:17 +08001114 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001115 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001116 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001117
1118 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1119 &cmd->bind.pipeline.graphics->vs);
1120 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1121 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001122 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001123 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001124 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001125
1126 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1127 &cmd->bind.pipeline.graphics->vs);
1128 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1129 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001130 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001131
Chia-I Wu42a56202014-08-23 16:47:48 +08001132 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1133
Chia-I Wu8370b402014-08-29 12:28:37 +08001134 cmd_wa_gen6_pre_depth_stall_write(cmd);
1135 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001136 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001137 cmd_batch_reserve(cmd, msaa->cmd_len);
1138 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001139}
1140
1141static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001142 const struct intel_pipe_shader *shader,
1143 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001144{
1145 uint32_t i;
1146 struct intel_cmd_shader *cmdShader;
1147
1148 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001149 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001150 /* shader is already part of pipeline */
1151 return;
1152 }
1153 }
1154
Chia-I Wu338fe642014-08-28 10:43:04 +08001155 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1156 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1157
1158 cmdShader = cmd->bind.shaderCache.shaderArray;
1159
1160 cmd->bind.shaderCache.shaderArray =
1161 icd_alloc(sizeof(*cmdShader) * new_count,
1162 0, XGL_SYSTEM_ALLOC_INTERNAL);
1163 if (cmd->bind.shaderCache.shaderArray == NULL) {
1164 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001165 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1166 return;
1167 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001168
1169 if (cmdShader) {
1170 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1171 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1172 icd_free(cmdShader);
1173 }
1174
1175 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001176 }
1177
Chia-I Wu338fe642014-08-28 10:43:04 +08001178 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001179 cmdShader->shader = shader;
1180 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001181 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001182 cmd->bind.shaderCache.used++;
1183 return;
1184}
1185
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001186static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001187 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001188{
1189 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001190
Chia-I Wu8370b402014-08-29 12:28:37 +08001191 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1192 cmd_wa_gen6_pre_depth_stall_write(cmd);
1193 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1194 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1195 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1196 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001197
1198 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001199 assert(pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001200 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001201
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001202 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001203 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001204 }
1205 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001206 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001207 }
1208 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001209 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001210 }
1211 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001212 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001213 }
1214 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001215 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001216 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001217
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001218 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1219 gen7_3DSTATE_GS(cmd);
1220 } else {
1221 gen6_3DSTATE_GS(cmd);
1222 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001223
Chia-I Wu8370b402014-08-29 12:28:37 +08001224 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1225 cmd_wa_gen7_post_command_cs_stall(cmd);
1226 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1227 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001228}
1229
1230static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1231 const struct intel_pipeline *pipeline)
1232{
1233 cmd->bind.pipeline.compute = pipeline;
1234}
1235
1236static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1237 const struct intel_pipeline_delta *delta)
1238{
1239 cmd->bind.pipeline.graphics_delta = delta;
1240}
1241
1242static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1243 const struct intel_pipeline_delta *delta)
1244{
1245 cmd->bind.pipeline.compute_delta = delta;
1246}
1247
1248static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1249 const struct intel_dset *dset,
1250 XGL_UINT slot_offset)
1251{
1252 cmd->bind.dset.graphics = dset;
1253 cmd->bind.dset.graphics_offset = slot_offset;
1254}
1255
1256static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1257 const struct intel_dset *dset,
1258 XGL_UINT slot_offset)
1259{
1260 cmd->bind.dset.compute = dset;
1261 cmd->bind.dset.compute_offset = slot_offset;
1262}
1263
1264static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1265 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1266{
1267 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1268}
1269
1270static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1271 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1272{
1273 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1274}
1275
1276static void cmd_bind_index_data(struct intel_cmd *cmd,
1277 const struct intel_mem *mem,
1278 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1279{
1280 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1281 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1282 } else {
1283 cmd->bind.index.mem = mem;
1284 cmd->bind.index.offset = offset;
1285 cmd->bind.index.type = type;
1286 }
1287}
1288
1289static void cmd_bind_rt(struct intel_cmd *cmd,
1290 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1291 XGL_UINT count)
1292{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001293 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001294 XGL_UINT i;
1295
1296 for (i = 0; i < count; i++) {
1297 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1298 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001299 const struct intel_layout *layout = &rt->img->layout;
1300
1301 if (i == 0) {
1302 width = layout->width0;
1303 height = layout->height0;
1304 } else {
1305 if (width > layout->width0)
1306 width = layout->width0;
1307 if (height > layout->height0)
1308 height = layout->height0;
1309 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001310
1311 cmd->bind.att.rt[i] = rt;
1312 }
1313
1314 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001315
Chia-I Wu8370b402014-08-29 12:28:37 +08001316 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001317 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001318}
1319
1320static void cmd_bind_ds(struct intel_cmd *cmd,
1321 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1322{
1323 const struct intel_ds_view *ds;
1324
1325 if (info) {
1326 cmd->bind.att.ds = intel_ds_view(info->view);
1327 ds = cmd->bind.att.ds;
1328 } else {
1329 /* all zeros */
1330 static const struct intel_ds_view null_ds;
1331 ds = &null_ds;
1332 }
1333
Chia-I Wu8370b402014-08-29 12:28:37 +08001334 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001335 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1336 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1337 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001338
1339 if (cmd_gen(cmd) >= INTEL_GEN(7))
1340 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1341 else
1342 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001343}
1344
1345static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1346 const struct intel_viewport_state *state)
1347{
1348 cmd->bind.state.viewport = state;
1349}
1350
1351static void cmd_bind_raster_state(struct intel_cmd *cmd,
1352 const struct intel_raster_state *state)
1353{
1354 cmd->bind.state.raster = state;
1355}
1356
1357static void cmd_bind_ds_state(struct intel_cmd *cmd,
1358 const struct intel_ds_state *state)
1359{
1360 cmd->bind.state.ds = state;
1361}
1362
1363static void cmd_bind_blend_state(struct intel_cmd *cmd,
1364 const struct intel_blend_state *state)
1365{
1366 cmd->bind.state.blend = state;
1367}
1368
1369static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1370 const struct intel_msaa_state *state)
1371{
1372 cmd->bind.state.msaa = state;
1373}
1374
1375static void cmd_draw(struct intel_cmd *cmd,
1376 XGL_UINT vertex_start,
1377 XGL_UINT vertex_count,
1378 XGL_UINT instance_start,
1379 XGL_UINT instance_count,
1380 bool indexed,
1381 XGL_UINT vertex_base)
1382{
1383 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1384
1385 emit_bounded_states(cmd);
1386
1387 if (indexed) {
1388 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1389 cmd->result = XGL_ERROR_UNKNOWN;
1390
1391 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1392 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1393 p->primitive_restart_index);
1394 } else {
1395 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1396 cmd->bind.index.offset, cmd->bind.index.type,
1397 p->primitive_restart);
1398 }
1399 } else {
1400 assert(!vertex_base);
1401 }
1402
1403 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1404 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1405 vertex_start, instance_count, instance_start, vertex_base);
1406 } else {
1407 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1408 vertex_start, instance_count, instance_start, vertex_base);
1409 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001410
Chia-I Wu707a29e2014-08-27 12:51:47 +08001411 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001412 /* need to re-emit all workarounds */
1413 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001414}
1415
Chia-I Wub2755562014-08-20 13:38:52 +08001416XGL_VOID XGLAPI intelCmdBindPipeline(
1417 XGL_CMD_BUFFER cmdBuffer,
1418 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1419 XGL_PIPELINE pipeline)
1420{
1421 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1422
1423 switch (pipelineBindPoint) {
1424 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001425 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001426 break;
1427 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001428 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001429 break;
1430 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001431 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001432 break;
1433 }
1434}
1435
1436XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1437 XGL_CMD_BUFFER cmdBuffer,
1438 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1439 XGL_PIPELINE_DELTA delta)
1440{
1441 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1442
1443 switch (pipelineBindPoint) {
1444 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001445 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001446 break;
1447 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001448 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001449 break;
1450 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001451 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001452 break;
1453 }
1454}
1455
1456XGL_VOID XGLAPI intelCmdBindStateObject(
1457 XGL_CMD_BUFFER cmdBuffer,
1458 XGL_STATE_BIND_POINT stateBindPoint,
1459 XGL_STATE_OBJECT state)
1460{
1461 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1462
1463 switch (stateBindPoint) {
1464 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001465 cmd_bind_viewport_state(cmd,
1466 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001467 break;
1468 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001469 cmd_bind_raster_state(cmd,
1470 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001471 break;
1472 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001473 cmd_bind_ds_state(cmd,
1474 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001475 break;
1476 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001477 cmd_bind_blend_state(cmd,
1478 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001479 break;
1480 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001481 cmd_bind_msaa_state(cmd,
1482 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001483 break;
1484 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001485 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001486 break;
1487 }
1488}
1489
1490XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1491 XGL_CMD_BUFFER cmdBuffer,
1492 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1493 XGL_UINT index,
1494 XGL_DESCRIPTOR_SET descriptorSet,
1495 XGL_UINT slotOffset)
1496{
1497 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1498 struct intel_dset *dset = intel_dset(descriptorSet);
1499
1500 assert(!index);
1501
1502 switch (pipelineBindPoint) {
1503 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001504 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001505 break;
1506 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001507 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001508 break;
1509 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001510 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001511 break;
1512 }
1513}
1514
1515XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1516 XGL_CMD_BUFFER cmdBuffer,
1517 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1518 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1519{
1520 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1521
1522 switch (pipelineBindPoint) {
1523 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001524 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001525 break;
1526 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001527 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001528 break;
1529 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001530 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001531 break;
1532 }
1533}
1534
1535XGL_VOID XGLAPI intelCmdBindIndexData(
1536 XGL_CMD_BUFFER cmdBuffer,
1537 XGL_GPU_MEMORY mem_,
1538 XGL_GPU_SIZE offset,
1539 XGL_INDEX_TYPE indexType)
1540{
1541 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1542 struct intel_mem *mem = intel_mem(mem_);
1543
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001544 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001545}
1546
1547XGL_VOID XGLAPI intelCmdBindAttachments(
1548 XGL_CMD_BUFFER cmdBuffer,
1549 XGL_UINT colorAttachmentCount,
1550 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1551 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1552{
1553 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001554
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001555 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1556 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001557}
1558
1559XGL_VOID XGLAPI intelCmdDraw(
1560 XGL_CMD_BUFFER cmdBuffer,
1561 XGL_UINT firstVertex,
1562 XGL_UINT vertexCount,
1563 XGL_UINT firstInstance,
1564 XGL_UINT instanceCount)
1565{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001566 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001567
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001568 cmd_draw(cmd, firstVertex, vertexCount,
1569 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08001570}
1571
1572XGL_VOID XGLAPI intelCmdDrawIndexed(
1573 XGL_CMD_BUFFER cmdBuffer,
1574 XGL_UINT firstIndex,
1575 XGL_UINT indexCount,
1576 XGL_INT vertexOffset,
1577 XGL_UINT firstInstance,
1578 XGL_UINT instanceCount)
1579{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001580 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001581
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001582 cmd_draw(cmd, firstIndex, indexCount,
1583 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001584}
1585
1586XGL_VOID XGLAPI intelCmdDrawIndirect(
1587 XGL_CMD_BUFFER cmdBuffer,
1588 XGL_GPU_MEMORY mem,
1589 XGL_GPU_SIZE offset,
1590 XGL_UINT32 count,
1591 XGL_UINT32 stride)
1592{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001593 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1594
1595 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001596}
1597
1598XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
1599 XGL_CMD_BUFFER cmdBuffer,
1600 XGL_GPU_MEMORY mem,
1601 XGL_GPU_SIZE offset,
1602 XGL_UINT32 count,
1603 XGL_UINT32 stride)
1604{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001605 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1606
1607 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001608}
1609
1610XGL_VOID XGLAPI intelCmdDispatch(
1611 XGL_CMD_BUFFER cmdBuffer,
1612 XGL_UINT x,
1613 XGL_UINT y,
1614 XGL_UINT z)
1615{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001616 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1617
1618 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001619}
1620
1621XGL_VOID XGLAPI intelCmdDispatchIndirect(
1622 XGL_CMD_BUFFER cmdBuffer,
1623 XGL_GPU_MEMORY mem,
1624 XGL_GPU_SIZE offset)
1625{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001626 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1627
1628 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001629}