blob: 74e70e3805cc6690142640c7a77b2477ba137bef [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wua4d1b392014-10-10 13:57:29 +080029#include <stdio.h> /* for printf */
Chia-I Wu9f039862014-08-20 15:39:56 +080030#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080031#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
40
Chia-I Wu59c097e2014-08-21 10:51:07 +080041static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080042 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080043 uint32_t vertex_count,
44 uint32_t vertex_start,
45 uint32_t instance_count,
46 uint32_t instance_start,
47 uint32_t vertex_base)
48{
49 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080050 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080051
52 CMD_ASSERT(cmd, 6, 6);
53
Chia-I Wu426072d2014-08-26 14:31:55 +080054 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080055 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080056 (cmd_len - 2);
57
58 if (indexed)
59 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
60
Chia-I Wu72292b72014-09-09 10:48:33 +080061 cmd_batch_pointer(cmd, cmd_len, &dw);
62 dw[0] = dw0;
63 dw[1] = vertex_count;
64 dw[2] = vertex_start;
65 dw[3] = instance_count;
66 dw[4] = instance_start;
67 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080068}
69
70static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080071 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080072 uint32_t vertex_count,
73 uint32_t vertex_start,
74 uint32_t instance_count,
75 uint32_t instance_start,
76 uint32_t vertex_base)
77{
78 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080079 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080080
81 CMD_ASSERT(cmd, 7, 7.5);
82
Chia-I Wu426072d2014-08-26 14:31:55 +080083 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080084 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080085
86 if (indexed)
87 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
88
Chia-I Wu72292b72014-09-09 10:48:33 +080089 cmd_batch_pointer(cmd, cmd_len, &dw);
90 dw[0] = dw0;
91 dw[1] = dw1;
92 dw[2] = vertex_count;
93 dw[3] = vertex_start;
94 dw[4] = instance_count;
95 dw[5] = instance_start;
96 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080097}
98
Chia-I Wu270b1e82014-08-25 15:53:39 +080099static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800100 struct intel_bo *bo, uint32_t bo_offset,
101 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800102{
103 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800104 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800105 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800106 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800107 uint32_t *dw;
108 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800109
110 CMD_ASSERT(cmd, 6, 7.5);
111
112 assert(bo_offset % 8 == 0);
113
114 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
115 /*
116 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
117 *
118 * "1 of the following must also be set (when CS stall is set):
119 *
120 * * Depth Cache Flush Enable ([0] of DW1)
121 * * Stall at Pixel Scoreboard ([1] of DW1)
122 * * Depth Stall ([13] of DW1)
123 * * Post-Sync Operation ([13] of DW1)
124 * * Render Target Cache Flush Enable ([12] of DW1)
125 * * Notify Enable ([8] of DW1)"
126 *
127 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
128 *
129 * "One of the following must also be set (when CS stall is set):
130 *
131 * * Render Target Cache Flush Enable ([12] of DW1)
132 * * Depth Cache Flush Enable ([0] of DW1)
133 * * Stall at Pixel Scoreboard ([1] of DW1)
134 * * Depth Stall ([13] of DW1)
135 * * Post-Sync Operation ([13] of DW1)"
136 */
137 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
138 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
140 GEN6_PIPE_CONTROL_DEPTH_STALL;
141
142 /* post-sync op */
143 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
144 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
145 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
146
147 if (cmd_gen(cmd) == INTEL_GEN(6))
148 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
149
150 assert(dw1 & bit_test);
151 }
152
153 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
154 /*
155 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
156 *
157 * "Following bits must be clear (when Depth Stall is set):
158 *
159 * * Render Target Cache Flush Enable ([12] of DW1)
160 * * Depth Cache Flush Enable ([0] of DW1)"
161 */
162 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
163 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
164 }
165
166 /*
167 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
168 *
169 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
170 * and PIPE_CONTROL are not supported."
171 *
172 * The kernel will add the mapping automatically (when write domain is
173 * INTEL_DOMAIN_INSTRUCTION).
174 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800175 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800176 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800177 reloc_flags |= INTEL_RELOC_GGTT;
178 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800179
Chia-I Wu72292b72014-09-09 10:48:33 +0800180 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
181 dw[0] = dw0;
182 dw[1] = dw1;
183 dw[2] = 0;
184 dw[3] = (uint32_t) imm;
185 dw[4] = (uint32_t) (imm >> 32);
186
187 if (bo) {
188 cmd_reserve_reloc(cmd, 1);
189 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
190 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800191}
192
Chia-I Wu254db422014-08-21 11:54:29 +0800193static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
194{
195 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
196 bool supported;
197
198 CMD_ASSERT(cmd, 6, 7.5);
199
200 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
201 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
202
203 switch (p->prim_type) {
204 case GEN6_3DPRIM_POINTLIST:
205 case GEN6_3DPRIM_LINELIST:
206 case GEN6_3DPRIM_LINESTRIP:
207 case GEN6_3DPRIM_TRILIST:
208 case GEN6_3DPRIM_TRISTRIP:
209 supported = true;
210 break;
211 default:
212 supported = false;
213 break;
214 }
215
216 if (!supported)
217 return false;
218
219 switch (cmd->bind.index.type) {
220 case XGL_INDEX_8:
221 supported = (p->primitive_restart_index != 0xffu);
222 break;
223 case XGL_INDEX_16:
224 supported = (p->primitive_restart_index != 0xffffu);
225 break;
226 case XGL_INDEX_32:
227 supported = (p->primitive_restart_index != 0xffffffffu);
228 break;
229 default:
230 supported = false;
231 break;
232 }
233
234 return supported;
235}
236
Chia-I Wu59c097e2014-08-21 10:51:07 +0800237static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800238 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 XGL_GPU_SIZE offset,
240 XGL_INDEX_TYPE type,
241 bool enable_cut_index)
242{
243 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800244 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800246 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800247
248 CMD_ASSERT(cmd, 6, 7.5);
249
Chia-I Wu426072d2014-08-26 14:31:55 +0800250 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800251
252 /* the bit is moved to 3DSTATE_VF */
253 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
254 assert(!enable_cut_index);
255 if (enable_cut_index)
256 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
257
258 switch (type) {
259 case XGL_INDEX_8:
260 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
261 offset_align = 1;
262 break;
263 case XGL_INDEX_16:
264 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
265 offset_align = 2;
266 break;
267 case XGL_INDEX_32:
268 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
269 offset_align = 4;
270 break;
271 default:
272 cmd->result = XGL_ERROR_INVALID_VALUE;
273 return;
274 break;
275 }
276
277 if (offset % offset_align) {
278 cmd->result = XGL_ERROR_INVALID_VALUE;
279 return;
280 }
281
282 /* aligned and inclusive */
283 end_offset = mem->size - (mem->size % offset_align) - 1;
284
Chia-I Wu72292b72014-09-09 10:48:33 +0800285 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
286 dw[0] = dw0;
287
288 cmd_reserve_reloc(cmd, 2);
289 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
290 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800291}
292
Chia-I Wu62a7f252014-08-29 11:31:16 +0800293static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
294 bool enable_cut_index,
295 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800296{
297 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800298 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800299
300 CMD_ASSERT(cmd, 7.5, 7.5);
301
Chia-I Wu426072d2014-08-26 14:31:55 +0800302 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800303 if (enable_cut_index)
304 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
305
Chia-I Wu72292b72014-09-09 10:48:33 +0800306 cmd_batch_pointer(cmd, cmd_len, &dw);
307 dw[0] = dw0;
308 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800309}
310
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600311
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800312static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
313{
314 const uint8_t cmd_len = 7;
315 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800316 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800317
318 CMD_ASSERT(cmd, 6, 6);
319
Chia-I Wu72292b72014-09-09 10:48:33 +0800320 cmd_batch_pointer(cmd, cmd_len, &dw);
321 dw[0] = dw0;
322 dw[1] = 0;
323 dw[2] = 0;
324 dw[3] = 0;
325 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
326 dw[5] = GEN6_GS_DW5_STATISTICS;
327 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800328}
329
Chia-I Wu62a7f252014-08-29 11:31:16 +0800330static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
331{
332 const uint8_t cmd_len = 7;
333 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800334 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800335
336 CMD_ASSERT(cmd, 7, 7.5);
337
Chia-I Wu72292b72014-09-09 10:48:33 +0800338 cmd_batch_pointer(cmd, cmd_len, &dw);
339 dw[0] = dw0;
340 dw[1] = 0;
341 dw[2] = 0;
342 dw[3] = 0;
343 dw[4] = 0;
344 dw[5] = GEN6_GS_DW5_STATISTICS;
345 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800346}
347
Chia-I Wud88e02d2014-08-25 10:56:13 +0800348static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
349 XGL_UINT width, XGL_UINT height)
350{
351 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800352 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800353 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800354 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800355
356 CMD_ASSERT(cmd, 6, 7.5);
357
Chia-I Wu72292b72014-09-09 10:48:33 +0800358 cmd_batch_pointer(cmd, cmd_len, &dw);
359 dw[0] = dw0;
360
Chia-I Wud88e02d2014-08-25 10:56:13 +0800361 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800362 dw[1] = 0;
363 dw[2] = (height - 1) << 16 |
364 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800365 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800366 dw[1] = 1;
367 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800368 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800369
370 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800371}
372
Chia-I Wu8016a172014-08-29 18:31:32 +0800373static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
374 uint32_t body[6])
375{
376 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
377 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
378 const struct intel_raster_state *raster = cmd->bind.state.raster;
379 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
380 uint32_t dw1, dw2, dw3;
381 int point_width;
382
383 CMD_ASSERT(cmd, 6, 7.5);
384
385 dw1 = GEN7_SF_DW1_STATISTICS |
386 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
387 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
388 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
389 GEN7_SF_DW1_VIEWPORT_ENABLE |
390 raster->cmd_sf_fill;
391
392 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
393 int format;
394
395 switch (pipeline->db_format.channelFormat) {
396 case XGL_CH_FMT_R16:
397 format = GEN6_ZFORMAT_D16_UNORM;
398 break;
399 case XGL_CH_FMT_R32:
400 case XGL_CH_FMT_R32G8:
401 format = GEN6_ZFORMAT_D32_FLOAT;
402 break;
403 default:
404 assert(!"unknown depth format");
405 format = 0;
406 break;
407 }
408
409 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
410 }
411
412 dw2 = raster->cmd_sf_cull;
413
414 if (msaa->sample_count > 1) {
415 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
416 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
417 } else {
418 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
419 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
420 }
421
422 if (viewport->scissor_enable)
423 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
424
425 /* in U8.3 */
426 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
427 point_width = U_CLAMP(point_width, 1, 2047);
428
429 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
431 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
432 GEN7_SF_DW3_SUBPIXEL_8BITS |
433 GEN7_SF_DW3_USE_POINT_WIDTH |
434 point_width;
435
436 body[0] = dw1;
437 body[1] = dw2;
438 body[2] = dw3;
439 body[3] = raster->cmd_depth_offset_const;
440 body[4] = raster->cmd_depth_offset_scale;
441 body[5] = raster->cmd_depth_offset_clamp;
442}
443
444static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
445 uint32_t body[13])
446{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800447 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
448 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449 XGL_UINT attr_skip, attr_count;
450 XGL_UINT vue_offset, vue_len;
451 XGL_UINT i;
452 uint32_t dw1;
453
454 CMD_ASSERT(cmd, 6, 7.5);
455
456 /* VS outputs VUE header and position additionally */
GregFbcbe19a2014-11-07 11:01:01 -0700457 assert(vs->out_count >= fs->in_count + 2);
458 attr_skip = vs->out_count - fs->in_count;
Chia-I Wu8016a172014-08-29 18:31:32 +0800459 attr_count = vs->out_count - attr_skip;
Chia-I Wu8016a172014-08-29 18:31:32 +0800460 assert(fs->in_count <= 32);
461
GregFbcbe19a2014-11-07 11:01:01 -0700462 vue_offset = (attr_skip + 1) / 2;
Chia-I Wu8016a172014-08-29 18:31:32 +0800463 vue_len = (attr_count + 1) / 2;
464 if (!vue_len)
465 vue_len = 1;
466
467 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
468 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
469 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
470
471 body[0] = dw1;
472
473 for (i = 0; i < 8; i++) {
474 uint16_t hi, lo;
475
476 /* no attr swizzles */
477 if (i * 2 + 1 < fs->in_count) {
478 hi = i * 2 + 1;
479 lo = i * 2;
480 } else if (i * 2 < fs->in_count) {
481 hi = 0;
482 lo = i * 2;
483 } else {
484 hi = 0;
485 lo = 0;
486 }
487
488 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
489 }
490
491 body[9] = 0; /* point sprite enables */
492 body[10] = 0; /* constant interpolation enables */
493 body[11] = 0; /* WrapShortest enables */
494 body[12] = 0;
495}
496
497static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
498{
499 const uint8_t cmd_len = 20;
500 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
501 (cmd_len - 2);
502 uint32_t sf[6];
503 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800504 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800505
506 CMD_ASSERT(cmd, 6, 6);
507
508 gen7_fill_3DSTATE_SF_body(cmd, sf);
509 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
510
Chia-I Wu72292b72014-09-09 10:48:33 +0800511 cmd_batch_pointer(cmd, cmd_len, &dw);
512 dw[0] = dw0;
513 dw[1] = sbe[0];
514 memcpy(&dw[2], sf, sizeof(sf));
515 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800516}
517
518static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
519{
520 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800521 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800522
523 CMD_ASSERT(cmd, 7, 7.5);
524
Chia-I Wu72292b72014-09-09 10:48:33 +0800525 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800526 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
527 (cmd_len - 2);
528 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800529}
530
531static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
532{
533 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800534 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800535
536 CMD_ASSERT(cmd, 7, 7.5);
537
Chia-I Wu72292b72014-09-09 10:48:33 +0800538 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800539 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
540 (cmd_len - 2);
541 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800542}
543
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800544static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
545{
546 const uint8_t cmd_len = 4;
547 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
548 (cmd_len - 2);
549 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700550 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800551 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800552 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
553 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800554 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800555
556 CMD_ASSERT(cmd, 6, 7.5);
557
558 dw1 = GEN6_CLIP_DW1_STATISTICS;
559 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
560 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
561 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
562 raster->cmd_clip_cull;
563 }
564
565 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
566 GEN6_CLIP_DW2_XY_TEST_ENABLE |
567 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700568 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800569 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
570 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
571 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
572
573 if (pipeline->rasterizerDiscardEnable)
574 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
575 else
576 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
577
578 if (pipeline->depthClipEnable)
579 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
580
581 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
582 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
583 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
584 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
585
586 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
587 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
588 (viewport->viewport_count - 1);
589
Chia-I Wu72292b72014-09-09 10:48:33 +0800590 cmd_batch_pointer(cmd, cmd_len, &dw);
591 dw[0] = dw0;
592 dw[1] = dw1;
593 dw[2] = dw2;
594 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800595}
596
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800597static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
598{
599 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
600 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800601 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800602 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
603 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800604 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800605
606 CMD_ASSERT(cmd, 6, 6);
607
608 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
609
610 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
611 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
612
613 dw4 = GEN6_WM_DW4_STATISTICS |
614 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
615 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
616 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
617
618 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
619 GEN6_WM_DW5_PS_ENABLE |
620 GEN6_WM_DW5_8_PIXEL_DISPATCH;
621
622 if (fs->uses & INTEL_SHADER_USE_KILL ||
623 pipeline->cb_state.alphaToCoverageEnable)
624 dw5 |= GEN6_WM_DW5_PS_KILL;
625
626 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
627 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
628 if (fs->uses & INTEL_SHADER_USE_DEPTH)
629 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
630 if (fs->uses & INTEL_SHADER_USE_W)
631 dw5 |= GEN6_WM_DW5_PS_USE_W;
632
633 if (pipeline->cb_state.dualSourceBlendEnable)
634 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
635
636 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
637 GEN6_WM_DW6_POSOFFSET_NONE |
638 GEN6_WM_DW6_ZW_INTERP_PIXEL |
639 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
640 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
641
642 if (msaa->sample_count > 1) {
643 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
644 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
645 } else {
646 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
647 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
648 }
649
Chia-I Wu72292b72014-09-09 10:48:33 +0800650 cmd_batch_pointer(cmd, cmd_len, &dw);
651 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800652 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800653 dw[2] = dw2;
654 dw[3] = 0; /* scratch */
655 dw[4] = dw4;
656 dw[5] = dw5;
657 dw[6] = dw6;
658 dw[7] = 0; /* kernel 1 */
659 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800660}
661
662static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
663{
664 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800665 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800666 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
667 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800668 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800669
670 CMD_ASSERT(cmd, 7, 7.5);
671
672 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
673
674 dw1 = GEN7_WM_DW1_STATISTICS |
675 GEN7_WM_DW1_PS_ENABLE |
676 GEN7_WM_DW1_ZW_INTERP_PIXEL |
677 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
678 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
679
680 if (fs->uses & INTEL_SHADER_USE_KILL ||
681 pipeline->cb_state.alphaToCoverageEnable)
682 dw1 |= GEN7_WM_DW1_PS_KILL;
683
684 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
685 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
686 if (fs->uses & INTEL_SHADER_USE_DEPTH)
687 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
688 if (fs->uses & INTEL_SHADER_USE_W)
689 dw1 |= GEN7_WM_DW1_PS_USE_W;
690
691 dw2 = 0;
692
693 if (msaa->sample_count > 1) {
694 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
695 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
696 } else {
697 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
698 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
699 }
700
Chia-I Wu72292b72014-09-09 10:48:33 +0800701 cmd_batch_pointer(cmd, cmd_len, &dw);
702 dw[0] = dw0;
703 dw[1] = dw1;
704 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800705}
706
707static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
708{
709 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800710 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800711 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
712 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800713 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800714
715 CMD_ASSERT(cmd, 7, 7.5);
716
717 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
718
719 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
720 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
721
722 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
723 GEN7_PS_DW4_8_PIXEL_DISPATCH;
724
725 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
726 const int max_threads =
727 (cmd->dev->gpu->gt == 3) ? 408 :
728 (cmd->dev->gpu->gt == 2) ? 204 : 102;
729 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
730 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
731 } else {
732 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
733 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
734 }
735
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800736 if (fs->in_count)
737 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
738
739 if (pipeline->cb_state.dualSourceBlendEnable)
740 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
741
742 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
743 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
744 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
745
Chia-I Wu72292b72014-09-09 10:48:33 +0800746 cmd_batch_pointer(cmd, cmd_len, &dw);
747 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800748 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800749 dw[2] = dw2;
750 dw[3] = 0; /* scratch */
751 dw[4] = dw4;
752 dw[5] = dw5;
753 dw[6] = 0; /* kernel 1 */
754 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800755}
756
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800757static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
758 const struct intel_ds_view *view)
759{
760 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800761 uint32_t dw0, *dw;
762 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800763
764 CMD_ASSERT(cmd, 6, 7.5);
765
766 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800767 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
768 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800769 dw0 |= (cmd_len - 2);
770
Chia-I Wu72292b72014-09-09 10:48:33 +0800771 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
772 dw[0] = dw0;
773 dw[1] = view->cmd[0];
774 dw[2] = 0;
775 dw[3] = view->cmd[2];
776 dw[4] = view->cmd[3];
777 dw[5] = view->cmd[4];
778 dw[6] = view->cmd[5];
779
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600780 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800781 cmd_reserve_reloc(cmd, 1);
782 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
783 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600784 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800785}
786
787static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
788 const struct intel_ds_view *view)
789{
790 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800791 uint32_t dw0, *dw;
792 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793
794 CMD_ASSERT(cmd, 6, 7.5);
795
796 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800797 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
798 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800799 dw0 |= (cmd_len - 2);
800
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
802 dw[0] = dw0;
803 dw[1] = view->cmd[6];
804 dw[2] = 0;
805
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600806 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800807 cmd_reserve_reloc(cmd, 1);
808 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
809 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600810 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800811}
812
813static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
814 const struct intel_ds_view *view)
815{
816 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800817 uint32_t dw0, *dw;
818 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800819
820 CMD_ASSERT(cmd, 6, 7.5);
821
822 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800823 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
824 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800825 dw0 |= (cmd_len - 2);
826
Chia-I Wu72292b72014-09-09 10:48:33 +0800827 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
828 dw[0] = dw0;
829 dw[1] = view->cmd[8];
830 dw[2] = 0;
831
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600832 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800833 cmd_reserve_reloc(cmd, 1);
834 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
835 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600836 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800837}
838
Chia-I Wuf8231032014-08-25 10:44:45 +0800839static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
840 uint32_t clear_val)
841{
842 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800843 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800844 GEN6_CLEAR_PARAMS_DW0_VALID |
845 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800846 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800847
848 CMD_ASSERT(cmd, 6, 6);
849
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 cmd_batch_pointer(cmd, cmd_len, &dw);
851 dw[0] = dw0;
852 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800853}
854
855static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
856 uint32_t clear_val)
857{
858 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800859 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800860 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800861 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800862
863 CMD_ASSERT(cmd, 7, 7.5);
864
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 cmd_batch_pointer(cmd, cmd_len, &dw);
866 dw[0] = dw0;
867 dw[1] = clear_val;
868 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800869}
870
Chia-I Wu302742d2014-08-22 10:28:29 +0800871static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800872 uint32_t blend_offset,
873 uint32_t ds_offset,
874 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800875{
876 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800877 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800878
879 CMD_ASSERT(cmd, 6, 6);
880
Chia-I Wu426072d2014-08-26 14:31:55 +0800881 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800882 (cmd_len - 2);
883
Chia-I Wu72292b72014-09-09 10:48:33 +0800884 cmd_batch_pointer(cmd, cmd_len, &dw);
885 dw[0] = dw0;
886 dw[1] = blend_offset | 1;
887 dw[2] = ds_offset | 1;
888 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800889}
890
Chia-I Wu1744cca2014-08-22 11:10:17 +0800891static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 uint32_t clip_offset,
893 uint32_t sf_offset,
894 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800895{
896 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800897 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800898
899 CMD_ASSERT(cmd, 6, 6);
900
Chia-I Wu426072d2014-08-26 14:31:55 +0800901 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800902 GEN6_PTR_VP_DW0_CLIP_CHANGED |
903 GEN6_PTR_VP_DW0_SF_CHANGED |
904 GEN6_PTR_VP_DW0_CC_CHANGED |
905 (cmd_len - 2);
906
Chia-I Wu72292b72014-09-09 10:48:33 +0800907 cmd_batch_pointer(cmd, cmd_len, &dw);
908 dw[0] = dw0;
909 dw[1] = clip_offset;
910 dw[2] = sf_offset;
911 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800912}
913
914static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800915 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800916{
917 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800918 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800919
920 CMD_ASSERT(cmd, 6, 6);
921
Chia-I Wu426072d2014-08-26 14:31:55 +0800922 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800923 (cmd_len - 2);
924
Chia-I Wu72292b72014-09-09 10:48:33 +0800925 cmd_batch_pointer(cmd, cmd_len, &dw);
926 dw[0] = dw0;
927 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800928}
929
Chia-I Wu42a56202014-08-23 16:47:48 +0800930static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800931 uint32_t vs_offset,
932 uint32_t gs_offset,
933 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800934{
935 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800936 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800937
938 CMD_ASSERT(cmd, 6, 6);
939
Chia-I Wu426072d2014-08-26 14:31:55 +0800940 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800941 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
942 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
943 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
944 (cmd_len - 2);
945
Chia-I Wu72292b72014-09-09 10:48:33 +0800946 cmd_batch_pointer(cmd, cmd_len, &dw);
947 dw[0] = dw0;
948 dw[1] = vs_offset;
949 dw[2] = gs_offset;
950 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800951}
952
Chia-I Wu257e75e2014-08-29 14:06:35 +0800953static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800954 uint32_t vs_offset,
955 uint32_t gs_offset,
956 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800957{
958 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800959 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800960
961 CMD_ASSERT(cmd, 6, 6);
962
963 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
964 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
965 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
966 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
967 (cmd_len - 2);
968
Chia-I Wu72292b72014-09-09 10:48:33 +0800969 cmd_batch_pointer(cmd, cmd_len, &dw);
970 dw[0] = dw0;
971 dw[1] = vs_offset;
972 dw[2] = gs_offset;
973 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800974}
975
Chia-I Wu302742d2014-08-22 10:28:29 +0800976static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800977 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800978{
979 const uint8_t cmd_len = 2;
980 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
981 GEN6_RENDER_SUBTYPE_3D |
982 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800984
Chia-I Wu72292b72014-09-09 10:48:33 +0800985 cmd_batch_pointer(cmd, cmd_len, &dw);
986 dw[0] = dw0;
987 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800988}
989
Chia-I Wu72292b72014-09-09 10:48:33 +0800990static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800991 const struct intel_blend_state *state)
992{
Chia-I Wu72292b72014-09-09 10:48:33 +0800993 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800994 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
995
996 CMD_ASSERT(cmd, 6, 7.5);
997 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
998
Chia-I Wu00b51a82014-09-09 12:07:37 +0800999 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
1000 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001001}
1002
Chia-I Wu72292b72014-09-09 10:48:33 +08001003static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001004 const struct intel_ds_state *state)
1005{
Chia-I Wu72292b72014-09-09 10:48:33 +08001006 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001007 const uint8_t cmd_len = 3;
1008
1009 CMD_ASSERT(cmd, 6, 7.5);
1010 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1011
Chia-I Wu00b51a82014-09-09 12:07:37 +08001012 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1013 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001014}
1015
Chia-I Wu72292b72014-09-09 10:48:33 +08001016static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001017 uint32_t stencil_ref,
1018 const uint32_t blend_color[4])
1019{
Chia-I Wu72292b72014-09-09 10:48:33 +08001020 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001021 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001022 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001023
1024 CMD_ASSERT(cmd, 6, 7.5);
1025
Chia-I Wu00b51a82014-09-09 12:07:37 +08001026 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1027 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001028 dw[0] = stencil_ref;
1029 dw[1] = 0;
1030 dw[2] = blend_color[0];
1031 dw[3] = blend_color[1];
1032 dw[4] = blend_color[2];
1033 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001034
Chia-I Wu72292b72014-09-09 10:48:33 +08001035 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001036}
1037
Chia-I Wu8370b402014-08-29 12:28:37 +08001038static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001039{
Chia-I Wu8370b402014-08-29 12:28:37 +08001040 CMD_ASSERT(cmd, 6, 7.5);
1041
Chia-I Wu707a29e2014-08-27 12:51:47 +08001042 if (!cmd->bind.draw_count)
1043 return;
1044
Chia-I Wu8370b402014-08-29 12:28:37 +08001045 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001046 return;
1047
Chia-I Wu8370b402014-08-29 12:28:37 +08001048 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001049
1050 /*
1051 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1052 *
1053 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1054 * pipe-control with a post-sync op and no write-cache flushes."
1055 *
1056 * The workaround below necessitates this workaround.
1057 */
1058 gen6_PIPE_CONTROL(cmd,
1059 GEN6_PIPE_CONTROL_CS_STALL |
1060 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001061 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001062
Chia-I Wud6d079d2014-08-31 13:14:21 +08001063 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1064 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001065}
1066
Chia-I Wu8370b402014-08-29 12:28:37 +08001067static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001068{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001069 CMD_ASSERT(cmd, 6, 7.5);
1070
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001071 if (!cmd->bind.draw_count)
1072 return;
1073
Chia-I Wud6d079d2014-08-31 13:14:21 +08001074 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1075 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001076}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001077
Chia-I Wu8370b402014-08-29 12:28:37 +08001078static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1079{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001080 CMD_ASSERT(cmd, 7, 7.5);
1081
Chia-I Wu8370b402014-08-29 12:28:37 +08001082 if (!cmd->bind.draw_count)
1083 return;
1084
1085 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001086
1087 gen6_PIPE_CONTROL(cmd,
1088 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001089 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001090}
1091
Chia-I Wu8370b402014-08-29 12:28:37 +08001092static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1093{
1094 CMD_ASSERT(cmd, 7, 7.5);
1095
1096 if (!cmd->bind.draw_count)
1097 return;
1098
1099 /*
1100 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1101 *
1102 * "One of the following must also be set (when CS stall is set):
1103 *
1104 * * Render Target Cache Flush Enable ([12] of DW1)
1105 * * Depth Cache Flush Enable ([0] of DW1)
1106 * * Stall at Pixel Scoreboard ([1] of DW1)
1107 * * Depth Stall ([13] of DW1)
1108 * * Post-Sync Operation ([13] of DW1)"
1109 */
1110 gen6_PIPE_CONTROL(cmd,
1111 GEN6_PIPE_CONTROL_CS_STALL |
1112 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001113 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001114}
1115
1116static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1117{
1118 CMD_ASSERT(cmd, 7, 7.5);
1119
1120 if (!cmd->bind.draw_count)
1121 return;
1122
1123 cmd_wa_gen6_pre_depth_stall_write(cmd);
1124
Chia-I Wud6d079d2014-08-31 13:14:21 +08001125 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001126}
1127
1128static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1129{
1130 CMD_ASSERT(cmd, 6, 7.5);
1131
1132 if (!cmd->bind.draw_count)
1133 return;
1134
1135 /*
1136 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1137 *
1138 * "Driver must guarentee that all the caches in the depth pipe are
1139 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1140 * requires driver to send a PIPE_CONTROL with a CS stall along with
1141 * a Depth Flush prior to this command."
1142 *
1143 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1144 *
1145 * "Driver must ierarchi that all the caches in the depth pipe are
1146 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1147 * requires driver to send a PIPE_CONTROL with a CS stall along with
1148 * a Depth Flush prior to this command.
1149 */
1150 gen6_PIPE_CONTROL(cmd,
1151 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1152 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001153 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001154}
1155
1156static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1157{
1158 CMD_ASSERT(cmd, 6, 7.5);
1159
1160 if (!cmd->bind.draw_count)
1161 return;
1162
1163 /*
1164 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1165 *
1166 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1167 * and a post sync operation prior to the group of depth
1168 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1169 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1170 *
1171 * This workaround satifies all the conditions.
1172 */
1173 cmd_wa_gen6_pre_depth_stall_write(cmd);
1174
1175 /*
1176 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1177 *
1178 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1179 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1180 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1181 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1182 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1183 * Depth Flush Bit set, followed by another pipelined depth stall
1184 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1185 * guarantee that the pipeline from WM onwards is already flushed
1186 * (e.g., via a preceding MI_FLUSH)."
1187 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001188 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1189 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1190 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001191}
1192
Chia-I Wu525c6602014-08-27 10:22:34 +08001193void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1194{
1195 if (!cmd->bind.draw_count)
1196 return;
1197
1198 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1199
Chia-I Wu8370b402014-08-29 12:28:37 +08001200 /*
1201 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1202 *
1203 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1204 * PIPE_CONTROL with any non-zero post-sync-op is required."
1205 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001206 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001207 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001208
Chia-I Wu092279a2014-08-30 19:05:30 +08001209 /*
1210 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1211 *
1212 * "One of the following must also be set (when CS stall is set):
1213 *
1214 * * Render Target Cache Flush Enable ([12] of DW1)
1215 * * Depth Cache Flush Enable ([0] of DW1)
1216 * * Stall at Pixel Scoreboard ([1] of DW1)
1217 * * Depth Stall ([13] of DW1)
1218 * * Post-Sync Operation ([13] of DW1)"
1219 */
1220 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1221 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1222 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1223 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1224 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1225 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1226
Chia-I Wud6d079d2014-08-31 13:14:21 +08001227 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001228}
1229
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001230void cmd_batch_flush_all(struct intel_cmd *cmd)
1231{
1232 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1233 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1234 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1235 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1236 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1237 GEN6_PIPE_CONTROL_CS_STALL);
1238}
1239
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001240void cmd_batch_depth_count(struct intel_cmd *cmd,
1241 struct intel_bo *bo,
1242 XGL_GPU_SIZE offset)
1243{
1244 cmd_wa_gen6_pre_depth_stall_write(cmd);
1245
1246 gen6_PIPE_CONTROL(cmd,
1247 GEN6_PIPE_CONTROL_DEPTH_STALL |
1248 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001249 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001250}
1251
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001252void cmd_batch_timestamp(struct intel_cmd *cmd,
1253 struct intel_bo *bo,
1254 XGL_GPU_SIZE offset)
1255{
1256 /* need any WA or stall? */
1257 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1258}
1259
1260void cmd_batch_immediate(struct intel_cmd *cmd,
1261 struct intel_bo *bo,
1262 XGL_GPU_SIZE offset,
1263 uint64_t val)
1264{
1265 /* need any WA or stall? */
1266 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1267}
1268
Chia-I Wu302742d2014-08-22 10:28:29 +08001269static void gen6_cc_states(struct intel_cmd *cmd)
1270{
1271 const struct intel_blend_state *blend = cmd->bind.state.blend;
1272 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001273 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001274 uint32_t stencil_ref;
1275 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001276
1277 CMD_ASSERT(cmd, 6, 6);
1278
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001279 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001280 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001281 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1282 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001283 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001284 memset(blend_color, 0, sizeof(blend_color));
1285 }
1286
1287 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001288 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001289 stencil_ref = ds->cmd_stencil_ref;
1290 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001291 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001292 stencil_ref = 0;
1293 }
1294
Chia-I Wu72292b72014-09-09 10:48:33 +08001295 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001296
Chia-I Wu72292b72014-09-09 10:48:33 +08001297 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001298}
1299
Chia-I Wu1744cca2014-08-22 11:10:17 +08001300static void gen6_viewport_states(struct intel_cmd *cmd)
1301{
1302 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001303 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001304
1305 if (!viewport)
1306 return;
1307
Chia-I Wub1d450a2014-09-09 13:48:03 +08001308 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1309 viewport->viewport_count);
1310
1311 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1312 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1313 viewport->cmd);
1314
1315 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1316 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1317 &viewport->cmd[viewport->cmd_clip_pos]);
1318
1319 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1320 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1321 &viewport->cmd[viewport->cmd_cc_pos]);
1322
1323 if (viewport->scissor_enable) {
1324 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1325 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1326 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1327 } else {
1328 scissor_offset = 0;
1329 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001330
1331 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001332 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001333
Chia-I Wub1d450a2014-09-09 13:48:03 +08001334 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001335}
1336
Chia-I Wu302742d2014-08-22 10:28:29 +08001337static void gen7_cc_states(struct intel_cmd *cmd)
1338{
1339 const struct intel_blend_state *blend = cmd->bind.state.blend;
1340 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001341 uint32_t stencil_ref;
1342 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001343 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001344
1345 CMD_ASSERT(cmd, 7, 7.5);
1346
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001347 if (!blend && !ds)
1348 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001349
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001350 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001351 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001352 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001353 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001354
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001355 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1356 } else {
1357 memset(blend_color, 0, sizeof(blend_color));
1358 }
1359
1360 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001361 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001362 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001363 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1364 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001365 } else {
1366 stencil_ref = 0;
1367 }
1368
Chia-I Wu72292b72014-09-09 10:48:33 +08001369 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001370 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001371 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001372}
1373
Chia-I Wu1744cca2014-08-22 11:10:17 +08001374static void gen7_viewport_states(struct intel_cmd *cmd)
1375{
1376 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001377 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001378
1379 if (!viewport)
1380 return;
1381
Chia-I Wub1d450a2014-09-09 13:48:03 +08001382 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1383 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001384
Chia-I Wub1d450a2014-09-09 13:48:03 +08001385 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1386 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1387 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001388 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001389 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1390 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001391
1392 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1393 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1394 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001395 gen7_3dstate_pointer(cmd,
1396 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001397 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001398
Chia-I Wu1744cca2014-08-22 11:10:17 +08001399 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001400 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1401 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1402 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001403 gen7_3dstate_pointer(cmd,
1404 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001405 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001406 }
1407}
1408
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001409static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001410 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001411{
1412 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001413 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001414
Chia-I Wu72292b72014-09-09 10:48:33 +08001415 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001416
1417 dw[0] = GEN6_RENDER_TYPE_RENDER |
1418 GEN6_RENDER_SUBTYPE_3D |
1419 subop | (cmd_len - 2);
1420 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001421 dw[2] = 0;
1422 dw[3] = 0;
1423 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001424}
1425
1426static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001427 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001428{
1429 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001430 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001431
Chia-I Wu72292b72014-09-09 10:48:33 +08001432 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001433
1434 dw[0] = GEN6_RENDER_TYPE_RENDER |
1435 GEN6_RENDER_SUBTYPE_3D |
1436 subop | (cmd_len - 2);
1437 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001438 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001439 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001440 dw[4] = 0;
1441 dw[5] = 0;
1442 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001443}
1444
Chia-I Wu625105f2014-10-13 15:35:29 +08001445static uint32_t emit_samplers(struct intel_cmd *cmd,
1446 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001447{
1448 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1449 const XGL_UINT border_stride =
1450 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001451 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001452 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001453 XGL_UINT i;
1454
1455 CMD_ASSERT(cmd, 6, 7.5);
1456
Chia-I Wu625105f2014-10-13 15:35:29 +08001457 if (!rmap || !rmap->sampler_count)
1458 return 0;
1459
1460 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1461
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001462 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1463 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1464 border_stride * rmap->sampler_count, &border_dw);
1465
1466 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1467 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1468 4 * rmap->sampler_count, &sampler_dw);
1469
1470 for (i = 0; i < rmap->sampler_count; i++) {
1471 const struct intel_pipeline_rmap_slot *slot =
1472 &rmap->slots[surface_count + i];
1473 const struct intel_sampler *sampler;
1474
1475 switch (slot->path_len) {
1476 case 0:
1477 sampler = NULL;
1478 break;
1479 case INTEL_PIPELINE_RMAP_SLOT_RT:
1480 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1481 assert(!"unexpected rmap slot type");
1482 sampler = NULL;
1483 break;
1484 case 1:
1485 {
1486 const struct intel_dset *dset = cmd->bind.dset.graphics;
1487 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1488 const struct intel_dset_slot *dset_slot =
1489 &dset->slots[slot_offset + slot->u.index];
1490
1491 switch (dset_slot->type) {
1492 case INTEL_DSET_SLOT_SAMPLER:
1493 sampler = dset_slot->u.sampler;
1494 break;
1495 default:
1496 assert(!"unexpected dset slot type");
1497 sampler = NULL;
1498 break;
1499 }
1500 }
1501 break;
1502 default:
1503 assert(!"nested descriptor set unsupported");
1504 sampler = NULL;
1505 break;
1506 }
1507
1508 if (sampler) {
1509 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1510
1511 sampler_dw[0] = sampler->cmd[0];
1512 sampler_dw[1] = sampler->cmd[1];
1513 sampler_dw[2] = border_offset;
1514 sampler_dw[3] = sampler->cmd[2];
1515 } else {
1516 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1517 sampler_dw[1] = 0;
1518 sampler_dw[2] = 0;
1519 sampler_dw[3] = 0;
1520 }
1521
1522 border_offset += border_stride * 4;
1523 border_dw += border_stride;
1524 sampler_dw += 4;
1525 }
1526
Chia-I Wu625105f2014-10-13 15:35:29 +08001527 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001528}
1529
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001530static uint32_t emit_binding_table(struct intel_cmd *cmd,
1531 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001532{
Chia-I Wu72292b72014-09-09 10:48:33 +08001533 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001534 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001535
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001536 CMD_ASSERT(cmd, 6, 7.5);
1537
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001538 surface_count = (rmap) ?
1539 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1540 if (!surface_count)
1541 return 0;
1542
Chia-I Wu42a56202014-08-23 16:47:48 +08001543 assert(surface_count <= ARRAY_SIZE(binding_table));
1544
1545 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001546 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001547
1548 switch (slot->path_len) {
1549 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001550 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001551 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001552 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001553 {
1554 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1555
Chia-I Wu00b51a82014-09-09 12:07:37 +08001556 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001557 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1558 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001559
Chia-I Wu72292b72014-09-09 10:48:33 +08001560 cmd_reserve_reloc(cmd, 1);
1561 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1562 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001563 }
1564 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001565 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001566 {
1567 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001568 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001569
Chia-I Wu00b51a82014-09-09 12:07:37 +08001570 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001571 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1572 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001573
Chia-I Wu72292b72014-09-09 10:48:33 +08001574 cmd_reserve_reloc(cmd, 1);
1575 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1576 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001577 }
1578 break;
1579 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001580 {
1581 const struct intel_dset *dset = cmd->bind.dset.graphics;
1582 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1583 const struct intel_dset_slot *dset_slot =
1584 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001585 const uint32_t reloc_flags =
1586 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001587
1588 switch (dset_slot->type) {
1589 case INTEL_DSET_SLOT_IMG_VIEW:
1590 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1591 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1592 dset_slot->u.img_view->cmd_len,
1593 dset_slot->u.img_view->cmd);
1594
1595 cmd_reserve_reloc(cmd, 1);
1596 cmd_surface_reloc(cmd, offset, 1,
1597 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001598 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001599 break;
1600 case INTEL_DSET_SLOT_MEM_VIEW:
1601 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1602 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1603 dset_slot->u.mem_view.cmd_len,
1604 dset_slot->u.mem_view.cmd);
1605
1606 cmd_reserve_reloc(cmd, 1);
1607 cmd_surface_reloc(cmd, offset, 1,
1608 dset_slot->u.mem_view.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001609 dset_slot->u.mem_view.cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001610 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001611 case INTEL_DSET_SLOT_SAMPLER:
1612 assert(0 == cmd->bind.dset.graphics_offset);
1613
1614 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1615 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1616 16, dset_slot->u.sampler->cmd);
1617 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001618 default:
1619 assert(!"unexpected dset slot type");
1620 break;
1621 }
1622 }
1623 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001624 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001625 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001626 break;
1627 }
1628
Chia-I Wu72292b72014-09-09 10:48:33 +08001629 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001630 }
1631
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001632 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001633 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001634 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001635}
1636
Chia-I Wu1d125092014-10-08 08:49:38 +08001637static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1638{
1639 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001640 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1641 uint32_t *dw;
1642 XGL_UINT pos, i;
1643
1644 CMD_ASSERT(cmd, 6, 7.5);
1645
1646 if (!pipeline->vb_count)
1647 return;
1648
1649 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1650
1651 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1652 dw++;
1653 pos++;
1654
1655 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001656 assert(pipeline->vb[i].strideInBytes <= 2048);
1657
1658 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1659 pipeline->vb[i].strideInBytes;
1660
1661 if (cmd_gen(cmd) >= INTEL_GEN(7))
1662 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1663
1664 switch (pipeline->vb[i].stepRate) {
1665 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1666 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1667 dw[3] = 0;
1668 break;
1669 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1670 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1671 dw[3] = 1;
1672 break;
1673 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1674 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1675 dw[3] = 0;
1676 break;
1677 default:
1678 assert(!"unknown step rate");
1679 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1680 dw[3] = 0;
1681 break;
1682 }
1683
Chia-I Wu3b04af52014-11-08 10:48:20 +08001684 if (cmd->bind.vertex.mem[i]) {
1685 const struct intel_mem *mem = cmd->bind.vertex.mem[i];
1686 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001687
1688 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3b04af52014-11-08 10:48:20 +08001689 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
1690 cmd_batch_reloc(cmd, pos + 2, mem->bo, mem->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001691 } else {
1692 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1693 dw[1] = 0;
1694 dw[2] = 0;
1695 }
1696
1697 dw += 4;
1698 pos += 4;
1699 }
1700}
1701
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001702static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1703{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001704 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1705 const struct intel_pipeline_shader *vs = &pipeline->vs;
1706 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001707 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001708 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001709 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001710
1711 CMD_ASSERT(cmd, 6, 7.5);
1712
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001713 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001714 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1715 *
1716 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1717 * 128-bit vertex elements to be passed into the payload for each
1718 * vertex."
1719 *
1720 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1721 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001722 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001723 vue_read_len = (vs->in_count + 1) / 2;
1724 if (!vue_read_len)
1725 vue_read_len = 1;
1726
1727 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1728 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1729
1730 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1731 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1732 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001733
1734 dw5 = GEN6_VS_DW5_STATISTICS |
1735 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001736
1737 switch (cmd_gen(cmd)) {
1738 case INTEL_GEN(7.5):
1739 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1740 break;
1741 case INTEL_GEN(7):
1742 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1743 break;
1744 case INTEL_GEN(6):
1745 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1746 break;
1747 default:
1748 max_threads = 1;
1749 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001750 }
1751
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001752 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1753 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1754 else
1755 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1756
Chia-I Wube0a3d92014-09-02 13:20:59 +08001757 if (pipeline->disable_vs_cache)
1758 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1759
Chia-I Wu72292b72014-09-09 10:48:33 +08001760 cmd_batch_pointer(cmd, cmd_len, &dw);
1761 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001762 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001763 dw[2] = dw2;
1764 dw[3] = 0; /* scratch */
1765 dw[4] = dw4;
1766 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001767}
1768
Chia-I Wu625105f2014-10-13 15:35:29 +08001769static void emit_shader_resources(struct intel_cmd *cmd)
1770{
1771 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001772 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001773
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001774 binding_tables[0] = emit_binding_table(cmd,
1775 cmd->bind.pipeline.graphics->vs.rmap);
1776 binding_tables[1] = emit_binding_table(cmd,
1777 cmd->bind.pipeline.graphics->tcs.rmap);
1778 binding_tables[2] = emit_binding_table(cmd,
1779 cmd->bind.pipeline.graphics->tes.rmap);
1780 binding_tables[3] = emit_binding_table(cmd,
1781 cmd->bind.pipeline.graphics->gs.rmap);
1782 binding_tables[4] = emit_binding_table(cmd,
1783 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001784
1785 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1786 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1787 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1788 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1789 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1790
1791 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1792 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001793 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1794 binding_tables[0]);
1795 gen7_3dstate_pointer(cmd,
1796 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1797 binding_tables[1]);
1798 gen7_3dstate_pointer(cmd,
1799 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1800 binding_tables[2]);
1801 gen7_3dstate_pointer(cmd,
1802 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1803 binding_tables[3]);
1804 gen7_3dstate_pointer(cmd,
1805 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1806 binding_tables[4]);
1807
1808 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001809 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1810 samplers[0]);
1811 gen7_3dstate_pointer(cmd,
1812 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1813 samplers[1]);
1814 gen7_3dstate_pointer(cmd,
1815 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1816 samplers[2]);
1817 gen7_3dstate_pointer(cmd,
1818 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1819 samplers[3]);
1820 gen7_3dstate_pointer(cmd,
1821 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1822 samplers[4]);
1823 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001824 assert(!binding_tables[1] && !binding_tables[2]);
1825 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1826 binding_tables[0], binding_tables[3], binding_tables[4]);
1827
Chia-I Wu625105f2014-10-13 15:35:29 +08001828 assert(!samplers[1] && !samplers[2]);
1829 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1830 samplers[0], samplers[3], samplers[4]);
1831 }
1832}
1833
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001834static void emit_rt(struct intel_cmd *cmd)
1835{
1836 cmd_wa_gen6_pre_depth_stall_write(cmd);
1837 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1838 cmd->bind.att.height);
1839}
1840
1841static void emit_ds(struct intel_cmd *cmd)
1842{
1843 const struct intel_ds_view *ds = cmd->bind.att.ds;
1844
1845 if (!ds) {
1846 /* all zeros */
1847 static const struct intel_ds_view null_ds;
1848 ds = &null_ds;
1849 }
1850
1851 cmd_wa_gen6_pre_ds_flush(cmd);
1852 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1853 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1854 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1855
1856 if (cmd_gen(cmd) >= INTEL_GEN(7))
1857 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1858 else
1859 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1860}
1861
Chia-I Wua57761b2014-10-14 14:27:44 +08001862static uint32_t emit_shader(struct intel_cmd *cmd,
1863 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001864{
Chia-I Wua57761b2014-10-14 14:27:44 +08001865 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1866 uint32_t offset;
1867 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001868
Chia-I Wua57761b2014-10-14 14:27:44 +08001869 /* see if the shader is already in the cache */
1870 for (i = 0; i < cache->used; i++) {
1871 if (cache->entries[i].shader == (const void *) shader)
1872 return cache->entries[i].kernel_offset;
1873 }
1874
1875 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1876
1877 /* grow the cache if full */
1878 if (cache->used >= cache->count) {
1879 const XGL_UINT count = cache->count + 16;
1880 void *entries;
1881
1882 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1883 XGL_SYSTEM_ALLOC_INTERNAL);
1884 if (entries) {
1885 if (cache->entries) {
1886 memcpy(entries, cache->entries,
1887 sizeof(cache->entries[0]) * cache->used);
1888 icd_free(cache->entries);
1889 }
1890
1891 cache->entries = entries;
1892 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001893 }
1894 }
1895
Chia-I Wua57761b2014-10-14 14:27:44 +08001896 /* add the shader to the cache */
1897 if (cache->used < cache->count) {
1898 cache->entries[cache->used].shader = (const void *) shader;
1899 cache->entries[cache->used].kernel_offset = offset;
1900 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001901 }
1902
Chia-I Wua57761b2014-10-14 14:27:44 +08001903 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001904}
1905
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001906static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001907{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001908 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001909
Chia-I Wu8370b402014-08-29 12:28:37 +08001910 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1911 cmd_wa_gen6_pre_depth_stall_write(cmd);
1912 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1913 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1914 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1915 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001916
1917 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001918 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001919 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001920
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001921 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001922 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001923 }
1924 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001925 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001926 }
1927 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001928 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1929 }
1930 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1931 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1932 }
1933 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1934 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001935 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001936
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001937 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1938 gen7_3DSTATE_GS(cmd);
1939 } else {
1940 gen6_3DSTATE_GS(cmd);
1941 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001942
Chia-I Wu8370b402014-08-29 12:28:37 +08001943 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1944 cmd_wa_gen7_post_command_cs_stall(cmd);
1945 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1946 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001947}
1948
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001949static void emit_bounded_states(struct intel_cmd *cmd)
1950{
1951 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1952
1953 emit_graphics_pipeline(cmd);
1954
1955 emit_rt(cmd);
1956 emit_ds(cmd);
1957
1958 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1959 gen7_cc_states(cmd);
1960 gen7_viewport_states(cmd);
1961
1962 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1963 &cmd->bind.pipeline.graphics->vs);
1964 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1965 &cmd->bind.pipeline.graphics->fs);
1966
1967 gen6_3DSTATE_CLIP(cmd);
1968 gen7_3DSTATE_SF(cmd);
1969 gen7_3DSTATE_SBE(cmd);
1970 gen7_3DSTATE_WM(cmd);
1971 gen7_3DSTATE_PS(cmd);
1972 } else {
1973 gen6_cc_states(cmd);
1974 gen6_viewport_states(cmd);
1975
1976 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1977 &cmd->bind.pipeline.graphics->vs);
1978 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1979 &cmd->bind.pipeline.graphics->fs);
1980
1981 gen6_3DSTATE_CLIP(cmd);
1982 gen6_3DSTATE_SF(cmd);
1983 gen6_3DSTATE_WM(cmd);
1984 }
1985
1986 emit_shader_resources(cmd);
1987
1988 cmd_wa_gen6_pre_depth_stall_write(cmd);
1989 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1990
1991 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
1992 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
1993
1994 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1995 gen6_3DSTATE_VS(cmd);
1996}
1997
Chia-I Wu6032b892014-10-17 14:47:18 +08001998static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
1999{
2000 const struct intel_cmd_meta *meta = cmd->bind.meta;
2001 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2002
2003 CMD_ASSERT(cmd, 6, 7.5);
2004
2005 blend_offset = 0;
2006 ds_offset = 0;
2007 cc_offset = 0;
2008 cc_vp_offset = 0;
2009
2010 if (meta->dst.valid) {
2011 /* BLEND_STATE */
2012 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
2013 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2014 dw[0] = 0;
2015 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2016 }
2017
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002018 if (meta->ds.state) {
2019 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002020
2021 /* DEPTH_STENCIL_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002022 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002023
2024 /* COLOR_CALC_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002025 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2026 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002027
2028 /* CC_VIEWPORT */
2029 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
2030 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002031 dw[0] = u_fui(0.0f);
2032 dw[1] = u_fui(1.0f);
Chia-I Wua667c2b2014-10-28 11:40:29 +08002033 } else {
2034 /* DEPTH_STENCIL_STATE */
2035 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2036 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4,
2037 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2038 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
Chia-I Wu6032b892014-10-17 14:47:18 +08002039 }
2040
2041 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2042 gen7_3dstate_pointer(cmd,
2043 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2044 blend_offset);
2045 gen7_3dstate_pointer(cmd,
2046 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2047 ds_offset);
2048 gen7_3dstate_pointer(cmd,
2049 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2050
2051 gen7_3dstate_pointer(cmd,
2052 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2053 cc_vp_offset);
2054 } else {
2055 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002056 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002057
2058 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2059 cmd_batch_pointer(cmd, 4, &dw);
2060 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2061 GEN6_PTR_VP_DW0_CC_CHANGED;
2062 dw[1] = 0;
2063 dw[2] = 0;
2064 dw[3] = cc_vp_offset;
2065 }
2066}
2067
2068static void gen6_meta_surface_states(struct intel_cmd *cmd)
2069{
2070 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002071 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002072 uint32_t offset;
2073
2074 CMD_ASSERT(cmd, 6, 7.5);
2075
Chia-I Wu005c47c2014-10-22 13:49:13 +08002076 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002077 if (meta->src.valid) {
2078 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2079 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2080 meta->src.surface_len, meta->src.surface);
2081
2082 cmd_reserve_reloc(cmd, 1);
2083 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2084 cmd_surface_reloc_writer(cmd, offset, 1,
2085 meta->src.reloc_target, meta->src.reloc_offset);
2086 } else {
2087 cmd_surface_reloc(cmd, offset, 1,
2088 (struct intel_bo *) meta->src.reloc_target,
2089 meta->src.reloc_offset, meta->src.reloc_flags);
2090 }
2091
Chia-I Wu005c47c2014-10-22 13:49:13 +08002092 binding_table[0] = offset;
2093 }
2094 if (meta->dst.valid) {
2095 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2096 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2097 meta->dst.surface_len, meta->dst.surface);
2098
2099 cmd_reserve_reloc(cmd, 1);
2100 cmd_surface_reloc(cmd, offset, 1,
2101 (struct intel_bo *) meta->dst.reloc_target,
2102 meta->dst.reloc_offset, meta->dst.reloc_flags);
2103
2104 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002105 }
2106
2107 /* BINDING_TABLE */
2108 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
2109 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002110 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002111
2112 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2113 gen7_3dstate_pointer(cmd,
2114 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2115 offset);
2116 } else {
2117 /* 3DSTATE_BINDING_TABLE_POINTERS */
2118 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
2119 }
2120}
2121
2122static void gen6_meta_urb(struct intel_cmd *cmd)
2123{
2124 uint32_t *dw;
2125
2126 CMD_ASSERT(cmd, 6, 6);
2127
2128 /* 3DSTATE_URB */
2129 cmd_batch_pointer(cmd, 3, &dw);
2130 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
2131 dw[1] = 128 << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
2132 dw[2] = 0;
2133}
2134
2135static void gen7_meta_urb(struct intel_cmd *cmd)
2136{
2137 uint32_t *dw;
2138
2139 CMD_ASSERT(cmd, 7, 7.5);
2140
2141 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2142 cmd_batch_pointer(cmd, 10, &dw);
2143
2144 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
2145 dw[1] = 0;
2146 dw += 2;
2147
2148 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2149 dw[1] = 0;
2150 dw += 2;
2151
2152 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2153 dw[1] = 0;
2154 dw += 2;
2155
2156 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2157 dw[1] = 0;
2158 dw += 2;
2159
2160 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2161 dw[1] = 1;
2162
2163 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2164
2165 /* 3DSTATE_URB_x */
2166 cmd_batch_pointer(cmd, 8, &dw);
2167
2168 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2169 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
2170 512;
2171 dw += 2;
2172
2173 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2174 dw[1] = 0;
2175 dw += 2;
2176
2177 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2178 dw[1] = 0;
2179 dw += 2;
2180
2181 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2182 dw[1] = 0;
2183 dw += 2;
2184}
2185
2186static void gen6_meta_vf(struct intel_cmd *cmd)
2187{
2188 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002189 uint32_t vb_start, vb_end, vb_stride;
2190 int ve_format, ve_z_source;
2191 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002192 XGL_UINT pos;
2193
2194 CMD_ASSERT(cmd, 6, 7.5);
2195
2196 /* write vertices */
Chia-I Wu3adf7212014-10-24 15:34:07 +08002197 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2198 XGL_FLOAT vertices[3][3];
2199
2200 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2201 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2202 vertices[0][2] = u_uif(meta->clear_val[0]);
2203 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2204 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2205 vertices[1][2] = u_uif(meta->clear_val[0]);
2206 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2207 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2208 vertices[2][2] = u_uif(meta->clear_val[0]);
2209
2210 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2211 sizeof(vertices) / 4, (const uint32_t *) vertices);
2212
2213 vb_end = vb_start + sizeof(vertices) - 1;
2214 vb_stride = sizeof(vertices[0]);
2215 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2216 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2217 } else {
2218 XGL_UINT vertices[3][2];
2219
2220 vertices[0][0] = meta->dst.x + meta->width;
2221 vertices[0][1] = meta->dst.y + meta->height;
2222 vertices[1][0] = meta->dst.x;
2223 vertices[1][1] = meta->dst.y + meta->height;
2224 vertices[2][0] = meta->dst.x;
2225 vertices[2][1] = meta->dst.y;
2226
2227 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2228 sizeof(vertices) / 4, (const uint32_t *) vertices);
2229
2230 vb_end = vb_start + sizeof(vertices) - 1;
2231 vb_stride = sizeof(vertices[0]);
2232 ve_z_source = GEN6_VFCOMP_STORE_0;
2233 ve_format = GEN6_FORMAT_R32G32_USCALED;
2234 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002235
2236 /* 3DSTATE_VERTEX_BUFFERS */
2237 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002238
Chia-I Wu6032b892014-10-17 14:47:18 +08002239 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002240 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002241 if (cmd_gen(cmd) >= INTEL_GEN(7))
2242 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2243
2244 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002245 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2246 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002247
2248 dw[4] = 0;
2249
2250 /* 3DSTATE_VERTEX_ELEMENTS */
2251 cmd_batch_pointer(cmd, 5, &dw);
2252 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
2253 dw[1] = GEN6_VE_STATE_DW0_VALID,
2254 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2255 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2256 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2257 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2258 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002259 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002260 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2261 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002262 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002263 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2264}
2265
2266static void gen6_meta_disabled(struct intel_cmd *cmd)
2267{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002268 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002269 uint32_t *dw;
2270
2271 CMD_ASSERT(cmd, 6, 6);
2272
2273 /* 3DSTATE_CONSTANT_VS */
2274 cmd_batch_pointer(cmd, 5, &dw);
2275 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2);
2276 dw[1] = 0;
2277 dw[2] = 0;
2278 dw[3] = 0;
2279 dw[4] = 0;
2280
2281 /* 3DSTATE_VS */
2282 cmd_batch_pointer(cmd, 6, &dw);
2283 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2284 dw[1] = 0;
2285 dw[2] = 0;
2286 dw[3] = 0;
2287 dw[4] = 0;
2288 dw[5] = 0;
2289
2290 /* 3DSTATE_CONSTANT_GS */
2291 cmd_batch_pointer(cmd, 5, &dw);
2292 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2293 dw[1] = 0;
2294 dw[2] = 0;
2295 dw[3] = 0;
2296 dw[4] = 0;
2297
2298 /* 3DSTATE_GS */
2299 cmd_batch_pointer(cmd, 7, &dw);
2300 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2301 dw[1] = 0;
2302 dw[2] = 0;
2303 dw[3] = 0;
2304 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2305 dw[5] = GEN6_GS_DW5_STATISTICS;
2306 dw[6] = 0;
2307
2308 /* 3DSTATE_CLIP */
2309 cmd_batch_pointer(cmd, 4, &dw);
2310 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2311 dw[1] = 0;
2312 dw[2] = 0;
2313 dw[3] = 0;
2314
2315 /* 3DSTATE_SF */
2316 cmd_batch_pointer(cmd, 20, &dw);
2317 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2318 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2319 memset(&dw[2], 0, 18 * sizeof(*dw));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002320
2321 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2322 /* 3DSTATE_CONSTANT_PS */
2323 cmd_batch_pointer(cmd, 5, &dw);
2324 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2325 dw[1] = 0;
2326 dw[2] = 0;
2327 dw[3] = 0;
2328 dw[4] = 0;
2329
2330 /* 3DSTATE_WM */
2331 cmd_batch_pointer(cmd, 9, &dw);
2332 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2333 dw[1] = 0;
2334 dw[2] = 0;
2335 dw[3] = 0;
2336 dw[4] = 0;
2337 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
2338 dw[6] = 0;
2339 dw[7] = 0;
2340 dw[8] = 0;
2341 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002342}
2343
2344static void gen7_meta_disabled(struct intel_cmd *cmd)
2345{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002346 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002347 uint32_t *dw;
2348
2349 CMD_ASSERT(cmd, 7, 7.5);
2350
2351 /* 3DSTATE_CONSTANT_VS */
2352 cmd_batch_pointer(cmd, 7, &dw);
2353 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2354 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2355
2356 /* 3DSTATE_VS */
2357 cmd_batch_pointer(cmd, 6, &dw);
2358 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2359 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2360
2361 /* 3DSTATE_CONSTANT_HS */
2362 cmd_batch_pointer(cmd, 7, &dw);
2363 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2364 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2365
2366 /* 3DSTATE_HS */
2367 cmd_batch_pointer(cmd, 7, &dw);
2368 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2369 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2370
2371 /* 3DSTATE_TE */
2372 cmd_batch_pointer(cmd, 4, &dw);
2373 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2374 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2375
2376 /* 3DSTATE_CONSTANT_DS */
2377 cmd_batch_pointer(cmd, 7, &dw);
2378 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2379 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2380
2381 /* 3DSTATE_DS */
2382 cmd_batch_pointer(cmd, 6, &dw);
2383 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2384 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2385
2386 /* 3DSTATE_CONSTANT_GS */
2387 cmd_batch_pointer(cmd, 7, &dw);
2388 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2389 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2390
2391 /* 3DSTATE_GS */
2392 cmd_batch_pointer(cmd, 7, &dw);
2393 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2394 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2395
2396 /* 3DSTATE_STREAMOUT */
2397 cmd_batch_pointer(cmd, 3, &dw);
2398 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2399 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2400
2401 /* 3DSTATE_CLIP */
2402 cmd_batch_pointer(cmd, 4, &dw);
2403 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2404 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2405
2406 /* 3DSTATE_SF */
2407 cmd_batch_pointer(cmd, 7, &dw);
2408 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2409 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2410
2411 /* 3DSTATE_SBE */
2412 cmd_batch_pointer(cmd, 14, &dw);
2413 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2414 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2415 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002416
2417 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2418 /* 3DSTATE_WM */
2419 cmd_batch_pointer(cmd, 3, &dw);
2420 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2421 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2422
2423 /* 3DSTATE_CONSTANT_GS */
2424 cmd_batch_pointer(cmd, 7, &dw);
2425 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2426 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2427
2428 /* 3DSTATE_PS */
2429 cmd_batch_pointer(cmd, 8, &dw);
2430 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2431 dw[1] = 0;
2432 dw[2] = 0;
2433 dw[3] = 0;
2434 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
2435 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2436 dw[5] = 0;
2437 dw[6] = 0;
2438 dw[7] = 0;
2439 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002440}
2441
2442static void gen6_meta_wm(struct intel_cmd *cmd)
2443{
2444 const struct intel_cmd_meta *meta = cmd->bind.meta;
2445 uint32_t *dw;
2446
2447 CMD_ASSERT(cmd, 6, 7.5);
2448
2449 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2450
2451 /* 3DSTATE_MULTISAMPLE */
2452 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2453 cmd_batch_pointer(cmd, 4, &dw);
2454 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2455 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2456 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2457 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2458 dw[2] = 0;
2459 dw[3] = 0;
2460 } else {
2461 cmd_batch_pointer(cmd, 3, &dw);
2462 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2463 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2464 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2465 dw[2] = 0;
2466 }
2467
2468 /* 3DSTATE_SAMPLE_MASK */
2469 cmd_batch_pointer(cmd, 2, &dw);
2470 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2471 dw[1] = (1 << meta->samples) - 1;
2472
2473 /* 3DSTATE_DRAWING_RECTANGLE */
2474 cmd_batch_pointer(cmd, 4, &dw);
2475 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2476 dw[1] = meta->dst.y << 16 | meta->dst.x;
2477 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2478 (meta->dst.x + meta->width - 1);
2479 dw[3] = 0;
2480}
2481
2482static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2483{
2484 const struct intel_cmd_meta *meta = cmd->bind.meta;
2485 XGL_UINT offset_x, offset_y;
2486 /* one GPR */
2487 XGL_UINT consts[8];
2488 XGL_UINT const_count;
2489
2490 CMD_ASSERT(cmd, 6, 7.5);
2491
2492 /* underflow is fine here */
2493 offset_x = meta->src.x - meta->dst.x;
2494 offset_y = meta->src.y - meta->dst.y;
2495
2496 switch (meta->shader_id) {
2497 case INTEL_DEV_META_FS_COPY_MEM:
2498 case INTEL_DEV_META_FS_COPY_1D:
2499 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2500 case INTEL_DEV_META_FS_COPY_2D:
2501 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2502 case INTEL_DEV_META_FS_COPY_2D_MS:
2503 consts[0] = offset_x;
2504 consts[1] = offset_y;
2505 consts[2] = meta->src.layer;
2506 consts[3] = meta->src.lod;
2507 const_count = 4;
2508 break;
2509 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2510 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2511 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2512 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2513 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2514 consts[0] = offset_x;
2515 consts[1] = offset_y;
2516 consts[2] = meta->src.layer;
2517 consts[3] = meta->src.lod;
2518 consts[4] = meta->src.x;
2519 consts[5] = meta->width;
2520 const_count = 6;
2521 break;
2522 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2523 consts[0] = offset_x;
2524 consts[1] = offset_y;
2525 consts[2] = meta->width;
2526 const_count = 3;
2527 break;
2528 case INTEL_DEV_META_FS_CLEAR_COLOR:
2529 consts[0] = meta->clear_val[0];
2530 consts[1] = meta->clear_val[1];
2531 consts[2] = meta->clear_val[2];
2532 consts[3] = meta->clear_val[3];
2533 const_count = 4;
2534 break;
2535 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2536 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002537 consts[1] = meta->clear_val[1];
2538 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002539 break;
2540 case INTEL_DEV_META_FS_RESOLVE_2X:
2541 case INTEL_DEV_META_FS_RESOLVE_4X:
2542 case INTEL_DEV_META_FS_RESOLVE_8X:
2543 case INTEL_DEV_META_FS_RESOLVE_16X:
2544 consts[0] = offset_x;
2545 consts[1] = offset_y;
2546 const_count = 2;
2547 break;
2548 default:
2549 assert(!"unknown meta shader id");
2550 const_count = 0;
2551 break;
2552 }
2553
2554 /* this can be skipped but it makes state dumping prettier */
2555 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2556
2557 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2558}
2559
2560static void gen6_meta_ps(struct intel_cmd *cmd)
2561{
2562 const struct intel_cmd_meta *meta = cmd->bind.meta;
2563 const struct intel_pipeline_shader *sh =
2564 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2565 uint32_t offset, *dw;
2566
2567 CMD_ASSERT(cmd, 6, 6);
2568
Chia-I Wu3adf7212014-10-24 15:34:07 +08002569 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2570 return;
2571 /* a normal color write */
2572 assert(meta->dst.valid && !sh->uses);
2573
Chia-I Wu6032b892014-10-17 14:47:18 +08002574 /* 3DSTATE_CONSTANT_PS */
2575 offset = gen6_meta_ps_constants(cmd);
2576 cmd_batch_pointer(cmd, 5, &dw);
2577 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2578 GEN6_PCB_ANY_DW0_PCB0_VALID;
2579 dw[1] = offset;
2580 dw[2] = 0;
2581 dw[3] = 0;
2582 dw[4] = 0;
2583
2584 /* 3DSTATE_WM */
2585 offset = emit_shader(cmd, sh);
2586 cmd_batch_pointer(cmd, 9, &dw);
2587 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2588 dw[1] = offset;
2589 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2590 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2591 dw[3] = 0;
2592 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
2593 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
2594 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002595 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2596
Chia-I Wu6032b892014-10-17 14:47:18 +08002597 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2598 GEN6_WM_DW6_POSOFFSET_NONE |
2599 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2600 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2601 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2602 if (meta->samples > 1) {
2603 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2604 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2605 } else {
2606 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2607 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2608 }
2609 dw[7] = 0;
2610 dw[8] = 0;
2611}
2612
2613static void gen7_meta_ps(struct intel_cmd *cmd)
2614{
2615 const struct intel_cmd_meta *meta = cmd->bind.meta;
2616 const struct intel_pipeline_shader *sh =
2617 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2618 uint32_t offset, *dw;
2619
2620 CMD_ASSERT(cmd, 7, 7.5);
2621
Chia-I Wu3adf7212014-10-24 15:34:07 +08002622 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2623 return;
2624 /* a normal color write */
2625 assert(meta->dst.valid && !sh->uses);
2626
Chia-I Wu6032b892014-10-17 14:47:18 +08002627 /* 3DSTATE_WM */
2628 cmd_batch_pointer(cmd, 3, &dw);
2629 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2630 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2631 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2632 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2633 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2634 dw[2] = 0;
2635
2636 /* 3DSTATE_CONSTANT_PS */
2637 offset = gen6_meta_ps_constants(cmd);
2638 cmd_batch_pointer(cmd, 7, &dw);
2639 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2640 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2641 dw[2] = 0;
2642 dw[3] = offset;
2643 dw[4] = 0;
2644 dw[5] = 0;
2645 dw[6] = 0;
2646
2647 /* 3DSTATE_PS */
2648 offset = emit_shader(cmd, sh);
2649 cmd_batch_pointer(cmd, 8, &dw);
2650 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2651 dw[1] = offset;
2652 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2653 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2654 dw[3] = 0;
2655
2656 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2657 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002658 GEN7_PS_DW4_16_PIXEL_DISPATCH |
Chia-I Wu6032b892014-10-17 14:47:18 +08002659 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2660 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
2661 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
2662
2663 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2664 dw[6] = 0;
2665 dw[7] = 0;
2666}
2667
2668static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2669{
2670 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002671 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002672
2673 CMD_ASSERT(cmd, 6, 7.5);
2674
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002675 if (!ds) {
2676 /* all zeros */
2677 static const struct intel_ds_view null_ds;
2678 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002679 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002680
2681 cmd_wa_gen6_pre_ds_flush(cmd);
2682 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2683 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2684 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2685
2686 if (cmd_gen(cmd) >= INTEL_GEN(7))
2687 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2688 else
2689 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002690}
2691
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002692static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2693 const struct intel_pipeline *pipeline)
2694{
2695 cmd->bind.pipeline.graphics = pipeline;
2696}
2697
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002698static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2699 const struct intel_pipeline *pipeline)
2700{
2701 cmd->bind.pipeline.compute = pipeline;
2702}
2703
2704static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2705 const struct intel_pipeline_delta *delta)
2706{
2707 cmd->bind.pipeline.graphics_delta = delta;
2708}
2709
2710static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2711 const struct intel_pipeline_delta *delta)
2712{
2713 cmd->bind.pipeline.compute_delta = delta;
2714}
2715
2716static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2717 const struct intel_dset *dset,
2718 XGL_UINT slot_offset)
2719{
2720 cmd->bind.dset.graphics = dset;
2721 cmd->bind.dset.graphics_offset = slot_offset;
2722}
2723
2724static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2725 const struct intel_dset *dset,
2726 XGL_UINT slot_offset)
2727{
2728 cmd->bind.dset.compute = dset;
2729 cmd->bind.dset.compute_offset = slot_offset;
2730}
2731
2732static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2733 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2734{
2735 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2736}
2737
2738static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2739 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2740{
2741 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2742}
2743
Chia-I Wu3b04af52014-11-08 10:48:20 +08002744static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2745 const struct intel_mem *mem,
2746 XGL_GPU_SIZE offset, XGL_UINT binding)
2747{
2748 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2749 cmd->result = XGL_ERROR_UNKNOWN;
2750 return;
2751 }
2752
2753 cmd->bind.vertex.mem[binding] = mem;
2754 cmd->bind.vertex.offset[binding] = offset;
2755}
2756
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002757static void cmd_bind_index_data(struct intel_cmd *cmd,
2758 const struct intel_mem *mem,
2759 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2760{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002761 cmd->bind.index.mem = mem;
2762 cmd->bind.index.offset = offset;
2763 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002764}
2765
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002766static void cmd_bind_attachments(struct intel_cmd *cmd,
2767 XGL_UINT rt_count,
2768 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2769 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002770{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002771 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002772 XGL_UINT i;
2773
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002774 for (i = 0; i < rt_count; i++) {
2775 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002776 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002777 const struct intel_layout *layout = &rt->img->layout;
2778
2779 if (i == 0) {
2780 width = layout->width0;
2781 height = layout->height0;
2782 } else {
2783 if (width > layout->width0)
2784 width = layout->width0;
2785 if (height > layout->height0)
2786 height = layout->height0;
2787 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002788
2789 cmd->bind.att.rt[i] = rt;
2790 }
2791
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002792 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002793
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002794 if (ds_info) {
2795 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002796
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002797 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2798 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002799
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002800 if (width > layout->width0)
2801 width = layout->width0;
2802 if (height > layout->height0)
2803 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002804 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002805 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002806 }
2807
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002808 cmd->bind.att.width = width;
2809 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002810}
2811
2812static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2813 const struct intel_viewport_state *state)
2814{
2815 cmd->bind.state.viewport = state;
2816}
2817
2818static void cmd_bind_raster_state(struct intel_cmd *cmd,
2819 const struct intel_raster_state *state)
2820{
2821 cmd->bind.state.raster = state;
2822}
2823
2824static void cmd_bind_ds_state(struct intel_cmd *cmd,
2825 const struct intel_ds_state *state)
2826{
2827 cmd->bind.state.ds = state;
2828}
2829
2830static void cmd_bind_blend_state(struct intel_cmd *cmd,
2831 const struct intel_blend_state *state)
2832{
2833 cmd->bind.state.blend = state;
2834}
2835
2836static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2837 const struct intel_msaa_state *state)
2838{
2839 cmd->bind.state.msaa = state;
2840}
2841
2842static void cmd_draw(struct intel_cmd *cmd,
2843 XGL_UINT vertex_start,
2844 XGL_UINT vertex_count,
2845 XGL_UINT instance_start,
2846 XGL_UINT instance_count,
2847 bool indexed,
2848 XGL_UINT vertex_base)
2849{
2850 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2851
2852 emit_bounded_states(cmd);
2853
2854 if (indexed) {
2855 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2856 cmd->result = XGL_ERROR_UNKNOWN;
2857
2858 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2859 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2860 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002861 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2862 cmd->bind.index.offset, cmd->bind.index.type,
2863 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002864 } else {
2865 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2866 cmd->bind.index.offset, cmd->bind.index.type,
2867 p->primitive_restart);
2868 }
2869 } else {
2870 assert(!vertex_base);
2871 }
2872
2873 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2874 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2875 vertex_start, instance_count, instance_start, vertex_base);
2876 } else {
2877 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2878 vertex_start, instance_count, instance_start, vertex_base);
2879 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002880
Chia-I Wu707a29e2014-08-27 12:51:47 +08002881 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002882 /* need to re-emit all workarounds */
2883 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08002884
2885 if (intel_debug & INTEL_DEBUG_NOCACHE)
2886 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002887}
2888
Chia-I Wuc14d1562014-10-17 09:49:22 +08002889void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2890{
Chia-I Wu6032b892014-10-17 14:47:18 +08002891 cmd->bind.meta = meta;
2892
2893 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08002894 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002895
2896 gen6_meta_dynamic_states(cmd);
2897 gen6_meta_surface_states(cmd);
2898
2899 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2900 gen7_meta_urb(cmd);
2901 gen6_meta_vf(cmd);
2902 gen7_meta_disabled(cmd);
2903 gen6_meta_wm(cmd);
2904 gen7_meta_ps(cmd);
2905 gen6_meta_depth_buffer(cmd);
2906
2907 cmd_wa_gen7_post_command_cs_stall(cmd);
2908 cmd_wa_gen7_post_command_depth_stall(cmd);
2909
2910 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2911 } else {
2912 gen6_meta_urb(cmd);
2913 gen6_meta_vf(cmd);
2914 gen6_meta_disabled(cmd);
2915 gen6_meta_wm(cmd);
2916 gen6_meta_ps(cmd);
2917 gen6_meta_depth_buffer(cmd);
2918
2919 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2920 }
2921
2922 cmd->bind.draw_count++;
2923 /* need to re-emit all workarounds */
2924 cmd->bind.wa_flags = 0;
2925
2926 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08002927
2928 if (intel_debug & INTEL_DEBUG_NOCACHE)
2929 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08002930}
2931
Chia-I Wub2755562014-08-20 13:38:52 +08002932XGL_VOID XGLAPI intelCmdBindPipeline(
2933 XGL_CMD_BUFFER cmdBuffer,
2934 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2935 XGL_PIPELINE pipeline)
2936{
2937 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2938
2939 switch (pipelineBindPoint) {
2940 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002941 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002942 break;
2943 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002944 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002945 break;
2946 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002947 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002948 break;
2949 }
2950}
2951
2952XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2953 XGL_CMD_BUFFER cmdBuffer,
2954 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2955 XGL_PIPELINE_DELTA delta)
2956{
2957 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2958
2959 switch (pipelineBindPoint) {
2960 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002961 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002962 break;
2963 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002964 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002965 break;
2966 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002967 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002968 break;
2969 }
2970}
2971
2972XGL_VOID XGLAPI intelCmdBindStateObject(
2973 XGL_CMD_BUFFER cmdBuffer,
2974 XGL_STATE_BIND_POINT stateBindPoint,
2975 XGL_STATE_OBJECT state)
2976{
2977 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2978
2979 switch (stateBindPoint) {
2980 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002981 cmd_bind_viewport_state(cmd,
2982 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002983 break;
2984 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002985 cmd_bind_raster_state(cmd,
2986 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002987 break;
2988 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002989 cmd_bind_ds_state(cmd,
2990 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002991 break;
2992 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002993 cmd_bind_blend_state(cmd,
2994 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002995 break;
2996 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002997 cmd_bind_msaa_state(cmd,
2998 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002999 break;
3000 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003001 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003002 break;
3003 }
3004}
3005
3006XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3007 XGL_CMD_BUFFER cmdBuffer,
3008 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3009 XGL_UINT index,
3010 XGL_DESCRIPTOR_SET descriptorSet,
3011 XGL_UINT slotOffset)
3012{
3013 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3014 struct intel_dset *dset = intel_dset(descriptorSet);
3015
3016 assert(!index);
3017
3018 switch (pipelineBindPoint) {
3019 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003020 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003021 break;
3022 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003023 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003024 break;
3025 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003026 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003027 break;
3028 }
3029}
3030
3031XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3032 XGL_CMD_BUFFER cmdBuffer,
3033 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3034 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3035{
3036 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3037
3038 switch (pipelineBindPoint) {
3039 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003040 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003041 break;
3042 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003043 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003044 break;
3045 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003046 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003047 break;
3048 }
3049}
3050
Chia-I Wu3b04af52014-11-08 10:48:20 +08003051XGL_VOID XGLAPI intelCmdBindVertexData(
3052 XGL_CMD_BUFFER cmdBuffer,
3053 XGL_GPU_MEMORY mem_,
3054 XGL_GPU_SIZE offset,
3055 XGL_UINT binding)
3056{
3057 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3058 struct intel_mem *mem = intel_mem(mem_);
3059
3060 cmd_bind_vertex_data(cmd, mem, offset, binding);
3061}
3062
Chia-I Wub2755562014-08-20 13:38:52 +08003063XGL_VOID XGLAPI intelCmdBindIndexData(
3064 XGL_CMD_BUFFER cmdBuffer,
3065 XGL_GPU_MEMORY mem_,
3066 XGL_GPU_SIZE offset,
3067 XGL_INDEX_TYPE indexType)
3068{
3069 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3070 struct intel_mem *mem = intel_mem(mem_);
3071
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003072 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003073}
3074
3075XGL_VOID XGLAPI intelCmdBindAttachments(
3076 XGL_CMD_BUFFER cmdBuffer,
3077 XGL_UINT colorAttachmentCount,
3078 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3079 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3080{
3081 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003082
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003083 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3084 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003085}
3086
3087XGL_VOID XGLAPI intelCmdDraw(
3088 XGL_CMD_BUFFER cmdBuffer,
3089 XGL_UINT firstVertex,
3090 XGL_UINT vertexCount,
3091 XGL_UINT firstInstance,
3092 XGL_UINT instanceCount)
3093{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003094 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003095
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003096 cmd_draw(cmd, firstVertex, vertexCount,
3097 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003098}
3099
3100XGL_VOID XGLAPI intelCmdDrawIndexed(
3101 XGL_CMD_BUFFER cmdBuffer,
3102 XGL_UINT firstIndex,
3103 XGL_UINT indexCount,
3104 XGL_INT vertexOffset,
3105 XGL_UINT firstInstance,
3106 XGL_UINT instanceCount)
3107{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003108 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003109
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003110 cmd_draw(cmd, firstIndex, indexCount,
3111 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003112}
3113
3114XGL_VOID XGLAPI intelCmdDrawIndirect(
3115 XGL_CMD_BUFFER cmdBuffer,
3116 XGL_GPU_MEMORY mem,
3117 XGL_GPU_SIZE offset,
3118 XGL_UINT32 count,
3119 XGL_UINT32 stride)
3120{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003121 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3122
3123 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003124}
3125
3126XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3127 XGL_CMD_BUFFER cmdBuffer,
3128 XGL_GPU_MEMORY mem,
3129 XGL_GPU_SIZE offset,
3130 XGL_UINT32 count,
3131 XGL_UINT32 stride)
3132{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003133 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3134
3135 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003136}
3137
3138XGL_VOID XGLAPI intelCmdDispatch(
3139 XGL_CMD_BUFFER cmdBuffer,
3140 XGL_UINT x,
3141 XGL_UINT y,
3142 XGL_UINT z)
3143{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003144 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3145
3146 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003147}
3148
3149XGL_VOID XGLAPI intelCmdDispatchIndirect(
3150 XGL_CMD_BUFFER cmdBuffer,
3151 XGL_GPU_MEMORY mem,
3152 XGL_GPU_SIZE offset)
3153{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003154 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3155
3156 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003157}