blob: 4d36a4df1184ec9042a122362d107eef944dae88 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080030#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080031#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080032#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080033#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080034#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080035#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080036#include "state.h"
37#include "view.h"
38#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070039#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080040
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:
Courtney Goeltzenleuchterd65a16f2015-01-06 15:19:38 -0700404 assert(!cmd->bind.att.ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800405 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{
GregF8cd81832014-11-18 18:01:01 -0700447 XGL_UINT sbe_offset;
448 XGL_INT i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449
450 CMD_ASSERT(cmd, 6, 7.5);
451
GregF8cd81832014-11-18 18:01:01 -0700452 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800453
GregF8cd81832014-11-18 18:01:01 -0700454 for (i = 0; i < 13; i++) {
455 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
456 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800457 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800458}
459
460static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
461{
462 const uint8_t cmd_len = 20;
463 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
464 (cmd_len - 2);
465 uint32_t sf[6];
466 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800467 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800468
469 CMD_ASSERT(cmd, 6, 6);
470
471 gen7_fill_3DSTATE_SF_body(cmd, sf);
472 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
473
Chia-I Wu72292b72014-09-09 10:48:33 +0800474 cmd_batch_pointer(cmd, cmd_len, &dw);
475 dw[0] = dw0;
476 dw[1] = sbe[0];
477 memcpy(&dw[2], sf, sizeof(sf));
478 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800479}
480
481static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
482{
483 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800484 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800485
486 CMD_ASSERT(cmd, 7, 7.5);
487
Chia-I Wu72292b72014-09-09 10:48:33 +0800488 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800489 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
490 (cmd_len - 2);
491 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800492}
493
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800494static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
495{
496 const uint8_t cmd_len = 4;
497 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
498 (cmd_len - 2);
499 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700500 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800501 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800502 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
503 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800504 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800505
506 CMD_ASSERT(cmd, 6, 7.5);
507
508 dw1 = GEN6_CLIP_DW1_STATISTICS;
509 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
510 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
511 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
512 raster->cmd_clip_cull;
513 }
514
515 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
516 GEN6_CLIP_DW2_XY_TEST_ENABLE |
517 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700518 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800519 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
520 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
521 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
522
523 if (pipeline->rasterizerDiscardEnable)
524 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
525 else
526 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
527
528 if (pipeline->depthClipEnable)
529 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
530
531 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
532 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
533 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
534 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
535
536 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
537 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
538 (viewport->viewport_count - 1);
539
Chia-I Wu72292b72014-09-09 10:48:33 +0800540 cmd_batch_pointer(cmd, cmd_len, &dw);
541 dw[0] = dw0;
542 dw[1] = dw1;
543 dw[2] = dw2;
544 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800545}
546
Chia-I Wu784d3042014-12-19 14:30:04 +0800547static void gen6_add_scratch_space(struct intel_cmd *cmd,
548 XGL_UINT batch_pos,
549 const struct intel_pipeline *pipeline,
550 const struct intel_pipeline_shader *sh)
551{
552 int scratch_space;
553
554 CMD_ASSERT(cmd, 6, 7.5);
555
556 assert(sh->per_thread_scratch_size &&
557 sh->per_thread_scratch_size % 1024 == 0 &&
558 u_is_pow2(sh->per_thread_scratch_size) &&
559 sh->scratch_offset % 1024 == 0);
560 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
561
562 cmd_reserve_reloc(cmd, 1);
563 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
564 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
565}
566
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800567static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
568{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800569 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800570 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800571 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
572 const uint8_t cmd_len = 9;
Chia-I Wu784d3042014-12-19 14:30:04 +0800573 XGL_UINT pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800574 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800575
576 CMD_ASSERT(cmd, 6, 6);
577
578 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
579
580 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
581 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
582
583 dw4 = GEN6_WM_DW4_STATISTICS |
584 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
585 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
586 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
587
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800588 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800589 GEN6_WM_DW5_PS_ENABLE |
590 GEN6_WM_DW5_8_PIXEL_DISPATCH;
591
592 if (fs->uses & INTEL_SHADER_USE_KILL ||
593 pipeline->cb_state.alphaToCoverageEnable)
594 dw5 |= GEN6_WM_DW5_PS_KILL;
595
Cody Northrope238deb2015-01-26 14:41:36 -0700596 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800597 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
598 if (fs->uses & INTEL_SHADER_USE_DEPTH)
599 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
600 if (fs->uses & INTEL_SHADER_USE_W)
601 dw5 |= GEN6_WM_DW5_PS_USE_W;
602
603 if (pipeline->cb_state.dualSourceBlendEnable)
604 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
605
606 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
607 GEN6_WM_DW6_POSOFFSET_NONE |
608 GEN6_WM_DW6_ZW_INTERP_PIXEL |
609 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
610 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
611
612 if (msaa->sample_count > 1) {
613 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
614 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
615 } else {
616 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
617 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
618 }
619
Chia-I Wu784d3042014-12-19 14:30:04 +0800620 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800621 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800622 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800623 dw[2] = dw2;
624 dw[3] = 0; /* scratch */
625 dw[4] = dw4;
626 dw[5] = dw5;
627 dw[6] = dw6;
628 dw[7] = 0; /* kernel 1 */
629 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800630
631 if (fs->per_thread_scratch_size)
632 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800633}
634
635static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
636{
637 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800638 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800639 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
640 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800641 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800642
643 CMD_ASSERT(cmd, 7, 7.5);
644
645 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
646
647 dw1 = GEN7_WM_DW1_STATISTICS |
648 GEN7_WM_DW1_PS_ENABLE |
649 GEN7_WM_DW1_ZW_INTERP_PIXEL |
650 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
651 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
652
653 if (fs->uses & INTEL_SHADER_USE_KILL ||
654 pipeline->cb_state.alphaToCoverageEnable)
655 dw1 |= GEN7_WM_DW1_PS_KILL;
656
Cody Northrope238deb2015-01-26 14:41:36 -0700657 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
658
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800659 if (fs->uses & INTEL_SHADER_USE_DEPTH)
660 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
661 if (fs->uses & INTEL_SHADER_USE_W)
662 dw1 |= GEN7_WM_DW1_PS_USE_W;
663
664 dw2 = 0;
665
666 if (msaa->sample_count > 1) {
667 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
668 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
669 } else {
670 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
671 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
672 }
673
Chia-I Wu72292b72014-09-09 10:48:33 +0800674 cmd_batch_pointer(cmd, cmd_len, &dw);
675 dw[0] = dw0;
676 dw[1] = dw1;
677 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800678}
679
680static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
681{
682 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800683 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800684 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
685 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800686 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +0800687 XGL_UINT pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688
689 CMD_ASSERT(cmd, 7, 7.5);
690
691 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
692
693 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
694 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
695
696 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
697 GEN7_PS_DW4_8_PIXEL_DISPATCH;
698
699 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800700 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800701 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
702 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800703 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 }
705
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800706 if (fs->in_count)
707 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
708
709 if (pipeline->cb_state.dualSourceBlendEnable)
710 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
711
712 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
713 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
714 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
715
Chia-I Wu784d3042014-12-19 14:30:04 +0800716 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800718 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800719 dw[2] = dw2;
720 dw[3] = 0; /* scratch */
721 dw[4] = dw4;
722 dw[5] = dw5;
723 dw[6] = 0; /* kernel 1 */
724 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800725
726 if (fs->per_thread_scratch_size)
727 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800728}
729
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800730static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
731 const struct intel_ds_view *view)
732{
733 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800734 uint32_t dw0, *dw;
735 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800736
737 CMD_ASSERT(cmd, 6, 7.5);
738
739 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800740 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
741 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800742 dw0 |= (cmd_len - 2);
743
Chia-I Wu72292b72014-09-09 10:48:33 +0800744 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
745 dw[0] = dw0;
746 dw[1] = view->cmd[0];
747 dw[2] = 0;
748 dw[3] = view->cmd[2];
749 dw[4] = view->cmd[3];
750 dw[5] = view->cmd[4];
751 dw[6] = view->cmd[5];
752
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600753 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800754 cmd_reserve_reloc(cmd, 1);
755 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
756 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600757 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800758}
759
760static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
761 const struct intel_ds_view *view)
762{
763 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800764 uint32_t dw0, *dw;
765 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800766
767 CMD_ASSERT(cmd, 6, 7.5);
768
769 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800770 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
771 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800772 dw0 |= (cmd_len - 2);
773
Chia-I Wu72292b72014-09-09 10:48:33 +0800774 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
775 dw[0] = dw0;
776 dw[1] = view->cmd[6];
777 dw[2] = 0;
778
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600779 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800780 cmd_reserve_reloc(cmd, 1);
781 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
782 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600783 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800784}
785
786static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
787 const struct intel_ds_view *view)
788{
789 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 uint32_t dw0, *dw;
791 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800792
793 CMD_ASSERT(cmd, 6, 7.5);
794
795 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800796 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
797 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800798 dw0 |= (cmd_len - 2);
799
Chia-I Wu72292b72014-09-09 10:48:33 +0800800 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
801 dw[0] = dw0;
802 dw[1] = view->cmd[8];
803 dw[2] = 0;
804
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600805 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 cmd_reserve_reloc(cmd, 1);
807 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
808 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600809 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810}
811
Chia-I Wuf8231032014-08-25 10:44:45 +0800812static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
813 uint32_t clear_val)
814{
815 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800816 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800817 GEN6_CLEAR_PARAMS_DW0_VALID |
818 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800819 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800820
821 CMD_ASSERT(cmd, 6, 6);
822
Chia-I Wu72292b72014-09-09 10:48:33 +0800823 cmd_batch_pointer(cmd, cmd_len, &dw);
824 dw[0] = dw0;
825 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800826}
827
828static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
829 uint32_t clear_val)
830{
831 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800832 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800833 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800834 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800835
836 CMD_ASSERT(cmd, 7, 7.5);
837
Chia-I Wu72292b72014-09-09 10:48:33 +0800838 cmd_batch_pointer(cmd, cmd_len, &dw);
839 dw[0] = dw0;
840 dw[1] = clear_val;
841 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800842}
843
Chia-I Wu302742d2014-08-22 10:28:29 +0800844static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 uint32_t blend_offset,
846 uint32_t ds_offset,
847 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800848{
849 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800851
852 CMD_ASSERT(cmd, 6, 6);
853
Chia-I Wu426072d2014-08-26 14:31:55 +0800854 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800855 (cmd_len - 2);
856
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 cmd_batch_pointer(cmd, cmd_len, &dw);
858 dw[0] = dw0;
859 dw[1] = blend_offset | 1;
860 dw[2] = ds_offset | 1;
861 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800862}
863
Chia-I Wu1744cca2014-08-22 11:10:17 +0800864static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 uint32_t clip_offset,
866 uint32_t sf_offset,
867 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800868{
869 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800871
872 CMD_ASSERT(cmd, 6, 6);
873
Chia-I Wu426072d2014-08-26 14:31:55 +0800874 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800875 GEN6_PTR_VP_DW0_CLIP_CHANGED |
876 GEN6_PTR_VP_DW0_SF_CHANGED |
877 GEN6_PTR_VP_DW0_CC_CHANGED |
878 (cmd_len - 2);
879
Chia-I Wu72292b72014-09-09 10:48:33 +0800880 cmd_batch_pointer(cmd, cmd_len, &dw);
881 dw[0] = dw0;
882 dw[1] = clip_offset;
883 dw[2] = sf_offset;
884 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800885}
886
887static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800888 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800889{
890 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800891 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800892
893 CMD_ASSERT(cmd, 6, 6);
894
Chia-I Wu426072d2014-08-26 14:31:55 +0800895 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896 (cmd_len - 2);
897
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 cmd_batch_pointer(cmd, cmd_len, &dw);
899 dw[0] = dw0;
900 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800901}
902
Chia-I Wu42a56202014-08-23 16:47:48 +0800903static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 uint32_t vs_offset,
905 uint32_t gs_offset,
906 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800907{
908 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800910
911 CMD_ASSERT(cmd, 6, 6);
912
Chia-I Wu426072d2014-08-26 14:31:55 +0800913 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800914 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
915 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
916 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
917 (cmd_len - 2);
918
Chia-I Wu72292b72014-09-09 10:48:33 +0800919 cmd_batch_pointer(cmd, cmd_len, &dw);
920 dw[0] = dw0;
921 dw[1] = vs_offset;
922 dw[2] = gs_offset;
923 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800924}
925
Chia-I Wu257e75e2014-08-29 14:06:35 +0800926static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 uint32_t vs_offset,
928 uint32_t gs_offset,
929 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800930{
931 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800932 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800933
934 CMD_ASSERT(cmd, 6, 6);
935
936 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
937 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
938 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
939 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
940 (cmd_len - 2);
941
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 cmd_batch_pointer(cmd, cmd_len, &dw);
943 dw[0] = dw0;
944 dw[1] = vs_offset;
945 dw[2] = gs_offset;
946 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800947}
948
Chia-I Wu302742d2014-08-22 10:28:29 +0800949static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800950 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800951{
952 const uint8_t cmd_len = 2;
953 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
954 GEN6_RENDER_SUBTYPE_3D |
955 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800957
Chia-I Wu72292b72014-09-09 10:48:33 +0800958 cmd_batch_pointer(cmd, cmd_len, &dw);
959 dw[0] = dw0;
960 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800961}
962
Chia-I Wua6c4f152014-12-02 04:19:58 +0800963static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800964{
Chia-I Wue6073342014-11-30 09:43:42 +0800965 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800966 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
Chia-I Wua6c4f152014-12-02 04:19:58 +0800967 const XGL_PIPELINE_CB_STATE *cb = &cmd->bind.pipeline.graphics->cb_state;
968 const struct intel_blend_state *blend = cmd->bind.state.blend;
969 uint32_t dw[XGL_MAX_COLOR_ATTACHMENTS * 2];
970 int i;
Chia-I Wu302742d2014-08-22 10:28:29 +0800971
972 CMD_ASSERT(cmd, 6, 7.5);
Chia-I Wua6c4f152014-12-02 04:19:58 +0800973 STATIC_ASSERT(ARRAY_SIZE(blend->cmd_blend) >= XGL_MAX_COLOR_ATTACHMENTS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800974
Chia-I Wua6c4f152014-12-02 04:19:58 +0800975 for (i = 0; i < XGL_MAX_COLOR_ATTACHMENTS; i++) {
976 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &cb->attachment[i];
977 uint32_t dw0, dw1;
978
979 dw0 = 0;
980 dw1 = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
981 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
982 GEN6_BLEND_DW1_POST_BLEND_CLAMP;
983
984 if (cb->logicOp != XGL_LOGIC_OP_COPY) {
985 int logicop;
986
987 switch (cb->logicOp) {
988 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
989 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
990 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
991 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
992 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
993 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
994 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
995 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
996 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
997 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
998 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
999 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1000 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1001 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1002 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1003 default:
1004 assert(!"unknown logic op");
1005 logicop = GEN6_LOGICOP_CLEAR;
1006 break;
1007 }
1008
1009 dw1 |= GEN6_BLEND_DW1_LOGICOP_ENABLE |
1010 logicop << GEN6_BLEND_DW1_LOGICOP_FUNC__SHIFT;
1011 } else if (att->blendEnable && blend) {
1012 dw0 |= blend->cmd_blend[i];
1013 }
1014
1015 if (!(att->channelWriteMask & 0x1))
1016 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_R;
1017 if (!(att->channelWriteMask & 0x2))
1018 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_G;
1019 if (!(att->channelWriteMask & 0x4))
1020 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_B;
1021 if (!(att->channelWriteMask & 0x8))
1022 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_A;
1023
1024 dw[2 * i] = dw0;
1025 dw[2 * i + 1] = dw1;
1026 }
1027
1028 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001029}
1030
Chia-I Wu72292b72014-09-09 10:48:33 +08001031static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001032 const struct intel_ds_state *state)
1033{
Chia-I Wue6073342014-11-30 09:43:42 +08001034 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001035 const uint8_t cmd_len = 3;
1036
1037 CMD_ASSERT(cmd, 6, 7.5);
1038 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1039
Chia-I Wu00b51a82014-09-09 12:07:37 +08001040 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1041 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001042}
1043
Chia-I Wu72292b72014-09-09 10:48:33 +08001044static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001045 uint32_t stencil_ref,
1046 const uint32_t blend_color[4])
1047{
Chia-I Wue6073342014-11-30 09:43:42 +08001048 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001049 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001050 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001051
1052 CMD_ASSERT(cmd, 6, 7.5);
1053
Chia-I Wu00b51a82014-09-09 12:07:37 +08001054 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1055 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001056 dw[0] = stencil_ref;
1057 dw[1] = 0;
1058 dw[2] = blend_color[0];
1059 dw[3] = blend_color[1];
1060 dw[4] = blend_color[2];
1061 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001062
Chia-I Wu72292b72014-09-09 10:48:33 +08001063 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001064}
1065
Chia-I Wu8370b402014-08-29 12:28:37 +08001066static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001067{
Chia-I Wu8370b402014-08-29 12:28:37 +08001068 CMD_ASSERT(cmd, 6, 7.5);
1069
Chia-I Wu707a29e2014-08-27 12:51:47 +08001070 if (!cmd->bind.draw_count)
1071 return;
1072
Chia-I Wu8370b402014-08-29 12:28:37 +08001073 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001074 return;
1075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001077
1078 /*
1079 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1080 *
1081 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1082 * pipe-control with a post-sync op and no write-cache flushes."
1083 *
1084 * The workaround below necessitates this workaround.
1085 */
1086 gen6_PIPE_CONTROL(cmd,
1087 GEN6_PIPE_CONTROL_CS_STALL |
1088 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001089 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001090
Chia-I Wud6d079d2014-08-31 13:14:21 +08001091 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1092 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001093}
1094
Chia-I Wu8370b402014-08-29 12:28:37 +08001095static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001096{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001097 CMD_ASSERT(cmd, 6, 7.5);
1098
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001099 if (!cmd->bind.draw_count)
1100 return;
1101
Chia-I Wud6d079d2014-08-31 13:14:21 +08001102 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1103 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001104}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001105
Chia-I Wu8370b402014-08-29 12:28:37 +08001106static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1107{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001108 CMD_ASSERT(cmd, 7, 7.5);
1109
Chia-I Wu8370b402014-08-29 12:28:37 +08001110 if (!cmd->bind.draw_count)
1111 return;
1112
1113 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001114
1115 gen6_PIPE_CONTROL(cmd,
1116 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001117 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001118}
1119
Chia-I Wu8370b402014-08-29 12:28:37 +08001120static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1121{
1122 CMD_ASSERT(cmd, 7, 7.5);
1123
1124 if (!cmd->bind.draw_count)
1125 return;
1126
1127 /*
1128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1129 *
1130 * "One of the following must also be set (when CS stall is set):
1131 *
1132 * * Render Target Cache Flush Enable ([12] of DW1)
1133 * * Depth Cache Flush Enable ([0] of DW1)
1134 * * Stall at Pixel Scoreboard ([1] of DW1)
1135 * * Depth Stall ([13] of DW1)
1136 * * Post-Sync Operation ([13] of DW1)"
1137 */
1138 gen6_PIPE_CONTROL(cmd,
1139 GEN6_PIPE_CONTROL_CS_STALL |
1140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001141 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001142}
1143
1144static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1145{
1146 CMD_ASSERT(cmd, 7, 7.5);
1147
1148 if (!cmd->bind.draw_count)
1149 return;
1150
1151 cmd_wa_gen6_pre_depth_stall_write(cmd);
1152
Chia-I Wud6d079d2014-08-31 13:14:21 +08001153 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001154}
1155
1156static void cmd_wa_gen6_pre_multisample_depth_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 Sandy Bridge PRM, volume 2 part 1, page 305:
1165 *
1166 * "Driver must guarentee that all the caches in the depth pipe are
1167 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1168 * requires driver to send a PIPE_CONTROL with a CS stall along with
1169 * a Depth Flush prior to this command."
1170 *
1171 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1172 *
1173 * "Driver must ierarchi that all the caches in the depth pipe are
1174 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1175 * requires driver to send a PIPE_CONTROL with a CS stall along with
1176 * a Depth Flush prior to this command.
1177 */
1178 gen6_PIPE_CONTROL(cmd,
1179 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1180 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001181 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001182}
1183
1184static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1185{
1186 CMD_ASSERT(cmd, 6, 7.5);
1187
1188 if (!cmd->bind.draw_count)
1189 return;
1190
1191 /*
1192 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1193 *
1194 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1195 * and a post sync operation prior to the group of depth
1196 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1197 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1198 *
1199 * This workaround satifies all the conditions.
1200 */
1201 cmd_wa_gen6_pre_depth_stall_write(cmd);
1202
1203 /*
1204 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1205 *
1206 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1207 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1208 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1209 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1210 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1211 * Depth Flush Bit set, followed by another pipelined depth stall
1212 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1213 * guarantee that the pipeline from WM onwards is already flushed
1214 * (e.g., via a preceding MI_FLUSH)."
1215 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001216 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1217 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1218 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001219}
1220
Chia-I Wu525c6602014-08-27 10:22:34 +08001221void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1222{
1223 if (!cmd->bind.draw_count)
1224 return;
1225
1226 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1227
Chia-I Wu8370b402014-08-29 12:28:37 +08001228 /*
1229 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1230 *
1231 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1232 * PIPE_CONTROL with any non-zero post-sync-op is required."
1233 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001234 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001235 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001236
Chia-I Wu092279a2014-08-30 19:05:30 +08001237 /*
1238 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1239 *
1240 * "One of the following must also be set (when CS stall is set):
1241 *
1242 * * Render Target Cache Flush Enable ([12] of DW1)
1243 * * Depth Cache Flush Enable ([0] of DW1)
1244 * * Stall at Pixel Scoreboard ([1] of DW1)
1245 * * Depth Stall ([13] of DW1)
1246 * * Post-Sync Operation ([13] of DW1)"
1247 */
1248 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1249 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1250 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1251 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1252 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1253 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1254
Chia-I Wud6d079d2014-08-31 13:14:21 +08001255 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001256}
1257
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001258void cmd_batch_flush_all(struct intel_cmd *cmd)
1259{
1260 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1261 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1262 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1263 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1264 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1265 GEN6_PIPE_CONTROL_CS_STALL);
1266}
1267
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001268void cmd_batch_depth_count(struct intel_cmd *cmd,
1269 struct intel_bo *bo,
1270 XGL_GPU_SIZE offset)
1271{
1272 cmd_wa_gen6_pre_depth_stall_write(cmd);
1273
1274 gen6_PIPE_CONTROL(cmd,
1275 GEN6_PIPE_CONTROL_DEPTH_STALL |
1276 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001277 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001278}
1279
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001280void cmd_batch_timestamp(struct intel_cmd *cmd,
1281 struct intel_bo *bo,
1282 XGL_GPU_SIZE offset)
1283{
1284 /* need any WA or stall? */
1285 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1286}
1287
1288void cmd_batch_immediate(struct intel_cmd *cmd,
1289 struct intel_bo *bo,
1290 XGL_GPU_SIZE offset,
1291 uint64_t val)
1292{
1293 /* need any WA or stall? */
1294 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1295}
1296
Chia-I Wu302742d2014-08-22 10:28:29 +08001297static void gen6_cc_states(struct intel_cmd *cmd)
1298{
1299 const struct intel_blend_state *blend = cmd->bind.state.blend;
1300 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001301 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001302 uint32_t stencil_ref;
1303 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001304
1305 CMD_ASSERT(cmd, 6, 6);
1306
Chia-I Wua6c4f152014-12-02 04:19:58 +08001307 blend_offset = gen6_BLEND_STATE(cmd);
1308
1309 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001310 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001311 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001312 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001313
1314 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001315 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001316 stencil_ref = ds->cmd_stencil_ref;
1317 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001318 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001319 stencil_ref = 0;
1320 }
1321
Chia-I Wu72292b72014-09-09 10:48:33 +08001322 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001323
Chia-I Wu72292b72014-09-09 10:48:33 +08001324 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001325}
1326
Chia-I Wu1744cca2014-08-22 11:10:17 +08001327static void gen6_viewport_states(struct intel_cmd *cmd)
1328{
1329 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001330 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001331
1332 if (!viewport)
1333 return;
1334
Chia-I Wub1d450a2014-09-09 13:48:03 +08001335 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1336 viewport->viewport_count);
1337
1338 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001339 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001340 viewport->cmd);
1341
1342 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001343 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001344 &viewport->cmd[viewport->cmd_clip_pos]);
1345
1346 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001347 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001348 &viewport->cmd[viewport->cmd_cc_pos]);
1349
1350 if (viewport->scissor_enable) {
1351 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001352 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001353 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1354 } else {
1355 scissor_offset = 0;
1356 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001357
1358 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001359 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001360
Chia-I Wub1d450a2014-09-09 13:48:03 +08001361 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001362}
1363
Chia-I Wu302742d2014-08-22 10:28:29 +08001364static void gen7_cc_states(struct intel_cmd *cmd)
1365{
1366 const struct intel_blend_state *blend = cmd->bind.state.blend;
1367 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001368 uint32_t stencil_ref;
1369 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001370 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001371
1372 CMD_ASSERT(cmd, 7, 7.5);
1373
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001374 if (!blend && !ds)
1375 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001376
Chia-I Wua6c4f152014-12-02 04:19:58 +08001377 offset = gen6_BLEND_STATE(cmd);
1378 gen7_3dstate_pointer(cmd,
1379 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001380
Chia-I Wua6c4f152014-12-02 04:19:58 +08001381 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001382 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001383 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001384 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001385
1386 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001387 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Mike Stroyan214ad462015-01-15 11:27:12 -07001388 stencil_ref = ds->cmd_stencil_ref;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001389 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001390 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1391 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001392 } else {
1393 stencil_ref = 0;
1394 }
1395
Chia-I Wu72292b72014-09-09 10:48:33 +08001396 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001397 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001398 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001399}
1400
Chia-I Wu1744cca2014-08-22 11:10:17 +08001401static void gen7_viewport_states(struct intel_cmd *cmd)
1402{
1403 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001404 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001405
1406 if (!viewport)
1407 return;
1408
Chia-I Wub1d450a2014-09-09 13:48:03 +08001409 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1410 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001411
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001413 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001414 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001415 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001416 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1417 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001418
1419 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001420 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001421 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001422 gen7_3dstate_pointer(cmd,
1423 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001424 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001425
Chia-I Wu1744cca2014-08-22 11:10:17 +08001426 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001428 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001429 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001430 gen7_3dstate_pointer(cmd,
1431 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001432 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001433 }
1434}
1435
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001436static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001437 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001438{
1439 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001440 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001441
Chia-I Wu72292b72014-09-09 10:48:33 +08001442 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001443
1444 dw[0] = GEN6_RENDER_TYPE_RENDER |
1445 GEN6_RENDER_SUBTYPE_3D |
1446 subop | (cmd_len - 2);
1447 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001448 dw[2] = 0;
1449 dw[3] = 0;
1450 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001451}
1452
1453static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001454 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001455{
1456 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001457 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001458
Chia-I Wu72292b72014-09-09 10:48:33 +08001459 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001460
1461 dw[0] = GEN6_RENDER_TYPE_RENDER |
1462 GEN6_RENDER_SUBTYPE_3D |
1463 subop | (cmd_len - 2);
1464 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001465 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001466 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001467 dw[4] = 0;
1468 dw[5] = 0;
1469 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001470}
1471
Chia-I Wu625105f2014-10-13 15:35:29 +08001472static uint32_t emit_samplers(struct intel_cmd *cmd,
1473 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001474{
1475 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1476 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001477 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001478 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001479 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001480 XGL_UINT i;
1481
1482 CMD_ASSERT(cmd, 6, 7.5);
1483
Chia-I Wu625105f2014-10-13 15:35:29 +08001484 if (!rmap || !rmap->sampler_count)
1485 return 0;
1486
Cody Northrop40316a32014-12-09 19:08:33 -07001487 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001488
Chia-I Wudcb509d2014-12-10 08:53:10 +08001489 /*
1490 * note that we cannot call cmd_state_pointer() here as the following
1491 * cmd_state_pointer() would invalidate the pointer
1492 */
1493 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001494 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001495 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001496
1497 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001498 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001499 4 * rmap->sampler_count, &sampler_dw);
1500
Chia-I Wudcb509d2014-12-10 08:53:10 +08001501 cmd_state_update(cmd, border_offset,
1502 border_stride * rmap->sampler_count, &border_dw);
1503
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001504 for (i = 0; i < rmap->sampler_count; i++) {
1505 const struct intel_pipeline_rmap_slot *slot =
1506 &rmap->slots[surface_count + i];
1507 const struct intel_sampler *sampler;
1508
1509 switch (slot->path_len) {
1510 case 0:
1511 sampler = NULL;
1512 break;
1513 case INTEL_PIPELINE_RMAP_SLOT_RT:
1514 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1515 assert(!"unexpected rmap slot type");
1516 sampler = NULL;
1517 break;
1518 case 1:
1519 {
1520 const struct intel_dset *dset = cmd->bind.dset.graphics;
1521 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1522 const struct intel_dset_slot *dset_slot =
1523 &dset->slots[slot_offset + slot->u.index];
1524
1525 switch (dset_slot->type) {
1526 case INTEL_DSET_SLOT_SAMPLER:
1527 sampler = dset_slot->u.sampler;
1528 break;
1529 default:
1530 assert(!"unexpected dset slot type");
1531 sampler = NULL;
1532 break;
1533 }
1534 }
1535 break;
1536 default:
1537 assert(!"nested descriptor set unsupported");
1538 sampler = NULL;
1539 break;
1540 }
1541
1542 if (sampler) {
1543 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1544
1545 sampler_dw[0] = sampler->cmd[0];
1546 sampler_dw[1] = sampler->cmd[1];
1547 sampler_dw[2] = border_offset;
1548 sampler_dw[3] = sampler->cmd[2];
1549 } else {
1550 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1551 sampler_dw[1] = 0;
1552 sampler_dw[2] = 0;
1553 sampler_dw[3] = 0;
1554 }
1555
1556 border_offset += border_stride * 4;
1557 border_dw += border_stride;
1558 sampler_dw += 4;
1559 }
1560
Chia-I Wu625105f2014-10-13 15:35:29 +08001561 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001562}
1563
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001564static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001565 const struct intel_pipeline_rmap *rmap,
1566 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001567{
Chia-I Wu72292b72014-09-09 10:48:33 +08001568 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001569 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001570
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001571 CMD_ASSERT(cmd, 6, 7.5);
1572
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001573 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001574 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001575 if (!surface_count)
1576 return 0;
1577
Chia-I Wu42a56202014-08-23 16:47:48 +08001578 assert(surface_count <= ARRAY_SIZE(binding_table));
1579
1580 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001581 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001582
1583 switch (slot->path_len) {
1584 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001585 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001586 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001587 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001588 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001589 const struct intel_rt_view *view =
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001590 (slot->u.index < cmd->bind.render_pass->fb->rt_count) ?
1591 cmd->bind.render_pass->fb->rt[slot->u.index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001592
Chia-I Wu787a05b2014-12-05 11:02:20 +08001593 if (view) {
1594 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1595 GEN6_ALIGNMENT_SURFACE_STATE,
1596 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001597
Chia-I Wu787a05b2014-12-05 11:02:20 +08001598 cmd_reserve_reloc(cmd, 1);
1599 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1600 view->cmd[1], INTEL_RELOC_WRITE);
1601 } else {
1602 struct intel_null_view null_view;
1603 intel_null_view_init(&null_view, cmd->dev);
1604
1605 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1606 GEN6_ALIGNMENT_SURFACE_STATE,
1607 null_view.cmd_len, null_view.cmd);
1608 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001609 }
1610 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001611 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001612 {
1613 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001614 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001615
Chia-I Wu00b51a82014-09-09 12:07:37 +08001616 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001617 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001618 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001619
Chia-I Wu72292b72014-09-09 10:48:33 +08001620 cmd_reserve_reloc(cmd, 1);
1621 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1622 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001623 }
1624 break;
1625 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001626 {
1627 const struct intel_dset *dset = cmd->bind.dset.graphics;
1628 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1629 const struct intel_dset_slot *dset_slot =
1630 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001631 const uint32_t reloc_flags =
1632 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001633
1634 switch (dset_slot->type) {
1635 case INTEL_DSET_SLOT_IMG_VIEW:
1636 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001637 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001638 dset_slot->u.img_view->cmd_len,
1639 dset_slot->u.img_view->cmd);
1640
1641 cmd_reserve_reloc(cmd, 1);
1642 cmd_surface_reloc(cmd, offset, 1,
1643 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001644 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001645 break;
1646 case INTEL_DSET_SLOT_MEM_VIEW:
Cody Northrop7c76f302014-12-18 11:52:58 -07001647 {
1648 XGL_MEMORY_VIEW_ATTACH_INFO tmp_info = dset_slot->u.mem_view.info;
1649 struct intel_mem_view tmp;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001650
Cody Northrop7c76f302014-12-18 11:52:58 -07001651 memset(&tmp, 0, sizeof(tmp));
1652
1653 /* The compiler expects uniform buffers to have pitch of
1654 * 4 for fragment shaders, but 16 for other stages.
1655 */
Cody Northropbef0e552015-01-13 12:13:46 -07001656 tmp_info.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
1657 tmp_info.format.numericFormat = XGL_NUM_FMT_FLOAT;
Cody Northrop7c76f302014-12-18 11:52:58 -07001658 if (XGL_SHADER_STAGE_FRAGMENT == stage) {
1659 tmp_info.stride = 4;
1660 } else {
1661 tmp_info.stride = 16;
1662 }
1663
1664 intel_mem_view_init(&tmp, cmd->dev, &tmp_info);
1665
1666 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1667 GEN6_ALIGNMENT_SURFACE_STATE,
1668 tmp.cmd_len,
1669 tmp.cmd);
1670
1671 cmd_reserve_reloc(cmd, 1);
1672 cmd_surface_reloc(cmd, offset, 1,
1673 dset_slot->u.mem_view.mem->bo,
1674 tmp.cmd[1], reloc_flags);
1675 }
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001676 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001677 case INTEL_DSET_SLOT_SAMPLER:
1678 assert(0 == cmd->bind.dset.graphics_offset);
1679
1680 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001681 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001682 16, dset_slot->u.sampler->cmd);
1683 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001684 default:
1685 assert(!"unexpected dset slot type");
1686 break;
1687 }
1688 }
1689 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001690 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001691 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001692 break;
1693 }
1694
Chia-I Wu72292b72014-09-09 10:48:33 +08001695 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001696 }
1697
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001698 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001699 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001700 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001701}
1702
Chia-I Wu1d125092014-10-08 08:49:38 +08001703static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1704{
1705 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001706 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1707 uint32_t *dw;
1708 XGL_UINT pos, i;
1709
1710 CMD_ASSERT(cmd, 6, 7.5);
1711
1712 if (!pipeline->vb_count)
1713 return;
1714
1715 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1716
1717 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1718 dw++;
1719 pos++;
1720
1721 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001722 assert(pipeline->vb[i].strideInBytes <= 2048);
1723
1724 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1725 pipeline->vb[i].strideInBytes;
1726
1727 if (cmd_gen(cmd) >= INTEL_GEN(7))
1728 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1729
1730 switch (pipeline->vb[i].stepRate) {
1731 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1732 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1733 dw[3] = 0;
1734 break;
1735 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1736 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1737 dw[3] = 1;
1738 break;
1739 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1740 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1741 dw[3] = 0;
1742 break;
1743 default:
1744 assert(!"unknown step rate");
1745 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1746 dw[3] = 0;
1747 break;
1748 }
1749
Chia-I Wu3b04af52014-11-08 10:48:20 +08001750 if (cmd->bind.vertex.mem[i]) {
1751 const struct intel_mem *mem = cmd->bind.vertex.mem[i];
1752 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001753
1754 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3b04af52014-11-08 10:48:20 +08001755 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
1756 cmd_batch_reloc(cmd, pos + 2, mem->bo, mem->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001757 } else {
1758 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1759 dw[1] = 0;
1760 dw[2] = 0;
1761 }
1762
1763 dw += 4;
1764 pos += 4;
1765 }
1766}
1767
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001768static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1769{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001770 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1771 const struct intel_pipeline_shader *vs = &pipeline->vs;
1772 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001773 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001774 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001775 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001776 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001777
1778 CMD_ASSERT(cmd, 6, 7.5);
1779
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001780 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001781 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1782 *
1783 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1784 * 128-bit vertex elements to be passed into the payload for each
1785 * vertex."
1786 *
1787 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1788 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001789 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001790 vue_read_len = (vs->in_count + 1) / 2;
1791 if (!vue_read_len)
1792 vue_read_len = 1;
1793
1794 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1795 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1796
1797 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1798 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1799 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001800
1801 dw5 = GEN6_VS_DW5_STATISTICS |
1802 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001803
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001804 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001805 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001806 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001807 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001808
Chia-I Wube0a3d92014-09-02 13:20:59 +08001809 if (pipeline->disable_vs_cache)
1810 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1811
Chia-I Wu784d3042014-12-19 14:30:04 +08001812 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001813 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001814 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001815 dw[2] = dw2;
1816 dw[3] = 0; /* scratch */
1817 dw[4] = dw4;
1818 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001819
1820 if (vs->per_thread_scratch_size)
1821 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001822}
1823
Chia-I Wu625105f2014-10-13 15:35:29 +08001824static void emit_shader_resources(struct intel_cmd *cmd)
1825{
1826 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001827 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001828
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001829 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001830 cmd->bind.pipeline.graphics->vs.rmap,
1831 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001832 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001833 cmd->bind.pipeline.graphics->tcs.rmap,
1834 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001835 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001836 cmd->bind.pipeline.graphics->tes.rmap,
1837 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001838 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001839 cmd->bind.pipeline.graphics->gs.rmap,
1840 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001841 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001842 cmd->bind.pipeline.graphics->fs.rmap,
1843 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001844
1845 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1846 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1847 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1848 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1849 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1850
1851 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1852 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001853 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1854 binding_tables[0]);
1855 gen7_3dstate_pointer(cmd,
1856 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1857 binding_tables[1]);
1858 gen7_3dstate_pointer(cmd,
1859 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1860 binding_tables[2]);
1861 gen7_3dstate_pointer(cmd,
1862 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1863 binding_tables[3]);
1864 gen7_3dstate_pointer(cmd,
1865 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1866 binding_tables[4]);
1867
1868 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001869 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1870 samplers[0]);
1871 gen7_3dstate_pointer(cmd,
1872 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1873 samplers[1]);
1874 gen7_3dstate_pointer(cmd,
1875 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1876 samplers[2]);
1877 gen7_3dstate_pointer(cmd,
1878 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1879 samplers[3]);
1880 gen7_3dstate_pointer(cmd,
1881 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1882 samplers[4]);
1883 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001884 assert(!binding_tables[1] && !binding_tables[2]);
1885 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1886 binding_tables[0], binding_tables[3], binding_tables[4]);
1887
Chia-I Wu625105f2014-10-13 15:35:29 +08001888 assert(!samplers[1] && !samplers[2]);
1889 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1890 samplers[0], samplers[3], samplers[4]);
1891 }
1892}
1893
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001894static void emit_rt(struct intel_cmd *cmd)
1895{
1896 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001897 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1898 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001899}
1900
1901static void emit_ds(struct intel_cmd *cmd)
1902{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001903 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001904
1905 if (!ds) {
1906 /* all zeros */
1907 static const struct intel_ds_view null_ds;
1908 ds = &null_ds;
1909 }
1910
1911 cmd_wa_gen6_pre_ds_flush(cmd);
1912 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1913 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1914 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1915
1916 if (cmd_gen(cmd) >= INTEL_GEN(7))
1917 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1918 else
1919 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1920}
1921
Chia-I Wua57761b2014-10-14 14:27:44 +08001922static uint32_t emit_shader(struct intel_cmd *cmd,
1923 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001924{
Chia-I Wua57761b2014-10-14 14:27:44 +08001925 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1926 uint32_t offset;
1927 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001928
Chia-I Wua57761b2014-10-14 14:27:44 +08001929 /* see if the shader is already in the cache */
1930 for (i = 0; i < cache->used; i++) {
1931 if (cache->entries[i].shader == (const void *) shader)
1932 return cache->entries[i].kernel_offset;
1933 }
1934
1935 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1936
1937 /* grow the cache if full */
1938 if (cache->used >= cache->count) {
1939 const XGL_UINT count = cache->count + 16;
1940 void *entries;
1941
1942 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1943 XGL_SYSTEM_ALLOC_INTERNAL);
1944 if (entries) {
1945 if (cache->entries) {
1946 memcpy(entries, cache->entries,
1947 sizeof(cache->entries[0]) * cache->used);
1948 icd_free(cache->entries);
1949 }
1950
1951 cache->entries = entries;
1952 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001953 }
1954 }
1955
Chia-I Wua57761b2014-10-14 14:27:44 +08001956 /* add the shader to the cache */
1957 if (cache->used < cache->count) {
1958 cache->entries[cache->used].shader = (const void *) shader;
1959 cache->entries[cache->used].kernel_offset = offset;
1960 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001961 }
1962
Chia-I Wua57761b2014-10-14 14:27:44 +08001963 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001964}
1965
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001966static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001967{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001968 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001969
Chia-I Wu8370b402014-08-29 12:28:37 +08001970 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1971 cmd_wa_gen6_pre_depth_stall_write(cmd);
1972 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1973 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1974 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1975 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001976
1977 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001978 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001979 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001980
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001981 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001982 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001983 }
1984 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001985 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001986 }
1987 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001988 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1989 }
1990 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1991 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1992 }
1993 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1994 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001995 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001996
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001997 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1998 gen7_3DSTATE_GS(cmd);
1999 } else {
2000 gen6_3DSTATE_GS(cmd);
2001 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002002
Chia-I Wu8370b402014-08-29 12:28:37 +08002003 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2004 cmd_wa_gen7_post_command_cs_stall(cmd);
2005 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2006 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002007}
2008
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002009static void emit_bounded_states(struct intel_cmd *cmd)
2010{
2011 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
2012
2013 emit_graphics_pipeline(cmd);
2014
2015 emit_rt(cmd);
2016 emit_ds(cmd);
2017
2018 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2019 gen7_cc_states(cmd);
2020 gen7_viewport_states(cmd);
2021
2022 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2023 &cmd->bind.pipeline.graphics->vs);
2024 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2025 &cmd->bind.pipeline.graphics->fs);
2026
2027 gen6_3DSTATE_CLIP(cmd);
2028 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002029 gen7_3DSTATE_WM(cmd);
2030 gen7_3DSTATE_PS(cmd);
2031 } else {
2032 gen6_cc_states(cmd);
2033 gen6_viewport_states(cmd);
2034
2035 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2036 &cmd->bind.pipeline.graphics->vs);
2037 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2038 &cmd->bind.pipeline.graphics->fs);
2039
2040 gen6_3DSTATE_CLIP(cmd);
2041 gen6_3DSTATE_SF(cmd);
2042 gen6_3DSTATE_WM(cmd);
2043 }
2044
2045 emit_shader_resources(cmd);
2046
2047 cmd_wa_gen6_pre_depth_stall_write(cmd);
2048 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2049
2050 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2051 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2052
2053 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2054 gen6_3DSTATE_VS(cmd);
2055}
2056
Chia-I Wu6032b892014-10-17 14:47:18 +08002057static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2058{
2059 const struct intel_cmd_meta *meta = cmd->bind.meta;
2060 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2061
2062 CMD_ASSERT(cmd, 6, 7.5);
2063
2064 blend_offset = 0;
2065 ds_offset = 0;
2066 cc_offset = 0;
2067 cc_vp_offset = 0;
2068
Chia-I Wu29e6f502014-11-24 14:27:29 +08002069 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002070 /* BLEND_STATE */
2071 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002072 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002073 dw[0] = 0;
2074 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2075 }
2076
Chia-I Wu29e6f502014-11-24 14:27:29 +08002077 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2078 if (meta->ds.state) {
2079 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002080
Chia-I Wu29e6f502014-11-24 14:27:29 +08002081 /* DEPTH_STENCIL_STATE */
2082 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002083
Chia-I Wu29e6f502014-11-24 14:27:29 +08002084 /* COLOR_CALC_STATE */
2085 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2086 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002087
Chia-I Wu29e6f502014-11-24 14:27:29 +08002088 /* CC_VIEWPORT */
2089 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002090 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002091 dw[0] = u_fui(0.0f);
2092 dw[1] = u_fui(1.0f);
2093 } else {
2094 /* DEPTH_STENCIL_STATE */
2095 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002096 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002097 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2098 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2099 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002100 }
2101
2102 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2103 gen7_3dstate_pointer(cmd,
2104 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2105 blend_offset);
2106 gen7_3dstate_pointer(cmd,
2107 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2108 ds_offset);
2109 gen7_3dstate_pointer(cmd,
2110 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2111
2112 gen7_3dstate_pointer(cmd,
2113 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2114 cc_vp_offset);
2115 } else {
2116 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002117 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002118
2119 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2120 cmd_batch_pointer(cmd, 4, &dw);
2121 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2122 GEN6_PTR_VP_DW0_CC_CHANGED;
2123 dw[1] = 0;
2124 dw[2] = 0;
2125 dw[3] = cc_vp_offset;
2126 }
2127}
2128
2129static void gen6_meta_surface_states(struct intel_cmd *cmd)
2130{
2131 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002132 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002133 uint32_t offset;
2134
2135 CMD_ASSERT(cmd, 6, 7.5);
2136
Chia-I Wu29e6f502014-11-24 14:27:29 +08002137 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2138 return;
2139
Chia-I Wu005c47c2014-10-22 13:49:13 +08002140 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002141 if (meta->src.valid) {
2142 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002143 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002144 meta->src.surface_len, meta->src.surface);
2145
2146 cmd_reserve_reloc(cmd, 1);
2147 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2148 cmd_surface_reloc_writer(cmd, offset, 1,
2149 meta->src.reloc_target, meta->src.reloc_offset);
2150 } else {
2151 cmd_surface_reloc(cmd, offset, 1,
2152 (struct intel_bo *) meta->src.reloc_target,
2153 meta->src.reloc_offset, meta->src.reloc_flags);
2154 }
2155
Chia-I Wu005c47c2014-10-22 13:49:13 +08002156 binding_table[0] = offset;
2157 }
2158 if (meta->dst.valid) {
2159 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002160 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002161 meta->dst.surface_len, meta->dst.surface);
2162
2163 cmd_reserve_reloc(cmd, 1);
2164 cmd_surface_reloc(cmd, offset, 1,
2165 (struct intel_bo *) meta->dst.reloc_target,
2166 meta->dst.reloc_offset, meta->dst.reloc_flags);
2167
2168 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002169 }
2170
2171 /* BINDING_TABLE */
2172 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002173 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002174 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002175
2176 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002177 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2178 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2179 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2180 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002181 } else {
2182 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002183 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2184 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2185 else
2186 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002187 }
2188}
2189
2190static void gen6_meta_urb(struct intel_cmd *cmd)
2191{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002192 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002193 uint32_t *dw;
2194
2195 CMD_ASSERT(cmd, 6, 6);
2196
2197 /* 3DSTATE_URB */
2198 cmd_batch_pointer(cmd, 3, &dw);
2199 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002200 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002201 dw[2] = 0;
2202}
2203
2204static void gen7_meta_urb(struct intel_cmd *cmd)
2205{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002206 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002207 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002208 uint32_t *dw;
2209
2210 CMD_ASSERT(cmd, 7, 7.5);
2211
2212 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2213 cmd_batch_pointer(cmd, 10, &dw);
2214
2215 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002216 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002217 dw += 2;
2218
2219 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2220 dw[1] = 0;
2221 dw += 2;
2222
2223 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2224 dw[1] = 0;
2225 dw += 2;
2226
2227 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2228 dw[1] = 0;
2229 dw += 2;
2230
2231 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002232 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002233
2234 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2235
Chia-I Wu24aa1022014-11-25 11:53:19 +08002236 switch (cmd_gen(cmd)) {
2237 case INTEL_GEN(7.5):
2238 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2239 break;
2240 case INTEL_GEN(7):
2241 default:
2242 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2243 break;
2244 }
2245
Chia-I Wu6032b892014-10-17 14:47:18 +08002246 /* 3DSTATE_URB_x */
2247 cmd_batch_pointer(cmd, 8, &dw);
2248
2249 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2250 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002251 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002252 dw += 2;
2253
2254 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2255 dw[1] = 0;
2256 dw += 2;
2257
2258 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2259 dw[1] = 0;
2260 dw += 2;
2261
2262 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2263 dw[1] = 0;
2264 dw += 2;
2265}
2266
2267static void gen6_meta_vf(struct intel_cmd *cmd)
2268{
2269 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002270 uint32_t vb_start, vb_end, vb_stride;
2271 int ve_format, ve_z_source;
2272 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002273 XGL_UINT pos;
2274
2275 CMD_ASSERT(cmd, 6, 7.5);
2276
Chia-I Wu29e6f502014-11-24 14:27:29 +08002277 switch (meta->mode) {
2278 case INTEL_CMD_META_VS_POINTS:
2279 cmd_batch_pointer(cmd, 3, &dw);
2280 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2281 dw[1] = GEN6_VE_STATE_DW0_VALID;
2282 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2283 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2284 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2285 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2286 return;
2287 break;
2288 case INTEL_CMD_META_FS_RECT:
2289 {
2290 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002291
Chia-I Wu29e6f502014-11-24 14:27:29 +08002292 vertices[0][0] = meta->dst.x + meta->width;
2293 vertices[0][1] = meta->dst.y + meta->height;
2294 vertices[1][0] = meta->dst.x;
2295 vertices[1][1] = meta->dst.y + meta->height;
2296 vertices[2][0] = meta->dst.x;
2297 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002298
Chia-I Wu29e6f502014-11-24 14:27:29 +08002299 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2300 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002301
Chia-I Wu29e6f502014-11-24 14:27:29 +08002302 vb_end = vb_start + sizeof(vertices) - 1;
2303 vb_stride = sizeof(vertices[0]);
2304 ve_z_source = GEN6_VFCOMP_STORE_0;
2305 ve_format = GEN6_FORMAT_R32G32_USCALED;
2306 }
2307 break;
2308 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2309 {
2310 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002311
Chia-I Wu29e6f502014-11-24 14:27:29 +08002312 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2313 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2314 vertices[0][2] = u_uif(meta->clear_val[0]);
2315 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2316 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2317 vertices[1][2] = u_uif(meta->clear_val[0]);
2318 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2319 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2320 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002321
Chia-I Wu29e6f502014-11-24 14:27:29 +08002322 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2323 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002324
Chia-I Wu29e6f502014-11-24 14:27:29 +08002325 vb_end = vb_start + sizeof(vertices) - 1;
2326 vb_stride = sizeof(vertices[0]);
2327 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2328 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2329 }
2330 break;
2331 default:
2332 assert(!"unknown meta mode");
2333 return;
2334 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002335 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002336
2337 /* 3DSTATE_VERTEX_BUFFERS */
2338 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002339
Chia-I Wu6032b892014-10-17 14:47:18 +08002340 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002341 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002342 if (cmd_gen(cmd) >= INTEL_GEN(7))
2343 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2344
2345 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002346 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2347 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002348
2349 dw[4] = 0;
2350
2351 /* 3DSTATE_VERTEX_ELEMENTS */
2352 cmd_batch_pointer(cmd, 5, &dw);
2353 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002354 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002355 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2356 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2357 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2358 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2359 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002360 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002361 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2362 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002363 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002364 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2365}
2366
Chia-I Wu29e6f502014-11-24 14:27:29 +08002367static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002368{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002369 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002370 /* one GPR */
2371 XGL_UINT consts[8];
2372 XGL_UINT const_count;
2373
2374 CMD_ASSERT(cmd, 6, 7.5);
2375
2376 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002377 case INTEL_DEV_META_VS_FILL_MEM:
2378 consts[0] = meta->dst.x;
2379 consts[1] = meta->clear_val[0];
2380 const_count = 2;
2381 break;
2382 case INTEL_DEV_META_VS_COPY_MEM:
2383 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2384 consts[0] = meta->dst.x;
2385 consts[1] = meta->src.x;
2386 const_count = 2;
2387 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002388 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2389 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2390 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2391 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2392 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2393 consts[0] = meta->src.x;
2394 consts[1] = meta->src.y;
2395 consts[2] = meta->width;
2396 consts[3] = meta->dst.x;
2397 const_count = 4;
2398 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002399 default:
2400 assert(!"unknown meta shader id");
2401 const_count = 0;
2402 break;
2403 }
2404
2405 /* this can be skipped but it makes state dumping prettier */
2406 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2407
2408 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2409}
2410
2411static void gen6_meta_vs(struct intel_cmd *cmd)
2412{
2413 const struct intel_cmd_meta *meta = cmd->bind.meta;
2414 const struct intel_pipeline_shader *sh =
2415 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2416 uint32_t offset, *dw;
2417
2418 CMD_ASSERT(cmd, 6, 7.5);
2419
2420 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2421 XGL_UINT cmd_len;
2422
2423 /* 3DSTATE_CONSTANT_VS */
2424 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2425 cmd_batch_pointer(cmd, cmd_len, &dw);
2426 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2427 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2428
2429 /* 3DSTATE_VS */
2430 cmd_batch_pointer(cmd, 6, &dw);
2431 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2432 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2433
2434 return;
2435 }
2436
2437 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2438
2439 /* 3DSTATE_CONSTANT_VS */
2440 offset = gen6_meta_vs_constants(cmd);
2441 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2442 cmd_batch_pointer(cmd, 7, &dw);
2443 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2444 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2445 dw[2] = 0;
2446 dw[3] = offset;
2447 dw[4] = 0;
2448 dw[5] = 0;
2449 dw[6] = 0;
2450 } else {
2451 cmd_batch_pointer(cmd, 5, &dw);
2452 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2453 GEN6_PCB_ANY_DW0_PCB0_VALID;
2454 dw[1] = offset;
2455 dw[2] = 0;
2456 dw[3] = 0;
2457 dw[4] = 0;
2458 }
2459
2460 /* 3DSTATE_VS */
2461 offset = emit_shader(cmd, sh);
2462 cmd_batch_pointer(cmd, 6, &dw);
2463 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2464 dw[1] = offset;
2465 dw[2] = GEN6_THREADDISP_SPF |
2466 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2467 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002468 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002469 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2470 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2471
2472 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2473 GEN6_VS_DW5_VS_ENABLE;
2474 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002475 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002476 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002477 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002478
2479 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002480}
2481
2482static void gen6_meta_disabled(struct intel_cmd *cmd)
2483{
Chia-I Wu6032b892014-10-17 14:47:18 +08002484 uint32_t *dw;
2485
2486 CMD_ASSERT(cmd, 6, 6);
2487
Chia-I Wu6032b892014-10-17 14:47:18 +08002488 /* 3DSTATE_CONSTANT_GS */
2489 cmd_batch_pointer(cmd, 5, &dw);
2490 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2491 dw[1] = 0;
2492 dw[2] = 0;
2493 dw[3] = 0;
2494 dw[4] = 0;
2495
2496 /* 3DSTATE_GS */
2497 cmd_batch_pointer(cmd, 7, &dw);
2498 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2499 dw[1] = 0;
2500 dw[2] = 0;
2501 dw[3] = 0;
2502 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2503 dw[5] = GEN6_GS_DW5_STATISTICS;
2504 dw[6] = 0;
2505
Chia-I Wu6032b892014-10-17 14:47:18 +08002506 /* 3DSTATE_SF */
2507 cmd_batch_pointer(cmd, 20, &dw);
2508 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2509 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2510 memset(&dw[2], 0, 18 * sizeof(*dw));
2511}
2512
2513static void gen7_meta_disabled(struct intel_cmd *cmd)
2514{
2515 uint32_t *dw;
2516
2517 CMD_ASSERT(cmd, 7, 7.5);
2518
Chia-I Wu6032b892014-10-17 14:47:18 +08002519 /* 3DSTATE_CONSTANT_HS */
2520 cmd_batch_pointer(cmd, 7, &dw);
2521 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2522 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2523
2524 /* 3DSTATE_HS */
2525 cmd_batch_pointer(cmd, 7, &dw);
2526 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2527 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2528
2529 /* 3DSTATE_TE */
2530 cmd_batch_pointer(cmd, 4, &dw);
2531 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2532 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2533
2534 /* 3DSTATE_CONSTANT_DS */
2535 cmd_batch_pointer(cmd, 7, &dw);
2536 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2537 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2538
2539 /* 3DSTATE_DS */
2540 cmd_batch_pointer(cmd, 6, &dw);
2541 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2542 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2543
2544 /* 3DSTATE_CONSTANT_GS */
2545 cmd_batch_pointer(cmd, 7, &dw);
2546 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2547 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2548
2549 /* 3DSTATE_GS */
2550 cmd_batch_pointer(cmd, 7, &dw);
2551 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2552 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2553
2554 /* 3DSTATE_STREAMOUT */
2555 cmd_batch_pointer(cmd, 3, &dw);
2556 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2557 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2558
Chia-I Wu6032b892014-10-17 14:47:18 +08002559 /* 3DSTATE_SF */
2560 cmd_batch_pointer(cmd, 7, &dw);
2561 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2562 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2563
2564 /* 3DSTATE_SBE */
2565 cmd_batch_pointer(cmd, 14, &dw);
2566 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2567 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2568 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002569}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002570
Chia-I Wu29e6f502014-11-24 14:27:29 +08002571static void gen6_meta_clip(struct intel_cmd *cmd)
2572{
2573 const struct intel_cmd_meta *meta = cmd->bind.meta;
2574 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002575
Chia-I Wu29e6f502014-11-24 14:27:29 +08002576 /* 3DSTATE_CLIP */
2577 cmd_batch_pointer(cmd, 4, &dw);
2578 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2579 dw[1] = 0;
2580 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2581 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2582 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2583 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002584 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002585 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002586 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002587}
2588
2589static void gen6_meta_wm(struct intel_cmd *cmd)
2590{
2591 const struct intel_cmd_meta *meta = cmd->bind.meta;
2592 uint32_t *dw;
2593
2594 CMD_ASSERT(cmd, 6, 7.5);
2595
2596 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2597
2598 /* 3DSTATE_MULTISAMPLE */
2599 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2600 cmd_batch_pointer(cmd, 4, &dw);
2601 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2602 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2603 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2604 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2605 dw[2] = 0;
2606 dw[3] = 0;
2607 } else {
2608 cmd_batch_pointer(cmd, 3, &dw);
2609 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2610 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2611 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2612 dw[2] = 0;
2613 }
2614
2615 /* 3DSTATE_SAMPLE_MASK */
2616 cmd_batch_pointer(cmd, 2, &dw);
2617 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2618 dw[1] = (1 << meta->samples) - 1;
2619
2620 /* 3DSTATE_DRAWING_RECTANGLE */
2621 cmd_batch_pointer(cmd, 4, &dw);
2622 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2623 dw[1] = meta->dst.y << 16 | meta->dst.x;
2624 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2625 (meta->dst.x + meta->width - 1);
2626 dw[3] = 0;
2627}
2628
2629static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2630{
2631 const struct intel_cmd_meta *meta = cmd->bind.meta;
2632 XGL_UINT offset_x, offset_y;
2633 /* one GPR */
2634 XGL_UINT consts[8];
2635 XGL_UINT const_count;
2636
2637 CMD_ASSERT(cmd, 6, 7.5);
2638
2639 /* underflow is fine here */
2640 offset_x = meta->src.x - meta->dst.x;
2641 offset_y = meta->src.y - meta->dst.y;
2642
2643 switch (meta->shader_id) {
2644 case INTEL_DEV_META_FS_COPY_MEM:
2645 case INTEL_DEV_META_FS_COPY_1D:
2646 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2647 case INTEL_DEV_META_FS_COPY_2D:
2648 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2649 case INTEL_DEV_META_FS_COPY_2D_MS:
2650 consts[0] = offset_x;
2651 consts[1] = offset_y;
2652 consts[2] = meta->src.layer;
2653 consts[3] = meta->src.lod;
2654 const_count = 4;
2655 break;
2656 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2657 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2658 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2659 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2660 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2661 consts[0] = offset_x;
2662 consts[1] = offset_y;
2663 consts[2] = meta->src.layer;
2664 consts[3] = meta->src.lod;
2665 consts[4] = meta->src.x;
2666 consts[5] = meta->width;
2667 const_count = 6;
2668 break;
2669 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2670 consts[0] = offset_x;
2671 consts[1] = offset_y;
2672 consts[2] = meta->width;
2673 const_count = 3;
2674 break;
2675 case INTEL_DEV_META_FS_CLEAR_COLOR:
2676 consts[0] = meta->clear_val[0];
2677 consts[1] = meta->clear_val[1];
2678 consts[2] = meta->clear_val[2];
2679 consts[3] = meta->clear_val[3];
2680 const_count = 4;
2681 break;
2682 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2683 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002684 consts[1] = meta->clear_val[1];
2685 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002686 break;
2687 case INTEL_DEV_META_FS_RESOLVE_2X:
2688 case INTEL_DEV_META_FS_RESOLVE_4X:
2689 case INTEL_DEV_META_FS_RESOLVE_8X:
2690 case INTEL_DEV_META_FS_RESOLVE_16X:
2691 consts[0] = offset_x;
2692 consts[1] = offset_y;
2693 const_count = 2;
2694 break;
2695 default:
2696 assert(!"unknown meta shader id");
2697 const_count = 0;
2698 break;
2699 }
2700
2701 /* this can be skipped but it makes state dumping prettier */
2702 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2703
2704 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2705}
2706
2707static void gen6_meta_ps(struct intel_cmd *cmd)
2708{
2709 const struct intel_cmd_meta *meta = cmd->bind.meta;
2710 const struct intel_pipeline_shader *sh =
2711 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2712 uint32_t offset, *dw;
2713
2714 CMD_ASSERT(cmd, 6, 6);
2715
Chia-I Wu29e6f502014-11-24 14:27:29 +08002716 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2717 /* 3DSTATE_CONSTANT_PS */
2718 cmd_batch_pointer(cmd, 5, &dw);
2719 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2720 dw[1] = 0;
2721 dw[2] = 0;
2722 dw[3] = 0;
2723 dw[4] = 0;
2724
2725 /* 3DSTATE_WM */
2726 cmd_batch_pointer(cmd, 9, &dw);
2727 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2728 dw[1] = 0;
2729 dw[2] = 0;
2730 dw[3] = 0;
2731 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002732 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002733 dw[6] = 0;
2734 dw[7] = 0;
2735 dw[8] = 0;
2736
Chia-I Wu3adf7212014-10-24 15:34:07 +08002737 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002738 }
2739
Chia-I Wu3adf7212014-10-24 15:34:07 +08002740 /* a normal color write */
2741 assert(meta->dst.valid && !sh->uses);
2742
Chia-I Wu6032b892014-10-17 14:47:18 +08002743 /* 3DSTATE_CONSTANT_PS */
2744 offset = gen6_meta_ps_constants(cmd);
2745 cmd_batch_pointer(cmd, 5, &dw);
2746 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2747 GEN6_PCB_ANY_DW0_PCB0_VALID;
2748 dw[1] = offset;
2749 dw[2] = 0;
2750 dw[3] = 0;
2751 dw[4] = 0;
2752
2753 /* 3DSTATE_WM */
2754 offset = emit_shader(cmd, sh);
2755 cmd_batch_pointer(cmd, 9, &dw);
2756 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2757 dw[1] = offset;
2758 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2759 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002760 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002761 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002762 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002763 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002764 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2765
Chia-I Wu6032b892014-10-17 14:47:18 +08002766 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2767 GEN6_WM_DW6_POSOFFSET_NONE |
2768 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2769 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2770 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2771 if (meta->samples > 1) {
2772 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2773 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2774 } else {
2775 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2776 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2777 }
2778 dw[7] = 0;
2779 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002780
2781 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002782}
2783
2784static void gen7_meta_ps(struct intel_cmd *cmd)
2785{
2786 const struct intel_cmd_meta *meta = cmd->bind.meta;
2787 const struct intel_pipeline_shader *sh =
2788 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2789 uint32_t offset, *dw;
2790
2791 CMD_ASSERT(cmd, 7, 7.5);
2792
Chia-I Wu29e6f502014-11-24 14:27:29 +08002793 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2794 /* 3DSTATE_WM */
2795 cmd_batch_pointer(cmd, 3, &dw);
2796 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2797 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2798
2799 /* 3DSTATE_CONSTANT_GS */
2800 cmd_batch_pointer(cmd, 7, &dw);
2801 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2802 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2803
2804 /* 3DSTATE_PS */
2805 cmd_batch_pointer(cmd, 8, &dw);
2806 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2807 dw[1] = 0;
2808 dw[2] = 0;
2809 dw[3] = 0;
2810 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002811 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002812 dw[5] = 0;
2813 dw[6] = 0;
2814 dw[7] = 0;
2815
Chia-I Wu3adf7212014-10-24 15:34:07 +08002816 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002817 }
2818
Chia-I Wu3adf7212014-10-24 15:34:07 +08002819 /* a normal color write */
2820 assert(meta->dst.valid && !sh->uses);
2821
Chia-I Wu6032b892014-10-17 14:47:18 +08002822 /* 3DSTATE_WM */
2823 cmd_batch_pointer(cmd, 3, &dw);
2824 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2825 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2826 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2827 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2828 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2829 dw[2] = 0;
2830
2831 /* 3DSTATE_CONSTANT_PS */
2832 offset = gen6_meta_ps_constants(cmd);
2833 cmd_batch_pointer(cmd, 7, &dw);
2834 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2835 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2836 dw[2] = 0;
2837 dw[3] = offset;
2838 dw[4] = 0;
2839 dw[5] = 0;
2840 dw[6] = 0;
2841
2842 /* 3DSTATE_PS */
2843 offset = emit_shader(cmd, sh);
2844 cmd_batch_pointer(cmd, 8, &dw);
2845 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2846 dw[1] = offset;
2847 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2848 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002849 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002850
2851 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2852 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002853 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2854
2855 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002856 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002857 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002858 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002859 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002860 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002861
2862 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2863 dw[6] = 0;
2864 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002865
2866 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002867}
2868
2869static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2870{
2871 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002872 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002873
2874 CMD_ASSERT(cmd, 6, 7.5);
2875
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002876 if (!ds) {
2877 /* all zeros */
2878 static const struct intel_ds_view null_ds;
2879 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002880 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002881
2882 cmd_wa_gen6_pre_ds_flush(cmd);
2883 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2884 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2885 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2886
2887 if (cmd_gen(cmd) >= INTEL_GEN(7))
2888 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2889 else
2890 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002891}
2892
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002893static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2894 const struct intel_pipeline *pipeline)
2895{
2896 cmd->bind.pipeline.graphics = pipeline;
2897}
2898
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002899static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2900 const struct intel_pipeline *pipeline)
2901{
2902 cmd->bind.pipeline.compute = pipeline;
2903}
2904
2905static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2906 const struct intel_pipeline_delta *delta)
2907{
2908 cmd->bind.pipeline.graphics_delta = delta;
2909}
2910
2911static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2912 const struct intel_pipeline_delta *delta)
2913{
2914 cmd->bind.pipeline.compute_delta = delta;
2915}
2916
2917static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2918 const struct intel_dset *dset,
2919 XGL_UINT slot_offset)
2920{
2921 cmd->bind.dset.graphics = dset;
2922 cmd->bind.dset.graphics_offset = slot_offset;
2923}
2924
2925static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2926 const struct intel_dset *dset,
2927 XGL_UINT slot_offset)
2928{
2929 cmd->bind.dset.compute = dset;
2930 cmd->bind.dset.compute_offset = slot_offset;
2931}
2932
2933static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2934 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2935{
2936 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2937}
2938
2939static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2940 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2941{
2942 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2943}
2944
Chia-I Wu3b04af52014-11-08 10:48:20 +08002945static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2946 const struct intel_mem *mem,
2947 XGL_GPU_SIZE offset, XGL_UINT binding)
2948{
2949 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2950 cmd->result = XGL_ERROR_UNKNOWN;
2951 return;
2952 }
2953
2954 cmd->bind.vertex.mem[binding] = mem;
2955 cmd->bind.vertex.offset[binding] = offset;
2956}
2957
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002958static void cmd_bind_index_data(struct intel_cmd *cmd,
2959 const struct intel_mem *mem,
2960 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2961{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002962 cmd->bind.index.mem = mem;
2963 cmd->bind.index.offset = offset;
2964 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002965}
2966
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002967static void cmd_bind_attachments(struct intel_cmd *cmd,
2968 XGL_UINT rt_count,
2969 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2970 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002971{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002972 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002973 XGL_UINT i;
2974
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002975 for (i = 0; i < rt_count; i++) {
2976 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002977 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002978 const struct intel_layout *layout = &rt->img->layout;
2979
2980 if (i == 0) {
2981 width = layout->width0;
2982 height = layout->height0;
2983 } else {
2984 if (width > layout->width0)
2985 width = layout->width0;
2986 if (height > layout->height0)
2987 height = layout->height0;
2988 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002989
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07002990 cmd->bind.render_pass->fb->rt[i] = rt;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002991 }
2992
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07002993 cmd->bind.render_pass->fb->rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002994
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002995 if (ds_info) {
2996 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002997
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07002998 cmd->bind.render_pass->fb->ds = intel_ds_view(ds_info->view);
2999 layout = &cmd->bind.render_pass->fb->ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003000
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003001 if (width > layout->width0)
3002 width = layout->width0;
3003 if (height > layout->height0)
3004 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003005 } else {
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07003006 cmd->bind.render_pass->fb->ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003007 }
3008
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07003009 cmd->bind.render_pass->fb->width = width;
3010 cmd->bind.render_pass->fb->height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003011}
3012
3013static void cmd_bind_viewport_state(struct intel_cmd *cmd,
3014 const struct intel_viewport_state *state)
3015{
3016 cmd->bind.state.viewport = state;
3017}
3018
3019static void cmd_bind_raster_state(struct intel_cmd *cmd,
3020 const struct intel_raster_state *state)
3021{
3022 cmd->bind.state.raster = state;
3023}
3024
3025static void cmd_bind_ds_state(struct intel_cmd *cmd,
3026 const struct intel_ds_state *state)
3027{
3028 cmd->bind.state.ds = state;
3029}
3030
3031static void cmd_bind_blend_state(struct intel_cmd *cmd,
3032 const struct intel_blend_state *state)
3033{
3034 cmd->bind.state.blend = state;
3035}
3036
3037static void cmd_bind_msaa_state(struct intel_cmd *cmd,
3038 const struct intel_msaa_state *state)
3039{
3040 cmd->bind.state.msaa = state;
3041}
3042
3043static void cmd_draw(struct intel_cmd *cmd,
3044 XGL_UINT vertex_start,
3045 XGL_UINT vertex_count,
3046 XGL_UINT instance_start,
3047 XGL_UINT instance_count,
3048 bool indexed,
3049 XGL_UINT vertex_base)
3050{
3051 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
3052
3053 emit_bounded_states(cmd);
3054
3055 if (indexed) {
3056 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3057 cmd->result = XGL_ERROR_UNKNOWN;
3058
3059 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3060 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3061 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003062 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3063 cmd->bind.index.offset, cmd->bind.index.type,
3064 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003065 } else {
3066 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3067 cmd->bind.index.offset, cmd->bind.index.type,
3068 p->primitive_restart);
3069 }
3070 } else {
3071 assert(!vertex_base);
3072 }
3073
3074 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3075 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3076 vertex_start, instance_count, instance_start, vertex_base);
3077 } else {
3078 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3079 vertex_start, instance_count, instance_start, vertex_base);
3080 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003081
Chia-I Wu707a29e2014-08-27 12:51:47 +08003082 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003083 /* need to re-emit all workarounds */
3084 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003085
3086 if (intel_debug & INTEL_DEBUG_NOCACHE)
3087 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003088}
3089
Chia-I Wuc14d1562014-10-17 09:49:22 +08003090void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3091{
Chia-I Wu6032b892014-10-17 14:47:18 +08003092 cmd->bind.meta = meta;
3093
3094 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003095 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003096
3097 gen6_meta_dynamic_states(cmd);
3098 gen6_meta_surface_states(cmd);
3099
3100 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3101 gen7_meta_urb(cmd);
3102 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003103 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003104 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003105 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003106 gen6_meta_wm(cmd);
3107 gen7_meta_ps(cmd);
3108 gen6_meta_depth_buffer(cmd);
3109
3110 cmd_wa_gen7_post_command_cs_stall(cmd);
3111 cmd_wa_gen7_post_command_depth_stall(cmd);
3112
Chia-I Wu29e6f502014-11-24 14:27:29 +08003113 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3114 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003115 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003116 } else {
3117 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3118 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003119 } else {
3120 gen6_meta_urb(cmd);
3121 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003122 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003123 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003124 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003125 gen6_meta_wm(cmd);
3126 gen6_meta_ps(cmd);
3127 gen6_meta_depth_buffer(cmd);
3128
Chia-I Wu29e6f502014-11-24 14:27:29 +08003129 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3130 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003131 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003132 } else {
3133 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3134 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003135 }
3136
3137 cmd->bind.draw_count++;
3138 /* need to re-emit all workarounds */
3139 cmd->bind.wa_flags = 0;
3140
3141 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003142
3143 if (intel_debug & INTEL_DEBUG_NOCACHE)
3144 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003145}
3146
Chia-I Wu96177272015-01-03 15:27:41 +08003147ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003148 XGL_CMD_BUFFER cmdBuffer,
3149 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3150 XGL_PIPELINE pipeline)
3151{
3152 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3153
3154 switch (pipelineBindPoint) {
3155 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003156 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003157 break;
3158 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003159 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003160 break;
3161 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003162 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003163 break;
3164 }
3165}
3166
Chia-I Wu96177272015-01-03 15:27:41 +08003167ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003168 XGL_CMD_BUFFER cmdBuffer,
3169 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3170 XGL_PIPELINE_DELTA delta)
3171{
3172 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3173
3174 switch (pipelineBindPoint) {
3175 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003176 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003177 break;
3178 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003179 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003180 break;
3181 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003182 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003183 break;
3184 }
3185}
3186
Chia-I Wu96177272015-01-03 15:27:41 +08003187ICD_EXPORT XGL_VOID XGLAPI xglCmdBindStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003188 XGL_CMD_BUFFER cmdBuffer,
3189 XGL_STATE_BIND_POINT stateBindPoint,
3190 XGL_STATE_OBJECT state)
3191{
3192 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3193
3194 switch (stateBindPoint) {
3195 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003196 cmd_bind_viewport_state(cmd,
3197 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003198 break;
3199 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003200 cmd_bind_raster_state(cmd,
3201 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003202 break;
3203 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003204 cmd_bind_ds_state(cmd,
3205 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003206 break;
3207 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003208 cmd_bind_blend_state(cmd,
3209 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003210 break;
3211 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003212 cmd_bind_msaa_state(cmd,
3213 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003214 break;
3215 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003216 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003217 break;
3218 }
3219}
3220
Chia-I Wu96177272015-01-03 15:27:41 +08003221ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003222 XGL_CMD_BUFFER cmdBuffer,
3223 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3224 XGL_UINT index,
3225 XGL_DESCRIPTOR_SET descriptorSet,
3226 XGL_UINT slotOffset)
3227{
3228 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3229 struct intel_dset *dset = intel_dset(descriptorSet);
3230
3231 assert(!index);
3232
3233 switch (pipelineBindPoint) {
3234 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003235 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003236 break;
3237 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003238 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003239 break;
3240 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003241 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003242 break;
3243 }
3244}
3245
Chia-I Wu96177272015-01-03 15:27:41 +08003246ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicMemoryView(
Chia-I Wub2755562014-08-20 13:38:52 +08003247 XGL_CMD_BUFFER cmdBuffer,
3248 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3249 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3250{
3251 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3252
3253 switch (pipelineBindPoint) {
3254 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003255 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003256 break;
3257 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003258 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003259 break;
3260 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003261 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003262 break;
3263 }
3264}
3265
Chia-I Wu96177272015-01-03 15:27:41 +08003266ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexData(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003267 XGL_CMD_BUFFER cmdBuffer,
3268 XGL_GPU_MEMORY mem_,
3269 XGL_GPU_SIZE offset,
3270 XGL_UINT binding)
3271{
3272 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3273 struct intel_mem *mem = intel_mem(mem_);
3274
3275 cmd_bind_vertex_data(cmd, mem, offset, binding);
3276}
3277
Chia-I Wu96177272015-01-03 15:27:41 +08003278ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexData(
Chia-I Wub2755562014-08-20 13:38:52 +08003279 XGL_CMD_BUFFER cmdBuffer,
3280 XGL_GPU_MEMORY mem_,
3281 XGL_GPU_SIZE offset,
3282 XGL_INDEX_TYPE indexType)
3283{
3284 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3285 struct intel_mem *mem = intel_mem(mem_);
3286
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003287 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003288}
3289
Chia-I Wu96177272015-01-03 15:27:41 +08003290ICD_EXPORT XGL_VOID XGLAPI xglCmdBindAttachments(
Chia-I Wub2755562014-08-20 13:38:52 +08003291 XGL_CMD_BUFFER cmdBuffer,
3292 XGL_UINT colorAttachmentCount,
3293 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3294 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3295{
3296 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003297
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003298 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3299 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003300}
3301
Chia-I Wu96177272015-01-03 15:27:41 +08003302ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003303 XGL_CMD_BUFFER cmdBuffer,
3304 XGL_UINT firstVertex,
3305 XGL_UINT vertexCount,
3306 XGL_UINT firstInstance,
3307 XGL_UINT instanceCount)
3308{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003309 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003310
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003311 cmd_draw(cmd, firstVertex, vertexCount,
3312 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003313}
3314
Chia-I Wu96177272015-01-03 15:27:41 +08003315ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003316 XGL_CMD_BUFFER cmdBuffer,
3317 XGL_UINT firstIndex,
3318 XGL_UINT indexCount,
3319 XGL_INT vertexOffset,
3320 XGL_UINT firstInstance,
3321 XGL_UINT instanceCount)
3322{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003323 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003324
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003325 cmd_draw(cmd, firstIndex, indexCount,
3326 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003327}
3328
Chia-I Wu96177272015-01-03 15:27:41 +08003329ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003330 XGL_CMD_BUFFER cmdBuffer,
3331 XGL_GPU_MEMORY mem,
3332 XGL_GPU_SIZE offset,
3333 XGL_UINT32 count,
3334 XGL_UINT32 stride)
3335{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003336 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3337
3338 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003339}
3340
Chia-I Wu96177272015-01-03 15:27:41 +08003341ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003342 XGL_CMD_BUFFER cmdBuffer,
3343 XGL_GPU_MEMORY mem,
3344 XGL_GPU_SIZE offset,
3345 XGL_UINT32 count,
3346 XGL_UINT32 stride)
3347{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003348 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3349
3350 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003351}
3352
Chia-I Wu96177272015-01-03 15:27:41 +08003353ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003354 XGL_CMD_BUFFER cmdBuffer,
3355 XGL_UINT x,
3356 XGL_UINT y,
3357 XGL_UINT z)
3358{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003359 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3360
3361 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003362}
3363
Chia-I Wu96177272015-01-03 15:27:41 +08003364ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003365 XGL_CMD_BUFFER cmdBuffer,
3366 XGL_GPU_MEMORY mem,
3367 XGL_GPU_SIZE offset)
3368{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003369 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3370
3371 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003372}