blob: da843aecaa4550cb3fced896f73eda697a0aabe7 [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;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800550 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800551 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
552 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800553 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800554
555 CMD_ASSERT(cmd, 6, 7.5);
556
557 dw1 = GEN6_CLIP_DW1_STATISTICS;
558 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
559 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
560 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
561 raster->cmd_clip_cull;
562 }
563
GregFbcbe19a2014-11-07 11:01:01 -0700564// LunarG GSF CLIP TODO
565#define CLIP_ENABLE 1
566
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800567 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
568 GEN6_CLIP_DW2_XY_TEST_ENABLE |
569 GEN6_CLIP_DW2_APIMODE_OGL |
GregFe8f27aa2014-11-06 14:51:18 -0700570 // LunarG GSF CLIP TODO
571 //state->clip_plane_enable << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
GregFbcbe19a2014-11-07 11:01:01 -0700572 CLIP_ENABLE << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800573 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
574 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
575 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
576
577 if (pipeline->rasterizerDiscardEnable)
578 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
579 else
580 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
581
582 if (pipeline->depthClipEnable)
583 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
584
585 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
586 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
587 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
588 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
589
590 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
591 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
592 (viewport->viewport_count - 1);
593
Chia-I Wu72292b72014-09-09 10:48:33 +0800594 cmd_batch_pointer(cmd, cmd_len, &dw);
595 dw[0] = dw0;
596 dw[1] = dw1;
597 dw[2] = dw2;
598 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800599}
600
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800601static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
602{
603 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
604 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800605 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800606 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
607 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800608 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800609
610 CMD_ASSERT(cmd, 6, 6);
611
612 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
613
614 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
615 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
616
617 dw4 = GEN6_WM_DW4_STATISTICS |
618 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
619 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
620 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
621
622 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
623 GEN6_WM_DW5_PS_ENABLE |
624 GEN6_WM_DW5_8_PIXEL_DISPATCH;
625
626 if (fs->uses & INTEL_SHADER_USE_KILL ||
627 pipeline->cb_state.alphaToCoverageEnable)
628 dw5 |= GEN6_WM_DW5_PS_KILL;
629
630 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
631 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
632 if (fs->uses & INTEL_SHADER_USE_DEPTH)
633 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
634 if (fs->uses & INTEL_SHADER_USE_W)
635 dw5 |= GEN6_WM_DW5_PS_USE_W;
636
637 if (pipeline->cb_state.dualSourceBlendEnable)
638 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
639
640 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
641 GEN6_WM_DW6_POSOFFSET_NONE |
642 GEN6_WM_DW6_ZW_INTERP_PIXEL |
643 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
644 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
645
646 if (msaa->sample_count > 1) {
647 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
648 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
649 } else {
650 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
651 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
652 }
653
Chia-I Wu72292b72014-09-09 10:48:33 +0800654 cmd_batch_pointer(cmd, cmd_len, &dw);
655 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800656 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800657 dw[2] = dw2;
658 dw[3] = 0; /* scratch */
659 dw[4] = dw4;
660 dw[5] = dw5;
661 dw[6] = dw6;
662 dw[7] = 0; /* kernel 1 */
663 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800664}
665
666static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
667{
668 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800669 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800670 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
671 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800672 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800673
674 CMD_ASSERT(cmd, 7, 7.5);
675
676 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
677
678 dw1 = GEN7_WM_DW1_STATISTICS |
679 GEN7_WM_DW1_PS_ENABLE |
680 GEN7_WM_DW1_ZW_INTERP_PIXEL |
681 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
682 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
683
684 if (fs->uses & INTEL_SHADER_USE_KILL ||
685 pipeline->cb_state.alphaToCoverageEnable)
686 dw1 |= GEN7_WM_DW1_PS_KILL;
687
688 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
689 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
690 if (fs->uses & INTEL_SHADER_USE_DEPTH)
691 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
692 if (fs->uses & INTEL_SHADER_USE_W)
693 dw1 |= GEN7_WM_DW1_PS_USE_W;
694
695 dw2 = 0;
696
697 if (msaa->sample_count > 1) {
698 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
699 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
700 } else {
701 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
702 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
703 }
704
Chia-I Wu72292b72014-09-09 10:48:33 +0800705 cmd_batch_pointer(cmd, cmd_len, &dw);
706 dw[0] = dw0;
707 dw[1] = dw1;
708 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800709}
710
711static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
712{
713 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800714 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800715 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
716 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800718
719 CMD_ASSERT(cmd, 7, 7.5);
720
721 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
722
723 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
724 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
725
726 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
727 GEN7_PS_DW4_8_PIXEL_DISPATCH;
728
729 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
730 const int max_threads =
731 (cmd->dev->gpu->gt == 3) ? 408 :
732 (cmd->dev->gpu->gt == 2) ? 204 : 102;
733 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
734 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
735 } else {
736 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
737 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
738 }
739
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800740 if (fs->in_count)
741 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
742
743 if (pipeline->cb_state.dualSourceBlendEnable)
744 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
745
746 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
747 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
748 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
749
Chia-I Wu72292b72014-09-09 10:48:33 +0800750 cmd_batch_pointer(cmd, cmd_len, &dw);
751 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800752 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800753 dw[2] = dw2;
754 dw[3] = 0; /* scratch */
755 dw[4] = dw4;
756 dw[5] = dw5;
757 dw[6] = 0; /* kernel 1 */
758 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800759}
760
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800761static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
762 const struct intel_ds_view *view)
763{
764 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800765 uint32_t dw0, *dw;
766 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767
768 CMD_ASSERT(cmd, 6, 7.5);
769
770 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800771 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
772 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800773 dw0 |= (cmd_len - 2);
774
Chia-I Wu72292b72014-09-09 10:48:33 +0800775 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
776 dw[0] = dw0;
777 dw[1] = view->cmd[0];
778 dw[2] = 0;
779 dw[3] = view->cmd[2];
780 dw[4] = view->cmd[3];
781 dw[5] = view->cmd[4];
782 dw[6] = view->cmd[5];
783
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600784 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 cmd_reserve_reloc(cmd, 1);
786 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
787 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600788 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800789}
790
791static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
792 const struct intel_ds_view *view)
793{
794 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800795 uint32_t dw0, *dw;
796 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797
798 CMD_ASSERT(cmd, 6, 7.5);
799
800 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800801 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
802 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800803 dw0 |= (cmd_len - 2);
804
Chia-I Wu72292b72014-09-09 10:48:33 +0800805 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
806 dw[0] = dw0;
807 dw[1] = view->cmd[6];
808 dw[2] = 0;
809
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600810 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800811 cmd_reserve_reloc(cmd, 1);
812 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
813 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600814 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800815}
816
817static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
818 const struct intel_ds_view *view)
819{
820 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800821 uint32_t dw0, *dw;
822 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800823
824 CMD_ASSERT(cmd, 6, 7.5);
825
826 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800827 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
828 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800829 dw0 |= (cmd_len - 2);
830
Chia-I Wu72292b72014-09-09 10:48:33 +0800831 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
832 dw[0] = dw0;
833 dw[1] = view->cmd[8];
834 dw[2] = 0;
835
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600836 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800837 cmd_reserve_reloc(cmd, 1);
838 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
839 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600840 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800841}
842
Chia-I Wuf8231032014-08-25 10:44:45 +0800843static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
844 uint32_t clear_val)
845{
846 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800847 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800848 GEN6_CLEAR_PARAMS_DW0_VALID |
849 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800851
852 CMD_ASSERT(cmd, 6, 6);
853
Chia-I Wu72292b72014-09-09 10:48:33 +0800854 cmd_batch_pointer(cmd, cmd_len, &dw);
855 dw[0] = dw0;
856 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800857}
858
859static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
860 uint32_t clear_val)
861{
862 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800864 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800866
867 CMD_ASSERT(cmd, 7, 7.5);
868
Chia-I Wu72292b72014-09-09 10:48:33 +0800869 cmd_batch_pointer(cmd, cmd_len, &dw);
870 dw[0] = dw0;
871 dw[1] = clear_val;
872 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800873}
874
Chia-I Wu302742d2014-08-22 10:28:29 +0800875static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800876 uint32_t blend_offset,
877 uint32_t ds_offset,
878 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800879{
880 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800881 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800882
883 CMD_ASSERT(cmd, 6, 6);
884
Chia-I Wu426072d2014-08-26 14:31:55 +0800885 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800886 (cmd_len - 2);
887
Chia-I Wu72292b72014-09-09 10:48:33 +0800888 cmd_batch_pointer(cmd, cmd_len, &dw);
889 dw[0] = dw0;
890 dw[1] = blend_offset | 1;
891 dw[2] = ds_offset | 1;
892 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800893}
894
Chia-I Wu1744cca2014-08-22 11:10:17 +0800895static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800896 uint32_t clip_offset,
897 uint32_t sf_offset,
898 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800899{
900 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800901 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800902
903 CMD_ASSERT(cmd, 6, 6);
904
Chia-I Wu426072d2014-08-26 14:31:55 +0800905 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800906 GEN6_PTR_VP_DW0_CLIP_CHANGED |
907 GEN6_PTR_VP_DW0_SF_CHANGED |
908 GEN6_PTR_VP_DW0_CC_CHANGED |
909 (cmd_len - 2);
910
Chia-I Wu72292b72014-09-09 10:48:33 +0800911 cmd_batch_pointer(cmd, cmd_len, &dw);
912 dw[0] = dw0;
913 dw[1] = clip_offset;
914 dw[2] = sf_offset;
915 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800916}
917
918static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800919 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800920{
921 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800923
924 CMD_ASSERT(cmd, 6, 6);
925
Chia-I Wu426072d2014-08-26 14:31:55 +0800926 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800927 (cmd_len - 2);
928
Chia-I Wu72292b72014-09-09 10:48:33 +0800929 cmd_batch_pointer(cmd, cmd_len, &dw);
930 dw[0] = dw0;
931 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800932}
933
Chia-I Wu42a56202014-08-23 16:47:48 +0800934static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800935 uint32_t vs_offset,
936 uint32_t gs_offset,
937 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800938{
939 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800940 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800941
942 CMD_ASSERT(cmd, 6, 6);
943
Chia-I Wu426072d2014-08-26 14:31:55 +0800944 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800945 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
946 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
947 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
948 (cmd_len - 2);
949
Chia-I Wu72292b72014-09-09 10:48:33 +0800950 cmd_batch_pointer(cmd, cmd_len, &dw);
951 dw[0] = dw0;
952 dw[1] = vs_offset;
953 dw[2] = gs_offset;
954 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800955}
956
Chia-I Wu257e75e2014-08-29 14:06:35 +0800957static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800958 uint32_t vs_offset,
959 uint32_t gs_offset,
960 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800961{
962 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800963 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800964
965 CMD_ASSERT(cmd, 6, 6);
966
967 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
968 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
969 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
970 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
971 (cmd_len - 2);
972
Chia-I Wu72292b72014-09-09 10:48:33 +0800973 cmd_batch_pointer(cmd, cmd_len, &dw);
974 dw[0] = dw0;
975 dw[1] = vs_offset;
976 dw[2] = gs_offset;
977 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800978}
979
Chia-I Wu302742d2014-08-22 10:28:29 +0800980static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800981 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800982{
983 const uint8_t cmd_len = 2;
984 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
985 GEN6_RENDER_SUBTYPE_3D |
986 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800987 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800988
Chia-I Wu72292b72014-09-09 10:48:33 +0800989 cmd_batch_pointer(cmd, cmd_len, &dw);
990 dw[0] = dw0;
991 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800992}
993
Chia-I Wu72292b72014-09-09 10:48:33 +0800994static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800995 const struct intel_blend_state *state)
996{
Chia-I Wu72292b72014-09-09 10:48:33 +0800997 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800998 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
999
1000 CMD_ASSERT(cmd, 6, 7.5);
1001 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1002
Chia-I Wu00b51a82014-09-09 12:07:37 +08001003 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
1004 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001005}
1006
Chia-I Wu72292b72014-09-09 10:48:33 +08001007static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001008 const struct intel_ds_state *state)
1009{
Chia-I Wu72292b72014-09-09 10:48:33 +08001010 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001011 const uint8_t cmd_len = 3;
1012
1013 CMD_ASSERT(cmd, 6, 7.5);
1014 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1015
Chia-I Wu00b51a82014-09-09 12:07:37 +08001016 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1017 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001018}
1019
Chia-I Wu72292b72014-09-09 10:48:33 +08001020static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001021 uint32_t stencil_ref,
1022 const uint32_t blend_color[4])
1023{
Chia-I Wu72292b72014-09-09 10:48:33 +08001024 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001025 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001026 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001027
1028 CMD_ASSERT(cmd, 6, 7.5);
1029
Chia-I Wu00b51a82014-09-09 12:07:37 +08001030 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1031 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001032 dw[0] = stencil_ref;
1033 dw[1] = 0;
1034 dw[2] = blend_color[0];
1035 dw[3] = blend_color[1];
1036 dw[4] = blend_color[2];
1037 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001038
Chia-I Wu72292b72014-09-09 10:48:33 +08001039 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001040}
1041
Chia-I Wu8370b402014-08-29 12:28:37 +08001042static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001043{
Chia-I Wu8370b402014-08-29 12:28:37 +08001044 CMD_ASSERT(cmd, 6, 7.5);
1045
Chia-I Wu707a29e2014-08-27 12:51:47 +08001046 if (!cmd->bind.draw_count)
1047 return;
1048
Chia-I Wu8370b402014-08-29 12:28:37 +08001049 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001050 return;
1051
Chia-I Wu8370b402014-08-29 12:28:37 +08001052 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001053
1054 /*
1055 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1056 *
1057 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1058 * pipe-control with a post-sync op and no write-cache flushes."
1059 *
1060 * The workaround below necessitates this workaround.
1061 */
1062 gen6_PIPE_CONTROL(cmd,
1063 GEN6_PIPE_CONTROL_CS_STALL |
1064 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001065 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001066
Chia-I Wud6d079d2014-08-31 13:14:21 +08001067 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1068 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001069}
1070
Chia-I Wu8370b402014-08-29 12:28:37 +08001071static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001072{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001073 CMD_ASSERT(cmd, 6, 7.5);
1074
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001075 if (!cmd->bind.draw_count)
1076 return;
1077
Chia-I Wud6d079d2014-08-31 13:14:21 +08001078 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1079 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001080}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001081
Chia-I Wu8370b402014-08-29 12:28:37 +08001082static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1083{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001084 CMD_ASSERT(cmd, 7, 7.5);
1085
Chia-I Wu8370b402014-08-29 12:28:37 +08001086 if (!cmd->bind.draw_count)
1087 return;
1088
1089 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001090
1091 gen6_PIPE_CONTROL(cmd,
1092 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001093 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001094}
1095
Chia-I Wu8370b402014-08-29 12:28:37 +08001096static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1097{
1098 CMD_ASSERT(cmd, 7, 7.5);
1099
1100 if (!cmd->bind.draw_count)
1101 return;
1102
1103 /*
1104 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1105 *
1106 * "One of the following must also be set (when CS stall is set):
1107 *
1108 * * Render Target Cache Flush Enable ([12] of DW1)
1109 * * Depth Cache Flush Enable ([0] of DW1)
1110 * * Stall at Pixel Scoreboard ([1] of DW1)
1111 * * Depth Stall ([13] of DW1)
1112 * * Post-Sync Operation ([13] of DW1)"
1113 */
1114 gen6_PIPE_CONTROL(cmd,
1115 GEN6_PIPE_CONTROL_CS_STALL |
1116 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001117 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001118}
1119
1120static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1121{
1122 CMD_ASSERT(cmd, 7, 7.5);
1123
1124 if (!cmd->bind.draw_count)
1125 return;
1126
1127 cmd_wa_gen6_pre_depth_stall_write(cmd);
1128
Chia-I Wud6d079d2014-08-31 13:14:21 +08001129 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001130}
1131
1132static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1133{
1134 CMD_ASSERT(cmd, 6, 7.5);
1135
1136 if (!cmd->bind.draw_count)
1137 return;
1138
1139 /*
1140 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1141 *
1142 * "Driver must guarentee that all the caches in the depth pipe are
1143 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1144 * requires driver to send a PIPE_CONTROL with a CS stall along with
1145 * a Depth Flush prior to this command."
1146 *
1147 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1148 *
1149 * "Driver must ierarchi that all the caches in the depth pipe are
1150 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1151 * requires driver to send a PIPE_CONTROL with a CS stall along with
1152 * a Depth Flush prior to this command.
1153 */
1154 gen6_PIPE_CONTROL(cmd,
1155 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1156 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001157 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001158}
1159
1160static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1161{
1162 CMD_ASSERT(cmd, 6, 7.5);
1163
1164 if (!cmd->bind.draw_count)
1165 return;
1166
1167 /*
1168 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1169 *
1170 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1171 * and a post sync operation prior to the group of depth
1172 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1173 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1174 *
1175 * This workaround satifies all the conditions.
1176 */
1177 cmd_wa_gen6_pre_depth_stall_write(cmd);
1178
1179 /*
1180 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1181 *
1182 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1183 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1184 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1185 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1186 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1187 * Depth Flush Bit set, followed by another pipelined depth stall
1188 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1189 * guarantee that the pipeline from WM onwards is already flushed
1190 * (e.g., via a preceding MI_FLUSH)."
1191 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001192 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1193 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1194 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001195}
1196
Chia-I Wu525c6602014-08-27 10:22:34 +08001197void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1198{
1199 if (!cmd->bind.draw_count)
1200 return;
1201
1202 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1203
Chia-I Wu8370b402014-08-29 12:28:37 +08001204 /*
1205 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1206 *
1207 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1208 * PIPE_CONTROL with any non-zero post-sync-op is required."
1209 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001210 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001211 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001212
Chia-I Wu092279a2014-08-30 19:05:30 +08001213 /*
1214 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1215 *
1216 * "One of the following must also be set (when CS stall is set):
1217 *
1218 * * Render Target Cache Flush Enable ([12] of DW1)
1219 * * Depth Cache Flush Enable ([0] of DW1)
1220 * * Stall at Pixel Scoreboard ([1] of DW1)
1221 * * Depth Stall ([13] of DW1)
1222 * * Post-Sync Operation ([13] of DW1)"
1223 */
1224 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1225 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1226 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1227 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1228 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1229 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1230
Chia-I Wud6d079d2014-08-31 13:14:21 +08001231 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001232}
1233
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001234void cmd_batch_flush_all(struct intel_cmd *cmd)
1235{
1236 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1237 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1238 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1239 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1240 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1241 GEN6_PIPE_CONTROL_CS_STALL);
1242}
1243
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001244void cmd_batch_depth_count(struct intel_cmd *cmd,
1245 struct intel_bo *bo,
1246 XGL_GPU_SIZE offset)
1247{
1248 cmd_wa_gen6_pre_depth_stall_write(cmd);
1249
1250 gen6_PIPE_CONTROL(cmd,
1251 GEN6_PIPE_CONTROL_DEPTH_STALL |
1252 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001253 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001254}
1255
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001256void cmd_batch_timestamp(struct intel_cmd *cmd,
1257 struct intel_bo *bo,
1258 XGL_GPU_SIZE offset)
1259{
1260 /* need any WA or stall? */
1261 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1262}
1263
1264void cmd_batch_immediate(struct intel_cmd *cmd,
1265 struct intel_bo *bo,
1266 XGL_GPU_SIZE offset,
1267 uint64_t val)
1268{
1269 /* need any WA or stall? */
1270 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1271}
1272
Chia-I Wu302742d2014-08-22 10:28:29 +08001273static void gen6_cc_states(struct intel_cmd *cmd)
1274{
1275 const struct intel_blend_state *blend = cmd->bind.state.blend;
1276 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001277 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001278 uint32_t stencil_ref;
1279 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001280
1281 CMD_ASSERT(cmd, 6, 6);
1282
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001283 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001284 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001285 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1286 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001287 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001288 memset(blend_color, 0, sizeof(blend_color));
1289 }
1290
1291 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001292 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001293 stencil_ref = ds->cmd_stencil_ref;
1294 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001295 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001296 stencil_ref = 0;
1297 }
1298
Chia-I Wu72292b72014-09-09 10:48:33 +08001299 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001300
Chia-I Wu72292b72014-09-09 10:48:33 +08001301 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001302}
1303
Chia-I Wu1744cca2014-08-22 11:10:17 +08001304static void gen6_viewport_states(struct intel_cmd *cmd)
1305{
1306 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001307 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001308
1309 if (!viewport)
1310 return;
1311
Chia-I Wub1d450a2014-09-09 13:48:03 +08001312 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1313 viewport->viewport_count);
1314
1315 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1316 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1317 viewport->cmd);
1318
1319 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1320 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1321 &viewport->cmd[viewport->cmd_clip_pos]);
1322
1323 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1324 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1325 &viewport->cmd[viewport->cmd_cc_pos]);
1326
1327 if (viewport->scissor_enable) {
1328 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1329 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1330 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1331 } else {
1332 scissor_offset = 0;
1333 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001334
1335 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001336 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001337
Chia-I Wub1d450a2014-09-09 13:48:03 +08001338 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001339}
1340
Chia-I Wu302742d2014-08-22 10:28:29 +08001341static void gen7_cc_states(struct intel_cmd *cmd)
1342{
1343 const struct intel_blend_state *blend = cmd->bind.state.blend;
1344 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001345 uint32_t stencil_ref;
1346 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001347 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001348
1349 CMD_ASSERT(cmd, 7, 7.5);
1350
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001351 if (!blend && !ds)
1352 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001353
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001354 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001355 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001356 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001357 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001358
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001359 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1360 } else {
1361 memset(blend_color, 0, sizeof(blend_color));
1362 }
1363
1364 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001365 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001366 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001367 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1368 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001369 } else {
1370 stencil_ref = 0;
1371 }
1372
Chia-I Wu72292b72014-09-09 10:48:33 +08001373 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001374 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001375 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001376}
1377
Chia-I Wu1744cca2014-08-22 11:10:17 +08001378static void gen7_viewport_states(struct intel_cmd *cmd)
1379{
1380 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001381 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001382
1383 if (!viewport)
1384 return;
1385
Chia-I Wub1d450a2014-09-09 13:48:03 +08001386 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1387 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001388
Chia-I Wub1d450a2014-09-09 13:48:03 +08001389 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1390 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1391 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001392 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001393 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1394 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001395
1396 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1397 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1398 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001399 gen7_3dstate_pointer(cmd,
1400 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001401 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001402
Chia-I Wu1744cca2014-08-22 11:10:17 +08001403 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001404 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1405 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1406 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001407 gen7_3dstate_pointer(cmd,
1408 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001409 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001410 }
1411}
1412
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001413static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001414 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001415{
1416 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001417 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001418
Chia-I Wu72292b72014-09-09 10:48:33 +08001419 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001420
1421 dw[0] = GEN6_RENDER_TYPE_RENDER |
1422 GEN6_RENDER_SUBTYPE_3D |
1423 subop | (cmd_len - 2);
1424 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001425 dw[2] = 0;
1426 dw[3] = 0;
1427 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001428}
1429
1430static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001431 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001432{
1433 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001434 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001435
Chia-I Wu72292b72014-09-09 10:48:33 +08001436 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001437
1438 dw[0] = GEN6_RENDER_TYPE_RENDER |
1439 GEN6_RENDER_SUBTYPE_3D |
1440 subop | (cmd_len - 2);
1441 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001442 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001443 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001444 dw[4] = 0;
1445 dw[5] = 0;
1446 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001447}
1448
Chia-I Wu625105f2014-10-13 15:35:29 +08001449static uint32_t emit_samplers(struct intel_cmd *cmd,
1450 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001451{
1452 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1453 const XGL_UINT border_stride =
1454 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001455 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001456 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001457 XGL_UINT i;
1458
1459 CMD_ASSERT(cmd, 6, 7.5);
1460
Chia-I Wu625105f2014-10-13 15:35:29 +08001461 if (!rmap || !rmap->sampler_count)
1462 return 0;
1463
1464 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1465
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001466 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1467 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1468 border_stride * rmap->sampler_count, &border_dw);
1469
1470 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1471 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1472 4 * rmap->sampler_count, &sampler_dw);
1473
1474 for (i = 0; i < rmap->sampler_count; i++) {
1475 const struct intel_pipeline_rmap_slot *slot =
1476 &rmap->slots[surface_count + i];
1477 const struct intel_sampler *sampler;
1478
1479 switch (slot->path_len) {
1480 case 0:
1481 sampler = NULL;
1482 break;
1483 case INTEL_PIPELINE_RMAP_SLOT_RT:
1484 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1485 assert(!"unexpected rmap slot type");
1486 sampler = NULL;
1487 break;
1488 case 1:
1489 {
1490 const struct intel_dset *dset = cmd->bind.dset.graphics;
1491 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1492 const struct intel_dset_slot *dset_slot =
1493 &dset->slots[slot_offset + slot->u.index];
1494
1495 switch (dset_slot->type) {
1496 case INTEL_DSET_SLOT_SAMPLER:
1497 sampler = dset_slot->u.sampler;
1498 break;
1499 default:
1500 assert(!"unexpected dset slot type");
1501 sampler = NULL;
1502 break;
1503 }
1504 }
1505 break;
1506 default:
1507 assert(!"nested descriptor set unsupported");
1508 sampler = NULL;
1509 break;
1510 }
1511
1512 if (sampler) {
1513 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1514
1515 sampler_dw[0] = sampler->cmd[0];
1516 sampler_dw[1] = sampler->cmd[1];
1517 sampler_dw[2] = border_offset;
1518 sampler_dw[3] = sampler->cmd[2];
1519 } else {
1520 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1521 sampler_dw[1] = 0;
1522 sampler_dw[2] = 0;
1523 sampler_dw[3] = 0;
1524 }
1525
1526 border_offset += border_stride * 4;
1527 border_dw += border_stride;
1528 sampler_dw += 4;
1529 }
1530
Chia-I Wu625105f2014-10-13 15:35:29 +08001531 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001532}
1533
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001534static uint32_t emit_binding_table(struct intel_cmd *cmd,
1535 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001536{
Chia-I Wu72292b72014-09-09 10:48:33 +08001537 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001538 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001539
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001540 CMD_ASSERT(cmd, 6, 7.5);
1541
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001542 surface_count = (rmap) ?
1543 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1544 if (!surface_count)
1545 return 0;
1546
Chia-I Wu42a56202014-08-23 16:47:48 +08001547 assert(surface_count <= ARRAY_SIZE(binding_table));
1548
1549 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001550 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001551
1552 switch (slot->path_len) {
1553 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001554 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001555 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001556 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001557 {
1558 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1559
Chia-I Wu00b51a82014-09-09 12:07:37 +08001560 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001561 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1562 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001563
Chia-I Wu72292b72014-09-09 10:48:33 +08001564 cmd_reserve_reloc(cmd, 1);
1565 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1566 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001567 }
1568 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001569 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001570 {
1571 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001572 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001573
Chia-I Wu00b51a82014-09-09 12:07:37 +08001574 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001575 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1576 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001577
Chia-I Wu72292b72014-09-09 10:48:33 +08001578 cmd_reserve_reloc(cmd, 1);
1579 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1580 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001581 }
1582 break;
1583 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001584 {
1585 const struct intel_dset *dset = cmd->bind.dset.graphics;
1586 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1587 const struct intel_dset_slot *dset_slot =
1588 &dset->slots[slot_offset + slot->u.index];
1589
1590 switch (dset_slot->type) {
1591 case INTEL_DSET_SLOT_IMG_VIEW:
1592 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1593 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1594 dset_slot->u.img_view->cmd_len,
1595 dset_slot->u.img_view->cmd);
1596
1597 cmd_reserve_reloc(cmd, 1);
1598 cmd_surface_reloc(cmd, offset, 1,
1599 dset_slot->u.img_view->img->obj.mem->bo,
1600 dset_slot->u.img_view->cmd[1], 0);
1601 break;
1602 case INTEL_DSET_SLOT_MEM_VIEW:
1603 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1604 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1605 dset_slot->u.mem_view.cmd_len,
1606 dset_slot->u.mem_view.cmd);
1607
1608 cmd_reserve_reloc(cmd, 1);
1609 cmd_surface_reloc(cmd, offset, 1,
1610 dset_slot->u.mem_view.mem->bo,
1611 dset_slot->u.mem_view.cmd[1], 0);
1612 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001613 case INTEL_DSET_SLOT_SAMPLER:
1614 assert(0 == cmd->bind.dset.graphics_offset);
1615
1616 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1617 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1618 16, dset_slot->u.sampler->cmd);
1619 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001620 default:
1621 assert(!"unexpected dset slot type");
1622 break;
1623 }
1624 }
1625 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001626 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001627 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001628 break;
1629 }
1630
Chia-I Wu72292b72014-09-09 10:48:33 +08001631 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001632 }
1633
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001634 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001635 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001636 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001637}
1638
Chia-I Wu1d125092014-10-08 08:49:38 +08001639static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1640{
1641 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1642 const struct intel_pipeline_rmap *rmap = pipeline->vs.rmap;
1643 const struct intel_dset *dset = cmd->bind.dset.graphics;
1644 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1645 uint32_t *dw;
1646 XGL_UINT pos, i;
1647
1648 CMD_ASSERT(cmd, 6, 7.5);
1649
1650 if (!pipeline->vb_count)
1651 return;
1652
1653 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1654
1655 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1656 dw++;
1657 pos++;
1658
1659 for (i = 0; i < pipeline->vb_count; i++) {
1660 const XGL_UINT vb_offset = rmap->rt_count + rmap->resource_count +
1661 rmap->uav_count + rmap->sampler_count;
1662 const struct intel_pipeline_rmap_slot *slot = (i < rmap->vb_count) ?
1663 &rmap->slots[vb_offset + i] : NULL;
1664 struct intel_mem_view *view = NULL;
1665
1666 if (slot) {
1667 switch (slot->path_len) {
1668 case 1:
1669 view = (dset->slots[slot->u.index].type ==
1670 INTEL_DSET_SLOT_MEM_VIEW) ?
1671 &dset->slots[slot->u.index].u.mem_view : NULL;
1672 break;
1673 default:
1674 break;
1675 }
1676 }
1677
1678 assert(pipeline->vb[i].strideInBytes <= 2048);
1679
1680 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1681 pipeline->vb[i].strideInBytes;
1682
1683 if (cmd_gen(cmd) >= INTEL_GEN(7))
1684 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1685
1686 switch (pipeline->vb[i].stepRate) {
1687 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1688 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1689 dw[3] = 0;
1690 break;
1691 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1692 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1693 dw[3] = 1;
1694 break;
1695 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1696 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1697 dw[3] = 0;
1698 break;
1699 default:
1700 assert(!"unknown step rate");
1701 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1702 dw[3] = 0;
1703 break;
1704 }
1705
1706 if (view) {
1707 const uint32_t begin = view->cmd[1];
1708 const uint32_t end = view->mem->size - 1;
1709
1710 cmd_reserve_reloc(cmd, 2);
1711 cmd_batch_reloc(cmd, pos + 1, view->mem->bo, begin, 0);
1712 cmd_batch_reloc(cmd, pos + 2, view->mem->bo, end, 0);
1713 } else {
1714 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1715 dw[1] = 0;
1716 dw[2] = 0;
1717 }
1718
1719 dw += 4;
1720 pos += 4;
1721 }
1722}
1723
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001724static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1725{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001726 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1727 const struct intel_pipeline_shader *vs = &pipeline->vs;
1728 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001729 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001730 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001731 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001732
1733 CMD_ASSERT(cmd, 6, 7.5);
1734
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001735 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001736 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1737 *
1738 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1739 * 128-bit vertex elements to be passed into the payload for each
1740 * vertex."
1741 *
1742 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1743 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001744 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001745 vue_read_len = (vs->in_count + 1) / 2;
1746 if (!vue_read_len)
1747 vue_read_len = 1;
1748
1749 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1750 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1751
1752 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1753 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1754 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001755
1756 dw5 = GEN6_VS_DW5_STATISTICS |
1757 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001758
1759 switch (cmd_gen(cmd)) {
1760 case INTEL_GEN(7.5):
1761 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1762 break;
1763 case INTEL_GEN(7):
1764 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1765 break;
1766 case INTEL_GEN(6):
1767 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1768 break;
1769 default:
1770 max_threads = 1;
1771 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001772 }
1773
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001774 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1775 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1776 else
1777 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1778
Chia-I Wube0a3d92014-09-02 13:20:59 +08001779 if (pipeline->disable_vs_cache)
1780 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1781
Chia-I Wu72292b72014-09-09 10:48:33 +08001782 cmd_batch_pointer(cmd, cmd_len, &dw);
1783 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001784 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001785 dw[2] = dw2;
1786 dw[3] = 0; /* scratch */
1787 dw[4] = dw4;
1788 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001789}
1790
Chia-I Wu625105f2014-10-13 15:35:29 +08001791static void emit_shader_resources(struct intel_cmd *cmd)
1792{
1793 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001794 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001795
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001796 binding_tables[0] = emit_binding_table(cmd,
1797 cmd->bind.pipeline.graphics->vs.rmap);
1798 binding_tables[1] = emit_binding_table(cmd,
1799 cmd->bind.pipeline.graphics->tcs.rmap);
1800 binding_tables[2] = emit_binding_table(cmd,
1801 cmd->bind.pipeline.graphics->tes.rmap);
1802 binding_tables[3] = emit_binding_table(cmd,
1803 cmd->bind.pipeline.graphics->gs.rmap);
1804 binding_tables[4] = emit_binding_table(cmd,
1805 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001806
1807 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1808 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1809 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1810 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1811 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1812
1813 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1814 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001815 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1816 binding_tables[0]);
1817 gen7_3dstate_pointer(cmd,
1818 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1819 binding_tables[1]);
1820 gen7_3dstate_pointer(cmd,
1821 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1822 binding_tables[2]);
1823 gen7_3dstate_pointer(cmd,
1824 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1825 binding_tables[3]);
1826 gen7_3dstate_pointer(cmd,
1827 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1828 binding_tables[4]);
1829
1830 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001831 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1832 samplers[0]);
1833 gen7_3dstate_pointer(cmd,
1834 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1835 samplers[1]);
1836 gen7_3dstate_pointer(cmd,
1837 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1838 samplers[2]);
1839 gen7_3dstate_pointer(cmd,
1840 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1841 samplers[3]);
1842 gen7_3dstate_pointer(cmd,
1843 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1844 samplers[4]);
1845 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001846 assert(!binding_tables[1] && !binding_tables[2]);
1847 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1848 binding_tables[0], binding_tables[3], binding_tables[4]);
1849
Chia-I Wu625105f2014-10-13 15:35:29 +08001850 assert(!samplers[1] && !samplers[2]);
1851 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1852 samplers[0], samplers[3], samplers[4]);
1853 }
1854}
1855
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001856static void emit_rt(struct intel_cmd *cmd)
1857{
1858 cmd_wa_gen6_pre_depth_stall_write(cmd);
1859 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1860 cmd->bind.att.height);
1861}
1862
1863static void emit_ds(struct intel_cmd *cmd)
1864{
1865 const struct intel_ds_view *ds = cmd->bind.att.ds;
1866
1867 if (!ds) {
1868 /* all zeros */
1869 static const struct intel_ds_view null_ds;
1870 ds = &null_ds;
1871 }
1872
1873 cmd_wa_gen6_pre_ds_flush(cmd);
1874 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1875 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1876 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1877
1878 if (cmd_gen(cmd) >= INTEL_GEN(7))
1879 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1880 else
1881 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1882}
1883
Chia-I Wua57761b2014-10-14 14:27:44 +08001884static uint32_t emit_shader(struct intel_cmd *cmd,
1885 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001886{
Chia-I Wua57761b2014-10-14 14:27:44 +08001887 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1888 uint32_t offset;
1889 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001890
Chia-I Wua57761b2014-10-14 14:27:44 +08001891 /* see if the shader is already in the cache */
1892 for (i = 0; i < cache->used; i++) {
1893 if (cache->entries[i].shader == (const void *) shader)
1894 return cache->entries[i].kernel_offset;
1895 }
1896
1897 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1898
1899 /* grow the cache if full */
1900 if (cache->used >= cache->count) {
1901 const XGL_UINT count = cache->count + 16;
1902 void *entries;
1903
1904 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1905 XGL_SYSTEM_ALLOC_INTERNAL);
1906 if (entries) {
1907 if (cache->entries) {
1908 memcpy(entries, cache->entries,
1909 sizeof(cache->entries[0]) * cache->used);
1910 icd_free(cache->entries);
1911 }
1912
1913 cache->entries = entries;
1914 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001915 }
1916 }
1917
Chia-I Wua57761b2014-10-14 14:27:44 +08001918 /* add the shader to the cache */
1919 if (cache->used < cache->count) {
1920 cache->entries[cache->used].shader = (const void *) shader;
1921 cache->entries[cache->used].kernel_offset = offset;
1922 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001923 }
1924
Chia-I Wua57761b2014-10-14 14:27:44 +08001925 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001926}
1927
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001928static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001929{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001930 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001931
Chia-I Wu8370b402014-08-29 12:28:37 +08001932 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1933 cmd_wa_gen6_pre_depth_stall_write(cmd);
1934 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1935 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1936 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1937 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001938
1939 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001940 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001941 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001942
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001943 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001944 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001945 }
1946 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001947 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001948 }
1949 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001950 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1951 }
1952 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1953 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1954 }
1955 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1956 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001957 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001958
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001959 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1960 gen7_3DSTATE_GS(cmd);
1961 } else {
1962 gen6_3DSTATE_GS(cmd);
1963 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001964
Chia-I Wu8370b402014-08-29 12:28:37 +08001965 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1966 cmd_wa_gen7_post_command_cs_stall(cmd);
1967 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1968 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001969}
1970
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001971static void emit_bounded_states(struct intel_cmd *cmd)
1972{
1973 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1974
1975 emit_graphics_pipeline(cmd);
1976
1977 emit_rt(cmd);
1978 emit_ds(cmd);
1979
1980 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1981 gen7_cc_states(cmd);
1982 gen7_viewport_states(cmd);
1983
1984 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1985 &cmd->bind.pipeline.graphics->vs);
1986 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1987 &cmd->bind.pipeline.graphics->fs);
1988
1989 gen6_3DSTATE_CLIP(cmd);
1990 gen7_3DSTATE_SF(cmd);
1991 gen7_3DSTATE_SBE(cmd);
1992 gen7_3DSTATE_WM(cmd);
1993 gen7_3DSTATE_PS(cmd);
1994 } else {
1995 gen6_cc_states(cmd);
1996 gen6_viewport_states(cmd);
1997
1998 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1999 &cmd->bind.pipeline.graphics->vs);
2000 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2001 &cmd->bind.pipeline.graphics->fs);
2002
2003 gen6_3DSTATE_CLIP(cmd);
2004 gen6_3DSTATE_SF(cmd);
2005 gen6_3DSTATE_WM(cmd);
2006 }
2007
2008 emit_shader_resources(cmd);
2009
2010 cmd_wa_gen6_pre_depth_stall_write(cmd);
2011 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2012
2013 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2014 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2015
2016 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2017 gen6_3DSTATE_VS(cmd);
2018}
2019
Chia-I Wu6032b892014-10-17 14:47:18 +08002020static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2021{
2022 const struct intel_cmd_meta *meta = cmd->bind.meta;
2023 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2024
2025 CMD_ASSERT(cmd, 6, 7.5);
2026
2027 blend_offset = 0;
2028 ds_offset = 0;
2029 cc_offset = 0;
2030 cc_vp_offset = 0;
2031
2032 if (meta->dst.valid) {
2033 /* BLEND_STATE */
2034 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
2035 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2036 dw[0] = 0;
2037 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2038 }
2039
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002040 if (meta->ds.state) {
2041 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002042
2043 /* DEPTH_STENCIL_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002044 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002045
2046 /* COLOR_CALC_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002047 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2048 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002049
2050 /* CC_VIEWPORT */
2051 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
2052 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002053 dw[0] = u_fui(0.0f);
2054 dw[1] = u_fui(1.0f);
Chia-I Wua667c2b2014-10-28 11:40:29 +08002055 } else {
2056 /* DEPTH_STENCIL_STATE */
2057 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2058 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4,
2059 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2060 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
Chia-I Wu6032b892014-10-17 14:47:18 +08002061 }
2062
2063 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2064 gen7_3dstate_pointer(cmd,
2065 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2066 blend_offset);
2067 gen7_3dstate_pointer(cmd,
2068 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2069 ds_offset);
2070 gen7_3dstate_pointer(cmd,
2071 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2072
2073 gen7_3dstate_pointer(cmd,
2074 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2075 cc_vp_offset);
2076 } else {
2077 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002078 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002079
2080 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2081 cmd_batch_pointer(cmd, 4, &dw);
2082 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2083 GEN6_PTR_VP_DW0_CC_CHANGED;
2084 dw[1] = 0;
2085 dw[2] = 0;
2086 dw[3] = cc_vp_offset;
2087 }
2088}
2089
2090static void gen6_meta_surface_states(struct intel_cmd *cmd)
2091{
2092 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002093 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002094 uint32_t offset;
2095
2096 CMD_ASSERT(cmd, 6, 7.5);
2097
Chia-I Wu005c47c2014-10-22 13:49:13 +08002098 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002099 if (meta->src.valid) {
2100 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2101 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2102 meta->src.surface_len, meta->src.surface);
2103
2104 cmd_reserve_reloc(cmd, 1);
2105 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2106 cmd_surface_reloc_writer(cmd, offset, 1,
2107 meta->src.reloc_target, meta->src.reloc_offset);
2108 } else {
2109 cmd_surface_reloc(cmd, offset, 1,
2110 (struct intel_bo *) meta->src.reloc_target,
2111 meta->src.reloc_offset, meta->src.reloc_flags);
2112 }
2113
Chia-I Wu005c47c2014-10-22 13:49:13 +08002114 binding_table[0] = offset;
2115 }
2116 if (meta->dst.valid) {
2117 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2118 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2119 meta->dst.surface_len, meta->dst.surface);
2120
2121 cmd_reserve_reloc(cmd, 1);
2122 cmd_surface_reloc(cmd, offset, 1,
2123 (struct intel_bo *) meta->dst.reloc_target,
2124 meta->dst.reloc_offset, meta->dst.reloc_flags);
2125
2126 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002127 }
2128
2129 /* BINDING_TABLE */
2130 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
2131 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002132 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002133
2134 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2135 gen7_3dstate_pointer(cmd,
2136 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2137 offset);
2138 } else {
2139 /* 3DSTATE_BINDING_TABLE_POINTERS */
2140 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
2141 }
2142}
2143
2144static void gen6_meta_urb(struct intel_cmd *cmd)
2145{
2146 uint32_t *dw;
2147
2148 CMD_ASSERT(cmd, 6, 6);
2149
2150 /* 3DSTATE_URB */
2151 cmd_batch_pointer(cmd, 3, &dw);
2152 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
2153 dw[1] = 128 << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
2154 dw[2] = 0;
2155}
2156
2157static void gen7_meta_urb(struct intel_cmd *cmd)
2158{
2159 uint32_t *dw;
2160
2161 CMD_ASSERT(cmd, 7, 7.5);
2162
2163 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2164 cmd_batch_pointer(cmd, 10, &dw);
2165
2166 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
2167 dw[1] = 0;
2168 dw += 2;
2169
2170 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2171 dw[1] = 0;
2172 dw += 2;
2173
2174 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2175 dw[1] = 0;
2176 dw += 2;
2177
2178 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2179 dw[1] = 0;
2180 dw += 2;
2181
2182 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2183 dw[1] = 1;
2184
2185 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2186
2187 /* 3DSTATE_URB_x */
2188 cmd_batch_pointer(cmd, 8, &dw);
2189
2190 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2191 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
2192 512;
2193 dw += 2;
2194
2195 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2196 dw[1] = 0;
2197 dw += 2;
2198
2199 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2200 dw[1] = 0;
2201 dw += 2;
2202
2203 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2204 dw[1] = 0;
2205 dw += 2;
2206}
2207
2208static void gen6_meta_vf(struct intel_cmd *cmd)
2209{
2210 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002211 uint32_t vb_start, vb_end, vb_stride;
2212 int ve_format, ve_z_source;
2213 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002214 XGL_UINT pos;
2215
2216 CMD_ASSERT(cmd, 6, 7.5);
2217
2218 /* write vertices */
Chia-I Wu3adf7212014-10-24 15:34:07 +08002219 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2220 XGL_FLOAT vertices[3][3];
2221
2222 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2223 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2224 vertices[0][2] = u_uif(meta->clear_val[0]);
2225 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2226 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2227 vertices[1][2] = u_uif(meta->clear_val[0]);
2228 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2229 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2230 vertices[2][2] = u_uif(meta->clear_val[0]);
2231
2232 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2233 sizeof(vertices) / 4, (const uint32_t *) vertices);
2234
2235 vb_end = vb_start + sizeof(vertices) - 1;
2236 vb_stride = sizeof(vertices[0]);
2237 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2238 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2239 } else {
2240 XGL_UINT vertices[3][2];
2241
2242 vertices[0][0] = meta->dst.x + meta->width;
2243 vertices[0][1] = meta->dst.y + meta->height;
2244 vertices[1][0] = meta->dst.x;
2245 vertices[1][1] = meta->dst.y + meta->height;
2246 vertices[2][0] = meta->dst.x;
2247 vertices[2][1] = meta->dst.y;
2248
2249 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2250 sizeof(vertices) / 4, (const uint32_t *) vertices);
2251
2252 vb_end = vb_start + sizeof(vertices) - 1;
2253 vb_stride = sizeof(vertices[0]);
2254 ve_z_source = GEN6_VFCOMP_STORE_0;
2255 ve_format = GEN6_FORMAT_R32G32_USCALED;
2256 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002257
2258 /* 3DSTATE_VERTEX_BUFFERS */
2259 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002260
Chia-I Wu6032b892014-10-17 14:47:18 +08002261 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002262 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002263 if (cmd_gen(cmd) >= INTEL_GEN(7))
2264 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2265
2266 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002267 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2268 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002269
2270 dw[4] = 0;
2271
2272 /* 3DSTATE_VERTEX_ELEMENTS */
2273 cmd_batch_pointer(cmd, 5, &dw);
2274 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
2275 dw[1] = GEN6_VE_STATE_DW0_VALID,
2276 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2277 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2278 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2279 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2280 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002281 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002282 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2283 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002284 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002285 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2286}
2287
2288static void gen6_meta_disabled(struct intel_cmd *cmd)
2289{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002290 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002291 uint32_t *dw;
2292
2293 CMD_ASSERT(cmd, 6, 6);
2294
2295 /* 3DSTATE_CONSTANT_VS */
2296 cmd_batch_pointer(cmd, 5, &dw);
2297 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2);
2298 dw[1] = 0;
2299 dw[2] = 0;
2300 dw[3] = 0;
2301 dw[4] = 0;
2302
2303 /* 3DSTATE_VS */
2304 cmd_batch_pointer(cmd, 6, &dw);
2305 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2306 dw[1] = 0;
2307 dw[2] = 0;
2308 dw[3] = 0;
2309 dw[4] = 0;
2310 dw[5] = 0;
2311
2312 /* 3DSTATE_CONSTANT_GS */
2313 cmd_batch_pointer(cmd, 5, &dw);
2314 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2315 dw[1] = 0;
2316 dw[2] = 0;
2317 dw[3] = 0;
2318 dw[4] = 0;
2319
2320 /* 3DSTATE_GS */
2321 cmd_batch_pointer(cmd, 7, &dw);
2322 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2323 dw[1] = 0;
2324 dw[2] = 0;
2325 dw[3] = 0;
2326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2327 dw[5] = GEN6_GS_DW5_STATISTICS;
2328 dw[6] = 0;
2329
2330 /* 3DSTATE_CLIP */
2331 cmd_batch_pointer(cmd, 4, &dw);
2332 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2333 dw[1] = 0;
2334 dw[2] = 0;
2335 dw[3] = 0;
2336
2337 /* 3DSTATE_SF */
2338 cmd_batch_pointer(cmd, 20, &dw);
2339 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2340 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2341 memset(&dw[2], 0, 18 * sizeof(*dw));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002342
2343 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2344 /* 3DSTATE_CONSTANT_PS */
2345 cmd_batch_pointer(cmd, 5, &dw);
2346 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2347 dw[1] = 0;
2348 dw[2] = 0;
2349 dw[3] = 0;
2350 dw[4] = 0;
2351
2352 /* 3DSTATE_WM */
2353 cmd_batch_pointer(cmd, 9, &dw);
2354 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2355 dw[1] = 0;
2356 dw[2] = 0;
2357 dw[3] = 0;
2358 dw[4] = 0;
2359 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
2360 dw[6] = 0;
2361 dw[7] = 0;
2362 dw[8] = 0;
2363 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002364}
2365
2366static void gen7_meta_disabled(struct intel_cmd *cmd)
2367{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002368 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002369 uint32_t *dw;
2370
2371 CMD_ASSERT(cmd, 7, 7.5);
2372
2373 /* 3DSTATE_CONSTANT_VS */
2374 cmd_batch_pointer(cmd, 7, &dw);
2375 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2376 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2377
2378 /* 3DSTATE_VS */
2379 cmd_batch_pointer(cmd, 6, &dw);
2380 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2381 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2382
2383 /* 3DSTATE_CONSTANT_HS */
2384 cmd_batch_pointer(cmd, 7, &dw);
2385 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2386 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2387
2388 /* 3DSTATE_HS */
2389 cmd_batch_pointer(cmd, 7, &dw);
2390 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2391 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2392
2393 /* 3DSTATE_TE */
2394 cmd_batch_pointer(cmd, 4, &dw);
2395 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2396 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2397
2398 /* 3DSTATE_CONSTANT_DS */
2399 cmd_batch_pointer(cmd, 7, &dw);
2400 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2401 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2402
2403 /* 3DSTATE_DS */
2404 cmd_batch_pointer(cmd, 6, &dw);
2405 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2406 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2407
2408 /* 3DSTATE_CONSTANT_GS */
2409 cmd_batch_pointer(cmd, 7, &dw);
2410 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2411 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2412
2413 /* 3DSTATE_GS */
2414 cmd_batch_pointer(cmd, 7, &dw);
2415 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2416 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2417
2418 /* 3DSTATE_STREAMOUT */
2419 cmd_batch_pointer(cmd, 3, &dw);
2420 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2421 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2422
2423 /* 3DSTATE_CLIP */
2424 cmd_batch_pointer(cmd, 4, &dw);
2425 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2426 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2427
2428 /* 3DSTATE_SF */
2429 cmd_batch_pointer(cmd, 7, &dw);
2430 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2431 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2432
2433 /* 3DSTATE_SBE */
2434 cmd_batch_pointer(cmd, 14, &dw);
2435 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2436 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2437 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002438
2439 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2440 /* 3DSTATE_WM */
2441 cmd_batch_pointer(cmd, 3, &dw);
2442 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2443 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2444
2445 /* 3DSTATE_CONSTANT_GS */
2446 cmd_batch_pointer(cmd, 7, &dw);
2447 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2448 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2449
2450 /* 3DSTATE_PS */
2451 cmd_batch_pointer(cmd, 8, &dw);
2452 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2453 dw[1] = 0;
2454 dw[2] = 0;
2455 dw[3] = 0;
2456 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
2457 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2458 dw[5] = 0;
2459 dw[6] = 0;
2460 dw[7] = 0;
2461 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002462}
2463
2464static void gen6_meta_wm(struct intel_cmd *cmd)
2465{
2466 const struct intel_cmd_meta *meta = cmd->bind.meta;
2467 uint32_t *dw;
2468
2469 CMD_ASSERT(cmd, 6, 7.5);
2470
2471 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2472
2473 /* 3DSTATE_MULTISAMPLE */
2474 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2475 cmd_batch_pointer(cmd, 4, &dw);
2476 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2477 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2478 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2479 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2480 dw[2] = 0;
2481 dw[3] = 0;
2482 } else {
2483 cmd_batch_pointer(cmd, 3, &dw);
2484 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2485 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2486 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2487 dw[2] = 0;
2488 }
2489
2490 /* 3DSTATE_SAMPLE_MASK */
2491 cmd_batch_pointer(cmd, 2, &dw);
2492 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2493 dw[1] = (1 << meta->samples) - 1;
2494
2495 /* 3DSTATE_DRAWING_RECTANGLE */
2496 cmd_batch_pointer(cmd, 4, &dw);
2497 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2498 dw[1] = meta->dst.y << 16 | meta->dst.x;
2499 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2500 (meta->dst.x + meta->width - 1);
2501 dw[3] = 0;
2502}
2503
2504static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2505{
2506 const struct intel_cmd_meta *meta = cmd->bind.meta;
2507 XGL_UINT offset_x, offset_y;
2508 /* one GPR */
2509 XGL_UINT consts[8];
2510 XGL_UINT const_count;
2511
2512 CMD_ASSERT(cmd, 6, 7.5);
2513
2514 /* underflow is fine here */
2515 offset_x = meta->src.x - meta->dst.x;
2516 offset_y = meta->src.y - meta->dst.y;
2517
2518 switch (meta->shader_id) {
2519 case INTEL_DEV_META_FS_COPY_MEM:
2520 case INTEL_DEV_META_FS_COPY_1D:
2521 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2522 case INTEL_DEV_META_FS_COPY_2D:
2523 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2524 case INTEL_DEV_META_FS_COPY_2D_MS:
2525 consts[0] = offset_x;
2526 consts[1] = offset_y;
2527 consts[2] = meta->src.layer;
2528 consts[3] = meta->src.lod;
2529 const_count = 4;
2530 break;
2531 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2532 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2533 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2534 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2535 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2536 consts[0] = offset_x;
2537 consts[1] = offset_y;
2538 consts[2] = meta->src.layer;
2539 consts[3] = meta->src.lod;
2540 consts[4] = meta->src.x;
2541 consts[5] = meta->width;
2542 const_count = 6;
2543 break;
2544 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2545 consts[0] = offset_x;
2546 consts[1] = offset_y;
2547 consts[2] = meta->width;
2548 const_count = 3;
2549 break;
2550 case INTEL_DEV_META_FS_CLEAR_COLOR:
2551 consts[0] = meta->clear_val[0];
2552 consts[1] = meta->clear_val[1];
2553 consts[2] = meta->clear_val[2];
2554 consts[3] = meta->clear_val[3];
2555 const_count = 4;
2556 break;
2557 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2558 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002559 consts[1] = meta->clear_val[1];
2560 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002561 break;
2562 case INTEL_DEV_META_FS_RESOLVE_2X:
2563 case INTEL_DEV_META_FS_RESOLVE_4X:
2564 case INTEL_DEV_META_FS_RESOLVE_8X:
2565 case INTEL_DEV_META_FS_RESOLVE_16X:
2566 consts[0] = offset_x;
2567 consts[1] = offset_y;
2568 const_count = 2;
2569 break;
2570 default:
2571 assert(!"unknown meta shader id");
2572 const_count = 0;
2573 break;
2574 }
2575
2576 /* this can be skipped but it makes state dumping prettier */
2577 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2578
2579 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2580}
2581
2582static void gen6_meta_ps(struct intel_cmd *cmd)
2583{
2584 const struct intel_cmd_meta *meta = cmd->bind.meta;
2585 const struct intel_pipeline_shader *sh =
2586 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2587 uint32_t offset, *dw;
2588
2589 CMD_ASSERT(cmd, 6, 6);
2590
Chia-I Wu3adf7212014-10-24 15:34:07 +08002591 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2592 return;
2593 /* a normal color write */
2594 assert(meta->dst.valid && !sh->uses);
2595
Chia-I Wu6032b892014-10-17 14:47:18 +08002596 /* 3DSTATE_CONSTANT_PS */
2597 offset = gen6_meta_ps_constants(cmd);
2598 cmd_batch_pointer(cmd, 5, &dw);
2599 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2600 GEN6_PCB_ANY_DW0_PCB0_VALID;
2601 dw[1] = offset;
2602 dw[2] = 0;
2603 dw[3] = 0;
2604 dw[4] = 0;
2605
2606 /* 3DSTATE_WM */
2607 offset = emit_shader(cmd, sh);
2608 cmd_batch_pointer(cmd, 9, &dw);
2609 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2610 dw[1] = offset;
2611 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2612 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2613 dw[3] = 0;
2614 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
2615 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
2616 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002617 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2618
Chia-I Wu6032b892014-10-17 14:47:18 +08002619 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2620 GEN6_WM_DW6_POSOFFSET_NONE |
2621 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2622 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2623 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2624 if (meta->samples > 1) {
2625 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2626 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2627 } else {
2628 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2629 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2630 }
2631 dw[7] = 0;
2632 dw[8] = 0;
2633}
2634
2635static void gen7_meta_ps(struct intel_cmd *cmd)
2636{
2637 const struct intel_cmd_meta *meta = cmd->bind.meta;
2638 const struct intel_pipeline_shader *sh =
2639 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2640 uint32_t offset, *dw;
2641
2642 CMD_ASSERT(cmd, 7, 7.5);
2643
Chia-I Wu3adf7212014-10-24 15:34:07 +08002644 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2645 return;
2646 /* a normal color write */
2647 assert(meta->dst.valid && !sh->uses);
2648
Chia-I Wu6032b892014-10-17 14:47:18 +08002649 /* 3DSTATE_WM */
2650 cmd_batch_pointer(cmd, 3, &dw);
2651 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2652 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2653 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2654 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2655 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2656 dw[2] = 0;
2657
2658 /* 3DSTATE_CONSTANT_PS */
2659 offset = gen6_meta_ps_constants(cmd);
2660 cmd_batch_pointer(cmd, 7, &dw);
2661 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2662 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2663 dw[2] = 0;
2664 dw[3] = offset;
2665 dw[4] = 0;
2666 dw[5] = 0;
2667 dw[6] = 0;
2668
2669 /* 3DSTATE_PS */
2670 offset = emit_shader(cmd, sh);
2671 cmd_batch_pointer(cmd, 8, &dw);
2672 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2673 dw[1] = offset;
2674 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2675 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2676 dw[3] = 0;
2677
2678 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2679 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002680 GEN7_PS_DW4_16_PIXEL_DISPATCH |
Chia-I Wu6032b892014-10-17 14:47:18 +08002681 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2682 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
2683 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
2684
2685 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2686 dw[6] = 0;
2687 dw[7] = 0;
2688}
2689
2690static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2691{
2692 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002693 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002694
2695 CMD_ASSERT(cmd, 6, 7.5);
2696
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002697 if (!ds) {
2698 /* all zeros */
2699 static const struct intel_ds_view null_ds;
2700 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002701 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002702
2703 cmd_wa_gen6_pre_ds_flush(cmd);
2704 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2705 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2706 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2707
2708 if (cmd_gen(cmd) >= INTEL_GEN(7))
2709 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2710 else
2711 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002712}
2713
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002714static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2715 const struct intel_pipeline *pipeline)
2716{
2717 cmd->bind.pipeline.graphics = pipeline;
2718}
2719
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002720static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2721 const struct intel_pipeline *pipeline)
2722{
2723 cmd->bind.pipeline.compute = pipeline;
2724}
2725
2726static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2727 const struct intel_pipeline_delta *delta)
2728{
2729 cmd->bind.pipeline.graphics_delta = delta;
2730}
2731
2732static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2733 const struct intel_pipeline_delta *delta)
2734{
2735 cmd->bind.pipeline.compute_delta = delta;
2736}
2737
2738static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2739 const struct intel_dset *dset,
2740 XGL_UINT slot_offset)
2741{
2742 cmd->bind.dset.graphics = dset;
2743 cmd->bind.dset.graphics_offset = slot_offset;
2744}
2745
2746static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2747 const struct intel_dset *dset,
2748 XGL_UINT slot_offset)
2749{
2750 cmd->bind.dset.compute = dset;
2751 cmd->bind.dset.compute_offset = slot_offset;
2752}
2753
2754static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2755 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2756{
2757 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2758}
2759
2760static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2761 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2762{
2763 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2764}
2765
2766static void cmd_bind_index_data(struct intel_cmd *cmd,
2767 const struct intel_mem *mem,
2768 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2769{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002770 cmd->bind.index.mem = mem;
2771 cmd->bind.index.offset = offset;
2772 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002773}
2774
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002775static void cmd_bind_attachments(struct intel_cmd *cmd,
2776 XGL_UINT rt_count,
2777 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2778 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002779{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002780 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002781 XGL_UINT i;
2782
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002783 for (i = 0; i < rt_count; i++) {
2784 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002785 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002786 const struct intel_layout *layout = &rt->img->layout;
2787
2788 if (i == 0) {
2789 width = layout->width0;
2790 height = layout->height0;
2791 } else {
2792 if (width > layout->width0)
2793 width = layout->width0;
2794 if (height > layout->height0)
2795 height = layout->height0;
2796 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002797
2798 cmd->bind.att.rt[i] = rt;
2799 }
2800
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002801 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002802
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002803 if (ds_info) {
2804 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002805
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002806 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2807 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002808
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002809 if (width > layout->width0)
2810 width = layout->width0;
2811 if (height > layout->height0)
2812 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002813 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002814 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002815 }
2816
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002817 cmd->bind.att.width = width;
2818 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002819}
2820
2821static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2822 const struct intel_viewport_state *state)
2823{
2824 cmd->bind.state.viewport = state;
2825}
2826
2827static void cmd_bind_raster_state(struct intel_cmd *cmd,
2828 const struct intel_raster_state *state)
2829{
2830 cmd->bind.state.raster = state;
2831}
2832
2833static void cmd_bind_ds_state(struct intel_cmd *cmd,
2834 const struct intel_ds_state *state)
2835{
2836 cmd->bind.state.ds = state;
2837}
2838
2839static void cmd_bind_blend_state(struct intel_cmd *cmd,
2840 const struct intel_blend_state *state)
2841{
2842 cmd->bind.state.blend = state;
2843}
2844
2845static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2846 const struct intel_msaa_state *state)
2847{
2848 cmd->bind.state.msaa = state;
2849}
2850
2851static void cmd_draw(struct intel_cmd *cmd,
2852 XGL_UINT vertex_start,
2853 XGL_UINT vertex_count,
2854 XGL_UINT instance_start,
2855 XGL_UINT instance_count,
2856 bool indexed,
2857 XGL_UINT vertex_base)
2858{
2859 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2860
2861 emit_bounded_states(cmd);
2862
2863 if (indexed) {
2864 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2865 cmd->result = XGL_ERROR_UNKNOWN;
2866
2867 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2868 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2869 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002870 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2871 cmd->bind.index.offset, cmd->bind.index.type,
2872 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002873 } else {
2874 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2875 cmd->bind.index.offset, cmd->bind.index.type,
2876 p->primitive_restart);
2877 }
2878 } else {
2879 assert(!vertex_base);
2880 }
2881
2882 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2883 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2884 vertex_start, instance_count, instance_start, vertex_base);
2885 } else {
2886 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2887 vertex_start, instance_count, instance_start, vertex_base);
2888 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002889
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002890 if (intel_debug & INTEL_DEBUG_NOCACHE)
2891 cmd_batch_flush_all(cmd);
2892
Chia-I Wu707a29e2014-08-27 12:51:47 +08002893 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002894 /* need to re-emit all workarounds */
2895 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002896}
2897
Chia-I Wuc14d1562014-10-17 09:49:22 +08002898void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2899{
Chia-I Wu6032b892014-10-17 14:47:18 +08002900 cmd->bind.meta = meta;
2901
2902 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08002903 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002904
2905 gen6_meta_dynamic_states(cmd);
2906 gen6_meta_surface_states(cmd);
2907
2908 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2909 gen7_meta_urb(cmd);
2910 gen6_meta_vf(cmd);
2911 gen7_meta_disabled(cmd);
2912 gen6_meta_wm(cmd);
2913 gen7_meta_ps(cmd);
2914 gen6_meta_depth_buffer(cmd);
2915
2916 cmd_wa_gen7_post_command_cs_stall(cmd);
2917 cmd_wa_gen7_post_command_depth_stall(cmd);
2918
2919 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2920 } else {
2921 gen6_meta_urb(cmd);
2922 gen6_meta_vf(cmd);
2923 gen6_meta_disabled(cmd);
2924 gen6_meta_wm(cmd);
2925 gen6_meta_ps(cmd);
2926 gen6_meta_depth_buffer(cmd);
2927
2928 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2929 }
2930
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002931 if (intel_debug & INTEL_DEBUG_NOCACHE)
2932 cmd_batch_flush_all(cmd);
2933
Chia-I Wu6032b892014-10-17 14:47:18 +08002934 cmd->bind.draw_count++;
2935 /* need to re-emit all workarounds */
2936 cmd->bind.wa_flags = 0;
2937
2938 cmd->bind.meta = NULL;
Chia-I Wuc14d1562014-10-17 09:49:22 +08002939}
2940
Chia-I Wub2755562014-08-20 13:38:52 +08002941XGL_VOID XGLAPI intelCmdBindPipeline(
2942 XGL_CMD_BUFFER cmdBuffer,
2943 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2944 XGL_PIPELINE pipeline)
2945{
2946 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2947
2948 switch (pipelineBindPoint) {
2949 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002950 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002951 break;
2952 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002953 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002954 break;
2955 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002956 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002957 break;
2958 }
2959}
2960
2961XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2962 XGL_CMD_BUFFER cmdBuffer,
2963 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2964 XGL_PIPELINE_DELTA delta)
2965{
2966 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2967
2968 switch (pipelineBindPoint) {
2969 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002970 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002971 break;
2972 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002973 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002974 break;
2975 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002976 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002977 break;
2978 }
2979}
2980
2981XGL_VOID XGLAPI intelCmdBindStateObject(
2982 XGL_CMD_BUFFER cmdBuffer,
2983 XGL_STATE_BIND_POINT stateBindPoint,
2984 XGL_STATE_OBJECT state)
2985{
2986 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2987
2988 switch (stateBindPoint) {
2989 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002990 cmd_bind_viewport_state(cmd,
2991 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002992 break;
2993 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002994 cmd_bind_raster_state(cmd,
2995 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002996 break;
2997 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002998 cmd_bind_ds_state(cmd,
2999 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003000 break;
3001 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003002 cmd_bind_blend_state(cmd,
3003 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003004 break;
3005 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003006 cmd_bind_msaa_state(cmd,
3007 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003008 break;
3009 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003010 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003011 break;
3012 }
3013}
3014
3015XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3016 XGL_CMD_BUFFER cmdBuffer,
3017 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3018 XGL_UINT index,
3019 XGL_DESCRIPTOR_SET descriptorSet,
3020 XGL_UINT slotOffset)
3021{
3022 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3023 struct intel_dset *dset = intel_dset(descriptorSet);
3024
3025 assert(!index);
3026
3027 switch (pipelineBindPoint) {
3028 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003029 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003030 break;
3031 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003032 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003033 break;
3034 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003035 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003036 break;
3037 }
3038}
3039
3040XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3041 XGL_CMD_BUFFER cmdBuffer,
3042 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3043 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3044{
3045 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3046
3047 switch (pipelineBindPoint) {
3048 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003049 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003050 break;
3051 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003052 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003053 break;
3054 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003055 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003056 break;
3057 }
3058}
3059
3060XGL_VOID XGLAPI intelCmdBindIndexData(
3061 XGL_CMD_BUFFER cmdBuffer,
3062 XGL_GPU_MEMORY mem_,
3063 XGL_GPU_SIZE offset,
3064 XGL_INDEX_TYPE indexType)
3065{
3066 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3067 struct intel_mem *mem = intel_mem(mem_);
3068
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003069 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003070}
3071
3072XGL_VOID XGLAPI intelCmdBindAttachments(
3073 XGL_CMD_BUFFER cmdBuffer,
3074 XGL_UINT colorAttachmentCount,
3075 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3076 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3077{
3078 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003079
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003080 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3081 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003082}
3083
3084XGL_VOID XGLAPI intelCmdDraw(
3085 XGL_CMD_BUFFER cmdBuffer,
3086 XGL_UINT firstVertex,
3087 XGL_UINT vertexCount,
3088 XGL_UINT firstInstance,
3089 XGL_UINT instanceCount)
3090{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003091 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003092
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003093 cmd_draw(cmd, firstVertex, vertexCount,
3094 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003095}
3096
3097XGL_VOID XGLAPI intelCmdDrawIndexed(
3098 XGL_CMD_BUFFER cmdBuffer,
3099 XGL_UINT firstIndex,
3100 XGL_UINT indexCount,
3101 XGL_INT vertexOffset,
3102 XGL_UINT firstInstance,
3103 XGL_UINT instanceCount)
3104{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003105 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003106
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003107 cmd_draw(cmd, firstIndex, indexCount,
3108 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003109}
3110
3111XGL_VOID XGLAPI intelCmdDrawIndirect(
3112 XGL_CMD_BUFFER cmdBuffer,
3113 XGL_GPU_MEMORY mem,
3114 XGL_GPU_SIZE offset,
3115 XGL_UINT32 count,
3116 XGL_UINT32 stride)
3117{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003118 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3119
3120 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003121}
3122
3123XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3124 XGL_CMD_BUFFER cmdBuffer,
3125 XGL_GPU_MEMORY mem,
3126 XGL_GPU_SIZE offset,
3127 XGL_UINT32 count,
3128 XGL_UINT32 stride)
3129{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003130 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3131
3132 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003133}
3134
3135XGL_VOID XGLAPI intelCmdDispatch(
3136 XGL_CMD_BUFFER cmdBuffer,
3137 XGL_UINT x,
3138 XGL_UINT y,
3139 XGL_UINT z)
3140{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003141 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3142
3143 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003144}
3145
3146XGL_VOID XGLAPI intelCmdDispatchIndirect(
3147 XGL_CMD_BUFFER cmdBuffer,
3148 XGL_GPU_MEMORY mem,
3149 XGL_GPU_SIZE offset)
3150{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003151 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3152
3153 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003154}