blob: abd5cde10c8187c6eaa7ea42aef5d86de20081cf [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 Wu72292b72014-09-09 10:48:33 +08001297 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001298
1299 if (!viewport)
1300 return;
1301
Chia-I Wu00b51a82014-09-09 12:07:37 +08001302 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1303 viewport->cmd_align * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001304 viewport->cmd_len, viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001305
1306 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001307 offset + (viewport->cmd_clip_offset << 2),
1308 offset,
1309 offset + (viewport->cmd_cc_offset << 2));
Chia-I Wu1744cca2014-08-22 11:10:17 +08001310
Chia-I Wu72292b72014-09-09 10:48:33 +08001311 offset = (viewport->scissor_enable) ?
1312 offset + (viewport->cmd_scissor_rect_offset << 2) : 0;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001313
Chia-I Wu72292b72014-09-09 10:48:33 +08001314 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001315}
1316
Chia-I Wu302742d2014-08-22 10:28:29 +08001317static void gen7_cc_states(struct intel_cmd *cmd)
1318{
1319 const struct intel_blend_state *blend = cmd->bind.state.blend;
1320 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001321 uint32_t stencil_ref;
1322 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001323 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001324
1325 CMD_ASSERT(cmd, 7, 7.5);
1326
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001327 if (!blend && !ds)
1328 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001329
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001330 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001331 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001332 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001333 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001334
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001335 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1336 } else {
1337 memset(blend_color, 0, sizeof(blend_color));
1338 }
1339
1340 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001341 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001342 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001343 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1344 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001345 } else {
1346 stencil_ref = 0;
1347 }
1348
Chia-I Wu72292b72014-09-09 10:48:33 +08001349 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001350 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001351 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001352}
1353
Chia-I Wu1744cca2014-08-22 11:10:17 +08001354static void gen7_viewport_states(struct intel_cmd *cmd)
1355{
1356 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001357 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001358
1359 if (!viewport)
1360 return;
1361
Chia-I Wu00b51a82014-09-09 12:07:37 +08001362 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1363 viewport->cmd_align * 4, viewport->cmd_len, viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001364
1365 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001366 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1367 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001368 gen7_3dstate_pointer(cmd,
1369 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wu72292b72014-09-09 10:48:33 +08001370 offset + (viewport->cmd_cc_offset << 2));
1371
Chia-I Wu1744cca2014-08-22 11:10:17 +08001372 if (viewport->scissor_enable) {
1373 gen7_3dstate_pointer(cmd,
1374 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wu72292b72014-09-09 10:48:33 +08001375 offset + (viewport->cmd_scissor_rect_offset << 2));
Chia-I Wu1744cca2014-08-22 11:10:17 +08001376 }
1377}
1378
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001379static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001380 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001381{
1382 const uint8_t cmd_len = 5;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001383 /*
1384 * TODO It is actually 2048 for non-VS PCB. But we need to upload the
1385 * data to multiple PCBs when the size is greater than 1024.
1386 */
1387 const XGL_UINT max_size = 1024;
Chia-I Wu72292b72014-09-09 10:48:33 +08001388 uint32_t offset, dw0, *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001389
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001390 if (sh->pcb_size > max_size) {
1391 cmd->result = XGL_ERROR_UNKNOWN;
1392 return;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001393 }
1394
1395 dw0 = GEN6_RENDER_TYPE_RENDER |
1396 GEN6_RENDER_SUBTYPE_3D |
1397 subop |
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001398 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001399 offset = 0;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001400
1401 if (sh->pcb_size) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001402 const XGL_SIZE alignment = 32;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001403 const XGL_SIZE size = u_align(sh->pcb_size, alignment);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001404
Chia-I Wu00b51a82014-09-09 12:07:37 +08001405 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB, alignment,
Chia-I Wu72292b72014-09-09 10:48:33 +08001406 size / sizeof(uint32_t), &dw);
1407 memcpy(dw, sh->pcb, sh->pcb_size);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001408
1409 dw0 |= GEN6_PCB_ANY_DW0_PCB0_VALID;
Chia-I Wu72292b72014-09-09 10:48:33 +08001410 offset |= size / alignment - 1;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001411 }
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001412
Chia-I Wu72292b72014-09-09 10:48:33 +08001413 cmd_batch_pointer(cmd, cmd_len, &dw);
1414 dw[0] = dw0;
1415 dw[1] = offset;
1416 dw[2] = 0;
1417 dw[3] = 0;
1418 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001419}
1420
1421static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001422 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001423{
1424 const uint8_t cmd_len = 7;
1425 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1426 GEN6_RENDER_SUBTYPE_3D |
1427 subop |
1428 (cmd_len - 2);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001429 const XGL_UINT max_size = 2048;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001430 XGL_UINT pcb_len = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001431 uint32_t offset = 0, *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001432
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001433 if (sh->pcb_size > max_size) {
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001434 cmd->result = XGL_ERROR_UNKNOWN;
1435 return;
1436 }
1437
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001438 if (sh->pcb_size) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001439 const XGL_SIZE alignment = 32;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001440 const XGL_SIZE size = u_align(sh->pcb_size, alignment);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001441
1442 pcb_len = size / alignment;
1443
Chia-I Wu00b51a82014-09-09 12:07:37 +08001444 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB, alignment,
Chia-I Wu72292b72014-09-09 10:48:33 +08001445 size / sizeof(uint32_t), &dw);
1446 memcpy(dw, sh->pcb, sh->pcb_size);
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001447 }
1448
Chia-I Wu72292b72014-09-09 10:48:33 +08001449 cmd_batch_pointer(cmd, cmd_len, &dw);
1450 dw[0] = dw0;
1451 dw[1] = pcb_len;
1452 dw[2] = 0;
1453 dw[3] = offset;
1454 dw[4] = 0;
1455 dw[5] = 0;
1456 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001457}
1458
Chia-I Wu42a56202014-08-23 16:47:48 +08001459static void emit_ps_resources(struct intel_cmd *cmd,
Chia-I Wu20983762014-09-02 12:07:28 +08001460 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001461{
1462 const XGL_UINT surface_count = rmap->rt_count +
1463 rmap->resource_count + rmap->uav_count;
Chia-I Wu72292b72014-09-09 10:48:33 +08001464 uint32_t binding_table[256], offset;
1465 XGL_UINT i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001466
1467 assert(surface_count <= ARRAY_SIZE(binding_table));
1468
1469 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001470 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001471
1472 switch (slot->path_len) {
1473 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001474 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001475 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001476 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001477 {
1478 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1479
Chia-I Wu00b51a82014-09-09 12:07:37 +08001480 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001481 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1482 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001483
Chia-I Wu72292b72014-09-09 10:48:33 +08001484 cmd_reserve_reloc(cmd, 1);
1485 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1486 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001487 }
1488 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001489 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001490 {
1491 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001492 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001493
Chia-I Wu00b51a82014-09-09 12:07:37 +08001494 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001495 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1496 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001497
Chia-I Wu72292b72014-09-09 10:48:33 +08001498 cmd_reserve_reloc(cmd, 1);
1499 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1500 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001501 }
1502 break;
1503 case 1:
1504 default:
1505 /* TODO */
1506 assert(!"no dset support");
1507 break;
1508 }
1509
Chia-I Wu72292b72014-09-09 10:48:33 +08001510 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001511 }
1512
Chia-I Wu00b51a82014-09-09 12:07:37 +08001513 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
1514 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001515 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001516
1517 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1518 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001519 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS, offset);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001520
1521 gen7_3dstate_pointer(cmd,
1522 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS, 0);
1523 gen7_3dstate_pointer(cmd,
1524 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS, 0);
1525 gen7_3dstate_pointer(cmd,
1526 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS, 0);
1527 gen7_3dstate_pointer(cmd,
1528 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS, 0);
1529
1530 gen7_3dstate_pointer(cmd,
1531 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS, 0);
1532 gen7_3dstate_pointer(cmd,
1533 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS, 0);
1534 gen7_3dstate_pointer(cmd,
1535 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS, 0);
1536 gen7_3dstate_pointer(cmd,
1537 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS, 0);
1538 gen7_3dstate_pointer(cmd,
1539 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001540 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001541 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu257e75e2014-08-29 14:06:35 +08001542 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd, 0, 0, 0);
Chia-I Wu42a56202014-08-23 16:47:48 +08001543 }
1544}
1545
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001546static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1547{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001548 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1549 const struct intel_pipeline_shader *vs = &pipeline->vs;
1550 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001551 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001552 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001553 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001554
1555 CMD_ASSERT(cmd, 6, 7.5);
1556
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001557 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001558 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1559 *
1560 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1561 * 128-bit vertex elements to be passed into the payload for each
1562 * vertex."
1563 *
1564 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1565 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001566 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001567 vue_read_len = (vs->in_count + 1) / 2;
1568 if (!vue_read_len)
1569 vue_read_len = 1;
1570
1571 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1572 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1573
1574 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1575 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1576 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001577
1578 dw5 = GEN6_VS_DW5_STATISTICS |
1579 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001580
1581 switch (cmd_gen(cmd)) {
1582 case INTEL_GEN(7.5):
1583 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1584 break;
1585 case INTEL_GEN(7):
1586 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1587 break;
1588 case INTEL_GEN(6):
1589 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1590 break;
1591 default:
1592 max_threads = 1;
1593 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001594 }
1595
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001596 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1597 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1598 else
1599 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1600
Chia-I Wube0a3d92014-09-02 13:20:59 +08001601 if (pipeline->disable_vs_cache)
1602 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1603
Chia-I Wu72292b72014-09-09 10:48:33 +08001604 cmd_batch_pointer(cmd, cmd_len, &dw);
1605 dw[0] = dw0;
1606 dw[1] = cmd->bind.vs.kernel_offset;
1607 dw[2] = dw2;
1608 dw[3] = 0; /* scratch */
1609 dw[4] = dw4;
1610 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001611}
1612
Chia-I Wu52500102014-08-22 00:46:04 +08001613static void emit_bounded_states(struct intel_cmd *cmd)
1614{
1615 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1616
1617 /* TODO more states */
1618
Chia-I Wu1744cca2014-08-22 11:10:17 +08001619 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001620 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001621 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001622
1623 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1624 &cmd->bind.pipeline.graphics->vs);
1625 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1626 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001627
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001628 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001629 gen7_3DSTATE_SF(cmd);
1630 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001631 gen7_3DSTATE_WM(cmd);
1632 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001633 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001634 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001635 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001636
1637 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1638 &cmd->bind.pipeline.graphics->vs);
1639 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1640 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001641
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001642 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001643 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001644 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001645 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001646
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001647 emit_ps_resources(cmd, cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu42a56202014-08-23 16:47:48 +08001648
Chia-I Wu8370b402014-08-29 12:28:37 +08001649 cmd_wa_gen6_pre_depth_stall_write(cmd);
1650 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu72292b72014-09-09 10:48:33 +08001651
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001652 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu72292b72014-09-09 10:48:33 +08001653 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001654
1655 gen6_3DSTATE_VS(cmd);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001656}
1657
1658static void emit_shader(struct intel_cmd *cmd,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001659 const struct intel_pipeline_shader *shader,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001660 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001661{
1662 uint32_t i;
1663 struct intel_cmd_shader *cmdShader;
1664
1665 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001666 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001667 /* shader is already part of pipeline */
1668 return;
1669 }
1670 }
1671
Chia-I Wu338fe642014-08-28 10:43:04 +08001672 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1673 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1674
1675 cmdShader = cmd->bind.shaderCache.shaderArray;
1676
1677 cmd->bind.shaderCache.shaderArray =
1678 icd_alloc(sizeof(*cmdShader) * new_count,
1679 0, XGL_SYSTEM_ALLOC_INTERNAL);
1680 if (cmd->bind.shaderCache.shaderArray == NULL) {
1681 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001682 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1683 return;
1684 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001685
1686 if (cmdShader) {
1687 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1688 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1689 icd_free(cmdShader);
1690 }
1691
1692 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001693 }
1694
Chia-I Wu338fe642014-08-28 10:43:04 +08001695 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001696 cmdShader->shader = shader;
Chia-I Wu72292b72014-09-09 10:48:33 +08001697 cmdShader->kernel_offset =
1698 cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001699 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001700 cmd->bind.shaderCache.used++;
1701 return;
1702}
1703
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001704static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001705 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001706{
1707 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001708
Chia-I Wu8370b402014-08-29 12:28:37 +08001709 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1710 cmd_wa_gen6_pre_depth_stall_write(cmd);
1711 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1712 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1713 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1714 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001715
1716 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001717 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001718 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001719
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001720 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001721 emit_shader(cmd, &pipeline->vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001722 }
1723 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001724 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001725 }
1726 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001727 emit_shader(cmd, &pipeline->fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001728 }
1729 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +08001730 emit_shader(cmd, &pipeline->tcs, &cmd->bind.tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001731 }
1732 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +08001733 emit_shader(cmd, &pipeline->tes, &cmd->bind.tes);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001734 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001735
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001736 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1737 gen7_3DSTATE_GS(cmd);
1738 } else {
1739 gen6_3DSTATE_GS(cmd);
1740 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001741
Chia-I Wu8370b402014-08-29 12:28:37 +08001742 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1743 cmd_wa_gen7_post_command_cs_stall(cmd);
1744 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1745 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001746}
1747
1748static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
1749 const struct intel_pipeline *pipeline)
1750{
1751 cmd->bind.pipeline.compute = pipeline;
1752}
1753
1754static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
1755 const struct intel_pipeline_delta *delta)
1756{
1757 cmd->bind.pipeline.graphics_delta = delta;
1758}
1759
1760static void cmd_bind_compute_delta(struct intel_cmd *cmd,
1761 const struct intel_pipeline_delta *delta)
1762{
1763 cmd->bind.pipeline.compute_delta = delta;
1764}
1765
1766static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
1767 const struct intel_dset *dset,
1768 XGL_UINT slot_offset)
1769{
1770 cmd->bind.dset.graphics = dset;
1771 cmd->bind.dset.graphics_offset = slot_offset;
1772}
1773
1774static void cmd_bind_compute_dset(struct intel_cmd *cmd,
1775 const struct intel_dset *dset,
1776 XGL_UINT slot_offset)
1777{
1778 cmd->bind.dset.compute = dset;
1779 cmd->bind.dset.compute_offset = slot_offset;
1780}
1781
1782static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
1783 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1784{
1785 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
1786}
1787
1788static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
1789 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
1790{
1791 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
1792}
1793
1794static void cmd_bind_index_data(struct intel_cmd *cmd,
1795 const struct intel_mem *mem,
1796 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
1797{
1798 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1799 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
1800 } else {
1801 cmd->bind.index.mem = mem;
1802 cmd->bind.index.offset = offset;
1803 cmd->bind.index.type = type;
1804 }
1805}
1806
1807static void cmd_bind_rt(struct intel_cmd *cmd,
1808 const XGL_COLOR_ATTACHMENT_BIND_INFO *attachments,
1809 XGL_UINT count)
1810{
Chia-I Wud88e02d2014-08-25 10:56:13 +08001811 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001812 XGL_UINT i;
1813
1814 for (i = 0; i < count; i++) {
1815 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &attachments[i];
1816 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001817 const struct intel_layout *layout = &rt->img->layout;
1818
1819 if (i == 0) {
1820 width = layout->width0;
1821 height = layout->height0;
1822 } else {
1823 if (width > layout->width0)
1824 width = layout->width0;
1825 if (height > layout->height0)
1826 height = layout->height0;
1827 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001828
1829 cmd->bind.att.rt[i] = rt;
1830 }
1831
1832 cmd->bind.att.rt_count = count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08001833
Chia-I Wu8370b402014-08-29 12:28:37 +08001834 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wud88e02d2014-08-25 10:56:13 +08001835 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, width, height);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001836}
1837
1838static void cmd_bind_ds(struct intel_cmd *cmd,
1839 const XGL_DEPTH_STENCIL_BIND_INFO *info)
1840{
1841 const struct intel_ds_view *ds;
1842
1843 if (info) {
1844 cmd->bind.att.ds = intel_ds_view(info->view);
1845 ds = cmd->bind.att.ds;
1846 } else {
1847 /* all zeros */
1848 static const struct intel_ds_view null_ds;
1849 ds = &null_ds;
1850 }
1851
Chia-I Wu8370b402014-08-29 12:28:37 +08001852 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001853 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1854 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1855 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
Chia-I Wuf8231032014-08-25 10:44:45 +08001856
1857 if (cmd_gen(cmd) >= INTEL_GEN(7))
1858 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1859 else
1860 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001861}
1862
1863static void cmd_bind_viewport_state(struct intel_cmd *cmd,
1864 const struct intel_viewport_state *state)
1865{
1866 cmd->bind.state.viewport = state;
1867}
1868
1869static void cmd_bind_raster_state(struct intel_cmd *cmd,
1870 const struct intel_raster_state *state)
1871{
1872 cmd->bind.state.raster = state;
1873}
1874
1875static void cmd_bind_ds_state(struct intel_cmd *cmd,
1876 const struct intel_ds_state *state)
1877{
1878 cmd->bind.state.ds = state;
1879}
1880
1881static void cmd_bind_blend_state(struct intel_cmd *cmd,
1882 const struct intel_blend_state *state)
1883{
1884 cmd->bind.state.blend = state;
1885}
1886
1887static void cmd_bind_msaa_state(struct intel_cmd *cmd,
1888 const struct intel_msaa_state *state)
1889{
1890 cmd->bind.state.msaa = state;
1891}
1892
1893static void cmd_draw(struct intel_cmd *cmd,
1894 XGL_UINT vertex_start,
1895 XGL_UINT vertex_count,
1896 XGL_UINT instance_start,
1897 XGL_UINT instance_count,
1898 bool indexed,
1899 XGL_UINT vertex_base)
1900{
1901 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
1902
1903 emit_bounded_states(cmd);
1904
1905 if (indexed) {
1906 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
1907 cmd->result = XGL_ERROR_UNKNOWN;
1908
1909 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
1910 gen75_3DSTATE_VF(cmd, p->primitive_restart,
1911 p->primitive_restart_index);
1912 } else {
1913 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
1914 cmd->bind.index.offset, cmd->bind.index.type,
1915 p->primitive_restart);
1916 }
1917 } else {
1918 assert(!vertex_base);
1919 }
1920
1921 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1922 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1923 vertex_start, instance_count, instance_start, vertex_base);
1924 } else {
1925 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
1926 vertex_start, instance_count, instance_start, vertex_base);
1927 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08001928
Chia-I Wu707a29e2014-08-27 12:51:47 +08001929 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001930 /* need to re-emit all workarounds */
1931 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001932}
1933
Chia-I Wub2755562014-08-20 13:38:52 +08001934XGL_VOID XGLAPI intelCmdBindPipeline(
1935 XGL_CMD_BUFFER cmdBuffer,
1936 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1937 XGL_PIPELINE pipeline)
1938{
1939 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1940
1941 switch (pipelineBindPoint) {
1942 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001943 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001944 break;
1945 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001946 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08001947 break;
1948 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001949 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001950 break;
1951 }
1952}
1953
1954XGL_VOID XGLAPI intelCmdBindPipelineDelta(
1955 XGL_CMD_BUFFER cmdBuffer,
1956 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
1957 XGL_PIPELINE_DELTA delta)
1958{
1959 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1960
1961 switch (pipelineBindPoint) {
1962 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001963 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001964 break;
1965 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001966 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08001967 break;
1968 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001969 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08001970 break;
1971 }
1972}
1973
1974XGL_VOID XGLAPI intelCmdBindStateObject(
1975 XGL_CMD_BUFFER cmdBuffer,
1976 XGL_STATE_BIND_POINT stateBindPoint,
1977 XGL_STATE_OBJECT state)
1978{
1979 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
1980
1981 switch (stateBindPoint) {
1982 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001983 cmd_bind_viewport_state(cmd,
1984 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001985 break;
1986 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001987 cmd_bind_raster_state(cmd,
1988 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001989 break;
1990 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001991 cmd_bind_ds_state(cmd,
1992 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001993 break;
1994 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001995 cmd_bind_blend_state(cmd,
1996 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08001997 break;
1998 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001999 cmd_bind_msaa_state(cmd,
2000 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002001 break;
2002 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002003 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002004 break;
2005 }
2006}
2007
2008XGL_VOID XGLAPI intelCmdBindDescriptorSet(
2009 XGL_CMD_BUFFER cmdBuffer,
2010 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2011 XGL_UINT index,
2012 XGL_DESCRIPTOR_SET descriptorSet,
2013 XGL_UINT slotOffset)
2014{
2015 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2016 struct intel_dset *dset = intel_dset(descriptorSet);
2017
2018 assert(!index);
2019
2020 switch (pipelineBindPoint) {
2021 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002022 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002023 break;
2024 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002025 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002026 break;
2027 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002028 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002029 break;
2030 }
2031}
2032
2033XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
2034 XGL_CMD_BUFFER cmdBuffer,
2035 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2036 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
2037{
2038 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2039
2040 switch (pipelineBindPoint) {
2041 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002042 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002043 break;
2044 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002045 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002046 break;
2047 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002048 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002049 break;
2050 }
2051}
2052
2053XGL_VOID XGLAPI intelCmdBindIndexData(
2054 XGL_CMD_BUFFER cmdBuffer,
2055 XGL_GPU_MEMORY mem_,
2056 XGL_GPU_SIZE offset,
2057 XGL_INDEX_TYPE indexType)
2058{
2059 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2060 struct intel_mem *mem = intel_mem(mem_);
2061
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002062 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08002063}
2064
2065XGL_VOID XGLAPI intelCmdBindAttachments(
2066 XGL_CMD_BUFFER cmdBuffer,
2067 XGL_UINT colorAttachmentCount,
2068 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
2069 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
2070{
2071 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08002072
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002073 cmd_bind_rt(cmd, pColorAttachments, colorAttachmentCount);
2074 cmd_bind_ds(cmd, pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08002075}
2076
2077XGL_VOID XGLAPI intelCmdDraw(
2078 XGL_CMD_BUFFER cmdBuffer,
2079 XGL_UINT firstVertex,
2080 XGL_UINT vertexCount,
2081 XGL_UINT firstInstance,
2082 XGL_UINT instanceCount)
2083{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002084 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002085
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002086 cmd_draw(cmd, firstVertex, vertexCount,
2087 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08002088}
2089
2090XGL_VOID XGLAPI intelCmdDrawIndexed(
2091 XGL_CMD_BUFFER cmdBuffer,
2092 XGL_UINT firstIndex,
2093 XGL_UINT indexCount,
2094 XGL_INT vertexOffset,
2095 XGL_UINT firstInstance,
2096 XGL_UINT instanceCount)
2097{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002098 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002099
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002100 cmd_draw(cmd, firstIndex, indexCount,
2101 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002102}
2103
2104XGL_VOID XGLAPI intelCmdDrawIndirect(
2105 XGL_CMD_BUFFER cmdBuffer,
2106 XGL_GPU_MEMORY mem,
2107 XGL_GPU_SIZE offset,
2108 XGL_UINT32 count,
2109 XGL_UINT32 stride)
2110{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002111 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2112
2113 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002114}
2115
2116XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2117 XGL_CMD_BUFFER cmdBuffer,
2118 XGL_GPU_MEMORY mem,
2119 XGL_GPU_SIZE offset,
2120 XGL_UINT32 count,
2121 XGL_UINT32 stride)
2122{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002123 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2124
2125 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002126}
2127
2128XGL_VOID XGLAPI intelCmdDispatch(
2129 XGL_CMD_BUFFER cmdBuffer,
2130 XGL_UINT x,
2131 XGL_UINT y,
2132 XGL_UINT z)
2133{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002134 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2135
2136 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002137}
2138
2139XGL_VOID XGLAPI intelCmdDispatchIndirect(
2140 XGL_CMD_BUFFER cmdBuffer,
2141 XGL_GPU_MEMORY mem,
2142 XGL_GPU_SIZE offset)
2143{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002144 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2145
2146 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002147}