blob: c3d911068c0d778ccb18af521e504571f5249607 [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 Wufc05a2e2014-10-07 00:34:13 +080034#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080035#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080036#include "state.h"
37#include "view.h"
38#include "cmd_priv.h"
39
Chia-I Wu59c097e2014-08-21 10:51:07 +080040static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080041 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080042 uint32_t vertex_count,
43 uint32_t vertex_start,
44 uint32_t instance_count,
45 uint32_t instance_start,
46 uint32_t vertex_base)
47{
48 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080049 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080050
51 CMD_ASSERT(cmd, 6, 6);
52
Chia-I Wu426072d2014-08-26 14:31:55 +080053 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080054 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080055 (cmd_len - 2);
56
57 if (indexed)
58 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
59
Chia-I Wu72292b72014-09-09 10:48:33 +080060 cmd_batch_pointer(cmd, cmd_len, &dw);
61 dw[0] = dw0;
62 dw[1] = vertex_count;
63 dw[2] = vertex_start;
64 dw[3] = instance_count;
65 dw[4] = instance_start;
66 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080067}
68
69static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080070 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080071 uint32_t vertex_count,
72 uint32_t vertex_start,
73 uint32_t instance_count,
74 uint32_t instance_start,
75 uint32_t vertex_base)
76{
77 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080078 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080079
80 CMD_ASSERT(cmd, 7, 7.5);
81
Chia-I Wu426072d2014-08-26 14:31:55 +080082 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080083 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080084
85 if (indexed)
86 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
87
Chia-I Wu72292b72014-09-09 10:48:33 +080088 cmd_batch_pointer(cmd, cmd_len, &dw);
89 dw[0] = dw0;
90 dw[1] = dw1;
91 dw[2] = vertex_count;
92 dw[3] = vertex_start;
93 dw[4] = instance_count;
94 dw[5] = instance_start;
95 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080096}
97
Chia-I Wu270b1e82014-08-25 15:53:39 +080098static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +080099 struct intel_bo *bo, uint32_t bo_offset,
100 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800101{
102 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800103 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800104 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800105 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800106 uint32_t *dw;
107 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800108
109 CMD_ASSERT(cmd, 6, 7.5);
110
111 assert(bo_offset % 8 == 0);
112
113 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
114 /*
115 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
116 *
117 * "1 of the following must also be set (when CS stall is set):
118 *
119 * * Depth Cache Flush Enable ([0] of DW1)
120 * * Stall at Pixel Scoreboard ([1] of DW1)
121 * * Depth Stall ([13] of DW1)
122 * * Post-Sync Operation ([13] of DW1)
123 * * Render Target Cache Flush Enable ([12] of DW1)
124 * * Notify Enable ([8] of DW1)"
125 *
126 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
127 *
128 * "One of the following must also be set (when CS stall is set):
129 *
130 * * Render Target Cache Flush Enable ([12] of DW1)
131 * * Depth Cache Flush Enable ([0] of DW1)
132 * * Stall at Pixel Scoreboard ([1] of DW1)
133 * * Depth Stall ([13] of DW1)
134 * * Post-Sync Operation ([13] of DW1)"
135 */
136 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
137 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
138 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
139 GEN6_PIPE_CONTROL_DEPTH_STALL;
140
141 /* post-sync op */
142 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
143 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
144 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
145
146 if (cmd_gen(cmd) == INTEL_GEN(6))
147 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
148
149 assert(dw1 & bit_test);
150 }
151
152 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
153 /*
154 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
155 *
156 * "Following bits must be clear (when Depth Stall is set):
157 *
158 * * Render Target Cache Flush Enable ([12] of DW1)
159 * * Depth Cache Flush Enable ([0] of DW1)"
160 */
161 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
162 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
163 }
164
165 /*
166 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
167 *
168 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
169 * and PIPE_CONTROL are not supported."
170 *
171 * The kernel will add the mapping automatically (when write domain is
172 * INTEL_DOMAIN_INSTRUCTION).
173 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800174 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800175 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 reloc_flags |= INTEL_RELOC_GGTT;
177 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800178
Chia-I Wu72292b72014-09-09 10:48:33 +0800179 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
180 dw[0] = dw0;
181 dw[1] = dw1;
182 dw[2] = 0;
183 dw[3] = (uint32_t) imm;
184 dw[4] = (uint32_t) (imm >> 32);
185
186 if (bo) {
187 cmd_reserve_reloc(cmd, 1);
188 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
189 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800190}
191
Chia-I Wu254db422014-08-21 11:54:29 +0800192static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
193{
194 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
195 bool supported;
196
197 CMD_ASSERT(cmd, 6, 7.5);
198
199 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
200 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
201
202 switch (p->prim_type) {
203 case GEN6_3DPRIM_POINTLIST:
204 case GEN6_3DPRIM_LINELIST:
205 case GEN6_3DPRIM_LINESTRIP:
206 case GEN6_3DPRIM_TRILIST:
207 case GEN6_3DPRIM_TRISTRIP:
208 supported = true;
209 break;
210 default:
211 supported = false;
212 break;
213 }
214
215 if (!supported)
216 return false;
217
218 switch (cmd->bind.index.type) {
219 case XGL_INDEX_8:
220 supported = (p->primitive_restart_index != 0xffu);
221 break;
222 case XGL_INDEX_16:
223 supported = (p->primitive_restart_index != 0xffffu);
224 break;
225 case XGL_INDEX_32:
226 supported = (p->primitive_restart_index != 0xffffffffu);
227 break;
228 default:
229 supported = false;
230 break;
231 }
232
233 return supported;
234}
235
Chia-I Wu59c097e2014-08-21 10:51:07 +0800236static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800237 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238 XGL_GPU_SIZE offset,
239 XGL_INDEX_TYPE type,
240 bool enable_cut_index)
241{
242 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800243 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800244 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246
247 CMD_ASSERT(cmd, 6, 7.5);
248
Chia-I Wu426072d2014-08-26 14:31:55 +0800249 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800250
251 /* the bit is moved to 3DSTATE_VF */
252 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
253 assert(!enable_cut_index);
254 if (enable_cut_index)
255 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
256
257 switch (type) {
258 case XGL_INDEX_8:
259 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
260 offset_align = 1;
261 break;
262 case XGL_INDEX_16:
263 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
264 offset_align = 2;
265 break;
266 case XGL_INDEX_32:
267 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
268 offset_align = 4;
269 break;
270 default:
271 cmd->result = XGL_ERROR_INVALID_VALUE;
272 return;
273 break;
274 }
275
276 if (offset % offset_align) {
277 cmd->result = XGL_ERROR_INVALID_VALUE;
278 return;
279 }
280
281 /* aligned and inclusive */
282 end_offset = mem->size - (mem->size % offset_align) - 1;
283
Chia-I Wu72292b72014-09-09 10:48:33 +0800284 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
285 dw[0] = dw0;
286
287 cmd_reserve_reloc(cmd, 2);
288 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
289 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800290}
291
Chia-I Wu62a7f252014-08-29 11:31:16 +0800292static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
293 bool enable_cut_index,
294 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800295{
296 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800297 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800298
299 CMD_ASSERT(cmd, 7.5, 7.5);
300
Chia-I Wu426072d2014-08-26 14:31:55 +0800301 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800302 if (enable_cut_index)
303 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
304
Chia-I Wu72292b72014-09-09 10:48:33 +0800305 cmd_batch_pointer(cmd, cmd_len, &dw);
306 dw[0] = dw0;
307 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800308}
309
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600310
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800311static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
312{
313 const uint8_t cmd_len = 7;
314 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800315 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800316
317 CMD_ASSERT(cmd, 6, 6);
318
319 assert(cmd->bind.gs.shader == NULL);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
339 assert(cmd->bind.gs.shader == NULL);
340
Chia-I Wu72292b72014-09-09 10:48:33 +0800341 cmd_batch_pointer(cmd, cmd_len, &dw);
342 dw[0] = dw0;
343 dw[1] = 0;
344 dw[2] = 0;
345 dw[3] = 0;
346 dw[4] = 0;
347 dw[5] = GEN6_GS_DW5_STATISTICS;
348 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800349}
350
Chia-I Wud88e02d2014-08-25 10:56:13 +0800351static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
352 XGL_UINT width, XGL_UINT height)
353{
354 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800355 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800356 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800357 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800358
359 CMD_ASSERT(cmd, 6, 7.5);
360
Chia-I Wu72292b72014-09-09 10:48:33 +0800361 cmd_batch_pointer(cmd, cmd_len, &dw);
362 dw[0] = dw0;
363
Chia-I Wud88e02d2014-08-25 10:56:13 +0800364 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800365 dw[1] = 0;
366 dw[2] = (height - 1) << 16 |
367 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800368 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800369 dw[1] = 1;
370 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800371 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800372
373 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800374}
375
Chia-I Wu8016a172014-08-29 18:31:32 +0800376static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
377 uint32_t body[6])
378{
379 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
380 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
381 const struct intel_raster_state *raster = cmd->bind.state.raster;
382 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
383 uint32_t dw1, dw2, dw3;
384 int point_width;
385
386 CMD_ASSERT(cmd, 6, 7.5);
387
388 dw1 = GEN7_SF_DW1_STATISTICS |
389 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
390 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
391 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
392 GEN7_SF_DW1_VIEWPORT_ENABLE |
393 raster->cmd_sf_fill;
394
395 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
396 int format;
397
398 switch (pipeline->db_format.channelFormat) {
399 case XGL_CH_FMT_R16:
400 format = GEN6_ZFORMAT_D16_UNORM;
401 break;
402 case XGL_CH_FMT_R32:
403 case XGL_CH_FMT_R32G8:
404 format = GEN6_ZFORMAT_D32_FLOAT;
405 break;
406 default:
407 assert(!"unknown depth format");
408 format = 0;
409 break;
410 }
411
412 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
413 }
414
415 dw2 = raster->cmd_sf_cull;
416
417 if (msaa->sample_count > 1) {
418 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
419 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
420 } else {
421 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
422 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
423 }
424
425 if (viewport->scissor_enable)
426 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
427
428 /* in U8.3 */
429 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
430 point_width = U_CLAMP(point_width, 1, 2047);
431
432 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
433 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
434 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
435 GEN7_SF_DW3_SUBPIXEL_8BITS |
436 GEN7_SF_DW3_USE_POINT_WIDTH |
437 point_width;
438
439 body[0] = dw1;
440 body[1] = dw2;
441 body[2] = dw3;
442 body[3] = raster->cmd_depth_offset_const;
443 body[4] = raster->cmd_depth_offset_scale;
444 body[5] = raster->cmd_depth_offset_clamp;
445}
446
447static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
448 uint32_t body[13])
449{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800450 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
451 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452 XGL_UINT attr_skip, attr_count;
453 XGL_UINT vue_offset, vue_len;
454 XGL_UINT i;
455 uint32_t dw1;
456
457 CMD_ASSERT(cmd, 6, 7.5);
458
459 /* VS outputs VUE header and position additionally */
460 assert(vs->out_count >= 2);
461 attr_skip = 2;
462 attr_count = vs->out_count - attr_skip;
463 assert(fs->in_count == attr_count);
464 assert(fs->in_count <= 32);
465
466 vue_offset = attr_skip / 2;
467 vue_len = (attr_count + 1) / 2;
468 if (!vue_len)
469 vue_len = 1;
470
471 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
472 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
473 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
474
475 body[0] = dw1;
476
477 for (i = 0; i < 8; i++) {
478 uint16_t hi, lo;
479
480 /* no attr swizzles */
481 if (i * 2 + 1 < fs->in_count) {
482 hi = i * 2 + 1;
483 lo = i * 2;
484 } else if (i * 2 < fs->in_count) {
485 hi = 0;
486 lo = i * 2;
487 } else {
488 hi = 0;
489 lo = 0;
490 }
491
492 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
493 }
494
495 body[9] = 0; /* point sprite enables */
496 body[10] = 0; /* constant interpolation enables */
497 body[11] = 0; /* WrapShortest enables */
498 body[12] = 0;
499}
500
501static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
502{
503 const uint8_t cmd_len = 20;
504 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
505 (cmd_len - 2);
506 uint32_t sf[6];
507 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800508 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800509
510 CMD_ASSERT(cmd, 6, 6);
511
512 gen7_fill_3DSTATE_SF_body(cmd, sf);
513 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
514
Chia-I Wu72292b72014-09-09 10:48:33 +0800515 cmd_batch_pointer(cmd, cmd_len, &dw);
516 dw[0] = dw0;
517 dw[1] = sbe[0];
518 memcpy(&dw[2], sf, sizeof(sf));
519 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800520}
521
522static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
523{
524 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800525 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800526
527 CMD_ASSERT(cmd, 7, 7.5);
528
Chia-I Wu72292b72014-09-09 10:48:33 +0800529 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800530 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
531 (cmd_len - 2);
532 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800533}
534
535static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
536{
537 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800538 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800539
540 CMD_ASSERT(cmd, 7, 7.5);
541
Chia-I Wu72292b72014-09-09 10:48:33 +0800542 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800543 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
544 (cmd_len - 2);
545 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800546}
547
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800548static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
549{
550 const uint8_t cmd_len = 4;
551 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
552 (cmd_len - 2);
553 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800554 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800555 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
556 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800557 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800558
559 CMD_ASSERT(cmd, 6, 7.5);
560
561 dw1 = GEN6_CLIP_DW1_STATISTICS;
562 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
563 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
564 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
565 raster->cmd_clip_cull;
566 }
567
568 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
569 GEN6_CLIP_DW2_XY_TEST_ENABLE |
570 GEN6_CLIP_DW2_APIMODE_OGL |
571 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
572 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
573 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
574
575 if (pipeline->rasterizerDiscardEnable)
576 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
577 else
578 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
579
580 if (pipeline->depthClipEnable)
581 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
582
583 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
584 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
585 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
586 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
587
588 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
589 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
590 (viewport->viewport_count - 1);
591
Chia-I Wu72292b72014-09-09 10:48:33 +0800592 cmd_batch_pointer(cmd, cmd_len, &dw);
593 dw[0] = dw0;
594 dw[1] = dw1;
595 dw[2] = dw2;
596 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800597}
598
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800599static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
600{
601 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
602 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800603 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800604 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
605 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800606 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800607
608 CMD_ASSERT(cmd, 6, 6);
609
610 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
611
612 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
613 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
614
615 dw4 = GEN6_WM_DW4_STATISTICS |
616 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
617 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
618 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
619
620 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
621 GEN6_WM_DW5_PS_ENABLE |
622 GEN6_WM_DW5_8_PIXEL_DISPATCH;
623
624 if (fs->uses & INTEL_SHADER_USE_KILL ||
625 pipeline->cb_state.alphaToCoverageEnable)
626 dw5 |= GEN6_WM_DW5_PS_KILL;
627
628 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
629 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
630 if (fs->uses & INTEL_SHADER_USE_DEPTH)
631 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
632 if (fs->uses & INTEL_SHADER_USE_W)
633 dw5 |= GEN6_WM_DW5_PS_USE_W;
634
635 if (pipeline->cb_state.dualSourceBlendEnable)
636 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
637
638 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
639 GEN6_WM_DW6_POSOFFSET_NONE |
640 GEN6_WM_DW6_ZW_INTERP_PIXEL |
641 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
642 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
643
644 if (msaa->sample_count > 1) {
645 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
646 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
647 } else {
648 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
649 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
650 }
651
Chia-I Wu72292b72014-09-09 10:48:33 +0800652 cmd_batch_pointer(cmd, cmd_len, &dw);
653 dw[0] = dw0;
654 dw[1] = cmd->bind.fs.kernel_offset;
655 dw[2] = dw2;
656 dw[3] = 0; /* scratch */
657 dw[4] = dw4;
658 dw[5] = dw5;
659 dw[6] = dw6;
660 dw[7] = 0; /* kernel 1 */
661 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800662}
663
664static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
665{
666 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800667 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
669 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800670 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800671
672 CMD_ASSERT(cmd, 7, 7.5);
673
674 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
675
676 dw1 = GEN7_WM_DW1_STATISTICS |
677 GEN7_WM_DW1_PS_ENABLE |
678 GEN7_WM_DW1_ZW_INTERP_PIXEL |
679 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
680 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
681
682 if (fs->uses & INTEL_SHADER_USE_KILL ||
683 pipeline->cb_state.alphaToCoverageEnable)
684 dw1 |= GEN7_WM_DW1_PS_KILL;
685
686 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
687 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
688 if (fs->uses & INTEL_SHADER_USE_DEPTH)
689 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
690 if (fs->uses & INTEL_SHADER_USE_W)
691 dw1 |= GEN7_WM_DW1_PS_USE_W;
692
693 dw2 = 0;
694
695 if (msaa->sample_count > 1) {
696 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
697 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
698 } else {
699 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
700 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
701 }
702
Chia-I Wu72292b72014-09-09 10:48:33 +0800703 cmd_batch_pointer(cmd, cmd_len, &dw);
704 dw[0] = dw0;
705 dw[1] = dw1;
706 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800707}
708
709static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
710{
711 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800712 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800713 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
714 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800715 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800716
717 CMD_ASSERT(cmd, 7, 7.5);
718
719 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
720
721 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
722 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
723
724 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
725 GEN7_PS_DW4_8_PIXEL_DISPATCH;
726
727 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
728 const int max_threads =
729 (cmd->dev->gpu->gt == 3) ? 408 :
730 (cmd->dev->gpu->gt == 2) ? 204 : 102;
731 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
732 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
733 } else {
734 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
735 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
736 }
737
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800738 if (fs->in_count)
739 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
740
741 if (pipeline->cb_state.dualSourceBlendEnable)
742 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
743
744 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
745 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
746 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
747
Chia-I Wu72292b72014-09-09 10:48:33 +0800748 cmd_batch_pointer(cmd, cmd_len, &dw);
749 dw[0] = dw0;
750 dw[1] = cmd->bind.fs.kernel_offset;
751 dw[2] = dw2;
752 dw[3] = 0; /* scratch */
753 dw[4] = dw4;
754 dw[5] = dw5;
755 dw[6] = 0; /* kernel 1 */
756 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800757}
758
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800759static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
760 const struct intel_ds_view *view)
761{
762 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800763 uint32_t dw0, *dw;
764 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800765
766 CMD_ASSERT(cmd, 6, 7.5);
767
768 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800769 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
770 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800771 dw0 |= (cmd_len - 2);
772
Chia-I Wu72292b72014-09-09 10:48:33 +0800773 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
774 dw[0] = dw0;
775 dw[1] = view->cmd[0];
776 dw[2] = 0;
777 dw[3] = view->cmd[2];
778 dw[4] = view->cmd[3];
779 dw[5] = view->cmd[4];
780 dw[6] = view->cmd[5];
781
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600782 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800783 cmd_reserve_reloc(cmd, 1);
784 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
785 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600786 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800787}
788
789static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
790 const struct intel_ds_view *view)
791{
792 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800793 uint32_t dw0, *dw;
794 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800795
796 CMD_ASSERT(cmd, 6, 7.5);
797
798 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800799 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
800 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800801 dw0 |= (cmd_len - 2);
802
Chia-I Wu72292b72014-09-09 10:48:33 +0800803 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
804 dw[0] = dw0;
805 dw[1] = view->cmd[6];
806 dw[2] = 0;
807
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600808 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800809 cmd_reserve_reloc(cmd, 1);
810 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
811 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600812 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800813}
814
815static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
816 const struct intel_ds_view *view)
817{
818 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800819 uint32_t dw0, *dw;
820 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800821
822 CMD_ASSERT(cmd, 6, 7.5);
823
824 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800825 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
826 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800827 dw0 |= (cmd_len - 2);
828
Chia-I Wu72292b72014-09-09 10:48:33 +0800829 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
830 dw[0] = dw0;
831 dw[1] = view->cmd[8];
832 dw[2] = 0;
833
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600834 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800835 cmd_reserve_reloc(cmd, 1);
836 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
837 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600838 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800839}
840
Chia-I Wuf8231032014-08-25 10:44:45 +0800841static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
842 uint32_t clear_val)
843{
844 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800845 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800846 GEN6_CLEAR_PARAMS_DW0_VALID |
847 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800848 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800849
850 CMD_ASSERT(cmd, 6, 6);
851
Chia-I Wu72292b72014-09-09 10:48:33 +0800852 cmd_batch_pointer(cmd, cmd_len, &dw);
853 dw[0] = dw0;
854 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800855}
856
857static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
858 uint32_t clear_val)
859{
860 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800861 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800862 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800863 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800864
865 CMD_ASSERT(cmd, 7, 7.5);
866
Chia-I Wu72292b72014-09-09 10:48:33 +0800867 cmd_batch_pointer(cmd, cmd_len, &dw);
868 dw[0] = dw0;
869 dw[1] = clear_val;
870 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800871}
872
Chia-I Wu302742d2014-08-22 10:28:29 +0800873static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800874 uint32_t blend_offset,
875 uint32_t ds_offset,
876 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800877{
878 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800879 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800880
881 CMD_ASSERT(cmd, 6, 6);
882
Chia-I Wu426072d2014-08-26 14:31:55 +0800883 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800884 (cmd_len - 2);
885
Chia-I Wu72292b72014-09-09 10:48:33 +0800886 cmd_batch_pointer(cmd, cmd_len, &dw);
887 dw[0] = dw0;
888 dw[1] = blend_offset | 1;
889 dw[2] = ds_offset | 1;
890 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800891}
892
Chia-I Wu1744cca2014-08-22 11:10:17 +0800893static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800894 uint32_t clip_offset,
895 uint32_t sf_offset,
896 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800897{
898 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800899 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800900
901 CMD_ASSERT(cmd, 6, 6);
902
Chia-I Wu426072d2014-08-26 14:31:55 +0800903 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800904 GEN6_PTR_VP_DW0_CLIP_CHANGED |
905 GEN6_PTR_VP_DW0_SF_CHANGED |
906 GEN6_PTR_VP_DW0_CC_CHANGED |
907 (cmd_len - 2);
908
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 cmd_batch_pointer(cmd, cmd_len, &dw);
910 dw[0] = dw0;
911 dw[1] = clip_offset;
912 dw[2] = sf_offset;
913 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800914}
915
916static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800917 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800918{
919 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800920 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800921
922 CMD_ASSERT(cmd, 6, 6);
923
Chia-I Wu426072d2014-08-26 14:31:55 +0800924 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800925 (cmd_len - 2);
926
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 cmd_batch_pointer(cmd, cmd_len, &dw);
928 dw[0] = dw0;
929 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800930}
931
Chia-I Wu42a56202014-08-23 16:47:48 +0800932static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800933 uint32_t vs_offset,
934 uint32_t gs_offset,
935 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800936{
937 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800938 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800939
940 CMD_ASSERT(cmd, 6, 6);
941
Chia-I Wu426072d2014-08-26 14:31:55 +0800942 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800943 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
944 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
945 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
946 (cmd_len - 2);
947
Chia-I Wu72292b72014-09-09 10:48:33 +0800948 cmd_batch_pointer(cmd, cmd_len, &dw);
949 dw[0] = dw0;
950 dw[1] = vs_offset;
951 dw[2] = gs_offset;
952 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800953}
954
Chia-I Wu257e75e2014-08-29 14:06:35 +0800955static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 uint32_t vs_offset,
957 uint32_t gs_offset,
958 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800959{
960 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800961 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800962
963 CMD_ASSERT(cmd, 6, 6);
964
965 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
966 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
967 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
968 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
969 (cmd_len - 2);
970
Chia-I Wu72292b72014-09-09 10:48:33 +0800971 cmd_batch_pointer(cmd, cmd_len, &dw);
972 dw[0] = dw0;
973 dw[1] = vs_offset;
974 dw[2] = gs_offset;
975 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800976}
977
Chia-I Wu302742d2014-08-22 10:28:29 +0800978static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800979 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800980{
981 const uint8_t cmd_len = 2;
982 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
983 GEN6_RENDER_SUBTYPE_3D |
984 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800985 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800986
Chia-I Wu72292b72014-09-09 10:48:33 +0800987 cmd_batch_pointer(cmd, cmd_len, &dw);
988 dw[0] = dw0;
989 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800990}
991
Chia-I Wu72292b72014-09-09 10:48:33 +0800992static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800993 const struct intel_blend_state *state)
994{
Chia-I Wu72292b72014-09-09 10:48:33 +0800995 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800996 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
997
998 CMD_ASSERT(cmd, 6, 7.5);
999 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1000
Chia-I Wu00b51a82014-09-09 12:07:37 +08001001 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
1002 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001003}
1004
Chia-I Wu72292b72014-09-09 10:48:33 +08001005static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001006 const struct intel_ds_state *state)
1007{
Chia-I Wu72292b72014-09-09 10:48:33 +08001008 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001009 const uint8_t cmd_len = 3;
1010
1011 CMD_ASSERT(cmd, 6, 7.5);
1012 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1013
Chia-I Wu00b51a82014-09-09 12:07:37 +08001014 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1015 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 Wu00b51a82014-09-09 12:07:37 +08001028 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1029 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001030 dw[0] = stencil_ref;
1031 dw[1] = 0;
1032 dw[2] = blend_color[0];
1033 dw[3] = blend_color[1];
1034 dw[4] = blend_color[2];
1035 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001036
Chia-I Wu72292b72014-09-09 10:48:33 +08001037 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001038}
1039
Chia-I Wu8370b402014-08-29 12:28:37 +08001040static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001041{
Chia-I Wu8370b402014-08-29 12:28:37 +08001042 CMD_ASSERT(cmd, 6, 7.5);
1043
Chia-I Wu707a29e2014-08-27 12:51:47 +08001044 if (!cmd->bind.draw_count)
1045 return;
1046
Chia-I Wu8370b402014-08-29 12:28:37 +08001047 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001048 return;
1049
Chia-I Wu8370b402014-08-29 12:28:37 +08001050 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001051
1052 /*
1053 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1054 *
1055 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1056 * pipe-control with a post-sync op and no write-cache flushes."
1057 *
1058 * The workaround below necessitates this workaround.
1059 */
1060 gen6_PIPE_CONTROL(cmd,
1061 GEN6_PIPE_CONTROL_CS_STALL |
1062 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001063 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001064
Chia-I Wud6d079d2014-08-31 13:14:21 +08001065 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1066 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001067}
1068
Chia-I Wu8370b402014-08-29 12:28:37 +08001069static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001070{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001071 CMD_ASSERT(cmd, 6, 7.5);
1072
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001073 if (!cmd->bind.draw_count)
1074 return;
1075
Chia-I Wud6d079d2014-08-31 13:14:21 +08001076 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1077 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001078}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001079
Chia-I Wu8370b402014-08-29 12:28:37 +08001080static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1081{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001082 CMD_ASSERT(cmd, 7, 7.5);
1083
Chia-I Wu8370b402014-08-29 12:28:37 +08001084 if (!cmd->bind.draw_count)
1085 return;
1086
1087 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001088
1089 gen6_PIPE_CONTROL(cmd,
1090 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001091 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001092}
1093
Chia-I Wu8370b402014-08-29 12:28:37 +08001094static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1095{
1096 CMD_ASSERT(cmd, 7, 7.5);
1097
1098 if (!cmd->bind.draw_count)
1099 return;
1100
1101 /*
1102 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1103 *
1104 * "One of the following must also be set (when CS stall is set):
1105 *
1106 * * Render Target Cache Flush Enable ([12] of DW1)
1107 * * Depth Cache Flush Enable ([0] of DW1)
1108 * * Stall at Pixel Scoreboard ([1] of DW1)
1109 * * Depth Stall ([13] of DW1)
1110 * * Post-Sync Operation ([13] of DW1)"
1111 */
1112 gen6_PIPE_CONTROL(cmd,
1113 GEN6_PIPE_CONTROL_CS_STALL |
1114 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001115 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001116}
1117
1118static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1119{
1120 CMD_ASSERT(cmd, 7, 7.5);
1121
1122 if (!cmd->bind.draw_count)
1123 return;
1124
1125 cmd_wa_gen6_pre_depth_stall_write(cmd);
1126
Chia-I Wud6d079d2014-08-31 13:14:21 +08001127 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001128}
1129
1130static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1131{
1132 CMD_ASSERT(cmd, 6, 7.5);
1133
1134 if (!cmd->bind.draw_count)
1135 return;
1136
1137 /*
1138 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1139 *
1140 * "Driver must guarentee that all the caches in the depth pipe are
1141 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1142 * requires driver to send a PIPE_CONTROL with a CS stall along with
1143 * a Depth Flush prior to this command."
1144 *
1145 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1146 *
1147 * "Driver must ierarchi that all the caches in the depth pipe are
1148 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1149 * requires driver to send a PIPE_CONTROL with a CS stall along with
1150 * a Depth Flush prior to this command.
1151 */
1152 gen6_PIPE_CONTROL(cmd,
1153 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1154 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001155 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001156}
1157
1158static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1159{
1160 CMD_ASSERT(cmd, 6, 7.5);
1161
1162 if (!cmd->bind.draw_count)
1163 return;
1164
1165 /*
1166 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1167 *
1168 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1169 * and a post sync operation prior to the group of depth
1170 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1171 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1172 *
1173 * This workaround satifies all the conditions.
1174 */
1175 cmd_wa_gen6_pre_depth_stall_write(cmd);
1176
1177 /*
1178 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1179 *
1180 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1181 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1182 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1183 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1184 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1185 * Depth Flush Bit set, followed by another pipelined depth stall
1186 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1187 * guarantee that the pipeline from WM onwards is already flushed
1188 * (e.g., via a preceding MI_FLUSH)."
1189 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001190 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1191 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1192 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001193}
1194
Chia-I Wu525c6602014-08-27 10:22:34 +08001195void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1196{
1197 if (!cmd->bind.draw_count)
1198 return;
1199
1200 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1201
Chia-I Wu8370b402014-08-29 12:28:37 +08001202 /*
1203 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1204 *
1205 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1206 * PIPE_CONTROL with any non-zero post-sync-op is required."
1207 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001208 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001209 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001210
Chia-I Wu092279a2014-08-30 19:05:30 +08001211 /*
1212 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1213 *
1214 * "One of the following must also be set (when CS stall is set):
1215 *
1216 * * Render Target Cache Flush Enable ([12] of DW1)
1217 * * Depth Cache Flush Enable ([0] of DW1)
1218 * * Stall at Pixel Scoreboard ([1] of DW1)
1219 * * Depth Stall ([13] of DW1)
1220 * * Post-Sync Operation ([13] of DW1)"
1221 */
1222 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1223 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1224 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1225 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1226 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1227 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1228
Chia-I Wud6d079d2014-08-31 13:14:21 +08001229 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001230}
1231
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001232void cmd_batch_depth_count(struct intel_cmd *cmd,
1233 struct intel_bo *bo,
1234 XGL_GPU_SIZE offset)
1235{
1236 cmd_wa_gen6_pre_depth_stall_write(cmd);
1237
1238 gen6_PIPE_CONTROL(cmd,
1239 GEN6_PIPE_CONTROL_DEPTH_STALL |
1240 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001241 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001242}
1243
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001244void cmd_batch_timestamp(struct intel_cmd *cmd,
1245 struct intel_bo *bo,
1246 XGL_GPU_SIZE offset)
1247{
1248 /* need any WA or stall? */
1249 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1250}
1251
1252void cmd_batch_immediate(struct intel_cmd *cmd,
1253 struct intel_bo *bo,
1254 XGL_GPU_SIZE offset,
1255 uint64_t val)
1256{
1257 /* need any WA or stall? */
1258 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1259}
1260
Chia-I Wu302742d2014-08-22 10:28:29 +08001261static void gen6_cc_states(struct intel_cmd *cmd)
1262{
1263 const struct intel_blend_state *blend = cmd->bind.state.blend;
1264 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001265 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001266 uint32_t stencil_ref;
1267 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001268
1269 CMD_ASSERT(cmd, 6, 6);
1270
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001271 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001272 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001273 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1274 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001275 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001276 memset(blend_color, 0, sizeof(blend_color));
1277 }
1278
1279 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001280 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001281 stencil_ref = ds->cmd_stencil_ref;
1282 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001283 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001284 stencil_ref = 0;
1285 }
1286
Chia-I Wu72292b72014-09-09 10:48:33 +08001287 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001288
Chia-I Wu72292b72014-09-09 10:48:33 +08001289 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001290}
1291
Chia-I Wu1744cca2014-08-22 11:10:17 +08001292static void gen6_viewport_states(struct intel_cmd *cmd)
1293{
1294 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001295 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001296
1297 if (!viewport)
1298 return;
1299
Chia-I Wub1d450a2014-09-09 13:48:03 +08001300 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1301 viewport->viewport_count);
1302
1303 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1304 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1305 viewport->cmd);
1306
1307 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1308 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1309 &viewport->cmd[viewport->cmd_clip_pos]);
1310
1311 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1312 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1313 &viewport->cmd[viewport->cmd_cc_pos]);
1314
1315 if (viewport->scissor_enable) {
1316 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1317 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1318 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1319 } else {
1320 scissor_offset = 0;
1321 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001322
1323 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001324 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001325
Chia-I Wub1d450a2014-09-09 13:48:03 +08001326 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001327}
1328
Chia-I Wu302742d2014-08-22 10:28:29 +08001329static void gen7_cc_states(struct intel_cmd *cmd)
1330{
1331 const struct intel_blend_state *blend = cmd->bind.state.blend;
1332 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001333 uint32_t stencil_ref;
1334 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001335 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001336
1337 CMD_ASSERT(cmd, 7, 7.5);
1338
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001339 if (!blend && !ds)
1340 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001341
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001342 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001343 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001344 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001345 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001346
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001347 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1348 } else {
1349 memset(blend_color, 0, sizeof(blend_color));
1350 }
1351
1352 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001353 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001354 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001355 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1356 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001357 } else {
1358 stencil_ref = 0;
1359 }
1360
Chia-I Wu72292b72014-09-09 10:48:33 +08001361 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001362 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001363 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001364}
1365
Chia-I Wu1744cca2014-08-22 11:10:17 +08001366static void gen7_viewport_states(struct intel_cmd *cmd)
1367{
1368 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001369 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001370
1371 if (!viewport)
1372 return;
1373
Chia-I Wub1d450a2014-09-09 13:48:03 +08001374 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1375 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001376
Chia-I Wub1d450a2014-09-09 13:48:03 +08001377 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1378 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1379 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001380 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001381 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1382 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001383
1384 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1385 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1386 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001387 gen7_3dstate_pointer(cmd,
1388 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001389 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001390
Chia-I Wu1744cca2014-08-22 11:10:17 +08001391 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001392 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1393 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1394 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001395 gen7_3dstate_pointer(cmd,
1396 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001397 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001398 }
1399}
1400
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001401static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001402 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001403{
1404 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001405 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001406
Chia-I Wu72292b72014-09-09 10:48:33 +08001407 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001408
1409 dw[0] = GEN6_RENDER_TYPE_RENDER |
1410 GEN6_RENDER_SUBTYPE_3D |
1411 subop | (cmd_len - 2);
1412 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001413 dw[2] = 0;
1414 dw[3] = 0;
1415 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001416}
1417
1418static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001419 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001420{
1421 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001422 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001423
Chia-I Wu72292b72014-09-09 10:48:33 +08001424 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001425
1426 dw[0] = GEN6_RENDER_TYPE_RENDER |
1427 GEN6_RENDER_SUBTYPE_3D |
1428 subop | (cmd_len - 2);
1429 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001430 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001431 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001432 dw[4] = 0;
1433 dw[5] = 0;
1434 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001435}
1436
Chia-I Wu625105f2014-10-13 15:35:29 +08001437static uint32_t emit_samplers(struct intel_cmd *cmd,
1438 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001439{
1440 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1441 const XGL_UINT border_stride =
1442 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001443 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001444 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001445 XGL_UINT i;
1446
1447 CMD_ASSERT(cmd, 6, 7.5);
1448
Chia-I Wu625105f2014-10-13 15:35:29 +08001449 if (!rmap || !rmap->sampler_count)
1450 return 0;
1451
1452 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1453
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001454 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1455 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1456 border_stride * rmap->sampler_count, &border_dw);
1457
1458 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1459 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1460 4 * rmap->sampler_count, &sampler_dw);
1461
1462 for (i = 0; i < rmap->sampler_count; i++) {
1463 const struct intel_pipeline_rmap_slot *slot =
1464 &rmap->slots[surface_count + i];
1465 const struct intel_sampler *sampler;
1466
1467 switch (slot->path_len) {
1468 case 0:
1469 sampler = NULL;
1470 break;
1471 case INTEL_PIPELINE_RMAP_SLOT_RT:
1472 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1473 assert(!"unexpected rmap slot type");
1474 sampler = NULL;
1475 break;
1476 case 1:
1477 {
1478 const struct intel_dset *dset = cmd->bind.dset.graphics;
1479 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1480 const struct intel_dset_slot *dset_slot =
1481 &dset->slots[slot_offset + slot->u.index];
1482
1483 switch (dset_slot->type) {
1484 case INTEL_DSET_SLOT_SAMPLER:
1485 sampler = dset_slot->u.sampler;
1486 break;
1487 default:
1488 assert(!"unexpected dset slot type");
1489 sampler = NULL;
1490 break;
1491 }
1492 }
1493 break;
1494 default:
1495 assert(!"nested descriptor set unsupported");
1496 sampler = NULL;
1497 break;
1498 }
1499
1500 if (sampler) {
1501 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1502
1503 sampler_dw[0] = sampler->cmd[0];
1504 sampler_dw[1] = sampler->cmd[1];
1505 sampler_dw[2] = border_offset;
1506 sampler_dw[3] = sampler->cmd[2];
1507 } else {
1508 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1509 sampler_dw[1] = 0;
1510 sampler_dw[2] = 0;
1511 sampler_dw[3] = 0;
1512 }
1513
1514 border_offset += border_stride * 4;
1515 border_dw += border_stride;
1516 sampler_dw += 4;
1517 }
1518
Chia-I Wu625105f2014-10-13 15:35:29 +08001519 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001520}
1521
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001522static uint32_t emit_binding_table(struct intel_cmd *cmd,
1523 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001524{
Chia-I Wu72292b72014-09-09 10:48:33 +08001525 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001526 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001527
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001528 CMD_ASSERT(cmd, 6, 7.5);
1529
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001530 surface_count = (rmap) ?
1531 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1532 if (!surface_count)
1533 return 0;
1534
Chia-I Wu42a56202014-08-23 16:47:48 +08001535 assert(surface_count <= ARRAY_SIZE(binding_table));
1536
1537 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001538 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001539
1540 switch (slot->path_len) {
1541 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001542 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001543 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001544 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001545 {
1546 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1547
Chia-I Wu00b51a82014-09-09 12:07:37 +08001548 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001549 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1550 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001551
Chia-I Wu72292b72014-09-09 10:48:33 +08001552 cmd_reserve_reloc(cmd, 1);
1553 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1554 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001555 }
1556 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001557 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001558 {
1559 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001560 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001561
Chia-I Wu00b51a82014-09-09 12:07:37 +08001562 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001563 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1564 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001565
Chia-I Wu72292b72014-09-09 10:48:33 +08001566 cmd_reserve_reloc(cmd, 1);
1567 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1568 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001569 }
1570 break;
1571 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001572 {
1573 const struct intel_dset *dset = cmd->bind.dset.graphics;
1574 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1575 const struct intel_dset_slot *dset_slot =
1576 &dset->slots[slot_offset + slot->u.index];
1577
1578 switch (dset_slot->type) {
1579 case INTEL_DSET_SLOT_IMG_VIEW:
1580 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1581 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1582 dset_slot->u.img_view->cmd_len,
1583 dset_slot->u.img_view->cmd);
1584
1585 cmd_reserve_reloc(cmd, 1);
1586 cmd_surface_reloc(cmd, offset, 1,
1587 dset_slot->u.img_view->img->obj.mem->bo,
1588 dset_slot->u.img_view->cmd[1], 0);
1589 break;
1590 case INTEL_DSET_SLOT_MEM_VIEW:
1591 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1592 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1593 dset_slot->u.mem_view.cmd_len,
1594 dset_slot->u.mem_view.cmd);
1595
1596 cmd_reserve_reloc(cmd, 1);
1597 cmd_surface_reloc(cmd, offset, 1,
1598 dset_slot->u.mem_view.mem->bo,
1599 dset_slot->u.mem_view.cmd[1], 0);
1600 break;
1601 default:
1602 assert(!"unexpected dset slot type");
1603 break;
1604 }
1605 }
1606 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001607 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001608 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001609 break;
1610 }
1611
Chia-I Wu72292b72014-09-09 10:48:33 +08001612 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001613 }
1614
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001615 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001616 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001617 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001618}
1619
Chia-I Wu1d125092014-10-08 08:49:38 +08001620static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1621{
1622 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1623 const struct intel_pipeline_rmap *rmap = pipeline->vs.rmap;
1624 const struct intel_dset *dset = cmd->bind.dset.graphics;
1625 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1626 uint32_t *dw;
1627 XGL_UINT pos, i;
1628
1629 CMD_ASSERT(cmd, 6, 7.5);
1630
1631 if (!pipeline->vb_count)
1632 return;
1633
1634 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1635
1636 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1637 dw++;
1638 pos++;
1639
1640 for (i = 0; i < pipeline->vb_count; i++) {
1641 const XGL_UINT vb_offset = rmap->rt_count + rmap->resource_count +
1642 rmap->uav_count + rmap->sampler_count;
1643 const struct intel_pipeline_rmap_slot *slot = (i < rmap->vb_count) ?
1644 &rmap->slots[vb_offset + i] : NULL;
1645 struct intel_mem_view *view = NULL;
1646
1647 if (slot) {
1648 switch (slot->path_len) {
1649 case 1:
1650 view = (dset->slots[slot->u.index].type ==
1651 INTEL_DSET_SLOT_MEM_VIEW) ?
1652 &dset->slots[slot->u.index].u.mem_view : NULL;
1653 break;
1654 default:
1655 break;
1656 }
1657 }
1658
1659 assert(pipeline->vb[i].strideInBytes <= 2048);
1660
1661 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1662 pipeline->vb[i].strideInBytes;
1663
1664 if (cmd_gen(cmd) >= INTEL_GEN(7))
1665 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1666
1667 switch (pipeline->vb[i].stepRate) {
1668 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1669 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1670 dw[3] = 0;
1671 break;
1672 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1673 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1674 dw[3] = 1;
1675 break;
1676 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1677 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1678 dw[3] = 0;
1679 break;
1680 default:
1681 assert(!"unknown step rate");
1682 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1683 dw[3] = 0;
1684 break;
1685 }
1686
1687 if (view) {
1688 const uint32_t begin = view->cmd[1];
1689 const uint32_t end = view->mem->size - 1;
1690
1691 cmd_reserve_reloc(cmd, 2);
1692 cmd_batch_reloc(cmd, pos + 1, view->mem->bo, begin, 0);
1693 cmd_batch_reloc(cmd, pos + 2, view->mem->bo, end, 0);
1694 } else {
1695 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1696 dw[1] = 0;
1697 dw[2] = 0;
1698 }
1699
1700 dw += 4;
1701 pos += 4;
1702 }
1703}
1704
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001705static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1706{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001707 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1708 const struct intel_pipeline_shader *vs = &pipeline->vs;
1709 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001710 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001711 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001712 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001713
1714 CMD_ASSERT(cmd, 6, 7.5);
1715
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001716 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001717 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1718 *
1719 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1720 * 128-bit vertex elements to be passed into the payload for each
1721 * vertex."
1722 *
1723 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1724 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001725 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001726 vue_read_len = (vs->in_count + 1) / 2;
1727 if (!vue_read_len)
1728 vue_read_len = 1;
1729
1730 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1731 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1732
1733 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1734 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1735 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001736
1737 dw5 = GEN6_VS_DW5_STATISTICS |
1738 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001739
1740 switch (cmd_gen(cmd)) {
1741 case INTEL_GEN(7.5):
1742 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1743 break;
1744 case INTEL_GEN(7):
1745 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1746 break;
1747 case INTEL_GEN(6):
1748 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1749 break;
1750 default:
1751 max_threads = 1;
1752 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001753 }
1754
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001755 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1756 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1757 else
1758 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1759
Chia-I Wube0a3d92014-09-02 13:20:59 +08001760 if (pipeline->disable_vs_cache)
1761 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1762
Chia-I Wu72292b72014-09-09 10:48:33 +08001763 cmd_batch_pointer(cmd, cmd_len, &dw);
1764 dw[0] = dw0;
1765 dw[1] = cmd->bind.vs.kernel_offset;
1766 dw[2] = dw2;
1767 dw[3] = 0; /* scratch */
1768 dw[4] = dw4;
1769 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001770}
1771
Chia-I Wu625105f2014-10-13 15:35:29 +08001772static void emit_shader_resources(struct intel_cmd *cmd)
1773{
1774 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001775 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001776
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001777 binding_tables[0] = emit_binding_table(cmd,
1778 cmd->bind.pipeline.graphics->vs.rmap);
1779 binding_tables[1] = emit_binding_table(cmd,
1780 cmd->bind.pipeline.graphics->tcs.rmap);
1781 binding_tables[2] = emit_binding_table(cmd,
1782 cmd->bind.pipeline.graphics->tes.rmap);
1783 binding_tables[3] = emit_binding_table(cmd,
1784 cmd->bind.pipeline.graphics->gs.rmap);
1785 binding_tables[4] = emit_binding_table(cmd,
1786 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001787
1788 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1789 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1790 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1791 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1792 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1793
1794 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1795 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001796 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1797 binding_tables[0]);
1798 gen7_3dstate_pointer(cmd,
1799 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1800 binding_tables[1]);
1801 gen7_3dstate_pointer(cmd,
1802 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1803 binding_tables[2]);
1804 gen7_3dstate_pointer(cmd,
1805 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1806 binding_tables[3]);
1807 gen7_3dstate_pointer(cmd,
1808 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1809 binding_tables[4]);
1810
1811 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001812 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1813 samplers[0]);
1814 gen7_3dstate_pointer(cmd,
1815 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1816 samplers[1]);
1817 gen7_3dstate_pointer(cmd,
1818 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1819 samplers[2]);
1820 gen7_3dstate_pointer(cmd,
1821 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1822 samplers[3]);
1823 gen7_3dstate_pointer(cmd,
1824 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1825 samplers[4]);
1826 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001827 assert(!binding_tables[1] && !binding_tables[2]);
1828 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1829 binding_tables[0], binding_tables[3], binding_tables[4]);
1830
Chia-I Wu625105f2014-10-13 15:35:29 +08001831 assert(!samplers[1] && !samplers[2]);
1832 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1833 samplers[0], samplers[3], samplers[4]);
1834 }
1835}
1836
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001837static void emit_rt(struct intel_cmd *cmd)
1838{
1839 cmd_wa_gen6_pre_depth_stall_write(cmd);
1840 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1841 cmd->bind.att.height);
1842}
1843
1844static void emit_ds(struct intel_cmd *cmd)
1845{
1846 const struct intel_ds_view *ds = cmd->bind.att.ds;
1847
1848 if (!ds) {
1849 /* all zeros */
1850 static const struct intel_ds_view null_ds;
1851 ds = &null_ds;
1852 }
1853
1854 cmd_wa_gen6_pre_ds_flush(cmd);
1855 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1856 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1857 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1858
1859 if (cmd_gen(cmd) >= INTEL_GEN(7))
1860 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1861 else
1862 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1863}
1864
Chia-I Wu52500102014-08-22 00:46:04 +08001865static void emit_bounded_states(struct intel_cmd *cmd)
1866{
1867 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1868
1869 /* TODO more states */
1870
Chia-I Wu1744cca2014-08-22 11:10:17 +08001871 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu302742d2014-08-22 10:28:29 +08001872 gen7_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001873 gen7_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001874
1875 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1876 &cmd->bind.pipeline.graphics->vs);
1877 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1878 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001879
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001880 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001881 gen7_3DSTATE_SF(cmd);
1882 gen7_3DSTATE_SBE(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001883 gen7_3DSTATE_WM(cmd);
1884 gen7_3DSTATE_PS(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001885 } else {
Chia-I Wu302742d2014-08-22 10:28:29 +08001886 gen6_cc_states(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001887 gen6_viewport_states(cmd);
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001888
1889 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1890 &cmd->bind.pipeline.graphics->vs);
1891 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1892 &cmd->bind.pipeline.graphics->fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001893
Chia-I Wuc3f9c092014-08-30 14:29:29 +08001894 gen6_3DSTATE_CLIP(cmd);
Chia-I Wu8016a172014-08-29 18:31:32 +08001895 gen6_3DSTATE_SF(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +08001896 gen6_3DSTATE_WM(cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001897 }
Chia-I Wu302742d2014-08-22 10:28:29 +08001898
Chia-I Wu625105f2014-10-13 15:35:29 +08001899 emit_shader_resources(cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001900
Chia-I Wu8370b402014-08-29 12:28:37 +08001901 cmd_wa_gen6_pre_depth_stall_write(cmd);
1902 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wu72292b72014-09-09 10:48:33 +08001903
Chia-I Wu9cb84ee2014-08-28 10:12:34 +08001904 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
Chia-I Wu72292b72014-09-09 10:48:33 +08001905 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001906
Chia-I Wu1d125092014-10-08 08:49:38 +08001907 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001908 gen6_3DSTATE_VS(cmd);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001909}
1910
1911static void emit_shader(struct intel_cmd *cmd,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001912 const struct intel_pipeline_shader *shader,
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001913 struct intel_cmd_shader *pCmdShader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001914{
1915 uint32_t i;
1916 struct intel_cmd_shader *cmdShader;
1917
1918 for (i=0; i<cmd->bind.shaderCache.used; i++) {
Chia-I Wu338fe642014-08-28 10:43:04 +08001919 if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001920 /* shader is already part of pipeline */
1921 return;
1922 }
1923 }
1924
Chia-I Wu338fe642014-08-28 10:43:04 +08001925 if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
1926 const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
1927
1928 cmdShader = cmd->bind.shaderCache.shaderArray;
1929
1930 cmd->bind.shaderCache.shaderArray =
1931 icd_alloc(sizeof(*cmdShader) * new_count,
1932 0, XGL_SYSTEM_ALLOC_INTERNAL);
1933 if (cmd->bind.shaderCache.shaderArray == NULL) {
1934 cmd->bind.shaderCache.shaderArray = cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001935 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
1936 return;
1937 }
Chia-I Wu338fe642014-08-28 10:43:04 +08001938
1939 if (cmdShader) {
1940 memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
1941 sizeof(*cmdShader) * cmd->bind.shaderCache.used);
1942 icd_free(cmdShader);
1943 }
1944
1945 cmd->bind.shaderCache.count = new_count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001946 }
1947
Chia-I Wu338fe642014-08-28 10:43:04 +08001948 cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001949 cmdShader->shader = shader;
Chia-I Wu72292b72014-09-09 10:48:33 +08001950 cmdShader->kernel_offset =
1951 cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001952 *pCmdShader = *cmdShader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001953 cmd->bind.shaderCache.used++;
1954 return;
1955}
1956
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001957static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
Chia-I Wu338fe642014-08-28 10:43:04 +08001958 const struct intel_pipeline *pipeline)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001959{
1960 cmd->bind.pipeline.graphics = pipeline;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001961
Chia-I Wu8370b402014-08-29 12:28:37 +08001962 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1963 cmd_wa_gen6_pre_depth_stall_write(cmd);
1964 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1965 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1966 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1967 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001968
1969 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001970 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001971 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001972
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001973 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001974 emit_shader(cmd, &pipeline->vs, &cmd->bind.vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001975 }
1976 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -06001977 emit_shader(cmd, &pipeline->gs, &cmd->bind.gs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001978 }
1979 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001980 emit_shader(cmd, &pipeline->fs, &cmd->bind.fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001981 }
1982 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +08001983 emit_shader(cmd, &pipeline->tcs, &cmd->bind.tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001984 }
1985 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +08001986 emit_shader(cmd, &pipeline->tes, &cmd->bind.tes);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001987 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001988
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001989 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1990 gen7_3DSTATE_GS(cmd);
1991 } else {
1992 gen6_3DSTATE_GS(cmd);
1993 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001994
Chia-I Wu8370b402014-08-29 12:28:37 +08001995 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1996 cmd_wa_gen7_post_command_cs_stall(cmd);
1997 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1998 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001999}
2000
2001static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2002 const struct intel_pipeline *pipeline)
2003{
2004 cmd->bind.pipeline.compute = pipeline;
2005}
2006
2007static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2008 const struct intel_pipeline_delta *delta)
2009{
2010 cmd->bind.pipeline.graphics_delta = delta;
2011}
2012
2013static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2014 const struct intel_pipeline_delta *delta)
2015{
2016 cmd->bind.pipeline.compute_delta = delta;
2017}
2018
2019static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2020 const struct intel_dset *dset,
2021 XGL_UINT slot_offset)
2022{
2023 cmd->bind.dset.graphics = dset;
2024 cmd->bind.dset.graphics_offset = slot_offset;
2025}
2026
2027static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2028 const struct intel_dset *dset,
2029 XGL_UINT slot_offset)
2030{
2031 cmd->bind.dset.compute = dset;
2032 cmd->bind.dset.compute_offset = slot_offset;
2033}
2034
2035static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2036 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2037{
2038 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2039}
2040
2041static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2042 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2043{
2044 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2045}
2046
2047static void cmd_bind_index_data(struct intel_cmd *cmd,
2048 const struct intel_mem *mem,
2049 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2050{
2051 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2052 gen6_3DSTATE_INDEX_BUFFER(cmd, mem, offset, type, false);
2053 } else {
2054 cmd->bind.index.mem = mem;
2055 cmd->bind.index.offset = offset;
2056 cmd->bind.index.type = type;
2057 }
2058}
2059
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002060static void cmd_bind_attachments(struct intel_cmd *cmd,
2061 XGL_UINT rt_count,
2062 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2063 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002064{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002065 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002066 XGL_UINT i;
2067
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002068 for (i = 0; i < rt_count; i++) {
2069 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002070 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002071 const struct intel_layout *layout = &rt->img->layout;
2072
2073 if (i == 0) {
2074 width = layout->width0;
2075 height = layout->height0;
2076 } else {
2077 if (width > layout->width0)
2078 width = layout->width0;
2079 if (height > layout->height0)
2080 height = layout->height0;
2081 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002082
2083 cmd->bind.att.rt[i] = rt;
2084 }
2085
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002086 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002087
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002088 if (ds_info) {
2089 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002090
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002091 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2092 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002093
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002094 if (width > layout->width0)
2095 width = layout->width0;
2096 if (height > layout->height0)
2097 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002098 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002099 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002100 }
2101
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002102 cmd->bind.att.width = width;
2103 cmd->bind.att.height = height;
Chia-I Wuf8231032014-08-25 10:44:45 +08002104
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002105 emit_rt(cmd);
2106 emit_ds(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002107}
2108
2109static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2110 const struct intel_viewport_state *state)
2111{
2112 cmd->bind.state.viewport = state;
2113}
2114
2115static void cmd_bind_raster_state(struct intel_cmd *cmd,
2116 const struct intel_raster_state *state)
2117{
2118 cmd->bind.state.raster = state;
2119}
2120
2121static void cmd_bind_ds_state(struct intel_cmd *cmd,
2122 const struct intel_ds_state *state)
2123{
2124 cmd->bind.state.ds = state;
2125}
2126
2127static void cmd_bind_blend_state(struct intel_cmd *cmd,
2128 const struct intel_blend_state *state)
2129{
2130 cmd->bind.state.blend = state;
2131}
2132
2133static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2134 const struct intel_msaa_state *state)
2135{
2136 cmd->bind.state.msaa = state;
2137}
2138
2139static void cmd_draw(struct intel_cmd *cmd,
2140 XGL_UINT vertex_start,
2141 XGL_UINT vertex_count,
2142 XGL_UINT instance_start,
2143 XGL_UINT instance_count,
2144 bool indexed,
2145 XGL_UINT vertex_base)
2146{
2147 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2148
2149 emit_bounded_states(cmd);
2150
2151 if (indexed) {
2152 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2153 cmd->result = XGL_ERROR_UNKNOWN;
2154
2155 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2156 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2157 p->primitive_restart_index);
2158 } else {
2159 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2160 cmd->bind.index.offset, cmd->bind.index.type,
2161 p->primitive_restart);
2162 }
2163 } else {
2164 assert(!vertex_base);
2165 }
2166
2167 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2168 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2169 vertex_start, instance_count, instance_start, vertex_base);
2170 } else {
2171 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2172 vertex_start, instance_count, instance_start, vertex_base);
2173 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002174
Chia-I Wu707a29e2014-08-27 12:51:47 +08002175 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002176 /* need to re-emit all workarounds */
2177 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002178}
2179
Chia-I Wub2755562014-08-20 13:38:52 +08002180XGL_VOID XGLAPI intelCmdBindPipeline(
2181 XGL_CMD_BUFFER cmdBuffer,
2182 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2183 XGL_PIPELINE pipeline)
2184{
2185 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2186
2187 switch (pipelineBindPoint) {
2188 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002189 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002190 break;
2191 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002192 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002193 break;
2194 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002195 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002196 break;
2197 }
2198}
2199
2200XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2201 XGL_CMD_BUFFER cmdBuffer,
2202 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2203 XGL_PIPELINE_DELTA delta)
2204{
2205 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2206
2207 switch (pipelineBindPoint) {
2208 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002209 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002210 break;
2211 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002212 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002213 break;
2214 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002215 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002216 break;
2217 }
2218}
2219
2220XGL_VOID XGLAPI intelCmdBindStateObject(
2221 XGL_CMD_BUFFER cmdBuffer,
2222 XGL_STATE_BIND_POINT stateBindPoint,
2223 XGL_STATE_OBJECT state)
2224{
2225 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2226
2227 switch (stateBindPoint) {
2228 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002229 cmd_bind_viewport_state(cmd,
2230 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002231 break;
2232 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002233 cmd_bind_raster_state(cmd,
2234 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002235 break;
2236 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002237 cmd_bind_ds_state(cmd,
2238 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002239 break;
2240 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002241 cmd_bind_blend_state(cmd,
2242 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002243 break;
2244 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002245 cmd_bind_msaa_state(cmd,
2246 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002247 break;
2248 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002249 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002250 break;
2251 }
2252}
2253
2254XGL_VOID XGLAPI intelCmdBindDescriptorSet(
2255 XGL_CMD_BUFFER cmdBuffer,
2256 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2257 XGL_UINT index,
2258 XGL_DESCRIPTOR_SET descriptorSet,
2259 XGL_UINT slotOffset)
2260{
2261 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2262 struct intel_dset *dset = intel_dset(descriptorSet);
2263
2264 assert(!index);
2265
2266 switch (pipelineBindPoint) {
2267 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002268 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002269 break;
2270 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002271 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002272 break;
2273 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002274 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002275 break;
2276 }
2277}
2278
2279XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
2280 XGL_CMD_BUFFER cmdBuffer,
2281 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2282 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
2283{
2284 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2285
2286 switch (pipelineBindPoint) {
2287 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002288 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002289 break;
2290 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002291 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002292 break;
2293 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002294 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002295 break;
2296 }
2297}
2298
2299XGL_VOID XGLAPI intelCmdBindIndexData(
2300 XGL_CMD_BUFFER cmdBuffer,
2301 XGL_GPU_MEMORY mem_,
2302 XGL_GPU_SIZE offset,
2303 XGL_INDEX_TYPE indexType)
2304{
2305 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2306 struct intel_mem *mem = intel_mem(mem_);
2307
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002308 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08002309}
2310
2311XGL_VOID XGLAPI intelCmdBindAttachments(
2312 XGL_CMD_BUFFER cmdBuffer,
2313 XGL_UINT colorAttachmentCount,
2314 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
2315 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
2316{
2317 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08002318
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002319 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
2320 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08002321}
2322
2323XGL_VOID XGLAPI intelCmdDraw(
2324 XGL_CMD_BUFFER cmdBuffer,
2325 XGL_UINT firstVertex,
2326 XGL_UINT vertexCount,
2327 XGL_UINT firstInstance,
2328 XGL_UINT instanceCount)
2329{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002330 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002331
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002332 cmd_draw(cmd, firstVertex, vertexCount,
2333 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08002334}
2335
2336XGL_VOID XGLAPI intelCmdDrawIndexed(
2337 XGL_CMD_BUFFER cmdBuffer,
2338 XGL_UINT firstIndex,
2339 XGL_UINT indexCount,
2340 XGL_INT vertexOffset,
2341 XGL_UINT firstInstance,
2342 XGL_UINT instanceCount)
2343{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002344 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002345
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002346 cmd_draw(cmd, firstIndex, indexCount,
2347 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002348}
2349
2350XGL_VOID XGLAPI intelCmdDrawIndirect(
2351 XGL_CMD_BUFFER cmdBuffer,
2352 XGL_GPU_MEMORY mem,
2353 XGL_GPU_SIZE offset,
2354 XGL_UINT32 count,
2355 XGL_UINT32 stride)
2356{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002357 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2358
2359 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002360}
2361
2362XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
2363 XGL_CMD_BUFFER cmdBuffer,
2364 XGL_GPU_MEMORY mem,
2365 XGL_GPU_SIZE offset,
2366 XGL_UINT32 count,
2367 XGL_UINT32 stride)
2368{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002369 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2370
2371 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002372}
2373
2374XGL_VOID XGLAPI intelCmdDispatch(
2375 XGL_CMD_BUFFER cmdBuffer,
2376 XGL_UINT x,
2377 XGL_UINT y,
2378 XGL_UINT z)
2379{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002380 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2381
2382 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002383}
2384
2385XGL_VOID XGLAPI intelCmdDispatchIndirect(
2386 XGL_CMD_BUFFER cmdBuffer,
2387 XGL_GPU_MEMORY mem,
2388 XGL_GPU_SIZE offset)
2389{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002390 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2391
2392 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08002393}