blob: eb3e5c20f8dbd323676f8bf8eb88f27ffebe6176 [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
Chia-I Wu72292b72014-09-09 10:48:33 +0800319 cmd_batch_pointer(cmd, cmd_len, &dw);
320 dw[0] = dw0;
321 dw[1] = 0;
322 dw[2] = 0;
323 dw[3] = 0;
324 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
325 dw[5] = GEN6_GS_DW5_STATISTICS;
326 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800327}
328
Chia-I Wu62a7f252014-08-29 11:31:16 +0800329static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
330{
331 const uint8_t cmd_len = 7;
332 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800333 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800334
335 CMD_ASSERT(cmd, 7, 7.5);
336
Chia-I Wu72292b72014-09-09 10:48:33 +0800337 cmd_batch_pointer(cmd, cmd_len, &dw);
338 dw[0] = dw0;
339 dw[1] = 0;
340 dw[2] = 0;
341 dw[3] = 0;
342 dw[4] = 0;
343 dw[5] = GEN6_GS_DW5_STATISTICS;
344 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800345}
346
Chia-I Wud88e02d2014-08-25 10:56:13 +0800347static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
348 XGL_UINT width, XGL_UINT height)
349{
350 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800351 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800352 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800353 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354
355 CMD_ASSERT(cmd, 6, 7.5);
356
Chia-I Wu72292b72014-09-09 10:48:33 +0800357 cmd_batch_pointer(cmd, cmd_len, &dw);
358 dw[0] = dw0;
359
Chia-I Wud88e02d2014-08-25 10:56:13 +0800360 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800361 dw[1] = 0;
362 dw[2] = (height - 1) << 16 |
363 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800364 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800365 dw[1] = 1;
366 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800367 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800368
369 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800370}
371
Chia-I Wu8016a172014-08-29 18:31:32 +0800372static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
373 uint32_t body[6])
374{
375 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
376 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
377 const struct intel_raster_state *raster = cmd->bind.state.raster;
378 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
389 raster->cmd_sf_fill;
390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
394 switch (pipeline->db_format.channelFormat) {
395 case XGL_CH_FMT_R16:
396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
398 case XGL_CH_FMT_R32:
399 case XGL_CH_FMT_R32G8:
400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
403 assert(!"unknown depth format");
404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
411 dw2 = raster->cmd_sf_cull;
412
413 if (msaa->sample_count > 1) {
414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
421 if (viewport->scissor_enable)
422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
425 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
438 body[3] = raster->cmd_depth_offset_const;
439 body[4] = raster->cmd_depth_offset_scale;
440 body[5] = raster->cmd_depth_offset_clamp;
441}
442
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800446 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
447 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448 XGL_UINT attr_skip, attr_count;
449 XGL_UINT vue_offset, vue_len;
450 XGL_UINT i;
451 uint32_t dw1;
452
453 CMD_ASSERT(cmd, 6, 7.5);
454
455 /* VS outputs VUE header and position additionally */
456 assert(vs->out_count >= 2);
457 attr_skip = 2;
458 attr_count = vs->out_count - attr_skip;
Steve K42652ba2014-10-07 10:44:41 -0600459 printf("%d %d\n", fs->in_count, attr_count);
Chia-I Wu8016a172014-08-29 18:31:32 +0800460 assert(fs->in_count == attr_count);
461 assert(fs->in_count <= 32);
462
463 vue_offset = attr_skip / 2;
464 vue_len = (attr_count + 1) / 2;
465 if (!vue_len)
466 vue_len = 1;
467
468 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
469 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
470 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
471
472 body[0] = dw1;
473
474 for (i = 0; i < 8; i++) {
475 uint16_t hi, lo;
476
477 /* no attr swizzles */
478 if (i * 2 + 1 < fs->in_count) {
479 hi = i * 2 + 1;
480 lo = i * 2;
481 } else if (i * 2 < fs->in_count) {
482 hi = 0;
483 lo = i * 2;
484 } else {
485 hi = 0;
486 lo = 0;
487 }
488
489 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
490 }
491
492 body[9] = 0; /* point sprite enables */
493 body[10] = 0; /* constant interpolation enables */
494 body[11] = 0; /* WrapShortest enables */
495 body[12] = 0;
496}
497
498static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
499{
500 const uint8_t cmd_len = 20;
501 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
502 (cmd_len - 2);
503 uint32_t sf[6];
504 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800505 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800506
507 CMD_ASSERT(cmd, 6, 6);
508
509 gen7_fill_3DSTATE_SF_body(cmd, sf);
510 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
511
Chia-I Wu72292b72014-09-09 10:48:33 +0800512 cmd_batch_pointer(cmd, cmd_len, &dw);
513 dw[0] = dw0;
514 dw[1] = sbe[0];
515 memcpy(&dw[2], sf, sizeof(sf));
516 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800517}
518
519static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
520{
521 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800522 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800523
524 CMD_ASSERT(cmd, 7, 7.5);
525
Chia-I Wu72292b72014-09-09 10:48:33 +0800526 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800527 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
528 (cmd_len - 2);
529 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800530}
531
532static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
533{
534 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800535 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800536
537 CMD_ASSERT(cmd, 7, 7.5);
538
Chia-I Wu72292b72014-09-09 10:48:33 +0800539 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800540 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
541 (cmd_len - 2);
542 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800543}
544
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800545static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
546{
547 const uint8_t cmd_len = 4;
548 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
549 (cmd_len - 2);
550 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800551 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800552 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
553 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800554 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800555
556 CMD_ASSERT(cmd, 6, 7.5);
557
558 dw1 = GEN6_CLIP_DW1_STATISTICS;
559 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
560 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
561 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
562 raster->cmd_clip_cull;
563 }
564
565 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
566 GEN6_CLIP_DW2_XY_TEST_ENABLE |
567 GEN6_CLIP_DW2_APIMODE_OGL |
568 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
569 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
570 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
571
572 if (pipeline->rasterizerDiscardEnable)
573 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
574 else
575 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
576
577 if (pipeline->depthClipEnable)
578 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
579
580 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
581 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
582 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
583 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
584
585 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
586 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
587 (viewport->viewport_count - 1);
588
Chia-I Wu72292b72014-09-09 10:48:33 +0800589 cmd_batch_pointer(cmd, cmd_len, &dw);
590 dw[0] = dw0;
591 dw[1] = dw1;
592 dw[2] = dw2;
593 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800594}
595
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
597{
598 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
599 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800600 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800601 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
602 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800603 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800604
605 CMD_ASSERT(cmd, 6, 6);
606
607 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
608
609 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
610 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
611
612 dw4 = GEN6_WM_DW4_STATISTICS |
613 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
614 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
615 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
616
617 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
618 GEN6_WM_DW5_PS_ENABLE |
619 GEN6_WM_DW5_8_PIXEL_DISPATCH;
620
621 if (fs->uses & INTEL_SHADER_USE_KILL ||
622 pipeline->cb_state.alphaToCoverageEnable)
623 dw5 |= GEN6_WM_DW5_PS_KILL;
624
625 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
626 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
627 if (fs->uses & INTEL_SHADER_USE_DEPTH)
628 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
629 if (fs->uses & INTEL_SHADER_USE_W)
630 dw5 |= GEN6_WM_DW5_PS_USE_W;
631
632 if (pipeline->cb_state.dualSourceBlendEnable)
633 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
634
635 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
636 GEN6_WM_DW6_POSOFFSET_NONE |
637 GEN6_WM_DW6_ZW_INTERP_PIXEL |
638 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
639 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
640
641 if (msaa->sample_count > 1) {
642 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
643 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
644 } else {
645 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
646 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
647 }
648
Chia-I Wu72292b72014-09-09 10:48:33 +0800649 cmd_batch_pointer(cmd, cmd_len, &dw);
650 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800651 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800652 dw[2] = dw2;
653 dw[3] = 0; /* scratch */
654 dw[4] = dw4;
655 dw[5] = dw5;
656 dw[6] = dw6;
657 dw[7] = 0; /* kernel 1 */
658 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800659}
660
661static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
662{
663 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800664 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800665 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
666 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800667 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668
669 CMD_ASSERT(cmd, 7, 7.5);
670
671 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
672
673 dw1 = GEN7_WM_DW1_STATISTICS |
674 GEN7_WM_DW1_PS_ENABLE |
675 GEN7_WM_DW1_ZW_INTERP_PIXEL |
676 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
677 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
678
679 if (fs->uses & INTEL_SHADER_USE_KILL ||
680 pipeline->cb_state.alphaToCoverageEnable)
681 dw1 |= GEN7_WM_DW1_PS_KILL;
682
683 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
684 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
685 if (fs->uses & INTEL_SHADER_USE_DEPTH)
686 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
687 if (fs->uses & INTEL_SHADER_USE_W)
688 dw1 |= GEN7_WM_DW1_PS_USE_W;
689
690 dw2 = 0;
691
692 if (msaa->sample_count > 1) {
693 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
694 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
695 } else {
696 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
697 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
698 }
699
Chia-I Wu72292b72014-09-09 10:48:33 +0800700 cmd_batch_pointer(cmd, cmd_len, &dw);
701 dw[0] = dw0;
702 dw[1] = dw1;
703 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704}
705
706static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
707{
708 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800709 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800710 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
711 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800712 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800713
714 CMD_ASSERT(cmd, 7, 7.5);
715
716 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
717
718 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
719 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
720
721 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
722 GEN7_PS_DW4_8_PIXEL_DISPATCH;
723
724 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
725 const int max_threads =
726 (cmd->dev->gpu->gt == 3) ? 408 :
727 (cmd->dev->gpu->gt == 2) ? 204 : 102;
728 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
729 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
730 } else {
731 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
732 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
733 }
734
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800735 if (fs->in_count)
736 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
737
738 if (pipeline->cb_state.dualSourceBlendEnable)
739 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
740
741 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
742 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
743 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
744
Chia-I Wu72292b72014-09-09 10:48:33 +0800745 cmd_batch_pointer(cmd, cmd_len, &dw);
746 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800747 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800748 dw[2] = dw2;
749 dw[3] = 0; /* scratch */
750 dw[4] = dw4;
751 dw[5] = dw5;
752 dw[6] = 0; /* kernel 1 */
753 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800754}
755
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800756static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
757 const struct intel_ds_view *view)
758{
759 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800760 uint32_t dw0, *dw;
761 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800762
763 CMD_ASSERT(cmd, 6, 7.5);
764
765 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800766 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
767 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800768 dw0 |= (cmd_len - 2);
769
Chia-I Wu72292b72014-09-09 10:48:33 +0800770 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
771 dw[0] = dw0;
772 dw[1] = view->cmd[0];
773 dw[2] = 0;
774 dw[3] = view->cmd[2];
775 dw[4] = view->cmd[3];
776 dw[5] = view->cmd[4];
777 dw[6] = view->cmd[5];
778
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600779 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800780 cmd_reserve_reloc(cmd, 1);
781 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
782 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600783 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800784}
785
786static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
787 const struct intel_ds_view *view)
788{
789 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 uint32_t dw0, *dw;
791 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800792
793 CMD_ASSERT(cmd, 6, 7.5);
794
795 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800796 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
797 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800798 dw0 |= (cmd_len - 2);
799
Chia-I Wu72292b72014-09-09 10:48:33 +0800800 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
801 dw[0] = dw0;
802 dw[1] = view->cmd[6];
803 dw[2] = 0;
804
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600805 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 cmd_reserve_reloc(cmd, 1);
807 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
808 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600809 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810}
811
812static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
813 const struct intel_ds_view *view)
814{
815 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800816 uint32_t dw0, *dw;
817 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800818
819 CMD_ASSERT(cmd, 6, 7.5);
820
821 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800822 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
823 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800824 dw0 |= (cmd_len - 2);
825
Chia-I Wu72292b72014-09-09 10:48:33 +0800826 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
827 dw[0] = dw0;
828 dw[1] = view->cmd[8];
829 dw[2] = 0;
830
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600831 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800832 cmd_reserve_reloc(cmd, 1);
833 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
834 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600835 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800836}
837
Chia-I Wuf8231032014-08-25 10:44:45 +0800838static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
839 uint32_t clear_val)
840{
841 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800842 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800843 GEN6_CLEAR_PARAMS_DW0_VALID |
844 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800846
847 CMD_ASSERT(cmd, 6, 6);
848
Chia-I Wu72292b72014-09-09 10:48:33 +0800849 cmd_batch_pointer(cmd, cmd_len, &dw);
850 dw[0] = dw0;
851 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800852}
853
854static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
855 uint32_t clear_val)
856{
857 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800858 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800859 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800860 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800861
862 CMD_ASSERT(cmd, 7, 7.5);
863
Chia-I Wu72292b72014-09-09 10:48:33 +0800864 cmd_batch_pointer(cmd, cmd_len, &dw);
865 dw[0] = dw0;
866 dw[1] = clear_val;
867 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800868}
869
Chia-I Wu302742d2014-08-22 10:28:29 +0800870static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800871 uint32_t blend_offset,
872 uint32_t ds_offset,
873 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800874{
875 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800876 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800877
878 CMD_ASSERT(cmd, 6, 6);
879
Chia-I Wu426072d2014-08-26 14:31:55 +0800880 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800881 (cmd_len - 2);
882
Chia-I Wu72292b72014-09-09 10:48:33 +0800883 cmd_batch_pointer(cmd, cmd_len, &dw);
884 dw[0] = dw0;
885 dw[1] = blend_offset | 1;
886 dw[2] = ds_offset | 1;
887 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800888}
889
Chia-I Wu1744cca2014-08-22 11:10:17 +0800890static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800891 uint32_t clip_offset,
892 uint32_t sf_offset,
893 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800894{
895 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800896 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800897
898 CMD_ASSERT(cmd, 6, 6);
899
Chia-I Wu426072d2014-08-26 14:31:55 +0800900 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800901 GEN6_PTR_VP_DW0_CLIP_CHANGED |
902 GEN6_PTR_VP_DW0_SF_CHANGED |
903 GEN6_PTR_VP_DW0_CC_CHANGED |
904 (cmd_len - 2);
905
Chia-I Wu72292b72014-09-09 10:48:33 +0800906 cmd_batch_pointer(cmd, cmd_len, &dw);
907 dw[0] = dw0;
908 dw[1] = clip_offset;
909 dw[2] = sf_offset;
910 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800911}
912
913static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800914 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800915{
916 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800917 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800918
919 CMD_ASSERT(cmd, 6, 6);
920
Chia-I Wu426072d2014-08-26 14:31:55 +0800921 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800922 (cmd_len - 2);
923
Chia-I Wu72292b72014-09-09 10:48:33 +0800924 cmd_batch_pointer(cmd, cmd_len, &dw);
925 dw[0] = dw0;
926 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800927}
928
Chia-I Wu42a56202014-08-23 16:47:48 +0800929static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800930 uint32_t vs_offset,
931 uint32_t gs_offset,
932 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800933{
934 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800935 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800936
937 CMD_ASSERT(cmd, 6, 6);
938
Chia-I Wu426072d2014-08-26 14:31:55 +0800939 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800940 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
941 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
942 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
943 (cmd_len - 2);
944
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 cmd_batch_pointer(cmd, cmd_len, &dw);
946 dw[0] = dw0;
947 dw[1] = vs_offset;
948 dw[2] = gs_offset;
949 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800950}
951
Chia-I Wu257e75e2014-08-29 14:06:35 +0800952static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 uint32_t vs_offset,
954 uint32_t gs_offset,
955 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800956{
957 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800958 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800959
960 CMD_ASSERT(cmd, 6, 6);
961
962 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
963 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
964 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
965 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
966 (cmd_len - 2);
967
Chia-I Wu72292b72014-09-09 10:48:33 +0800968 cmd_batch_pointer(cmd, cmd_len, &dw);
969 dw[0] = dw0;
970 dw[1] = vs_offset;
971 dw[2] = gs_offset;
972 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800973}
974
Chia-I Wu302742d2014-08-22 10:28:29 +0800975static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800976 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800977{
978 const uint8_t cmd_len = 2;
979 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
980 GEN6_RENDER_SUBTYPE_3D |
981 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800982 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800983
Chia-I Wu72292b72014-09-09 10:48:33 +0800984 cmd_batch_pointer(cmd, cmd_len, &dw);
985 dw[0] = dw0;
986 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987}
988
Chia-I Wu72292b72014-09-09 10:48:33 +0800989static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800990 const struct intel_blend_state *state)
991{
Chia-I Wu72292b72014-09-09 10:48:33 +0800992 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800993 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
994
995 CMD_ASSERT(cmd, 6, 7.5);
996 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
997
Chia-I Wu00b51a82014-09-09 12:07:37 +0800998 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
999 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001000}
1001
Chia-I Wu72292b72014-09-09 10:48:33 +08001002static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001003 const struct intel_ds_state *state)
1004{
Chia-I Wu72292b72014-09-09 10:48:33 +08001005 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001006 const uint8_t cmd_len = 3;
1007
1008 CMD_ASSERT(cmd, 6, 7.5);
1009 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1010
Chia-I Wu00b51a82014-09-09 12:07:37 +08001011 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1012 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001013}
1014
Chia-I Wu72292b72014-09-09 10:48:33 +08001015static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001016 uint32_t stencil_ref,
1017 const uint32_t blend_color[4])
1018{
Chia-I Wu72292b72014-09-09 10:48:33 +08001019 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001020 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001021 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001022
1023 CMD_ASSERT(cmd, 6, 7.5);
1024
Chia-I Wu00b51a82014-09-09 12:07:37 +08001025 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1026 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001027 dw[0] = stencil_ref;
1028 dw[1] = 0;
1029 dw[2] = blend_color[0];
1030 dw[3] = blend_color[1];
1031 dw[4] = blend_color[2];
1032 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001033
Chia-I Wu72292b72014-09-09 10:48:33 +08001034 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001035}
1036
Chia-I Wu8370b402014-08-29 12:28:37 +08001037static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001038{
Chia-I Wu8370b402014-08-29 12:28:37 +08001039 CMD_ASSERT(cmd, 6, 7.5);
1040
Chia-I Wu707a29e2014-08-27 12:51:47 +08001041 if (!cmd->bind.draw_count)
1042 return;
1043
Chia-I Wu8370b402014-08-29 12:28:37 +08001044 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001045 return;
1046
Chia-I Wu8370b402014-08-29 12:28:37 +08001047 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001048
1049 /*
1050 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1051 *
1052 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1053 * pipe-control with a post-sync op and no write-cache flushes."
1054 *
1055 * The workaround below necessitates this workaround.
1056 */
1057 gen6_PIPE_CONTROL(cmd,
1058 GEN6_PIPE_CONTROL_CS_STALL |
1059 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001060 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001061
Chia-I Wud6d079d2014-08-31 13:14:21 +08001062 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1063 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001064}
1065
Chia-I Wu8370b402014-08-29 12:28:37 +08001066static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001067{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001068 CMD_ASSERT(cmd, 6, 7.5);
1069
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001070 if (!cmd->bind.draw_count)
1071 return;
1072
Chia-I Wud6d079d2014-08-31 13:14:21 +08001073 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1074 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001075}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001076
Chia-I Wu8370b402014-08-29 12:28:37 +08001077static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1078{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001079 CMD_ASSERT(cmd, 7, 7.5);
1080
Chia-I Wu8370b402014-08-29 12:28:37 +08001081 if (!cmd->bind.draw_count)
1082 return;
1083
1084 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001085
1086 gen6_PIPE_CONTROL(cmd,
1087 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001088 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001089}
1090
Chia-I Wu8370b402014-08-29 12:28:37 +08001091static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1092{
1093 CMD_ASSERT(cmd, 7, 7.5);
1094
1095 if (!cmd->bind.draw_count)
1096 return;
1097
1098 /*
1099 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1100 *
1101 * "One of the following must also be set (when CS stall is set):
1102 *
1103 * * Render Target Cache Flush Enable ([12] of DW1)
1104 * * Depth Cache Flush Enable ([0] of DW1)
1105 * * Stall at Pixel Scoreboard ([1] of DW1)
1106 * * Depth Stall ([13] of DW1)
1107 * * Post-Sync Operation ([13] of DW1)"
1108 */
1109 gen6_PIPE_CONTROL(cmd,
1110 GEN6_PIPE_CONTROL_CS_STALL |
1111 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001112 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001113}
1114
1115static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1116{
1117 CMD_ASSERT(cmd, 7, 7.5);
1118
1119 if (!cmd->bind.draw_count)
1120 return;
1121
1122 cmd_wa_gen6_pre_depth_stall_write(cmd);
1123
Chia-I Wud6d079d2014-08-31 13:14:21 +08001124 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001125}
1126
1127static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1128{
1129 CMD_ASSERT(cmd, 6, 7.5);
1130
1131 if (!cmd->bind.draw_count)
1132 return;
1133
1134 /*
1135 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1136 *
1137 * "Driver must guarentee that all the caches in the depth pipe are
1138 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1139 * requires driver to send a PIPE_CONTROL with a CS stall along with
1140 * a Depth Flush prior to this command."
1141 *
1142 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1143 *
1144 * "Driver must ierarchi that all the caches in the depth pipe are
1145 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1146 * requires driver to send a PIPE_CONTROL with a CS stall along with
1147 * a Depth Flush prior to this command.
1148 */
1149 gen6_PIPE_CONTROL(cmd,
1150 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1151 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001152 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001153}
1154
1155static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1156{
1157 CMD_ASSERT(cmd, 6, 7.5);
1158
1159 if (!cmd->bind.draw_count)
1160 return;
1161
1162 /*
1163 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1164 *
1165 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1166 * and a post sync operation prior to the group of depth
1167 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1168 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1169 *
1170 * This workaround satifies all the conditions.
1171 */
1172 cmd_wa_gen6_pre_depth_stall_write(cmd);
1173
1174 /*
1175 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1176 *
1177 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1178 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1179 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1180 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1181 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1182 * Depth Flush Bit set, followed by another pipelined depth stall
1183 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1184 * guarantee that the pipeline from WM onwards is already flushed
1185 * (e.g., via a preceding MI_FLUSH)."
1186 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001187 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1188 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1189 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001190}
1191
Chia-I Wu525c6602014-08-27 10:22:34 +08001192void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1193{
1194 if (!cmd->bind.draw_count)
1195 return;
1196
1197 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1198
Chia-I Wu8370b402014-08-29 12:28:37 +08001199 /*
1200 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1201 *
1202 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1203 * PIPE_CONTROL with any non-zero post-sync-op is required."
1204 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001205 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001206 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001207
Chia-I Wu092279a2014-08-30 19:05:30 +08001208 /*
1209 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1210 *
1211 * "One of the following must also be set (when CS stall is set):
1212 *
1213 * * Render Target Cache Flush Enable ([12] of DW1)
1214 * * Depth Cache Flush Enable ([0] of DW1)
1215 * * Stall at Pixel Scoreboard ([1] of DW1)
1216 * * Depth Stall ([13] of DW1)
1217 * * Post-Sync Operation ([13] of DW1)"
1218 */
1219 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1220 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1221 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1222 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1223 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1224 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1225
Chia-I Wud6d079d2014-08-31 13:14:21 +08001226 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001227}
1228
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001229void cmd_batch_flush_all(struct intel_cmd *cmd)
1230{
1231 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1232 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1233 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1234 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1235 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1236 GEN6_PIPE_CONTROL_CS_STALL);
1237}
1238
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001239void cmd_batch_depth_count(struct intel_cmd *cmd,
1240 struct intel_bo *bo,
1241 XGL_GPU_SIZE offset)
1242{
1243 cmd_wa_gen6_pre_depth_stall_write(cmd);
1244
1245 gen6_PIPE_CONTROL(cmd,
1246 GEN6_PIPE_CONTROL_DEPTH_STALL |
1247 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001248 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001249}
1250
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001251void cmd_batch_timestamp(struct intel_cmd *cmd,
1252 struct intel_bo *bo,
1253 XGL_GPU_SIZE offset)
1254{
1255 /* need any WA or stall? */
1256 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1257}
1258
1259void cmd_batch_immediate(struct intel_cmd *cmd,
1260 struct intel_bo *bo,
1261 XGL_GPU_SIZE offset,
1262 uint64_t val)
1263{
1264 /* need any WA or stall? */
1265 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1266}
1267
Chia-I Wu302742d2014-08-22 10:28:29 +08001268static void gen6_cc_states(struct intel_cmd *cmd)
1269{
1270 const struct intel_blend_state *blend = cmd->bind.state.blend;
1271 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001272 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001273 uint32_t stencil_ref;
1274 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001275
1276 CMD_ASSERT(cmd, 6, 6);
1277
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001278 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001279 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001280 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1281 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001282 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001283 memset(blend_color, 0, sizeof(blend_color));
1284 }
1285
1286 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001287 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001288 stencil_ref = ds->cmd_stencil_ref;
1289 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001290 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001291 stencil_ref = 0;
1292 }
1293
Chia-I Wu72292b72014-09-09 10:48:33 +08001294 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001295
Chia-I Wu72292b72014-09-09 10:48:33 +08001296 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001297}
1298
Chia-I Wu1744cca2014-08-22 11:10:17 +08001299static void gen6_viewport_states(struct intel_cmd *cmd)
1300{
1301 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001302 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001303
1304 if (!viewport)
1305 return;
1306
Chia-I Wub1d450a2014-09-09 13:48:03 +08001307 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1308 viewport->viewport_count);
1309
1310 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1311 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1312 viewport->cmd);
1313
1314 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1315 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1316 &viewport->cmd[viewport->cmd_clip_pos]);
1317
1318 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1319 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1320 &viewport->cmd[viewport->cmd_cc_pos]);
1321
1322 if (viewport->scissor_enable) {
1323 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1324 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1325 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1326 } else {
1327 scissor_offset = 0;
1328 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001329
1330 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001331 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001332
Chia-I Wub1d450a2014-09-09 13:48:03 +08001333 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001334}
1335
Chia-I Wu302742d2014-08-22 10:28:29 +08001336static void gen7_cc_states(struct intel_cmd *cmd)
1337{
1338 const struct intel_blend_state *blend = cmd->bind.state.blend;
1339 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001340 uint32_t stencil_ref;
1341 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001342 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001343
1344 CMD_ASSERT(cmd, 7, 7.5);
1345
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001346 if (!blend && !ds)
1347 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001348
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001349 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001350 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001351 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001352 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001353
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001354 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1355 } else {
1356 memset(blend_color, 0, sizeof(blend_color));
1357 }
1358
1359 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001360 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001361 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001362 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1363 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001364 } else {
1365 stencil_ref = 0;
1366 }
1367
Chia-I Wu72292b72014-09-09 10:48:33 +08001368 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001369 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001370 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001371}
1372
Chia-I Wu1744cca2014-08-22 11:10:17 +08001373static void gen7_viewport_states(struct intel_cmd *cmd)
1374{
1375 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001376 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001377
1378 if (!viewport)
1379 return;
1380
Chia-I Wub1d450a2014-09-09 13:48:03 +08001381 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1382 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001383
Chia-I Wub1d450a2014-09-09 13:48:03 +08001384 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1385 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1386 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001387 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001388 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1389 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001390
1391 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1392 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1393 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001394 gen7_3dstate_pointer(cmd,
1395 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001396 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001397
Chia-I Wu1744cca2014-08-22 11:10:17 +08001398 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001399 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1400 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1401 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001402 gen7_3dstate_pointer(cmd,
1403 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001404 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001405 }
1406}
1407
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001408static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001409 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001410{
1411 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001412 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001413
Chia-I Wu72292b72014-09-09 10:48:33 +08001414 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001415
1416 dw[0] = GEN6_RENDER_TYPE_RENDER |
1417 GEN6_RENDER_SUBTYPE_3D |
1418 subop | (cmd_len - 2);
1419 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001420 dw[2] = 0;
1421 dw[3] = 0;
1422 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001423}
1424
1425static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001426 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001427{
1428 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001429 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001430
Chia-I Wu72292b72014-09-09 10:48:33 +08001431 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001432
1433 dw[0] = GEN6_RENDER_TYPE_RENDER |
1434 GEN6_RENDER_SUBTYPE_3D |
1435 subop | (cmd_len - 2);
1436 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001437 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001438 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001439 dw[4] = 0;
1440 dw[5] = 0;
1441 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001442}
1443
Chia-I Wu625105f2014-10-13 15:35:29 +08001444static uint32_t emit_samplers(struct intel_cmd *cmd,
1445 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001446{
1447 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1448 const XGL_UINT border_stride =
1449 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001450 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001451 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001452 XGL_UINT i;
1453
1454 CMD_ASSERT(cmd, 6, 7.5);
1455
Chia-I Wu625105f2014-10-13 15:35:29 +08001456 if (!rmap || !rmap->sampler_count)
1457 return 0;
1458
1459 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1460
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001461 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1462 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1463 border_stride * rmap->sampler_count, &border_dw);
1464
1465 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1466 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1467 4 * rmap->sampler_count, &sampler_dw);
1468
1469 for (i = 0; i < rmap->sampler_count; i++) {
1470 const struct intel_pipeline_rmap_slot *slot =
1471 &rmap->slots[surface_count + i];
1472 const struct intel_sampler *sampler;
1473
1474 switch (slot->path_len) {
1475 case 0:
1476 sampler = NULL;
1477 break;
1478 case INTEL_PIPELINE_RMAP_SLOT_RT:
1479 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1480 assert(!"unexpected rmap slot type");
1481 sampler = NULL;
1482 break;
1483 case 1:
1484 {
1485 const struct intel_dset *dset = cmd->bind.dset.graphics;
1486 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1487 const struct intel_dset_slot *dset_slot =
1488 &dset->slots[slot_offset + slot->u.index];
1489
1490 switch (dset_slot->type) {
1491 case INTEL_DSET_SLOT_SAMPLER:
1492 sampler = dset_slot->u.sampler;
1493 break;
1494 default:
1495 assert(!"unexpected dset slot type");
1496 sampler = NULL;
1497 break;
1498 }
1499 }
1500 break;
1501 default:
1502 assert(!"nested descriptor set unsupported");
1503 sampler = NULL;
1504 break;
1505 }
1506
1507 if (sampler) {
1508 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1509
1510 sampler_dw[0] = sampler->cmd[0];
1511 sampler_dw[1] = sampler->cmd[1];
1512 sampler_dw[2] = border_offset;
1513 sampler_dw[3] = sampler->cmd[2];
1514 } else {
1515 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1516 sampler_dw[1] = 0;
1517 sampler_dw[2] = 0;
1518 sampler_dw[3] = 0;
1519 }
1520
1521 border_offset += border_stride * 4;
1522 border_dw += border_stride;
1523 sampler_dw += 4;
1524 }
1525
Chia-I Wu625105f2014-10-13 15:35:29 +08001526 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001527}
1528
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001529static uint32_t emit_binding_table(struct intel_cmd *cmd,
1530 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001531{
Chia-I Wu72292b72014-09-09 10:48:33 +08001532 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001533 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001534
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001535 CMD_ASSERT(cmd, 6, 7.5);
1536
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001537 surface_count = (rmap) ?
1538 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1539 if (!surface_count)
1540 return 0;
1541
Chia-I Wu42a56202014-08-23 16:47:48 +08001542 assert(surface_count <= ARRAY_SIZE(binding_table));
1543
1544 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001545 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001546
1547 switch (slot->path_len) {
1548 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001549 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001550 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001551 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001552 {
1553 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1554
Chia-I Wu00b51a82014-09-09 12:07:37 +08001555 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001556 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1557 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001558
Chia-I Wu72292b72014-09-09 10:48:33 +08001559 cmd_reserve_reloc(cmd, 1);
1560 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1561 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001562 }
1563 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001564 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001565 {
1566 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001567 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001568
Chia-I Wu00b51a82014-09-09 12:07:37 +08001569 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001570 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1571 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001572
Chia-I Wu72292b72014-09-09 10:48:33 +08001573 cmd_reserve_reloc(cmd, 1);
1574 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1575 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001576 }
1577 break;
1578 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001579 {
1580 const struct intel_dset *dset = cmd->bind.dset.graphics;
1581 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1582 const struct intel_dset_slot *dset_slot =
1583 &dset->slots[slot_offset + slot->u.index];
1584
1585 switch (dset_slot->type) {
1586 case INTEL_DSET_SLOT_IMG_VIEW:
1587 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1588 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1589 dset_slot->u.img_view->cmd_len,
1590 dset_slot->u.img_view->cmd);
1591
1592 cmd_reserve_reloc(cmd, 1);
1593 cmd_surface_reloc(cmd, offset, 1,
1594 dset_slot->u.img_view->img->obj.mem->bo,
1595 dset_slot->u.img_view->cmd[1], 0);
1596 break;
1597 case INTEL_DSET_SLOT_MEM_VIEW:
1598 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1599 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1600 dset_slot->u.mem_view.cmd_len,
1601 dset_slot->u.mem_view.cmd);
1602
1603 cmd_reserve_reloc(cmd, 1);
1604 cmd_surface_reloc(cmd, offset, 1,
1605 dset_slot->u.mem_view.mem->bo,
1606 dset_slot->u.mem_view.cmd[1], 0);
1607 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001608 case INTEL_DSET_SLOT_SAMPLER:
1609 assert(0 == cmd->bind.dset.graphics_offset);
1610
1611 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1612 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1613 16, dset_slot->u.sampler->cmd);
1614 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001615 default:
1616 assert(!"unexpected dset slot type");
1617 break;
1618 }
1619 }
1620 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001621 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001622 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001623 break;
1624 }
1625
Chia-I Wu72292b72014-09-09 10:48:33 +08001626 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001627 }
1628
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001629 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001630 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001631 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001632}
1633
Chia-I Wu1d125092014-10-08 08:49:38 +08001634static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1635{
1636 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1637 const struct intel_pipeline_rmap *rmap = pipeline->vs.rmap;
1638 const struct intel_dset *dset = cmd->bind.dset.graphics;
1639 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1640 uint32_t *dw;
1641 XGL_UINT pos, i;
1642
1643 CMD_ASSERT(cmd, 6, 7.5);
1644
1645 if (!pipeline->vb_count)
1646 return;
1647
1648 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1649
1650 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1651 dw++;
1652 pos++;
1653
1654 for (i = 0; i < pipeline->vb_count; i++) {
1655 const XGL_UINT vb_offset = rmap->rt_count + rmap->resource_count +
1656 rmap->uav_count + rmap->sampler_count;
1657 const struct intel_pipeline_rmap_slot *slot = (i < rmap->vb_count) ?
1658 &rmap->slots[vb_offset + i] : NULL;
1659 struct intel_mem_view *view = NULL;
1660
1661 if (slot) {
1662 switch (slot->path_len) {
1663 case 1:
1664 view = (dset->slots[slot->u.index].type ==
1665 INTEL_DSET_SLOT_MEM_VIEW) ?
1666 &dset->slots[slot->u.index].u.mem_view : NULL;
1667 break;
1668 default:
1669 break;
1670 }
1671 }
1672
1673 assert(pipeline->vb[i].strideInBytes <= 2048);
1674
1675 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1676 pipeline->vb[i].strideInBytes;
1677
1678 if (cmd_gen(cmd) >= INTEL_GEN(7))
1679 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1680
1681 switch (pipeline->vb[i].stepRate) {
1682 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1683 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1684 dw[3] = 0;
1685 break;
1686 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1687 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1688 dw[3] = 1;
1689 break;
1690 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1691 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1692 dw[3] = 0;
1693 break;
1694 default:
1695 assert(!"unknown step rate");
1696 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1697 dw[3] = 0;
1698 break;
1699 }
1700
1701 if (view) {
1702 const uint32_t begin = view->cmd[1];
1703 const uint32_t end = view->mem->size - 1;
1704
1705 cmd_reserve_reloc(cmd, 2);
1706 cmd_batch_reloc(cmd, pos + 1, view->mem->bo, begin, 0);
1707 cmd_batch_reloc(cmd, pos + 2, view->mem->bo, end, 0);
1708 } else {
1709 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1710 dw[1] = 0;
1711 dw[2] = 0;
1712 }
1713
1714 dw += 4;
1715 pos += 4;
1716 }
1717}
1718
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001719static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1720{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001721 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1722 const struct intel_pipeline_shader *vs = &pipeline->vs;
1723 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001724 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001725 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001726 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001727
1728 CMD_ASSERT(cmd, 6, 7.5);
1729
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001730 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001731 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1732 *
1733 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1734 * 128-bit vertex elements to be passed into the payload for each
1735 * vertex."
1736 *
1737 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1738 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001739 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001740 vue_read_len = (vs->in_count + 1) / 2;
1741 if (!vue_read_len)
1742 vue_read_len = 1;
1743
1744 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1745 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1746
1747 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1748 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1749 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001750
1751 dw5 = GEN6_VS_DW5_STATISTICS |
1752 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001753
1754 switch (cmd_gen(cmd)) {
1755 case INTEL_GEN(7.5):
1756 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1757 break;
1758 case INTEL_GEN(7):
1759 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1760 break;
1761 case INTEL_GEN(6):
1762 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1763 break;
1764 default:
1765 max_threads = 1;
1766 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001767 }
1768
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001769 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1770 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1771 else
1772 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1773
Chia-I Wube0a3d92014-09-02 13:20:59 +08001774 if (pipeline->disable_vs_cache)
1775 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1776
Chia-I Wu72292b72014-09-09 10:48:33 +08001777 cmd_batch_pointer(cmd, cmd_len, &dw);
1778 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001779 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001780 dw[2] = dw2;
1781 dw[3] = 0; /* scratch */
1782 dw[4] = dw4;
1783 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001784}
1785
Chia-I Wu625105f2014-10-13 15:35:29 +08001786static void emit_shader_resources(struct intel_cmd *cmd)
1787{
1788 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001789 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001790
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001791 binding_tables[0] = emit_binding_table(cmd,
1792 cmd->bind.pipeline.graphics->vs.rmap);
1793 binding_tables[1] = emit_binding_table(cmd,
1794 cmd->bind.pipeline.graphics->tcs.rmap);
1795 binding_tables[2] = emit_binding_table(cmd,
1796 cmd->bind.pipeline.graphics->tes.rmap);
1797 binding_tables[3] = emit_binding_table(cmd,
1798 cmd->bind.pipeline.graphics->gs.rmap);
1799 binding_tables[4] = emit_binding_table(cmd,
1800 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001801
1802 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1803 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1804 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1805 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1806 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1807
1808 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1809 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001810 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1811 binding_tables[0]);
1812 gen7_3dstate_pointer(cmd,
1813 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1814 binding_tables[1]);
1815 gen7_3dstate_pointer(cmd,
1816 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1817 binding_tables[2]);
1818 gen7_3dstate_pointer(cmd,
1819 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1820 binding_tables[3]);
1821 gen7_3dstate_pointer(cmd,
1822 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1823 binding_tables[4]);
1824
1825 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001826 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1827 samplers[0]);
1828 gen7_3dstate_pointer(cmd,
1829 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1830 samplers[1]);
1831 gen7_3dstate_pointer(cmd,
1832 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1833 samplers[2]);
1834 gen7_3dstate_pointer(cmd,
1835 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1836 samplers[3]);
1837 gen7_3dstate_pointer(cmd,
1838 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1839 samplers[4]);
1840 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001841 assert(!binding_tables[1] && !binding_tables[2]);
1842 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1843 binding_tables[0], binding_tables[3], binding_tables[4]);
1844
Chia-I Wu625105f2014-10-13 15:35:29 +08001845 assert(!samplers[1] && !samplers[2]);
1846 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1847 samplers[0], samplers[3], samplers[4]);
1848 }
1849}
1850
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001851static void emit_rt(struct intel_cmd *cmd)
1852{
1853 cmd_wa_gen6_pre_depth_stall_write(cmd);
1854 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1855 cmd->bind.att.height);
1856}
1857
1858static void emit_ds(struct intel_cmd *cmd)
1859{
1860 const struct intel_ds_view *ds = cmd->bind.att.ds;
1861
1862 if (!ds) {
1863 /* all zeros */
1864 static const struct intel_ds_view null_ds;
1865 ds = &null_ds;
1866 }
1867
1868 cmd_wa_gen6_pre_ds_flush(cmd);
1869 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1870 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1871 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1872
1873 if (cmd_gen(cmd) >= INTEL_GEN(7))
1874 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1875 else
1876 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1877}
1878
Chia-I Wua57761b2014-10-14 14:27:44 +08001879static uint32_t emit_shader(struct intel_cmd *cmd,
1880 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001881{
Chia-I Wua57761b2014-10-14 14:27:44 +08001882 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1883 uint32_t offset;
1884 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001885
Chia-I Wua57761b2014-10-14 14:27:44 +08001886 /* see if the shader is already in the cache */
1887 for (i = 0; i < cache->used; i++) {
1888 if (cache->entries[i].shader == (const void *) shader)
1889 return cache->entries[i].kernel_offset;
1890 }
1891
1892 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1893
1894 /* grow the cache if full */
1895 if (cache->used >= cache->count) {
1896 const XGL_UINT count = cache->count + 16;
1897 void *entries;
1898
1899 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1900 XGL_SYSTEM_ALLOC_INTERNAL);
1901 if (entries) {
1902 if (cache->entries) {
1903 memcpy(entries, cache->entries,
1904 sizeof(cache->entries[0]) * cache->used);
1905 icd_free(cache->entries);
1906 }
1907
1908 cache->entries = entries;
1909 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001910 }
1911 }
1912
Chia-I Wua57761b2014-10-14 14:27:44 +08001913 /* add the shader to the cache */
1914 if (cache->used < cache->count) {
1915 cache->entries[cache->used].shader = (const void *) shader;
1916 cache->entries[cache->used].kernel_offset = offset;
1917 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001918 }
1919
Chia-I Wua57761b2014-10-14 14:27:44 +08001920 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001921}
1922
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001923static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001924{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001925 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001926
Chia-I Wu8370b402014-08-29 12:28:37 +08001927 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1928 cmd_wa_gen6_pre_depth_stall_write(cmd);
1929 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1930 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1931 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1932 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001933
1934 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001935 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001936 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001937
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001938 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001939 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001940 }
1941 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001942 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001943 }
1944 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001945 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1946 }
1947 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1948 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1949 }
1950 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1951 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001952 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001953
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001954 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1955 gen7_3DSTATE_GS(cmd);
1956 } else {
1957 gen6_3DSTATE_GS(cmd);
1958 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001959
Chia-I Wu8370b402014-08-29 12:28:37 +08001960 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1961 cmd_wa_gen7_post_command_cs_stall(cmd);
1962 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1963 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001964}
1965
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001966static void emit_bounded_states(struct intel_cmd *cmd)
1967{
1968 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1969
1970 emit_graphics_pipeline(cmd);
1971
1972 emit_rt(cmd);
1973 emit_ds(cmd);
1974
1975 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1976 gen7_cc_states(cmd);
1977 gen7_viewport_states(cmd);
1978
1979 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1980 &cmd->bind.pipeline.graphics->vs);
1981 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1982 &cmd->bind.pipeline.graphics->fs);
1983
1984 gen6_3DSTATE_CLIP(cmd);
1985 gen7_3DSTATE_SF(cmd);
1986 gen7_3DSTATE_SBE(cmd);
1987 gen7_3DSTATE_WM(cmd);
1988 gen7_3DSTATE_PS(cmd);
1989 } else {
1990 gen6_cc_states(cmd);
1991 gen6_viewport_states(cmd);
1992
1993 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1994 &cmd->bind.pipeline.graphics->vs);
1995 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1996 &cmd->bind.pipeline.graphics->fs);
1997
1998 gen6_3DSTATE_CLIP(cmd);
1999 gen6_3DSTATE_SF(cmd);
2000 gen6_3DSTATE_WM(cmd);
2001 }
2002
2003 emit_shader_resources(cmd);
2004
2005 cmd_wa_gen6_pre_depth_stall_write(cmd);
2006 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2007
2008 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2009 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2010
2011 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2012 gen6_3DSTATE_VS(cmd);
2013}
2014
Chia-I Wu6032b892014-10-17 14:47:18 +08002015static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2016{
2017 const struct intel_cmd_meta *meta = cmd->bind.meta;
2018 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2019
2020 CMD_ASSERT(cmd, 6, 7.5);
2021
2022 blend_offset = 0;
2023 ds_offset = 0;
2024 cc_offset = 0;
2025 cc_vp_offset = 0;
2026
2027 if (meta->dst.valid) {
2028 /* BLEND_STATE */
2029 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
2030 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2031 dw[0] = 0;
2032 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2033 }
2034
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002035 if (meta->ds.state) {
2036 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002037
2038 /* DEPTH_STENCIL_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002039 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002040
2041 /* COLOR_CALC_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002042 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2043 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002044
2045 /* CC_VIEWPORT */
2046 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
2047 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002048 dw[0] = u_fui(0.0f);
2049 dw[1] = u_fui(1.0f);
Chia-I Wua667c2b2014-10-28 11:40:29 +08002050 } else {
2051 /* DEPTH_STENCIL_STATE */
2052 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2053 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4,
2054 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2055 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
Chia-I Wu6032b892014-10-17 14:47:18 +08002056 }
2057
2058 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2059 gen7_3dstate_pointer(cmd,
2060 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2061 blend_offset);
2062 gen7_3dstate_pointer(cmd,
2063 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2064 ds_offset);
2065 gen7_3dstate_pointer(cmd,
2066 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2067
2068 gen7_3dstate_pointer(cmd,
2069 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2070 cc_vp_offset);
2071 } else {
2072 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002073 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002074
2075 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2076 cmd_batch_pointer(cmd, 4, &dw);
2077 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2078 GEN6_PTR_VP_DW0_CC_CHANGED;
2079 dw[1] = 0;
2080 dw[2] = 0;
2081 dw[3] = cc_vp_offset;
2082 }
2083}
2084
2085static void gen6_meta_surface_states(struct intel_cmd *cmd)
2086{
2087 const struct intel_cmd_meta *meta = cmd->bind.meta;
2088 uint32_t binding_table[2];
2089 XGL_UINT surface_count = 0;
2090 uint32_t offset;
2091
2092 CMD_ASSERT(cmd, 6, 7.5);
2093
2094 /* SURFACE_STATE */
2095 if (meta->dst.valid) {
2096 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2097 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2098 meta->dst.surface_len, meta->dst.surface);
2099
2100 cmd_reserve_reloc(cmd, 1);
2101 cmd_surface_reloc(cmd, offset, 1,
2102 (struct intel_bo *) meta->dst.reloc_target,
2103 meta->dst.reloc_offset, meta->dst.reloc_flags);
2104
2105 binding_table[surface_count++] = offset;
2106 }
2107 if (meta->src.valid) {
2108 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2109 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2110 meta->src.surface_len, meta->src.surface);
2111
2112 cmd_reserve_reloc(cmd, 1);
2113 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2114 cmd_surface_reloc_writer(cmd, offset, 1,
2115 meta->src.reloc_target, meta->src.reloc_offset);
2116 } else {
2117 cmd_surface_reloc(cmd, offset, 1,
2118 (struct intel_bo *) meta->src.reloc_target,
2119 meta->src.reloc_offset, meta->src.reloc_flags);
2120 }
2121
2122 binding_table[surface_count++] = offset;
2123 }
2124
2125 /* BINDING_TABLE */
2126 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
2127 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
2128 surface_count, binding_table);
2129
2130 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2131 gen7_3dstate_pointer(cmd,
2132 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2133 offset);
2134 } else {
2135 /* 3DSTATE_BINDING_TABLE_POINTERS */
2136 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
2137 }
2138}
2139
2140static void gen6_meta_urb(struct intel_cmd *cmd)
2141{
2142 uint32_t *dw;
2143
2144 CMD_ASSERT(cmd, 6, 6);
2145
2146 /* 3DSTATE_URB */
2147 cmd_batch_pointer(cmd, 3, &dw);
2148 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
2149 dw[1] = 128 << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
2150 dw[2] = 0;
2151}
2152
2153static void gen7_meta_urb(struct intel_cmd *cmd)
2154{
2155 uint32_t *dw;
2156
2157 CMD_ASSERT(cmd, 7, 7.5);
2158
2159 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2160 cmd_batch_pointer(cmd, 10, &dw);
2161
2162 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
2163 dw[1] = 0;
2164 dw += 2;
2165
2166 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2167 dw[1] = 0;
2168 dw += 2;
2169
2170 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2171 dw[1] = 0;
2172 dw += 2;
2173
2174 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2175 dw[1] = 0;
2176 dw += 2;
2177
2178 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2179 dw[1] = 1;
2180
2181 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2182
2183 /* 3DSTATE_URB_x */
2184 cmd_batch_pointer(cmd, 8, &dw);
2185
2186 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2187 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
2188 512;
2189 dw += 2;
2190
2191 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2192 dw[1] = 0;
2193 dw += 2;
2194
2195 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2196 dw[1] = 0;
2197 dw += 2;
2198
2199 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2200 dw[1] = 0;
2201 dw += 2;
2202}
2203
2204static void gen6_meta_vf(struct intel_cmd *cmd)
2205{
2206 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002207 uint32_t vb_start, vb_end, vb_stride;
2208 int ve_format, ve_z_source;
2209 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002210 XGL_UINT pos;
2211
2212 CMD_ASSERT(cmd, 6, 7.5);
2213
2214 /* write vertices */
Chia-I Wu3adf7212014-10-24 15:34:07 +08002215 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2216 XGL_FLOAT vertices[3][3];
2217
2218 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2219 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2220 vertices[0][2] = u_uif(meta->clear_val[0]);
2221 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2222 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2223 vertices[1][2] = u_uif(meta->clear_val[0]);
2224 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2225 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2226 vertices[2][2] = u_uif(meta->clear_val[0]);
2227
2228 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2229 sizeof(vertices) / 4, (const uint32_t *) vertices);
2230
2231 vb_end = vb_start + sizeof(vertices) - 1;
2232 vb_stride = sizeof(vertices[0]);
2233 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2234 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2235 } else {
2236 XGL_UINT vertices[3][2];
2237
2238 vertices[0][0] = meta->dst.x + meta->width;
2239 vertices[0][1] = meta->dst.y + meta->height;
2240 vertices[1][0] = meta->dst.x;
2241 vertices[1][1] = meta->dst.y + meta->height;
2242 vertices[2][0] = meta->dst.x;
2243 vertices[2][1] = meta->dst.y;
2244
2245 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2246 sizeof(vertices) / 4, (const uint32_t *) vertices);
2247
2248 vb_end = vb_start + sizeof(vertices) - 1;
2249 vb_stride = sizeof(vertices[0]);
2250 ve_z_source = GEN6_VFCOMP_STORE_0;
2251 ve_format = GEN6_FORMAT_R32G32_USCALED;
2252 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002253
2254 /* 3DSTATE_VERTEX_BUFFERS */
2255 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002256
Chia-I Wu6032b892014-10-17 14:47:18 +08002257 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002258 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002259 if (cmd_gen(cmd) >= INTEL_GEN(7))
2260 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2261
2262 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002263 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2264 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002265
2266 dw[4] = 0;
2267
2268 /* 3DSTATE_VERTEX_ELEMENTS */
2269 cmd_batch_pointer(cmd, 5, &dw);
2270 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
2271 dw[1] = GEN6_VE_STATE_DW0_VALID,
2272 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2273 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2274 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2275 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2276 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002277 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002278 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2279 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002280 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002281 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2282}
2283
2284static void gen6_meta_disabled(struct intel_cmd *cmd)
2285{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002286 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002287 uint32_t *dw;
2288
2289 CMD_ASSERT(cmd, 6, 6);
2290
2291 /* 3DSTATE_CONSTANT_VS */
2292 cmd_batch_pointer(cmd, 5, &dw);
2293 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2);
2294 dw[1] = 0;
2295 dw[2] = 0;
2296 dw[3] = 0;
2297 dw[4] = 0;
2298
2299 /* 3DSTATE_VS */
2300 cmd_batch_pointer(cmd, 6, &dw);
2301 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2302 dw[1] = 0;
2303 dw[2] = 0;
2304 dw[3] = 0;
2305 dw[4] = 0;
2306 dw[5] = 0;
2307
2308 /* 3DSTATE_CONSTANT_GS */
2309 cmd_batch_pointer(cmd, 5, &dw);
2310 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2311 dw[1] = 0;
2312 dw[2] = 0;
2313 dw[3] = 0;
2314 dw[4] = 0;
2315
2316 /* 3DSTATE_GS */
2317 cmd_batch_pointer(cmd, 7, &dw);
2318 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2319 dw[1] = 0;
2320 dw[2] = 0;
2321 dw[3] = 0;
2322 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2323 dw[5] = GEN6_GS_DW5_STATISTICS;
2324 dw[6] = 0;
2325
2326 /* 3DSTATE_CLIP */
2327 cmd_batch_pointer(cmd, 4, &dw);
2328 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2329 dw[1] = 0;
2330 dw[2] = 0;
2331 dw[3] = 0;
2332
2333 /* 3DSTATE_SF */
2334 cmd_batch_pointer(cmd, 20, &dw);
2335 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2336 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2337 memset(&dw[2], 0, 18 * sizeof(*dw));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002338
2339 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2340 /* 3DSTATE_CONSTANT_PS */
2341 cmd_batch_pointer(cmd, 5, &dw);
2342 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2343 dw[1] = 0;
2344 dw[2] = 0;
2345 dw[3] = 0;
2346 dw[4] = 0;
2347
2348 /* 3DSTATE_WM */
2349 cmd_batch_pointer(cmd, 9, &dw);
2350 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2351 dw[1] = 0;
2352 dw[2] = 0;
2353 dw[3] = 0;
2354 dw[4] = 0;
2355 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
2356 dw[6] = 0;
2357 dw[7] = 0;
2358 dw[8] = 0;
2359 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002360}
2361
2362static void gen7_meta_disabled(struct intel_cmd *cmd)
2363{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002364 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002365 uint32_t *dw;
2366
2367 CMD_ASSERT(cmd, 7, 7.5);
2368
2369 /* 3DSTATE_CONSTANT_VS */
2370 cmd_batch_pointer(cmd, 7, &dw);
2371 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2372 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2373
2374 /* 3DSTATE_VS */
2375 cmd_batch_pointer(cmd, 6, &dw);
2376 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2377 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2378
2379 /* 3DSTATE_CONSTANT_HS */
2380 cmd_batch_pointer(cmd, 7, &dw);
2381 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2382 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2383
2384 /* 3DSTATE_HS */
2385 cmd_batch_pointer(cmd, 7, &dw);
2386 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2387 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2388
2389 /* 3DSTATE_TE */
2390 cmd_batch_pointer(cmd, 4, &dw);
2391 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2392 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2393
2394 /* 3DSTATE_CONSTANT_DS */
2395 cmd_batch_pointer(cmd, 7, &dw);
2396 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2397 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2398
2399 /* 3DSTATE_DS */
2400 cmd_batch_pointer(cmd, 6, &dw);
2401 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2402 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2403
2404 /* 3DSTATE_CONSTANT_GS */
2405 cmd_batch_pointer(cmd, 7, &dw);
2406 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2407 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2408
2409 /* 3DSTATE_GS */
2410 cmd_batch_pointer(cmd, 7, &dw);
2411 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2412 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2413
2414 /* 3DSTATE_STREAMOUT */
2415 cmd_batch_pointer(cmd, 3, &dw);
2416 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2417 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2418
2419 /* 3DSTATE_CLIP */
2420 cmd_batch_pointer(cmd, 4, &dw);
2421 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2422 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2423
2424 /* 3DSTATE_SF */
2425 cmd_batch_pointer(cmd, 7, &dw);
2426 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2427 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2428
2429 /* 3DSTATE_SBE */
2430 cmd_batch_pointer(cmd, 14, &dw);
2431 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2432 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2433 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002434
2435 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2436 /* 3DSTATE_WM */
2437 cmd_batch_pointer(cmd, 3, &dw);
2438 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2439 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2440
2441 /* 3DSTATE_CONSTANT_GS */
2442 cmd_batch_pointer(cmd, 7, &dw);
2443 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2444 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2445
2446 /* 3DSTATE_PS */
2447 cmd_batch_pointer(cmd, 8, &dw);
2448 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2449 dw[1] = 0;
2450 dw[2] = 0;
2451 dw[3] = 0;
2452 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
2453 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2454 dw[5] = 0;
2455 dw[6] = 0;
2456 dw[7] = 0;
2457 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002458}
2459
2460static void gen6_meta_wm(struct intel_cmd *cmd)
2461{
2462 const struct intel_cmd_meta *meta = cmd->bind.meta;
2463 uint32_t *dw;
2464
2465 CMD_ASSERT(cmd, 6, 7.5);
2466
2467 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2468
2469 /* 3DSTATE_MULTISAMPLE */
2470 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2471 cmd_batch_pointer(cmd, 4, &dw);
2472 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2473 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2474 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2475 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2476 dw[2] = 0;
2477 dw[3] = 0;
2478 } else {
2479 cmd_batch_pointer(cmd, 3, &dw);
2480 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2481 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2482 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2483 dw[2] = 0;
2484 }
2485
2486 /* 3DSTATE_SAMPLE_MASK */
2487 cmd_batch_pointer(cmd, 2, &dw);
2488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2489 dw[1] = (1 << meta->samples) - 1;
2490
2491 /* 3DSTATE_DRAWING_RECTANGLE */
2492 cmd_batch_pointer(cmd, 4, &dw);
2493 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2494 dw[1] = meta->dst.y << 16 | meta->dst.x;
2495 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2496 (meta->dst.x + meta->width - 1);
2497 dw[3] = 0;
2498}
2499
2500static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2501{
2502 const struct intel_cmd_meta *meta = cmd->bind.meta;
2503 XGL_UINT offset_x, offset_y;
2504 /* one GPR */
2505 XGL_UINT consts[8];
2506 XGL_UINT const_count;
2507
2508 CMD_ASSERT(cmd, 6, 7.5);
2509
2510 /* underflow is fine here */
2511 offset_x = meta->src.x - meta->dst.x;
2512 offset_y = meta->src.y - meta->dst.y;
2513
2514 switch (meta->shader_id) {
2515 case INTEL_DEV_META_FS_COPY_MEM:
2516 case INTEL_DEV_META_FS_COPY_1D:
2517 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2518 case INTEL_DEV_META_FS_COPY_2D:
2519 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2520 case INTEL_DEV_META_FS_COPY_2D_MS:
2521 consts[0] = offset_x;
2522 consts[1] = offset_y;
2523 consts[2] = meta->src.layer;
2524 consts[3] = meta->src.lod;
2525 const_count = 4;
2526 break;
2527 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2528 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2529 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2530 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2531 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2532 consts[0] = offset_x;
2533 consts[1] = offset_y;
2534 consts[2] = meta->src.layer;
2535 consts[3] = meta->src.lod;
2536 consts[4] = meta->src.x;
2537 consts[5] = meta->width;
2538 const_count = 6;
2539 break;
2540 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2541 consts[0] = offset_x;
2542 consts[1] = offset_y;
2543 consts[2] = meta->width;
2544 const_count = 3;
2545 break;
2546 case INTEL_DEV_META_FS_CLEAR_COLOR:
2547 consts[0] = meta->clear_val[0];
2548 consts[1] = meta->clear_val[1];
2549 consts[2] = meta->clear_val[2];
2550 consts[3] = meta->clear_val[3];
2551 const_count = 4;
2552 break;
2553 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2554 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002555 consts[1] = meta->clear_val[1];
2556 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002557 break;
2558 case INTEL_DEV_META_FS_RESOLVE_2X:
2559 case INTEL_DEV_META_FS_RESOLVE_4X:
2560 case INTEL_DEV_META_FS_RESOLVE_8X:
2561 case INTEL_DEV_META_FS_RESOLVE_16X:
2562 consts[0] = offset_x;
2563 consts[1] = offset_y;
2564 const_count = 2;
2565 break;
2566 default:
2567 assert(!"unknown meta shader id");
2568 const_count = 0;
2569 break;
2570 }
2571
2572 /* this can be skipped but it makes state dumping prettier */
2573 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2574
2575 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2576}
2577
2578static void gen6_meta_ps(struct intel_cmd *cmd)
2579{
2580 const struct intel_cmd_meta *meta = cmd->bind.meta;
2581 const struct intel_pipeline_shader *sh =
2582 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2583 uint32_t offset, *dw;
2584
2585 CMD_ASSERT(cmd, 6, 6);
2586
Chia-I Wu3adf7212014-10-24 15:34:07 +08002587 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2588 return;
2589 /* a normal color write */
2590 assert(meta->dst.valid && !sh->uses);
2591
Chia-I Wu6032b892014-10-17 14:47:18 +08002592 /* 3DSTATE_CONSTANT_PS */
2593 offset = gen6_meta_ps_constants(cmd);
2594 cmd_batch_pointer(cmd, 5, &dw);
2595 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2596 GEN6_PCB_ANY_DW0_PCB0_VALID;
2597 dw[1] = offset;
2598 dw[2] = 0;
2599 dw[3] = 0;
2600 dw[4] = 0;
2601
2602 /* 3DSTATE_WM */
2603 offset = emit_shader(cmd, sh);
2604 cmd_batch_pointer(cmd, 9, &dw);
2605 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2606 dw[1] = offset;
2607 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2608 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2609 dw[3] = 0;
2610 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
2611 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
2612 GEN6_WM_DW5_PS_ENABLE |
2613 GEN6_WM_DW5_8_PIXEL_DISPATCH;
2614 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2615 GEN6_WM_DW6_POSOFFSET_NONE |
2616 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2617 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2618 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2619 if (meta->samples > 1) {
2620 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2621 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2622 } else {
2623 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2624 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2625 }
2626 dw[7] = 0;
2627 dw[8] = 0;
2628}
2629
2630static void gen7_meta_ps(struct intel_cmd *cmd)
2631{
2632 const struct intel_cmd_meta *meta = cmd->bind.meta;
2633 const struct intel_pipeline_shader *sh =
2634 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2635 uint32_t offset, *dw;
2636
2637 CMD_ASSERT(cmd, 7, 7.5);
2638
Chia-I Wu3adf7212014-10-24 15:34:07 +08002639 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2640 return;
2641 /* a normal color write */
2642 assert(meta->dst.valid && !sh->uses);
2643
Chia-I Wu6032b892014-10-17 14:47:18 +08002644 /* 3DSTATE_WM */
2645 cmd_batch_pointer(cmd, 3, &dw);
2646 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2647 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2648 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2649 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2650 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2651 dw[2] = 0;
2652
2653 /* 3DSTATE_CONSTANT_PS */
2654 offset = gen6_meta_ps_constants(cmd);
2655 cmd_batch_pointer(cmd, 7, &dw);
2656 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2657 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2658 dw[2] = 0;
2659 dw[3] = offset;
2660 dw[4] = 0;
2661 dw[5] = 0;
2662 dw[6] = 0;
2663
2664 /* 3DSTATE_PS */
2665 offset = emit_shader(cmd, sh);
2666 cmd_batch_pointer(cmd, 8, &dw);
2667 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2668 dw[1] = offset;
2669 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2670 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2671 dw[3] = 0;
2672
2673 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2674 GEN7_PS_DW4_POSOFFSET_NONE |
2675 GEN7_PS_DW4_8_PIXEL_DISPATCH |
2676 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2677 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
2678 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
2679
2680 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2681 dw[6] = 0;
2682 dw[7] = 0;
2683}
2684
2685static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2686{
2687 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002688 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002689
2690 CMD_ASSERT(cmd, 6, 7.5);
2691
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002692 if (!ds) {
2693 /* all zeros */
2694 static const struct intel_ds_view null_ds;
2695 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002696 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002697
2698 cmd_wa_gen6_pre_ds_flush(cmd);
2699 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2700 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2701 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2702
2703 if (cmd_gen(cmd) >= INTEL_GEN(7))
2704 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2705 else
2706 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002707}
2708
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002709static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2710 const struct intel_pipeline *pipeline)
2711{
2712 cmd->bind.pipeline.graphics = pipeline;
2713}
2714
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002715static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2716 const struct intel_pipeline *pipeline)
2717{
2718 cmd->bind.pipeline.compute = pipeline;
2719}
2720
2721static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2722 const struct intel_pipeline_delta *delta)
2723{
2724 cmd->bind.pipeline.graphics_delta = delta;
2725}
2726
2727static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2728 const struct intel_pipeline_delta *delta)
2729{
2730 cmd->bind.pipeline.compute_delta = delta;
2731}
2732
2733static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2734 const struct intel_dset *dset,
2735 XGL_UINT slot_offset)
2736{
2737 cmd->bind.dset.graphics = dset;
2738 cmd->bind.dset.graphics_offset = slot_offset;
2739}
2740
2741static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2742 const struct intel_dset *dset,
2743 XGL_UINT slot_offset)
2744{
2745 cmd->bind.dset.compute = dset;
2746 cmd->bind.dset.compute_offset = slot_offset;
2747}
2748
2749static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2750 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2751{
2752 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2753}
2754
2755static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2756 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2757{
2758 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2759}
2760
2761static void cmd_bind_index_data(struct intel_cmd *cmd,
2762 const struct intel_mem *mem,
2763 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2764{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002765 cmd->bind.index.mem = mem;
2766 cmd->bind.index.offset = offset;
2767 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002768}
2769
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002770static void cmd_bind_attachments(struct intel_cmd *cmd,
2771 XGL_UINT rt_count,
2772 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2773 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002774{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002775 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002776 XGL_UINT i;
2777
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002778 for (i = 0; i < rt_count; i++) {
2779 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002780 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002781 const struct intel_layout *layout = &rt->img->layout;
2782
2783 if (i == 0) {
2784 width = layout->width0;
2785 height = layout->height0;
2786 } else {
2787 if (width > layout->width0)
2788 width = layout->width0;
2789 if (height > layout->height0)
2790 height = layout->height0;
2791 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002792
2793 cmd->bind.att.rt[i] = rt;
2794 }
2795
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002796 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002797
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002798 if (ds_info) {
2799 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002800
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002801 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2802 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002803
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002804 if (width > layout->width0)
2805 width = layout->width0;
2806 if (height > layout->height0)
2807 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002808 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002809 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002810 }
2811
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002812 cmd->bind.att.width = width;
2813 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002814}
2815
2816static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2817 const struct intel_viewport_state *state)
2818{
2819 cmd->bind.state.viewport = state;
2820}
2821
2822static void cmd_bind_raster_state(struct intel_cmd *cmd,
2823 const struct intel_raster_state *state)
2824{
2825 cmd->bind.state.raster = state;
2826}
2827
2828static void cmd_bind_ds_state(struct intel_cmd *cmd,
2829 const struct intel_ds_state *state)
2830{
2831 cmd->bind.state.ds = state;
2832}
2833
2834static void cmd_bind_blend_state(struct intel_cmd *cmd,
2835 const struct intel_blend_state *state)
2836{
2837 cmd->bind.state.blend = state;
2838}
2839
2840static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2841 const struct intel_msaa_state *state)
2842{
2843 cmd->bind.state.msaa = state;
2844}
2845
2846static void cmd_draw(struct intel_cmd *cmd,
2847 XGL_UINT vertex_start,
2848 XGL_UINT vertex_count,
2849 XGL_UINT instance_start,
2850 XGL_UINT instance_count,
2851 bool indexed,
2852 XGL_UINT vertex_base)
2853{
2854 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2855
2856 emit_bounded_states(cmd);
2857
2858 if (indexed) {
2859 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2860 cmd->result = XGL_ERROR_UNKNOWN;
2861
2862 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2863 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2864 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002865 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2866 cmd->bind.index.offset, cmd->bind.index.type,
2867 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002868 } else {
2869 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2870 cmd->bind.index.offset, cmd->bind.index.type,
2871 p->primitive_restart);
2872 }
2873 } else {
2874 assert(!vertex_base);
2875 }
2876
2877 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2878 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2879 vertex_start, instance_count, instance_start, vertex_base);
2880 } else {
2881 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2882 vertex_start, instance_count, instance_start, vertex_base);
2883 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002884
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002885 if (intel_debug & INTEL_DEBUG_NOCACHE)
2886 cmd_batch_flush_all(cmd);
2887
Chia-I Wu707a29e2014-08-27 12:51:47 +08002888 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002889 /* need to re-emit all workarounds */
2890 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002891}
2892
Chia-I Wuc14d1562014-10-17 09:49:22 +08002893void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2894{
Chia-I Wu6032b892014-10-17 14:47:18 +08002895 cmd->bind.meta = meta;
2896
2897 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08002898 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002899
2900 gen6_meta_dynamic_states(cmd);
2901 gen6_meta_surface_states(cmd);
2902
2903 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2904 gen7_meta_urb(cmd);
2905 gen6_meta_vf(cmd);
2906 gen7_meta_disabled(cmd);
2907 gen6_meta_wm(cmd);
2908 gen7_meta_ps(cmd);
2909 gen6_meta_depth_buffer(cmd);
2910
2911 cmd_wa_gen7_post_command_cs_stall(cmd);
2912 cmd_wa_gen7_post_command_depth_stall(cmd);
2913
2914 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2915 } else {
2916 gen6_meta_urb(cmd);
2917 gen6_meta_vf(cmd);
2918 gen6_meta_disabled(cmd);
2919 gen6_meta_wm(cmd);
2920 gen6_meta_ps(cmd);
2921 gen6_meta_depth_buffer(cmd);
2922
2923 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2924 }
2925
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002926 if (intel_debug & INTEL_DEBUG_NOCACHE)
2927 cmd_batch_flush_all(cmd);
2928
Chia-I Wu6032b892014-10-17 14:47:18 +08002929 cmd->bind.draw_count++;
2930 /* need to re-emit all workarounds */
2931 cmd->bind.wa_flags = 0;
2932
2933 cmd->bind.meta = NULL;
Chia-I Wuc14d1562014-10-17 09:49:22 +08002934}
2935
Chia-I Wub2755562014-08-20 13:38:52 +08002936XGL_VOID XGLAPI intelCmdBindPipeline(
2937 XGL_CMD_BUFFER cmdBuffer,
2938 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2939 XGL_PIPELINE pipeline)
2940{
2941 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2942
2943 switch (pipelineBindPoint) {
2944 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002945 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002946 break;
2947 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002948 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002949 break;
2950 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002951 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002952 break;
2953 }
2954}
2955
2956XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2957 XGL_CMD_BUFFER cmdBuffer,
2958 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2959 XGL_PIPELINE_DELTA delta)
2960{
2961 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2962
2963 switch (pipelineBindPoint) {
2964 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002965 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002966 break;
2967 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002968 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002969 break;
2970 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002971 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002972 break;
2973 }
2974}
2975
2976XGL_VOID XGLAPI intelCmdBindStateObject(
2977 XGL_CMD_BUFFER cmdBuffer,
2978 XGL_STATE_BIND_POINT stateBindPoint,
2979 XGL_STATE_OBJECT state)
2980{
2981 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2982
2983 switch (stateBindPoint) {
2984 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002985 cmd_bind_viewport_state(cmd,
2986 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002987 break;
2988 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002989 cmd_bind_raster_state(cmd,
2990 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002991 break;
2992 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002993 cmd_bind_ds_state(cmd,
2994 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002995 break;
2996 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002997 cmd_bind_blend_state(cmd,
2998 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002999 break;
3000 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003001 cmd_bind_msaa_state(cmd,
3002 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003003 break;
3004 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003005 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003006 break;
3007 }
3008}
3009
3010XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3011 XGL_CMD_BUFFER cmdBuffer,
3012 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3013 XGL_UINT index,
3014 XGL_DESCRIPTOR_SET descriptorSet,
3015 XGL_UINT slotOffset)
3016{
3017 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3018 struct intel_dset *dset = intel_dset(descriptorSet);
3019
3020 assert(!index);
3021
3022 switch (pipelineBindPoint) {
3023 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003024 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003025 break;
3026 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003027 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003028 break;
3029 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003030 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003031 break;
3032 }
3033}
3034
3035XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3036 XGL_CMD_BUFFER cmdBuffer,
3037 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3038 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3039{
3040 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3041
3042 switch (pipelineBindPoint) {
3043 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003044 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003045 break;
3046 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003047 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003048 break;
3049 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003050 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003051 break;
3052 }
3053}
3054
3055XGL_VOID XGLAPI intelCmdBindIndexData(
3056 XGL_CMD_BUFFER cmdBuffer,
3057 XGL_GPU_MEMORY mem_,
3058 XGL_GPU_SIZE offset,
3059 XGL_INDEX_TYPE indexType)
3060{
3061 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3062 struct intel_mem *mem = intel_mem(mem_);
3063
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003064 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003065}
3066
3067XGL_VOID XGLAPI intelCmdBindAttachments(
3068 XGL_CMD_BUFFER cmdBuffer,
3069 XGL_UINT colorAttachmentCount,
3070 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3071 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3072{
3073 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003074
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003075 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3076 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003077}
3078
3079XGL_VOID XGLAPI intelCmdDraw(
3080 XGL_CMD_BUFFER cmdBuffer,
3081 XGL_UINT firstVertex,
3082 XGL_UINT vertexCount,
3083 XGL_UINT firstInstance,
3084 XGL_UINT instanceCount)
3085{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003086 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003087
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003088 cmd_draw(cmd, firstVertex, vertexCount,
3089 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003090}
3091
3092XGL_VOID XGLAPI intelCmdDrawIndexed(
3093 XGL_CMD_BUFFER cmdBuffer,
3094 XGL_UINT firstIndex,
3095 XGL_UINT indexCount,
3096 XGL_INT vertexOffset,
3097 XGL_UINT firstInstance,
3098 XGL_UINT instanceCount)
3099{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003100 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003101
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003102 cmd_draw(cmd, firstIndex, indexCount,
3103 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003104}
3105
3106XGL_VOID XGLAPI intelCmdDrawIndirect(
3107 XGL_CMD_BUFFER cmdBuffer,
3108 XGL_GPU_MEMORY mem,
3109 XGL_GPU_SIZE offset,
3110 XGL_UINT32 count,
3111 XGL_UINT32 stride)
3112{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003113 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3114
3115 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003116}
3117
3118XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3119 XGL_CMD_BUFFER cmdBuffer,
3120 XGL_GPU_MEMORY mem,
3121 XGL_GPU_SIZE offset,
3122 XGL_UINT32 count,
3123 XGL_UINT32 stride)
3124{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003125 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3126
3127 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003128}
3129
3130XGL_VOID XGLAPI intelCmdDispatch(
3131 XGL_CMD_BUFFER cmdBuffer,
3132 XGL_UINT x,
3133 XGL_UINT y,
3134 XGL_UINT z)
3135{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003136 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3137
3138 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003139}
3140
3141XGL_VOID XGLAPI intelCmdDispatchIndirect(
3142 XGL_CMD_BUFFER cmdBuffer,
3143 XGL_GPU_MEMORY mem,
3144 XGL_GPU_SIZE offset)
3145{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003146 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3147
3148 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003149}