blob: e7a32607564ccf59f277152e3070712c504b148c [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 Wub0b9f692014-08-21 11:33:29 +080047 dw0 = GEN_RENDER_CMD(3D, GEN6, 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 Wub0b9f692014-08-21 11:33:29 +080076 dw0 = GEN_RENDER_CMD(3D, GEN6, 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;
96 const uint32_t dw0 = GEN_RENDER_CMD(3D, GEN6, PIPE_CONTROL) |
97 (cmd_len - 2);
98 const uint32_t read_domains = INTEL_DOMAIN_INSTRUCTION;
99 const uint32_t write_domain = INTEL_DOMAIN_INSTRUCTION;
100
101 CMD_ASSERT(cmd, 6, 7.5);
102
103 assert(bo_offset % 8 == 0);
104
105 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
106 /*
107 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
108 *
109 * "1 of the following must also be set (when CS stall is set):
110 *
111 * * Depth Cache Flush Enable ([0] of DW1)
112 * * Stall at Pixel Scoreboard ([1] of DW1)
113 * * Depth Stall ([13] of DW1)
114 * * Post-Sync Operation ([13] of DW1)
115 * * Render Target Cache Flush Enable ([12] of DW1)
116 * * Notify Enable ([8] of DW1)"
117 *
118 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
119 *
120 * "One of the following must also be set (when CS stall is set):
121 *
122 * * Render Target Cache Flush Enable ([12] of DW1)
123 * * Depth Cache Flush Enable ([0] of DW1)
124 * * Stall at Pixel Scoreboard ([1] of DW1)
125 * * Depth Stall ([13] of DW1)
126 * * Post-Sync Operation ([13] of DW1)"
127 */
128 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
129 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
130 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
131 GEN6_PIPE_CONTROL_DEPTH_STALL;
132
133 /* post-sync op */
134 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
135 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
136 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
137
138 if (cmd_gen(cmd) == INTEL_GEN(6))
139 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
140
141 assert(dw1 & bit_test);
142 }
143
144 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
145 /*
146 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
147 *
148 * "Following bits must be clear (when Depth Stall is set):
149 *
150 * * Render Target Cache Flush Enable ([12] of DW1)
151 * * Depth Cache Flush Enable ([0] of DW1)"
152 */
153 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
154 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
155 }
156
157 /*
158 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
159 *
160 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
161 * and PIPE_CONTROL are not supported."
162 *
163 * The kernel will add the mapping automatically (when write domain is
164 * INTEL_DOMAIN_INSTRUCTION).
165 */
166 if (cmd_gen(cmd) == INTEL_GEN(6) && bo)
167 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
168
169 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) bo);
170 cmd_batch_write(cmd, dw0);
171 cmd_batch_write(cmd, dw1);
172 if (bo)
173 cmd_batch_reloc(cmd, bo_offset, bo, read_domains, write_domain);
174 else
175 cmd_batch_write(cmd, 0);
176 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 Wub0b9f692014-08-21 11:33:29 +0800236 dw0 = GEN_RENDER_CMD(3D, GEN6, 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 Wu9ee38722014-08-25 12:11:36 +0800273 cmd_batch_reloc(cmd, offset, mem->bo, INTEL_DOMAIN_VERTEX, 0);
274 cmd_batch_reloc(cmd, end_offset, mem->bo, INTEL_DOMAIN_VERTEX, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800275}
276
Chia-I Wu254db422014-08-21 11:54:29 +0800277static inline void
278gen75_3DSTATE_VF(struct intel_cmd *cmd,
279 bool enable_cut_index,
280 uint32_t cut_index)
281{
282 const uint8_t cmd_len = 2;
283 uint32_t dw0;
284
285 CMD_ASSERT(cmd, 7.5, 7.5);
286
287 dw0 = GEN_RENDER_CMD(3D, GEN75, 3DSTATE_VF) | (cmd_len - 2);
288 if (enable_cut_index)
289 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
290
Chia-I Wue24c3292014-08-21 14:05:23 +0800291 cmd_batch_reserve(cmd, cmd_len);
292 cmd_batch_write(cmd, dw0);
293 cmd_batch_write(cmd, cut_index);
Chia-I Wu254db422014-08-21 11:54:29 +0800294}
295
Chia-I Wud88e02d2014-08-25 10:56:13 +0800296static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
297 XGL_UINT width, XGL_UINT height)
298{
299 const uint8_t cmd_len = 4;
300 const uint32_t dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_DRAWING_RECTANGLE) |
301 (cmd_len - 2);
302
303 CMD_ASSERT(cmd, 6, 7.5);
304
305 cmd_batch_reserve(cmd, cmd_len);
306 cmd_batch_write(cmd, dw0);
307 if (width && height) {
308 cmd_batch_write(cmd, 0);
309 cmd_batch_write(cmd, (height - 1) << 16 |
310 (width - 1));
311 } else {
312 cmd_batch_write(cmd, 1);
313 cmd_batch_write(cmd, 0);
314 }
315 cmd_batch_write(cmd, 0);
316}
317
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800318static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
319 const struct intel_ds_view *view)
320{
321 const uint8_t cmd_len = 7;
322 uint32_t dw0;
323
324 CMD_ASSERT(cmd, 6, 7.5);
325
326 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
327 GEN_RENDER_CMD(3D, GEN7, 3DSTATE_DEPTH_BUFFER) :
328 GEN_RENDER_CMD(3D, GEN6, 3DSTATE_DEPTH_BUFFER);
329 dw0 |= (cmd_len - 2);
330
Chia-I Wu2de65d02014-08-25 10:02:53 +0800331 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800332 cmd_batch_write(cmd, dw0);
333 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600334 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800335 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600336 INTEL_DOMAIN_RENDER,
337 INTEL_DOMAIN_RENDER);
338 } else {
339 cmd_batch_write(cmd, 0);
340 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800341 cmd_batch_write(cmd, view->cmd[2]);
342 cmd_batch_write(cmd, view->cmd[3]);
343 cmd_batch_write(cmd, view->cmd[4]);
344 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800345}
346
347static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
348 const struct intel_ds_view *view)
349{
350 const uint8_t cmd_len = 3;
351 uint32_t dw0;
352
353 CMD_ASSERT(cmd, 6, 7.5);
354
355 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
356 GEN_RENDER_CMD(3D, GEN7, 3DSTATE_STENCIL_BUFFER) :
357 GEN_RENDER_CMD(3D, GEN6, 3DSTATE_STENCIL_BUFFER);
358 dw0 |= (cmd_len - 2);
359
Chia-I Wu2de65d02014-08-25 10:02:53 +0800360 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800361 cmd_batch_write(cmd, dw0);
362 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600363 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800364 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600365 INTEL_DOMAIN_RENDER,
366 INTEL_DOMAIN_RENDER);
367 } else {
368 cmd_batch_write(cmd, 0);
369 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800370}
371
372static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
373 const struct intel_ds_view *view)
374{
375 const uint8_t cmd_len = 3;
376 uint32_t dw0;
377
378 CMD_ASSERT(cmd, 6, 7.5);
379
380 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
381 GEN_RENDER_CMD(3D, GEN7, 3DSTATE_HIER_DEPTH_BUFFER) :
382 GEN_RENDER_CMD(3D, GEN6, 3DSTATE_HIER_DEPTH_BUFFER);
383 dw0 |= (cmd_len - 2);
384
Chia-I Wu2de65d02014-08-25 10:02:53 +0800385 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800386 cmd_batch_write(cmd, dw0);
387 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600388 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800389 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600390 INTEL_DOMAIN_RENDER,
391 INTEL_DOMAIN_RENDER);
392 } else {
393 cmd_batch_write(cmd, 0);
394 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800395}
396
Chia-I Wuf8231032014-08-25 10:44:45 +0800397static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
398 uint32_t clear_val)
399{
400 const uint8_t cmd_len = 2;
401 const uint32_t dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_CLEAR_PARAMS) |
402 GEN6_CLEAR_PARAMS_DW0_VALID |
403 (cmd_len - 2);
404
405 CMD_ASSERT(cmd, 6, 6);
406
407 cmd_batch_reserve(cmd, cmd_len);
408 cmd_batch_write(cmd, dw0);
409 cmd_batch_write(cmd, clear_val);
410}
411
412static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
413 uint32_t clear_val)
414{
415 const uint8_t cmd_len = 3;
416 const uint32_t dw0 = GEN_RENDER_CMD(3D, GEN7, 3DSTATE_CLEAR_PARAMS) |
417 (cmd_len - 2);
418
419 CMD_ASSERT(cmd, 7, 7.5);
420
421 cmd_batch_reserve(cmd, cmd_len);
422 cmd_batch_write(cmd, dw0);
423 cmd_batch_write(cmd, clear_val);
424 cmd_batch_write(cmd, 1);
425}
426
Chia-I Wu302742d2014-08-22 10:28:29 +0800427static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
428 XGL_UINT blend_pos,
429 XGL_UINT ds_pos,
430 XGL_UINT cc_pos)
431{
432 const uint8_t cmd_len = 4;
433 uint32_t dw0;
434
435 CMD_ASSERT(cmd, 6, 6);
436
437 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_CC_STATE_POINTERS) |
438 (cmd_len - 2);
439
440 cmd_batch_reserve(cmd, cmd_len);
441 cmd_batch_write(cmd, dw0);
442 cmd_batch_write(cmd, (blend_pos << 2) | 1);
443 cmd_batch_write(cmd, (ds_pos << 2) | 1);
444 cmd_batch_write(cmd, (cc_pos << 2) | 1);
445}
446
Chia-I Wu1744cca2014-08-22 11:10:17 +0800447static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
448 XGL_UINT clip_pos,
449 XGL_UINT sf_pos,
450 XGL_UINT cc_pos)
451{
452 const uint8_t cmd_len = 4;
453 uint32_t dw0;
454
455 CMD_ASSERT(cmd, 6, 6);
456
457 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_VIEWPORT_STATE_POINTERS) |
458 GEN6_PTR_VP_DW0_CLIP_CHANGED |
459 GEN6_PTR_VP_DW0_SF_CHANGED |
460 GEN6_PTR_VP_DW0_CC_CHANGED |
461 (cmd_len - 2);
462
463 cmd_batch_reserve(cmd, cmd_len);
464 cmd_batch_write(cmd, dw0);
465 cmd_batch_write(cmd, clip_pos << 2);
466 cmd_batch_write(cmd, sf_pos << 2);
467 cmd_batch_write(cmd, cc_pos << 2);
468}
469
470static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
471 XGL_UINT scissor_pos)
472{
473 const uint8_t cmd_len = 2;
474 uint32_t dw0;
475
476 CMD_ASSERT(cmd, 6, 6);
477
478 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_SCISSOR_STATE_POINTERS) |
479 (cmd_len - 2);
480
481 cmd_batch_reserve(cmd, cmd_len);
482 cmd_batch_write(cmd, dw0);
483 cmd_batch_write(cmd, scissor_pos << 2);
484}
485
Chia-I Wu42a56202014-08-23 16:47:48 +0800486static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
487 XGL_UINT vs_pos,
488 XGL_UINT gs_pos,
489 XGL_UINT ps_pos)
490{
491 const uint8_t cmd_len = 4;
492 uint32_t dw0;
493
494 CMD_ASSERT(cmd, 6, 6);
495
496 dw0 = GEN_RENDER_CMD(3D, GEN6, 3DSTATE_BINDING_TABLE_POINTERS) |
497 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
498 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
499 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
500 (cmd_len - 2);
501
502 cmd_batch_reserve(cmd, cmd_len);
503 cmd_batch_write(cmd, dw0);
504 cmd_batch_write(cmd, vs_pos << 2);
505 cmd_batch_write(cmd, gs_pos << 2);
506 cmd_batch_write(cmd, ps_pos << 2);
507}
508
Chia-I Wu302742d2014-08-22 10:28:29 +0800509static void gen7_3dstate_pointer(struct intel_cmd *cmd,
510 int subop, XGL_UINT pos)
511{
512 const uint8_t cmd_len = 2;
513 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
514 GEN6_RENDER_SUBTYPE_3D |
515 subop | (cmd_len - 2);
516
517 cmd_batch_reserve(cmd, cmd_len);
518 cmd_batch_write(cmd, dw0);
519 cmd_batch_write(cmd, pos << 2);
520}
521
522static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
523 const struct intel_blend_state *state)
524{
525 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
526 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
527
528 CMD_ASSERT(cmd, 6, 7.5);
529 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
530
531 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
532}
533
534static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
535 const struct intel_ds_state *state)
536{
537 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
538 const uint8_t cmd_len = 3;
539
540 CMD_ASSERT(cmd, 6, 7.5);
541 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
542
543 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
544}
545
546static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
547 uint32_t stencil_ref,
548 const uint32_t blend_color[4])
549{
550 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
551 const uint8_t cmd_len = 6;
552 XGL_UINT pos;
553 uint32_t *dw;
554
555 CMD_ASSERT(cmd, 6, 7.5);
556
557 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
558 dw[0] = stencil_ref;
559 dw[1] = 0;
560 dw[2] = blend_color[0];
561 dw[3] = blend_color[1];
562 dw[4] = blend_color[2];
563 dw[5] = blend_color[3];
564 cmd_state_advance(cmd, cmd_len);
565
566 return pos;
567}
568
569static void gen6_cc_states(struct intel_cmd *cmd)
570{
571 const struct intel_blend_state *blend = cmd->bind.state.blend;
572 const struct intel_ds_state *ds = cmd->bind.state.ds;
573 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800574 uint32_t stencil_ref;
575 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800576
577 CMD_ASSERT(cmd, 6, 6);
578
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800579 if (blend) {
580 blend_pos = gen6_BLEND_STATE(cmd, blend);
581 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
582 } else {
583 blend_pos = 0;
584 memset(blend_color, 0, sizeof(blend_color));
585 }
586
587 if (ds) {
588 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
589 stencil_ref = ds->cmd_stencil_ref;
590 } else {
591 ds_pos = 0;
592 stencil_ref = 0;
593 }
594
595 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800596
597 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
598}
599
Chia-I Wu1744cca2014-08-22 11:10:17 +0800600static void gen6_viewport_states(struct intel_cmd *cmd)
601{
602 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
603 XGL_UINT pos;
604
605 if (!viewport)
606 return;
607
608 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
609 viewport->cmd_align);
610
611 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
612 pos + viewport->cmd_clip_offset,
613 pos,
614 pos + viewport->cmd_cc_offset);
615
616 pos = (viewport->scissor_enable) ?
617 pos + viewport->cmd_scissor_rect_offset : 0;
618
619 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
620}
621
Chia-I Wu302742d2014-08-22 10:28:29 +0800622static void gen7_cc_states(struct intel_cmd *cmd)
623{
624 const struct intel_blend_state *blend = cmd->bind.state.blend;
625 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800626 uint32_t stencil_ref;
627 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800628 XGL_UINT pos;
629
630 CMD_ASSERT(cmd, 7, 7.5);
631
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800632 if (!blend && !ds)
633 return;
Chia-I Wu302742d2014-08-22 10:28:29 +0800634
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800635 if (blend) {
636 pos = gen6_BLEND_STATE(cmd, blend);
637 gen7_3dstate_pointer(cmd,
638 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +0800639
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800640 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
641 } else {
642 memset(blend_color, 0, sizeof(blend_color));
643 }
644
645 if (ds) {
646 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
647 gen7_3dstate_pointer(cmd,
648 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
649 } else {
650 stencil_ref = 0;
651 }
652
653 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800654 gen7_3dstate_pointer(cmd,
655 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
656}
657
Chia-I Wu1744cca2014-08-22 11:10:17 +0800658static void gen7_viewport_states(struct intel_cmd *cmd)
659{
660 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
661 XGL_UINT pos;
662
663 if (!viewport)
664 return;
665
666 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
667 viewport->cmd_align);
668
669 gen7_3dstate_pointer(cmd,
670 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
671 gen7_3dstate_pointer(cmd,
672 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
673 pos + viewport->cmd_cc_offset);
674 if (viewport->scissor_enable) {
675 gen7_3dstate_pointer(cmd,
676 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
677 pos + viewport->cmd_scissor_rect_offset);
678 }
679}
680
Chia-I Wu42a56202014-08-23 16:47:48 +0800681static void emit_ps_resources(struct intel_cmd *cmd,
682 const struct intel_rmap *rmap)
683{
684 const XGL_UINT surface_count = rmap->rt_count +
685 rmap->resource_count + rmap->uav_count;
686 uint32_t binding_table[256];
687 XGL_UINT pos, i;
688
689 assert(surface_count <= ARRAY_SIZE(binding_table));
690
691 for (i = 0; i < surface_count; i++) {
692 const struct intel_rmap_slot *slot = &rmap->slots[i];
693 uint32_t *dw;
694
695 switch (slot->path_len) {
696 case 0:
697 pos = 0;
698 break;
699 case INTEL_RMAP_SLOT_RT:
700 {
701 const struct intel_rt_view *view = cmd->bind.att.rt[i];
702
703 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
704 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
705
706 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800707 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu42a56202014-08-23 16:47:48 +0800708 INTEL_DOMAIN_RENDER, INTEL_DOMAIN_RENDER);
709 cmd_state_advance(cmd, view->cmd_len);
710 }
711 break;
712 case INTEL_RMAP_SLOT_DYN:
713 {
714 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800715 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +0800716
717 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
718 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
719
720 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800721 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu42a56202014-08-23 16:47:48 +0800722 INTEL_DOMAIN_RENDER, INTEL_DOMAIN_RENDER);
723 cmd_state_advance(cmd, view->cmd_len);
724 }
725 break;
726 case 1:
727 default:
728 /* TODO */
729 assert(!"no dset support");
730 break;
731 }
732
733 binding_table[i] = pos << 2;
734 }
735
736 pos = cmd_state_copy(cmd, binding_table, surface_count,
737 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
738
739 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
740 gen7_3dstate_pointer(cmd,
741 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
742 } else {
743 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
744 }
745}
746
Chia-I Wu52500102014-08-22 00:46:04 +0800747static void emit_bounded_states(struct intel_cmd *cmd)
748{
749 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
750
751 /* TODO more states */
752
Chia-I Wu1744cca2014-08-22 11:10:17 +0800753 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +0800754 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800755 gen7_viewport_states(cmd);
756 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +0800757 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800758 gen6_viewport_states(cmd);
759 }
Chia-I Wu302742d2014-08-22 10:28:29 +0800760
Chia-I Wu42a56202014-08-23 16:47:48 +0800761 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
762
Chia-I Wu52500102014-08-22 00:46:04 +0800763 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
764 cmd_batch_reserve(cmd, msaa->cmd_len);
765 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
766}
767
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800768static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
769 const struct intel_pipeline *pipeline)
770{
771 cmd->bind.pipeline.graphics = pipeline;
772}
773
774static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
775 const struct intel_pipeline *pipeline)
776{
777 cmd->bind.pipeline.compute = pipeline;
778}
779
780static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
781 const struct intel_pipeline_delta *delta)
782{
783 cmd->bind.pipeline.graphics_delta = delta;
784}
785
786static void cmd_bind_compute_delta(struct intel_cmd *cmd,
787 const struct intel_pipeline_delta *delta)
788{
789 cmd->bind.pipeline.compute_delta = delta;
790}
791
792static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
793 const struct intel_dset *dset,
794 XGL_UINT slot_offset)
795{
796 cmd->bind.dset.graphics = dset;
797 cmd->bind.dset.graphics_offset = slot_offset;
798}
799
800static void cmd_bind_compute_dset(struct intel_cmd *cmd,
801 const struct intel_dset *dset,
802 XGL_UINT slot_offset)
803{
804 cmd->bind.dset.compute = dset;
805 cmd->bind.dset.compute_offset = slot_offset;
806}
807
808static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
809 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
810{
811 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
812}
813
814static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
815 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
816{
817 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
818}
819
820static void cmd_bind_index_data(struct intel_cmd *cmd,
821 const struct intel_mem *mem,
822 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
823{
824 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
825 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
826 } else {
827 cmd->bind.index.mem = mem;
828 cmd->bind.index.offset = offset;
829 cmd->bind.index.type = type;
830 }
831}
832
833static void cmd_bind_rt(struct intel_cmd *cmd,
834 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
835 XGL_UINT count)
836{
Chia-I Wud88e02d2014-08-25 10:56:13 +0800837 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800838 XGL_UINT i;
839
840 for (i = 0; i < count; i++) {
841 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
842 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800843 const struct intel_layout *layout = &rt->img->layout;
844
845 if (i == 0) {
846 width = layout->width0;
847 height = layout->height0;
848 } else {
849 if (width > layout->width0)
850 width = layout->width0;
851 if (height > layout->height0)
852 height = layout->height0;
853 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800854
855 cmd->bind.att.rt[i] = rt;
856 }
857
858 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800859
860 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800861}
862
863static void cmd_bind_ds(struct intel_cmd *cmd,
864 const XGL_DEPTH_STENCIL_BIND_INFO *info)
865{
866 const struct intel_ds_view *ds;
867
868 if (info) {
869 cmd->bind.att.ds = intel_ds_view(info->view);
870 ds = cmd->bind.att.ds;
871 } else {
872 /* all zeros */
873 static const struct intel_ds_view null_ds;
874 ds = &null_ds;
875 }
876
Chia-I Wu270b1e82014-08-25 15:53:39 +0800877 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
878 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
879 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
880
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800881 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
882 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
883 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +0800884
885 if (cmd_gen(cmd) >= INTEL_GEN(7))
886 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
887 else
888 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800889}
890
891static void cmd_bind_viewport_state(struct intel_cmd *cmd,
892 const struct intel_viewport_state *state)
893{
894 cmd->bind.state.viewport = state;
895}
896
897static void cmd_bind_raster_state(struct intel_cmd *cmd,
898 const struct intel_raster_state *state)
899{
900 cmd->bind.state.raster = state;
901}
902
903static void cmd_bind_ds_state(struct intel_cmd *cmd,
904 const struct intel_ds_state *state)
905{
906 cmd->bind.state.ds = state;
907}
908
909static void cmd_bind_blend_state(struct intel_cmd *cmd,
910 const struct intel_blend_state *state)
911{
912 cmd->bind.state.blend = state;
913}
914
915static void cmd_bind_msaa_state(struct intel_cmd *cmd,
916 const struct intel_msaa_state *state)
917{
918 cmd->bind.state.msaa = state;
919}
920
921static void cmd_draw(struct intel_cmd *cmd,
922 XGL_UINT vertex_start,
923 XGL_UINT vertex_count,
924 XGL_UINT instance_start,
925 XGL_UINT instance_count,
926 bool indexed,
927 XGL_UINT vertex_base)
928{
929 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
930
931 emit_bounded_states(cmd);
932
933 if (indexed) {
934 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
935 cmd->result = XGL_ERROR_UNKNOWN;
936
937 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
938 gen75_3DSTATE_VF(cmd, p->primitive_restart,
939 p->primitive_restart_index);
940 } else {
941 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
942 cmd->bind.index.offset, cmd->bind.index.type,
943 p->primitive_restart);
944 }
945 } else {
946 assert(!vertex_base);
947 }
948
949 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
950 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
951 vertex_start, instance_count, instance_start, vertex_base);
952 } else {
953 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
954 vertex_start, instance_count, instance_start, vertex_base);
955 }
956}
957
Chia-I Wub2755562014-08-20 13:38:52 +0800958XGL_VOID XGLAPI intelCmdBindPipeline(
959 XGL_CMD_BUFFER cmdBuffer,
960 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
961 XGL_PIPELINE pipeline)
962{
963 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
964
965 switch (pipelineBindPoint) {
966 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800967 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +0800968 break;
969 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800970 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +0800971 break;
972 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800973 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +0800974 break;
975 }
976}
977
978XGL_VOID XGLAPI intelCmdBindPipelineDelta(
979 XGL_CMD_BUFFER cmdBuffer,
980 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
981 XGL_PIPELINE_DELTA delta)
982{
983 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
984
985 switch (pipelineBindPoint) {
986 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800987 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +0800988 break;
989 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800990 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +0800991 break;
992 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800993 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +0800994 break;
995 }
996}
997
998XGL_VOID XGLAPI intelCmdBindStateObject(
999 XGL_CMD_BUFFER cmdBuffer,
1000 XGL_STATE_BIND_POINT stateBindPoint,
1001 XGL_STATE_OBJECT state)
1002{
1003 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1004
1005 switch (stateBindPoint) {
1006 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001007 cmd_bind_viewport_state(cmd,
1008 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001009 break;
1010 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001011 cmd_bind_raster_state(cmd,
1012 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001013 break;
1014 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001015 cmd_bind_ds_state(cmd,
1016 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001017 break;
1018 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001019 cmd_bind_blend_state(cmd,
1020 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001021 break;
1022 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001023 cmd_bind_msaa_state(cmd,
1024 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001025 break;
1026 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001027 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001028 break;
1029 }
1030}
1031
1032XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1033 XGL_CMD_BUFFER cmdBuffer,
1034 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1035 XGL_UINT index,
1036 XGL_DESCRIPTOR_SET descriptorSet,
1037 XGL_UINT slotOffset)
1038{
1039 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1040 struct intel_dset *dset = intel_dset(descriptorSet);
1041
1042 assert(!index);
1043
1044 switch (pipelineBindPoint) {
1045 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001046 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001047 break;
1048 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001049 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001050 break;
1051 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001052 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001053 break;
1054 }
1055}
1056
1057XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1058 XGL_CMD_BUFFER cmdBuffer,
1059 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1060 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1061{
1062 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1063
1064 switch (pipelineBindPoint) {
1065 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001066 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001067 break;
1068 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001069 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001070 break;
1071 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001072 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001073 break;
1074 }
1075}
1076
1077XGL_VOID XGLAPI intelCmdBindIndexData(
1078 XGL_CMD_BUFFER cmdBuffer,
1079 XGL_GPU_MEMORY mem_,
1080 XGL_GPU_SIZE offset,
1081 XGL_INDEX_TYPE indexType)
1082{
1083 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1084 struct intel_mem *mem = intel_mem(mem_);
1085
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001086 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001087}
1088
1089XGL_VOID XGLAPI intelCmdBindAttachments(
1090 XGL_CMD_BUFFER cmdBuffer,
1091 XGL_UINT colorAttachmentCount,
1092 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1093 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1094{
1095 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001096
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001097 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1098 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001099}
1100
1101XGL_VOID XGLAPI intelCmdDraw(
1102 XGL_CMD_BUFFER cmdBuffer,
1103 XGL_UINT firstVertex,
1104 XGL_UINT vertexCount,
1105 XGL_UINT firstInstance,
1106 XGL_UINT instanceCount)
1107{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001108 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001109
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001110 cmd_draw(cmd, firstVertex, vertexCount,
1111 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08001112}
1113
1114XGL_VOID XGLAPI intelCmdDrawIndexed(
1115 XGL_CMD_BUFFER cmdBuffer,
1116 XGL_UINT firstIndex,
1117 XGL_UINT indexCount,
1118 XGL_INT vertexOffset,
1119 XGL_UINT firstInstance,
1120 XGL_UINT instanceCount)
1121{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001122 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001123
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001124 cmd_draw(cmd, firstIndex, indexCount,
1125 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001126}
1127
1128XGL_VOID XGLAPI intelCmdDrawIndirect(
1129 XGL_CMD_BUFFER cmdBuffer,
1130 XGL_GPU_MEMORY mem,
1131 XGL_GPU_SIZE offset,
1132 XGL_UINT32 count,
1133 XGL_UINT32 stride)
1134{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001135 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1136
1137 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001138}
1139
1140XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
1141 XGL_CMD_BUFFER cmdBuffer,
1142 XGL_GPU_MEMORY mem,
1143 XGL_GPU_SIZE offset,
1144 XGL_UINT32 count,
1145 XGL_UINT32 stride)
1146{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001147 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1148
1149 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001150}
1151
1152XGL_VOID XGLAPI intelCmdDispatch(
1153 XGL_CMD_BUFFER cmdBuffer,
1154 XGL_UINT x,
1155 XGL_UINT y,
1156 XGL_UINT z)
1157{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001158 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1159
1160 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001161}
1162
1163XGL_VOID XGLAPI intelCmdDispatchIndirect(
1164 XGL_CMD_BUFFER cmdBuffer,
1165 XGL_GPU_MEMORY mem,
1166 XGL_GPU_SIZE offset)
1167{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001168 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1169
1170 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001171}