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