blob: 2e9e7121030307a7263e2a6ae53118d268117321 [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 Wud95aa2b2014-08-29 12:07:47 +0800296static void gen6_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, 6, 6);
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, 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT);
311 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
312 cmd_batch_write(cmd, 0);
313}
314
Chia-I Wu62a7f252014-08-29 11:31:16 +0800315static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
316{
317 const uint8_t cmd_len = 7;
318 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
319
320 CMD_ASSERT(cmd, 7, 7.5);
321
322 assert(cmd->bind.gs.shader == NULL);
323
324 cmd_batch_reserve(cmd, cmd_len);
325 cmd_batch_write(cmd, dw0);
326 cmd_batch_write(cmd, 0);
327 cmd_batch_write(cmd, 0);
328 cmd_batch_write(cmd, 0);
329 cmd_batch_write(cmd, 0);
330 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
331 cmd_batch_write(cmd, 0);
332}
333
Chia-I Wud88e02d2014-08-25 10:56:13 +0800334static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
335 XGL_UINT width, XGL_UINT height)
336{
337 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800338 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800339 (cmd_len - 2);
340
341 CMD_ASSERT(cmd, 6, 7.5);
342
343 cmd_batch_reserve(cmd, cmd_len);
344 cmd_batch_write(cmd, dw0);
345 if (width && height) {
346 cmd_batch_write(cmd, 0);
347 cmd_batch_write(cmd, (height - 1) << 16 |
348 (width - 1));
349 } else {
350 cmd_batch_write(cmd, 1);
351 cmd_batch_write(cmd, 0);
352 }
353 cmd_batch_write(cmd, 0);
354}
355
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800356static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
357 const struct intel_ds_view *view)
358{
359 const uint8_t cmd_len = 7;
360 uint32_t dw0;
361
362 CMD_ASSERT(cmd, 6, 7.5);
363
364 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800365 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
366 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800367 dw0 |= (cmd_len - 2);
368
Chia-I Wu2de65d02014-08-25 10:02:53 +0800369 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800370 cmd_batch_write(cmd, dw0);
371 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600372 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800373 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800374 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600375 } else {
376 cmd_batch_write(cmd, 0);
377 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800378 cmd_batch_write(cmd, view->cmd[2]);
379 cmd_batch_write(cmd, view->cmd[3]);
380 cmd_batch_write(cmd, view->cmd[4]);
381 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800382}
383
384static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
385 const struct intel_ds_view *view)
386{
387 const uint8_t cmd_len = 3;
388 uint32_t dw0;
389
390 CMD_ASSERT(cmd, 6, 7.5);
391
392 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800393 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
394 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800395 dw0 |= (cmd_len - 2);
396
Chia-I Wu2de65d02014-08-25 10:02:53 +0800397 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800398 cmd_batch_write(cmd, dw0);
399 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600400 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800401 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800402 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600403 } else {
404 cmd_batch_write(cmd, 0);
405 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800406}
407
408static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
409 const struct intel_ds_view *view)
410{
411 const uint8_t cmd_len = 3;
412 uint32_t dw0;
413
414 CMD_ASSERT(cmd, 6, 7.5);
415
416 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800417 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
418 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800419 dw0 |= (cmd_len - 2);
420
Chia-I Wu2de65d02014-08-25 10:02:53 +0800421 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800422 cmd_batch_write(cmd, dw0);
423 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600424 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800425 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800426 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600427 } else {
428 cmd_batch_write(cmd, 0);
429 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800430}
431
Chia-I Wuf8231032014-08-25 10:44:45 +0800432static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
433 uint32_t clear_val)
434{
435 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800436 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800437 GEN6_CLEAR_PARAMS_DW0_VALID |
438 (cmd_len - 2);
439
440 CMD_ASSERT(cmd, 6, 6);
441
442 cmd_batch_reserve(cmd, cmd_len);
443 cmd_batch_write(cmd, dw0);
444 cmd_batch_write(cmd, clear_val);
445}
446
447static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
448 uint32_t clear_val)
449{
450 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800451 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800452 (cmd_len - 2);
453
454 CMD_ASSERT(cmd, 7, 7.5);
455
456 cmd_batch_reserve(cmd, cmd_len);
457 cmd_batch_write(cmd, dw0);
458 cmd_batch_write(cmd, clear_val);
459 cmd_batch_write(cmd, 1);
460}
461
Chia-I Wu302742d2014-08-22 10:28:29 +0800462static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
463 XGL_UINT blend_pos,
464 XGL_UINT ds_pos,
465 XGL_UINT cc_pos)
466{
467 const uint8_t cmd_len = 4;
468 uint32_t dw0;
469
470 CMD_ASSERT(cmd, 6, 6);
471
Chia-I Wu426072d2014-08-26 14:31:55 +0800472 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800473 (cmd_len - 2);
474
475 cmd_batch_reserve(cmd, cmd_len);
476 cmd_batch_write(cmd, dw0);
477 cmd_batch_write(cmd, (blend_pos << 2) | 1);
478 cmd_batch_write(cmd, (ds_pos << 2) | 1);
479 cmd_batch_write(cmd, (cc_pos << 2) | 1);
480}
481
Chia-I Wu1744cca2014-08-22 11:10:17 +0800482static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
483 XGL_UINT clip_pos,
484 XGL_UINT sf_pos,
485 XGL_UINT cc_pos)
486{
487 const uint8_t cmd_len = 4;
488 uint32_t dw0;
489
490 CMD_ASSERT(cmd, 6, 6);
491
Chia-I Wu426072d2014-08-26 14:31:55 +0800492 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800493 GEN6_PTR_VP_DW0_CLIP_CHANGED |
494 GEN6_PTR_VP_DW0_SF_CHANGED |
495 GEN6_PTR_VP_DW0_CC_CHANGED |
496 (cmd_len - 2);
497
498 cmd_batch_reserve(cmd, cmd_len);
499 cmd_batch_write(cmd, dw0);
500 cmd_batch_write(cmd, clip_pos << 2);
501 cmd_batch_write(cmd, sf_pos << 2);
502 cmd_batch_write(cmd, cc_pos << 2);
503}
504
505static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
506 XGL_UINT scissor_pos)
507{
508 const uint8_t cmd_len = 2;
509 uint32_t dw0;
510
511 CMD_ASSERT(cmd, 6, 6);
512
Chia-I Wu426072d2014-08-26 14:31:55 +0800513 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800514 (cmd_len - 2);
515
516 cmd_batch_reserve(cmd, cmd_len);
517 cmd_batch_write(cmd, dw0);
518 cmd_batch_write(cmd, scissor_pos << 2);
519}
520
Chia-I Wu42a56202014-08-23 16:47:48 +0800521static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
522 XGL_UINT vs_pos,
523 XGL_UINT gs_pos,
524 XGL_UINT ps_pos)
525{
526 const uint8_t cmd_len = 4;
527 uint32_t dw0;
528
529 CMD_ASSERT(cmd, 6, 6);
530
Chia-I Wu426072d2014-08-26 14:31:55 +0800531 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800532 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
533 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
534 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
535 (cmd_len - 2);
536
537 cmd_batch_reserve(cmd, cmd_len);
538 cmd_batch_write(cmd, dw0);
539 cmd_batch_write(cmd, vs_pos << 2);
540 cmd_batch_write(cmd, gs_pos << 2);
541 cmd_batch_write(cmd, ps_pos << 2);
542}
543
Chia-I Wu302742d2014-08-22 10:28:29 +0800544static void gen7_3dstate_pointer(struct intel_cmd *cmd,
545 int subop, XGL_UINT pos)
546{
547 const uint8_t cmd_len = 2;
548 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
549 GEN6_RENDER_SUBTYPE_3D |
550 subop | (cmd_len - 2);
551
552 cmd_batch_reserve(cmd, cmd_len);
553 cmd_batch_write(cmd, dw0);
554 cmd_batch_write(cmd, pos << 2);
555}
556
557static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
558 const struct intel_blend_state *state)
559{
560 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
561 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
562
563 CMD_ASSERT(cmd, 6, 7.5);
564 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
565
566 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
567}
568
569static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
570 const struct intel_ds_state *state)
571{
572 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
573 const uint8_t cmd_len = 3;
574
575 CMD_ASSERT(cmd, 6, 7.5);
576 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
577
578 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
579}
580
581static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
582 uint32_t stencil_ref,
583 const uint32_t blend_color[4])
584{
585 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
586 const uint8_t cmd_len = 6;
587 XGL_UINT pos;
588 uint32_t *dw;
589
590 CMD_ASSERT(cmd, 6, 7.5);
591
592 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
593 dw[0] = stencil_ref;
594 dw[1] = 0;
595 dw[2] = blend_color[0];
596 dw[3] = blend_color[1];
597 dw[4] = blend_color[2];
598 dw[5] = blend_color[3];
599 cmd_state_advance(cmd, cmd_len);
600
601 return pos;
602}
603
Chia-I Wu48c283d2014-08-25 23:13:46 +0800604static void gen6_wa_post_sync_flush(struct intel_cmd *cmd)
605{
Chia-I Wu707a29e2014-08-27 12:51:47 +0800606 if (!cmd->bind.draw_count)
607 return;
608
Chia-I Wu48c283d2014-08-25 23:13:46 +0800609 if (cmd->bind.wa_flags & GEN6_WA_POST_SYNC_FLUSH)
610 return;
611
612 CMD_ASSERT(cmd, 6, 7.5);
613
614 cmd->bind.wa_flags |= GEN6_WA_POST_SYNC_FLUSH;
615
616 /*
617 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
618 *
619 * "Pipe-control with CS-stall bit set must be sent BEFORE the
620 * pipe-control with a post-sync op and no write-cache flushes."
621 *
622 * The workaround below necessitates this workaround.
623 */
624 gen6_PIPE_CONTROL(cmd,
625 GEN6_PIPE_CONTROL_CS_STALL |
626 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
627 NULL, 0);
628
629 /*
630 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
631 *
632 * "Before any depth stall flush (including those produced by
633 * non-pipelined state commands), software needs to first send a
634 * PIPE_CONTROL with no bits set except Post-Sync Operation != 0."
635 *
636 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
637 * PIPE_CONTROL with any non-zero post-sync-op is required."
638 */
639 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, cmd->scratch_bo, 0);
640}
641
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -0600642static void gen6_wa_wm_multisample_flush(struct intel_cmd *cmd)
643{
Chia-I Wu9cb84ee2014-08-28 10:12:34 +0800644 if (!cmd->bind.draw_count)
645 return;
646
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -0600647 CMD_ASSERT(cmd, 6, 6);
648
649 gen6_wa_post_sync_flush(cmd);
650
651 /*
652 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
653 *
654 * "Driver must guarentee that all the caches in the depth pipe are
655 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
656 * requires driver to send a PIPE_CONTROL with a CS stall along with a
657 * Depth Flush prior to this command."
658 */
659 gen6_PIPE_CONTROL(cmd,
660 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
661 GEN6_PIPE_CONTROL_CS_STALL,
662 0, 0);
663}
664
Chia-I Wu48c283d2014-08-25 23:13:46 +0800665static void gen6_wa_ds_flush(struct intel_cmd *cmd)
666{
Chia-I Wu707a29e2014-08-27 12:51:47 +0800667 if (!cmd->bind.draw_count)
668 return;
669
Chia-I Wu48c283d2014-08-25 23:13:46 +0800670 CMD_ASSERT(cmd, 6, 7.5);
671
Chia-I Wu48c283d2014-08-25 23:13:46 +0800672 gen6_wa_post_sync_flush(cmd);
673
674 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
675 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
676 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
677}
678
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800679static void gen7_wa_vs_flush(struct intel_cmd *cmd)
680{
681 if (!cmd->bind.draw_count)
682 return;
683
684 if (cmd->bind.wa_flags & GEN6_WA_GEN7_VS_FLUSH)
685 return;
686
687 CMD_ASSERT(cmd, 7, 7.5);
688
689 cmd->bind.wa_flags |= GEN6_WA_GEN7_VS_FLUSH;
690
691 gen6_PIPE_CONTROL(cmd,
692 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
693 cmd->scratch_bo, 0);
694}
695
Chia-I Wu525c6602014-08-27 10:22:34 +0800696void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
697{
698 if (!cmd->bind.draw_count)
699 return;
700
701 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
702
703 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
704 gen6_wa_post_sync_flush(cmd);
705
706 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0);
707}
708
Chia-I Wu302742d2014-08-22 10:28:29 +0800709static void gen6_cc_states(struct intel_cmd *cmd)
710{
711 const struct intel_blend_state *blend = cmd->bind.state.blend;
712 const struct intel_ds_state *ds = cmd->bind.state.ds;
713 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800714 uint32_t stencil_ref;
715 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800716
717 CMD_ASSERT(cmd, 6, 6);
718
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800719 if (blend) {
720 blend_pos = gen6_BLEND_STATE(cmd, blend);
721 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
722 } else {
723 blend_pos = 0;
724 memset(blend_color, 0, sizeof(blend_color));
725 }
726
727 if (ds) {
728 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
729 stencil_ref = ds->cmd_stencil_ref;
730 } else {
731 ds_pos = 0;
732 stencil_ref = 0;
733 }
734
735 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800736
737 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
738}
739
Chia-I Wu1744cca2014-08-22 11:10:17 +0800740static void gen6_viewport_states(struct intel_cmd *cmd)
741{
742 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
743 XGL_UINT pos;
744
745 if (!viewport)
746 return;
747
748 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
749 viewport->cmd_align);
750
751 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
752 pos + viewport->cmd_clip_offset,
753 pos,
754 pos + viewport->cmd_cc_offset);
755
756 pos = (viewport->scissor_enable) ?
757 pos + viewport->cmd_scissor_rect_offset : 0;
758
759 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
760}
761
Chia-I Wu302742d2014-08-22 10:28:29 +0800762static void gen7_cc_states(struct intel_cmd *cmd)
763{
764 const struct intel_blend_state *blend = cmd->bind.state.blend;
765 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800766 uint32_t stencil_ref;
767 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800768 XGL_UINT pos;
769
770 CMD_ASSERT(cmd, 7, 7.5);
771
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800772 if (!blend && !ds)
773 return;
Chia-I Wu302742d2014-08-22 10:28:29 +0800774
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800775 if (blend) {
776 pos = gen6_BLEND_STATE(cmd, blend);
777 gen7_3dstate_pointer(cmd,
778 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +0800779
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800780 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
781 } else {
782 memset(blend_color, 0, sizeof(blend_color));
783 }
784
785 if (ds) {
786 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
787 gen7_3dstate_pointer(cmd,
788 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
789 } else {
790 stencil_ref = 0;
791 }
792
793 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800794 gen7_3dstate_pointer(cmd,
795 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
796}
797
Chia-I Wu1744cca2014-08-22 11:10:17 +0800798static void gen7_viewport_states(struct intel_cmd *cmd)
799{
800 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
801 XGL_UINT pos;
802
803 if (!viewport)
804 return;
805
806 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
807 viewport->cmd_align);
808
809 gen7_3dstate_pointer(cmd,
810 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
811 gen7_3dstate_pointer(cmd,
812 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
813 pos + viewport->cmd_cc_offset);
814 if (viewport->scissor_enable) {
815 gen7_3dstate_pointer(cmd,
816 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
817 pos + viewport->cmd_scissor_rect_offset);
818 }
819}
820
Chia-I Wu7fd5cac2014-08-27 13:19:29 +0800821static void gen6_pcb(struct intel_cmd *cmd, int subop,
822 const XGL_PIPELINE_SHADER *sh)
823{
824 const uint8_t cmd_len = 5;
825 const XGL_UINT alignment = 32;
826 const XGL_UINT max_size =
827 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
828 const XGL_UINT max_pcb = 4;
829 uint32_t pcb[4] = { 0, 0, 0, 0 };
830 XGL_FLAGS pcb_enables = 0;
831 XGL_SIZE total_size = 0;
832 uint32_t dw0;
833 XGL_UINT i;
834
835 for (i = 0; i < sh->linkConstBufferCount; i++) {
836 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
837 const XGL_SIZE size = u_align(info->bufferSize, alignment);
838 void *ptr;
839
840 if (info->bufferId >= max_pcb ||
841 pcb_enables & ((1 << info->bufferId)) ||
842 total_size + info->bufferSize > max_size) {
843 cmd->result = XGL_ERROR_UNKNOWN;
844 return;
845 }
846 if (!size)
847 continue;
848
849 pcb_enables |= 1 << info->bufferId;
850 total_size += size;
851
852 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
853 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
854 memcpy(ptr, info->pBufferData, info->bufferSize);
855 cmd_state_advance(cmd, size / sizeof(uint32_t));
856
857 pcb[info->bufferId] |= size / alignment - 1;
858 }
859
860 dw0 = GEN6_RENDER_TYPE_RENDER |
861 GEN6_RENDER_SUBTYPE_3D |
862 subop |
863 pcb_enables << 12 |
864 (cmd_len - 2);
865
866 cmd_batch_reserve(cmd, cmd_len);
867 cmd_batch_write(cmd, dw0);
868 cmd_batch_write(cmd, pcb[0]);
869 cmd_batch_write(cmd, pcb[1]);
870 cmd_batch_write(cmd, pcb[2]);
871 cmd_batch_write(cmd, pcb[3]);
872}
873
874static void gen7_pcb(struct intel_cmd *cmd, int subop,
875 const XGL_PIPELINE_SHADER *sh)
876{
877 const uint8_t cmd_len = 7;
878 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
879 GEN6_RENDER_SUBTYPE_3D |
880 subop |
881 (cmd_len - 2);
882 const XGL_UINT alignment = 32;
883 const XGL_UINT max_size = 2048;
884 const XGL_UINT max_pcb = 4;
885 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
886 uint32_t pcb[4] = { 0, 0, 0, 0 };
887 XGL_FLAGS pcb_enables = 0;
888 XGL_SIZE total_size = 0;
889 XGL_UINT i;
890
891 for (i = 0; i < sh->linkConstBufferCount; i++) {
892 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
893 const XGL_SIZE size = u_align(info->bufferSize, alignment);
894 void *ptr;
895
896 if (info->bufferId >= max_pcb ||
897 pcb_enables & ((1 << info->bufferId)) ||
898 total_size + info->bufferSize > max_size) {
899 cmd->result = XGL_ERROR_UNKNOWN;
900 return;
901 }
902 if (!size)
903 continue;
904
905 pcb_enables |= 1 << info->bufferId;
906 total_size += size;
907
908 pcb_len[info->bufferId] = size / alignment;
909
910 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
911 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
912 memcpy(ptr, info->pBufferData, info->bufferSize);
913 cmd_state_advance(cmd, size / sizeof(uint32_t));
914 }
915
916 /* no holes */
917 if (!u_is_pow2(pcb_enables + 1)) {
918 cmd->result = XGL_ERROR_UNKNOWN;
919 return;
920 }
921
922 cmd_batch_reserve(cmd, cmd_len);
923 cmd_batch_write(cmd, dw0);
924 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
925 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
926 cmd_batch_write(cmd, pcb[0]);
927 cmd_batch_write(cmd, pcb[1]);
928 cmd_batch_write(cmd, pcb[2]);
929 cmd_batch_write(cmd, pcb[3]);
930}
931
Chia-I Wu42a56202014-08-23 16:47:48 +0800932static void emit_ps_resources(struct intel_cmd *cmd,
933 const struct intel_rmap *rmap)
934{
935 const XGL_UINT surface_count = rmap->rt_count +
936 rmap->resource_count + rmap->uav_count;
937 uint32_t binding_table[256];
938 XGL_UINT pos, i;
939
940 assert(surface_count <= ARRAY_SIZE(binding_table));
941
942 for (i = 0; i < surface_count; i++) {
943 const struct intel_rmap_slot *slot = &rmap->slots[i];
944 uint32_t *dw;
945
946 switch (slot->path_len) {
947 case 0:
948 pos = 0;
949 break;
950 case INTEL_RMAP_SLOT_RT:
951 {
952 const struct intel_rt_view *view = cmd->bind.att.rt[i];
953
954 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
955 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
956
957 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800958 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800959 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +0800960 cmd_state_advance(cmd, view->cmd_len);
961 }
962 break;
963 case INTEL_RMAP_SLOT_DYN:
964 {
965 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800966 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +0800967
968 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
969 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
970
971 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800972 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800973 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +0800974 cmd_state_advance(cmd, view->cmd_len);
975 }
976 break;
977 case 1:
978 default:
979 /* TODO */
980 assert(!"no dset support");
981 break;
982 }
983
984 binding_table[i] = pos << 2;
985 }
986
987 pos = cmd_state_copy(cmd, binding_table, surface_count,
988 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
989
990 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
991 gen7_3dstate_pointer(cmd,
992 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
993 } else {
994 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
995 }
996}
997
Chia-I Wu52500102014-08-22 00:46:04 +0800998static void emit_bounded_states(struct intel_cmd *cmd)
999{
1000 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1001
1002 /* TODO more states */
1003
Chia-I Wu1744cca2014-08-22 11:10:17 +08001004 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001005 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001006 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001007
1008 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1009 &cmd->bind.pipeline.graphics->vs);
1010 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1011 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001012 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001013 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001014 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001015
1016 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1017 &cmd->bind.pipeline.graphics->vs);
1018 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1019 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001020 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001021
Chia-I Wu42a56202014-08-23 16:47:48 +08001022 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
1023
Chia-I Wu48c283d2014-08-25 23:13:46 +08001024 gen6_wa_post_sync_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001025 /* need multisample flush on gen6 */
1026 if (cmd_gen(cmd) == INTEL_GEN(6))
1027 gen6_wa_wm_multisample_flush(cmd);
1028 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +08001029 cmd_batch_reserve(cmd, msaa->cmd_len);
1030 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001031}
1032
1033static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001034 const struct intel_pipe_shader *shader,
1035 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001036{
1037 uint32_t i;
1038 struct intel_cmd_shader *cmdShader;
1039
1040 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001041 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001042 /* shader is already part of pipeline */
1043 return;
1044 }
1045 }
1046
Chia-I Wu338fe642014-08-28 10:43:04 +08001047 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1048 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1049
1050 cmdShader = cmd->bind.shaderCache.shaderArray;
1051
1052 cmd->bind.shaderCache.shaderArray =
1053 icd_alloc(sizeof(*cmdShader) * new_count,
1054 0, XGL_SYSTEM_ALLOC_INTERNAL);
1055 if (cmd->bind.shaderCache.shaderArray == NULL) {
1056 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001057 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1058 return;
1059 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001060
1061 if (cmdShader) {
1062 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1063 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1064 icd_free(cmdShader);
1065 }
1066
1067 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001068 }
1069
Chia-I Wu338fe642014-08-28 10:43:04 +08001070 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001071 cmdShader->shader = shader;
1072 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001073 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001074 cmd->bind.shaderCache.used++;
1075 return;
1076}
1077
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001078static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001079 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001080{
1081 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001082
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001083 // TODO: This probably isn't quite what we want.
1084 // While this does reflect the call that was made, it would be
1085 // more appropriate to indicate the behavior, ie. CS_STALL, WRITE_IMM
1086 // and then issue the minimum number of pipe_control commands
1087 // This sequence could do some duplicate work though we have
1088 // WA_POST_SYNC_FLUSH first to try to minimize that.
1089 if (pipeline->pre_pso_wa_flags & GEN6_WA_POST_SYNC_FLUSH) {
1090 gen6_wa_post_sync_flush(cmd);
1091 }
1092 if (pipeline->pre_pso_wa_flags & GEN7_WA_MULTISAMPLE_FLUSH) {
1093 gen6_wa_wm_multisample_flush(cmd);
1094 }
1095 if (pipeline->pre_pso_wa_flags & GEN6_WA_GEN7_VS_FLUSH) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001096 gen7_wa_vs_flush(cmd);
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001097 }
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001098
1099 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001100 assert(pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001101 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001102
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001103 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001104 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001105 }
1106 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001107 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001108 }
1109 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001110 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001111 }
1112 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001113 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001114 }
1115 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001116 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001117 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001118
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001119 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1120 gen7_3DSTATE_GS(cmd);
1121 } else {
1122 gen6_3DSTATE_GS(cmd);
1123 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001124
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001125 if (pipeline->post_pso_wa_flags & GEN6_WA_POST_SYNC_FLUSH) {
1126 gen6_wa_post_sync_flush(cmd);
1127 }
1128 if (pipeline->post_pso_wa_flags & GEN7_WA_MULTISAMPLE_FLUSH) {
1129 gen6_wa_wm_multisample_flush(cmd);
1130 }
1131 if (pipeline->post_pso_wa_flags & GEN6_WA_GEN7_VS_FLUSH) {
1132 gen7_wa_vs_flush(cmd);
1133 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001134}
1135
1136static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1137 const struct intel_pipeline *pipeline)
1138{
1139 cmd->bind.pipeline.compute = pipeline;
1140}
1141
1142static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1143 const struct intel_pipeline_delta *delta)
1144{
1145 cmd->bind.pipeline.graphics_delta = delta;
1146}
1147
1148static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1149 const struct intel_pipeline_delta *delta)
1150{
1151 cmd->bind.pipeline.compute_delta = delta;
1152}
1153
1154static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1155 const struct intel_dset *dset,
1156 XGL_UINT slot_offset)
1157{
1158 cmd->bind.dset.graphics = dset;
1159 cmd->bind.dset.graphics_offset = slot_offset;
1160}
1161
1162static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1163 const struct intel_dset *dset,
1164 XGL_UINT slot_offset)
1165{
1166 cmd->bind.dset.compute = dset;
1167 cmd->bind.dset.compute_offset = slot_offset;
1168}
1169
1170static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1171 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1172{
1173 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1174}
1175
1176static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1177 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1178{
1179 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1180}
1181
1182static void cmd_bind_index_data(struct intel_cmd *cmd,
1183 const struct intel_mem *mem,
1184 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1185{
1186 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1187 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1188 } else {
1189 cmd->bind.index.mem = mem;
1190 cmd->bind.index.offset = offset;
1191 cmd->bind.index.type = type;
1192 }
1193}
1194
1195static void cmd_bind_rt(struct intel_cmd *cmd,
1196 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1197 XGL_UINT count)
1198{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001199 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001200 XGL_UINT i;
1201
1202 for (i = 0; i < count; i++) {
1203 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1204 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001205 const struct intel_layout *layout = &rt->img->layout;
1206
1207 if (i == 0) {
1208 width = layout->width0;
1209 height = layout->height0;
1210 } else {
1211 if (width > layout->width0)
1212 width = layout->width0;
1213 if (height > layout->height0)
1214 height = layout->height0;
1215 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001216
1217 cmd->bind.att.rt[i] = rt;
1218 }
1219
1220 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001221
Chia-I Wu48c283d2014-08-25 23:13:46 +08001222 gen6_wa_post_sync_flush(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001223 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001224}
1225
1226static void cmd_bind_ds(struct intel_cmd *cmd,
1227 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1228{
1229 const struct intel_ds_view *ds;
1230
1231 if (info) {
1232 cmd->bind.att.ds = intel_ds_view(info->view);
1233 ds = cmd->bind.att.ds;
1234 } else {
1235 /* all zeros */
1236 static const struct intel_ds_view null_ds;
1237 ds = &null_ds;
1238 }
1239
Chia-I Wu48c283d2014-08-25 23:13:46 +08001240 gen6_wa_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001241 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1242 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1243 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001244
1245 if (cmd_gen(cmd) >= INTEL_GEN(7))
1246 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1247 else
1248 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001249}
1250
1251static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1252 const struct intel_viewport_state *state)
1253{
1254 cmd->bind.state.viewport = state;
1255}
1256
1257static void cmd_bind_raster_state(struct intel_cmd *cmd,
1258 const struct intel_raster_state *state)
1259{
1260 cmd->bind.state.raster = state;
1261}
1262
1263static void cmd_bind_ds_state(struct intel_cmd *cmd,
1264 const struct intel_ds_state *state)
1265{
1266 cmd->bind.state.ds = state;
1267}
1268
1269static void cmd_bind_blend_state(struct intel_cmd *cmd,
1270 const struct intel_blend_state *state)
1271{
1272 cmd->bind.state.blend = state;
1273}
1274
1275static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1276 const struct intel_msaa_state *state)
1277{
1278 cmd->bind.state.msaa = state;
1279}
1280
1281static void cmd_draw(struct intel_cmd *cmd,
1282 XGL_UINT vertex_start,
1283 XGL_UINT vertex_count,
1284 XGL_UINT instance_start,
1285 XGL_UINT instance_count,
1286 bool indexed,
1287 XGL_UINT vertex_base)
1288{
1289 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1290
1291 emit_bounded_states(cmd);
1292
1293 if (indexed) {
1294 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1295 cmd->result = XGL_ERROR_UNKNOWN;
1296
1297 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1298 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1299 p->primitive_restart_index);
1300 } else {
1301 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1302 cmd->bind.index.offset, cmd->bind.index.type,
1303 p->primitive_restart);
1304 }
1305 } else {
1306 assert(!vertex_base);
1307 }
1308
1309 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1310 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1311 vertex_start, instance_count, instance_start, vertex_base);
1312 } else {
1313 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1314 vertex_start, instance_count, instance_start, vertex_base);
1315 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001316
Chia-I Wu707a29e2014-08-27 12:51:47 +08001317 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001318 /* need to re-emit all workarounds */
1319 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001320}
1321
Chia-I Wub2755562014-08-20 13:38:52 +08001322XGL_VOID XGLAPI intelCmdBindPipeline(
1323 XGL_CMD_BUFFER cmdBuffer,
1324 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1325 XGL_PIPELINE pipeline)
1326{
1327 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1328
1329 switch (pipelineBindPoint) {
1330 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001331 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001332 break;
1333 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001334 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001335 break;
1336 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001337 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001338 break;
1339 }
1340}
1341
1342XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1343 XGL_CMD_BUFFER cmdBuffer,
1344 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1345 XGL_PIPELINE_DELTA delta)
1346{
1347 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1348
1349 switch (pipelineBindPoint) {
1350 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001351 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001352 break;
1353 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001354 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001355 break;
1356 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001357 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001358 break;
1359 }
1360}
1361
1362XGL_VOID XGLAPI intelCmdBindStateObject(
1363 XGL_CMD_BUFFER cmdBuffer,
1364 XGL_STATE_BIND_POINT stateBindPoint,
1365 XGL_STATE_OBJECT state)
1366{
1367 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1368
1369 switch (stateBindPoint) {
1370 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001371 cmd_bind_viewport_state(cmd,
1372 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001373 break;
1374 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001375 cmd_bind_raster_state(cmd,
1376 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001377 break;
1378 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001379 cmd_bind_ds_state(cmd,
1380 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001381 break;
1382 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001383 cmd_bind_blend_state(cmd,
1384 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001385 break;
1386 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001387 cmd_bind_msaa_state(cmd,
1388 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001389 break;
1390 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001391 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001392 break;
1393 }
1394}
1395
1396XGL_VOID XGLAPI intelCmdBindDescriptorSet(
1397 XGL_CMD_BUFFER cmdBuffer,
1398 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1399 XGL_UINT index,
1400 XGL_DESCRIPTOR_SET descriptorSet,
1401 XGL_UINT slotOffset)
1402{
1403 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1404 struct intel_dset *dset = intel_dset(descriptorSet);
1405
1406 assert(!index);
1407
1408 switch (pipelineBindPoint) {
1409 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001410 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001411 break;
1412 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001413 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001414 break;
1415 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001416 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001417 break;
1418 }
1419}
1420
1421XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
1422 XGL_CMD_BUFFER cmdBuffer,
1423 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1424 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
1425{
1426 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1427
1428 switch (pipelineBindPoint) {
1429 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001430 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001431 break;
1432 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001433 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08001434 break;
1435 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001436 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001437 break;
1438 }
1439}
1440
1441XGL_VOID XGLAPI intelCmdBindIndexData(
1442 XGL_CMD_BUFFER cmdBuffer,
1443 XGL_GPU_MEMORY mem_,
1444 XGL_GPU_SIZE offset,
1445 XGL_INDEX_TYPE indexType)
1446{
1447 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1448 struct intel_mem *mem = intel_mem(mem_);
1449
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001450 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08001451}
1452
1453XGL_VOID XGLAPI intelCmdBindAttachments(
1454 XGL_CMD_BUFFER cmdBuffer,
1455 XGL_UINT colorAttachmentCount,
1456 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
1457 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
1458{
1459 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08001460
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001461 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
1462 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08001463}
1464
1465XGL_VOID XGLAPI intelCmdDraw(
1466 XGL_CMD_BUFFER cmdBuffer,
1467 XGL_UINT firstVertex,
1468 XGL_UINT vertexCount,
1469 XGL_UINT firstInstance,
1470 XGL_UINT instanceCount)
1471{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001472 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001473
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001474 cmd_draw(cmd, firstVertex, vertexCount,
1475 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08001476}
1477
1478XGL_VOID XGLAPI intelCmdDrawIndexed(
1479 XGL_CMD_BUFFER cmdBuffer,
1480 XGL_UINT firstIndex,
1481 XGL_UINT indexCount,
1482 XGL_INT vertexOffset,
1483 XGL_UINT firstInstance,
1484 XGL_UINT instanceCount)
1485{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001486 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08001487
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001488 cmd_draw(cmd, firstIndex, indexCount,
1489 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08001490}
1491
1492XGL_VOID XGLAPI intelCmdDrawIndirect(
1493 XGL_CMD_BUFFER cmdBuffer,
1494 XGL_GPU_MEMORY mem,
1495 XGL_GPU_SIZE offset,
1496 XGL_UINT32 count,
1497 XGL_UINT32 stride)
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 intelCmdDrawIndexedIndirect(
1505 XGL_CMD_BUFFER cmdBuffer,
1506 XGL_GPU_MEMORY mem,
1507 XGL_GPU_SIZE offset,
1508 XGL_UINT32 count,
1509 XGL_UINT32 stride)
1510{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001511 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1512
1513 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001514}
1515
1516XGL_VOID XGLAPI intelCmdDispatch(
1517 XGL_CMD_BUFFER cmdBuffer,
1518 XGL_UINT x,
1519 XGL_UINT y,
1520 XGL_UINT z)
1521{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001522 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1523
1524 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001525}
1526
1527XGL_VOID XGLAPI intelCmdDispatchIndirect(
1528 XGL_CMD_BUFFER cmdBuffer,
1529 XGL_GPU_MEMORY mem,
1530 XGL_GPU_SIZE offset)
1531{
Chia-I Wu59c097e2014-08-21 10:51:07 +08001532 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1533
1534 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08001535}