blob: e5441904a520aa47c2174d245531687c975b35fd [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 +080034
Chia-I Wu59c097e2014-08-21 10:51:07 +080035static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080036 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080037 uint32_t vertex_count,
38 uint32_t vertex_start,
39 uint32_t instance_count,
40 uint32_t instance_start,
41 uint32_t vertex_base)
42{
43 const uint8_t cmd_len = 6;
44 uint32_t dw0;
45
46 CMD_ASSERT(cmd, 6, 6);
47
Chia-I Wu426072d2014-08-26 14:31:55 +080048 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080049 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080050 (cmd_len - 2);
51
52 if (indexed)
53 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
54
Chia-I Wue24c3292014-08-21 14:05:23 +080055 cmd_batch_reserve(cmd, cmd_len);
56 cmd_batch_write(cmd, dw0);
57 cmd_batch_write(cmd, vertex_count);
58 cmd_batch_write(cmd, vertex_start);
59 cmd_batch_write(cmd, instance_count);
60 cmd_batch_write(cmd, instance_start);
61 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080062}
63
64static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080065 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080066 uint32_t vertex_count,
67 uint32_t vertex_start,
68 uint32_t instance_count,
69 uint32_t instance_start,
70 uint32_t vertex_base)
71{
72 const uint8_t cmd_len = 7;
73 uint32_t dw0, dw1;
74
75 CMD_ASSERT(cmd, 7, 7.5);
76
Chia-I Wu426072d2014-08-26 14:31:55 +080077 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080078 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080079
80 if (indexed)
81 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
82
Chia-I Wue24c3292014-08-21 14:05:23 +080083 cmd_batch_reserve(cmd, cmd_len);
84 cmd_batch_write(cmd, dw0);
85 cmd_batch_write(cmd, dw1);
86 cmd_batch_write(cmd, vertex_count);
87 cmd_batch_write(cmd, vertex_start);
88 cmd_batch_write(cmd, instance_count);
89 cmd_batch_write(cmd, instance_start);
90 cmd_batch_write(cmd, vertex_base);
Chia-I Wu59c097e2014-08-21 10:51:07 +080091}
92
Chia-I Wu270b1e82014-08-25 15:53:39 +080093static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
94 struct intel_bo *bo, uint32_t bo_offset)
95{
96 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +080097 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +080098 (cmd_len - 2);
Chia-I Wu270b1e82014-08-25 15:53:39 +080099
100 CMD_ASSERT(cmd, 6, 7.5);
101
102 assert(bo_offset % 8 == 0);
103
104 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
105 /*
106 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
107 *
108 * "1 of the following must also be set (when CS stall is set):
109 *
110 * * Depth Cache Flush Enable ([0] of DW1)
111 * * Stall at Pixel Scoreboard ([1] of DW1)
112 * * Depth Stall ([13] of DW1)
113 * * Post-Sync Operation ([13] of DW1)
114 * * Render Target Cache Flush Enable ([12] of DW1)
115 * * Notify Enable ([8] of DW1)"
116 *
117 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
118 *
119 * "One of the following must also be set (when CS stall is set):
120 *
121 * * Render Target Cache Flush Enable ([12] of DW1)
122 * * Depth Cache Flush Enable ([0] of DW1)
123 * * Stall at Pixel Scoreboard ([1] of DW1)
124 * * Depth Stall ([13] of DW1)
125 * * Post-Sync Operation ([13] of DW1)"
126 */
127 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
128 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
129 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
130 GEN6_PIPE_CONTROL_DEPTH_STALL;
131
132 /* post-sync op */
133 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
134 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
135 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
136
137 if (cmd_gen(cmd) == INTEL_GEN(6))
138 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
139
140 assert(dw1 & bit_test);
141 }
142
143 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
144 /*
145 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
146 *
147 * "Following bits must be clear (when Depth Stall is set):
148 *
149 * * Render Target Cache Flush Enable ([12] of DW1)
150 * * Depth Cache Flush Enable ([0] of DW1)"
151 */
152 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
153 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
154 }
155
156 /*
157 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
158 *
159 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
160 * and PIPE_CONTROL are not supported."
161 *
162 * The kernel will add the mapping automatically (when write domain is
163 * INTEL_DOMAIN_INSTRUCTION).
164 */
165 if (cmd_gen(cmd) == INTEL_GEN(6) && bo)
166 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
167
168 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) bo);
169 cmd_batch_write(cmd, dw0);
170 cmd_batch_write(cmd, dw1);
Chia-I Wu32a22462014-08-26 14:13:46 +0800171 if (bo) {
172 cmd_batch_reloc(cmd, bo_offset, bo, INTEL_RELOC_GGTT |
173 INTEL_RELOC_WRITE);
174 } else {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800175 cmd_batch_write(cmd, 0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800176 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 cmd_batch_write(cmd, 0);
178 cmd_batch_write(cmd, 0);
179}
180
Chia-I Wu254db422014-08-21 11:54:29 +0800181static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
182{
183 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
184 bool supported;
185
186 CMD_ASSERT(cmd, 6, 7.5);
187
188 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
189 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
190
191 switch (p->prim_type) {
192 case GEN6_3DPRIM_POINTLIST:
193 case GEN6_3DPRIM_LINELIST:
194 case GEN6_3DPRIM_LINESTRIP:
195 case GEN6_3DPRIM_TRILIST:
196 case GEN6_3DPRIM_TRISTRIP:
197 supported = true;
198 break;
199 default:
200 supported = false;
201 break;
202 }
203
204 if (!supported)
205 return false;
206
207 switch (cmd->bind.index.type) {
208 case XGL_INDEX_8:
209 supported = (p->primitive_restart_index != 0xffu);
210 break;
211 case XGL_INDEX_16:
212 supported = (p->primitive_restart_index != 0xffffu);
213 break;
214 case XGL_INDEX_32:
215 supported = (p->primitive_restart_index != 0xffffffffu);
216 break;
217 default:
218 supported = false;
219 break;
220 }
221
222 return supported;
223}
224
Chia-I Wu59c097e2014-08-21 10:51:07 +0800225static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800226 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800227 XGL_GPU_SIZE offset,
228 XGL_INDEX_TYPE type,
229 bool enable_cut_index)
230{
231 const uint8_t cmd_len = 3;
232 uint32_t dw0, end_offset;
233 unsigned offset_align;
234
235 CMD_ASSERT(cmd, 6, 7.5);
236
Chia-I Wu426072d2014-08-26 14:31:55 +0800237 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238
239 /* the bit is moved to 3DSTATE_VF */
240 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
241 assert(!enable_cut_index);
242 if (enable_cut_index)
243 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
244
245 switch (type) {
246 case XGL_INDEX_8:
247 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
248 offset_align = 1;
249 break;
250 case XGL_INDEX_16:
251 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
252 offset_align = 2;
253 break;
254 case XGL_INDEX_32:
255 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
256 offset_align = 4;
257 break;
258 default:
259 cmd->result = XGL_ERROR_INVALID_VALUE;
260 return;
261 break;
262 }
263
264 if (offset % offset_align) {
265 cmd->result = XGL_ERROR_INVALID_VALUE;
266 return;
267 }
268
269 /* aligned and inclusive */
270 end_offset = mem->size - (mem->size % offset_align) - 1;
271
Chia-I Wu2de65d02014-08-25 10:02:53 +0800272 cmd_batch_reserve_reloc(cmd, cmd_len, 2);
Chia-I Wue24c3292014-08-21 14:05:23 +0800273 cmd_batch_write(cmd, dw0);
Chia-I Wu32a22462014-08-26 14:13:46 +0800274 cmd_batch_reloc(cmd, offset, mem->bo, 0);
275 cmd_batch_reloc(cmd, end_offset, mem->bo, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800276}
277
Chia-I Wu62a7f252014-08-29 11:31:16 +0800278static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
279 bool enable_cut_index,
280 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800281{
282 const uint8_t cmd_len = 2;
283 uint32_t dw0;
284
285 CMD_ASSERT(cmd, 7.5, 7.5);
286
Chia-I Wu426072d2014-08-26 14:31:55 +0800287 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800288 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 Wu62a7f252014-08-29 11:31:16 +0800296static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
297{
298 const uint8_t cmd_len = 7;
299 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
300
301 CMD_ASSERT(cmd, 7, 7.5);
302
303 assert(cmd->bind.gs.shader == NULL);
304
305 cmd_batch_reserve(cmd, cmd_len);
306 cmd_batch_write(cmd, dw0);
307 cmd_batch_write(cmd, 0);
308 cmd_batch_write(cmd, 0);
309 cmd_batch_write(cmd, 0);
310 cmd_batch_write(cmd, 0);
311 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
312 cmd_batch_write(cmd, 0);
313}
314
Chia-I Wud88e02d2014-08-25 10:56:13 +0800315static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
316 XGL_UINT width, XGL_UINT height)
317{
318 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800319 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800320 (cmd_len - 2);
321
322 CMD_ASSERT(cmd, 6, 7.5);
323
324 cmd_batch_reserve(cmd, cmd_len);
325 cmd_batch_write(cmd, dw0);
326 if (width && height) {
327 cmd_batch_write(cmd, 0);
328 cmd_batch_write(cmd, (height - 1) << 16 |
329 (width - 1));
330 } else {
331 cmd_batch_write(cmd, 1);
332 cmd_batch_write(cmd, 0);
333 }
334 cmd_batch_write(cmd, 0);
335}
336
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800337static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
338 const struct intel_ds_view *view)
339{
340 const uint8_t cmd_len = 7;
341 uint32_t dw0;
342
343 CMD_ASSERT(cmd, 6, 7.5);
344
345 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800346 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
347 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800348 dw0 |= (cmd_len - 2);
349
Chia-I Wu2de65d02014-08-25 10:02:53 +0800350 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800351 cmd_batch_write(cmd, dw0);
352 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600353 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800354 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800355 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600356 } else {
357 cmd_batch_write(cmd, 0);
358 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800359 cmd_batch_write(cmd, view->cmd[2]);
360 cmd_batch_write(cmd, view->cmd[3]);
361 cmd_batch_write(cmd, view->cmd[4]);
362 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800363}
364
365static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
366 const struct intel_ds_view *view)
367{
368 const uint8_t cmd_len = 3;
369 uint32_t dw0;
370
371 CMD_ASSERT(cmd, 6, 7.5);
372
373 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800374 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
375 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800376 dw0 |= (cmd_len - 2);
377
Chia-I Wu2de65d02014-08-25 10:02:53 +0800378 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800379 cmd_batch_write(cmd, dw0);
380 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600381 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800382 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800383 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600384 } else {
385 cmd_batch_write(cmd, 0);
386 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800387}
388
389static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
390 const struct intel_ds_view *view)
391{
392 const uint8_t cmd_len = 3;
393 uint32_t dw0;
394
395 CMD_ASSERT(cmd, 6, 7.5);
396
397 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800398 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
399 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800400 dw0 |= (cmd_len - 2);
401
Chia-I Wu2de65d02014-08-25 10:02:53 +0800402 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800403 cmd_batch_write(cmd, dw0);
404 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600405 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800406 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800407 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600408 } else {
409 cmd_batch_write(cmd, 0);
410 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800411}
412
Chia-I Wuf8231032014-08-25 10:44:45 +0800413static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
414 uint32_t clear_val)
415{
416 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800417 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800418 GEN6_CLEAR_PARAMS_DW0_VALID |
419 (cmd_len - 2);
420
421 CMD_ASSERT(cmd, 6, 6);
422
423 cmd_batch_reserve(cmd, cmd_len);
424 cmd_batch_write(cmd, dw0);
425 cmd_batch_write(cmd, clear_val);
426}
427
428static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
429 uint32_t clear_val)
430{
431 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800432 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800433 (cmd_len - 2);
434
435 CMD_ASSERT(cmd, 7, 7.5);
436
437 cmd_batch_reserve(cmd, cmd_len);
438 cmd_batch_write(cmd, dw0);
439 cmd_batch_write(cmd, clear_val);
440 cmd_batch_write(cmd, 1);
441}
442
Chia-I Wu302742d2014-08-22 10:28:29 +0800443static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
444 XGL_UINT blend_pos,
445 XGL_UINT ds_pos,
446 XGL_UINT cc_pos)
447{
448 const uint8_t cmd_len = 4;
449 uint32_t dw0;
450
451 CMD_ASSERT(cmd, 6, 6);
452
Chia-I Wu426072d2014-08-26 14:31:55 +0800453 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800454 (cmd_len - 2);
455
456 cmd_batch_reserve(cmd, cmd_len);
457 cmd_batch_write(cmd, dw0);
458 cmd_batch_write(cmd, (blend_pos << 2) | 1);
459 cmd_batch_write(cmd, (ds_pos << 2) | 1);
460 cmd_batch_write(cmd, (cc_pos << 2) | 1);
461}
462
Chia-I Wu1744cca2014-08-22 11:10:17 +0800463static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
464 XGL_UINT clip_pos,
465 XGL_UINT sf_pos,
466 XGL_UINT cc_pos)
467{
468 const uint8_t cmd_len = 4;
469 uint32_t dw0;
470
471 CMD_ASSERT(cmd, 6, 6);
472
Chia-I Wu426072d2014-08-26 14:31:55 +0800473 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800474 GEN6_PTR_VP_DW0_CLIP_CHANGED |
475 GEN6_PTR_VP_DW0_SF_CHANGED |
476 GEN6_PTR_VP_DW0_CC_CHANGED |
477 (cmd_len - 2);
478
479 cmd_batch_reserve(cmd, cmd_len);
480 cmd_batch_write(cmd, dw0);
481 cmd_batch_write(cmd, clip_pos << 2);
482 cmd_batch_write(cmd, sf_pos << 2);
483 cmd_batch_write(cmd, cc_pos << 2);
484}
485
486static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
487 XGL_UINT scissor_pos)
488{
489 const uint8_t cmd_len = 2;
490 uint32_t dw0;
491
492 CMD_ASSERT(cmd, 6, 6);
493
Chia-I Wu426072d2014-08-26 14:31:55 +0800494 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800495 (cmd_len - 2);
496
497 cmd_batch_reserve(cmd, cmd_len);
498 cmd_batch_write(cmd, dw0);
499 cmd_batch_write(cmd, scissor_pos << 2);
500}
501
Chia-I Wu42a56202014-08-23 16:47:48 +0800502static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
503 XGL_UINT vs_pos,
504 XGL_UINT gs_pos,
505 XGL_UINT ps_pos)
506{
507 const uint8_t cmd_len = 4;
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_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800513 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
514 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
515 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
516 (cmd_len - 2);
517
518 cmd_batch_reserve(cmd, cmd_len);
519 cmd_batch_write(cmd, dw0);
520 cmd_batch_write(cmd, vs_pos << 2);
521 cmd_batch_write(cmd, gs_pos << 2);
522 cmd_batch_write(cmd, ps_pos << 2);
523}
524
Chia-I Wu302742d2014-08-22 10:28:29 +0800525static void gen7_3dstate_pointer(struct intel_cmd *cmd,
526 int subop, XGL_UINT pos)
527{
528 const uint8_t cmd_len = 2;
529 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
530 GEN6_RENDER_SUBTYPE_3D |
531 subop | (cmd_len - 2);
532
533 cmd_batch_reserve(cmd, cmd_len);
534 cmd_batch_write(cmd, dw0);
535 cmd_batch_write(cmd, pos << 2);
536}
537
538static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
539 const struct intel_blend_state *state)
540{
541 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
542 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
543
544 CMD_ASSERT(cmd, 6, 7.5);
545 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
546
547 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
548}
549
550static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
551 const struct intel_ds_state *state)
552{
553 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
554 const uint8_t cmd_len = 3;
555
556 CMD_ASSERT(cmd, 6, 7.5);
557 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
558
559 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
560}
561
562static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
563 uint32_t stencil_ref,
564 const uint32_t blend_color[4])
565{
566 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
567 const uint8_t cmd_len = 6;
568 XGL_UINT pos;
569 uint32_t *dw;
570
571 CMD_ASSERT(cmd, 6, 7.5);
572
573 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
574 dw[0] = stencil_ref;
575 dw[1] = 0;
576 dw[2] = blend_color[0];
577 dw[3] = blend_color[1];
578 dw[4] = blend_color[2];
579 dw[5] = blend_color[3];
580 cmd_state_advance(cmd, cmd_len);
581
582 return pos;
583}
584
Chia-I Wu48c283d2014-08-25 23:13:46 +0800585static void gen6_wa_post_sync_flush(struct intel_cmd *cmd)
586{
Chia-I Wu707a29e2014-08-27 12:51:47 +0800587 if (!cmd->bind.draw_count)
588 return;
589
Chia-I Wu48c283d2014-08-25 23:13:46 +0800590 if (cmd->bind.wa_flags & GEN6_WA_POST_SYNC_FLUSH)
591 return;
592
593 CMD_ASSERT(cmd, 6, 7.5);
594
595 cmd->bind.wa_flags |= GEN6_WA_POST_SYNC_FLUSH;
596
597 /*
598 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
599 *
600 * "Pipe-control with CS-stall bit set must be sent BEFORE the
601 * pipe-control with a post-sync op and no write-cache flushes."
602 *
603 * The workaround below necessitates this workaround.
604 */
605 gen6_PIPE_CONTROL(cmd,
606 GEN6_PIPE_CONTROL_CS_STALL |
607 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
608 NULL, 0);
609
610 /*
611 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
612 *
613 * "Before any depth stall flush (including those produced by
614 * non-pipelined state commands), software needs to first send a
615 * PIPE_CONTROL with no bits set except Post-Sync Operation != 0."
616 *
617 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
618 * PIPE_CONTROL with any non-zero post-sync-op is required."
619 */
620 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, cmd->scratch_bo, 0);
621}
622
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -0600623static void gen6_wa_wm_multisample_flush(struct intel_cmd *cmd)
624{
Chia-I Wu9cb84ee2014-08-28 10:12:34 +0800625 if (!cmd->bind.draw_count)
626 return;
627
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -0600628 CMD_ASSERT(cmd, 6, 6);
629
630 gen6_wa_post_sync_flush(cmd);
631
632 /*
633 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
634 *
635 * "Driver must guarentee that all the caches in the depth pipe are
636 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
637 * requires driver to send a PIPE_CONTROL with a CS stall along with a
638 * Depth Flush prior to this command."
639 */
640 gen6_PIPE_CONTROL(cmd,
641 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
642 GEN6_PIPE_CONTROL_CS_STALL,
643 0, 0);
644}
645
Chia-I Wu48c283d2014-08-25 23:13:46 +0800646static void gen6_wa_ds_flush(struct intel_cmd *cmd)
647{
Chia-I Wu707a29e2014-08-27 12:51:47 +0800648 if (!cmd->bind.draw_count)
649 return;
650
Chia-I Wu48c283d2014-08-25 23:13:46 +0800651 CMD_ASSERT(cmd, 6, 7.5);
652
Chia-I Wu48c283d2014-08-25 23:13:46 +0800653 gen6_wa_post_sync_flush(cmd);
654
655 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
656 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
657 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
658}
659
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800660static void gen7_wa_vs_flush(struct intel_cmd *cmd)
661{
662 if (!cmd->bind.draw_count)
663 return;
664
665 if (cmd->bind.wa_flags & GEN6_WA_GEN7_VS_FLUSH)
666 return;
667
668 CMD_ASSERT(cmd, 7, 7.5);
669
670 cmd->bind.wa_flags |= GEN6_WA_GEN7_VS_FLUSH;
671
672 gen6_PIPE_CONTROL(cmd,
673 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
674 cmd->scratch_bo, 0);
675}
676
Chia-I Wu525c6602014-08-27 10:22:34 +0800677void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
678{
679 if (!cmd->bind.draw_count)
680 return;
681
682 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
683
684 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
685 gen6_wa_post_sync_flush(cmd);
686
687 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0);
688}
689
Chia-I Wu302742d2014-08-22 10:28:29 +0800690static void gen6_cc_states(struct intel_cmd *cmd)
691{
692 const struct intel_blend_state *blend = cmd->bind.state.blend;
693 const struct intel_ds_state *ds = cmd->bind.state.ds;
694 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800695 uint32_t stencil_ref;
696 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800697
698 CMD_ASSERT(cmd, 6, 6);
699
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800700 if (blend) {
701 blend_pos = gen6_BLEND_STATE(cmd, blend);
702 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
703 } else {
704 blend_pos = 0;
705 memset(blend_color, 0, sizeof(blend_color));
706 }
707
708 if (ds) {
709 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
710 stencil_ref = ds->cmd_stencil_ref;
711 } else {
712 ds_pos = 0;
713 stencil_ref = 0;
714 }
715
716 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800717
718 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
719}
720
Chia-I Wu1744cca2014-08-22 11:10:17 +0800721static void gen6_viewport_states(struct intel_cmd *cmd)
722{
723 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
724 XGL_UINT pos;
725
726 if (!viewport)
727 return;
728
729 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
730 viewport->cmd_align);
731
732 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
733 pos + viewport->cmd_clip_offset,
734 pos,
735 pos + viewport->cmd_cc_offset);
736
737 pos = (viewport->scissor_enable) ?
738 pos + viewport->cmd_scissor_rect_offset : 0;
739
740 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
741}
742
Chia-I Wu302742d2014-08-22 10:28:29 +0800743static void gen7_cc_states(struct intel_cmd *cmd)
744{
745 const struct intel_blend_state *blend = cmd->bind.state.blend;
746 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800747 uint32_t stencil_ref;
748 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800749 XGL_UINT pos;
750
751 CMD_ASSERT(cmd, 7, 7.5);
752
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800753 if (!blend && !ds)
754 return;
Chia-I Wu302742d2014-08-22 10:28:29 +0800755
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800756 if (blend) {
757 pos = gen6_BLEND_STATE(cmd, blend);
758 gen7_3dstate_pointer(cmd,
759 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +0800760
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800761 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
762 } else {
763 memset(blend_color, 0, sizeof(blend_color));
764 }
765
766 if (ds) {
767 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
768 gen7_3dstate_pointer(cmd,
769 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
770 } else {
771 stencil_ref = 0;
772 }
773
774 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800775 gen7_3dstate_pointer(cmd,
776 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
777}
778
Chia-I Wu1744cca2014-08-22 11:10:17 +0800779static void gen7_viewport_states(struct intel_cmd *cmd)
780{
781 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
782 XGL_UINT pos;
783
784 if (!viewport)
785 return;
786
787 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
788 viewport->cmd_align);
789
790 gen7_3dstate_pointer(cmd,
791 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
792 gen7_3dstate_pointer(cmd,
793 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
794 pos + viewport->cmd_cc_offset);
795 if (viewport->scissor_enable) {
796 gen7_3dstate_pointer(cmd,
797 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
798 pos + viewport->cmd_scissor_rect_offset);
799 }
800}
801
Chia-I Wu7fd5cac2014-08-27 13:19:29 +0800802static void gen6_pcb(struct intel_cmd *cmd, int subop,
803 const XGL_PIPELINE_SHADER *sh)
804{
805 const uint8_t cmd_len = 5;
806 const XGL_UINT alignment = 32;
807 const XGL_UINT max_size =
808 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
809 const XGL_UINT max_pcb = 4;
810 uint32_t pcb[4] = { 0, 0, 0, 0 };
811 XGL_FLAGS pcb_enables = 0;
812 XGL_SIZE total_size = 0;
813 uint32_t dw0;
814 XGL_UINT i;
815
816 for (i = 0; i < sh->linkConstBufferCount; i++) {
817 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
818 const XGL_SIZE size = u_align(info->bufferSize, alignment);
819 void *ptr;
820
821 if (info->bufferId >= max_pcb ||
822 pcb_enables & ((1 << info->bufferId)) ||
823 total_size + info->bufferSize > max_size) {
824 cmd->result = XGL_ERROR_UNKNOWN;
825 return;
826 }
827 if (!size)
828 continue;
829
830 pcb_enables |= 1 << info->bufferId;
831 total_size += size;
832
833 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
834 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
835 memcpy(ptr, info->pBufferData, info->bufferSize);
836 cmd_state_advance(cmd, size / sizeof(uint32_t));
837
838 pcb[info->bufferId] |= size / alignment - 1;
839 }
840
841 dw0 = GEN6_RENDER_TYPE_RENDER |
842 GEN6_RENDER_SUBTYPE_3D |
843 subop |
844 pcb_enables << 12 |
845 (cmd_len - 2);
846
847 cmd_batch_reserve(cmd, cmd_len);
848 cmd_batch_write(cmd, dw0);
849 cmd_batch_write(cmd, pcb[0]);
850 cmd_batch_write(cmd, pcb[1]);
851 cmd_batch_write(cmd, pcb[2]);
852 cmd_batch_write(cmd, pcb[3]);
853}
854
855static void gen7_pcb(struct intel_cmd *cmd, int subop,
856 const XGL_PIPELINE_SHADER *sh)
857{
858 const uint8_t cmd_len = 7;
859 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
860 GEN6_RENDER_SUBTYPE_3D |
861 subop |
862 (cmd_len - 2);
863 const XGL_UINT alignment = 32;
864 const XGL_UINT max_size = 2048;
865 const XGL_UINT max_pcb = 4;
866 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
867 uint32_t pcb[4] = { 0, 0, 0, 0 };
868 XGL_FLAGS pcb_enables = 0;
869 XGL_SIZE total_size = 0;
870 XGL_UINT i;
871
872 for (i = 0; i < sh->linkConstBufferCount; i++) {
873 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
874 const XGL_SIZE size = u_align(info->bufferSize, alignment);
875 void *ptr;
876
877 if (info->bufferId >= max_pcb ||
878 pcb_enables & ((1 << info->bufferId)) ||
879 total_size + info->bufferSize > max_size) {
880 cmd->result = XGL_ERROR_UNKNOWN;
881 return;
882 }
883 if (!size)
884 continue;
885
886 pcb_enables |= 1 << info->bufferId;
887 total_size += size;
888
889 pcb_len[info->bufferId] = size / alignment;
890
891 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
892 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
893 memcpy(ptr, info->pBufferData, info->bufferSize);
894 cmd_state_advance(cmd, size / sizeof(uint32_t));
895 }
896
897 /* no holes */
898 if (!u_is_pow2(pcb_enables + 1)) {
899 cmd->result = XGL_ERROR_UNKNOWN;
900 return;
901 }
902
903 cmd_batch_reserve(cmd, cmd_len);
904 cmd_batch_write(cmd, dw0);
905 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
906 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
907 cmd_batch_write(cmd, pcb[0]);
908 cmd_batch_write(cmd, pcb[1]);
909 cmd_batch_write(cmd, pcb[2]);
910 cmd_batch_write(cmd, pcb[3]);
911}
912
Chia-I Wu42a56202014-08-23 16:47:48 +0800913static void emit_ps_resources(struct intel_cmd *cmd,
914 const struct intel_rmap *rmap)
915{
916 const XGL_UINT surface_count = rmap->rt_count +
917 rmap->resource_count + rmap->uav_count;
918 uint32_t binding_table[256];
919 XGL_UINT pos, i;
920
921 assert(surface_count <= ARRAY_SIZE(binding_table));
922
923 for (i = 0; i < surface_count; i++) {
924 const struct intel_rmap_slot *slot = &rmap->slots[i];
925 uint32_t *dw;
926
927 switch (slot->path_len) {
928 case 0:
929 pos = 0;
930 break;
931 case INTEL_RMAP_SLOT_RT:
932 {
933 const struct intel_rt_view *view = cmd->bind.att.rt[i];
934
935 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
936 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
937
938 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800939 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800940 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +0800941 cmd_state_advance(cmd, view->cmd_len);
942 }
943 break;
944 case INTEL_RMAP_SLOT_DYN:
945 {
946 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800947 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +0800948
949 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
950 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
951
952 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800953 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800954 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +0800955 cmd_state_advance(cmd, view->cmd_len);
956 }
957 break;
958 case 1:
959 default:
960 /* TODO */
961 assert(!"no dset support");
962 break;
963 }
964
965 binding_table[i] = pos << 2;
966 }
967
968 pos = cmd_state_copy(cmd, binding_table, surface_count,
969 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
970
971 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
972 gen7_3dstate_pointer(cmd,
973 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
974 } else {
975 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
976 }
977}
978
Chia-I Wu52500102014-08-22 00:46:04 +0800979static void emit_bounded_states(struct intel_cmd *cmd)
980{
981 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
982
983 /* TODO more states */
984
Chia-I Wu1744cca2014-08-22 11:10:17 +0800985 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +0800986 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800987 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +0800988
989 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
990 &cmd->bind.pipeline.graphics->vs);
991 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
992 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800993 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +0800994 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800995 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +0800996
997 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
998 &cmd->bind.pipeline.graphics->vs);
999 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1000 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001001 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001002
Chia-I Wu42a56202014-08-23 16:47:48 +08001003 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1004
Chia-I Wu48c283d2014-08-25 23:13:46 +08001005 gen6_wa_post_sync_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001006 /* need multisample flush on gen6 */
1007 if (cmd_gen(cmd) == INTEL_GEN(6))
1008 gen6_wa_wm_multisample_flush(cmd);
1009 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001010 cmd_batch_reserve(cmd, msaa->cmd_len);
1011 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001012}
1013
1014static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001015 const struct intel_pipe_shader *shader,
1016 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001017{
1018 uint32_t i;
1019 struct intel_cmd_shader *cmdShader;
1020
1021 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001022 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001023 /* shader is already part of pipeline */
1024 return;
1025 }
1026 }
1027
Chia-I Wu338fe642014-08-28 10:43:04 +08001028 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1029 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1030
1031 cmdShader = cmd->bind.shaderCache.shaderArray;
1032
1033 cmd->bind.shaderCache.shaderArray =
1034 icd_alloc(sizeof(*cmdShader) * new_count,
1035 0, XGL_SYSTEM_ALLOC_INTERNAL);
1036 if (cmd->bind.shaderCache.shaderArray == NULL) {
1037 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001038 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1039 return;
1040 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001041
1042 if (cmdShader) {
1043 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1044 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1045 icd_free(cmdShader);
1046 }
1047
1048 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001049 }
1050
Chia-I Wu338fe642014-08-28 10:43:04 +08001051 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001052 cmdShader->shader = shader;
1053 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001054 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001055 cmd->bind.shaderCache.used++;
1056 return;
1057}
1058
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001059static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001060 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001061{
1062 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001063
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001064 // TODO: This probably isn't quite what we want.
1065 // While this does reflect the call that was made, it would be
1066 // more appropriate to indicate the behavior, ie. CS_STALL, WRITE_IMM
1067 // and then issue the minimum number of pipe_control commands
1068 // This sequence could do some duplicate work though we have
1069 // WA_POST_SYNC_FLUSH first to try to minimize that.
1070 if (pipeline->pre_pso_wa_flags & GEN6_WA_POST_SYNC_FLUSH) {
1071 gen6_wa_post_sync_flush(cmd);
1072 }
1073 if (pipeline->pre_pso_wa_flags & GEN7_WA_MULTISAMPLE_FLUSH) {
1074 gen6_wa_wm_multisample_flush(cmd);
1075 }
1076 if (pipeline->pre_pso_wa_flags & GEN6_WA_GEN7_VS_FLUSH) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001077 gen7_wa_vs_flush(cmd);
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001078 }
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001079
1080 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001081 assert(pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001082 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001083
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001084 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001085 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001086 }
1087 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001088 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001089 }
1090 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001091 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001092 }
1093 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001094 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001095 }
1096 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001097 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001098 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001099
Chia-I Wu62a7f252014-08-29 11:31:16 +08001100 gen7_3DSTATE_GS(cmd);
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001101
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001102 if (pipeline->post_pso_wa_flags & GEN6_WA_POST_SYNC_FLUSH) {
1103 gen6_wa_post_sync_flush(cmd);
1104 }
1105 if (pipeline->post_pso_wa_flags & GEN7_WA_MULTISAMPLE_FLUSH) {
1106 gen6_wa_wm_multisample_flush(cmd);
1107 }
1108 if (pipeline->post_pso_wa_flags & GEN6_WA_GEN7_VS_FLUSH) {
1109 gen7_wa_vs_flush(cmd);
1110 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001111}
1112
1113static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1114 const struct intel_pipeline *pipeline)
1115{
1116 cmd->bind.pipeline.compute = pipeline;
1117}
1118
1119static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1120 const struct intel_pipeline_delta *delta)
1121{
1122 cmd->bind.pipeline.graphics_delta = delta;
1123}
1124
1125static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1126 const struct intel_pipeline_delta *delta)
1127{
1128 cmd->bind.pipeline.compute_delta = delta;
1129}
1130
1131static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1132 const struct intel_dset *dset,
1133 XGL_UINT slot_offset)
1134{
1135 cmd->bind.dset.graphics = dset;
1136 cmd->bind.dset.graphics_offset = slot_offset;
1137}
1138
1139static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1140 const struct intel_dset *dset,
1141 XGL_UINT slot_offset)
1142{
1143 cmd->bind.dset.compute = dset;
1144 cmd->bind.dset.compute_offset = slot_offset;
1145}
1146
1147static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1148 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1149{
1150 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1151}
1152
1153static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1154 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1155{
1156 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1157}
1158
1159static void cmd_bind_index_data(struct intel_cmd *cmd,
1160 const struct intel_mem *mem,
1161 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1162{
1163 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1164 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1165 } else {
1166 cmd->bind.index.mem = mem;
1167 cmd->bind.index.offset = offset;
1168 cmd->bind.index.type = type;
1169 }
1170}
1171
1172static void cmd_bind_rt(struct intel_cmd *cmd,
1173 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1174 XGL_UINT count)
1175{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001176 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001177 XGL_UINT i;
1178
1179 for (i = 0; i < count; i++) {
1180 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1181 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001182 const struct intel_layout *layout = &rt->img->layout;
1183
1184 if (i == 0) {
1185 width = layout->width0;
1186 height = layout->height0;
1187 } else {
1188 if (width > layout->width0)
1189 width = layout->width0;
1190 if (height > layout->height0)
1191 height = layout->height0;
1192 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001193
1194 cmd->bind.att.rt[i] = rt;
1195 }
1196
1197 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001198
Chia-I Wu48c283d2014-08-25 23:13:46 +08001199 gen6_wa_post_sync_flush(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001200 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001201}
1202
1203static void cmd_bind_ds(struct intel_cmd *cmd,
1204 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1205{
1206 const struct intel_ds_view *ds;
1207
1208 if (info) {
1209 cmd->bind.att.ds = intel_ds_view(info->view);
1210 ds = cmd->bind.att.ds;
1211 } else {
1212 /* all zeros */
1213 static const struct intel_ds_view null_ds;
1214 ds = &null_ds;
1215 }
1216
Chia-I Wu48c283d2014-08-25 23:13:46 +08001217 gen6_wa_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001218 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1219 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1220 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001221
1222 if (cmd_gen(cmd) >= INTEL_GEN(7))
1223 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1224 else
1225 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001226}
1227
1228static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1229 const struct intel_viewport_state *state)
1230{
1231 cmd->bind.state.viewport = state;
1232}
1233
1234static void cmd_bind_raster_state(struct intel_cmd *cmd,
1235 const struct intel_raster_state *state)
1236{
1237 cmd->bind.state.raster = state;
1238}
1239
1240static void cmd_bind_ds_state(struct intel_cmd *cmd,
1241 const struct intel_ds_state *state)
1242{
1243 cmd->bind.state.ds = state;
1244}
1245
1246static void cmd_bind_blend_state(struct intel_cmd *cmd,
1247 const struct intel_blend_state *state)
1248{
1249 cmd->bind.state.blend = state;
1250}
1251
1252static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1253 const struct intel_msaa_state *state)
1254{
1255 cmd->bind.state.msaa = state;
1256}
1257
1258static void cmd_draw(struct intel_cmd *cmd,
1259 XGL_UINT vertex_start,
1260 XGL_UINT vertex_count,
1261 XGL_UINT instance_start,
1262 XGL_UINT instance_count,
1263 bool indexed,
1264 XGL_UINT vertex_base)
1265{
1266 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1267
1268 emit_bounded_states(cmd);
1269
1270 if (indexed) {
1271 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1272 cmd->result = XGL_ERROR_UNKNOWN;
1273
1274 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1275 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1276 p->primitive_restart_index);
1277 } else {
1278 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1279 cmd->bind.index.offset, cmd->bind.index.type,
1280 p->primitive_restart);
1281 }
1282 } else {
1283 assert(!vertex_base);
1284 }
1285
1286 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1287 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1288 vertex_start, instance_count, instance_start, vertex_base);
1289 } else {
1290 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1291 vertex_start, instance_count, instance_start, vertex_base);
1292 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001293
Chia-I Wu707a29e2014-08-27 12:51:47 +08001294 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001295 /* need to re-emit all workarounds */
1296 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001297}
1298
Chia-I Wub2755562014-08-20 13:38:52 +08001299XGL_VOID XGLAPI intelCmdBindPipeline(
1300 XGL_CMD_BUFFER cmdBuffer,
1301 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1302 XGL_PIPELINE pipeline)
1303{
1304 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1305
1306 switch (pipelineBindPoint) {
1307 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001308 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001309 break;
1310 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001311 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001312 break;
1313 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001314 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001315 break;
1316 }
1317}
1318
1319XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1320 XGL_CMD_BUFFER cmdBuffer,
1321 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1322 XGL_PIPELINE_DELTA delta)
1323{
1324 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1325
1326 switch (pipelineBindPoint) {
1327 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001328 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001329 break;
1330 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001331 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001332 break;
1333 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001334 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001335 break;
1336 }
1337}
1338
1339XGL_VOID XGLAPI intelCmdBindStateObject(
1340 XGL_CMD_BUFFER cmdBuffer,
1341 XGL_STATE_BIND_POINT stateBindPoint,
1342 XGL_STATE_OBJECT state)
1343{
1344 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1345
1346 switch (stateBindPoint) {
1347 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001348 cmd_bind_viewport_state(cmd,
1349 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001350 break;
1351 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001352 cmd_bind_raster_state(cmd,
1353 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001354 break;
1355 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001356 cmd_bind_ds_state(cmd,
1357 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001358 break;
1359 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001360 cmd_bind_blend_state(cmd,
1361 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001362 break;
1363 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001364 cmd_bind_msaa_state(cmd,
1365 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001366 break;
1367 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001368 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001369 break;
1370 }
1371}
1372
1373XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1374 XGL_CMD_BUFFER cmdBuffer,
1375 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1376 XGL_UINT index,
1377 XGL_DESCRIPTOR_SET descriptorSet,
1378 XGL_UINT slotOffset)
1379{
1380 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1381 struct intel_dset *dset = intel_dset(descriptorSet);
1382
1383 assert(!index);
1384
1385 switch (pipelineBindPoint) {
1386 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001387 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001388 break;
1389 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001390 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001391 break;
1392 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001393 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001394 break;
1395 }
1396}
1397
1398XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1399 XGL_CMD_BUFFER cmdBuffer,
1400 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1401 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1402{
1403 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1404
1405 switch (pipelineBindPoint) {
1406 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001407 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001408 break;
1409 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001410 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001411 break;
1412 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001413 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001414 break;
1415 }
1416}
1417
1418XGL_VOID XGLAPI intelCmdBindIndexData(
1419 XGL_CMD_BUFFER cmdBuffer,
1420 XGL_GPU_MEMORY mem_,
1421 XGL_GPU_SIZE offset,
1422 XGL_INDEX_TYPE indexType)
1423{
1424 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1425 struct intel_mem *mem = intel_mem(mem_);
1426
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001427 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001428}
1429
1430XGL_VOID XGLAPI intelCmdBindAttachments(
1431 XGL_CMD_BUFFER cmdBuffer,
1432 XGL_UINT colorAttachmentCount,
1433 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1434 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1435{
1436 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001437
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001438 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1439 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001440}
1441
1442XGL_VOID XGLAPI intelCmdDraw(
1443 XGL_CMD_BUFFER cmdBuffer,
1444 XGL_UINT firstVertex,
1445 XGL_UINT vertexCount,
1446 XGL_UINT firstInstance,
1447 XGL_UINT instanceCount)
1448{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001449 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001450
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001451 cmd_draw(cmd, firstVertex, vertexCount,
1452 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08001453}
1454
1455XGL_VOID XGLAPI intelCmdDrawIndexed(
1456 XGL_CMD_BUFFER cmdBuffer,
1457 XGL_UINT firstIndex,
1458 XGL_UINT indexCount,
1459 XGL_INT vertexOffset,
1460 XGL_UINT firstInstance,
1461 XGL_UINT instanceCount)
1462{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001463 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001464
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001465 cmd_draw(cmd, firstIndex, indexCount,
1466 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001467}
1468
1469XGL_VOID XGLAPI intelCmdDrawIndirect(
1470 XGL_CMD_BUFFER cmdBuffer,
1471 XGL_GPU_MEMORY mem,
1472 XGL_GPU_SIZE offset,
1473 XGL_UINT32 count,
1474 XGL_UINT32 stride)
1475{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001476 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1477
1478 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001479}
1480
1481XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
1482 XGL_CMD_BUFFER cmdBuffer,
1483 XGL_GPU_MEMORY mem,
1484 XGL_GPU_SIZE offset,
1485 XGL_UINT32 count,
1486 XGL_UINT32 stride)
1487{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001488 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1489
1490 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001491}
1492
1493XGL_VOID XGLAPI intelCmdDispatch(
1494 XGL_CMD_BUFFER cmdBuffer,
1495 XGL_UINT x,
1496 XGL_UINT y,
1497 XGL_UINT z)
1498{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001499 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1500
1501 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001502}
1503
1504XGL_VOID XGLAPI intelCmdDispatchIndirect(
1505 XGL_CMD_BUFFER cmdBuffer,
1506 XGL_GPU_MEMORY mem,
1507 XGL_GPU_SIZE offset)
1508{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001509 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1510
1511 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001512}