blob: 019c197582da5759d64a706b2d5091dda81d4c4d [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 Wu302742d2014-08-22 10:28:29 +0800543static void gen7_3dstate_pointer(struct intel_cmd *cmd,
544 int subop, XGL_UINT pos)
545{
546 const uint8_t cmd_len = 2;
547 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
548 GEN6_RENDER_SUBTYPE_3D |
549 subop | (cmd_len - 2);
550
551 cmd_batch_reserve(cmd, cmd_len);
552 cmd_batch_write(cmd, dw0);
553 cmd_batch_write(cmd, pos << 2);
554}
555
556static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
557 const struct intel_blend_state *state)
558{
559 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
560 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
561
562 CMD_ASSERT(cmd, 6, 7.5);
563 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
564
565 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
566}
567
568static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
569 const struct intel_ds_state *state)
570{
571 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
572 const uint8_t cmd_len = 3;
573
574 CMD_ASSERT(cmd, 6, 7.5);
575 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
576
577 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
578}
579
580static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
581 uint32_t stencil_ref,
582 const uint32_t blend_color[4])
583{
584 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
585 const uint8_t cmd_len = 6;
586 XGL_UINT pos;
587 uint32_t *dw;
588
589 CMD_ASSERT(cmd, 6, 7.5);
590
591 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
592 dw[0] = stencil_ref;
593 dw[1] = 0;
594 dw[2] = blend_color[0];
595 dw[3] = blend_color[1];
596 dw[4] = blend_color[2];
597 dw[5] = blend_color[3];
598 cmd_state_advance(cmd, cmd_len);
599
600 return pos;
601}
602
Chia-I Wu8370b402014-08-29 12:28:37 +0800603static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +0800604{
Chia-I Wu8370b402014-08-29 12:28:37 +0800605 CMD_ASSERT(cmd, 6, 7.5);
606
Chia-I Wu707a29e2014-08-27 12:51:47 +0800607 if (!cmd->bind.draw_count)
608 return;
609
Chia-I Wu8370b402014-08-29 12:28:37 +0800610 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +0800611 return;
612
Chia-I Wu8370b402014-08-29 12:28:37 +0800613 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +0800614
615 /*
616 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
617 *
618 * "Pipe-control with CS-stall bit set must be sent BEFORE the
619 * pipe-control with a post-sync op and no write-cache flushes."
620 *
621 * The workaround below necessitates this workaround.
622 */
623 gen6_PIPE_CONTROL(cmd,
624 GEN6_PIPE_CONTROL_CS_STALL |
625 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
626 NULL, 0);
627
Chia-I Wu8370b402014-08-29 12:28:37 +0800628 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, cmd->scratch_bo, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +0800629}
630
Chia-I Wu8370b402014-08-29 12:28:37 +0800631static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -0600632{
Chia-I Wu48c283d2014-08-25 23:13:46 +0800633 CMD_ASSERT(cmd, 6, 7.5);
634
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800635 if (!cmd->bind.draw_count)
636 return;
637
Chia-I Wu8370b402014-08-29 12:28:37 +0800638 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL, NULL, 0);
639}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800640
Chia-I Wu8370b402014-08-29 12:28:37 +0800641static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
642{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800643 CMD_ASSERT(cmd, 7, 7.5);
644
Chia-I Wu8370b402014-08-29 12:28:37 +0800645 if (!cmd->bind.draw_count)
646 return;
647
648 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800649
650 gen6_PIPE_CONTROL(cmd,
651 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
652 cmd->scratch_bo, 0);
653}
654
Chia-I Wu8370b402014-08-29 12:28:37 +0800655static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
656{
657 CMD_ASSERT(cmd, 7, 7.5);
658
659 if (!cmd->bind.draw_count)
660 return;
661
662 /*
663 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
664 *
665 * "One of the following must also be set (when CS stall is set):
666 *
667 * * Render Target Cache Flush Enable ([12] of DW1)
668 * * Depth Cache Flush Enable ([0] of DW1)
669 * * Stall at Pixel Scoreboard ([1] of DW1)
670 * * Depth Stall ([13] of DW1)
671 * * Post-Sync Operation ([13] of DW1)"
672 */
673 gen6_PIPE_CONTROL(cmd,
674 GEN6_PIPE_CONTROL_CS_STALL |
675 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
676 NULL, 0);
677}
678
679static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
680{
681 CMD_ASSERT(cmd, 7, 7.5);
682
683 if (!cmd->bind.draw_count)
684 return;
685
686 cmd_wa_gen6_pre_depth_stall_write(cmd);
687
688 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
689}
690
691static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
692{
693 CMD_ASSERT(cmd, 6, 7.5);
694
695 if (!cmd->bind.draw_count)
696 return;
697
698 /*
699 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
700 *
701 * "Driver must guarentee that all the caches in the depth pipe are
702 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
703 * requires driver to send a PIPE_CONTROL with a CS stall along with
704 * a Depth Flush prior to this command."
705 *
706 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
707 *
708 * "Driver must ierarchi that all the caches in the depth pipe are
709 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
710 * requires driver to send a PIPE_CONTROL with a CS stall along with
711 * a Depth Flush prior to this command.
712 */
713 gen6_PIPE_CONTROL(cmd,
714 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
715 GEN6_PIPE_CONTROL_CS_STALL,
716 0, 0);
717}
718
719static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
720{
721 CMD_ASSERT(cmd, 6, 7.5);
722
723 if (!cmd->bind.draw_count)
724 return;
725
726 /*
727 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
728 *
729 * "Driver must send a least one PIPE_CONTROL command with CS Stall
730 * and a post sync operation prior to the group of depth
731 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
732 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
733 *
734 * This workaround satifies all the conditions.
735 */
736 cmd_wa_gen6_pre_depth_stall_write(cmd);
737
738 /*
739 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
740 *
741 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
742 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
743 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
744 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
745 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
746 * Depth Flush Bit set, followed by another pipelined depth stall
747 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
748 * guarantee that the pipeline from WM onwards is already flushed
749 * (e.g., via a preceding MI_FLUSH)."
750 */
751 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
752 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
753 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
754}
755
Chia-I Wu525c6602014-08-27 10:22:34 +0800756void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
757{
758 if (!cmd->bind.draw_count)
759 return;
760
761 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
762
Chia-I Wu8370b402014-08-29 12:28:37 +0800763 /*
764 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
765 *
766 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
767 * PIPE_CONTROL with any non-zero post-sync-op is required."
768 */
Chia-I Wu525c6602014-08-27 10:22:34 +0800769 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +0800770 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +0800771
772 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0);
773}
774
Chia-I Wu302742d2014-08-22 10:28:29 +0800775static void gen6_cc_states(struct intel_cmd *cmd)
776{
777 const struct intel_blend_state *blend = cmd->bind.state.blend;
778 const struct intel_ds_state *ds = cmd->bind.state.ds;
779 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800780 uint32_t stencil_ref;
781 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800782
783 CMD_ASSERT(cmd, 6, 6);
784
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800785 if (blend) {
786 blend_pos = gen6_BLEND_STATE(cmd, blend);
787 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
788 } else {
789 blend_pos = 0;
790 memset(blend_color, 0, sizeof(blend_color));
791 }
792
793 if (ds) {
794 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
795 stencil_ref = ds->cmd_stencil_ref;
796 } else {
797 ds_pos = 0;
798 stencil_ref = 0;
799 }
800
801 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800802
803 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
804}
805
Chia-I Wu1744cca2014-08-22 11:10:17 +0800806static void gen6_viewport_states(struct intel_cmd *cmd)
807{
808 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
809 XGL_UINT pos;
810
811 if (!viewport)
812 return;
813
814 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
815 viewport->cmd_align);
816
817 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
818 pos + viewport->cmd_clip_offset,
819 pos,
820 pos + viewport->cmd_cc_offset);
821
822 pos = (viewport->scissor_enable) ?
823 pos + viewport->cmd_scissor_rect_offset : 0;
824
825 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
826}
827
Chia-I Wu302742d2014-08-22 10:28:29 +0800828static void gen7_cc_states(struct intel_cmd *cmd)
829{
830 const struct intel_blend_state *blend = cmd->bind.state.blend;
831 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800832 uint32_t stencil_ref;
833 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800834 XGL_UINT pos;
835
836 CMD_ASSERT(cmd, 7, 7.5);
837
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800838 if (!blend && !ds)
839 return;
Chia-I Wu302742d2014-08-22 10:28:29 +0800840
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800841 if (blend) {
842 pos = gen6_BLEND_STATE(cmd, blend);
843 gen7_3dstate_pointer(cmd,
844 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +0800845
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800846 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
847 } else {
848 memset(blend_color, 0, sizeof(blend_color));
849 }
850
851 if (ds) {
852 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
853 gen7_3dstate_pointer(cmd,
854 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
855 } else {
856 stencil_ref = 0;
857 }
858
859 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800860 gen7_3dstate_pointer(cmd,
861 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
862}
863
Chia-I Wu1744cca2014-08-22 11:10:17 +0800864static void gen7_viewport_states(struct intel_cmd *cmd)
865{
866 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
867 XGL_UINT pos;
868
869 if (!viewport)
870 return;
871
872 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
873 viewport->cmd_align);
874
875 gen7_3dstate_pointer(cmd,
876 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
877 gen7_3dstate_pointer(cmd,
878 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
879 pos + viewport->cmd_cc_offset);
880 if (viewport->scissor_enable) {
881 gen7_3dstate_pointer(cmd,
882 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
883 pos + viewport->cmd_scissor_rect_offset);
884 }
885}
886
Chia-I Wu7fd5cac2014-08-27 13:19:29 +0800887static void gen6_pcb(struct intel_cmd *cmd, int subop,
888 const XGL_PIPELINE_SHADER *sh)
889{
890 const uint8_t cmd_len = 5;
891 const XGL_UINT alignment = 32;
892 const XGL_UINT max_size =
893 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
894 const XGL_UINT max_pcb = 4;
895 uint32_t pcb[4] = { 0, 0, 0, 0 };
896 XGL_FLAGS pcb_enables = 0;
897 XGL_SIZE total_size = 0;
898 uint32_t dw0;
899 XGL_UINT i;
900
901 for (i = 0; i < sh->linkConstBufferCount; i++) {
902 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
903 const XGL_SIZE size = u_align(info->bufferSize, alignment);
904 void *ptr;
905
906 if (info->bufferId >= max_pcb ||
907 pcb_enables & ((1 << info->bufferId)) ||
908 total_size + info->bufferSize > max_size) {
909 cmd->result = XGL_ERROR_UNKNOWN;
910 return;
911 }
912 if (!size)
913 continue;
914
915 pcb_enables |= 1 << info->bufferId;
916 total_size += size;
917
918 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
919 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
920 memcpy(ptr, info->pBufferData, info->bufferSize);
921 cmd_state_advance(cmd, size / sizeof(uint32_t));
922
923 pcb[info->bufferId] |= size / alignment - 1;
924 }
925
926 dw0 = GEN6_RENDER_TYPE_RENDER |
927 GEN6_RENDER_SUBTYPE_3D |
928 subop |
929 pcb_enables << 12 |
930 (cmd_len - 2);
931
932 cmd_batch_reserve(cmd, cmd_len);
933 cmd_batch_write(cmd, dw0);
934 cmd_batch_write(cmd, pcb[0]);
935 cmd_batch_write(cmd, pcb[1]);
936 cmd_batch_write(cmd, pcb[2]);
937 cmd_batch_write(cmd, pcb[3]);
938}
939
940static void gen7_pcb(struct intel_cmd *cmd, int subop,
941 const XGL_PIPELINE_SHADER *sh)
942{
943 const uint8_t cmd_len = 7;
944 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
945 GEN6_RENDER_SUBTYPE_3D |
946 subop |
947 (cmd_len - 2);
948 const XGL_UINT alignment = 32;
949 const XGL_UINT max_size = 2048;
950 const XGL_UINT max_pcb = 4;
951 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
952 uint32_t pcb[4] = { 0, 0, 0, 0 };
953 XGL_FLAGS pcb_enables = 0;
954 XGL_SIZE total_size = 0;
955 XGL_UINT i;
956
957 for (i = 0; i < sh->linkConstBufferCount; i++) {
958 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
959 const XGL_SIZE size = u_align(info->bufferSize, alignment);
960 void *ptr;
961
962 if (info->bufferId >= max_pcb ||
963 pcb_enables & ((1 << info->bufferId)) ||
964 total_size + info->bufferSize > max_size) {
965 cmd->result = XGL_ERROR_UNKNOWN;
966 return;
967 }
968 if (!size)
969 continue;
970
971 pcb_enables |= 1 << info->bufferId;
972 total_size += size;
973
974 pcb_len[info->bufferId] = size / alignment;
975
976 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
977 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
978 memcpy(ptr, info->pBufferData, info->bufferSize);
979 cmd_state_advance(cmd, size / sizeof(uint32_t));
980 }
981
982 /* no holes */
983 if (!u_is_pow2(pcb_enables + 1)) {
984 cmd->result = XGL_ERROR_UNKNOWN;
985 return;
986 }
987
988 cmd_batch_reserve(cmd, cmd_len);
989 cmd_batch_write(cmd, dw0);
990 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
991 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
992 cmd_batch_write(cmd, pcb[0]);
993 cmd_batch_write(cmd, pcb[1]);
994 cmd_batch_write(cmd, pcb[2]);
995 cmd_batch_write(cmd, pcb[3]);
996}
997
Chia-I Wu42a56202014-08-23 16:47:48 +0800998static void emit_ps_resources(struct intel_cmd *cmd,
999 const struct intel_rmap *rmap)
1000{
1001 const XGL_UINT surface_count = rmap->rt_count +
1002 rmap->resource_count + rmap->uav_count;
1003 uint32_t binding_table[256];
1004 XGL_UINT pos, i;
1005
1006 assert(surface_count <= ARRAY_SIZE(binding_table));
1007
1008 for (i = 0; i < surface_count; i++) {
1009 const struct intel_rmap_slot *slot = &rmap->slots[i];
1010 uint32_t *dw;
1011
1012 switch (slot->path_len) {
1013 case 0:
1014 pos = 0;
1015 break;
1016 case INTEL_RMAP_SLOT_RT:
1017 {
1018 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1019
1020 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1021 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1022
1023 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001024 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001025 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001026 cmd_state_advance(cmd, view->cmd_len);
1027 }
1028 break;
1029 case INTEL_RMAP_SLOT_DYN:
1030 {
1031 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001032 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001033
1034 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
1035 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
1036
1037 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +08001038 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +08001039 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001040 cmd_state_advance(cmd, view->cmd_len);
1041 }
1042 break;
1043 case 1:
1044 default:
1045 /* TODO */
1046 assert(!"no dset support");
1047 break;
1048 }
1049
1050 binding_table[i] = pos << 2;
1051 }
1052
1053 pos = cmd_state_copy(cmd, binding_table, surface_count,
1054 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
1055
1056 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1057 gen7_3dstate_pointer(cmd,
1058 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
1059 } else {
1060 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
1061 }
1062}
1063
Chia-I Wu52500102014-08-22 00:46:04 +08001064static void emit_bounded_states(struct intel_cmd *cmd)
1065{
1066 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1067
1068 /* TODO more states */
1069
Chia-I Wu1744cca2014-08-22 11:10:17 +08001070 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001071 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001072 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001073
1074 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1075 &cmd->bind.pipeline.graphics->vs);
1076 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1077 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001078 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001079 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001080 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001081
1082 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1083 &cmd->bind.pipeline.graphics->vs);
1084 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1085 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001086 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001087
Chia-I Wu42a56202014-08-23 16:47:48 +08001088 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1089
Chia-I Wu8370b402014-08-29 12:28:37 +08001090 cmd_wa_gen6_pre_depth_stall_write(cmd);
1091 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001092 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001093 cmd_batch_reserve(cmd, msaa->cmd_len);
1094 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001095}
1096
1097static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001098 const struct intel_pipe_shader *shader,
1099 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001100{
1101 uint32_t i;
1102 struct intel_cmd_shader *cmdShader;
1103
1104 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001105 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001106 /* shader is already part of pipeline */
1107 return;
1108 }
1109 }
1110
Chia-I Wu338fe642014-08-28 10:43:04 +08001111 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1112 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1113
1114 cmdShader = cmd->bind.shaderCache.shaderArray;
1115
1116 cmd->bind.shaderCache.shaderArray =
1117 icd_alloc(sizeof(*cmdShader) * new_count,
1118 0, XGL_SYSTEM_ALLOC_INTERNAL);
1119 if (cmd->bind.shaderCache.shaderArray == NULL) {
1120 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001121 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1122 return;
1123 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001124
1125 if (cmdShader) {
1126 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1127 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1128 icd_free(cmdShader);
1129 }
1130
1131 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001132 }
1133
Chia-I Wu338fe642014-08-28 10:43:04 +08001134 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001135 cmdShader->shader = shader;
1136 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001137 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001138 cmd->bind.shaderCache.used++;
1139 return;
1140}
1141
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001142static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001143 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001144{
1145 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001146
Chia-I Wu8370b402014-08-29 12:28:37 +08001147 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1148 cmd_wa_gen6_pre_depth_stall_write(cmd);
1149 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1150 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1151 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1152 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001153
1154 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001155 assert(pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001156 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001157
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001158 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001159 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001160 }
1161 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001162 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001163 }
1164 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001165 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001166 }
1167 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001168 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001169 }
1170 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001171 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001172 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001173
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001174 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1175 gen7_3DSTATE_GS(cmd);
1176 } else {
1177 gen6_3DSTATE_GS(cmd);
1178 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001179
Chia-I Wu8370b402014-08-29 12:28:37 +08001180 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1181 cmd_wa_gen7_post_command_cs_stall(cmd);
1182 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1183 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001184}
1185
1186static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1187 const struct intel_pipeline *pipeline)
1188{
1189 cmd->bind.pipeline.compute = pipeline;
1190}
1191
1192static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1193 const struct intel_pipeline_delta *delta)
1194{
1195 cmd->bind.pipeline.graphics_delta = delta;
1196}
1197
1198static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1199 const struct intel_pipeline_delta *delta)
1200{
1201 cmd->bind.pipeline.compute_delta = delta;
1202}
1203
1204static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1205 const struct intel_dset *dset,
1206 XGL_UINT slot_offset)
1207{
1208 cmd->bind.dset.graphics = dset;
1209 cmd->bind.dset.graphics_offset = slot_offset;
1210}
1211
1212static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1213 const struct intel_dset *dset,
1214 XGL_UINT slot_offset)
1215{
1216 cmd->bind.dset.compute = dset;
1217 cmd->bind.dset.compute_offset = slot_offset;
1218}
1219
1220static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1221 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1222{
1223 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1224}
1225
1226static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1227 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1228{
1229 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1230}
1231
1232static void cmd_bind_index_data(struct intel_cmd *cmd,
1233 const struct intel_mem *mem,
1234 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1235{
1236 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1237 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1238 } else {
1239 cmd->bind.index.mem = mem;
1240 cmd->bind.index.offset = offset;
1241 cmd->bind.index.type = type;
1242 }
1243}
1244
1245static void cmd_bind_rt(struct intel_cmd *cmd,
1246 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1247 XGL_UINT count)
1248{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001249 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001250 XGL_UINT i;
1251
1252 for (i = 0; i < count; i++) {
1253 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1254 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001255 const struct intel_layout *layout = &rt->img->layout;
1256
1257 if (i == 0) {
1258 width = layout->width0;
1259 height = layout->height0;
1260 } else {
1261 if (width > layout->width0)
1262 width = layout->width0;
1263 if (height > layout->height0)
1264 height = layout->height0;
1265 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001266
1267 cmd->bind.att.rt[i] = rt;
1268 }
1269
1270 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001271
Chia-I Wu8370b402014-08-29 12:28:37 +08001272 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001273 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001274}
1275
1276static void cmd_bind_ds(struct intel_cmd *cmd,
1277 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1278{
1279 const struct intel_ds_view *ds;
1280
1281 if (info) {
1282 cmd->bind.att.ds = intel_ds_view(info->view);
1283 ds = cmd->bind.att.ds;
1284 } else {
1285 /* all zeros */
1286 static const struct intel_ds_view null_ds;
1287 ds = &null_ds;
1288 }
1289
Chia-I Wu8370b402014-08-29 12:28:37 +08001290 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001291 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1292 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1293 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001294
1295 if (cmd_gen(cmd) >= INTEL_GEN(7))
1296 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1297 else
1298 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001299}
1300
1301static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1302 const struct intel_viewport_state *state)
1303{
1304 cmd->bind.state.viewport = state;
1305}
1306
1307static void cmd_bind_raster_state(struct intel_cmd *cmd,
1308 const struct intel_raster_state *state)
1309{
1310 cmd->bind.state.raster = state;
1311}
1312
1313static void cmd_bind_ds_state(struct intel_cmd *cmd,
1314 const struct intel_ds_state *state)
1315{
1316 cmd->bind.state.ds = state;
1317}
1318
1319static void cmd_bind_blend_state(struct intel_cmd *cmd,
1320 const struct intel_blend_state *state)
1321{
1322 cmd->bind.state.blend = state;
1323}
1324
1325static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1326 const struct intel_msaa_state *state)
1327{
1328 cmd->bind.state.msaa = state;
1329}
1330
1331static void cmd_draw(struct intel_cmd *cmd,
1332 XGL_UINT vertex_start,
1333 XGL_UINT vertex_count,
1334 XGL_UINT instance_start,
1335 XGL_UINT instance_count,
1336 bool indexed,
1337 XGL_UINT vertex_base)
1338{
1339 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1340
1341 emit_bounded_states(cmd);
1342
1343 if (indexed) {
1344 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1345 cmd->result = XGL_ERROR_UNKNOWN;
1346
1347 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1348 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1349 p->primitive_restart_index);
1350 } else {
1351 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1352 cmd->bind.index.offset, cmd->bind.index.type,
1353 p->primitive_restart);
1354 }
1355 } else {
1356 assert(!vertex_base);
1357 }
1358
1359 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1360 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1361 vertex_start, instance_count, instance_start, vertex_base);
1362 } else {
1363 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1364 vertex_start, instance_count, instance_start, vertex_base);
1365 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001366
Chia-I Wu707a29e2014-08-27 12:51:47 +08001367 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001368 /* need to re-emit all workarounds */
1369 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001370}
1371
Chia-I Wub2755562014-08-20 13:38:52 +08001372XGL_VOID XGLAPI intelCmdBindPipeline(
1373 XGL_CMD_BUFFER cmdBuffer,
1374 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1375 XGL_PIPELINE pipeline)
1376{
1377 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1378
1379 switch (pipelineBindPoint) {
1380 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001381 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001382 break;
1383 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001384 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001385 break;
1386 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001387 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001388 break;
1389 }
1390}
1391
1392XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1393 XGL_CMD_BUFFER cmdBuffer,
1394 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1395 XGL_PIPELINE_DELTA delta)
1396{
1397 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1398
1399 switch (pipelineBindPoint) {
1400 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001401 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001402 break;
1403 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001404 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001405 break;
1406 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001407 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001408 break;
1409 }
1410}
1411
1412XGL_VOID XGLAPI intelCmdBindStateObject(
1413 XGL_CMD_BUFFER cmdBuffer,
1414 XGL_STATE_BIND_POINT stateBindPoint,
1415 XGL_STATE_OBJECT state)
1416{
1417 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1418
1419 switch (stateBindPoint) {
1420 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001421 cmd_bind_viewport_state(cmd,
1422 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001423 break;
1424 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001425 cmd_bind_raster_state(cmd,
1426 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001427 break;
1428 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001429 cmd_bind_ds_state(cmd,
1430 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001431 break;
1432 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001433 cmd_bind_blend_state(cmd,
1434 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001435 break;
1436 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001437 cmd_bind_msaa_state(cmd,
1438 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001439 break;
1440 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001441 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001442 break;
1443 }
1444}
1445
1446XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1447 XGL_CMD_BUFFER cmdBuffer,
1448 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1449 XGL_UINT index,
1450 XGL_DESCRIPTOR_SET descriptorSet,
1451 XGL_UINT slotOffset)
1452{
1453 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1454 struct intel_dset *dset = intel_dset(descriptorSet);
1455
1456 assert(!index);
1457
1458 switch (pipelineBindPoint) {
1459 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001460 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001461 break;
1462 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001463 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001464 break;
1465 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001466 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001467 break;
1468 }
1469}
1470
1471XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1472 XGL_CMD_BUFFER cmdBuffer,
1473 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1474 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1475{
1476 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1477
1478 switch (pipelineBindPoint) {
1479 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001480 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001481 break;
1482 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001483 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001484 break;
1485 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001486 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001487 break;
1488 }
1489}
1490
1491XGL_VOID XGLAPI intelCmdBindIndexData(
1492 XGL_CMD_BUFFER cmdBuffer,
1493 XGL_GPU_MEMORY mem_,
1494 XGL_GPU_SIZE offset,
1495 XGL_INDEX_TYPE indexType)
1496{
1497 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1498 struct intel_mem *mem = intel_mem(mem_);
1499
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001500 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001501}
1502
1503XGL_VOID XGLAPI intelCmdBindAttachments(
1504 XGL_CMD_BUFFER cmdBuffer,
1505 XGL_UINT colorAttachmentCount,
1506 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1507 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1508{
1509 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001510
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001511 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1512 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001513}
1514
1515XGL_VOID XGLAPI intelCmdDraw(
1516 XGL_CMD_BUFFER cmdBuffer,
1517 XGL_UINT firstVertex,
1518 XGL_UINT vertexCount,
1519 XGL_UINT firstInstance,
1520 XGL_UINT instanceCount)
1521{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001522 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001523
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001524 cmd_draw(cmd, firstVertex, vertexCount,
1525 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08001526}
1527
1528XGL_VOID XGLAPI intelCmdDrawIndexed(
1529 XGL_CMD_BUFFER cmdBuffer,
1530 XGL_UINT firstIndex,
1531 XGL_UINT indexCount,
1532 XGL_INT vertexOffset,
1533 XGL_UINT firstInstance,
1534 XGL_UINT instanceCount)
1535{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001536 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001537
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001538 cmd_draw(cmd, firstIndex, indexCount,
1539 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001540}
1541
1542XGL_VOID XGLAPI intelCmdDrawIndirect(
1543 XGL_CMD_BUFFER cmdBuffer,
1544 XGL_GPU_MEMORY mem,
1545 XGL_GPU_SIZE offset,
1546 XGL_UINT32 count,
1547 XGL_UINT32 stride)
1548{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001549 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1550
1551 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001552}
1553
1554XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
1555 XGL_CMD_BUFFER cmdBuffer,
1556 XGL_GPU_MEMORY mem,
1557 XGL_GPU_SIZE offset,
1558 XGL_UINT32 count,
1559 XGL_UINT32 stride)
1560{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001561 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1562
1563 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001564}
1565
1566XGL_VOID XGLAPI intelCmdDispatch(
1567 XGL_CMD_BUFFER cmdBuffer,
1568 XGL_UINT x,
1569 XGL_UINT y,
1570 XGL_UINT z)
1571{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001572 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1573
1574 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001575}
1576
1577XGL_VOID XGLAPI intelCmdDispatchIndirect(
1578 XGL_CMD_BUFFER cmdBuffer,
1579 XGL_GPU_MEMORY mem,
1580 XGL_GPU_SIZE offset)
1581{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001582 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1583
1584 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001585}