blob: b20ba29b8b6c181ca89606cecb2ee30417206880 [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.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080030#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080031#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080032#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080033#include "pipeline.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080034#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080035#include "state.h"
36#include "view.h"
37#include "cmd_priv.h"
38
Chia-I Wu59c097e2014-08-21 10:51:07 +080039static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080040 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080041 uint32_t vertex_count,
42 uint32_t vertex_start,
43 uint32_t instance_count,
44 uint32_t instance_start,
45 uint32_t vertex_base)
46{
47 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080048 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080049
50 CMD_ASSERT(cmd, 6, 6);
51
Chia-I Wu426072d2014-08-26 14:31:55 +080052 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080053 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080054 (cmd_len - 2);
55
56 if (indexed)
57 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
58
Chia-I Wu72292b72014-09-09 10:48:33 +080059 cmd_batch_pointer(cmd, cmd_len, &dw);
60 dw[0] = dw0;
61 dw[1] = vertex_count;
62 dw[2] = vertex_start;
63 dw[3] = instance_count;
64 dw[4] = instance_start;
65 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080066}
67
68static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080069 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080070 uint32_t vertex_count,
71 uint32_t vertex_start,
72 uint32_t instance_count,
73 uint32_t instance_start,
74 uint32_t vertex_base)
75{
76 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080077 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080078
79 CMD_ASSERT(cmd, 7, 7.5);
80
Chia-I Wu426072d2014-08-26 14:31:55 +080081 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080082 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080083
84 if (indexed)
85 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
86
Chia-I Wu72292b72014-09-09 10:48:33 +080087 cmd_batch_pointer(cmd, cmd_len, &dw);
88 dw[0] = dw0;
89 dw[1] = dw1;
90 dw[2] = vertex_count;
91 dw[3] = vertex_start;
92 dw[4] = instance_count;
93 dw[5] = instance_start;
94 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080095}
96
Chia-I Wu270b1e82014-08-25 15:53:39 +080097static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +080098 struct intel_bo *bo, uint32_t bo_offset,
99 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100{
101 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800102 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800104 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800105 uint32_t *dw;
106 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800107
108 CMD_ASSERT(cmd, 6, 7.5);
109
110 assert(bo_offset % 8 == 0);
111
112 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
113 /*
114 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
115 *
116 * "1 of the following must also be set (when CS stall is set):
117 *
118 * * Depth Cache Flush Enable ([0] of DW1)
119 * * Stall at Pixel Scoreboard ([1] of DW1)
120 * * Depth Stall ([13] of DW1)
121 * * Post-Sync Operation ([13] of DW1)
122 * * Render Target Cache Flush Enable ([12] of DW1)
123 * * Notify Enable ([8] of DW1)"
124 *
125 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
126 *
127 * "One of the following must also be set (when CS stall is set):
128 *
129 * * Render Target Cache Flush Enable ([12] of DW1)
130 * * Depth Cache Flush Enable ([0] of DW1)
131 * * Stall at Pixel Scoreboard ([1] of DW1)
132 * * Depth Stall ([13] of DW1)
133 * * Post-Sync Operation ([13] of DW1)"
134 */
135 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
136 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
137 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
138 GEN6_PIPE_CONTROL_DEPTH_STALL;
139
140 /* post-sync op */
141 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
142 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
143 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
144
145 if (cmd_gen(cmd) == INTEL_GEN(6))
146 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
147
148 assert(dw1 & bit_test);
149 }
150
151 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
152 /*
153 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
154 *
155 * "Following bits must be clear (when Depth Stall is set):
156 *
157 * * Render Target Cache Flush Enable ([12] of DW1)
158 * * Depth Cache Flush Enable ([0] of DW1)"
159 */
160 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
161 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
162 }
163
164 /*
165 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
166 *
167 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
168 * and PIPE_CONTROL are not supported."
169 *
170 * The kernel will add the mapping automatically (when write domain is
171 * INTEL_DOMAIN_INSTRUCTION).
172 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800173 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800174 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800175 reloc_flags |= INTEL_RELOC_GGTT;
176 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177
Chia-I Wu72292b72014-09-09 10:48:33 +0800178 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
179 dw[0] = dw0;
180 dw[1] = dw1;
181 dw[2] = 0;
182 dw[3] = (uint32_t) imm;
183 dw[4] = (uint32_t) (imm >> 32);
184
185 if (bo) {
186 cmd_reserve_reloc(cmd, 1);
187 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
188 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800189}
190
Chia-I Wu254db422014-08-21 11:54:29 +0800191static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
192{
193 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
194 bool supported;
195
196 CMD_ASSERT(cmd, 6, 7.5);
197
198 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
199 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
200
201 switch (p->prim_type) {
202 case GEN6_3DPRIM_POINTLIST:
203 case GEN6_3DPRIM_LINELIST:
204 case GEN6_3DPRIM_LINESTRIP:
205 case GEN6_3DPRIM_TRILIST:
206 case GEN6_3DPRIM_TRISTRIP:
207 supported = true;
208 break;
209 default:
210 supported = false;
211 break;
212 }
213
214 if (!supported)
215 return false;
216
217 switch (cmd->bind.index.type) {
218 case XGL_INDEX_8:
219 supported = (p->primitive_restart_index != 0xffu);
220 break;
221 case XGL_INDEX_16:
222 supported = (p->primitive_restart_index != 0xffffu);
223 break;
224 case XGL_INDEX_32:
225 supported = (p->primitive_restart_index != 0xffffffffu);
226 break;
227 default:
228 supported = false;
229 break;
230 }
231
232 return supported;
233}
234
Chia-I Wu59c097e2014-08-21 10:51:07 +0800235static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800236 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800237 XGL_GPU_SIZE offset,
238 XGL_INDEX_TYPE type,
239 bool enable_cut_index)
240{
241 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800242 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800243 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800244 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245
246 CMD_ASSERT(cmd, 6, 7.5);
247
Chia-I Wu426072d2014-08-26 14:31:55 +0800248 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800249
250 /* the bit is moved to 3DSTATE_VF */
251 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
252 assert(!enable_cut_index);
253 if (enable_cut_index)
254 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
255
256 switch (type) {
257 case XGL_INDEX_8:
258 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
259 offset_align = 1;
260 break;
261 case XGL_INDEX_16:
262 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
263 offset_align = 2;
264 break;
265 case XGL_INDEX_32:
266 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
267 offset_align = 4;
268 break;
269 default:
270 cmd->result = XGL_ERROR_INVALID_VALUE;
271 return;
272 break;
273 }
274
275 if (offset % offset_align) {
276 cmd->result = XGL_ERROR_INVALID_VALUE;
277 return;
278 }
279
280 /* aligned and inclusive */
281 end_offset = mem->size - (mem->size % offset_align) - 1;
282
Chia-I Wu72292b72014-09-09 10:48:33 +0800283 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
284 dw[0] = dw0;
285
286 cmd_reserve_reloc(cmd, 2);
287 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
288 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800289}
290
Chia-I Wu62a7f252014-08-29 11:31:16 +0800291static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
292 bool enable_cut_index,
293 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800294{
295 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800296 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800297
298 CMD_ASSERT(cmd, 7.5, 7.5);
299
Chia-I Wu426072d2014-08-26 14:31:55 +0800300 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800301 if (enable_cut_index)
302 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
303
Chia-I Wu72292b72014-09-09 10:48:33 +0800304 cmd_batch_pointer(cmd, cmd_len, &dw);
305 dw[0] = dw0;
306 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800307}
308
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600309
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800310static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
311{
312 const uint8_t cmd_len = 7;
313 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800314 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800315
316 CMD_ASSERT(cmd, 6, 6);
317
318 assert(cmd->bind.gs.shader == NULL);
319
Chia-I Wu72292b72014-09-09 10:48:33 +0800320 cmd_batch_pointer(cmd, cmd_len, &dw);
321 dw[0] = dw0;
322 dw[1] = 0;
323 dw[2] = 0;
324 dw[3] = 0;
325 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
326 dw[5] = GEN6_GS_DW5_STATISTICS;
327 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800328}
329
Chia-I Wu62a7f252014-08-29 11:31:16 +0800330static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
331{
332 const uint8_t cmd_len = 7;
333 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800334 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800335
336 CMD_ASSERT(cmd, 7, 7.5);
337
338 assert(cmd->bind.gs.shader == NULL);
339
Chia-I Wu72292b72014-09-09 10:48:33 +0800340 cmd_batch_pointer(cmd, cmd_len, &dw);
341 dw[0] = dw0;
342 dw[1] = 0;
343 dw[2] = 0;
344 dw[3] = 0;
345 dw[4] = 0;
346 dw[5] = GEN6_GS_DW5_STATISTICS;
347 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800348}
349
Chia-I Wud88e02d2014-08-25 10:56:13 +0800350static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
351 XGL_UINT width, XGL_UINT height)
352{
353 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800354 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800355 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800356 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800357
358 CMD_ASSERT(cmd, 6, 7.5);
359
Chia-I Wu72292b72014-09-09 10:48:33 +0800360 cmd_batch_pointer(cmd, cmd_len, &dw);
361 dw[0] = dw0;
362
Chia-I Wud88e02d2014-08-25 10:56:13 +0800363 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800364 dw[1] = 0;
365 dw[2] = (height - 1) << 16 |
366 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800367 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800368 dw[1] = 1;
369 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800370 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800371
372 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800373}
374
Chia-I Wu8016a172014-08-29 18:31:32 +0800375static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
376 uint32_t body[6])
377{
378 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
379 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
380 const struct intel_raster_state *raster = cmd->bind.state.raster;
381 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
382 uint32_t dw1, dw2, dw3;
383 int point_width;
384
385 CMD_ASSERT(cmd, 6, 7.5);
386
387 dw1 = GEN7_SF_DW1_STATISTICS |
388 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
389 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
390 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
391 GEN7_SF_DW1_VIEWPORT_ENABLE |
392 raster->cmd_sf_fill;
393
394 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
395 int format;
396
397 switch (pipeline->db_format.channelFormat) {
398 case XGL_CH_FMT_R16:
399 format = GEN6_ZFORMAT_D16_UNORM;
400 break;
401 case XGL_CH_FMT_R32:
402 case XGL_CH_FMT_R32G8:
403 format = GEN6_ZFORMAT_D32_FLOAT;
404 break;
405 default:
406 assert(!"unknown depth format");
407 format = 0;
408 break;
409 }
410
411 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
412 }
413
414 dw2 = raster->cmd_sf_cull;
415
416 if (msaa->sample_count > 1) {
417 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
419 } else {
420 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
421 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
422 }
423
424 if (viewport->scissor_enable)
425 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
426
427 /* in U8.3 */
428 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
429 point_width = U_CLAMP(point_width, 1, 2047);
430
431 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
432 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
433 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
434 GEN7_SF_DW3_SUBPIXEL_8BITS |
435 GEN7_SF_DW3_USE_POINT_WIDTH |
436 point_width;
437
438 body[0] = dw1;
439 body[1] = dw2;
440 body[2] = dw3;
441 body[3] = raster->cmd_depth_offset_const;
442 body[4] = raster->cmd_depth_offset_scale;
443 body[5] = raster->cmd_depth_offset_clamp;
444}
445
446static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
447 uint32_t body[13])
448{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800449 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
450 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800451 XGL_UINT attr_skip, attr_count;
452 XGL_UINT vue_offset, vue_len;
453 XGL_UINT i;
454 uint32_t dw1;
455
456 CMD_ASSERT(cmd, 6, 7.5);
457
458 /* VS outputs VUE header and position additionally */
459 assert(vs->out_count >= 2);
460 attr_skip = 2;
461 attr_count = vs->out_count - attr_skip;
462 assert(fs->in_count == attr_count);
463 assert(fs->in_count <= 32);
464
465 vue_offset = attr_skip / 2;
466 vue_len = (attr_count + 1) / 2;
467 if (!vue_len)
468 vue_len = 1;
469
470 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
471 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
472 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
473
474 body[0] = dw1;
475
476 for (i = 0; i < 8; i++) {
477 uint16_t hi, lo;
478
479 /* no attr swizzles */
480 if (i * 2 + 1 < fs->in_count) {
481 hi = i * 2 + 1;
482 lo = i * 2;
483 } else if (i * 2 < fs->in_count) {
484 hi = 0;
485 lo = i * 2;
486 } else {
487 hi = 0;
488 lo = 0;
489 }
490
491 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
492 }
493
494 body[9] = 0; /* point sprite enables */
495 body[10] = 0; /* constant interpolation enables */
496 body[11] = 0; /* WrapShortest enables */
497 body[12] = 0;
498}
499
500static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
501{
502 const uint8_t cmd_len = 20;
503 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
504 (cmd_len - 2);
505 uint32_t sf[6];
506 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800507 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800508
509 CMD_ASSERT(cmd, 6, 6);
510
511 gen7_fill_3DSTATE_SF_body(cmd, sf);
512 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
513
Chia-I Wu72292b72014-09-09 10:48:33 +0800514 cmd_batch_pointer(cmd, cmd_len, &dw);
515 dw[0] = dw0;
516 dw[1] = sbe[0];
517 memcpy(&dw[2], sf, sizeof(sf));
518 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800519}
520
521static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
522{
523 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800524 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800525
526 CMD_ASSERT(cmd, 7, 7.5);
527
Chia-I Wu72292b72014-09-09 10:48:33 +0800528 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800529 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
530 (cmd_len - 2);
531 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800532}
533
534static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
535{
536 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800537 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800538
539 CMD_ASSERT(cmd, 7, 7.5);
540
Chia-I Wu72292b72014-09-09 10:48:33 +0800541 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800542 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
543 (cmd_len - 2);
544 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800545}
546
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800547static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
548{
549 const uint8_t cmd_len = 4;
550 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
551 (cmd_len - 2);
552 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800553 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800554 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
555 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800556 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800557
558 CMD_ASSERT(cmd, 6, 7.5);
559
560 dw1 = GEN6_CLIP_DW1_STATISTICS;
561 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
562 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
563 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
564 raster->cmd_clip_cull;
565 }
566
567 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
568 GEN6_CLIP_DW2_XY_TEST_ENABLE |
569 GEN6_CLIP_DW2_APIMODE_OGL |
570 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
571 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
572 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
573
574 if (pipeline->rasterizerDiscardEnable)
575 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
576 else
577 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
578
579 if (pipeline->depthClipEnable)
580 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
581
582 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
583 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
584 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
585 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
586
587 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
588 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
589 (viewport->viewport_count - 1);
590
Chia-I Wu72292b72014-09-09 10:48:33 +0800591 cmd_batch_pointer(cmd, cmd_len, &dw);
592 dw[0] = dw0;
593 dw[1] = dw1;
594 dw[2] = dw2;
595 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800596}
597
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800598static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
599{
600 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
601 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800602 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800603 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
604 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800605 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800606
607 CMD_ASSERT(cmd, 6, 6);
608
609 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
610
611 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
612 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
613
614 dw4 = GEN6_WM_DW4_STATISTICS |
615 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
616 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
617 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
618
619 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
620 GEN6_WM_DW5_PS_ENABLE |
621 GEN6_WM_DW5_8_PIXEL_DISPATCH;
622
623 if (fs->uses & INTEL_SHADER_USE_KILL ||
624 pipeline->cb_state.alphaToCoverageEnable)
625 dw5 |= GEN6_WM_DW5_PS_KILL;
626
627 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
628 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
629 if (fs->uses & INTEL_SHADER_USE_DEPTH)
630 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
631 if (fs->uses & INTEL_SHADER_USE_W)
632 dw5 |= GEN6_WM_DW5_PS_USE_W;
633
634 if (pipeline->cb_state.dualSourceBlendEnable)
635 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
636
637 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
638 GEN6_WM_DW6_POSOFFSET_NONE |
639 GEN6_WM_DW6_ZW_INTERP_PIXEL |
640 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
641 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
642
643 if (msaa->sample_count > 1) {
644 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
645 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
646 } else {
647 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
648 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
649 }
650
Chia-I Wu72292b72014-09-09 10:48:33 +0800651 cmd_batch_pointer(cmd, cmd_len, &dw);
652 dw[0] = dw0;
653 dw[1] = cmd->bind.fs.kernel_offset;
654 dw[2] = dw2;
655 dw[3] = 0; /* scratch */
656 dw[4] = dw4;
657 dw[5] = dw5;
658 dw[6] = dw6;
659 dw[7] = 0; /* kernel 1 */
660 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800661}
662
663static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
664{
665 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800666 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
668 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800669 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800670
671 CMD_ASSERT(cmd, 7, 7.5);
672
673 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
674
675 dw1 = GEN7_WM_DW1_STATISTICS |
676 GEN7_WM_DW1_PS_ENABLE |
677 GEN7_WM_DW1_ZW_INTERP_PIXEL |
678 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
679 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
680
681 if (fs->uses & INTEL_SHADER_USE_KILL ||
682 pipeline->cb_state.alphaToCoverageEnable)
683 dw1 |= GEN7_WM_DW1_PS_KILL;
684
685 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
686 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
687 if (fs->uses & INTEL_SHADER_USE_DEPTH)
688 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
689 if (fs->uses & INTEL_SHADER_USE_W)
690 dw1 |= GEN7_WM_DW1_PS_USE_W;
691
692 dw2 = 0;
693
694 if (msaa->sample_count > 1) {
695 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
696 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
697 } else {
698 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
699 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
700 }
701
Chia-I Wu72292b72014-09-09 10:48:33 +0800702 cmd_batch_pointer(cmd, cmd_len, &dw);
703 dw[0] = dw0;
704 dw[1] = dw1;
705 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800706}
707
708static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
709{
710 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800711 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800712 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
713 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800714 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800715
716 CMD_ASSERT(cmd, 7, 7.5);
717
718 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
719
720 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
721 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
722
723 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
724 GEN7_PS_DW4_8_PIXEL_DISPATCH;
725
726 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
727 const int max_threads =
728 (cmd->dev->gpu->gt == 3) ? 408 :
729 (cmd->dev->gpu->gt == 2) ? 204 : 102;
730 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
731 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
732 } else {
733 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
734 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
735 }
736
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800737 if (fs->pcb_size)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800738 dw4 |= GEN7_PS_DW4_PUSH_CONSTANT_ENABLE;
739
740 if (fs->in_count)
741 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
742
743 if (pipeline->cb_state.dualSourceBlendEnable)
744 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
745
746 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
747 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
748 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
749
Chia-I Wu72292b72014-09-09 10:48:33 +0800750 cmd_batch_pointer(cmd, cmd_len, &dw);
751 dw[0] = dw0;
752 dw[1] = cmd->bind.fs.kernel_offset;
753 dw[2] = dw2;
754 dw[3] = 0; /* scratch */
755 dw[4] = dw4;
756 dw[5] = dw5;
757 dw[6] = 0; /* kernel 1 */
758 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800759}
760
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800761static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
762 const struct intel_ds_view *view)
763{
764 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800765 uint32_t dw0, *dw;
766 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767
768 CMD_ASSERT(cmd, 6, 7.5);
769
770 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800771 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
772 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800773 dw0 |= (cmd_len - 2);
774
Chia-I Wu72292b72014-09-09 10:48:33 +0800775 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
776 dw[0] = dw0;
777 dw[1] = view->cmd[0];
778 dw[2] = 0;
779 dw[3] = view->cmd[2];
780 dw[4] = view->cmd[3];
781 dw[5] = view->cmd[4];
782 dw[6] = view->cmd[5];
783
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600784 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 cmd_reserve_reloc(cmd, 1);
786 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
787 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600788 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800789}
790
791static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
792 const struct intel_ds_view *view)
793{
794 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800795 uint32_t dw0, *dw;
796 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797
798 CMD_ASSERT(cmd, 6, 7.5);
799
800 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800801 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
802 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800803 dw0 |= (cmd_len - 2);
804
Chia-I Wu72292b72014-09-09 10:48:33 +0800805 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
806 dw[0] = dw0;
807 dw[1] = view->cmd[6];
808 dw[2] = 0;
809
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600810 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800811 cmd_reserve_reloc(cmd, 1);
812 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
813 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600814 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800815}
816
817static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
818 const struct intel_ds_view *view)
819{
820 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800821 uint32_t dw0, *dw;
822 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800823
824 CMD_ASSERT(cmd, 6, 7.5);
825
826 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800827 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
828 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800829 dw0 |= (cmd_len - 2);
830
Chia-I Wu72292b72014-09-09 10:48:33 +0800831 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
832 dw[0] = dw0;
833 dw[1] = view->cmd[8];
834 dw[2] = 0;
835
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600836 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800837 cmd_reserve_reloc(cmd, 1);
838 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
839 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600840 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800841}
842
Chia-I Wuf8231032014-08-25 10:44:45 +0800843static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
844 uint32_t clear_val)
845{
846 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800847 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800848 GEN6_CLEAR_PARAMS_DW0_VALID |
849 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800851
852 CMD_ASSERT(cmd, 6, 6);
853
Chia-I Wu72292b72014-09-09 10:48:33 +0800854 cmd_batch_pointer(cmd, cmd_len, &dw);
855 dw[0] = dw0;
856 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800857}
858
859static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
860 uint32_t clear_val)
861{
862 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800864 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800866
867 CMD_ASSERT(cmd, 7, 7.5);
868
Chia-I Wu72292b72014-09-09 10:48:33 +0800869 cmd_batch_pointer(cmd, cmd_len, &dw);
870 dw[0] = dw0;
871 dw[1] = clear_val;
872 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800873}
874
Chia-I Wu302742d2014-08-22 10:28:29 +0800875static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800876 uint32_t blend_offset,
877 uint32_t ds_offset,
878 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800879{
880 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800881 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800882
883 CMD_ASSERT(cmd, 6, 6);
884
Chia-I Wu426072d2014-08-26 14:31:55 +0800885 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800886 (cmd_len - 2);
887
Chia-I Wu72292b72014-09-09 10:48:33 +0800888 cmd_batch_pointer(cmd, cmd_len, &dw);
889 dw[0] = dw0;
890 dw[1] = blend_offset | 1;
891 dw[2] = ds_offset | 1;
892 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800893}
894
Chia-I Wu1744cca2014-08-22 11:10:17 +0800895static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800896 uint32_t clip_offset,
897 uint32_t sf_offset,
898 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800899{
900 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800901 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800902
903 CMD_ASSERT(cmd, 6, 6);
904
Chia-I Wu426072d2014-08-26 14:31:55 +0800905 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800906 GEN6_PTR_VP_DW0_CLIP_CHANGED |
907 GEN6_PTR_VP_DW0_SF_CHANGED |
908 GEN6_PTR_VP_DW0_CC_CHANGED |
909 (cmd_len - 2);
910
Chia-I Wu72292b72014-09-09 10:48:33 +0800911 cmd_batch_pointer(cmd, cmd_len, &dw);
912 dw[0] = dw0;
913 dw[1] = clip_offset;
914 dw[2] = sf_offset;
915 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800916}
917
918static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800919 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800920{
921 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800923
924 CMD_ASSERT(cmd, 6, 6);
925
Chia-I Wu426072d2014-08-26 14:31:55 +0800926 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800927 (cmd_len - 2);
928
Chia-I Wu72292b72014-09-09 10:48:33 +0800929 cmd_batch_pointer(cmd, cmd_len, &dw);
930 dw[0] = dw0;
931 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800932}
933
Chia-I Wu42a56202014-08-23 16:47:48 +0800934static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800935 uint32_t vs_offset,
936 uint32_t gs_offset,
937 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800938{
939 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800940 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800941
942 CMD_ASSERT(cmd, 6, 6);
943
Chia-I Wu426072d2014-08-26 14:31:55 +0800944 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800945 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
946 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
947 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
948 (cmd_len - 2);
949
Chia-I Wu72292b72014-09-09 10:48:33 +0800950 cmd_batch_pointer(cmd, cmd_len, &dw);
951 dw[0] = dw0;
952 dw[1] = vs_offset;
953 dw[2] = gs_offset;
954 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800955}
956
Chia-I Wu257e75e2014-08-29 14:06:35 +0800957static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800958 uint32_t vs_offset,
959 uint32_t gs_offset,
960 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800961{
962 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800963 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800964
965 CMD_ASSERT(cmd, 6, 6);
966
967 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
968 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
969 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
970 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
971 (cmd_len - 2);
972
Chia-I Wu72292b72014-09-09 10:48:33 +0800973 cmd_batch_pointer(cmd, cmd_len, &dw);
974 dw[0] = dw0;
975 dw[1] = vs_offset;
976 dw[2] = gs_offset;
977 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800978}
979
Chia-I Wu302742d2014-08-22 10:28:29 +0800980static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800981 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800982{
983 const uint8_t cmd_len = 2;
984 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
985 GEN6_RENDER_SUBTYPE_3D |
986 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800987 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800988
Chia-I Wu72292b72014-09-09 10:48:33 +0800989 cmd_batch_pointer(cmd, cmd_len, &dw);
990 dw[0] = dw0;
991 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800992}
993
Chia-I Wu72292b72014-09-09 10:48:33 +0800994static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800995 const struct intel_blend_state *state)
996{
Chia-I Wu72292b72014-09-09 10:48:33 +0800997 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800998 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
999
1000 CMD_ASSERT(cmd, 6, 7.5);
1001 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1002
Chia-I Wu00b51a82014-09-09 12:07:37 +08001003 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
1004 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001005}
1006
Chia-I Wu72292b72014-09-09 10:48:33 +08001007static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001008 const struct intel_ds_state *state)
1009{
Chia-I Wu72292b72014-09-09 10:48:33 +08001010 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001011 const uint8_t cmd_len = 3;
1012
1013 CMD_ASSERT(cmd, 6, 7.5);
1014 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1015
Chia-I Wu00b51a82014-09-09 12:07:37 +08001016 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1017 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001018}
1019
Chia-I Wu72292b72014-09-09 10:48:33 +08001020static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001021 uint32_t stencil_ref,
1022 const uint32_t blend_color[4])
1023{
Chia-I Wu72292b72014-09-09 10:48:33 +08001024 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001025 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001026 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001027
1028 CMD_ASSERT(cmd, 6, 7.5);
1029
Chia-I Wu00b51a82014-09-09 12:07:37 +08001030 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1031 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001032 dw[0] = stencil_ref;
1033 dw[1] = 0;
1034 dw[2] = blend_color[0];
1035 dw[3] = blend_color[1];
1036 dw[4] = blend_color[2];
1037 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001038
Chia-I Wu72292b72014-09-09 10:48:33 +08001039 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001040}
1041
Chia-I Wu8370b402014-08-29 12:28:37 +08001042static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001043{
Chia-I Wu8370b402014-08-29 12:28:37 +08001044 CMD_ASSERT(cmd, 6, 7.5);
1045
Chia-I Wu707a29e2014-08-27 12:51:47 +08001046 if (!cmd->bind.draw_count)
1047 return;
1048
Chia-I Wu8370b402014-08-29 12:28:37 +08001049 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001050 return;
1051
Chia-I Wu8370b402014-08-29 12:28:37 +08001052 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001053
1054 /*
1055 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1056 *
1057 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1058 * pipe-control with a post-sync op and no write-cache flushes."
1059 *
1060 * The workaround below necessitates this workaround.
1061 */
1062 gen6_PIPE_CONTROL(cmd,
1063 GEN6_PIPE_CONTROL_CS_STALL |
1064 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001065 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001066
Chia-I Wud6d079d2014-08-31 13:14:21 +08001067 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1068 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001069}
1070
Chia-I Wu8370b402014-08-29 12:28:37 +08001071static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001072{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001073 CMD_ASSERT(cmd, 6, 7.5);
1074
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001075 if (!cmd->bind.draw_count)
1076 return;
1077
Chia-I Wud6d079d2014-08-31 13:14:21 +08001078 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1079 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001080}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001081
Chia-I Wu8370b402014-08-29 12:28:37 +08001082static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1083{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001084 CMD_ASSERT(cmd, 7, 7.5);
1085
Chia-I Wu8370b402014-08-29 12:28:37 +08001086 if (!cmd->bind.draw_count)
1087 return;
1088
1089 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001090
1091 gen6_PIPE_CONTROL(cmd,
1092 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001093 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001094}
1095
Chia-I Wu8370b402014-08-29 12:28:37 +08001096static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1097{
1098 CMD_ASSERT(cmd, 7, 7.5);
1099
1100 if (!cmd->bind.draw_count)
1101 return;
1102
1103 /*
1104 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1105 *
1106 * "One of the following must also be set (when CS stall is set):
1107 *
1108 * * Render Target Cache Flush Enable ([12] of DW1)
1109 * * Depth Cache Flush Enable ([0] of DW1)
1110 * * Stall at Pixel Scoreboard ([1] of DW1)
1111 * * Depth Stall ([13] of DW1)
1112 * * Post-Sync Operation ([13] of DW1)"
1113 */
1114 gen6_PIPE_CONTROL(cmd,
1115 GEN6_PIPE_CONTROL_CS_STALL |
1116 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001117 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001118}
1119
1120static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1121{
1122 CMD_ASSERT(cmd, 7, 7.5);
1123
1124 if (!cmd->bind.draw_count)
1125 return;
1126
1127 cmd_wa_gen6_pre_depth_stall_write(cmd);
1128
Chia-I Wud6d079d2014-08-31 13:14:21 +08001129 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001130}
1131
1132static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1133{
1134 CMD_ASSERT(cmd, 6, 7.5);
1135
1136 if (!cmd->bind.draw_count)
1137 return;
1138
1139 /*
1140 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1141 *
1142 * "Driver must guarentee that all the caches in the depth pipe are
1143 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1144 * requires driver to send a PIPE_CONTROL with a CS stall along with
1145 * a Depth Flush prior to this command."
1146 *
1147 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1148 *
1149 * "Driver must ierarchi that all the caches in the depth pipe are
1150 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1151 * requires driver to send a PIPE_CONTROL with a CS stall along with
1152 * a Depth Flush prior to this command.
1153 */
1154 gen6_PIPE_CONTROL(cmd,
1155 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1156 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001157 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001158}
1159
1160static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1161{
1162 CMD_ASSERT(cmd, 6, 7.5);
1163
1164 if (!cmd->bind.draw_count)
1165 return;
1166
1167 /*
1168 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1169 *
1170 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1171 * and a post sync operation prior to the group of depth
1172 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1173 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1174 *
1175 * This workaround satifies all the conditions.
1176 */
1177 cmd_wa_gen6_pre_depth_stall_write(cmd);
1178
1179 /*
1180 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1181 *
1182 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1183 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1184 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1185 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1186 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1187 * Depth Flush Bit set, followed by another pipelined depth stall
1188 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1189 * guarantee that the pipeline from WM onwards is already flushed
1190 * (e.g., via a preceding MI_FLUSH)."
1191 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001192 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1193 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1194 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001195}
1196
Chia-I Wu525c6602014-08-27 10:22:34 +08001197void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1198{
1199 if (!cmd->bind.draw_count)
1200 return;
1201
1202 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1203
Chia-I Wu8370b402014-08-29 12:28:37 +08001204 /*
1205 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1206 *
1207 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1208 * PIPE_CONTROL with any non-zero post-sync-op is required."
1209 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001210 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001211 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001212
Chia-I Wu092279a2014-08-30 19:05:30 +08001213 /*
1214 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1215 *
1216 * "One of the following must also be set (when CS stall is set):
1217 *
1218 * * Render Target Cache Flush Enable ([12] of DW1)
1219 * * Depth Cache Flush Enable ([0] of DW1)
1220 * * Stall at Pixel Scoreboard ([1] of DW1)
1221 * * Depth Stall ([13] of DW1)
1222 * * Post-Sync Operation ([13] of DW1)"
1223 */
1224 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1225 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1226 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1227 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1228 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1229 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1230
Chia-I Wud6d079d2014-08-31 13:14:21 +08001231 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001232}
1233
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001234void cmd_batch_depth_count(struct intel_cmd *cmd,
1235 struct intel_bo *bo,
1236 XGL_GPU_SIZE offset)
1237{
1238 cmd_wa_gen6_pre_depth_stall_write(cmd);
1239
1240 gen6_PIPE_CONTROL(cmd,
1241 GEN6_PIPE_CONTROL_DEPTH_STALL |
1242 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001243 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001244}
1245
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001246void cmd_batch_timestamp(struct intel_cmd *cmd,
1247 struct intel_bo *bo,
1248 XGL_GPU_SIZE offset)
1249{
1250 /* need any WA or stall? */
1251 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1252}
1253
1254void cmd_batch_immediate(struct intel_cmd *cmd,
1255 struct intel_bo *bo,
1256 XGL_GPU_SIZE offset,
1257 uint64_t val)
1258{
1259 /* need any WA or stall? */
1260 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1261}
1262
Chia-I Wu302742d2014-08-22 10:28:29 +08001263static void gen6_cc_states(struct intel_cmd *cmd)
1264{
1265 const struct intel_blend_state *blend = cmd->bind.state.blend;
1266 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001267 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001268 uint32_t stencil_ref;
1269 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001270
1271 CMD_ASSERT(cmd, 6, 6);
1272
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001273 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001274 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001275 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1276 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001277 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001278 memset(blend_color, 0, sizeof(blend_color));
1279 }
1280
1281 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001282 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001283 stencil_ref = ds->cmd_stencil_ref;
1284 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001285 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001286 stencil_ref = 0;
1287 }
1288
Chia-I Wu72292b72014-09-09 10:48:33 +08001289 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001290
Chia-I Wu72292b72014-09-09 10:48:33 +08001291 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001292}
1293
Chia-I Wu1744cca2014-08-22 11:10:17 +08001294static void gen6_viewport_states(struct intel_cmd *cmd)
1295{
1296 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001297 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001298
1299 if (!viewport)
1300 return;
1301
Chia-I Wub1d450a2014-09-09 13:48:03 +08001302 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1303 viewport->viewport_count);
1304
1305 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1306 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1307 viewport->cmd);
1308
1309 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1310 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1311 &viewport->cmd[viewport->cmd_clip_pos]);
1312
1313 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1314 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1315 &viewport->cmd[viewport->cmd_cc_pos]);
1316
1317 if (viewport->scissor_enable) {
1318 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1319 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1320 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1321 } else {
1322 scissor_offset = 0;
1323 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001324
1325 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001326 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001327
Chia-I Wub1d450a2014-09-09 13:48:03 +08001328 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001329}
1330
Chia-I Wu302742d2014-08-22 10:28:29 +08001331static void gen7_cc_states(struct intel_cmd *cmd)
1332{
1333 const struct intel_blend_state *blend = cmd->bind.state.blend;
1334 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001335 uint32_t stencil_ref;
1336 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001337 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001338
1339 CMD_ASSERT(cmd, 7, 7.5);
1340
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001341 if (!blend && !ds)
1342 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001343
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001344 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001345 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001346 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001347 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001348
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001349 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1350 } else {
1351 memset(blend_color, 0, sizeof(blend_color));
1352 }
1353
1354 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001355 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001356 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001357 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1358 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001359 } else {
1360 stencil_ref = 0;
1361 }
1362
Chia-I Wu72292b72014-09-09 10:48:33 +08001363 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001364 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001365 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001366}
1367
Chia-I Wu1744cca2014-08-22 11:10:17 +08001368static void gen7_viewport_states(struct intel_cmd *cmd)
1369{
1370 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001371 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001372
1373 if (!viewport)
1374 return;
1375
Chia-I Wub1d450a2014-09-09 13:48:03 +08001376 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1377 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001378
Chia-I Wub1d450a2014-09-09 13:48:03 +08001379 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1380 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1381 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001382 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001383 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1384 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001385
1386 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1387 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1388 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001389 gen7_3dstate_pointer(cmd,
1390 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001391 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001392
Chia-I Wu1744cca2014-08-22 11:10:17 +08001393 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001394 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1395 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1396 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001397 gen7_3dstate_pointer(cmd,
1398 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001399 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001400 }
1401}
1402
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001403static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001404 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001405{
1406 const uint8_t cmd_len = 5;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001407 /*
1408 * TODO It is actually 2048 for non-VS PCB. But we need to upload the
1409 * data to multiple PCBs when the size is greater than 1024.
1410 */
1411 const XGL_UINT max_size = 1024;
Chia-I Wu72292b72014-09-09 10:48:33 +08001412 uint32_t offset, dw0, *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001413
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001414 if (sh->pcb_size > max_size) {
1415 cmd->result = XGL_ERROR_UNKNOWN;
1416 return;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001417 }
1418
1419 dw0 = GEN6_RENDER_TYPE_RENDER |
1420 GEN6_RENDER_SUBTYPE_3D |
1421 subop |
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001422 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001423 offset = 0;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001424
1425 if (sh->pcb_size) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001426 const XGL_SIZE alignment = 32;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001427 const XGL_SIZE size = u_align(sh->pcb_size, alignment);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001428
Chia-I Wu00b51a82014-09-09 12:07:37 +08001429 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB, alignment,
Chia-I Wu72292b72014-09-09 10:48:33 +08001430 size / sizeof(uint32_t), &dw);
1431 memcpy(dw, sh->pcb, sh->pcb_size);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001432
1433 dw0 |= GEN6_PCB_ANY_DW0_PCB0_VALID;
Chia-I Wu72292b72014-09-09 10:48:33 +08001434 offset |= size / alignment - 1;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001435 }
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001436
Chia-I Wu72292b72014-09-09 10:48:33 +08001437 cmd_batch_pointer(cmd, cmd_len, &dw);
1438 dw[0] = dw0;
1439 dw[1] = offset;
1440 dw[2] = 0;
1441 dw[3] = 0;
1442 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001443}
1444
1445static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001446 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001447{
1448 const uint8_t cmd_len = 7;
1449 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1450 GEN6_RENDER_SUBTYPE_3D |
1451 subop |
1452 (cmd_len - 2);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001453 const XGL_UINT max_size = 2048;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001454 XGL_UINT pcb_len = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001455 uint32_t offset = 0, *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001456
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001457 if (sh->pcb_size > max_size) {
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001458 cmd->result = XGL_ERROR_UNKNOWN;
1459 return;
1460 }
1461
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001462 if (sh->pcb_size) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001463 const XGL_SIZE alignment = 32;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001464 const XGL_SIZE size = u_align(sh->pcb_size, alignment);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001465
1466 pcb_len = size / alignment;
1467
Chia-I Wu00b51a82014-09-09 12:07:37 +08001468 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB, alignment,
Chia-I Wu72292b72014-09-09 10:48:33 +08001469 size / sizeof(uint32_t), &dw);
1470 memcpy(dw, sh->pcb, sh->pcb_size);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001471 }
1472
Chia-I Wu72292b72014-09-09 10:48:33 +08001473 cmd_batch_pointer(cmd, cmd_len, &dw);
1474 dw[0] = dw0;
1475 dw[1] = pcb_len;
1476 dw[2] = 0;
1477 dw[3] = offset;
1478 dw[4] = 0;
1479 dw[5] = 0;
1480 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001481}
1482
Chia-I Wu42a56202014-08-23 16:47:48 +08001483static void emit_ps_resources(struct intel_cmd *cmd,
Chia-I Wu20983762014-09-02 12:07:28 +08001484 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001485{
1486 const XGL_UINT surface_count = rmap->rt_count +
1487 rmap->resource_count + rmap->uav_count;
Chia-I Wu72292b72014-09-09 10:48:33 +08001488 uint32_t binding_table[256], offset;
1489 XGL_UINT i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001490
1491 assert(surface_count <= ARRAY_SIZE(binding_table));
1492
1493 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001494 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001495
1496 switch (slot->path_len) {
1497 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001498 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001499 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001500 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001501 {
1502 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1503
Chia-I Wu00b51a82014-09-09 12:07:37 +08001504 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001505 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1506 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001507
Chia-I Wu72292b72014-09-09 10:48:33 +08001508 cmd_reserve_reloc(cmd, 1);
1509 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1510 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001511 }
1512 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001513 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001514 {
1515 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001516 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001517
Chia-I Wu00b51a82014-09-09 12:07:37 +08001518 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001519 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1520 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001521
Chia-I Wu72292b72014-09-09 10:48:33 +08001522 cmd_reserve_reloc(cmd, 1);
1523 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1524 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001525 }
1526 break;
1527 case 1:
1528 default:
1529 /* TODO */
1530 assert(!"no dset support");
1531 break;
1532 }
1533
Chia-I Wu72292b72014-09-09 10:48:33 +08001534 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001535 }
1536
Chia-I Wu00b51a82014-09-09 12:07:37 +08001537 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
1538 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001539 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001540
1541 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1542 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001543 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, offset);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001544
1545 gen7_3dstate_pointer(cmd,
1546 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1547 gen7_3dstate_pointer(cmd,
1548 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1549 gen7_3dstate_pointer(cmd,
1550 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1551 gen7_3dstate_pointer(cmd,
1552 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1553
1554 gen7_3dstate_pointer(cmd,
1555 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1556 gen7_3dstate_pointer(cmd,
1557 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1558 gen7_3dstate_pointer(cmd,
1559 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1560 gen7_3dstate_pointer(cmd,
1561 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1562 gen7_3dstate_pointer(cmd,
1563 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001564 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001565 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001566 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001567 }
1568}
1569
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001570static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1571{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001572 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1573 const struct intel_pipeline_shader *vs = &pipeline->vs;
1574 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001575 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001576 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001577 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001578
1579 CMD_ASSERT(cmd, 6, 7.5);
1580
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001581 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001582 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1583 *
1584 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1585 * 128-bit vertex elements to be passed into the payload for each
1586 * vertex."
1587 *
1588 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1589 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001590 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001591 vue_read_len = (vs->in_count + 1) / 2;
1592 if (!vue_read_len)
1593 vue_read_len = 1;
1594
1595 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1596 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1597
1598 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1599 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1600 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001601
1602 dw5 = GEN6_VS_DW5_STATISTICS |
1603 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001604
1605 switch (cmd_gen(cmd)) {
1606 case INTEL_GEN(7.5):
1607 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1608 break;
1609 case INTEL_GEN(7):
1610 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1611 break;
1612 case INTEL_GEN(6):
1613 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1614 break;
1615 default:
1616 max_threads = 1;
1617 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001618 }
1619
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001620 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1621 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1622 else
1623 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1624
Chia-I Wube0a3d92014-09-02 13:20:59 +08001625 if (pipeline->disable_vs_cache)
1626 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1627
Chia-I Wu72292b72014-09-09 10:48:33 +08001628 cmd_batch_pointer(cmd, cmd_len, &dw);
1629 dw[0] = dw0;
1630 dw[1] = cmd->bind.vs.kernel_offset;
1631 dw[2] = dw2;
1632 dw[3] = 0; /* scratch */
1633 dw[4] = dw4;
1634 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001635}
1636
Chia-I Wu52500102014-08-22 00:46:04 +08001637static void emit_bounded_states(struct intel_cmd *cmd)
1638{
1639 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1640
1641 /* TODO more states */
1642
Chia-I Wu1744cca2014-08-22 11:10:17 +08001643 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001644 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001645 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001646
1647 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1648 &cmd->bind.pipeline.graphics->vs);
1649 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1650 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001651
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001652 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001653 gen7_3DSTATE_SF(cmd);
1654 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001655 gen7_3DSTATE_WM(cmd);
1656 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001657 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001658 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001659 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001660
1661 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1662 &cmd->bind.pipeline.graphics->vs);
1663 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1664 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001665
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001666 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001667 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001668 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001669 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001670
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001671 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu42a56202014-08-23 16:47:48 +08001672
Chia-I Wu8370b402014-08-29 12:28:37 +08001673 cmd_wa_gen6_pre_depth_stall_write(cmd);
1674 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu72292b72014-09-09 10:48:33 +08001675
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001676 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu72292b72014-09-09 10:48:33 +08001677 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001678
1679 gen6_3DSTATE_VS(cmd);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001680}
1681
1682static void emit_shader(struct intel_cmd *cmd,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001683 const struct intel_pipeline_shader *shader,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001684 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001685{
1686 uint32_t i;
1687 struct intel_cmd_shader *cmdShader;
1688
1689 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001690 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001691 /* shader is already part of pipeline */
1692 return;
1693 }
1694 }
1695
Chia-I Wu338fe642014-08-28 10:43:04 +08001696 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1697 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1698
1699 cmdShader = cmd->bind.shaderCache.shaderArray;
1700
1701 cmd->bind.shaderCache.shaderArray =
1702 icd_alloc(sizeof(*cmdShader) * new_count,
1703 0, XGL_SYSTEM_ALLOC_INTERNAL);
1704 if (cmd->bind.shaderCache.shaderArray == NULL) {
1705 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001706 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1707 return;
1708 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001709
1710 if (cmdShader) {
1711 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1712 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1713 icd_free(cmdShader);
1714 }
1715
1716 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001717 }
1718
Chia-I Wu338fe642014-08-28 10:43:04 +08001719 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001720 cmdShader->shader = shader;
Chia-I Wu72292b72014-09-09 10:48:33 +08001721 cmdShader->kernel_offset =
1722 cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001723 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001724 cmd->bind.shaderCache.used++;
1725 return;
1726}
1727
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001728static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001729 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001730{
1731 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001732
Chia-I Wu8370b402014-08-29 12:28:37 +08001733 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1734 cmd_wa_gen6_pre_depth_stall_write(cmd);
1735 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1736 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1737 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1738 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001739
1740 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001741 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001742 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001743
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001744 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001745 emit_shader(cmd, &pipeline->vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001746 }
1747 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001748 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001749 }
1750 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001751 emit_shader(cmd, &pipeline->fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001752 }
1753 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +08001754 emit_shader(cmd, &pipeline->tcs, &cmd->bind.tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001755 }
1756 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +08001757 emit_shader(cmd, &pipeline->tes, &cmd->bind.tes);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001758 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001759
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001760 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1761 gen7_3DSTATE_GS(cmd);
1762 } else {
1763 gen6_3DSTATE_GS(cmd);
1764 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001765
Chia-I Wu8370b402014-08-29 12:28:37 +08001766 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1767 cmd_wa_gen7_post_command_cs_stall(cmd);
1768 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1769 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001770}
1771
1772static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1773 const struct intel_pipeline *pipeline)
1774{
1775 cmd->bind.pipeline.compute = pipeline;
1776}
1777
1778static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1779 const struct intel_pipeline_delta *delta)
1780{
1781 cmd->bind.pipeline.graphics_delta = delta;
1782}
1783
1784static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1785 const struct intel_pipeline_delta *delta)
1786{
1787 cmd->bind.pipeline.compute_delta = delta;
1788}
1789
1790static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1791 const struct intel_dset *dset,
1792 XGL_UINT slot_offset)
1793{
1794 cmd->bind.dset.graphics = dset;
1795 cmd->bind.dset.graphics_offset = slot_offset;
1796}
1797
1798static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1799 const struct intel_dset *dset,
1800 XGL_UINT slot_offset)
1801{
1802 cmd->bind.dset.compute = dset;
1803 cmd->bind.dset.compute_offset = slot_offset;
1804}
1805
1806static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1807 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1808{
1809 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1810}
1811
1812static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1813 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1814{
1815 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1816}
1817
1818static void cmd_bind_index_data(struct intel_cmd *cmd,
1819 const struct intel_mem *mem,
1820 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1821{
1822 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1823 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1824 } else {
1825 cmd->bind.index.mem = mem;
1826 cmd->bind.index.offset = offset;
1827 cmd->bind.index.type = type;
1828 }
1829}
1830
1831static void cmd_bind_rt(struct intel_cmd *cmd,
1832 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1833 XGL_UINT count)
1834{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001835 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001836 XGL_UINT i;
1837
1838 for (i = 0; i < count; i++) {
1839 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1840 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001841 const struct intel_layout *layout = &rt->img->layout;
1842
1843 if (i == 0) {
1844 width = layout->width0;
1845 height = layout->height0;
1846 } else {
1847 if (width > layout->width0)
1848 width = layout->width0;
1849 if (height > layout->height0)
1850 height = layout->height0;
1851 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001852
1853 cmd->bind.att.rt[i] = rt;
1854 }
1855
1856 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001857
Chia-I Wu8370b402014-08-29 12:28:37 +08001858 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001859 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001860}
1861
1862static void cmd_bind_ds(struct intel_cmd *cmd,
1863 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1864{
1865 const struct intel_ds_view *ds;
1866
1867 if (info) {
1868 cmd->bind.att.ds = intel_ds_view(info->view);
1869 ds = cmd->bind.att.ds;
1870 } else {
1871 /* all zeros */
1872 static const struct intel_ds_view null_ds;
1873 ds = &null_ds;
1874 }
1875
Chia-I Wu8370b402014-08-29 12:28:37 +08001876 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001877 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1878 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1879 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001880
1881 if (cmd_gen(cmd) >= INTEL_GEN(7))
1882 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1883 else
1884 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001885}
1886
1887static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1888 const struct intel_viewport_state *state)
1889{
1890 cmd->bind.state.viewport = state;
1891}
1892
1893static void cmd_bind_raster_state(struct intel_cmd *cmd,
1894 const struct intel_raster_state *state)
1895{
1896 cmd->bind.state.raster = state;
1897}
1898
1899static void cmd_bind_ds_state(struct intel_cmd *cmd,
1900 const struct intel_ds_state *state)
1901{
1902 cmd->bind.state.ds = state;
1903}
1904
1905static void cmd_bind_blend_state(struct intel_cmd *cmd,
1906 const struct intel_blend_state *state)
1907{
1908 cmd->bind.state.blend = state;
1909}
1910
1911static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1912 const struct intel_msaa_state *state)
1913{
1914 cmd->bind.state.msaa = state;
1915}
1916
1917static void cmd_draw(struct intel_cmd *cmd,
1918 XGL_UINT vertex_start,
1919 XGL_UINT vertex_count,
1920 XGL_UINT instance_start,
1921 XGL_UINT instance_count,
1922 bool indexed,
1923 XGL_UINT vertex_base)
1924{
1925 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1926
1927 emit_bounded_states(cmd);
1928
1929 if (indexed) {
1930 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1931 cmd->result = XGL_ERROR_UNKNOWN;
1932
1933 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1934 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1935 p->primitive_restart_index);
1936 } else {
1937 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1938 cmd->bind.index.offset, cmd->bind.index.type,
1939 p->primitive_restart);
1940 }
1941 } else {
1942 assert(!vertex_base);
1943 }
1944
1945 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1946 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1947 vertex_start, instance_count, instance_start, vertex_base);
1948 } else {
1949 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1950 vertex_start, instance_count, instance_start, vertex_base);
1951 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001952
Chia-I Wu707a29e2014-08-27 12:51:47 +08001953 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001954 /* need to re-emit all workarounds */
1955 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001956}
1957
Chia-I Wub2755562014-08-20 13:38:52 +08001958XGL_VOID XGLAPI intelCmdBindPipeline(
1959 XGL_CMD_BUFFER cmdBuffer,
1960 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1961 XGL_PIPELINE pipeline)
1962{
1963 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1964
1965 switch (pipelineBindPoint) {
1966 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001967 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001968 break;
1969 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001970 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001971 break;
1972 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001973 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001974 break;
1975 }
1976}
1977
1978XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1979 XGL_CMD_BUFFER cmdBuffer,
1980 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1981 XGL_PIPELINE_DELTA delta)
1982{
1983 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1984
1985 switch (pipelineBindPoint) {
1986 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001987 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001988 break;
1989 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001990 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001991 break;
1992 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001993 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001994 break;
1995 }
1996}
1997
1998XGL_VOID XGLAPI intelCmdBindStateObject(
1999 XGL_CMD_BUFFER cmdBuffer,
2000 XGL_STATE_BIND_POINT stateBindPoint,
2001 XGL_STATE_OBJECT state)
2002{
2003 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2004
2005 switch (stateBindPoint) {
2006 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002007 cmd_bind_viewport_state(cmd,
2008 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002009 break;
2010 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002011 cmd_bind_raster_state(cmd,
2012 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002013 break;
2014 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002015 cmd_bind_ds_state(cmd,
2016 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002017 break;
2018 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002019 cmd_bind_blend_state(cmd,
2020 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002021 break;
2022 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002023 cmd_bind_msaa_state(cmd,
2024 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002025 break;
2026 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002027 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002028 break;
2029 }
2030}
2031
2032XGL_VOID XGLAPI intelCmdBindDescriptorSet(
2033 XGL_CMD_BUFFER cmdBuffer,
2034 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2035 XGL_UINT index,
2036 XGL_DESCRIPTOR_SET descriptorSet,
2037 XGL_UINT slotOffset)
2038{
2039 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2040 struct intel_dset *dset = intel_dset(descriptorSet);
2041
2042 assert(!index);
2043
2044 switch (pipelineBindPoint) {
2045 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002046 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002047 break;
2048 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002049 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002050 break;
2051 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002052 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002053 break;
2054 }
2055}
2056
2057XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
2058 XGL_CMD_BUFFER cmdBuffer,
2059 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2060 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
2061{
2062 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2063
2064 switch (pipelineBindPoint) {
2065 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002066 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002067 break;
2068 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002069 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002070 break;
2071 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002072 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002073 break;
2074 }
2075}
2076
2077XGL_VOID XGLAPI intelCmdBindIndexData(
2078 XGL_CMD_BUFFER cmdBuffer,
2079 XGL_GPU_MEMORY mem_,
2080 XGL_GPU_SIZE offset,
2081 XGL_INDEX_TYPE indexType)
2082{
2083 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2084 struct intel_mem *mem = intel_mem(mem_);
2085
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002086 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08002087}
2088
2089XGL_VOID XGLAPI intelCmdBindAttachments(
2090 XGL_CMD_BUFFER cmdBuffer,
2091 XGL_UINT colorAttachmentCount,
2092 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
2093 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
2094{
2095 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08002096
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002097 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
2098 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08002099}
2100
2101XGL_VOID XGLAPI intelCmdDraw(
2102 XGL_CMD_BUFFER cmdBuffer,
2103 XGL_UINT firstVertex,
2104 XGL_UINT vertexCount,
2105 XGL_UINT firstInstance,
2106 XGL_UINT instanceCount)
2107{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002108 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002109
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002110 cmd_draw(cmd, firstVertex, vertexCount,
2111 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08002112}
2113
2114XGL_VOID XGLAPI intelCmdDrawIndexed(
2115 XGL_CMD_BUFFER cmdBuffer,
2116 XGL_UINT firstIndex,
2117 XGL_UINT indexCount,
2118 XGL_INT vertexOffset,
2119 XGL_UINT firstInstance,
2120 XGL_UINT instanceCount)
2121{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002122 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002123
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002124 cmd_draw(cmd, firstIndex, indexCount,
2125 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002126}
2127
2128XGL_VOID XGLAPI intelCmdDrawIndirect(
2129 XGL_CMD_BUFFER cmdBuffer,
2130 XGL_GPU_MEMORY mem,
2131 XGL_GPU_SIZE offset,
2132 XGL_UINT32 count,
2133 XGL_UINT32 stride)
2134{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002135 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2136
2137 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002138}
2139
2140XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2141 XGL_CMD_BUFFER cmdBuffer,
2142 XGL_GPU_MEMORY mem,
2143 XGL_GPU_SIZE offset,
2144 XGL_UINT32 count,
2145 XGL_UINT32 stride)
2146{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002147 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2148
2149 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002150}
2151
2152XGL_VOID XGLAPI intelCmdDispatch(
2153 XGL_CMD_BUFFER cmdBuffer,
2154 XGL_UINT x,
2155 XGL_UINT y,
2156 XGL_UINT z)
2157{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002158 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2159
2160 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002161}
2162
2163XGL_VOID XGLAPI intelCmdDispatchIndirect(
2164 XGL_CMD_BUFFER cmdBuffer,
2165 XGL_GPU_MEMORY mem,
2166 XGL_GPU_SIZE offset)
2167{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002168 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2169
2170 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002171}