blob: bccd4a4f999c38a23cc617d68f4a3f4aff14be68 [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 Wu254db422014-08-21 11:54:29 +0800278static inline void
279gen75_3DSTATE_VF(struct intel_cmd *cmd,
280 bool enable_cut_index,
281 uint32_t cut_index)
282{
283 const uint8_t cmd_len = 2;
284 uint32_t dw0;
285
286 CMD_ASSERT(cmd, 7.5, 7.5);
287
Chia-I Wu426072d2014-08-26 14:31:55 +0800288 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800289 if (enable_cut_index)
290 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
291
Chia-I Wue24c3292014-08-21 14:05:23 +0800292 cmd_batch_reserve(cmd, cmd_len);
293 cmd_batch_write(cmd, dw0);
294 cmd_batch_write(cmd, cut_index);
Chia-I Wu254db422014-08-21 11:54:29 +0800295}
296
Chia-I Wud88e02d2014-08-25 10:56:13 +0800297static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
298 XGL_UINT width, XGL_UINT height)
299{
300 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800301 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800302 (cmd_len - 2);
303
304 CMD_ASSERT(cmd, 6, 7.5);
305
306 cmd_batch_reserve(cmd, cmd_len);
307 cmd_batch_write(cmd, dw0);
308 if (width && height) {
309 cmd_batch_write(cmd, 0);
310 cmd_batch_write(cmd, (height - 1) << 16 |
311 (width - 1));
312 } else {
313 cmd_batch_write(cmd, 1);
314 cmd_batch_write(cmd, 0);
315 }
316 cmd_batch_write(cmd, 0);
317}
318
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800319static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
320 const struct intel_ds_view *view)
321{
322 const uint8_t cmd_len = 7;
323 uint32_t dw0;
324
325 CMD_ASSERT(cmd, 6, 7.5);
326
327 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800328 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
329 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800330 dw0 |= (cmd_len - 2);
331
Chia-I Wu2de65d02014-08-25 10:02:53 +0800332 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800333 cmd_batch_write(cmd, dw0);
334 cmd_batch_write(cmd, view->cmd[0]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600335 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800336 cmd_batch_reloc(cmd, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800337 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600338 } else {
339 cmd_batch_write(cmd, 0);
340 }
Chia-I Wue24c3292014-08-21 14:05:23 +0800341 cmd_batch_write(cmd, view->cmd[2]);
342 cmd_batch_write(cmd, view->cmd[3]);
343 cmd_batch_write(cmd, view->cmd[4]);
344 cmd_batch_write(cmd, view->cmd[5]);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800345}
346
347static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
348 const struct intel_ds_view *view)
349{
350 const uint8_t cmd_len = 3;
351 uint32_t dw0;
352
353 CMD_ASSERT(cmd, 6, 7.5);
354
355 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800356 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
357 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800358 dw0 |= (cmd_len - 2);
359
Chia-I Wu2de65d02014-08-25 10:02:53 +0800360 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800361 cmd_batch_write(cmd, dw0);
362 cmd_batch_write(cmd, view->cmd[6]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600363 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800364 cmd_batch_reloc(cmd, view->cmd[7], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800365 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600366 } else {
367 cmd_batch_write(cmd, 0);
368 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800369}
370
371static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
372 const struct intel_ds_view *view)
373{
374 const uint8_t cmd_len = 3;
375 uint32_t dw0;
376
377 CMD_ASSERT(cmd, 6, 7.5);
378
379 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800380 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
381 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800382 dw0 |= (cmd_len - 2);
383
Chia-I Wu2de65d02014-08-25 10:02:53 +0800384 cmd_batch_reserve_reloc(cmd, cmd_len, (bool) view->img);
Chia-I Wue24c3292014-08-21 14:05:23 +0800385 cmd_batch_write(cmd, dw0);
386 cmd_batch_write(cmd, view->cmd[8]);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600387 if (view->img) {
Chia-I Wu9ee38722014-08-25 12:11:36 +0800388 cmd_batch_reloc(cmd, view->cmd[9], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800389 INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600390 } else {
391 cmd_batch_write(cmd, 0);
392 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800393}
394
Chia-I Wuf8231032014-08-25 10:44:45 +0800395static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
396 uint32_t clear_val)
397{
398 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800399 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800400 GEN6_CLEAR_PARAMS_DW0_VALID |
401 (cmd_len - 2);
402
403 CMD_ASSERT(cmd, 6, 6);
404
405 cmd_batch_reserve(cmd, cmd_len);
406 cmd_batch_write(cmd, dw0);
407 cmd_batch_write(cmd, clear_val);
408}
409
410static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
411 uint32_t clear_val)
412{
413 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800414 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800415 (cmd_len - 2);
416
417 CMD_ASSERT(cmd, 7, 7.5);
418
419 cmd_batch_reserve(cmd, cmd_len);
420 cmd_batch_write(cmd, dw0);
421 cmd_batch_write(cmd, clear_val);
422 cmd_batch_write(cmd, 1);
423}
424
Chia-I Wu302742d2014-08-22 10:28:29 +0800425static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
426 XGL_UINT blend_pos,
427 XGL_UINT ds_pos,
428 XGL_UINT cc_pos)
429{
430 const uint8_t cmd_len = 4;
431 uint32_t dw0;
432
433 CMD_ASSERT(cmd, 6, 6);
434
Chia-I Wu426072d2014-08-26 14:31:55 +0800435 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800436 (cmd_len - 2);
437
438 cmd_batch_reserve(cmd, cmd_len);
439 cmd_batch_write(cmd, dw0);
440 cmd_batch_write(cmd, (blend_pos << 2) | 1);
441 cmd_batch_write(cmd, (ds_pos << 2) | 1);
442 cmd_batch_write(cmd, (cc_pos << 2) | 1);
443}
444
Chia-I Wu1744cca2014-08-22 11:10:17 +0800445static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
446 XGL_UINT clip_pos,
447 XGL_UINT sf_pos,
448 XGL_UINT cc_pos)
449{
450 const uint8_t cmd_len = 4;
451 uint32_t dw0;
452
453 CMD_ASSERT(cmd, 6, 6);
454
Chia-I Wu426072d2014-08-26 14:31:55 +0800455 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800456 GEN6_PTR_VP_DW0_CLIP_CHANGED |
457 GEN6_PTR_VP_DW0_SF_CHANGED |
458 GEN6_PTR_VP_DW0_CC_CHANGED |
459 (cmd_len - 2);
460
461 cmd_batch_reserve(cmd, cmd_len);
462 cmd_batch_write(cmd, dw0);
463 cmd_batch_write(cmd, clip_pos << 2);
464 cmd_batch_write(cmd, sf_pos << 2);
465 cmd_batch_write(cmd, cc_pos << 2);
466}
467
468static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
469 XGL_UINT scissor_pos)
470{
471 const uint8_t cmd_len = 2;
472 uint32_t dw0;
473
474 CMD_ASSERT(cmd, 6, 6);
475
Chia-I Wu426072d2014-08-26 14:31:55 +0800476 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800477 (cmd_len - 2);
478
479 cmd_batch_reserve(cmd, cmd_len);
480 cmd_batch_write(cmd, dw0);
481 cmd_batch_write(cmd, scissor_pos << 2);
482}
483
Chia-I Wu42a56202014-08-23 16:47:48 +0800484static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
485 XGL_UINT vs_pos,
486 XGL_UINT gs_pos,
487 XGL_UINT ps_pos)
488{
489 const uint8_t cmd_len = 4;
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_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800495 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
496 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
497 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
498 (cmd_len - 2);
499
500 cmd_batch_reserve(cmd, cmd_len);
501 cmd_batch_write(cmd, dw0);
502 cmd_batch_write(cmd, vs_pos << 2);
503 cmd_batch_write(cmd, gs_pos << 2);
504 cmd_batch_write(cmd, ps_pos << 2);
505}
506
Chia-I Wu302742d2014-08-22 10:28:29 +0800507static void gen7_3dstate_pointer(struct intel_cmd *cmd,
508 int subop, XGL_UINT pos)
509{
510 const uint8_t cmd_len = 2;
511 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
512 GEN6_RENDER_SUBTYPE_3D |
513 subop | (cmd_len - 2);
514
515 cmd_batch_reserve(cmd, cmd_len);
516 cmd_batch_write(cmd, dw0);
517 cmd_batch_write(cmd, pos << 2);
518}
519
520static XGL_UINT gen6_BLEND_STATE(struct intel_cmd *cmd,
521 const struct intel_blend_state *state)
522{
523 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
524 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
525
526 CMD_ASSERT(cmd, 6, 7.5);
527 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
528
529 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
530}
531
532static XGL_UINT gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
533 const struct intel_ds_state *state)
534{
535 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
536 const uint8_t cmd_len = 3;
537
538 CMD_ASSERT(cmd, 6, 7.5);
539 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
540
541 return cmd_state_copy(cmd, state->cmd, cmd_len, cmd_align);
542}
543
544static XGL_UINT gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
545 uint32_t stencil_ref,
546 const uint32_t blend_color[4])
547{
548 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
549 const uint8_t cmd_len = 6;
550 XGL_UINT pos;
551 uint32_t *dw;
552
553 CMD_ASSERT(cmd, 6, 7.5);
554
555 dw = cmd_state_reserve(cmd, cmd_len, cmd_align, &pos);
556 dw[0] = stencil_ref;
557 dw[1] = 0;
558 dw[2] = blend_color[0];
559 dw[3] = blend_color[1];
560 dw[4] = blend_color[2];
561 dw[5] = blend_color[3];
562 cmd_state_advance(cmd, cmd_len);
563
564 return pos;
565}
566
Chia-I Wu48c283d2014-08-25 23:13:46 +0800567static void gen6_wa_post_sync_flush(struct intel_cmd *cmd)
568{
Chia-I Wu707a29e2014-08-27 12:51:47 +0800569 if (!cmd->bind.draw_count)
570 return;
571
Chia-I Wu48c283d2014-08-25 23:13:46 +0800572 if (cmd->bind.wa_flags & GEN6_WA_POST_SYNC_FLUSH)
573 return;
574
575 CMD_ASSERT(cmd, 6, 7.5);
576
577 cmd->bind.wa_flags |= GEN6_WA_POST_SYNC_FLUSH;
578
579 /*
580 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
581 *
582 * "Pipe-control with CS-stall bit set must be sent BEFORE the
583 * pipe-control with a post-sync op and no write-cache flushes."
584 *
585 * The workaround below necessitates this workaround.
586 */
587 gen6_PIPE_CONTROL(cmd,
588 GEN6_PIPE_CONTROL_CS_STALL |
589 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
590 NULL, 0);
591
592 /*
593 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
594 *
595 * "Before any depth stall flush (including those produced by
596 * non-pipelined state commands), software needs to first send a
597 * PIPE_CONTROL with no bits set except Post-Sync Operation != 0."
598 *
599 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
600 * PIPE_CONTROL with any non-zero post-sync-op is required."
601 */
602 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, cmd->scratch_bo, 0);
603}
604
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -0600605static void gen6_wa_wm_multisample_flush(struct intel_cmd *cmd)
606{
Chia-I Wu9cb84ee2014-08-28 10:12:34 +0800607 if (!cmd->bind.draw_count)
608 return;
609
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -0600610 CMD_ASSERT(cmd, 6, 6);
611
612 gen6_wa_post_sync_flush(cmd);
613
614 /*
615 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
616 *
617 * "Driver must guarentee that all the caches in the depth pipe are
618 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
619 * requires driver to send a PIPE_CONTROL with a CS stall along with a
620 * Depth Flush prior to this command."
621 */
622 gen6_PIPE_CONTROL(cmd,
623 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
624 GEN6_PIPE_CONTROL_CS_STALL,
625 0, 0);
626}
627
Chia-I Wu48c283d2014-08-25 23:13:46 +0800628static void gen6_wa_ds_flush(struct intel_cmd *cmd)
629{
Chia-I Wu707a29e2014-08-27 12:51:47 +0800630 if (!cmd->bind.draw_count)
631 return;
632
Chia-I Wu48c283d2014-08-25 23:13:46 +0800633 CMD_ASSERT(cmd, 6, 7.5);
634
Chia-I Wu48c283d2014-08-25 23:13:46 +0800635 gen6_wa_post_sync_flush(cmd);
636
637 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
638 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0);
639 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0);
640}
641
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800642static void gen7_wa_vs_flush(struct intel_cmd *cmd)
643{
644 if (!cmd->bind.draw_count)
645 return;
646
647 if (cmd->bind.wa_flags & GEN6_WA_GEN7_VS_FLUSH)
648 return;
649
650 CMD_ASSERT(cmd, 7, 7.5);
651
652 cmd->bind.wa_flags |= GEN6_WA_GEN7_VS_FLUSH;
653
654 gen6_PIPE_CONTROL(cmd,
655 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
656 cmd->scratch_bo, 0);
657}
658
Chia-I Wu525c6602014-08-27 10:22:34 +0800659void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
660{
661 if (!cmd->bind.draw_count)
662 return;
663
664 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
665
666 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
667 gen6_wa_post_sync_flush(cmd);
668
669 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0);
670}
671
Chia-I Wu302742d2014-08-22 10:28:29 +0800672static void gen6_cc_states(struct intel_cmd *cmd)
673{
674 const struct intel_blend_state *blend = cmd->bind.state.blend;
675 const struct intel_ds_state *ds = cmd->bind.state.ds;
676 XGL_UINT blend_pos, ds_pos, cc_pos;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800677 uint32_t stencil_ref;
678 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800679
680 CMD_ASSERT(cmd, 6, 6);
681
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800682 if (blend) {
683 blend_pos = gen6_BLEND_STATE(cmd, blend);
684 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
685 } else {
686 blend_pos = 0;
687 memset(blend_color, 0, sizeof(blend_color));
688 }
689
690 if (ds) {
691 ds_pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
692 stencil_ref = ds->cmd_stencil_ref;
693 } else {
694 ds_pos = 0;
695 stencil_ref = 0;
696 }
697
698 cc_pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800699
700 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_pos, ds_pos, cc_pos);
701}
702
Chia-I Wu1744cca2014-08-22 11:10:17 +0800703static void gen6_viewport_states(struct intel_cmd *cmd)
704{
705 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
706 XGL_UINT pos;
707
708 if (!viewport)
709 return;
710
711 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
712 viewport->cmd_align);
713
714 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
715 pos + viewport->cmd_clip_offset,
716 pos,
717 pos + viewport->cmd_cc_offset);
718
719 pos = (viewport->scissor_enable) ?
720 pos + viewport->cmd_scissor_rect_offset : 0;
721
722 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, pos);
723}
724
Chia-I Wu302742d2014-08-22 10:28:29 +0800725static void gen7_cc_states(struct intel_cmd *cmd)
726{
727 const struct intel_blend_state *blend = cmd->bind.state.blend;
728 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800729 uint32_t stencil_ref;
730 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +0800731 XGL_UINT pos;
732
733 CMD_ASSERT(cmd, 7, 7.5);
734
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800735 if (!blend && !ds)
736 return;
Chia-I Wu302742d2014-08-22 10:28:29 +0800737
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800738 if (blend) {
739 pos = gen6_BLEND_STATE(cmd, blend);
740 gen7_3dstate_pointer(cmd,
741 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, pos);
Chia-I Wu302742d2014-08-22 10:28:29 +0800742
Chia-I Wuce9f11f2014-08-22 10:38:51 +0800743 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
744 } else {
745 memset(blend_color, 0, sizeof(blend_color));
746 }
747
748 if (ds) {
749 pos = gen6_DEPTH_STENCIL_STATE(cmd, ds);
750 gen7_3dstate_pointer(cmd,
751 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS, pos);
752 } else {
753 stencil_ref = 0;
754 }
755
756 pos = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +0800757 gen7_3dstate_pointer(cmd,
758 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, pos);
759}
760
Chia-I Wu1744cca2014-08-22 11:10:17 +0800761static void gen7_viewport_states(struct intel_cmd *cmd)
762{
763 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
764 XGL_UINT pos;
765
766 if (!viewport)
767 return;
768
769 pos = cmd_state_copy(cmd, viewport->cmd, viewport->cmd_len,
770 viewport->cmd_align);
771
772 gen7_3dstate_pointer(cmd,
773 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, pos);
774 gen7_3dstate_pointer(cmd,
775 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
776 pos + viewport->cmd_cc_offset);
777 if (viewport->scissor_enable) {
778 gen7_3dstate_pointer(cmd,
779 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
780 pos + viewport->cmd_scissor_rect_offset);
781 }
782}
783
Chia-I Wu7fd5cac2014-08-27 13:19:29 +0800784static void gen6_pcb(struct intel_cmd *cmd, int subop,
785 const XGL_PIPELINE_SHADER *sh)
786{
787 const uint8_t cmd_len = 5;
788 const XGL_UINT alignment = 32;
789 const XGL_UINT max_size =
790 (subop == GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS) ? 1024 : 2048;
791 const XGL_UINT max_pcb = 4;
792 uint32_t pcb[4] = { 0, 0, 0, 0 };
793 XGL_FLAGS pcb_enables = 0;
794 XGL_SIZE total_size = 0;
795 uint32_t dw0;
796 XGL_UINT i;
797
798 for (i = 0; i < sh->linkConstBufferCount; i++) {
799 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
800 const XGL_SIZE size = u_align(info->bufferSize, alignment);
801 void *ptr;
802
803 if (info->bufferId >= max_pcb ||
804 pcb_enables & ((1 << info->bufferId)) ||
805 total_size + info->bufferSize > max_size) {
806 cmd->result = XGL_ERROR_UNKNOWN;
807 return;
808 }
809 if (!size)
810 continue;
811
812 pcb_enables |= 1 << info->bufferId;
813 total_size += size;
814
815 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
816 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
817 memcpy(ptr, info->pBufferData, info->bufferSize);
818 cmd_state_advance(cmd, size / sizeof(uint32_t));
819
820 pcb[info->bufferId] |= size / alignment - 1;
821 }
822
823 dw0 = GEN6_RENDER_TYPE_RENDER |
824 GEN6_RENDER_SUBTYPE_3D |
825 subop |
826 pcb_enables << 12 |
827 (cmd_len - 2);
828
829 cmd_batch_reserve(cmd, cmd_len);
830 cmd_batch_write(cmd, dw0);
831 cmd_batch_write(cmd, pcb[0]);
832 cmd_batch_write(cmd, pcb[1]);
833 cmd_batch_write(cmd, pcb[2]);
834 cmd_batch_write(cmd, pcb[3]);
835}
836
837static void gen7_pcb(struct intel_cmd *cmd, int subop,
838 const XGL_PIPELINE_SHADER *sh)
839{
840 const uint8_t cmd_len = 7;
841 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
842 GEN6_RENDER_SUBTYPE_3D |
843 subop |
844 (cmd_len - 2);
845 const XGL_UINT alignment = 32;
846 const XGL_UINT max_size = 2048;
847 const XGL_UINT max_pcb = 4;
848 uint16_t pcb_len[4] = { 0, 0, 0, 0 };
849 uint32_t pcb[4] = { 0, 0, 0, 0 };
850 XGL_FLAGS pcb_enables = 0;
851 XGL_SIZE total_size = 0;
852 XGL_UINT i;
853
854 for (i = 0; i < sh->linkConstBufferCount; i++) {
855 const XGL_LINK_CONST_BUFFER *info = &sh->pLinkConstBufferInfo[i];
856 const XGL_SIZE size = u_align(info->bufferSize, alignment);
857 void *ptr;
858
859 if (info->bufferId >= max_pcb ||
860 pcb_enables & ((1 << info->bufferId)) ||
861 total_size + info->bufferSize > max_size) {
862 cmd->result = XGL_ERROR_UNKNOWN;
863 return;
864 }
865 if (!size)
866 continue;
867
868 pcb_enables |= 1 << info->bufferId;
869 total_size += size;
870
871 pcb_len[info->bufferId] = size / alignment;
872
873 ptr = cmd_state_reserve(cmd, size / sizeof(uint32_t),
874 alignment / sizeof(uint32_t), &pcb[info->bufferId]);
875 memcpy(ptr, info->pBufferData, info->bufferSize);
876 cmd_state_advance(cmd, size / sizeof(uint32_t));
877 }
878
879 /* no holes */
880 if (!u_is_pow2(pcb_enables + 1)) {
881 cmd->result = XGL_ERROR_UNKNOWN;
882 return;
883 }
884
885 cmd_batch_reserve(cmd, cmd_len);
886 cmd_batch_write(cmd, dw0);
887 cmd_batch_write(cmd, pcb_len[1] << 16 | pcb_len[0]);
888 cmd_batch_write(cmd, pcb_len[3] << 16 | pcb_len[2]);
889 cmd_batch_write(cmd, pcb[0]);
890 cmd_batch_write(cmd, pcb[1]);
891 cmd_batch_write(cmd, pcb[2]);
892 cmd_batch_write(cmd, pcb[3]);
893}
894
Chia-I Wu42a56202014-08-23 16:47:48 +0800895static void emit_ps_resources(struct intel_cmd *cmd,
896 const struct intel_rmap *rmap)
897{
898 const XGL_UINT surface_count = rmap->rt_count +
899 rmap->resource_count + rmap->uav_count;
900 uint32_t binding_table[256];
901 XGL_UINT pos, i;
902
903 assert(surface_count <= ARRAY_SIZE(binding_table));
904
905 for (i = 0; i < surface_count; i++) {
906 const struct intel_rmap_slot *slot = &rmap->slots[i];
907 uint32_t *dw;
908
909 switch (slot->path_len) {
910 case 0:
911 pos = 0;
912 break;
913 case INTEL_RMAP_SLOT_RT:
914 {
915 const struct intel_rt_view *view = cmd->bind.att.rt[i];
916
917 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
918 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
919
920 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800921 cmd_state_reloc(cmd, 1, view->cmd[1], view->img->obj.mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800922 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +0800923 cmd_state_advance(cmd, view->cmd_len);
924 }
925 break;
926 case INTEL_RMAP_SLOT_DYN:
927 {
928 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800929 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +0800930
931 dw = cmd_state_reserve_reloc(cmd, view->cmd_len, 1,
932 GEN6_ALIGNMENT_SURFACE_STATE, &pos);
933
934 memcpy(dw, view->cmd, sizeof(uint32_t) * view->cmd_len);
Chia-I Wubda55fd2014-08-25 12:46:10 +0800935 cmd_state_reloc(cmd, 1, view->cmd[1], view->mem->bo,
Chia-I Wu32a22462014-08-26 14:13:46 +0800936 INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +0800937 cmd_state_advance(cmd, view->cmd_len);
938 }
939 break;
940 case 1:
941 default:
942 /* TODO */
943 assert(!"no dset support");
944 break;
945 }
946
947 binding_table[i] = pos << 2;
948 }
949
950 pos = cmd_state_copy(cmd, binding_table, surface_count,
951 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
952
953 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
954 gen7_3dstate_pointer(cmd,
955 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, pos);
956 } else {
957 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, pos);
958 }
959}
960
Chia-I Wu52500102014-08-22 00:46:04 +0800961static void emit_bounded_states(struct intel_cmd *cmd)
962{
963 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
964
965 /* TODO more states */
966
Chia-I Wu1744cca2014-08-22 11:10:17 +0800967 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +0800968 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800969 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +0800970
971 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
972 &cmd->bind.pipeline.graphics->vs);
973 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
974 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800975 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +0800976 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800977 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +0800978
979 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
980 &cmd->bind.pipeline.graphics->vs);
981 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
982 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1744cca2014-08-22 11:10:17 +0800983 }
Chia-I Wu302742d2014-08-22 10:28:29 +0800984
Chia-I Wu42a56202014-08-23 16:47:48 +0800985 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs_rmap);
986
Chia-I Wu48c283d2014-08-25 23:13:46 +0800987 gen6_wa_post_sync_flush(cmd);
Chia-I Wu9cb84ee2014-08-28 10:12:34 +0800988 /* need multisample flush on gen6 */
989 if (cmd_gen(cmd) == INTEL_GEN(6))
990 gen6_wa_wm_multisample_flush(cmd);
991 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu52500102014-08-22 00:46:04 +0800992 cmd_batch_reserve(cmd, msaa->cmd_len);
993 cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600994}
995
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -0600996static void
997gen7_emit_3DSTATE_GS(struct intel_cmd *cmd)
998{
999 const uint8_t cmd_len = 7;
1000 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
1001 const struct intel_shader_cso *cso;
1002 uint32_t dw2, dw4, dw5;
1003
1004 CMD_ASSERT(cmd, 7, 7);
1005
1006 if (cmd->bind.gs.shader == NULL) {
1007 cmd_batch_reserve(cmd, cmd_len);
1008 cmd_batch_write(cmd, dw0);
1009 cmd_batch_write(cmd, 0);
1010 cmd_batch_write(cmd, 0);
1011 cmd_batch_write(cmd, 0);
1012 cmd_batch_write(cmd, 0);
1013 cmd_batch_write(cmd, GEN6_GS_DW5_STATISTICS);
1014 cmd_batch_write(cmd, 0);
1015 return;
1016 }
1017
1018 cso = &cmd->bind.gs.shader->cso;
1019 dw2 = cso->payload[0];
1020 dw4 = cso->payload[1];
1021 dw5 = cso->payload[2];
1022
1023 // TODO: This should come from genhw.h
1024# define GEN6_GS_SAMPLER_COUNT_SHIFT 27
1025 dw2 |= ((cmd->bind.gs.shader->num_samplers + 3) / 4) << GEN6_GS_SAMPLER_COUNT_SHIFT;
1026
1027 cmd_batch_reserve(cmd, cmd_len);
1028 cmd_batch_write(cmd, dw0);
1029 cmd_batch_write(cmd, cmd->bind.gs.kernel_pos);
1030 cmd_batch_write(cmd, dw2);
1031 cmd_batch_write(cmd, 0); /* scratch */
1032 cmd_batch_write(cmd, dw4);
1033 cmd_batch_write(cmd, dw5);
1034 cmd_batch_write(cmd, 0);
1035}
1036
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001037static void emit_shader(struct intel_cmd *cmd,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001038 const struct intel_pipe_shader *shader,
1039 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001040{
1041 uint32_t i;
1042 struct intel_cmd_shader *cmdShader;
1043
1044 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001045 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001046 /* shader is already part of pipeline */
1047 return;
1048 }
1049 }
1050
Chia-I Wu338fe642014-08-28 10:43:04 +08001051 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1052 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1053
1054 cmdShader = cmd->bind.shaderCache.shaderArray;
1055
1056 cmd->bind.shaderCache.shaderArray =
1057 icd_alloc(sizeof(*cmdShader) * new_count,
1058 0, XGL_SYSTEM_ALLOC_INTERNAL);
1059 if (cmd->bind.shaderCache.shaderArray == NULL) {
1060 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001061 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1062 return;
1063 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001064
1065 if (cmdShader) {
1066 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1067 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1068 icd_free(cmdShader);
1069 }
1070
1071 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001072 }
1073
Chia-I Wu338fe642014-08-28 10:43:04 +08001074 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001075 cmdShader->shader = shader;
1076 cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001077 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001078 cmd->bind.shaderCache.used++;
1079 return;
1080}
1081
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001082static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001083 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001084{
1085 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001086
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001087 // TODO: This probably isn't quite what we want.
1088 // While this does reflect the call that was made, it would be
1089 // more appropriate to indicate the behavior, ie. CS_STALL, WRITE_IMM
1090 // and then issue the minimum number of pipe_control commands
1091 // This sequence could do some duplicate work though we have
1092 // WA_POST_SYNC_FLUSH first to try to minimize that.
1093 if (pipeline->pre_pso_wa_flags & GEN6_WA_POST_SYNC_FLUSH) {
1094 gen6_wa_post_sync_flush(cmd);
1095 }
1096 if (pipeline->pre_pso_wa_flags & GEN7_WA_MULTISAMPLE_FLUSH) {
1097 gen6_wa_wm_multisample_flush(cmd);
1098 }
1099 if (pipeline->pre_pso_wa_flags & GEN6_WA_GEN7_VS_FLUSH) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001100 gen7_wa_vs_flush(cmd);
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001101 }
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001102
1103 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001104 assert(pipeline->cmd_len);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001105 cmd_batch_write_n(cmd, pipeline->cmds, pipeline->cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001106
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001107 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001108 emit_shader(cmd, &pipeline->intel_vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001109 }
1110 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001111 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001112 }
1113 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001114 emit_shader(cmd, &pipeline->intel_fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001115 }
1116 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001117 emit_shader(cmd, &pipeline->tess_control, &cmd->bind.tess_control);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001118 }
1119 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001120 emit_shader(cmd, &pipeline->tess_eval, &cmd->bind.tess_eval);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001121 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001122
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001123 gen7_emit_3DSTATE_GS(cmd);
1124
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}