blob: a81082948a15aad3a26fdae13e5929d3d65157df [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 Wu72292b72014-09-09 10:48:33 +08001003 return cmd_state_write(cmd, cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001004}
1005
Chia-I Wu72292b72014-09-09 10:48:33 +08001006static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001007 const struct intel_ds_state *state)
1008{
Chia-I Wu72292b72014-09-09 10:48:33 +08001009 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001010 const uint8_t cmd_len = 3;
1011
1012 CMD_ASSERT(cmd, 6, 7.5);
1013 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1014
Chia-I Wu72292b72014-09-09 10:48:33 +08001015 return cmd_state_write(cmd, cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001016}
1017
Chia-I Wu72292b72014-09-09 10:48:33 +08001018static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001019 uint32_t stencil_ref,
1020 const uint32_t blend_color[4])
1021{
Chia-I Wu72292b72014-09-09 10:48:33 +08001022 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001023 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001024 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001025
1026 CMD_ASSERT(cmd, 6, 7.5);
1027
Chia-I Wu72292b72014-09-09 10:48:33 +08001028 offset = cmd_state_pointer(cmd, cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001029 dw[0] = stencil_ref;
1030 dw[1] = 0;
1031 dw[2] = blend_color[0];
1032 dw[3] = blend_color[1];
1033 dw[4] = blend_color[2];
1034 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001035
Chia-I Wu72292b72014-09-09 10:48:33 +08001036 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001037}
1038
Chia-I Wu8370b402014-08-29 12:28:37 +08001039static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001040{
Chia-I Wu8370b402014-08-29 12:28:37 +08001041 CMD_ASSERT(cmd, 6, 7.5);
1042
Chia-I Wu707a29e2014-08-27 12:51:47 +08001043 if (!cmd->bind.draw_count)
1044 return;
1045
Chia-I Wu8370b402014-08-29 12:28:37 +08001046 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001047 return;
1048
Chia-I Wu8370b402014-08-29 12:28:37 +08001049 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001050
1051 /*
1052 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1053 *
1054 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1055 * pipe-control with a post-sync op and no write-cache flushes."
1056 *
1057 * The workaround below necessitates this workaround.
1058 */
1059 gen6_PIPE_CONTROL(cmd,
1060 GEN6_PIPE_CONTROL_CS_STALL |
1061 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001062 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001063
Chia-I Wud6d079d2014-08-31 13:14:21 +08001064 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1065 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001066}
1067
Chia-I Wu8370b402014-08-29 12:28:37 +08001068static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001069{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001070 CMD_ASSERT(cmd, 6, 7.5);
1071
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001072 if (!cmd->bind.draw_count)
1073 return;
1074
Chia-I Wud6d079d2014-08-31 13:14:21 +08001075 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1076 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001077}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001078
Chia-I Wu8370b402014-08-29 12:28:37 +08001079static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1080{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001081 CMD_ASSERT(cmd, 7, 7.5);
1082
Chia-I Wu8370b402014-08-29 12:28:37 +08001083 if (!cmd->bind.draw_count)
1084 return;
1085
1086 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001087
1088 gen6_PIPE_CONTROL(cmd,
1089 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001090 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001091}
1092
Chia-I Wu8370b402014-08-29 12:28:37 +08001093static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1094{
1095 CMD_ASSERT(cmd, 7, 7.5);
1096
1097 if (!cmd->bind.draw_count)
1098 return;
1099
1100 /*
1101 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1102 *
1103 * "One of the following must also be set (when CS stall is set):
1104 *
1105 * * Render Target Cache Flush Enable ([12] of DW1)
1106 * * Depth Cache Flush Enable ([0] of DW1)
1107 * * Stall at Pixel Scoreboard ([1] of DW1)
1108 * * Depth Stall ([13] of DW1)
1109 * * Post-Sync Operation ([13] of DW1)"
1110 */
1111 gen6_PIPE_CONTROL(cmd,
1112 GEN6_PIPE_CONTROL_CS_STALL |
1113 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001114 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001115}
1116
1117static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1118{
1119 CMD_ASSERT(cmd, 7, 7.5);
1120
1121 if (!cmd->bind.draw_count)
1122 return;
1123
1124 cmd_wa_gen6_pre_depth_stall_write(cmd);
1125
Chia-I Wud6d079d2014-08-31 13:14:21 +08001126 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001127}
1128
1129static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1130{
1131 CMD_ASSERT(cmd, 6, 7.5);
1132
1133 if (!cmd->bind.draw_count)
1134 return;
1135
1136 /*
1137 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1138 *
1139 * "Driver must guarentee that all the caches in the depth pipe are
1140 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1141 * requires driver to send a PIPE_CONTROL with a CS stall along with
1142 * a Depth Flush prior to this command."
1143 *
1144 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1145 *
1146 * "Driver must ierarchi that all the caches in the depth pipe are
1147 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1148 * requires driver to send a PIPE_CONTROL with a CS stall along with
1149 * a Depth Flush prior to this command.
1150 */
1151 gen6_PIPE_CONTROL(cmd,
1152 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1153 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001154 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001155}
1156
1157static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1158{
1159 CMD_ASSERT(cmd, 6, 7.5);
1160
1161 if (!cmd->bind.draw_count)
1162 return;
1163
1164 /*
1165 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1166 *
1167 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1168 * and a post sync operation prior to the group of depth
1169 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1170 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1171 *
1172 * This workaround satifies all the conditions.
1173 */
1174 cmd_wa_gen6_pre_depth_stall_write(cmd);
1175
1176 /*
1177 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1178 *
1179 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1180 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1181 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1182 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1183 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1184 * Depth Flush Bit set, followed by another pipelined depth stall
1185 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1186 * guarantee that the pipeline from WM onwards is already flushed
1187 * (e.g., via a preceding MI_FLUSH)."
1188 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001189 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1190 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1191 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001192}
1193
Chia-I Wu525c6602014-08-27 10:22:34 +08001194void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1195{
1196 if (!cmd->bind.draw_count)
1197 return;
1198
1199 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1200
Chia-I Wu8370b402014-08-29 12:28:37 +08001201 /*
1202 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1203 *
1204 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1205 * PIPE_CONTROL with any non-zero post-sync-op is required."
1206 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001207 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001208 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001209
Chia-I Wu092279a2014-08-30 19:05:30 +08001210 /*
1211 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1212 *
1213 * "One of the following must also be set (when CS stall is set):
1214 *
1215 * * Render Target Cache Flush Enable ([12] of DW1)
1216 * * Depth Cache Flush Enable ([0] of DW1)
1217 * * Stall at Pixel Scoreboard ([1] of DW1)
1218 * * Depth Stall ([13] of DW1)
1219 * * Post-Sync Operation ([13] of DW1)"
1220 */
1221 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1222 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1223 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1224 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1225 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1226 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1227
Chia-I Wud6d079d2014-08-31 13:14:21 +08001228 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001229}
1230
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001231void cmd_batch_depth_count(struct intel_cmd *cmd,
1232 struct intel_bo *bo,
1233 XGL_GPU_SIZE offset)
1234{
1235 cmd_wa_gen6_pre_depth_stall_write(cmd);
1236
1237 gen6_PIPE_CONTROL(cmd,
1238 GEN6_PIPE_CONTROL_DEPTH_STALL |
1239 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001240 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001241}
1242
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001243void cmd_batch_timestamp(struct intel_cmd *cmd,
1244 struct intel_bo *bo,
1245 XGL_GPU_SIZE offset)
1246{
1247 /* need any WA or stall? */
1248 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1249}
1250
1251void cmd_batch_immediate(struct intel_cmd *cmd,
1252 struct intel_bo *bo,
1253 XGL_GPU_SIZE offset,
1254 uint64_t val)
1255{
1256 /* need any WA or stall? */
1257 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1258}
1259
Chia-I Wu302742d2014-08-22 10:28:29 +08001260static void gen6_cc_states(struct intel_cmd *cmd)
1261{
1262 const struct intel_blend_state *blend = cmd->bind.state.blend;
1263 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001264 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001265 uint32_t stencil_ref;
1266 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001267
1268 CMD_ASSERT(cmd, 6, 6);
1269
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001270 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001271 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001272 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1273 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001274 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001275 memset(blend_color, 0, sizeof(blend_color));
1276 }
1277
1278 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001279 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001280 stencil_ref = ds->cmd_stencil_ref;
1281 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001282 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001283 stencil_ref = 0;
1284 }
1285
Chia-I Wu72292b72014-09-09 10:48:33 +08001286 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001287
Chia-I Wu72292b72014-09-09 10:48:33 +08001288 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001289}
1290
Chia-I Wu1744cca2014-08-22 11:10:17 +08001291static void gen6_viewport_states(struct intel_cmd *cmd)
1292{
1293 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001294 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001295
1296 if (!viewport)
1297 return;
1298
Chia-I Wu72292b72014-09-09 10:48:33 +08001299 offset = cmd_state_write(cmd, viewport->cmd_align * 4,
1300 viewport->cmd_len, viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001301
1302 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001303 offset + (viewport->cmd_clip_offset << 2),
1304 offset,
1305 offset + (viewport->cmd_cc_offset << 2));
Chia-I Wu1744cca2014-08-22 11:10:17 +08001306
Chia-I Wu72292b72014-09-09 10:48:33 +08001307 offset = (viewport->scissor_enable) ?
1308 offset + (viewport->cmd_scissor_rect_offset << 2) : 0;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001309
Chia-I Wu72292b72014-09-09 10:48:33 +08001310 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001311}
1312
Chia-I Wu302742d2014-08-22 10:28:29 +08001313static void gen7_cc_states(struct intel_cmd *cmd)
1314{
1315 const struct intel_blend_state *blend = cmd->bind.state.blend;
1316 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001317 uint32_t stencil_ref;
1318 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001319 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001320
1321 CMD_ASSERT(cmd, 7, 7.5);
1322
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001323 if (!blend && !ds)
1324 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001325
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001326 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001327 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001328 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001329 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001330
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001331 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1332 } else {
1333 memset(blend_color, 0, sizeof(blend_color));
1334 }
1335
1336 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001337 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001338 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001339 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1340 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001341 } else {
1342 stencil_ref = 0;
1343 }
1344
Chia-I Wu72292b72014-09-09 10:48:33 +08001345 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001346 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001347 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001348}
1349
Chia-I Wu1744cca2014-08-22 11:10:17 +08001350static void gen7_viewport_states(struct intel_cmd *cmd)
1351{
1352 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001353 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001354
1355 if (!viewport)
1356 return;
1357
Chia-I Wu72292b72014-09-09 10:48:33 +08001358 offset = cmd_state_write(cmd, viewport->cmd_align * 4,
1359 viewport->cmd_len, viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001360
1361 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001362 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1363 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001364 gen7_3dstate_pointer(cmd,
1365 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wu72292b72014-09-09 10:48:33 +08001366 offset + (viewport->cmd_cc_offset << 2));
1367
Chia-I Wu1744cca2014-08-22 11:10:17 +08001368 if (viewport->scissor_enable) {
1369 gen7_3dstate_pointer(cmd,
1370 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wu72292b72014-09-09 10:48:33 +08001371 offset + (viewport->cmd_scissor_rect_offset << 2));
Chia-I Wu1744cca2014-08-22 11:10:17 +08001372 }
1373}
1374
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001375static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001376 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001377{
1378 const uint8_t cmd_len = 5;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001379 /*
1380 * TODO It is actually 2048 for non-VS PCB. But we need to upload the
1381 * data to multiple PCBs when the size is greater than 1024.
1382 */
1383 const XGL_UINT max_size = 1024;
Chia-I Wu72292b72014-09-09 10:48:33 +08001384 uint32_t offset, dw0, *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001385
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001386 if (sh->pcb_size > max_size) {
1387 cmd->result = XGL_ERROR_UNKNOWN;
1388 return;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001389 }
1390
1391 dw0 = GEN6_RENDER_TYPE_RENDER |
1392 GEN6_RENDER_SUBTYPE_3D |
1393 subop |
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001394 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001395 offset = 0;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001396
1397 if (sh->pcb_size) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001398 const XGL_SIZE alignment = 32;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001399 const XGL_SIZE size = u_align(sh->pcb_size, alignment);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001400
Chia-I Wu72292b72014-09-09 10:48:33 +08001401 offset = cmd_state_pointer(cmd, alignment,
1402 size / sizeof(uint32_t), &dw);
1403 memcpy(dw, sh->pcb, sh->pcb_size);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001404
1405 dw0 |= GEN6_PCB_ANY_DW0_PCB0_VALID;
Chia-I Wu72292b72014-09-09 10:48:33 +08001406 offset |= size / alignment - 1;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001407 }
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001408
Chia-I Wu72292b72014-09-09 10:48:33 +08001409 cmd_batch_pointer(cmd, cmd_len, &dw);
1410 dw[0] = dw0;
1411 dw[1] = offset;
1412 dw[2] = 0;
1413 dw[3] = 0;
1414 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001415}
1416
1417static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001418 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001419{
1420 const uint8_t cmd_len = 7;
1421 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1422 GEN6_RENDER_SUBTYPE_3D |
1423 subop |
1424 (cmd_len - 2);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001425 const XGL_UINT max_size = 2048;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001426 XGL_UINT pcb_len = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001427 uint32_t offset = 0, *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001428
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001429 if (sh->pcb_size > max_size) {
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001430 cmd->result = XGL_ERROR_UNKNOWN;
1431 return;
1432 }
1433
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001434 if (sh->pcb_size) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001435 const XGL_SIZE alignment = 32;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001436 const XGL_SIZE size = u_align(sh->pcb_size, alignment);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001437
1438 pcb_len = size / alignment;
1439
Chia-I Wu72292b72014-09-09 10:48:33 +08001440 offset = cmd_state_pointer(cmd, alignment,
1441 size / sizeof(uint32_t), &dw);
1442 memcpy(dw, sh->pcb, sh->pcb_size);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001443 }
1444
Chia-I Wu72292b72014-09-09 10:48:33 +08001445 cmd_batch_pointer(cmd, cmd_len, &dw);
1446 dw[0] = dw0;
1447 dw[1] = pcb_len;
1448 dw[2] = 0;
1449 dw[3] = offset;
1450 dw[4] = 0;
1451 dw[5] = 0;
1452 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001453}
1454
Chia-I Wu42a56202014-08-23 16:47:48 +08001455static void emit_ps_resources(struct intel_cmd *cmd,
Chia-I Wu20983762014-09-02 12:07:28 +08001456 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001457{
1458 const XGL_UINT surface_count = rmap->rt_count +
1459 rmap->resource_count + rmap->uav_count;
Chia-I Wu72292b72014-09-09 10:48:33 +08001460 uint32_t binding_table[256], offset;
1461 XGL_UINT i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001462
1463 assert(surface_count <= ARRAY_SIZE(binding_table));
1464
1465 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001466 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001467
1468 switch (slot->path_len) {
1469 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001470 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001471 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001472 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001473 {
1474 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1475
Chia-I Wu72292b72014-09-09 10:48:33 +08001476 offset = cmd_surface_write(cmd,
1477 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1478 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001479
Chia-I Wu72292b72014-09-09 10:48:33 +08001480 cmd_reserve_reloc(cmd, 1);
1481 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1482 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001483 }
1484 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001485 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001486 {
1487 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001488 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001489
Chia-I Wu72292b72014-09-09 10:48:33 +08001490 offset = cmd_surface_write(cmd,
1491 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1492 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001493
Chia-I Wu72292b72014-09-09 10:48:33 +08001494 cmd_reserve_reloc(cmd, 1);
1495 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1496 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001497 }
1498 break;
1499 case 1:
1500 default:
1501 /* TODO */
1502 assert(!"no dset support");
1503 break;
1504 }
1505
Chia-I Wu72292b72014-09-09 10:48:33 +08001506 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001507 }
1508
Chia-I Wu72292b72014-09-09 10:48:33 +08001509 offset = cmd_state_write(cmd, GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
1510 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001511
1512 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1513 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001514 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, offset);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001515
1516 gen7_3dstate_pointer(cmd,
1517 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1518 gen7_3dstate_pointer(cmd,
1519 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1520 gen7_3dstate_pointer(cmd,
1521 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1522 gen7_3dstate_pointer(cmd,
1523 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1524
1525 gen7_3dstate_pointer(cmd,
1526 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1527 gen7_3dstate_pointer(cmd,
1528 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1529 gen7_3dstate_pointer(cmd,
1530 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1531 gen7_3dstate_pointer(cmd,
1532 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1533 gen7_3dstate_pointer(cmd,
1534 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001535 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001536 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001537 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001538 }
1539}
1540
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001541static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1542{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001543 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1544 const struct intel_pipeline_shader *vs = &pipeline->vs;
1545 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001546 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001547 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001548 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001549
1550 CMD_ASSERT(cmd, 6, 7.5);
1551
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001552 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001553 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1554 *
1555 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1556 * 128-bit vertex elements to be passed into the payload for each
1557 * vertex."
1558 *
1559 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1560 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001561 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001562 vue_read_len = (vs->in_count + 1) / 2;
1563 if (!vue_read_len)
1564 vue_read_len = 1;
1565
1566 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1567 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1568
1569 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1570 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1571 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001572
1573 dw5 = GEN6_VS_DW5_STATISTICS |
1574 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001575
1576 switch (cmd_gen(cmd)) {
1577 case INTEL_GEN(7.5):
1578 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1579 break;
1580 case INTEL_GEN(7):
1581 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1582 break;
1583 case INTEL_GEN(6):
1584 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1585 break;
1586 default:
1587 max_threads = 1;
1588 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001589 }
1590
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001591 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1592 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1593 else
1594 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1595
Chia-I Wube0a3d92014-09-02 13:20:59 +08001596 if (pipeline->disable_vs_cache)
1597 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1598
Chia-I Wu72292b72014-09-09 10:48:33 +08001599 cmd_batch_pointer(cmd, cmd_len, &dw);
1600 dw[0] = dw0;
1601 dw[1] = cmd->bind.vs.kernel_offset;
1602 dw[2] = dw2;
1603 dw[3] = 0; /* scratch */
1604 dw[4] = dw4;
1605 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001606}
1607
Chia-I Wu52500102014-08-22 00:46:04 +08001608static void emit_bounded_states(struct intel_cmd *cmd)
1609{
1610 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1611
1612 /* TODO more states */
1613
Chia-I Wu1744cca2014-08-22 11:10:17 +08001614 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001615 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001616 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001617
1618 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1619 &cmd->bind.pipeline.graphics->vs);
1620 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1621 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001622
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001623 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001624 gen7_3DSTATE_SF(cmd);
1625 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001626 gen7_3DSTATE_WM(cmd);
1627 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001628 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001629 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001630 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001631
1632 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1633 &cmd->bind.pipeline.graphics->vs);
1634 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1635 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001636
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001637 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001638 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001639 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001640 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001641
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001642 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu42a56202014-08-23 16:47:48 +08001643
Chia-I Wu8370b402014-08-29 12:28:37 +08001644 cmd_wa_gen6_pre_depth_stall_write(cmd);
1645 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu72292b72014-09-09 10:48:33 +08001646
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001647 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu72292b72014-09-09 10:48:33 +08001648 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001649
1650 gen6_3DSTATE_VS(cmd);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001651}
1652
1653static void emit_shader(struct intel_cmd *cmd,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001654 const struct intel_pipeline_shader *shader,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001655 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001656{
1657 uint32_t i;
1658 struct intel_cmd_shader *cmdShader;
1659
1660 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001661 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001662 /* shader is already part of pipeline */
1663 return;
1664 }
1665 }
1666
Chia-I Wu338fe642014-08-28 10:43:04 +08001667 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1668 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1669
1670 cmdShader = cmd->bind.shaderCache.shaderArray;
1671
1672 cmd->bind.shaderCache.shaderArray =
1673 icd_alloc(sizeof(*cmdShader) * new_count,
1674 0, XGL_SYSTEM_ALLOC_INTERNAL);
1675 if (cmd->bind.shaderCache.shaderArray == NULL) {
1676 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001677 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1678 return;
1679 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001680
1681 if (cmdShader) {
1682 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1683 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1684 icd_free(cmdShader);
1685 }
1686
1687 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001688 }
1689
Chia-I Wu338fe642014-08-28 10:43:04 +08001690 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001691 cmdShader->shader = shader;
Chia-I Wu72292b72014-09-09 10:48:33 +08001692 cmdShader->kernel_offset =
1693 cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001694 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001695 cmd->bind.shaderCache.used++;
1696 return;
1697}
1698
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001699static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001700 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001701{
1702 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001703
Chia-I Wu8370b402014-08-29 12:28:37 +08001704 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1705 cmd_wa_gen6_pre_depth_stall_write(cmd);
1706 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1707 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1708 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1709 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001710
1711 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001712 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001713 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001714
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001715 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001716 emit_shader(cmd, &pipeline->vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001717 }
1718 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001719 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001720 }
1721 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001722 emit_shader(cmd, &pipeline->fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001723 }
1724 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +08001725 emit_shader(cmd, &pipeline->tcs, &cmd->bind.tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001726 }
1727 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +08001728 emit_shader(cmd, &pipeline->tes, &cmd->bind.tes);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001729 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001730
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001731 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1732 gen7_3DSTATE_GS(cmd);
1733 } else {
1734 gen6_3DSTATE_GS(cmd);
1735 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001736
Chia-I Wu8370b402014-08-29 12:28:37 +08001737 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1738 cmd_wa_gen7_post_command_cs_stall(cmd);
1739 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1740 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001741}
1742
1743static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1744 const struct intel_pipeline *pipeline)
1745{
1746 cmd->bind.pipeline.compute = pipeline;
1747}
1748
1749static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1750 const struct intel_pipeline_delta *delta)
1751{
1752 cmd->bind.pipeline.graphics_delta = delta;
1753}
1754
1755static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1756 const struct intel_pipeline_delta *delta)
1757{
1758 cmd->bind.pipeline.compute_delta = delta;
1759}
1760
1761static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1762 const struct intel_dset *dset,
1763 XGL_UINT slot_offset)
1764{
1765 cmd->bind.dset.graphics = dset;
1766 cmd->bind.dset.graphics_offset = slot_offset;
1767}
1768
1769static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1770 const struct intel_dset *dset,
1771 XGL_UINT slot_offset)
1772{
1773 cmd->bind.dset.compute = dset;
1774 cmd->bind.dset.compute_offset = slot_offset;
1775}
1776
1777static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1778 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1779{
1780 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1781}
1782
1783static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1784 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1785{
1786 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1787}
1788
1789static void cmd_bind_index_data(struct intel_cmd *cmd,
1790 const struct intel_mem *mem,
1791 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1792{
1793 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1794 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1795 } else {
1796 cmd->bind.index.mem = mem;
1797 cmd->bind.index.offset = offset;
1798 cmd->bind.index.type = type;
1799 }
1800}
1801
1802static void cmd_bind_rt(struct intel_cmd *cmd,
1803 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1804 XGL_UINT count)
1805{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001806 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001807 XGL_UINT i;
1808
1809 for (i = 0; i < count; i++) {
1810 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1811 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001812 const struct intel_layout *layout = &rt->img->layout;
1813
1814 if (i == 0) {
1815 width = layout->width0;
1816 height = layout->height0;
1817 } else {
1818 if (width > layout->width0)
1819 width = layout->width0;
1820 if (height > layout->height0)
1821 height = layout->height0;
1822 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001823
1824 cmd->bind.att.rt[i] = rt;
1825 }
1826
1827 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001828
Chia-I Wu8370b402014-08-29 12:28:37 +08001829 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001830 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001831}
1832
1833static void cmd_bind_ds(struct intel_cmd *cmd,
1834 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1835{
1836 const struct intel_ds_view *ds;
1837
1838 if (info) {
1839 cmd->bind.att.ds = intel_ds_view(info->view);
1840 ds = cmd->bind.att.ds;
1841 } else {
1842 /* all zeros */
1843 static const struct intel_ds_view null_ds;
1844 ds = &null_ds;
1845 }
1846
Chia-I Wu8370b402014-08-29 12:28:37 +08001847 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001848 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1849 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1850 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001851
1852 if (cmd_gen(cmd) >= INTEL_GEN(7))
1853 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1854 else
1855 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001856}
1857
1858static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1859 const struct intel_viewport_state *state)
1860{
1861 cmd->bind.state.viewport = state;
1862}
1863
1864static void cmd_bind_raster_state(struct intel_cmd *cmd,
1865 const struct intel_raster_state *state)
1866{
1867 cmd->bind.state.raster = state;
1868}
1869
1870static void cmd_bind_ds_state(struct intel_cmd *cmd,
1871 const struct intel_ds_state *state)
1872{
1873 cmd->bind.state.ds = state;
1874}
1875
1876static void cmd_bind_blend_state(struct intel_cmd *cmd,
1877 const struct intel_blend_state *state)
1878{
1879 cmd->bind.state.blend = state;
1880}
1881
1882static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1883 const struct intel_msaa_state *state)
1884{
1885 cmd->bind.state.msaa = state;
1886}
1887
1888static void cmd_draw(struct intel_cmd *cmd,
1889 XGL_UINT vertex_start,
1890 XGL_UINT vertex_count,
1891 XGL_UINT instance_start,
1892 XGL_UINT instance_count,
1893 bool indexed,
1894 XGL_UINT vertex_base)
1895{
1896 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1897
1898 emit_bounded_states(cmd);
1899
1900 if (indexed) {
1901 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1902 cmd->result = XGL_ERROR_UNKNOWN;
1903
1904 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1905 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1906 p->primitive_restart_index);
1907 } else {
1908 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1909 cmd->bind.index.offset, cmd->bind.index.type,
1910 p->primitive_restart);
1911 }
1912 } else {
1913 assert(!vertex_base);
1914 }
1915
1916 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1917 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1918 vertex_start, instance_count, instance_start, vertex_base);
1919 } else {
1920 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1921 vertex_start, instance_count, instance_start, vertex_base);
1922 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001923
Chia-I Wu707a29e2014-08-27 12:51:47 +08001924 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001925 /* need to re-emit all workarounds */
1926 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001927}
1928
Chia-I Wub2755562014-08-20 13:38:52 +08001929XGL_VOID XGLAPI intelCmdBindPipeline(
1930 XGL_CMD_BUFFER cmdBuffer,
1931 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1932 XGL_PIPELINE pipeline)
1933{
1934 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1935
1936 switch (pipelineBindPoint) {
1937 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001938 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001939 break;
1940 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001941 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001942 break;
1943 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001944 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001945 break;
1946 }
1947}
1948
1949XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1950 XGL_CMD_BUFFER cmdBuffer,
1951 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1952 XGL_PIPELINE_DELTA delta)
1953{
1954 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1955
1956 switch (pipelineBindPoint) {
1957 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001958 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001959 break;
1960 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001961 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001962 break;
1963 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001964 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001965 break;
1966 }
1967}
1968
1969XGL_VOID XGLAPI intelCmdBindStateObject(
1970 XGL_CMD_BUFFER cmdBuffer,
1971 XGL_STATE_BIND_POINT stateBindPoint,
1972 XGL_STATE_OBJECT state)
1973{
1974 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1975
1976 switch (stateBindPoint) {
1977 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001978 cmd_bind_viewport_state(cmd,
1979 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001980 break;
1981 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001982 cmd_bind_raster_state(cmd,
1983 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001984 break;
1985 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001986 cmd_bind_ds_state(cmd,
1987 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001988 break;
1989 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001990 cmd_bind_blend_state(cmd,
1991 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001992 break;
1993 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001994 cmd_bind_msaa_state(cmd,
1995 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001996 break;
1997 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001998 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001999 break;
2000 }
2001}
2002
2003XGL_VOID XGLAPI intelCmdBindDescriptorSet(
2004 XGL_CMD_BUFFER cmdBuffer,
2005 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2006 XGL_UINT index,
2007 XGL_DESCRIPTOR_SET descriptorSet,
2008 XGL_UINT slotOffset)
2009{
2010 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2011 struct intel_dset *dset = intel_dset(descriptorSet);
2012
2013 assert(!index);
2014
2015 switch (pipelineBindPoint) {
2016 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002017 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002018 break;
2019 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002020 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002021 break;
2022 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002023 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002024 break;
2025 }
2026}
2027
2028XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
2029 XGL_CMD_BUFFER cmdBuffer,
2030 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2031 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
2032{
2033 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2034
2035 switch (pipelineBindPoint) {
2036 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002037 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002038 break;
2039 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002040 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002041 break;
2042 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002043 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002044 break;
2045 }
2046}
2047
2048XGL_VOID XGLAPI intelCmdBindIndexData(
2049 XGL_CMD_BUFFER cmdBuffer,
2050 XGL_GPU_MEMORY mem_,
2051 XGL_GPU_SIZE offset,
2052 XGL_INDEX_TYPE indexType)
2053{
2054 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2055 struct intel_mem *mem = intel_mem(mem_);
2056
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002057 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08002058}
2059
2060XGL_VOID XGLAPI intelCmdBindAttachments(
2061 XGL_CMD_BUFFER cmdBuffer,
2062 XGL_UINT colorAttachmentCount,
2063 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
2064 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
2065{
2066 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08002067
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002068 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
2069 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08002070}
2071
2072XGL_VOID XGLAPI intelCmdDraw(
2073 XGL_CMD_BUFFER cmdBuffer,
2074 XGL_UINT firstVertex,
2075 XGL_UINT vertexCount,
2076 XGL_UINT firstInstance,
2077 XGL_UINT instanceCount)
2078{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002079 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002080
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002081 cmd_draw(cmd, firstVertex, vertexCount,
2082 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08002083}
2084
2085XGL_VOID XGLAPI intelCmdDrawIndexed(
2086 XGL_CMD_BUFFER cmdBuffer,
2087 XGL_UINT firstIndex,
2088 XGL_UINT indexCount,
2089 XGL_INT vertexOffset,
2090 XGL_UINT firstInstance,
2091 XGL_UINT instanceCount)
2092{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002093 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002094
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002095 cmd_draw(cmd, firstIndex, indexCount,
2096 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002097}
2098
2099XGL_VOID XGLAPI intelCmdDrawIndirect(
2100 XGL_CMD_BUFFER cmdBuffer,
2101 XGL_GPU_MEMORY mem,
2102 XGL_GPU_SIZE offset,
2103 XGL_UINT32 count,
2104 XGL_UINT32 stride)
2105{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002106 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2107
2108 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002109}
2110
2111XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2112 XGL_CMD_BUFFER cmdBuffer,
2113 XGL_GPU_MEMORY mem,
2114 XGL_GPU_SIZE offset,
2115 XGL_UINT32 count,
2116 XGL_UINT32 stride)
2117{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002118 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2119
2120 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002121}
2122
2123XGL_VOID XGLAPI intelCmdDispatch(
2124 XGL_CMD_BUFFER cmdBuffer,
2125 XGL_UINT x,
2126 XGL_UINT y,
2127 XGL_UINT z)
2128{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002129 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2130
2131 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002132}
2133
2134XGL_VOID XGLAPI intelCmdDispatchIndirect(
2135 XGL_CMD_BUFFER cmdBuffer,
2136 XGL_GPU_MEMORY mem,
2137 XGL_GPU_SIZE offset)
2138{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002139 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2140
2141 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002142}