blob: 0b37c55ee2b635f6288e4eefb9d018f3fb257c0a [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 Wu48c283d2014-08-25 23:13:46 +080034enum {
35 GEN6_WA_POST_SYNC_FLUSH = 1 << 0,
36 GEN6_WA_DS_FLUSH = 1 << 1,
37};
38
Chia-I Wu59c097e2014-08-21 10:51:07 +080039static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080040 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080041 uint32_t vertex_count,
42 uint32_t vertex_start,
43 uint32_t instance_count,
44 uint32_t instance_start,
45 uint32_t vertex_base)
46{
47 const uint8_t cmd_len = 6;
48 uint32_t dw0;
49
50 CMD_ASSERT(cmd, 6, 6);
51
Chia-I Wub0b9f692014-08-21 11:33:29 +080052 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080053 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080054 (cmd_len - 2);
55
56 if (indexed)
57 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
58
Chia-I Wue24c3292014-08-21 14:05:23 +080059 cmd_batch_reserve(cmd, cmd_len);
60 cmd_batch_write(cmd, dw0);
61 cmd_batch_write(cmd, vertex_count);
62 cmd_batch_write(cmd, vertex_start);
63 cmd_batch_write(cmd, instance_count);
64 cmd_batch_write(cmd, instance_start);
65 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080066}
67
68static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080069 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080070 uint32_t vertex_count,
71 uint32_t vertex_start,
72 uint32_t instance_count,
73 uint32_t instance_start,
74 uint32_t vertex_base)
75{
76 const uint8_t cmd_len = 7;
77 uint32_t dw0, dw1;
78
79 CMD_ASSERT(cmd, 7, 7.5);
80
Chia-I Wub0b9f692014-08-21 11:33:29 +080081 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080082 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080083
84 if (indexed)
85 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
86
Chia-I Wue24c3292014-08-21 14:05:23 +080087 cmd_batch_reserve(cmd, cmd_len);
88 cmd_batch_write(cmd, dw0);
89 cmd_batch_write(cmd, dw1);
90 cmd_batch_write(cmd, vertex_count);
91 cmd_batch_write(cmd, vertex_start);
92 cmd_batch_write(cmd, instance_count);
93 cmd_batch_write(cmd, instance_start);
94 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080095}
96
Chia-I Wu270b1e82014-08-25 15:53:39 +080097static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
98 struct intel_bo *bo, uint32_t bo_offset)
99{
100 const uint8_t cmd_len = 5;
101 const uint32_t dw0 = GEN_RENDER_CMD(3D, GEN6, PIPE_CONTROL) |
102 (cmd_len - 2);
103 const uint32_t read_domains = INTEL_DOMAIN_INSTRUCTION;
104 const uint32_t write_domain = INTEL_DOMAIN_INSTRUCTION;
105
106 CMD_ASSERT(cmd, 6, 7.5);
107
108 assert(bo_offset % 8 == 0);
109
110 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
111 /*
112 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
113 *
114 * "1 of the following must also be set (when CS stall is set):
115 *
116 * * Depth Cache Flush Enable ([0] of DW1)
117 * * Stall at Pixel Scoreboard ([1] of DW1)
118 * * Depth Stall ([13] of DW1)
119 * * Post-Sync Operation ([13] of DW1)
120 * * Render Target Cache Flush Enable ([12] of DW1)
121 * * Notify Enable ([8] of DW1)"
122 *
123 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
124 *
125 * "One of the following must also be set (when CS stall is set):
126 *
127 * * Render Target Cache Flush Enable ([12] of DW1)
128 * * Depth Cache Flush Enable ([0] of DW1)
129 * * Stall at Pixel Scoreboard ([1] of DW1)
130 * * Depth Stall ([13] of DW1)
131 * * Post-Sync Operation ([13] of DW1)"
132 */
133 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
134 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
135 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
136 GEN6_PIPE_CONTROL_DEPTH_STALL;
137
138 /* post-sync op */
139 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
140 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
141 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
142
143 if (cmd_gen(cmd) == INTEL_GEN(6))
144 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
145
146 assert(dw1 & bit_test);
147 }
148
149 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
150 /*
151 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
152 *
153 * "Following bits must be clear (when Depth Stall is set):
154 *
155 * * Render Target Cache Flush Enable ([12] of DW1)
156 * * Depth Cache Flush Enable ([0] of DW1)"
157 */
158 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
159 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
160 }
161
162 /*
163 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
164 *
165 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
166 * and PIPE_CONTROL are not supported."
167 *
168 * The kernel will add the mapping automatically (when write domain is
169 * INTEL_DOMAIN_INSTRUCTION).
170 */
171 if (cmd_gen(cmd) == INTEL_GEN(6) && bo)
172 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
173
174 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) bo);
175 cmd_batch_write(cmd, dw0);
176 cmd_batch_write(cmd, dw1);
177 if (bo)
178 cmd_batch_reloc(cmd, bo_offset, bo, read_domains, write_domain);
179 else
180 cmd_batch_write(cmd, 0);
181 cmd_batch_write(cmd, 0);
182 cmd_batch_write(cmd, 0);
183}
184
Chia-I Wu254db422014-08-21 11:54:29 +0800185static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
186{
187 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
188 bool supported;
189
190 CMD_ASSERT(cmd, 6, 7.5);
191
192 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
193 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
194
195 switch (p->prim_type) {
196 case GEN6_3DPRIM_POINTLIST:
197 case GEN6_3DPRIM_LINELIST:
198 case GEN6_3DPRIM_LINESTRIP:
199 case GEN6_3DPRIM_TRILIST:
200 case GEN6_3DPRIM_TRISTRIP:
201 supported = true;
202 break;
203 default:
204 supported = false;
205 break;
206 }
207
208 if (!supported)
209 return false;
210
211 switch (cmd->bind.index.type) {
212 case XGL_INDEX_8:
213 supported = (p->primitive_restart_index != 0xffu);
214 break;
215 case XGL_INDEX_16:
216 supported = (p->primitive_restart_index != 0xffffu);
217 break;
218 case XGL_INDEX_32:
219 supported = (p->primitive_restart_index != 0xffffffffu);
220 break;
221 default:
222 supported = false;
223 break;
224 }
225
226 return supported;
227}
228
Chia-I Wu59c097e2014-08-21 10:51:07 +0800229static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800230 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800231 XGL_GPU_SIZE offset,
232 XGL_INDEX_TYPE type,
233 bool enable_cut_index)
234{
235 const uint8_t cmd_len = 3;
236 uint32_t dw0, end_offset;
237 unsigned offset_align;
238
239 CMD_ASSERT(cmd, 6, 7.5);
240
Chia-I Wub0b9f692014-08-21 11:33:29 +0800241 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800242
243 /* the bit is moved to 3DSTATE_VF */
244 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
245 assert(!enable_cut_index);
246 if (enable_cut_index)
247 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
248
249 switch (type) {
250 case XGL_INDEX_8:
251 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
252 offset_align = 1;
253 break;
254 case XGL_INDEX_16:
255 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
256 offset_align = 2;
257 break;
258 case XGL_INDEX_32:
259 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
260 offset_align = 4;
261 break;
262 default:
263 cmd->result = XGL_ERROR_INVALID_VALUE;
264 return;
265 break;
266 }
267
268 if (offset % offset_align) {
269 cmd->result = XGL_ERROR_INVALID_VALUE;
270 return;
271 }
272
273 /* aligned and inclusive */
274 end_offset = mem->size - (mem->size % offset_align) - 1;
275
Chia-I Wu2de65d02014-08-25 10:02:53 +0800276 cmd_batch_reserve_reloc(cmd, cmd_len, 2);
Chia-I Wue24c3292014-08-21 14:05:23 +0800277 cmd_batch_write(cmd, dw0);
Chia-I Wu9ee38722014-08-25 12:11:36 +0800278 cmd_batch_reloc(cmd, offset, mem->bo, INTEL_DOMAIN_VERTEX, 0);
279 cmd_batch_reloc(cmd, end_offset, mem->bo, INTEL_DOMAIN_VERTEX, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280}
281
Chia-I Wu254db422014-08-21 11:54:29 +0800282static inline void
283gen75_3DSTATE_VF(struct intel_cmd *cmd,
284 bool enable_cut_index,
285 uint32_t cut_index)
286{
287 const uint8_t cmd_len = 2;
288 uint32_t dw0;
289
290 CMD_ASSERT(cmd, 7.5, 7.5);
291
292 dw0 = GEN_RENDER_CMD(3D, GEN75, 3DSTATE_VF) | (cmd_len - 2);
293 if (enable_cut_index)
294 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
295
Chia-I Wue24c3292014-08-21 14:05:23 +0800296 cmd_batch_reserve(cmd, cmd_len);
297 cmd_batch_write(cmd, dw0);
298 cmd_batch_write(cmd, cut_index);
Chia-I Wu254db422014-08-21 11:54:29 +0800299}
300
Chia-I Wud88e02d2014-08-25 10:56:13 +0800301static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
302 XGL_UINT width, XGL_UINT height)
303{
304 const uint8_t cmd_len = 4;
305 const uint32_t dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_DRAWING_RECTANGLE) |
306 (cmd_len - 2);
307
308 CMD_ASSERT(cmd, 6, 7.5);
309
310 cmd_batch_reserve(cmd, cmd_len);
311 cmd_batch_write(cmd, dw0);
312 if (width && height) {
313 cmd_batch_write(cmd, 0);
314 cmd_batch_write(cmd, (height - 1) << 16 |
315 (width - 1));
316 } else {
317 cmd_batch_write(cmd, 1);
318 cmd_batch_write(cmd, 0);
319 }
320 cmd_batch_write(cmd, 0);
321}
322
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800323static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
324 const struct intel_ds_view *view)
325{
326 const uint8_t cmd_len = 7;
327 uint32_t dw0;
328
329 CMD_ASSERT(cmd, 6, 7.5);
330
331 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
332 GEN_RENDER_CMD(3D, GEN7, 3DSTATE_DEPTH_BUFFER) :
333 GEN_RENDER_CMD(3D, GEN6, 3DSTATE_DEPTH_BUFFER);
334 dw0 |= (cmd_len - 2);
335
Chia-I Wu2de65d02014-08-25 10:02:53 +0800336 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800337 cmd_batch_write(cmd, dw0);
338 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600339 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800340 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600341 INTEL_DOMAIN_RENDER,
342 INTEL_DOMAIN_RENDER);
343 } else {
344 cmd_batch_write(cmd, 0);
345 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800346 cmd_batch_write(cmd, view->cmd[2]);
347 cmd_batch_write(cmd, view->cmd[3]);
348 cmd_batch_write(cmd, view->cmd[4]);
349 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800350}
351
352static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
353 const struct intel_ds_view *view)
354{
355 const uint8_t cmd_len = 3;
356 uint32_t dw0;
357
358 CMD_ASSERT(cmd, 6, 7.5);
359
360 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
361 GEN_RENDER_CMD(3D, GEN7, 3DSTATE_STENCIL_BUFFER) :
362 GEN_RENDER_CMD(3D, GEN6, 3DSTATE_STENCIL_BUFFER);
363 dw0 |= (cmd_len - 2);
364
Chia-I Wu2de65d02014-08-25 10:02:53 +0800365 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800366 cmd_batch_write(cmd, dw0);
367 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600368 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800369 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600370 INTEL_DOMAIN_RENDER,
371 INTEL_DOMAIN_RENDER);
372 } else {
373 cmd_batch_write(cmd, 0);
374 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800375}
376
377static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
378 const struct intel_ds_view *view)
379{
380 const uint8_t cmd_len = 3;
381 uint32_t dw0;
382
383 CMD_ASSERT(cmd, 6, 7.5);
384
385 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
386 GEN_RENDER_CMD(3D, GEN7, 3DSTATE_HIER_DEPTH_BUFFER) :
387 GEN_RENDER_CMD(3D, GEN6, 3DSTATE_HIER_DEPTH_BUFFER);
388 dw0 |= (cmd_len - 2);
389
Chia-I Wu2de65d02014-08-25 10:02:53 +0800390 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800391 cmd_batch_write(cmd, dw0);
392 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600393 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800394 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600395 INTEL_DOMAIN_RENDER,
396 INTEL_DOMAIN_RENDER);
397 } else {
398 cmd_batch_write(cmd, 0);
399 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800400}
401
Chia-I Wuf8231032014-08-25 10:44:45 +0800402static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
403 uint32_t clear_val)
404{
405 const uint8_t cmd_len = 2;
406 const uint32_t dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_CLEAR_PARAMS) |
407 GEN6_CLEAR_PARAMS_DW0_VALID |
408 (cmd_len - 2);
409
410 CMD_ASSERT(cmd, 6, 6);
411
412 cmd_batch_reserve(cmd, cmd_len);
413 cmd_batch_write(cmd, dw0);
414 cmd_batch_write(cmd, clear_val);
415}
416
417static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
418 uint32_t clear_val)
419{
420 const uint8_t cmd_len = 3;
421 const uint32_t dw0 = GEN_RENDER_CMD(3D, GEN7, 3DSTATE_CLEAR_PARAMS) |
422 (cmd_len - 2);
423
424 CMD_ASSERT(cmd, 7, 7.5);
425
426 cmd_batch_reserve(cmd, cmd_len);
427 cmd_batch_write(cmd, dw0);
428 cmd_batch_write(cmd, clear_val);
429 cmd_batch_write(cmd, 1);
430}
431
Chia-I Wu302742d2014-08-22 10:28:29 +0800432static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
433 XGL_UINT blend_pos,
434 XGL_UINT ds_pos,
435 XGL_UINT cc_pos)
436{
437 const uint8_t cmd_len = 4;
438 uint32_t dw0;
439
440 CMD_ASSERT(cmd, 6, 6);
441
442 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_CC_STATE_POINTERS) |
443 (cmd_len - 2);
444
445 cmd_batch_reserve(cmd, cmd_len);
446 cmd_batch_write(cmd, dw0);
447 cmd_batch_write(cmd, (blend_pos << 2) | 1);
448 cmd_batch_write(cmd, (ds_pos << 2) | 1);
449 cmd_batch_write(cmd, (cc_pos << 2) | 1);
450}
451
Chia-I Wu1744cca2014-08-22 11:10:17 +0800452static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
453 XGL_UINT clip_pos,
454 XGL_UINT sf_pos,
455 XGL_UINT cc_pos)
456{
457 const uint8_t cmd_len = 4;
458 uint32_t dw0;
459
460 CMD_ASSERT(cmd, 6, 6);
461
462 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_VIEWPORT_STATE_POINTERS) |
463 GEN6_PTR_VP_DW0_CLIP_CHANGED |
464 GEN6_PTR_VP_DW0_SF_CHANGED |
465 GEN6_PTR_VP_DW0_CC_CHANGED |
466 (cmd_len - 2);
467
468 cmd_batch_reserve(cmd, cmd_len);
469 cmd_batch_write(cmd, dw0);
470 cmd_batch_write(cmd, clip_pos << 2);
471 cmd_batch_write(cmd, sf_pos << 2);
472 cmd_batch_write(cmd, cc_pos << 2);
473}
474
475static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
476 XGL_UINT scissor_pos)
477{
478 const uint8_t cmd_len = 2;
479 uint32_t dw0;
480
481 CMD_ASSERT(cmd, 6, 6);
482
483 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_SCISSOR_STATE_POINTERS) |
484 (cmd_len - 2);
485
486 cmd_batch_reserve(cmd, cmd_len);
487 cmd_batch_write(cmd, dw0);
488 cmd_batch_write(cmd, scissor_pos << 2);
489}
490
Chia-I Wu42a56202014-08-23 16:47:48 +0800491static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
492 XGL_UINT vs_pos,
493 XGL_UINT gs_pos,
494 XGL_UINT ps_pos)
495{
496 const uint8_t cmd_len = 4;
497 uint32_t dw0;
498
499 CMD_ASSERT(cmd, 6, 6);
500
501 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_BINDING_TABLE_POINTERS) |
502 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
503 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
504 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
505 (cmd_len - 2);
506
507 cmd_batch_reserve(cmd, cmd_len);
508 cmd_batch_write(cmd, dw0);
509 cmd_batch_write(cmd, vs_pos << 2);
510 cmd_batch_write(cmd, gs_pos << 2);
511 cmd_batch_write(cmd, ps_pos << 2);
512}
513
Chia-I Wu302742d2014-08-22 10:28:29 +0800514static void gen7_3dstate_pointer(struct intel_cmd *cmd,
515 int subop, XGL_UINT pos)
516{
517 const uint8_t cmd_len = 2;
518 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
519 GEN6_RENDER_SUBTYPE_3D |
520 subop | (cmd_len - 2);
521
522 cmd_batch_reserve(cmd, cmd_len);
523 cmd_batch_write(cmd, dw0);
524 cmd_batch_write(cmd, pos << 2);
525}
526
527static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
528 const struct intel_blend_state *state)
529{
530 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
531 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
532
533 CMD_ASSERT(cmd, 6, 7.5);
534 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
535
536 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
537}
538
539static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
540 const struct intel_ds_state *state)
541{
542 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
543 const uint8_t cmd_len = 3;
544
545 CMD_ASSERT(cmd, 6, 7.5);
546 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
547
548 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
549}
550
551static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
552 uint32_t stencil_ref,
553 const uint32_t blend_color[4])
554{
555 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
556 const uint8_t cmd_len = 6;
557 XGL_UINT pos;
558 uint32_t *dw;
559
560 CMD_ASSERT(cmd, 6, 7.5);
561
562 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
563 dw[0] = stencil_ref;
564 dw[1] = 0;
565 dw[2] = blend_color[0];
566 dw[3] = blend_color[1];
567 dw[4] = blend_color[2];
568 dw[5] = blend_color[3];
569 cmd_state_advance(cmd, cmd_len);
570
571 return pos;
572}
573
Chia-I Wu48c283d2014-08-25 23:13:46 +0800574static void gen6_wa_post_sync_flush(struct intel_cmd *cmd)
575{
576 if (cmd->bind.wa_flags & GEN6_WA_POST_SYNC_FLUSH)
577 return;
578
579 CMD_ASSERT(cmd, 6, 7.5);
580
581 cmd->bind.wa_flags |= GEN6_WA_POST_SYNC_FLUSH;
582
583 /*
584 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
585 *
586 * "Pipe-control with CS-stall bit set must be sent BEFORE the
587 * pipe-control with a post-sync op and no write-cache flushes."
588 *
589 * The workaround below necessitates this workaround.
590 */
591 gen6_PIPE_CONTROL(cmd,
592 GEN6_PIPE_CONTROL_CS_STALL |
593 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
594 NULL, 0);
595
596 /*
597 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
598 *
599 * "Before any depth stall flush (including those produced by
600 * non-pipelined state commands), software needs to first send a
601 * PIPE_CONTROL with no bits set except Post-Sync Operation != 0."
602 *
603 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
604 * PIPE_CONTROL with any non-zero post-sync-op is required."
605 */
606 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, cmd->scratch_bo, 0);
607}
608
609static void gen6_wa_ds_flush(struct intel_cmd *cmd)
610{
611 if (cmd->bind.wa_flags & GEN6_WA_DS_FLUSH)
612 return;
613
614 CMD_ASSERT(cmd, 6, 7.5);
615
616 cmd->bind.wa_flags |= GEN6_WA_DS_FLUSH;
617
618 gen6_wa_post_sync_flush(cmd);
619
620 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
621 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
622 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
623}
624
Chia-I Wu302742d2014-08-22 10:28:29 +0800625static void gen6_cc_states(struct intel_cmd *cmd)
626{
627 const struct intel_blend_state *blend = cmd->bind.state.blend;
628 const struct intel_ds_state *ds = cmd->bind.state.ds;
629 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800630 uint32_t stencil_ref;
631 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800632
633 CMD_ASSERT(cmd, 6, 6);
634
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800635 if (blend) {
636 blend_pos = gen6_BLEND_STATE(cmd, blend);
637 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
638 } else {
639 blend_pos = 0;
640 memset(blend_color, 0, sizeof(blend_color));
641 }
642
643 if (ds) {
644 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
645 stencil_ref = ds->cmd_stencil_ref;
646 } else {
647 ds_pos = 0;
648 stencil_ref = 0;
649 }
650
651 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800652
653 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
654}
655
Chia-I Wu1744cca2014-08-22 11:10:17 +0800656static void gen6_viewport_states(struct intel_cmd *cmd)
657{
658 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
659 XGL_UINT pos;
660
661 if (!viewport)
662 return;
663
664 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
665 viewport->cmd_align);
666
667 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
668 pos + viewport->cmd_clip_offset,
669 pos,
670 pos + viewport->cmd_cc_offset);
671
672 pos = (viewport->scissor_enable) ?
673 pos + viewport->cmd_scissor_rect_offset : 0;
674
675 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
676}
677
Chia-I Wu302742d2014-08-22 10:28:29 +0800678static void gen7_cc_states(struct intel_cmd *cmd)
679{
680 const struct intel_blend_state *blend = cmd->bind.state.blend;
681 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800682 uint32_t stencil_ref;
683 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800684 XGL_UINT pos;
685
686 CMD_ASSERT(cmd, 7, 7.5);
687
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800688 if (!blend && !ds)
689 return;
Chia-I Wu302742d2014-08-22 10:28:29 +0800690
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800691 if (blend) {
692 pos = gen6_BLEND_STATE(cmd, blend);
693 gen7_3dstate_pointer(cmd,
694 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +0800695
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800696 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
697 } else {
698 memset(blend_color, 0, sizeof(blend_color));
699 }
700
701 if (ds) {
702 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
703 gen7_3dstate_pointer(cmd,
704 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
705 } else {
706 stencil_ref = 0;
707 }
708
709 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800710 gen7_3dstate_pointer(cmd,
711 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
712}
713
Chia-I Wu1744cca2014-08-22 11:10:17 +0800714static void gen7_viewport_states(struct intel_cmd *cmd)
715{
716 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
717 XGL_UINT pos;
718
719 if (!viewport)
720 return;
721
722 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
723 viewport->cmd_align);
724
725 gen7_3dstate_pointer(cmd,
726 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
727 gen7_3dstate_pointer(cmd,
728 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
729 pos + viewport->cmd_cc_offset);
730 if (viewport->scissor_enable) {
731 gen7_3dstate_pointer(cmd,
732 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
733 pos + viewport->cmd_scissor_rect_offset);
734 }
735}
736
Chia-I Wu42a56202014-08-23 16:47:48 +0800737static void emit_ps_resources(struct intel_cmd *cmd,
738 const struct intel_rmap *rmap)
739{
740 const XGL_UINT surface_count = rmap->rt_count +
741 rmap->resource_count + rmap->uav_count;
742 uint32_t binding_table[256];
743 XGL_UINT pos, i;
744
745 assert(surface_count <= ARRAY_SIZE(binding_table));
746
747 for (i = 0; i < surface_count; i++) {
748 const struct intel_rmap_slot *slot = &rmap->slots[i];
749 uint32_t *dw;
750
751 switch (slot->path_len) {
752 case 0:
753 pos = 0;
754 break;
755 case INTEL_RMAP_SLOT_RT:
756 {
757 const struct intel_rt_view *view = cmd->bind.att.rt[i];
758
759 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
760 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
761
762 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800763 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu42a56202014-08-23 16:47:48 +0800764 INTEL_DOMAIN_RENDER, INTEL_DOMAIN_RENDER);
765 cmd_state_advance(cmd, view->cmd_len);
766 }
767 break;
768 case INTEL_RMAP_SLOT_DYN:
769 {
770 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800771 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +0800772
773 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
774 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
775
776 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800777 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu42a56202014-08-23 16:47:48 +0800778 INTEL_DOMAIN_RENDER, INTEL_DOMAIN_RENDER);
779 cmd_state_advance(cmd, view->cmd_len);
780 }
781 break;
782 case 1:
783 default:
784 /* TODO */
785 assert(!"no dset support");
786 break;
787 }
788
789 binding_table[i] = pos << 2;
790 }
791
792 pos = cmd_state_copy(cmd, binding_table, surface_count,
793 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
794
795 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
796 gen7_3dstate_pointer(cmd,
797 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
798 } else {
799 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
800 }
801}
802
Chia-I Wu52500102014-08-22 00:46:04 +0800803static void emit_bounded_states(struct intel_cmd *cmd)
804{
805 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
806
807 /* TODO more states */
808
Chia-I Wu1744cca2014-08-22 11:10:17 +0800809 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +0800810 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800811 gen7_viewport_states(cmd);
812 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +0800813 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800814 gen6_viewport_states(cmd);
815 }
Chia-I Wu302742d2014-08-22 10:28:29 +0800816
Chia-I Wu42a56202014-08-23 16:47:48 +0800817 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
818
Chia-I Wu52500102014-08-22 00:46:04 +0800819 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu48c283d2014-08-25 23:13:46 +0800820 gen6_wa_post_sync_flush(cmd);
Chia-I Wu52500102014-08-22 00:46:04 +0800821 cmd_batch_reserve(cmd, msaa->cmd_len);
822 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
823}
824
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800825static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
826 const struct intel_pipeline *pipeline)
827{
828 cmd->bind.pipeline.graphics = pipeline;
829}
830
831static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
832 const struct intel_pipeline *pipeline)
833{
834 cmd->bind.pipeline.compute = pipeline;
835}
836
837static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
838 const struct intel_pipeline_delta *delta)
839{
840 cmd->bind.pipeline.graphics_delta = delta;
841}
842
843static void cmd_bind_compute_delta(struct intel_cmd *cmd,
844 const struct intel_pipeline_delta *delta)
845{
846 cmd->bind.pipeline.compute_delta = delta;
847}
848
849static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
850 const struct intel_dset *dset,
851 XGL_UINT slot_offset)
852{
853 cmd->bind.dset.graphics = dset;
854 cmd->bind.dset.graphics_offset = slot_offset;
855}
856
857static void cmd_bind_compute_dset(struct intel_cmd *cmd,
858 const struct intel_dset *dset,
859 XGL_UINT slot_offset)
860{
861 cmd->bind.dset.compute = dset;
862 cmd->bind.dset.compute_offset = slot_offset;
863}
864
865static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
866 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
867{
868 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
869}
870
871static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
872 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
873{
874 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
875}
876
877static void cmd_bind_index_data(struct intel_cmd *cmd,
878 const struct intel_mem *mem,
879 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
880{
881 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
882 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
883 } else {
884 cmd->bind.index.mem = mem;
885 cmd->bind.index.offset = offset;
886 cmd->bind.index.type = type;
887 }
888}
889
890static void cmd_bind_rt(struct intel_cmd *cmd,
891 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
892 XGL_UINT count)
893{
Chia-I Wud88e02d2014-08-25 10:56:13 +0800894 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800895 XGL_UINT i;
896
897 for (i = 0; i < count; i++) {
898 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
899 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800900 const struct intel_layout *layout = &rt->img->layout;
901
902 if (i == 0) {
903 width = layout->width0;
904 height = layout->height0;
905 } else {
906 if (width > layout->width0)
907 width = layout->width0;
908 if (height > layout->height0)
909 height = layout->height0;
910 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800911
912 cmd->bind.att.rt[i] = rt;
913 }
914
915 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800916
Chia-I Wu48c283d2014-08-25 23:13:46 +0800917 gen6_wa_post_sync_flush(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800918 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800919}
920
921static void cmd_bind_ds(struct intel_cmd *cmd,
922 const XGL_DEPTH_STENCIL_BIND_INFO *info)
923{
924 const struct intel_ds_view *ds;
925
926 if (info) {
927 cmd->bind.att.ds = intel_ds_view(info->view);
928 ds = cmd->bind.att.ds;
929 } else {
930 /* all zeros */
931 static const struct intel_ds_view null_ds;
932 ds = &null_ds;
933 }
934
Chia-I Wu48c283d2014-08-25 23:13:46 +0800935 gen6_wa_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800936 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
937 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
938 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +0800939
940 if (cmd_gen(cmd) >= INTEL_GEN(7))
941 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
942 else
943 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800944}
945
946static void cmd_bind_viewport_state(struct intel_cmd *cmd,
947 const struct intel_viewport_state *state)
948{
949 cmd->bind.state.viewport = state;
950}
951
952static void cmd_bind_raster_state(struct intel_cmd *cmd,
953 const struct intel_raster_state *state)
954{
955 cmd->bind.state.raster = state;
956}
957
958static void cmd_bind_ds_state(struct intel_cmd *cmd,
959 const struct intel_ds_state *state)
960{
961 cmd->bind.state.ds = state;
962}
963
964static void cmd_bind_blend_state(struct intel_cmd *cmd,
965 const struct intel_blend_state *state)
966{
967 cmd->bind.state.blend = state;
968}
969
970static void cmd_bind_msaa_state(struct intel_cmd *cmd,
971 const struct intel_msaa_state *state)
972{
973 cmd->bind.state.msaa = state;
974}
975
976static void cmd_draw(struct intel_cmd *cmd,
977 XGL_UINT vertex_start,
978 XGL_UINT vertex_count,
979 XGL_UINT instance_start,
980 XGL_UINT instance_count,
981 bool indexed,
982 XGL_UINT vertex_base)
983{
984 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
985
986 emit_bounded_states(cmd);
987
988 if (indexed) {
989 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
990 cmd->result = XGL_ERROR_UNKNOWN;
991
992 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
993 gen75_3DSTATE_VF(cmd, p->primitive_restart,
994 p->primitive_restart_index);
995 } else {
996 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
997 cmd->bind.index.offset, cmd->bind.index.type,
998 p->primitive_restart);
999 }
1000 } else {
1001 assert(!vertex_base);
1002 }
1003
1004 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1005 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1006 vertex_start, instance_count, instance_start, vertex_base);
1007 } else {
1008 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1009 vertex_start, instance_count, instance_start, vertex_base);
1010 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001011
1012 /* need to re-emit all workarounds */
1013 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001014}
1015
Chia-I Wub2755562014-08-20 13:38:52 +08001016XGL_VOID XGLAPI intelCmdBindPipeline(
1017 XGL_CMD_BUFFER cmdBuffer,
1018 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1019 XGL_PIPELINE pipeline)
1020{
1021 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1022
1023 switch (pipelineBindPoint) {
1024 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001025 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001026 break;
1027 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001028 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001029 break;
1030 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001031 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001032 break;
1033 }
1034}
1035
1036XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1037 XGL_CMD_BUFFER cmdBuffer,
1038 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1039 XGL_PIPELINE_DELTA delta)
1040{
1041 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1042
1043 switch (pipelineBindPoint) {
1044 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001045 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001046 break;
1047 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001048 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001049 break;
1050 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001051 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001052 break;
1053 }
1054}
1055
1056XGL_VOID XGLAPI intelCmdBindStateObject(
1057 XGL_CMD_BUFFER cmdBuffer,
1058 XGL_STATE_BIND_POINT stateBindPoint,
1059 XGL_STATE_OBJECT state)
1060{
1061 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1062
1063 switch (stateBindPoint) {
1064 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001065 cmd_bind_viewport_state(cmd,
1066 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001067 break;
1068 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001069 cmd_bind_raster_state(cmd,
1070 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001071 break;
1072 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001073 cmd_bind_ds_state(cmd,
1074 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001075 break;
1076 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001077 cmd_bind_blend_state(cmd,
1078 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001079 break;
1080 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001081 cmd_bind_msaa_state(cmd,
1082 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001083 break;
1084 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001085 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001086 break;
1087 }
1088}
1089
1090XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1091 XGL_CMD_BUFFER cmdBuffer,
1092 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1093 XGL_UINT index,
1094 XGL_DESCRIPTOR_SET descriptorSet,
1095 XGL_UINT slotOffset)
1096{
1097 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1098 struct intel_dset *dset = intel_dset(descriptorSet);
1099
1100 assert(!index);
1101
1102 switch (pipelineBindPoint) {
1103 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001104 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001105 break;
1106 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001107 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001108 break;
1109 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001110 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001111 break;
1112 }
1113}
1114
1115XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1116 XGL_CMD_BUFFER cmdBuffer,
1117 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1118 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1119{
1120 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1121
1122 switch (pipelineBindPoint) {
1123 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001124 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001125 break;
1126 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001127 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001128 break;
1129 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001130 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001131 break;
1132 }
1133}
1134
1135XGL_VOID XGLAPI intelCmdBindIndexData(
1136 XGL_CMD_BUFFER cmdBuffer,
1137 XGL_GPU_MEMORY mem_,
1138 XGL_GPU_SIZE offset,
1139 XGL_INDEX_TYPE indexType)
1140{
1141 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1142 struct intel_mem *mem = intel_mem(mem_);
1143
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001144 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001145}
1146
1147XGL_VOID XGLAPI intelCmdBindAttachments(
1148 XGL_CMD_BUFFER cmdBuffer,
1149 XGL_UINT colorAttachmentCount,
1150 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1151 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1152{
1153 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001154
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001155 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1156 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001157}
1158
1159XGL_VOID XGLAPI intelCmdDraw(
1160 XGL_CMD_BUFFER cmdBuffer,
1161 XGL_UINT firstVertex,
1162 XGL_UINT vertexCount,
1163 XGL_UINT firstInstance,
1164 XGL_UINT instanceCount)
1165{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001166 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001167
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001168 cmd_draw(cmd, firstVertex, vertexCount,
1169 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08001170}
1171
1172XGL_VOID XGLAPI intelCmdDrawIndexed(
1173 XGL_CMD_BUFFER cmdBuffer,
1174 XGL_UINT firstIndex,
1175 XGL_UINT indexCount,
1176 XGL_INT vertexOffset,
1177 XGL_UINT firstInstance,
1178 XGL_UINT instanceCount)
1179{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001180 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001181
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001182 cmd_draw(cmd, firstIndex, indexCount,
1183 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001184}
1185
1186XGL_VOID XGLAPI intelCmdDrawIndirect(
1187 XGL_CMD_BUFFER cmdBuffer,
1188 XGL_GPU_MEMORY mem,
1189 XGL_GPU_SIZE offset,
1190 XGL_UINT32 count,
1191 XGL_UINT32 stride)
1192{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001193 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1194
1195 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001196}
1197
1198XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
1199 XGL_CMD_BUFFER cmdBuffer,
1200 XGL_GPU_MEMORY mem,
1201 XGL_GPU_SIZE offset,
1202 XGL_UINT32 count,
1203 XGL_UINT32 stride)
1204{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001205 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1206
1207 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001208}
1209
1210XGL_VOID XGLAPI intelCmdDispatch(
1211 XGL_CMD_BUFFER cmdBuffer,
1212 XGL_UINT x,
1213 XGL_UINT y,
1214 XGL_UINT z)
1215{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001216 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1217
1218 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001219}
1220
1221XGL_VOID XGLAPI intelCmdDispatchIndirect(
1222 XGL_CMD_BUFFER cmdBuffer,
1223 XGL_GPU_MEMORY mem,
1224 XGL_GPU_SIZE offset)
1225{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001226 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1227
1228 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001229}