blob: c12857b38fcfbcd639785e61fe87eac8ddbfa6bb [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 Wua4d1b392014-10-10 13:57:29 +080029#include <stdio.h> /* for printf */
Chia-I Wu9f039862014-08-20 15:39:56 +080030#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080031#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
40
Chia-I Wu59c097e2014-08-21 10:51:07 +080041static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080042 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080043 uint32_t vertex_count,
44 uint32_t vertex_start,
45 uint32_t instance_count,
46 uint32_t instance_start,
47 uint32_t vertex_base)
48{
49 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080050 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080051
52 CMD_ASSERT(cmd, 6, 6);
53
Chia-I Wu426072d2014-08-26 14:31:55 +080054 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080055 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080056 (cmd_len - 2);
57
58 if (indexed)
59 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
60
Chia-I Wu72292b72014-09-09 10:48:33 +080061 cmd_batch_pointer(cmd, cmd_len, &dw);
62 dw[0] = dw0;
63 dw[1] = vertex_count;
64 dw[2] = vertex_start;
65 dw[3] = instance_count;
66 dw[4] = instance_start;
67 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080068}
69
70static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080071 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080072 uint32_t vertex_count,
73 uint32_t vertex_start,
74 uint32_t instance_count,
75 uint32_t instance_start,
76 uint32_t vertex_base)
77{
78 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080079 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080080
81 CMD_ASSERT(cmd, 7, 7.5);
82
Chia-I Wu426072d2014-08-26 14:31:55 +080083 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080084 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080085
86 if (indexed)
87 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
88
Chia-I Wu72292b72014-09-09 10:48:33 +080089 cmd_batch_pointer(cmd, cmd_len, &dw);
90 dw[0] = dw0;
91 dw[1] = dw1;
92 dw[2] = vertex_count;
93 dw[3] = vertex_start;
94 dw[4] = instance_count;
95 dw[5] = instance_start;
96 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080097}
98
Chia-I Wu270b1e82014-08-25 15:53:39 +080099static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800100 struct intel_bo *bo, uint32_t bo_offset,
101 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800102{
103 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800104 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800105 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800106 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800107 uint32_t *dw;
108 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800109
110 CMD_ASSERT(cmd, 6, 7.5);
111
112 assert(bo_offset % 8 == 0);
113
114 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
115 /*
116 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
117 *
118 * "1 of the following must also be set (when CS stall is set):
119 *
120 * * Depth Cache Flush Enable ([0] of DW1)
121 * * Stall at Pixel Scoreboard ([1] of DW1)
122 * * Depth Stall ([13] of DW1)
123 * * Post-Sync Operation ([13] of DW1)
124 * * Render Target Cache Flush Enable ([12] of DW1)
125 * * Notify Enable ([8] of DW1)"
126 *
127 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
128 *
129 * "One of the following must also be set (when CS stall is set):
130 *
131 * * Render Target Cache Flush Enable ([12] of DW1)
132 * * Depth Cache Flush Enable ([0] of DW1)
133 * * Stall at Pixel Scoreboard ([1] of DW1)
134 * * Depth Stall ([13] of DW1)
135 * * Post-Sync Operation ([13] of DW1)"
136 */
137 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
138 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
140 GEN6_PIPE_CONTROL_DEPTH_STALL;
141
142 /* post-sync op */
143 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
144 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
145 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
146
147 if (cmd_gen(cmd) == INTEL_GEN(6))
148 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
149
150 assert(dw1 & bit_test);
151 }
152
153 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
154 /*
155 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
156 *
157 * "Following bits must be clear (when Depth Stall is set):
158 *
159 * * Render Target Cache Flush Enable ([12] of DW1)
160 * * Depth Cache Flush Enable ([0] of DW1)"
161 */
162 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
163 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
164 }
165
166 /*
167 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
168 *
169 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
170 * and PIPE_CONTROL are not supported."
171 *
172 * The kernel will add the mapping automatically (when write domain is
173 * INTEL_DOMAIN_INSTRUCTION).
174 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800175 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800176 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800177 reloc_flags |= INTEL_RELOC_GGTT;
178 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800179
Chia-I Wu72292b72014-09-09 10:48:33 +0800180 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
181 dw[0] = dw0;
182 dw[1] = dw1;
183 dw[2] = 0;
184 dw[3] = (uint32_t) imm;
185 dw[4] = (uint32_t) (imm >> 32);
186
187 if (bo) {
188 cmd_reserve_reloc(cmd, 1);
189 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
190 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800191}
192
Chia-I Wu254db422014-08-21 11:54:29 +0800193static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
194{
195 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
196 bool supported;
197
198 CMD_ASSERT(cmd, 6, 7.5);
199
200 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
201 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
202
203 switch (p->prim_type) {
204 case GEN6_3DPRIM_POINTLIST:
205 case GEN6_3DPRIM_LINELIST:
206 case GEN6_3DPRIM_LINESTRIP:
207 case GEN6_3DPRIM_TRILIST:
208 case GEN6_3DPRIM_TRISTRIP:
209 supported = true;
210 break;
211 default:
212 supported = false;
213 break;
214 }
215
216 if (!supported)
217 return false;
218
219 switch (cmd->bind.index.type) {
220 case XGL_INDEX_8:
221 supported = (p->primitive_restart_index != 0xffu);
222 break;
223 case XGL_INDEX_16:
224 supported = (p->primitive_restart_index != 0xffffu);
225 break;
226 case XGL_INDEX_32:
227 supported = (p->primitive_restart_index != 0xffffffffu);
228 break;
229 default:
230 supported = false;
231 break;
232 }
233
234 return supported;
235}
236
Chia-I Wu59c097e2014-08-21 10:51:07 +0800237static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800238 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 XGL_GPU_SIZE offset,
240 XGL_INDEX_TYPE type,
241 bool enable_cut_index)
242{
243 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800244 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800246 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800247
248 CMD_ASSERT(cmd, 6, 7.5);
249
Chia-I Wu426072d2014-08-26 14:31:55 +0800250 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800251
252 /* the bit is moved to 3DSTATE_VF */
253 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
254 assert(!enable_cut_index);
255 if (enable_cut_index)
256 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
257
258 switch (type) {
259 case XGL_INDEX_8:
260 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
261 offset_align = 1;
262 break;
263 case XGL_INDEX_16:
264 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
265 offset_align = 2;
266 break;
267 case XGL_INDEX_32:
268 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
269 offset_align = 4;
270 break;
271 default:
272 cmd->result = XGL_ERROR_INVALID_VALUE;
273 return;
274 break;
275 }
276
277 if (offset % offset_align) {
278 cmd->result = XGL_ERROR_INVALID_VALUE;
279 return;
280 }
281
282 /* aligned and inclusive */
283 end_offset = mem->size - (mem->size % offset_align) - 1;
284
Chia-I Wu72292b72014-09-09 10:48:33 +0800285 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
286 dw[0] = dw0;
287
288 cmd_reserve_reloc(cmd, 2);
289 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
290 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800291}
292
Chia-I Wu62a7f252014-08-29 11:31:16 +0800293static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
294 bool enable_cut_index,
295 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800296{
297 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800298 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800299
300 CMD_ASSERT(cmd, 7.5, 7.5);
301
Chia-I Wu426072d2014-08-26 14:31:55 +0800302 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800303 if (enable_cut_index)
304 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
305
Chia-I Wu72292b72014-09-09 10:48:33 +0800306 cmd_batch_pointer(cmd, cmd_len, &dw);
307 dw[0] = dw0;
308 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800309}
310
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600311
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800312static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
313{
314 const uint8_t cmd_len = 7;
315 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800316 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800317
318 CMD_ASSERT(cmd, 6, 6);
319
Chia-I Wu72292b72014-09-09 10:48:33 +0800320 cmd_batch_pointer(cmd, cmd_len, &dw);
321 dw[0] = dw0;
322 dw[1] = 0;
323 dw[2] = 0;
324 dw[3] = 0;
325 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
326 dw[5] = GEN6_GS_DW5_STATISTICS;
327 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800328}
329
Chia-I Wu62a7f252014-08-29 11:31:16 +0800330static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
331{
332 const uint8_t cmd_len = 7;
333 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800334 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800335
336 CMD_ASSERT(cmd, 7, 7.5);
337
Chia-I Wu72292b72014-09-09 10:48:33 +0800338 cmd_batch_pointer(cmd, cmd_len, &dw);
339 dw[0] = dw0;
340 dw[1] = 0;
341 dw[2] = 0;
342 dw[3] = 0;
343 dw[4] = 0;
344 dw[5] = GEN6_GS_DW5_STATISTICS;
345 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800346}
347
Chia-I Wud88e02d2014-08-25 10:56:13 +0800348static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
349 XGL_UINT width, XGL_UINT height)
350{
351 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800352 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800353 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800354 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800355
356 CMD_ASSERT(cmd, 6, 7.5);
357
Chia-I Wu72292b72014-09-09 10:48:33 +0800358 cmd_batch_pointer(cmd, cmd_len, &dw);
359 dw[0] = dw0;
360
Chia-I Wud88e02d2014-08-25 10:56:13 +0800361 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800362 dw[1] = 0;
363 dw[2] = (height - 1) << 16 |
364 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800365 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800366 dw[1] = 1;
367 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800368 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800369
370 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800371}
372
Chia-I Wu8016a172014-08-29 18:31:32 +0800373static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
374 uint32_t body[6])
375{
376 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
377 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
378 const struct intel_raster_state *raster = cmd->bind.state.raster;
379 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
380 uint32_t dw1, dw2, dw3;
381 int point_width;
382
383 CMD_ASSERT(cmd, 6, 7.5);
384
385 dw1 = GEN7_SF_DW1_STATISTICS |
386 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
387 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
388 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
389 GEN7_SF_DW1_VIEWPORT_ENABLE |
390 raster->cmd_sf_fill;
391
392 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
393 int format;
394
395 switch (pipeline->db_format.channelFormat) {
396 case XGL_CH_FMT_R16:
397 format = GEN6_ZFORMAT_D16_UNORM;
398 break;
399 case XGL_CH_FMT_R32:
400 case XGL_CH_FMT_R32G8:
401 format = GEN6_ZFORMAT_D32_FLOAT;
402 break;
403 default:
404 assert(!"unknown depth format");
405 format = 0;
406 break;
407 }
408
409 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
410 }
411
412 dw2 = raster->cmd_sf_cull;
413
414 if (msaa->sample_count > 1) {
415 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
416 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
417 } else {
418 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
419 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
420 }
421
422 if (viewport->scissor_enable)
423 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
424
425 /* in U8.3 */
426 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
427 point_width = U_CLAMP(point_width, 1, 2047);
428
429 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
431 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
432 GEN7_SF_DW3_SUBPIXEL_8BITS |
433 GEN7_SF_DW3_USE_POINT_WIDTH |
434 point_width;
435
436 body[0] = dw1;
437 body[1] = dw2;
438 body[2] = dw3;
439 body[3] = raster->cmd_depth_offset_const;
440 body[4] = raster->cmd_depth_offset_scale;
441 body[5] = raster->cmd_depth_offset_clamp;
442}
443
444static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
445 uint32_t body[13])
446{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800447 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
448 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449 XGL_UINT attr_skip, attr_count;
450 XGL_UINT vue_offset, vue_len;
451 XGL_UINT i;
452 uint32_t dw1;
453
454 CMD_ASSERT(cmd, 6, 7.5);
455
456 /* VS outputs VUE header and position additionally */
GregFbcbe19a2014-11-07 11:01:01 -0700457 assert(vs->out_count >= fs->in_count + 2);
458 attr_skip = vs->out_count - fs->in_count;
Chia-I Wu8016a172014-08-29 18:31:32 +0800459 attr_count = vs->out_count - attr_skip;
Chia-I Wu8016a172014-08-29 18:31:32 +0800460 assert(fs->in_count <= 32);
461
GregFbcbe19a2014-11-07 11:01:01 -0700462 vue_offset = (attr_skip + 1) / 2;
Chia-I Wu8016a172014-08-29 18:31:32 +0800463 vue_len = (attr_count + 1) / 2;
464 if (!vue_len)
465 vue_len = 1;
466
467 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
468 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
469 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
470
471 body[0] = dw1;
472
473 for (i = 0; i < 8; i++) {
474 uint16_t hi, lo;
475
476 /* no attr swizzles */
477 if (i * 2 + 1 < fs->in_count) {
478 hi = i * 2 + 1;
479 lo = i * 2;
480 } else if (i * 2 < fs->in_count) {
481 hi = 0;
482 lo = i * 2;
483 } else {
484 hi = 0;
485 lo = 0;
486 }
487
488 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
489 }
490
491 body[9] = 0; /* point sprite enables */
492 body[10] = 0; /* constant interpolation enables */
493 body[11] = 0; /* WrapShortest enables */
494 body[12] = 0;
495}
496
497static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
498{
499 const uint8_t cmd_len = 20;
500 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
501 (cmd_len - 2);
502 uint32_t sf[6];
503 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800504 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800505
506 CMD_ASSERT(cmd, 6, 6);
507
508 gen7_fill_3DSTATE_SF_body(cmd, sf);
509 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
510
Chia-I Wu72292b72014-09-09 10:48:33 +0800511 cmd_batch_pointer(cmd, cmd_len, &dw);
512 dw[0] = dw0;
513 dw[1] = sbe[0];
514 memcpy(&dw[2], sf, sizeof(sf));
515 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800516}
517
518static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
519{
520 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800521 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800522
523 CMD_ASSERT(cmd, 7, 7.5);
524
Chia-I Wu72292b72014-09-09 10:48:33 +0800525 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800526 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
527 (cmd_len - 2);
528 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800529}
530
531static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
532{
533 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800534 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800535
536 CMD_ASSERT(cmd, 7, 7.5);
537
Chia-I Wu72292b72014-09-09 10:48:33 +0800538 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800539 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
540 (cmd_len - 2);
541 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800542}
543
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800544static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
545{
546 const uint8_t cmd_len = 4;
547 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
548 (cmd_len - 2);
549 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700550 const struct intel_pipeline_shader *vs = &pipeline->vs;
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 |
GregFfd4c1f92014-11-07 15:32:52 -0700568 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800569 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
570 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
571 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
572
573 if (pipeline->rasterizerDiscardEnable)
574 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
575 else
576 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
577
578 if (pipeline->depthClipEnable)
579 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
580
581 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
582 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
583 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
584 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
585
586 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
587 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
588 (viewport->viewport_count - 1);
589
Chia-I Wu72292b72014-09-09 10:48:33 +0800590 cmd_batch_pointer(cmd, cmd_len, &dw);
591 dw[0] = dw0;
592 dw[1] = dw1;
593 dw[2] = dw2;
594 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800595}
596
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800597static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
598{
599 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
600 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800601 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800602 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
603 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800604 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800605
606 CMD_ASSERT(cmd, 6, 6);
607
608 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
609
610 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
611 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
612
613 dw4 = GEN6_WM_DW4_STATISTICS |
614 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
615 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
616 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
617
618 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
619 GEN6_WM_DW5_PS_ENABLE |
620 GEN6_WM_DW5_8_PIXEL_DISPATCH;
621
622 if (fs->uses & INTEL_SHADER_USE_KILL ||
623 pipeline->cb_state.alphaToCoverageEnable)
624 dw5 |= GEN6_WM_DW5_PS_KILL;
625
626 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
627 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
628 if (fs->uses & INTEL_SHADER_USE_DEPTH)
629 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
630 if (fs->uses & INTEL_SHADER_USE_W)
631 dw5 |= GEN6_WM_DW5_PS_USE_W;
632
633 if (pipeline->cb_state.dualSourceBlendEnable)
634 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
635
636 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
637 GEN6_WM_DW6_POSOFFSET_NONE |
638 GEN6_WM_DW6_ZW_INTERP_PIXEL |
639 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
640 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
641
642 if (msaa->sample_count > 1) {
643 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
644 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
645 } else {
646 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
647 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
648 }
649
Chia-I Wu72292b72014-09-09 10:48:33 +0800650 cmd_batch_pointer(cmd, cmd_len, &dw);
651 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800652 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800653 dw[2] = dw2;
654 dw[3] = 0; /* scratch */
655 dw[4] = dw4;
656 dw[5] = dw5;
657 dw[6] = dw6;
658 dw[7] = 0; /* kernel 1 */
659 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800660}
661
662static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
663{
664 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800665 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800666 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
667 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800668 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800669
670 CMD_ASSERT(cmd, 7, 7.5);
671
672 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
673
674 dw1 = GEN7_WM_DW1_STATISTICS |
675 GEN7_WM_DW1_PS_ENABLE |
676 GEN7_WM_DW1_ZW_INTERP_PIXEL |
677 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
678 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
679
680 if (fs->uses & INTEL_SHADER_USE_KILL ||
681 pipeline->cb_state.alphaToCoverageEnable)
682 dw1 |= GEN7_WM_DW1_PS_KILL;
683
684 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
685 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
686 if (fs->uses & INTEL_SHADER_USE_DEPTH)
687 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
688 if (fs->uses & INTEL_SHADER_USE_W)
689 dw1 |= GEN7_WM_DW1_PS_USE_W;
690
691 dw2 = 0;
692
693 if (msaa->sample_count > 1) {
694 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
695 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
696 } else {
697 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
698 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
699 }
700
Chia-I Wu72292b72014-09-09 10:48:33 +0800701 cmd_batch_pointer(cmd, cmd_len, &dw);
702 dw[0] = dw0;
703 dw[1] = dw1;
704 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800705}
706
707static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
708{
709 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800710 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800711 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
712 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800713 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800714
715 CMD_ASSERT(cmd, 7, 7.5);
716
717 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
718
719 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
720 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
721
722 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
723 GEN7_PS_DW4_8_PIXEL_DISPATCH;
724
725 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
726 const int max_threads =
727 (cmd->dev->gpu->gt == 3) ? 408 :
728 (cmd->dev->gpu->gt == 2) ? 204 : 102;
729 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
730 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
731 } else {
732 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
733 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
734 }
735
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800736 if (fs->in_count)
737 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
738
739 if (pipeline->cb_state.dualSourceBlendEnable)
740 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
741
742 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
743 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
744 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
745
Chia-I Wu72292b72014-09-09 10:48:33 +0800746 cmd_batch_pointer(cmd, cmd_len, &dw);
747 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800748 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800749 dw[2] = dw2;
750 dw[3] = 0; /* scratch */
751 dw[4] = dw4;
752 dw[5] = dw5;
753 dw[6] = 0; /* kernel 1 */
754 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800755}
756
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800757static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
758 const struct intel_ds_view *view)
759{
760 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800761 uint32_t dw0, *dw;
762 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800763
764 CMD_ASSERT(cmd, 6, 7.5);
765
766 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800767 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
768 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800769 dw0 |= (cmd_len - 2);
770
Chia-I Wu72292b72014-09-09 10:48:33 +0800771 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
772 dw[0] = dw0;
773 dw[1] = view->cmd[0];
774 dw[2] = 0;
775 dw[3] = view->cmd[2];
776 dw[4] = view->cmd[3];
777 dw[5] = view->cmd[4];
778 dw[6] = view->cmd[5];
779
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600780 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800781 cmd_reserve_reloc(cmd, 1);
782 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
783 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600784 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800785}
786
787static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
788 const struct intel_ds_view *view)
789{
790 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800791 uint32_t dw0, *dw;
792 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793
794 CMD_ASSERT(cmd, 6, 7.5);
795
796 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800797 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
798 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800799 dw0 |= (cmd_len - 2);
800
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
802 dw[0] = dw0;
803 dw[1] = view->cmd[6];
804 dw[2] = 0;
805
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600806 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800807 cmd_reserve_reloc(cmd, 1);
808 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
809 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600810 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800811}
812
813static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
814 const struct intel_ds_view *view)
815{
816 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800817 uint32_t dw0, *dw;
818 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800819
820 CMD_ASSERT(cmd, 6, 7.5);
821
822 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800823 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
824 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800825 dw0 |= (cmd_len - 2);
826
Chia-I Wu72292b72014-09-09 10:48:33 +0800827 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
828 dw[0] = dw0;
829 dw[1] = view->cmd[8];
830 dw[2] = 0;
831
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600832 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800833 cmd_reserve_reloc(cmd, 1);
834 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
835 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600836 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800837}
838
Chia-I Wuf8231032014-08-25 10:44:45 +0800839static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
840 uint32_t clear_val)
841{
842 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800843 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800844 GEN6_CLEAR_PARAMS_DW0_VALID |
845 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800846 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800847
848 CMD_ASSERT(cmd, 6, 6);
849
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 cmd_batch_pointer(cmd, cmd_len, &dw);
851 dw[0] = dw0;
852 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800853}
854
855static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
856 uint32_t clear_val)
857{
858 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800859 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800860 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800861 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800862
863 CMD_ASSERT(cmd, 7, 7.5);
864
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 cmd_batch_pointer(cmd, cmd_len, &dw);
866 dw[0] = dw0;
867 dw[1] = clear_val;
868 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800869}
870
Chia-I Wu302742d2014-08-22 10:28:29 +0800871static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800872 uint32_t blend_offset,
873 uint32_t ds_offset,
874 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800875{
876 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800877 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800878
879 CMD_ASSERT(cmd, 6, 6);
880
Chia-I Wu426072d2014-08-26 14:31:55 +0800881 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800882 (cmd_len - 2);
883
Chia-I Wu72292b72014-09-09 10:48:33 +0800884 cmd_batch_pointer(cmd, cmd_len, &dw);
885 dw[0] = dw0;
886 dw[1] = blend_offset | 1;
887 dw[2] = ds_offset | 1;
888 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800889}
890
Chia-I Wu1744cca2014-08-22 11:10:17 +0800891static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 uint32_t clip_offset,
893 uint32_t sf_offset,
894 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800895{
896 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800897 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800898
899 CMD_ASSERT(cmd, 6, 6);
900
Chia-I Wu426072d2014-08-26 14:31:55 +0800901 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800902 GEN6_PTR_VP_DW0_CLIP_CHANGED |
903 GEN6_PTR_VP_DW0_SF_CHANGED |
904 GEN6_PTR_VP_DW0_CC_CHANGED |
905 (cmd_len - 2);
906
Chia-I Wu72292b72014-09-09 10:48:33 +0800907 cmd_batch_pointer(cmd, cmd_len, &dw);
908 dw[0] = dw0;
909 dw[1] = clip_offset;
910 dw[2] = sf_offset;
911 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800912}
913
914static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800915 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800916{
917 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800918 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800919
920 CMD_ASSERT(cmd, 6, 6);
921
Chia-I Wu426072d2014-08-26 14:31:55 +0800922 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800923 (cmd_len - 2);
924
Chia-I Wu72292b72014-09-09 10:48:33 +0800925 cmd_batch_pointer(cmd, cmd_len, &dw);
926 dw[0] = dw0;
927 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800928}
929
Chia-I Wu42a56202014-08-23 16:47:48 +0800930static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800931 uint32_t vs_offset,
932 uint32_t gs_offset,
933 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800934{
935 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800936 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800937
938 CMD_ASSERT(cmd, 6, 6);
939
Chia-I Wu426072d2014-08-26 14:31:55 +0800940 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800941 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
942 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
943 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
944 (cmd_len - 2);
945
Chia-I Wu72292b72014-09-09 10:48:33 +0800946 cmd_batch_pointer(cmd, cmd_len, &dw);
947 dw[0] = dw0;
948 dw[1] = vs_offset;
949 dw[2] = gs_offset;
950 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800951}
952
Chia-I Wu257e75e2014-08-29 14:06:35 +0800953static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800954 uint32_t vs_offset,
955 uint32_t gs_offset,
956 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800957{
958 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800959 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800960
961 CMD_ASSERT(cmd, 6, 6);
962
963 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
964 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
965 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
966 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
967 (cmd_len - 2);
968
Chia-I Wu72292b72014-09-09 10:48:33 +0800969 cmd_batch_pointer(cmd, cmd_len, &dw);
970 dw[0] = dw0;
971 dw[1] = vs_offset;
972 dw[2] = gs_offset;
973 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800974}
975
Chia-I Wu302742d2014-08-22 10:28:29 +0800976static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800977 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800978{
979 const uint8_t cmd_len = 2;
980 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
981 GEN6_RENDER_SUBTYPE_3D |
982 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800984
Chia-I Wu72292b72014-09-09 10:48:33 +0800985 cmd_batch_pointer(cmd, cmd_len, &dw);
986 dw[0] = dw0;
987 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800988}
989
Chia-I Wu72292b72014-09-09 10:48:33 +0800990static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800991 const struct intel_blend_state *state)
992{
Chia-I Wu72292b72014-09-09 10:48:33 +0800993 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800994 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
995
996 CMD_ASSERT(cmd, 6, 7.5);
997 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
998
Chia-I Wu00b51a82014-09-09 12:07:37 +0800999 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
1000 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001001}
1002
Chia-I Wu72292b72014-09-09 10:48:33 +08001003static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001004 const struct intel_ds_state *state)
1005{
Chia-I Wu72292b72014-09-09 10:48:33 +08001006 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001007 const uint8_t cmd_len = 3;
1008
1009 CMD_ASSERT(cmd, 6, 7.5);
1010 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1011
Chia-I Wu00b51a82014-09-09 12:07:37 +08001012 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1013 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001014}
1015
Chia-I Wu72292b72014-09-09 10:48:33 +08001016static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001017 uint32_t stencil_ref,
1018 const uint32_t blend_color[4])
1019{
Chia-I Wu72292b72014-09-09 10:48:33 +08001020 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001021 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001022 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001023
1024 CMD_ASSERT(cmd, 6, 7.5);
1025
Chia-I Wu00b51a82014-09-09 12:07:37 +08001026 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1027 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001028 dw[0] = stencil_ref;
1029 dw[1] = 0;
1030 dw[2] = blend_color[0];
1031 dw[3] = blend_color[1];
1032 dw[4] = blend_color[2];
1033 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001034
Chia-I Wu72292b72014-09-09 10:48:33 +08001035 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001036}
1037
Chia-I Wu8370b402014-08-29 12:28:37 +08001038static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001039{
Chia-I Wu8370b402014-08-29 12:28:37 +08001040 CMD_ASSERT(cmd, 6, 7.5);
1041
Chia-I Wu707a29e2014-08-27 12:51:47 +08001042 if (!cmd->bind.draw_count)
1043 return;
1044
Chia-I Wu8370b402014-08-29 12:28:37 +08001045 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001046 return;
1047
Chia-I Wu8370b402014-08-29 12:28:37 +08001048 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001049
1050 /*
1051 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1052 *
1053 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1054 * pipe-control with a post-sync op and no write-cache flushes."
1055 *
1056 * The workaround below necessitates this workaround.
1057 */
1058 gen6_PIPE_CONTROL(cmd,
1059 GEN6_PIPE_CONTROL_CS_STALL |
1060 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001061 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001062
Chia-I Wud6d079d2014-08-31 13:14:21 +08001063 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1064 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001065}
1066
Chia-I Wu8370b402014-08-29 12:28:37 +08001067static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001068{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001069 CMD_ASSERT(cmd, 6, 7.5);
1070
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001071 if (!cmd->bind.draw_count)
1072 return;
1073
Chia-I Wud6d079d2014-08-31 13:14:21 +08001074 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1075 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001076}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001077
Chia-I Wu8370b402014-08-29 12:28:37 +08001078static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1079{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001080 CMD_ASSERT(cmd, 7, 7.5);
1081
Chia-I Wu8370b402014-08-29 12:28:37 +08001082 if (!cmd->bind.draw_count)
1083 return;
1084
1085 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001086
1087 gen6_PIPE_CONTROL(cmd,
1088 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001089 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001090}
1091
Chia-I Wu8370b402014-08-29 12:28:37 +08001092static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1093{
1094 CMD_ASSERT(cmd, 7, 7.5);
1095
1096 if (!cmd->bind.draw_count)
1097 return;
1098
1099 /*
1100 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1101 *
1102 * "One of the following must also be set (when CS stall is set):
1103 *
1104 * * Render Target Cache Flush Enable ([12] of DW1)
1105 * * Depth Cache Flush Enable ([0] of DW1)
1106 * * Stall at Pixel Scoreboard ([1] of DW1)
1107 * * Depth Stall ([13] of DW1)
1108 * * Post-Sync Operation ([13] of DW1)"
1109 */
1110 gen6_PIPE_CONTROL(cmd,
1111 GEN6_PIPE_CONTROL_CS_STALL |
1112 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001113 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001114}
1115
1116static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1117{
1118 CMD_ASSERT(cmd, 7, 7.5);
1119
1120 if (!cmd->bind.draw_count)
1121 return;
1122
1123 cmd_wa_gen6_pre_depth_stall_write(cmd);
1124
Chia-I Wud6d079d2014-08-31 13:14:21 +08001125 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001126}
1127
1128static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1129{
1130 CMD_ASSERT(cmd, 6, 7.5);
1131
1132 if (!cmd->bind.draw_count)
1133 return;
1134
1135 /*
1136 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1137 *
1138 * "Driver must guarentee that all the caches in the depth pipe are
1139 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1140 * requires driver to send a PIPE_CONTROL with a CS stall along with
1141 * a Depth Flush prior to this command."
1142 *
1143 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1144 *
1145 * "Driver must ierarchi that all the caches in the depth pipe are
1146 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1147 * requires driver to send a PIPE_CONTROL with a CS stall along with
1148 * a Depth Flush prior to this command.
1149 */
1150 gen6_PIPE_CONTROL(cmd,
1151 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1152 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001153 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001154}
1155
1156static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1157{
1158 CMD_ASSERT(cmd, 6, 7.5);
1159
1160 if (!cmd->bind.draw_count)
1161 return;
1162
1163 /*
1164 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1165 *
1166 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1167 * and a post sync operation prior to the group of depth
1168 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1169 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1170 *
1171 * This workaround satifies all the conditions.
1172 */
1173 cmd_wa_gen6_pre_depth_stall_write(cmd);
1174
1175 /*
1176 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1177 *
1178 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1179 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1180 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1181 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1182 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1183 * Depth Flush Bit set, followed by another pipelined depth stall
1184 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1185 * guarantee that the pipeline from WM onwards is already flushed
1186 * (e.g., via a preceding MI_FLUSH)."
1187 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001188 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1189 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1190 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001191}
1192
Chia-I Wu525c6602014-08-27 10:22:34 +08001193void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1194{
1195 if (!cmd->bind.draw_count)
1196 return;
1197
1198 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1199
Chia-I Wu8370b402014-08-29 12:28:37 +08001200 /*
1201 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1202 *
1203 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1204 * PIPE_CONTROL with any non-zero post-sync-op is required."
1205 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001206 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001207 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001208
Chia-I Wu092279a2014-08-30 19:05:30 +08001209 /*
1210 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1211 *
1212 * "One of the following must also be set (when CS stall is set):
1213 *
1214 * * Render Target Cache Flush Enable ([12] of DW1)
1215 * * Depth Cache Flush Enable ([0] of DW1)
1216 * * Stall at Pixel Scoreboard ([1] of DW1)
1217 * * Depth Stall ([13] of DW1)
1218 * * Post-Sync Operation ([13] of DW1)"
1219 */
1220 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1221 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1222 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1223 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1224 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1225 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1226
Chia-I Wud6d079d2014-08-31 13:14:21 +08001227 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001228}
1229
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001230void cmd_batch_flush_all(struct intel_cmd *cmd)
1231{
1232 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1233 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1234 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1235 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1236 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1237 GEN6_PIPE_CONTROL_CS_STALL);
1238}
1239
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001240void cmd_batch_depth_count(struct intel_cmd *cmd,
1241 struct intel_bo *bo,
1242 XGL_GPU_SIZE offset)
1243{
1244 cmd_wa_gen6_pre_depth_stall_write(cmd);
1245
1246 gen6_PIPE_CONTROL(cmd,
1247 GEN6_PIPE_CONTROL_DEPTH_STALL |
1248 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001249 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001250}
1251
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001252void cmd_batch_timestamp(struct intel_cmd *cmd,
1253 struct intel_bo *bo,
1254 XGL_GPU_SIZE offset)
1255{
1256 /* need any WA or stall? */
1257 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1258}
1259
1260void cmd_batch_immediate(struct intel_cmd *cmd,
1261 struct intel_bo *bo,
1262 XGL_GPU_SIZE offset,
1263 uint64_t val)
1264{
1265 /* need any WA or stall? */
1266 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1267}
1268
Chia-I Wu302742d2014-08-22 10:28:29 +08001269static void gen6_cc_states(struct intel_cmd *cmd)
1270{
1271 const struct intel_blend_state *blend = cmd->bind.state.blend;
1272 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001273 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001274 uint32_t stencil_ref;
1275 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001276
1277 CMD_ASSERT(cmd, 6, 6);
1278
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001279 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001280 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001281 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1282 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001283 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001284 memset(blend_color, 0, sizeof(blend_color));
1285 }
1286
1287 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001288 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001289 stencil_ref = ds->cmd_stencil_ref;
1290 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001291 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001292 stencil_ref = 0;
1293 }
1294
Chia-I Wu72292b72014-09-09 10:48:33 +08001295 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001296
Chia-I Wu72292b72014-09-09 10:48:33 +08001297 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001298}
1299
Chia-I Wu1744cca2014-08-22 11:10:17 +08001300static void gen6_viewport_states(struct intel_cmd *cmd)
1301{
1302 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001303 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001304
1305 if (!viewport)
1306 return;
1307
Chia-I Wub1d450a2014-09-09 13:48:03 +08001308 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1309 viewport->viewport_count);
1310
1311 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1312 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1313 viewport->cmd);
1314
1315 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1316 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1317 &viewport->cmd[viewport->cmd_clip_pos]);
1318
1319 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1320 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1321 &viewport->cmd[viewport->cmd_cc_pos]);
1322
1323 if (viewport->scissor_enable) {
1324 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1325 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1326 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1327 } else {
1328 scissor_offset = 0;
1329 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001330
1331 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001332 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001333
Chia-I Wub1d450a2014-09-09 13:48:03 +08001334 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001335}
1336
Chia-I Wu302742d2014-08-22 10:28:29 +08001337static void gen7_cc_states(struct intel_cmd *cmd)
1338{
1339 const struct intel_blend_state *blend = cmd->bind.state.blend;
1340 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001341 uint32_t stencil_ref;
1342 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001343 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001344
1345 CMD_ASSERT(cmd, 7, 7.5);
1346
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001347 if (!blend && !ds)
1348 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001349
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001350 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001351 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001352 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001353 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001354
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001355 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1356 } else {
1357 memset(blend_color, 0, sizeof(blend_color));
1358 }
1359
1360 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001361 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001362 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001363 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1364 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001365 } else {
1366 stencil_ref = 0;
1367 }
1368
Chia-I Wu72292b72014-09-09 10:48:33 +08001369 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001370 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001371 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001372}
1373
Chia-I Wu1744cca2014-08-22 11:10:17 +08001374static void gen7_viewport_states(struct intel_cmd *cmd)
1375{
1376 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001377 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001378
1379 if (!viewport)
1380 return;
1381
Chia-I Wub1d450a2014-09-09 13:48:03 +08001382 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1383 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001384
Chia-I Wub1d450a2014-09-09 13:48:03 +08001385 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1386 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1387 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001388 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001389 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1390 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001391
1392 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1393 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1394 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001395 gen7_3dstate_pointer(cmd,
1396 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001397 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001398
Chia-I Wu1744cca2014-08-22 11:10:17 +08001399 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001400 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1401 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1402 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001403 gen7_3dstate_pointer(cmd,
1404 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001405 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001406 }
1407}
1408
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001409static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001410 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001411{
1412 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001413 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001414
Chia-I Wu72292b72014-09-09 10:48:33 +08001415 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001416
1417 dw[0] = GEN6_RENDER_TYPE_RENDER |
1418 GEN6_RENDER_SUBTYPE_3D |
1419 subop | (cmd_len - 2);
1420 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001421 dw[2] = 0;
1422 dw[3] = 0;
1423 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001424}
1425
1426static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001427 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001428{
1429 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001430 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001431
Chia-I Wu72292b72014-09-09 10:48:33 +08001432 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001433
1434 dw[0] = GEN6_RENDER_TYPE_RENDER |
1435 GEN6_RENDER_SUBTYPE_3D |
1436 subop | (cmd_len - 2);
1437 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001438 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001439 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001440 dw[4] = 0;
1441 dw[5] = 0;
1442 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001443}
1444
Chia-I Wu625105f2014-10-13 15:35:29 +08001445static uint32_t emit_samplers(struct intel_cmd *cmd,
1446 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001447{
1448 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1449 const XGL_UINT border_stride =
1450 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001451 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001452 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001453 XGL_UINT i;
1454
1455 CMD_ASSERT(cmd, 6, 7.5);
1456
Chia-I Wu625105f2014-10-13 15:35:29 +08001457 if (!rmap || !rmap->sampler_count)
1458 return 0;
1459
1460 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1461
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001462 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1463 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1464 border_stride * rmap->sampler_count, &border_dw);
1465
1466 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1467 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1468 4 * rmap->sampler_count, &sampler_dw);
1469
1470 for (i = 0; i < rmap->sampler_count; i++) {
1471 const struct intel_pipeline_rmap_slot *slot =
1472 &rmap->slots[surface_count + i];
1473 const struct intel_sampler *sampler;
1474
1475 switch (slot->path_len) {
1476 case 0:
1477 sampler = NULL;
1478 break;
1479 case INTEL_PIPELINE_RMAP_SLOT_RT:
1480 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1481 assert(!"unexpected rmap slot type");
1482 sampler = NULL;
1483 break;
1484 case 1:
1485 {
1486 const struct intel_dset *dset = cmd->bind.dset.graphics;
1487 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1488 const struct intel_dset_slot *dset_slot =
1489 &dset->slots[slot_offset + slot->u.index];
1490
1491 switch (dset_slot->type) {
1492 case INTEL_DSET_SLOT_SAMPLER:
1493 sampler = dset_slot->u.sampler;
1494 break;
1495 default:
1496 assert(!"unexpected dset slot type");
1497 sampler = NULL;
1498 break;
1499 }
1500 }
1501 break;
1502 default:
1503 assert(!"nested descriptor set unsupported");
1504 sampler = NULL;
1505 break;
1506 }
1507
1508 if (sampler) {
1509 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1510
1511 sampler_dw[0] = sampler->cmd[0];
1512 sampler_dw[1] = sampler->cmd[1];
1513 sampler_dw[2] = border_offset;
1514 sampler_dw[3] = sampler->cmd[2];
1515 } else {
1516 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1517 sampler_dw[1] = 0;
1518 sampler_dw[2] = 0;
1519 sampler_dw[3] = 0;
1520 }
1521
1522 border_offset += border_stride * 4;
1523 border_dw += border_stride;
1524 sampler_dw += 4;
1525 }
1526
Chia-I Wu625105f2014-10-13 15:35:29 +08001527 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001528}
1529
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001530static uint32_t emit_binding_table(struct intel_cmd *cmd,
1531 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001532{
Chia-I Wu72292b72014-09-09 10:48:33 +08001533 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001534 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001535
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001536 CMD_ASSERT(cmd, 6, 7.5);
1537
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001538 surface_count = (rmap) ?
1539 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1540 if (!surface_count)
1541 return 0;
1542
Chia-I Wu42a56202014-08-23 16:47:48 +08001543 assert(surface_count <= ARRAY_SIZE(binding_table));
1544
1545 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001546 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001547
1548 switch (slot->path_len) {
1549 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001550 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001551 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001552 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001553 {
1554 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1555
Chia-I Wu00b51a82014-09-09 12:07:37 +08001556 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001557 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1558 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001559
Chia-I Wu72292b72014-09-09 10:48:33 +08001560 cmd_reserve_reloc(cmd, 1);
1561 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1562 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001563 }
1564 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001565 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001566 {
1567 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001568 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001569
Chia-I Wu00b51a82014-09-09 12:07:37 +08001570 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001571 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1572 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001573
Chia-I Wu72292b72014-09-09 10:48:33 +08001574 cmd_reserve_reloc(cmd, 1);
1575 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1576 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001577 }
1578 break;
1579 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001580 {
1581 const struct intel_dset *dset = cmd->bind.dset.graphics;
1582 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1583 const struct intel_dset_slot *dset_slot =
1584 &dset->slots[slot_offset + slot->u.index];
1585
1586 switch (dset_slot->type) {
1587 case INTEL_DSET_SLOT_IMG_VIEW:
1588 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1589 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1590 dset_slot->u.img_view->cmd_len,
1591 dset_slot->u.img_view->cmd);
1592
1593 cmd_reserve_reloc(cmd, 1);
1594 cmd_surface_reloc(cmd, offset, 1,
1595 dset_slot->u.img_view->img->obj.mem->bo,
1596 dset_slot->u.img_view->cmd[1], 0);
1597 break;
1598 case INTEL_DSET_SLOT_MEM_VIEW:
1599 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1600 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1601 dset_slot->u.mem_view.cmd_len,
1602 dset_slot->u.mem_view.cmd);
1603
1604 cmd_reserve_reloc(cmd, 1);
1605 cmd_surface_reloc(cmd, offset, 1,
1606 dset_slot->u.mem_view.mem->bo,
1607 dset_slot->u.mem_view.cmd[1], 0);
1608 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001609 case INTEL_DSET_SLOT_SAMPLER:
1610 assert(0 == cmd->bind.dset.graphics_offset);
1611
1612 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1613 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1614 16, dset_slot->u.sampler->cmd);
1615 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001616 default:
1617 assert(!"unexpected dset slot type");
1618 break;
1619 }
1620 }
1621 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001622 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001623 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001624 break;
1625 }
1626
Chia-I Wu72292b72014-09-09 10:48:33 +08001627 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001628 }
1629
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001630 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001631 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001632 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001633}
1634
Chia-I Wu1d125092014-10-08 08:49:38 +08001635static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1636{
1637 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1638 const struct intel_pipeline_rmap *rmap = pipeline->vs.rmap;
1639 const struct intel_dset *dset = cmd->bind.dset.graphics;
1640 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1641 uint32_t *dw;
1642 XGL_UINT pos, i;
1643
1644 CMD_ASSERT(cmd, 6, 7.5);
1645
1646 if (!pipeline->vb_count)
1647 return;
1648
1649 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1650
1651 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1652 dw++;
1653 pos++;
1654
1655 for (i = 0; i < pipeline->vb_count; i++) {
1656 const XGL_UINT vb_offset = rmap->rt_count + rmap->resource_count +
1657 rmap->uav_count + rmap->sampler_count;
1658 const struct intel_pipeline_rmap_slot *slot = (i < rmap->vb_count) ?
1659 &rmap->slots[vb_offset + i] : NULL;
1660 struct intel_mem_view *view = NULL;
1661
1662 if (slot) {
1663 switch (slot->path_len) {
1664 case 1:
1665 view = (dset->slots[slot->u.index].type ==
1666 INTEL_DSET_SLOT_MEM_VIEW) ?
1667 &dset->slots[slot->u.index].u.mem_view : NULL;
1668 break;
1669 default:
1670 break;
1671 }
1672 }
1673
1674 assert(pipeline->vb[i].strideInBytes <= 2048);
1675
1676 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1677 pipeline->vb[i].strideInBytes;
1678
1679 if (cmd_gen(cmd) >= INTEL_GEN(7))
1680 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1681
1682 switch (pipeline->vb[i].stepRate) {
1683 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1684 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1685 dw[3] = 0;
1686 break;
1687 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1688 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1689 dw[3] = 1;
1690 break;
1691 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1692 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1693 dw[3] = 0;
1694 break;
1695 default:
1696 assert(!"unknown step rate");
1697 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1698 dw[3] = 0;
1699 break;
1700 }
1701
1702 if (view) {
1703 const uint32_t begin = view->cmd[1];
1704 const uint32_t end = view->mem->size - 1;
1705
1706 cmd_reserve_reloc(cmd, 2);
1707 cmd_batch_reloc(cmd, pos + 1, view->mem->bo, begin, 0);
1708 cmd_batch_reloc(cmd, pos + 2, view->mem->bo, end, 0);
1709 } else {
1710 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1711 dw[1] = 0;
1712 dw[2] = 0;
1713 }
1714
1715 dw += 4;
1716 pos += 4;
1717 }
1718}
1719
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001720static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1721{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001722 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1723 const struct intel_pipeline_shader *vs = &pipeline->vs;
1724 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001725 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001726 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001727 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001728
1729 CMD_ASSERT(cmd, 6, 7.5);
1730
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001731 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001732 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1733 *
1734 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1735 * 128-bit vertex elements to be passed into the payload for each
1736 * vertex."
1737 *
1738 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1739 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001740 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001741 vue_read_len = (vs->in_count + 1) / 2;
1742 if (!vue_read_len)
1743 vue_read_len = 1;
1744
1745 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1746 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1747
1748 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1749 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1750 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001751
1752 dw5 = GEN6_VS_DW5_STATISTICS |
1753 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001754
1755 switch (cmd_gen(cmd)) {
1756 case INTEL_GEN(7.5):
1757 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1758 break;
1759 case INTEL_GEN(7):
1760 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1761 break;
1762 case INTEL_GEN(6):
1763 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1764 break;
1765 default:
1766 max_threads = 1;
1767 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001768 }
1769
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001770 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1771 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1772 else
1773 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1774
Chia-I Wube0a3d92014-09-02 13:20:59 +08001775 if (pipeline->disable_vs_cache)
1776 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1777
Chia-I Wu72292b72014-09-09 10:48:33 +08001778 cmd_batch_pointer(cmd, cmd_len, &dw);
1779 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001780 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001781 dw[2] = dw2;
1782 dw[3] = 0; /* scratch */
1783 dw[4] = dw4;
1784 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001785}
1786
Chia-I Wu625105f2014-10-13 15:35:29 +08001787static void emit_shader_resources(struct intel_cmd *cmd)
1788{
1789 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001790 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001791
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001792 binding_tables[0] = emit_binding_table(cmd,
1793 cmd->bind.pipeline.graphics->vs.rmap);
1794 binding_tables[1] = emit_binding_table(cmd,
1795 cmd->bind.pipeline.graphics->tcs.rmap);
1796 binding_tables[2] = emit_binding_table(cmd,
1797 cmd->bind.pipeline.graphics->tes.rmap);
1798 binding_tables[3] = emit_binding_table(cmd,
1799 cmd->bind.pipeline.graphics->gs.rmap);
1800 binding_tables[4] = emit_binding_table(cmd,
1801 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001802
1803 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1804 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1805 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1806 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1807 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1808
1809 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1810 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001811 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1812 binding_tables[0]);
1813 gen7_3dstate_pointer(cmd,
1814 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1815 binding_tables[1]);
1816 gen7_3dstate_pointer(cmd,
1817 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1818 binding_tables[2]);
1819 gen7_3dstate_pointer(cmd,
1820 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1821 binding_tables[3]);
1822 gen7_3dstate_pointer(cmd,
1823 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1824 binding_tables[4]);
1825
1826 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001827 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1828 samplers[0]);
1829 gen7_3dstate_pointer(cmd,
1830 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1831 samplers[1]);
1832 gen7_3dstate_pointer(cmd,
1833 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1834 samplers[2]);
1835 gen7_3dstate_pointer(cmd,
1836 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1837 samplers[3]);
1838 gen7_3dstate_pointer(cmd,
1839 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1840 samplers[4]);
1841 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001842 assert(!binding_tables[1] && !binding_tables[2]);
1843 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1844 binding_tables[0], binding_tables[3], binding_tables[4]);
1845
Chia-I Wu625105f2014-10-13 15:35:29 +08001846 assert(!samplers[1] && !samplers[2]);
1847 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1848 samplers[0], samplers[3], samplers[4]);
1849 }
1850}
1851
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001852static void emit_rt(struct intel_cmd *cmd)
1853{
1854 cmd_wa_gen6_pre_depth_stall_write(cmd);
1855 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1856 cmd->bind.att.height);
1857}
1858
1859static void emit_ds(struct intel_cmd *cmd)
1860{
1861 const struct intel_ds_view *ds = cmd->bind.att.ds;
1862
1863 if (!ds) {
1864 /* all zeros */
1865 static const struct intel_ds_view null_ds;
1866 ds = &null_ds;
1867 }
1868
1869 cmd_wa_gen6_pre_ds_flush(cmd);
1870 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1871 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1872 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1873
1874 if (cmd_gen(cmd) >= INTEL_GEN(7))
1875 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1876 else
1877 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1878}
1879
Chia-I Wua57761b2014-10-14 14:27:44 +08001880static uint32_t emit_shader(struct intel_cmd *cmd,
1881 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001882{
Chia-I Wua57761b2014-10-14 14:27:44 +08001883 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1884 uint32_t offset;
1885 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001886
Chia-I Wua57761b2014-10-14 14:27:44 +08001887 /* see if the shader is already in the cache */
1888 for (i = 0; i < cache->used; i++) {
1889 if (cache->entries[i].shader == (const void *) shader)
1890 return cache->entries[i].kernel_offset;
1891 }
1892
1893 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1894
1895 /* grow the cache if full */
1896 if (cache->used >= cache->count) {
1897 const XGL_UINT count = cache->count + 16;
1898 void *entries;
1899
1900 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1901 XGL_SYSTEM_ALLOC_INTERNAL);
1902 if (entries) {
1903 if (cache->entries) {
1904 memcpy(entries, cache->entries,
1905 sizeof(cache->entries[0]) * cache->used);
1906 icd_free(cache->entries);
1907 }
1908
1909 cache->entries = entries;
1910 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001911 }
1912 }
1913
Chia-I Wua57761b2014-10-14 14:27:44 +08001914 /* add the shader to the cache */
1915 if (cache->used < cache->count) {
1916 cache->entries[cache->used].shader = (const void *) shader;
1917 cache->entries[cache->used].kernel_offset = offset;
1918 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001919 }
1920
Chia-I Wua57761b2014-10-14 14:27:44 +08001921 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001922}
1923
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001924static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001925{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001926 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001927
Chia-I Wu8370b402014-08-29 12:28:37 +08001928 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1929 cmd_wa_gen6_pre_depth_stall_write(cmd);
1930 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1931 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1932 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1933 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001934
1935 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001936 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001937 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001938
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001939 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001940 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001941 }
1942 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001943 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001944 }
1945 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001946 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1947 }
1948 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1949 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1950 }
1951 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1952 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001953 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001954
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001955 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1956 gen7_3DSTATE_GS(cmd);
1957 } else {
1958 gen6_3DSTATE_GS(cmd);
1959 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001960
Chia-I Wu8370b402014-08-29 12:28:37 +08001961 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1962 cmd_wa_gen7_post_command_cs_stall(cmd);
1963 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1964 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001965}
1966
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001967static void emit_bounded_states(struct intel_cmd *cmd)
1968{
1969 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1970
1971 emit_graphics_pipeline(cmd);
1972
1973 emit_rt(cmd);
1974 emit_ds(cmd);
1975
1976 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1977 gen7_cc_states(cmd);
1978 gen7_viewport_states(cmd);
1979
1980 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1981 &cmd->bind.pipeline.graphics->vs);
1982 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1983 &cmd->bind.pipeline.graphics->fs);
1984
1985 gen6_3DSTATE_CLIP(cmd);
1986 gen7_3DSTATE_SF(cmd);
1987 gen7_3DSTATE_SBE(cmd);
1988 gen7_3DSTATE_WM(cmd);
1989 gen7_3DSTATE_PS(cmd);
1990 } else {
1991 gen6_cc_states(cmd);
1992 gen6_viewport_states(cmd);
1993
1994 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1995 &cmd->bind.pipeline.graphics->vs);
1996 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1997 &cmd->bind.pipeline.graphics->fs);
1998
1999 gen6_3DSTATE_CLIP(cmd);
2000 gen6_3DSTATE_SF(cmd);
2001 gen6_3DSTATE_WM(cmd);
2002 }
2003
2004 emit_shader_resources(cmd);
2005
2006 cmd_wa_gen6_pre_depth_stall_write(cmd);
2007 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2008
2009 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2010 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2011
2012 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2013 gen6_3DSTATE_VS(cmd);
2014}
2015
Chia-I Wu6032b892014-10-17 14:47:18 +08002016static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2017{
2018 const struct intel_cmd_meta *meta = cmd->bind.meta;
2019 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2020
2021 CMD_ASSERT(cmd, 6, 7.5);
2022
2023 blend_offset = 0;
2024 ds_offset = 0;
2025 cc_offset = 0;
2026 cc_vp_offset = 0;
2027
2028 if (meta->dst.valid) {
2029 /* BLEND_STATE */
2030 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
2031 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2032 dw[0] = 0;
2033 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2034 }
2035
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002036 if (meta->ds.state) {
2037 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002038
2039 /* DEPTH_STENCIL_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002040 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002041
2042 /* COLOR_CALC_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002043 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2044 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002045
2046 /* CC_VIEWPORT */
2047 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
2048 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002049 dw[0] = u_fui(0.0f);
2050 dw[1] = u_fui(1.0f);
Chia-I Wua667c2b2014-10-28 11:40:29 +08002051 } else {
2052 /* DEPTH_STENCIL_STATE */
2053 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2054 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4,
2055 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2056 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
Chia-I Wu6032b892014-10-17 14:47:18 +08002057 }
2058
2059 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2060 gen7_3dstate_pointer(cmd,
2061 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2062 blend_offset);
2063 gen7_3dstate_pointer(cmd,
2064 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2065 ds_offset);
2066 gen7_3dstate_pointer(cmd,
2067 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2068
2069 gen7_3dstate_pointer(cmd,
2070 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2071 cc_vp_offset);
2072 } else {
2073 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002074 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002075
2076 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2077 cmd_batch_pointer(cmd, 4, &dw);
2078 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2079 GEN6_PTR_VP_DW0_CC_CHANGED;
2080 dw[1] = 0;
2081 dw[2] = 0;
2082 dw[3] = cc_vp_offset;
2083 }
2084}
2085
2086static void gen6_meta_surface_states(struct intel_cmd *cmd)
2087{
2088 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002089 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002090 uint32_t offset;
2091
2092 CMD_ASSERT(cmd, 6, 7.5);
2093
Chia-I Wu005c47c2014-10-22 13:49:13 +08002094 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002095 if (meta->src.valid) {
2096 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2097 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2098 meta->src.surface_len, meta->src.surface);
2099
2100 cmd_reserve_reloc(cmd, 1);
2101 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2102 cmd_surface_reloc_writer(cmd, offset, 1,
2103 meta->src.reloc_target, meta->src.reloc_offset);
2104 } else {
2105 cmd_surface_reloc(cmd, offset, 1,
2106 (struct intel_bo *) meta->src.reloc_target,
2107 meta->src.reloc_offset, meta->src.reloc_flags);
2108 }
2109
Chia-I Wu005c47c2014-10-22 13:49:13 +08002110 binding_table[0] = offset;
2111 }
2112 if (meta->dst.valid) {
2113 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2114 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2115 meta->dst.surface_len, meta->dst.surface);
2116
2117 cmd_reserve_reloc(cmd, 1);
2118 cmd_surface_reloc(cmd, offset, 1,
2119 (struct intel_bo *) meta->dst.reloc_target,
2120 meta->dst.reloc_offset, meta->dst.reloc_flags);
2121
2122 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002123 }
2124
2125 /* BINDING_TABLE */
2126 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
2127 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002128 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002129
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 |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002613 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2614
Chia-I Wu6032b892014-10-17 14:47:18 +08002615 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2616 GEN6_WM_DW6_POSOFFSET_NONE |
2617 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2618 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2619 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2620 if (meta->samples > 1) {
2621 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2622 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2623 } else {
2624 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2625 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2626 }
2627 dw[7] = 0;
2628 dw[8] = 0;
2629}
2630
2631static void gen7_meta_ps(struct intel_cmd *cmd)
2632{
2633 const struct intel_cmd_meta *meta = cmd->bind.meta;
2634 const struct intel_pipeline_shader *sh =
2635 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2636 uint32_t offset, *dw;
2637
2638 CMD_ASSERT(cmd, 7, 7.5);
2639
Chia-I Wu3adf7212014-10-24 15:34:07 +08002640 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2641 return;
2642 /* a normal color write */
2643 assert(meta->dst.valid && !sh->uses);
2644
Chia-I Wu6032b892014-10-17 14:47:18 +08002645 /* 3DSTATE_WM */
2646 cmd_batch_pointer(cmd, 3, &dw);
2647 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2648 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2649 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2650 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2651 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2652 dw[2] = 0;
2653
2654 /* 3DSTATE_CONSTANT_PS */
2655 offset = gen6_meta_ps_constants(cmd);
2656 cmd_batch_pointer(cmd, 7, &dw);
2657 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2658 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2659 dw[2] = 0;
2660 dw[3] = offset;
2661 dw[4] = 0;
2662 dw[5] = 0;
2663 dw[6] = 0;
2664
2665 /* 3DSTATE_PS */
2666 offset = emit_shader(cmd, sh);
2667 cmd_batch_pointer(cmd, 8, &dw);
2668 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2669 dw[1] = offset;
2670 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2671 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2672 dw[3] = 0;
2673
2674 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2675 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002676 GEN7_PS_DW4_16_PIXEL_DISPATCH |
Chia-I Wu6032b892014-10-17 14:47:18 +08002677 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2678 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
2679 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
2680
2681 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2682 dw[6] = 0;
2683 dw[7] = 0;
2684}
2685
2686static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2687{
2688 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002689 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002690
2691 CMD_ASSERT(cmd, 6, 7.5);
2692
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002693 if (!ds) {
2694 /* all zeros */
2695 static const struct intel_ds_view null_ds;
2696 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002697 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002698
2699 cmd_wa_gen6_pre_ds_flush(cmd);
2700 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2701 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2702 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2703
2704 if (cmd_gen(cmd) >= INTEL_GEN(7))
2705 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2706 else
2707 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002708}
2709
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002710static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2711 const struct intel_pipeline *pipeline)
2712{
2713 cmd->bind.pipeline.graphics = pipeline;
2714}
2715
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002716static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2717 const struct intel_pipeline *pipeline)
2718{
2719 cmd->bind.pipeline.compute = pipeline;
2720}
2721
2722static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2723 const struct intel_pipeline_delta *delta)
2724{
2725 cmd->bind.pipeline.graphics_delta = delta;
2726}
2727
2728static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2729 const struct intel_pipeline_delta *delta)
2730{
2731 cmd->bind.pipeline.compute_delta = delta;
2732}
2733
2734static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2735 const struct intel_dset *dset,
2736 XGL_UINT slot_offset)
2737{
2738 cmd->bind.dset.graphics = dset;
2739 cmd->bind.dset.graphics_offset = slot_offset;
2740}
2741
2742static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2743 const struct intel_dset *dset,
2744 XGL_UINT slot_offset)
2745{
2746 cmd->bind.dset.compute = dset;
2747 cmd->bind.dset.compute_offset = slot_offset;
2748}
2749
2750static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2751 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2752{
2753 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2754}
2755
2756static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2757 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2758{
2759 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2760}
2761
2762static void cmd_bind_index_data(struct intel_cmd *cmd,
2763 const struct intel_mem *mem,
2764 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2765{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002766 cmd->bind.index.mem = mem;
2767 cmd->bind.index.offset = offset;
2768 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002769}
2770
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002771static void cmd_bind_attachments(struct intel_cmd *cmd,
2772 XGL_UINT rt_count,
2773 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2774 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002775{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002776 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002777 XGL_UINT i;
2778
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002779 for (i = 0; i < rt_count; i++) {
2780 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002781 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002782 const struct intel_layout *layout = &rt->img->layout;
2783
2784 if (i == 0) {
2785 width = layout->width0;
2786 height = layout->height0;
2787 } else {
2788 if (width > layout->width0)
2789 width = layout->width0;
2790 if (height > layout->height0)
2791 height = layout->height0;
2792 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002793
2794 cmd->bind.att.rt[i] = rt;
2795 }
2796
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002797 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002798
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002799 if (ds_info) {
2800 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002801
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002802 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2803 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002804
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002805 if (width > layout->width0)
2806 width = layout->width0;
2807 if (height > layout->height0)
2808 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002809 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002810 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002811 }
2812
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002813 cmd->bind.att.width = width;
2814 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002815}
2816
2817static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2818 const struct intel_viewport_state *state)
2819{
2820 cmd->bind.state.viewport = state;
2821}
2822
2823static void cmd_bind_raster_state(struct intel_cmd *cmd,
2824 const struct intel_raster_state *state)
2825{
2826 cmd->bind.state.raster = state;
2827}
2828
2829static void cmd_bind_ds_state(struct intel_cmd *cmd,
2830 const struct intel_ds_state *state)
2831{
2832 cmd->bind.state.ds = state;
2833}
2834
2835static void cmd_bind_blend_state(struct intel_cmd *cmd,
2836 const struct intel_blend_state *state)
2837{
2838 cmd->bind.state.blend = state;
2839}
2840
2841static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2842 const struct intel_msaa_state *state)
2843{
2844 cmd->bind.state.msaa = state;
2845}
2846
2847static void cmd_draw(struct intel_cmd *cmd,
2848 XGL_UINT vertex_start,
2849 XGL_UINT vertex_count,
2850 XGL_UINT instance_start,
2851 XGL_UINT instance_count,
2852 bool indexed,
2853 XGL_UINT vertex_base)
2854{
2855 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2856
2857 emit_bounded_states(cmd);
2858
2859 if (indexed) {
2860 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2861 cmd->result = XGL_ERROR_UNKNOWN;
2862
2863 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2864 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2865 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002866 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2867 cmd->bind.index.offset, cmd->bind.index.type,
2868 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002869 } else {
2870 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2871 cmd->bind.index.offset, cmd->bind.index.type,
2872 p->primitive_restart);
2873 }
2874 } else {
2875 assert(!vertex_base);
2876 }
2877
2878 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2879 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2880 vertex_start, instance_count, instance_start, vertex_base);
2881 } else {
2882 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2883 vertex_start, instance_count, instance_start, vertex_base);
2884 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002885
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002886 if (intel_debug & INTEL_DEBUG_NOCACHE)
2887 cmd_batch_flush_all(cmd);
2888
Chia-I Wu707a29e2014-08-27 12:51:47 +08002889 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002890 /* need to re-emit all workarounds */
2891 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002892}
2893
Chia-I Wuc14d1562014-10-17 09:49:22 +08002894void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2895{
Chia-I Wu6032b892014-10-17 14:47:18 +08002896 cmd->bind.meta = meta;
2897
2898 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08002899 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002900
2901 gen6_meta_dynamic_states(cmd);
2902 gen6_meta_surface_states(cmd);
2903
2904 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2905 gen7_meta_urb(cmd);
2906 gen6_meta_vf(cmd);
2907 gen7_meta_disabled(cmd);
2908 gen6_meta_wm(cmd);
2909 gen7_meta_ps(cmd);
2910 gen6_meta_depth_buffer(cmd);
2911
2912 cmd_wa_gen7_post_command_cs_stall(cmd);
2913 cmd_wa_gen7_post_command_depth_stall(cmd);
2914
2915 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2916 } else {
2917 gen6_meta_urb(cmd);
2918 gen6_meta_vf(cmd);
2919 gen6_meta_disabled(cmd);
2920 gen6_meta_wm(cmd);
2921 gen6_meta_ps(cmd);
2922 gen6_meta_depth_buffer(cmd);
2923
2924 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2925 }
2926
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002927 if (intel_debug & INTEL_DEBUG_NOCACHE)
2928 cmd_batch_flush_all(cmd);
2929
Chia-I Wu6032b892014-10-17 14:47:18 +08002930 cmd->bind.draw_count++;
2931 /* need to re-emit all workarounds */
2932 cmd->bind.wa_flags = 0;
2933
2934 cmd->bind.meta = NULL;
Chia-I Wuc14d1562014-10-17 09:49:22 +08002935}
2936
Chia-I Wub2755562014-08-20 13:38:52 +08002937XGL_VOID XGLAPI intelCmdBindPipeline(
2938 XGL_CMD_BUFFER cmdBuffer,
2939 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2940 XGL_PIPELINE pipeline)
2941{
2942 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2943
2944 switch (pipelineBindPoint) {
2945 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002946 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002947 break;
2948 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002949 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002950 break;
2951 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002952 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002953 break;
2954 }
2955}
2956
2957XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2958 XGL_CMD_BUFFER cmdBuffer,
2959 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2960 XGL_PIPELINE_DELTA delta)
2961{
2962 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2963
2964 switch (pipelineBindPoint) {
2965 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002966 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002967 break;
2968 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002969 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002970 break;
2971 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002972 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002973 break;
2974 }
2975}
2976
2977XGL_VOID XGLAPI intelCmdBindStateObject(
2978 XGL_CMD_BUFFER cmdBuffer,
2979 XGL_STATE_BIND_POINT stateBindPoint,
2980 XGL_STATE_OBJECT state)
2981{
2982 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2983
2984 switch (stateBindPoint) {
2985 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002986 cmd_bind_viewport_state(cmd,
2987 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002988 break;
2989 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002990 cmd_bind_raster_state(cmd,
2991 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002992 break;
2993 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002994 cmd_bind_ds_state(cmd,
2995 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002996 break;
2997 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002998 cmd_bind_blend_state(cmd,
2999 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003000 break;
3001 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003002 cmd_bind_msaa_state(cmd,
3003 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003004 break;
3005 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003006 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003007 break;
3008 }
3009}
3010
3011XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3012 XGL_CMD_BUFFER cmdBuffer,
3013 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3014 XGL_UINT index,
3015 XGL_DESCRIPTOR_SET descriptorSet,
3016 XGL_UINT slotOffset)
3017{
3018 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3019 struct intel_dset *dset = intel_dset(descriptorSet);
3020
3021 assert(!index);
3022
3023 switch (pipelineBindPoint) {
3024 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003025 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003026 break;
3027 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003028 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003029 break;
3030 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003031 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003032 break;
3033 }
3034}
3035
3036XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3037 XGL_CMD_BUFFER cmdBuffer,
3038 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3039 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3040{
3041 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3042
3043 switch (pipelineBindPoint) {
3044 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003045 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003046 break;
3047 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003048 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003049 break;
3050 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003051 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003052 break;
3053 }
3054}
3055
3056XGL_VOID XGLAPI intelCmdBindIndexData(
3057 XGL_CMD_BUFFER cmdBuffer,
3058 XGL_GPU_MEMORY mem_,
3059 XGL_GPU_SIZE offset,
3060 XGL_INDEX_TYPE indexType)
3061{
3062 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3063 struct intel_mem *mem = intel_mem(mem_);
3064
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003065 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003066}
3067
3068XGL_VOID XGLAPI intelCmdBindAttachments(
3069 XGL_CMD_BUFFER cmdBuffer,
3070 XGL_UINT colorAttachmentCount,
3071 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3072 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3073{
3074 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003075
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003076 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3077 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003078}
3079
3080XGL_VOID XGLAPI intelCmdDraw(
3081 XGL_CMD_BUFFER cmdBuffer,
3082 XGL_UINT firstVertex,
3083 XGL_UINT vertexCount,
3084 XGL_UINT firstInstance,
3085 XGL_UINT instanceCount)
3086{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003087 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003088
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003089 cmd_draw(cmd, firstVertex, vertexCount,
3090 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003091}
3092
3093XGL_VOID XGLAPI intelCmdDrawIndexed(
3094 XGL_CMD_BUFFER cmdBuffer,
3095 XGL_UINT firstIndex,
3096 XGL_UINT indexCount,
3097 XGL_INT vertexOffset,
3098 XGL_UINT firstInstance,
3099 XGL_UINT instanceCount)
3100{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003101 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003102
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003103 cmd_draw(cmd, firstIndex, indexCount,
3104 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003105}
3106
3107XGL_VOID XGLAPI intelCmdDrawIndirect(
3108 XGL_CMD_BUFFER cmdBuffer,
3109 XGL_GPU_MEMORY mem,
3110 XGL_GPU_SIZE offset,
3111 XGL_UINT32 count,
3112 XGL_UINT32 stride)
3113{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003114 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3115
3116 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003117}
3118
3119XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3120 XGL_CMD_BUFFER cmdBuffer,
3121 XGL_GPU_MEMORY mem,
3122 XGL_GPU_SIZE offset,
3123 XGL_UINT32 count,
3124 XGL_UINT32 stride)
3125{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003126 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3127
3128 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003129}
3130
3131XGL_VOID XGLAPI intelCmdDispatch(
3132 XGL_CMD_BUFFER cmdBuffer,
3133 XGL_UINT x,
3134 XGL_UINT y,
3135 XGL_UINT z)
3136{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003137 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3138
3139 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003140}
3141
3142XGL_VOID XGLAPI intelCmdDispatchIndirect(
3143 XGL_CMD_BUFFER cmdBuffer,
3144 XGL_GPU_MEMORY mem,
3145 XGL_GPU_SIZE offset)
3146{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003147 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3148
3149 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003150}