blob: b15d44a91aaaf8ecd5452c4f0ad6e01018ca30df [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wua4d1b392014-10-10 13:57:29 +080029#include <stdio.h> /* for printf */
Chia-I Wu9f039862014-08-20 15:39:56 +080030#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080031#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
40
Chia-I Wu59c097e2014-08-21 10:51:07 +080041static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080042 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080043 uint32_t vertex_count,
44 uint32_t vertex_start,
45 uint32_t instance_count,
46 uint32_t instance_start,
47 uint32_t vertex_base)
48{
49 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080050 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080051
52 CMD_ASSERT(cmd, 6, 6);
53
Chia-I Wu426072d2014-08-26 14:31:55 +080054 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080055 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080056 (cmd_len - 2);
57
58 if (indexed)
59 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
60
Chia-I Wu72292b72014-09-09 10:48:33 +080061 cmd_batch_pointer(cmd, cmd_len, &dw);
62 dw[0] = dw0;
63 dw[1] = vertex_count;
64 dw[2] = vertex_start;
65 dw[3] = instance_count;
66 dw[4] = instance_start;
67 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080068}
69
70static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080071 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080072 uint32_t vertex_count,
73 uint32_t vertex_start,
74 uint32_t instance_count,
75 uint32_t instance_start,
76 uint32_t vertex_base)
77{
78 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080079 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080080
81 CMD_ASSERT(cmd, 7, 7.5);
82
Chia-I Wu426072d2014-08-26 14:31:55 +080083 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080084 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080085
86 if (indexed)
87 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
88
Chia-I Wu72292b72014-09-09 10:48:33 +080089 cmd_batch_pointer(cmd, cmd_len, &dw);
90 dw[0] = dw0;
91 dw[1] = dw1;
92 dw[2] = vertex_count;
93 dw[3] = vertex_start;
94 dw[4] = instance_count;
95 dw[5] = instance_start;
96 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080097}
98
Chia-I Wu270b1e82014-08-25 15:53:39 +080099static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800100 struct intel_bo *bo, uint32_t bo_offset,
101 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800102{
103 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800104 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800105 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800106 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800107 uint32_t *dw;
108 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800109
110 CMD_ASSERT(cmd, 6, 7.5);
111
112 assert(bo_offset % 8 == 0);
113
114 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
115 /*
116 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
117 *
118 * "1 of the following must also be set (when CS stall is set):
119 *
120 * * Depth Cache Flush Enable ([0] of DW1)
121 * * Stall at Pixel Scoreboard ([1] of DW1)
122 * * Depth Stall ([13] of DW1)
123 * * Post-Sync Operation ([13] of DW1)
124 * * Render Target Cache Flush Enable ([12] of DW1)
125 * * Notify Enable ([8] of DW1)"
126 *
127 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
128 *
129 * "One of the following must also be set (when CS stall is set):
130 *
131 * * Render Target Cache Flush Enable ([12] of DW1)
132 * * Depth Cache Flush Enable ([0] of DW1)
133 * * Stall at Pixel Scoreboard ([1] of DW1)
134 * * Depth Stall ([13] of DW1)
135 * * Post-Sync Operation ([13] of DW1)"
136 */
137 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
138 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
140 GEN6_PIPE_CONTROL_DEPTH_STALL;
141
142 /* post-sync op */
143 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
144 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
145 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
146
147 if (cmd_gen(cmd) == INTEL_GEN(6))
148 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
149
150 assert(dw1 & bit_test);
151 }
152
153 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
154 /*
155 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
156 *
157 * "Following bits must be clear (when Depth Stall is set):
158 *
159 * * Render Target Cache Flush Enable ([12] of DW1)
160 * * Depth Cache Flush Enable ([0] of DW1)"
161 */
162 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
163 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
164 }
165
166 /*
167 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
168 *
169 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
170 * and PIPE_CONTROL are not supported."
171 *
172 * The kernel will add the mapping automatically (when write domain is
173 * INTEL_DOMAIN_INSTRUCTION).
174 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800175 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800176 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800177 reloc_flags |= INTEL_RELOC_GGTT;
178 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800179
Chia-I Wu72292b72014-09-09 10:48:33 +0800180 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
181 dw[0] = dw0;
182 dw[1] = dw1;
183 dw[2] = 0;
184 dw[3] = (uint32_t) imm;
185 dw[4] = (uint32_t) (imm >> 32);
186
187 if (bo) {
188 cmd_reserve_reloc(cmd, 1);
189 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
190 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800191}
192
Chia-I Wu254db422014-08-21 11:54:29 +0800193static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
194{
195 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
196 bool supported;
197
198 CMD_ASSERT(cmd, 6, 7.5);
199
200 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
201 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
202
203 switch (p->prim_type) {
204 case GEN6_3DPRIM_POINTLIST:
205 case GEN6_3DPRIM_LINELIST:
206 case GEN6_3DPRIM_LINESTRIP:
207 case GEN6_3DPRIM_TRILIST:
208 case GEN6_3DPRIM_TRISTRIP:
209 supported = true;
210 break;
211 default:
212 supported = false;
213 break;
214 }
215
216 if (!supported)
217 return false;
218
219 switch (cmd->bind.index.type) {
220 case XGL_INDEX_8:
221 supported = (p->primitive_restart_index != 0xffu);
222 break;
223 case XGL_INDEX_16:
224 supported = (p->primitive_restart_index != 0xffffu);
225 break;
226 case XGL_INDEX_32:
227 supported = (p->primitive_restart_index != 0xffffffffu);
228 break;
229 default:
230 supported = false;
231 break;
232 }
233
234 return supported;
235}
236
Chia-I Wu59c097e2014-08-21 10:51:07 +0800237static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800238 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 XGL_GPU_SIZE offset,
240 XGL_INDEX_TYPE type,
241 bool enable_cut_index)
242{
243 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800244 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800246 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800247
248 CMD_ASSERT(cmd, 6, 7.5);
249
Chia-I Wu426072d2014-08-26 14:31:55 +0800250 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800251
252 /* the bit is moved to 3DSTATE_VF */
253 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
254 assert(!enable_cut_index);
255 if (enable_cut_index)
256 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
257
258 switch (type) {
259 case XGL_INDEX_8:
260 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
261 offset_align = 1;
262 break;
263 case XGL_INDEX_16:
264 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
265 offset_align = 2;
266 break;
267 case XGL_INDEX_32:
268 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
269 offset_align = 4;
270 break;
271 default:
272 cmd->result = XGL_ERROR_INVALID_VALUE;
273 return;
274 break;
275 }
276
277 if (offset % offset_align) {
278 cmd->result = XGL_ERROR_INVALID_VALUE;
279 return;
280 }
281
282 /* aligned and inclusive */
283 end_offset = mem->size - (mem->size % offset_align) - 1;
284
Chia-I Wu72292b72014-09-09 10:48:33 +0800285 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
286 dw[0] = dw0;
287
288 cmd_reserve_reloc(cmd, 2);
289 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
290 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800291}
292
Chia-I Wu62a7f252014-08-29 11:31:16 +0800293static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
294 bool enable_cut_index,
295 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800296{
297 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800298 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800299
300 CMD_ASSERT(cmd, 7.5, 7.5);
301
Chia-I Wu426072d2014-08-26 14:31:55 +0800302 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800303 if (enable_cut_index)
304 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
305
Chia-I Wu72292b72014-09-09 10:48:33 +0800306 cmd_batch_pointer(cmd, cmd_len, &dw);
307 dw[0] = dw0;
308 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800309}
310
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600311
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800312static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
313{
314 const uint8_t cmd_len = 7;
315 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800316 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800317
318 CMD_ASSERT(cmd, 6, 6);
319
Chia-I Wu72292b72014-09-09 10:48:33 +0800320 cmd_batch_pointer(cmd, cmd_len, &dw);
321 dw[0] = dw0;
322 dw[1] = 0;
323 dw[2] = 0;
324 dw[3] = 0;
325 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
326 dw[5] = GEN6_GS_DW5_STATISTICS;
327 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800328}
329
Chia-I Wu62a7f252014-08-29 11:31:16 +0800330static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
331{
332 const uint8_t cmd_len = 7;
333 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800334 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800335
336 CMD_ASSERT(cmd, 7, 7.5);
337
Chia-I Wu72292b72014-09-09 10:48:33 +0800338 cmd_batch_pointer(cmd, cmd_len, &dw);
339 dw[0] = dw0;
340 dw[1] = 0;
341 dw[2] = 0;
342 dw[3] = 0;
343 dw[4] = 0;
344 dw[5] = GEN6_GS_DW5_STATISTICS;
345 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800346}
347
Chia-I Wud88e02d2014-08-25 10:56:13 +0800348static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
349 XGL_UINT width, XGL_UINT height)
350{
351 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800352 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800353 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800354 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800355
356 CMD_ASSERT(cmd, 6, 7.5);
357
Chia-I Wu72292b72014-09-09 10:48:33 +0800358 cmd_batch_pointer(cmd, cmd_len, &dw);
359 dw[0] = dw0;
360
Chia-I Wud88e02d2014-08-25 10:56:13 +0800361 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800362 dw[1] = 0;
363 dw[2] = (height - 1) << 16 |
364 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800365 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800366 dw[1] = 1;
367 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800368 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800369
370 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800371}
372
Chia-I Wu8016a172014-08-29 18:31:32 +0800373static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
374 uint32_t body[6])
375{
376 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
377 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
378 const struct intel_raster_state *raster = cmd->bind.state.raster;
379 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
380 uint32_t dw1, dw2, dw3;
381 int point_width;
382
383 CMD_ASSERT(cmd, 6, 7.5);
384
385 dw1 = GEN7_SF_DW1_STATISTICS |
386 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
387 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
388 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
389 GEN7_SF_DW1_VIEWPORT_ENABLE |
390 raster->cmd_sf_fill;
391
392 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
393 int format;
394
395 switch (pipeline->db_format.channelFormat) {
396 case XGL_CH_FMT_R16:
397 format = GEN6_ZFORMAT_D16_UNORM;
398 break;
399 case XGL_CH_FMT_R32:
400 case XGL_CH_FMT_R32G8:
401 format = GEN6_ZFORMAT_D32_FLOAT;
402 break;
403 default:
404 assert(!"unknown depth format");
405 format = 0;
406 break;
407 }
408
409 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
410 }
411
412 dw2 = raster->cmd_sf_cull;
413
414 if (msaa->sample_count > 1) {
415 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
416 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
417 } else {
418 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
419 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
420 }
421
422 if (viewport->scissor_enable)
423 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
424
425 /* in U8.3 */
426 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
427 point_width = U_CLAMP(point_width, 1, 2047);
428
429 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
431 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
432 GEN7_SF_DW3_SUBPIXEL_8BITS |
433 GEN7_SF_DW3_USE_POINT_WIDTH |
434 point_width;
435
436 body[0] = dw1;
437 body[1] = dw2;
438 body[2] = dw3;
439 body[3] = raster->cmd_depth_offset_const;
440 body[4] = raster->cmd_depth_offset_scale;
441 body[5] = raster->cmd_depth_offset_clamp;
442}
443
444static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
445 uint32_t body[13])
446{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800447 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
448 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449 XGL_UINT attr_skip, attr_count;
450 XGL_UINT vue_offset, vue_len;
451 XGL_UINT i;
452 uint32_t dw1;
453
454 CMD_ASSERT(cmd, 6, 7.5);
455
456 /* VS outputs VUE header and position additionally */
457 assert(vs->out_count >= 2);
458 attr_skip = 2;
459 attr_count = vs->out_count - attr_skip;
GregF42543d22014-11-05 15:09:17 -0700460 // LunarG TODO: Redo this assert for user varyings only
461 // and then only assert that vs_out is greater than fs_in?
462 //assert(fs->in_count == attr_count);
Chia-I Wu8016a172014-08-29 18:31:32 +0800463 assert(fs->in_count <= 32);
464
465 vue_offset = attr_skip / 2;
466 vue_len = (attr_count + 1) / 2;
467 if (!vue_len)
468 vue_len = 1;
469
470 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
471 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
472 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
473
474 body[0] = dw1;
475
476 for (i = 0; i < 8; i++) {
477 uint16_t hi, lo;
478
479 /* no attr swizzles */
480 if (i * 2 + 1 < fs->in_count) {
481 hi = i * 2 + 1;
482 lo = i * 2;
483 } else if (i * 2 < fs->in_count) {
484 hi = 0;
485 lo = i * 2;
486 } else {
487 hi = 0;
488 lo = 0;
489 }
490
491 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
492 }
493
494 body[9] = 0; /* point sprite enables */
495 body[10] = 0; /* constant interpolation enables */
496 body[11] = 0; /* WrapShortest enables */
497 body[12] = 0;
498}
499
500static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
501{
502 const uint8_t cmd_len = 20;
503 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
504 (cmd_len - 2);
505 uint32_t sf[6];
506 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800507 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800508
509 CMD_ASSERT(cmd, 6, 6);
510
511 gen7_fill_3DSTATE_SF_body(cmd, sf);
512 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
513
Chia-I Wu72292b72014-09-09 10:48:33 +0800514 cmd_batch_pointer(cmd, cmd_len, &dw);
515 dw[0] = dw0;
516 dw[1] = sbe[0];
517 memcpy(&dw[2], sf, sizeof(sf));
518 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800519}
520
521static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
522{
523 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800524 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800525
526 CMD_ASSERT(cmd, 7, 7.5);
527
Chia-I Wu72292b72014-09-09 10:48:33 +0800528 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800529 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
530 (cmd_len - 2);
531 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800532}
533
534static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
535{
536 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800537 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800538
539 CMD_ASSERT(cmd, 7, 7.5);
540
Chia-I Wu72292b72014-09-09 10:48:33 +0800541 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800542 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
543 (cmd_len - 2);
544 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800545}
546
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800547static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
548{
549 const uint8_t cmd_len = 4;
550 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
551 (cmd_len - 2);
552 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800553 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800554 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
555 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800556 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800557
558 CMD_ASSERT(cmd, 6, 7.5);
559
560 dw1 = GEN6_CLIP_DW1_STATISTICS;
561 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
562 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
563 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
564 raster->cmd_clip_cull;
565 }
566
567 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
568 GEN6_CLIP_DW2_XY_TEST_ENABLE |
569 GEN6_CLIP_DW2_APIMODE_OGL |
570 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
571 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
572 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
573
574 if (pipeline->rasterizerDiscardEnable)
575 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
576 else
577 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
578
579 if (pipeline->depthClipEnable)
580 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
581
582 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
583 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
584 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
585 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
586
587 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
588 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
589 (viewport->viewport_count - 1);
590
Chia-I Wu72292b72014-09-09 10:48:33 +0800591 cmd_batch_pointer(cmd, cmd_len, &dw);
592 dw[0] = dw0;
593 dw[1] = dw1;
594 dw[2] = dw2;
595 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800596}
597
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800598static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
599{
600 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
601 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800602 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800603 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
604 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800605 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800606
607 CMD_ASSERT(cmd, 6, 6);
608
609 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
610
611 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
612 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
613
614 dw4 = GEN6_WM_DW4_STATISTICS |
615 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
616 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
617 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
618
619 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
620 GEN6_WM_DW5_PS_ENABLE |
621 GEN6_WM_DW5_8_PIXEL_DISPATCH;
622
623 if (fs->uses & INTEL_SHADER_USE_KILL ||
624 pipeline->cb_state.alphaToCoverageEnable)
625 dw5 |= GEN6_WM_DW5_PS_KILL;
626
627 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
628 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
629 if (fs->uses & INTEL_SHADER_USE_DEPTH)
630 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
631 if (fs->uses & INTEL_SHADER_USE_W)
632 dw5 |= GEN6_WM_DW5_PS_USE_W;
633
634 if (pipeline->cb_state.dualSourceBlendEnable)
635 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
636
637 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
638 GEN6_WM_DW6_POSOFFSET_NONE |
639 GEN6_WM_DW6_ZW_INTERP_PIXEL |
640 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
641 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
642
643 if (msaa->sample_count > 1) {
644 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
645 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
646 } else {
647 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
648 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
649 }
650
Chia-I Wu72292b72014-09-09 10:48:33 +0800651 cmd_batch_pointer(cmd, cmd_len, &dw);
652 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800653 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800654 dw[2] = dw2;
655 dw[3] = 0; /* scratch */
656 dw[4] = dw4;
657 dw[5] = dw5;
658 dw[6] = dw6;
659 dw[7] = 0; /* kernel 1 */
660 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800661}
662
663static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
664{
665 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800666 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
668 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800669 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800670
671 CMD_ASSERT(cmd, 7, 7.5);
672
673 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
674
675 dw1 = GEN7_WM_DW1_STATISTICS |
676 GEN7_WM_DW1_PS_ENABLE |
677 GEN7_WM_DW1_ZW_INTERP_PIXEL |
678 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
679 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
680
681 if (fs->uses & INTEL_SHADER_USE_KILL ||
682 pipeline->cb_state.alphaToCoverageEnable)
683 dw1 |= GEN7_WM_DW1_PS_KILL;
684
685 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
686 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
687 if (fs->uses & INTEL_SHADER_USE_DEPTH)
688 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
689 if (fs->uses & INTEL_SHADER_USE_W)
690 dw1 |= GEN7_WM_DW1_PS_USE_W;
691
692 dw2 = 0;
693
694 if (msaa->sample_count > 1) {
695 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
696 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
697 } else {
698 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
699 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
700 }
701
Chia-I Wu72292b72014-09-09 10:48:33 +0800702 cmd_batch_pointer(cmd, cmd_len, &dw);
703 dw[0] = dw0;
704 dw[1] = dw1;
705 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800706}
707
708static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
709{
710 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800711 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800712 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
713 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800714 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800715
716 CMD_ASSERT(cmd, 7, 7.5);
717
718 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
719
720 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
721 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
722
723 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
724 GEN7_PS_DW4_8_PIXEL_DISPATCH;
725
726 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
727 const int max_threads =
728 (cmd->dev->gpu->gt == 3) ? 408 :
729 (cmd->dev->gpu->gt == 2) ? 204 : 102;
730 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
731 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
732 } else {
733 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
734 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
735 }
736
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800737 if (fs->in_count)
738 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
739
740 if (pipeline->cb_state.dualSourceBlendEnable)
741 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
742
743 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
744 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
745 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
746
Chia-I Wu72292b72014-09-09 10:48:33 +0800747 cmd_batch_pointer(cmd, cmd_len, &dw);
748 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800749 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800750 dw[2] = dw2;
751 dw[3] = 0; /* scratch */
752 dw[4] = dw4;
753 dw[5] = dw5;
754 dw[6] = 0; /* kernel 1 */
755 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800756}
757
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800758static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
759 const struct intel_ds_view *view)
760{
761 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800762 uint32_t dw0, *dw;
763 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800764
765 CMD_ASSERT(cmd, 6, 7.5);
766
767 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800768 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
769 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800770 dw0 |= (cmd_len - 2);
771
Chia-I Wu72292b72014-09-09 10:48:33 +0800772 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
773 dw[0] = dw0;
774 dw[1] = view->cmd[0];
775 dw[2] = 0;
776 dw[3] = view->cmd[2];
777 dw[4] = view->cmd[3];
778 dw[5] = view->cmd[4];
779 dw[6] = view->cmd[5];
780
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600781 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800782 cmd_reserve_reloc(cmd, 1);
783 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
784 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600785 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800786}
787
788static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
789 const struct intel_ds_view *view)
790{
791 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800792 uint32_t dw0, *dw;
793 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800794
795 CMD_ASSERT(cmd, 6, 7.5);
796
797 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800798 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
799 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800800 dw0 |= (cmd_len - 2);
801
Chia-I Wu72292b72014-09-09 10:48:33 +0800802 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
803 dw[0] = dw0;
804 dw[1] = view->cmd[6];
805 dw[2] = 0;
806
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600807 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800808 cmd_reserve_reloc(cmd, 1);
809 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
810 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600811 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800812}
813
814static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
815 const struct intel_ds_view *view)
816{
817 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800818 uint32_t dw0, *dw;
819 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800820
821 CMD_ASSERT(cmd, 6, 7.5);
822
823 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800824 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
825 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800826 dw0 |= (cmd_len - 2);
827
Chia-I Wu72292b72014-09-09 10:48:33 +0800828 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
829 dw[0] = dw0;
830 dw[1] = view->cmd[8];
831 dw[2] = 0;
832
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600833 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800834 cmd_reserve_reloc(cmd, 1);
835 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
836 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600837 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800838}
839
Chia-I Wuf8231032014-08-25 10:44:45 +0800840static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
841 uint32_t clear_val)
842{
843 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800844 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800845 GEN6_CLEAR_PARAMS_DW0_VALID |
846 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800847 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800848
849 CMD_ASSERT(cmd, 6, 6);
850
Chia-I Wu72292b72014-09-09 10:48:33 +0800851 cmd_batch_pointer(cmd, cmd_len, &dw);
852 dw[0] = dw0;
853 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800854}
855
856static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
857 uint32_t clear_val)
858{
859 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800860 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800861 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800862 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800863
864 CMD_ASSERT(cmd, 7, 7.5);
865
Chia-I Wu72292b72014-09-09 10:48:33 +0800866 cmd_batch_pointer(cmd, cmd_len, &dw);
867 dw[0] = dw0;
868 dw[1] = clear_val;
869 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800870}
871
Chia-I Wu302742d2014-08-22 10:28:29 +0800872static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800873 uint32_t blend_offset,
874 uint32_t ds_offset,
875 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800876{
877 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800878 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800879
880 CMD_ASSERT(cmd, 6, 6);
881
Chia-I Wu426072d2014-08-26 14:31:55 +0800882 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800883 (cmd_len - 2);
884
Chia-I Wu72292b72014-09-09 10:48:33 +0800885 cmd_batch_pointer(cmd, cmd_len, &dw);
886 dw[0] = dw0;
887 dw[1] = blend_offset | 1;
888 dw[2] = ds_offset | 1;
889 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800890}
891
Chia-I Wu1744cca2014-08-22 11:10:17 +0800892static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800893 uint32_t clip_offset,
894 uint32_t sf_offset,
895 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896{
897 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800899
900 CMD_ASSERT(cmd, 6, 6);
901
Chia-I Wu426072d2014-08-26 14:31:55 +0800902 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800903 GEN6_PTR_VP_DW0_CLIP_CHANGED |
904 GEN6_PTR_VP_DW0_SF_CHANGED |
905 GEN6_PTR_VP_DW0_CC_CHANGED |
906 (cmd_len - 2);
907
Chia-I Wu72292b72014-09-09 10:48:33 +0800908 cmd_batch_pointer(cmd, cmd_len, &dw);
909 dw[0] = dw0;
910 dw[1] = clip_offset;
911 dw[2] = sf_offset;
912 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800913}
914
915static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800917{
918 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800919 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800920
921 CMD_ASSERT(cmd, 6, 6);
922
Chia-I Wu426072d2014-08-26 14:31:55 +0800923 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800924 (cmd_len - 2);
925
Chia-I Wu72292b72014-09-09 10:48:33 +0800926 cmd_batch_pointer(cmd, cmd_len, &dw);
927 dw[0] = dw0;
928 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800929}
930
Chia-I Wu42a56202014-08-23 16:47:48 +0800931static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800932 uint32_t vs_offset,
933 uint32_t gs_offset,
934 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800935{
936 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800937 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800938
939 CMD_ASSERT(cmd, 6, 6);
940
Chia-I Wu426072d2014-08-26 14:31:55 +0800941 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800942 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
943 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
944 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
945 (cmd_len - 2);
946
Chia-I Wu72292b72014-09-09 10:48:33 +0800947 cmd_batch_pointer(cmd, cmd_len, &dw);
948 dw[0] = dw0;
949 dw[1] = vs_offset;
950 dw[2] = gs_offset;
951 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800952}
953
Chia-I Wu257e75e2014-08-29 14:06:35 +0800954static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 uint32_t vs_offset,
956 uint32_t gs_offset,
957 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800958{
959 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800960 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800961
962 CMD_ASSERT(cmd, 6, 6);
963
964 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
965 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
966 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
967 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
968 (cmd_len - 2);
969
Chia-I Wu72292b72014-09-09 10:48:33 +0800970 cmd_batch_pointer(cmd, cmd_len, &dw);
971 dw[0] = dw0;
972 dw[1] = vs_offset;
973 dw[2] = gs_offset;
974 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800975}
976
Chia-I Wu302742d2014-08-22 10:28:29 +0800977static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800978 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800979{
980 const uint8_t cmd_len = 2;
981 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
982 GEN6_RENDER_SUBTYPE_3D |
983 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800984 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800985
Chia-I Wu72292b72014-09-09 10:48:33 +0800986 cmd_batch_pointer(cmd, cmd_len, &dw);
987 dw[0] = dw0;
988 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800989}
990
Chia-I Wu72292b72014-09-09 10:48:33 +0800991static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800992 const struct intel_blend_state *state)
993{
Chia-I Wu72292b72014-09-09 10:48:33 +0800994 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800995 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
996
997 CMD_ASSERT(cmd, 6, 7.5);
998 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
999
Chia-I Wu00b51a82014-09-09 12:07:37 +08001000 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
1001 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001002}
1003
Chia-I Wu72292b72014-09-09 10:48:33 +08001004static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001005 const struct intel_ds_state *state)
1006{
Chia-I Wu72292b72014-09-09 10:48:33 +08001007 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001008 const uint8_t cmd_len = 3;
1009
1010 CMD_ASSERT(cmd, 6, 7.5);
1011 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1012
Chia-I Wu00b51a82014-09-09 12:07:37 +08001013 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1014 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001015}
1016
Chia-I Wu72292b72014-09-09 10:48:33 +08001017static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001018 uint32_t stencil_ref,
1019 const uint32_t blend_color[4])
1020{
Chia-I Wu72292b72014-09-09 10:48:33 +08001021 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001022 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001023 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001024
1025 CMD_ASSERT(cmd, 6, 7.5);
1026
Chia-I Wu00b51a82014-09-09 12:07:37 +08001027 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1028 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001029 dw[0] = stencil_ref;
1030 dw[1] = 0;
1031 dw[2] = blend_color[0];
1032 dw[3] = blend_color[1];
1033 dw[4] = blend_color[2];
1034 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001035
Chia-I Wu72292b72014-09-09 10:48:33 +08001036 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001037}
1038
Chia-I Wu8370b402014-08-29 12:28:37 +08001039static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001040{
Chia-I Wu8370b402014-08-29 12:28:37 +08001041 CMD_ASSERT(cmd, 6, 7.5);
1042
Chia-I Wu707a29e2014-08-27 12:51:47 +08001043 if (!cmd->bind.draw_count)
1044 return;
1045
Chia-I Wu8370b402014-08-29 12:28:37 +08001046 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001047 return;
1048
Chia-I Wu8370b402014-08-29 12:28:37 +08001049 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001050
1051 /*
1052 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1053 *
1054 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1055 * pipe-control with a post-sync op and no write-cache flushes."
1056 *
1057 * The workaround below necessitates this workaround.
1058 */
1059 gen6_PIPE_CONTROL(cmd,
1060 GEN6_PIPE_CONTROL_CS_STALL |
1061 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001062 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001063
Chia-I Wud6d079d2014-08-31 13:14:21 +08001064 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1065 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001066}
1067
Chia-I Wu8370b402014-08-29 12:28:37 +08001068static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001069{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001070 CMD_ASSERT(cmd, 6, 7.5);
1071
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001072 if (!cmd->bind.draw_count)
1073 return;
1074
Chia-I Wud6d079d2014-08-31 13:14:21 +08001075 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1076 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001077}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001078
Chia-I Wu8370b402014-08-29 12:28:37 +08001079static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1080{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001081 CMD_ASSERT(cmd, 7, 7.5);
1082
Chia-I Wu8370b402014-08-29 12:28:37 +08001083 if (!cmd->bind.draw_count)
1084 return;
1085
1086 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001087
1088 gen6_PIPE_CONTROL(cmd,
1089 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001090 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001091}
1092
Chia-I Wu8370b402014-08-29 12:28:37 +08001093static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1094{
1095 CMD_ASSERT(cmd, 7, 7.5);
1096
1097 if (!cmd->bind.draw_count)
1098 return;
1099
1100 /*
1101 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1102 *
1103 * "One of the following must also be set (when CS stall is set):
1104 *
1105 * * Render Target Cache Flush Enable ([12] of DW1)
1106 * * Depth Cache Flush Enable ([0] of DW1)
1107 * * Stall at Pixel Scoreboard ([1] of DW1)
1108 * * Depth Stall ([13] of DW1)
1109 * * Post-Sync Operation ([13] of DW1)"
1110 */
1111 gen6_PIPE_CONTROL(cmd,
1112 GEN6_PIPE_CONTROL_CS_STALL |
1113 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001114 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001115}
1116
1117static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1118{
1119 CMD_ASSERT(cmd, 7, 7.5);
1120
1121 if (!cmd->bind.draw_count)
1122 return;
1123
1124 cmd_wa_gen6_pre_depth_stall_write(cmd);
1125
Chia-I Wud6d079d2014-08-31 13:14:21 +08001126 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001127}
1128
1129static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1130{
1131 CMD_ASSERT(cmd, 6, 7.5);
1132
1133 if (!cmd->bind.draw_count)
1134 return;
1135
1136 /*
1137 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1138 *
1139 * "Driver must guarentee that all the caches in the depth pipe are
1140 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1141 * requires driver to send a PIPE_CONTROL with a CS stall along with
1142 * a Depth Flush prior to this command."
1143 *
1144 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1145 *
1146 * "Driver must ierarchi that all the caches in the depth pipe are
1147 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1148 * requires driver to send a PIPE_CONTROL with a CS stall along with
1149 * a Depth Flush prior to this command.
1150 */
1151 gen6_PIPE_CONTROL(cmd,
1152 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1153 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001154 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001155}
1156
1157static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1158{
1159 CMD_ASSERT(cmd, 6, 7.5);
1160
1161 if (!cmd->bind.draw_count)
1162 return;
1163
1164 /*
1165 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1166 *
1167 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1168 * and a post sync operation prior to the group of depth
1169 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1170 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1171 *
1172 * This workaround satifies all the conditions.
1173 */
1174 cmd_wa_gen6_pre_depth_stall_write(cmd);
1175
1176 /*
1177 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1178 *
1179 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1180 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1181 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1182 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1183 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1184 * Depth Flush Bit set, followed by another pipelined depth stall
1185 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1186 * guarantee that the pipeline from WM onwards is already flushed
1187 * (e.g., via a preceding MI_FLUSH)."
1188 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001189 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1190 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1191 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001192}
1193
Chia-I Wu525c6602014-08-27 10:22:34 +08001194void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1195{
1196 if (!cmd->bind.draw_count)
1197 return;
1198
1199 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1200
Chia-I Wu8370b402014-08-29 12:28:37 +08001201 /*
1202 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1203 *
1204 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1205 * PIPE_CONTROL with any non-zero post-sync-op is required."
1206 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001207 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001208 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001209
Chia-I Wu092279a2014-08-30 19:05:30 +08001210 /*
1211 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1212 *
1213 * "One of the following must also be set (when CS stall is set):
1214 *
1215 * * Render Target Cache Flush Enable ([12] of DW1)
1216 * * Depth Cache Flush Enable ([0] of DW1)
1217 * * Stall at Pixel Scoreboard ([1] of DW1)
1218 * * Depth Stall ([13] of DW1)
1219 * * Post-Sync Operation ([13] of DW1)"
1220 */
1221 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1222 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1223 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1224 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1225 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1226 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1227
Chia-I Wud6d079d2014-08-31 13:14:21 +08001228 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001229}
1230
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001231void cmd_batch_flush_all(struct intel_cmd *cmd)
1232{
1233 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1234 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1235 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1236 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1237 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1238 GEN6_PIPE_CONTROL_CS_STALL);
1239}
1240
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001241void cmd_batch_depth_count(struct intel_cmd *cmd,
1242 struct intel_bo *bo,
1243 XGL_GPU_SIZE offset)
1244{
1245 cmd_wa_gen6_pre_depth_stall_write(cmd);
1246
1247 gen6_PIPE_CONTROL(cmd,
1248 GEN6_PIPE_CONTROL_DEPTH_STALL |
1249 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001250 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001251}
1252
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001253void cmd_batch_timestamp(struct intel_cmd *cmd,
1254 struct intel_bo *bo,
1255 XGL_GPU_SIZE offset)
1256{
1257 /* need any WA or stall? */
1258 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1259}
1260
1261void cmd_batch_immediate(struct intel_cmd *cmd,
1262 struct intel_bo *bo,
1263 XGL_GPU_SIZE offset,
1264 uint64_t val)
1265{
1266 /* need any WA or stall? */
1267 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1268}
1269
Chia-I Wu302742d2014-08-22 10:28:29 +08001270static void gen6_cc_states(struct intel_cmd *cmd)
1271{
1272 const struct intel_blend_state *blend = cmd->bind.state.blend;
1273 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001274 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001275 uint32_t stencil_ref;
1276 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001277
1278 CMD_ASSERT(cmd, 6, 6);
1279
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001280 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001281 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001282 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1283 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001284 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001285 memset(blend_color, 0, sizeof(blend_color));
1286 }
1287
1288 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001289 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001290 stencil_ref = ds->cmd_stencil_ref;
1291 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001292 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001293 stencil_ref = 0;
1294 }
1295
Chia-I Wu72292b72014-09-09 10:48:33 +08001296 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001297
Chia-I Wu72292b72014-09-09 10:48:33 +08001298 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001299}
1300
Chia-I Wu1744cca2014-08-22 11:10:17 +08001301static void gen6_viewport_states(struct intel_cmd *cmd)
1302{
1303 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001304 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001305
1306 if (!viewport)
1307 return;
1308
Chia-I Wub1d450a2014-09-09 13:48:03 +08001309 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1310 viewport->viewport_count);
1311
1312 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1313 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1314 viewport->cmd);
1315
1316 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1317 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1318 &viewport->cmd[viewport->cmd_clip_pos]);
1319
1320 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1321 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1322 &viewport->cmd[viewport->cmd_cc_pos]);
1323
1324 if (viewport->scissor_enable) {
1325 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1326 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1327 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1328 } else {
1329 scissor_offset = 0;
1330 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001331
1332 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001333 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001334
Chia-I Wub1d450a2014-09-09 13:48:03 +08001335 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001336}
1337
Chia-I Wu302742d2014-08-22 10:28:29 +08001338static void gen7_cc_states(struct intel_cmd *cmd)
1339{
1340 const struct intel_blend_state *blend = cmd->bind.state.blend;
1341 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001342 uint32_t stencil_ref;
1343 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001344 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001345
1346 CMD_ASSERT(cmd, 7, 7.5);
1347
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001348 if (!blend && !ds)
1349 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001350
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001351 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001352 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001353 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001354 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001355
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001356 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1357 } else {
1358 memset(blend_color, 0, sizeof(blend_color));
1359 }
1360
1361 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001362 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001363 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001364 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1365 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001366 } else {
1367 stencil_ref = 0;
1368 }
1369
Chia-I Wu72292b72014-09-09 10:48:33 +08001370 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001371 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001372 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001373}
1374
Chia-I Wu1744cca2014-08-22 11:10:17 +08001375static void gen7_viewport_states(struct intel_cmd *cmd)
1376{
1377 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001378 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001379
1380 if (!viewport)
1381 return;
1382
Chia-I Wub1d450a2014-09-09 13:48:03 +08001383 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1384 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001385
Chia-I Wub1d450a2014-09-09 13:48:03 +08001386 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1387 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1388 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001389 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001390 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1391 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001392
1393 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1394 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1395 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001396 gen7_3dstate_pointer(cmd,
1397 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001398 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001399
Chia-I Wu1744cca2014-08-22 11:10:17 +08001400 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001401 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1402 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1403 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001404 gen7_3dstate_pointer(cmd,
1405 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001406 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001407 }
1408}
1409
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001410static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001411 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001412{
1413 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001414 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001415
Chia-I Wu72292b72014-09-09 10:48:33 +08001416 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001417
1418 dw[0] = GEN6_RENDER_TYPE_RENDER |
1419 GEN6_RENDER_SUBTYPE_3D |
1420 subop | (cmd_len - 2);
1421 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001422 dw[2] = 0;
1423 dw[3] = 0;
1424 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001425}
1426
1427static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001428 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001429{
1430 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001431 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001432
Chia-I Wu72292b72014-09-09 10:48:33 +08001433 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001434
1435 dw[0] = GEN6_RENDER_TYPE_RENDER |
1436 GEN6_RENDER_SUBTYPE_3D |
1437 subop | (cmd_len - 2);
1438 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001439 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001440 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001441 dw[4] = 0;
1442 dw[5] = 0;
1443 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001444}
1445
Chia-I Wu625105f2014-10-13 15:35:29 +08001446static uint32_t emit_samplers(struct intel_cmd *cmd,
1447 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001448{
1449 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1450 const XGL_UINT border_stride =
1451 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001452 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001453 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001454 XGL_UINT i;
1455
1456 CMD_ASSERT(cmd, 6, 7.5);
1457
Chia-I Wu625105f2014-10-13 15:35:29 +08001458 if (!rmap || !rmap->sampler_count)
1459 return 0;
1460
1461 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1462
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001463 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1464 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1465 border_stride * rmap->sampler_count, &border_dw);
1466
1467 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1468 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1469 4 * rmap->sampler_count, &sampler_dw);
1470
1471 for (i = 0; i < rmap->sampler_count; i++) {
1472 const struct intel_pipeline_rmap_slot *slot =
1473 &rmap->slots[surface_count + i];
1474 const struct intel_sampler *sampler;
1475
1476 switch (slot->path_len) {
1477 case 0:
1478 sampler = NULL;
1479 break;
1480 case INTEL_PIPELINE_RMAP_SLOT_RT:
1481 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1482 assert(!"unexpected rmap slot type");
1483 sampler = NULL;
1484 break;
1485 case 1:
1486 {
1487 const struct intel_dset *dset = cmd->bind.dset.graphics;
1488 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1489 const struct intel_dset_slot *dset_slot =
1490 &dset->slots[slot_offset + slot->u.index];
1491
1492 switch (dset_slot->type) {
1493 case INTEL_DSET_SLOT_SAMPLER:
1494 sampler = dset_slot->u.sampler;
1495 break;
1496 default:
1497 assert(!"unexpected dset slot type");
1498 sampler = NULL;
1499 break;
1500 }
1501 }
1502 break;
1503 default:
1504 assert(!"nested descriptor set unsupported");
1505 sampler = NULL;
1506 break;
1507 }
1508
1509 if (sampler) {
1510 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1511
1512 sampler_dw[0] = sampler->cmd[0];
1513 sampler_dw[1] = sampler->cmd[1];
1514 sampler_dw[2] = border_offset;
1515 sampler_dw[3] = sampler->cmd[2];
1516 } else {
1517 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1518 sampler_dw[1] = 0;
1519 sampler_dw[2] = 0;
1520 sampler_dw[3] = 0;
1521 }
1522
1523 border_offset += border_stride * 4;
1524 border_dw += border_stride;
1525 sampler_dw += 4;
1526 }
1527
Chia-I Wu625105f2014-10-13 15:35:29 +08001528 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001529}
1530
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001531static uint32_t emit_binding_table(struct intel_cmd *cmd,
1532 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001533{
Chia-I Wu72292b72014-09-09 10:48:33 +08001534 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001535 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001536
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001537 CMD_ASSERT(cmd, 6, 7.5);
1538
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001539 surface_count = (rmap) ?
1540 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1541 if (!surface_count)
1542 return 0;
1543
Chia-I Wu42a56202014-08-23 16:47:48 +08001544 assert(surface_count <= ARRAY_SIZE(binding_table));
1545
1546 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001547 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001548
1549 switch (slot->path_len) {
1550 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001551 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001552 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001553 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001554 {
1555 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1556
Chia-I Wu00b51a82014-09-09 12:07:37 +08001557 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001558 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1559 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001560
Chia-I Wu72292b72014-09-09 10:48:33 +08001561 cmd_reserve_reloc(cmd, 1);
1562 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1563 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001564 }
1565 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001566 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001567 {
1568 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001569 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001570
Chia-I Wu00b51a82014-09-09 12:07:37 +08001571 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001572 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1573 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001574
Chia-I Wu72292b72014-09-09 10:48:33 +08001575 cmd_reserve_reloc(cmd, 1);
1576 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1577 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001578 }
1579 break;
1580 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001581 {
1582 const struct intel_dset *dset = cmd->bind.dset.graphics;
1583 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1584 const struct intel_dset_slot *dset_slot =
1585 &dset->slots[slot_offset + slot->u.index];
1586
1587 switch (dset_slot->type) {
1588 case INTEL_DSET_SLOT_IMG_VIEW:
1589 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1590 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1591 dset_slot->u.img_view->cmd_len,
1592 dset_slot->u.img_view->cmd);
1593
1594 cmd_reserve_reloc(cmd, 1);
1595 cmd_surface_reloc(cmd, offset, 1,
1596 dset_slot->u.img_view->img->obj.mem->bo,
1597 dset_slot->u.img_view->cmd[1], 0);
1598 break;
1599 case INTEL_DSET_SLOT_MEM_VIEW:
1600 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1601 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1602 dset_slot->u.mem_view.cmd_len,
1603 dset_slot->u.mem_view.cmd);
1604
1605 cmd_reserve_reloc(cmd, 1);
1606 cmd_surface_reloc(cmd, offset, 1,
1607 dset_slot->u.mem_view.mem->bo,
1608 dset_slot->u.mem_view.cmd[1], 0);
1609 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001610 case INTEL_DSET_SLOT_SAMPLER:
1611 assert(0 == cmd->bind.dset.graphics_offset);
1612
1613 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1614 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1615 16, dset_slot->u.sampler->cmd);
1616 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001617 default:
1618 assert(!"unexpected dset slot type");
1619 break;
1620 }
1621 }
1622 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001623 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001624 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001625 break;
1626 }
1627
Chia-I Wu72292b72014-09-09 10:48:33 +08001628 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001629 }
1630
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001631 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001632 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001633 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001634}
1635
Chia-I Wu1d125092014-10-08 08:49:38 +08001636static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1637{
1638 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1639 const struct intel_pipeline_rmap *rmap = pipeline->vs.rmap;
1640 const struct intel_dset *dset = cmd->bind.dset.graphics;
1641 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1642 uint32_t *dw;
1643 XGL_UINT pos, i;
1644
1645 CMD_ASSERT(cmd, 6, 7.5);
1646
1647 if (!pipeline->vb_count)
1648 return;
1649
1650 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1651
1652 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1653 dw++;
1654 pos++;
1655
1656 for (i = 0; i < pipeline->vb_count; i++) {
1657 const XGL_UINT vb_offset = rmap->rt_count + rmap->resource_count +
1658 rmap->uav_count + rmap->sampler_count;
1659 const struct intel_pipeline_rmap_slot *slot = (i < rmap->vb_count) ?
1660 &rmap->slots[vb_offset + i] : NULL;
1661 struct intel_mem_view *view = NULL;
1662
1663 if (slot) {
1664 switch (slot->path_len) {
1665 case 1:
1666 view = (dset->slots[slot->u.index].type ==
1667 INTEL_DSET_SLOT_MEM_VIEW) ?
1668 &dset->slots[slot->u.index].u.mem_view : NULL;
1669 break;
1670 default:
1671 break;
1672 }
1673 }
1674
1675 assert(pipeline->vb[i].strideInBytes <= 2048);
1676
1677 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1678 pipeline->vb[i].strideInBytes;
1679
1680 if (cmd_gen(cmd) >= INTEL_GEN(7))
1681 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1682
1683 switch (pipeline->vb[i].stepRate) {
1684 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1685 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1686 dw[3] = 0;
1687 break;
1688 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1689 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1690 dw[3] = 1;
1691 break;
1692 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1693 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1694 dw[3] = 0;
1695 break;
1696 default:
1697 assert(!"unknown step rate");
1698 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1699 dw[3] = 0;
1700 break;
1701 }
1702
1703 if (view) {
1704 const uint32_t begin = view->cmd[1];
1705 const uint32_t end = view->mem->size - 1;
1706
1707 cmd_reserve_reloc(cmd, 2);
1708 cmd_batch_reloc(cmd, pos + 1, view->mem->bo, begin, 0);
1709 cmd_batch_reloc(cmd, pos + 2, view->mem->bo, end, 0);
1710 } else {
1711 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1712 dw[1] = 0;
1713 dw[2] = 0;
1714 }
1715
1716 dw += 4;
1717 pos += 4;
1718 }
1719}
1720
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001721static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1722{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001723 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1724 const struct intel_pipeline_shader *vs = &pipeline->vs;
1725 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001726 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001727 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001728 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001729
1730 CMD_ASSERT(cmd, 6, 7.5);
1731
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001732 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001733 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1734 *
1735 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1736 * 128-bit vertex elements to be passed into the payload for each
1737 * vertex."
1738 *
1739 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1740 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001741 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001742 vue_read_len = (vs->in_count + 1) / 2;
1743 if (!vue_read_len)
1744 vue_read_len = 1;
1745
1746 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1747 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1748
1749 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1750 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1751 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001752
1753 dw5 = GEN6_VS_DW5_STATISTICS |
1754 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001755
1756 switch (cmd_gen(cmd)) {
1757 case INTEL_GEN(7.5):
1758 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1759 break;
1760 case INTEL_GEN(7):
1761 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1762 break;
1763 case INTEL_GEN(6):
1764 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1765 break;
1766 default:
1767 max_threads = 1;
1768 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001769 }
1770
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001771 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1772 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1773 else
1774 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1775
Chia-I Wube0a3d92014-09-02 13:20:59 +08001776 if (pipeline->disable_vs_cache)
1777 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1778
Chia-I Wu72292b72014-09-09 10:48:33 +08001779 cmd_batch_pointer(cmd, cmd_len, &dw);
1780 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001781 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001782 dw[2] = dw2;
1783 dw[3] = 0; /* scratch */
1784 dw[4] = dw4;
1785 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001786}
1787
Chia-I Wu625105f2014-10-13 15:35:29 +08001788static void emit_shader_resources(struct intel_cmd *cmd)
1789{
1790 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001791 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001792
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001793 binding_tables[0] = emit_binding_table(cmd,
1794 cmd->bind.pipeline.graphics->vs.rmap);
1795 binding_tables[1] = emit_binding_table(cmd,
1796 cmd->bind.pipeline.graphics->tcs.rmap);
1797 binding_tables[2] = emit_binding_table(cmd,
1798 cmd->bind.pipeline.graphics->tes.rmap);
1799 binding_tables[3] = emit_binding_table(cmd,
1800 cmd->bind.pipeline.graphics->gs.rmap);
1801 binding_tables[4] = emit_binding_table(cmd,
1802 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001803
1804 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1805 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1806 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1807 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1808 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1809
1810 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1811 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001812 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1813 binding_tables[0]);
1814 gen7_3dstate_pointer(cmd,
1815 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1816 binding_tables[1]);
1817 gen7_3dstate_pointer(cmd,
1818 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1819 binding_tables[2]);
1820 gen7_3dstate_pointer(cmd,
1821 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1822 binding_tables[3]);
1823 gen7_3dstate_pointer(cmd,
1824 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1825 binding_tables[4]);
1826
1827 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001828 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1829 samplers[0]);
1830 gen7_3dstate_pointer(cmd,
1831 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1832 samplers[1]);
1833 gen7_3dstate_pointer(cmd,
1834 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1835 samplers[2]);
1836 gen7_3dstate_pointer(cmd,
1837 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1838 samplers[3]);
1839 gen7_3dstate_pointer(cmd,
1840 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1841 samplers[4]);
1842 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001843 assert(!binding_tables[1] && !binding_tables[2]);
1844 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1845 binding_tables[0], binding_tables[3], binding_tables[4]);
1846
Chia-I Wu625105f2014-10-13 15:35:29 +08001847 assert(!samplers[1] && !samplers[2]);
1848 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1849 samplers[0], samplers[3], samplers[4]);
1850 }
1851}
1852
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001853static void emit_rt(struct intel_cmd *cmd)
1854{
1855 cmd_wa_gen6_pre_depth_stall_write(cmd);
1856 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1857 cmd->bind.att.height);
1858}
1859
1860static void emit_ds(struct intel_cmd *cmd)
1861{
1862 const struct intel_ds_view *ds = cmd->bind.att.ds;
1863
1864 if (!ds) {
1865 /* all zeros */
1866 static const struct intel_ds_view null_ds;
1867 ds = &null_ds;
1868 }
1869
1870 cmd_wa_gen6_pre_ds_flush(cmd);
1871 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1872 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1873 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1874
1875 if (cmd_gen(cmd) >= INTEL_GEN(7))
1876 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1877 else
1878 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1879}
1880
Chia-I Wua57761b2014-10-14 14:27:44 +08001881static uint32_t emit_shader(struct intel_cmd *cmd,
1882 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001883{
Chia-I Wua57761b2014-10-14 14:27:44 +08001884 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1885 uint32_t offset;
1886 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001887
Chia-I Wua57761b2014-10-14 14:27:44 +08001888 /* see if the shader is already in the cache */
1889 for (i = 0; i < cache->used; i++) {
1890 if (cache->entries[i].shader == (const void *) shader)
1891 return cache->entries[i].kernel_offset;
1892 }
1893
1894 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1895
1896 /* grow the cache if full */
1897 if (cache->used >= cache->count) {
1898 const XGL_UINT count = cache->count + 16;
1899 void *entries;
1900
1901 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1902 XGL_SYSTEM_ALLOC_INTERNAL);
1903 if (entries) {
1904 if (cache->entries) {
1905 memcpy(entries, cache->entries,
1906 sizeof(cache->entries[0]) * cache->used);
1907 icd_free(cache->entries);
1908 }
1909
1910 cache->entries = entries;
1911 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001912 }
1913 }
1914
Chia-I Wua57761b2014-10-14 14:27:44 +08001915 /* add the shader to the cache */
1916 if (cache->used < cache->count) {
1917 cache->entries[cache->used].shader = (const void *) shader;
1918 cache->entries[cache->used].kernel_offset = offset;
1919 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001920 }
1921
Chia-I Wua57761b2014-10-14 14:27:44 +08001922 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001923}
1924
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001925static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001926{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001927 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001928
Chia-I Wu8370b402014-08-29 12:28:37 +08001929 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1930 cmd_wa_gen6_pre_depth_stall_write(cmd);
1931 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1932 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1933 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1934 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001935
1936 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001937 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001938 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001939
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001940 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001941 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001942 }
1943 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001944 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001945 }
1946 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001947 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1948 }
1949 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1950 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1951 }
1952 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1953 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001954 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001955
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001956 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1957 gen7_3DSTATE_GS(cmd);
1958 } else {
1959 gen6_3DSTATE_GS(cmd);
1960 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001961
Chia-I Wu8370b402014-08-29 12:28:37 +08001962 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1963 cmd_wa_gen7_post_command_cs_stall(cmd);
1964 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1965 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001966}
1967
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001968static void emit_bounded_states(struct intel_cmd *cmd)
1969{
1970 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1971
1972 emit_graphics_pipeline(cmd);
1973
1974 emit_rt(cmd);
1975 emit_ds(cmd);
1976
1977 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1978 gen7_cc_states(cmd);
1979 gen7_viewport_states(cmd);
1980
1981 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1982 &cmd->bind.pipeline.graphics->vs);
1983 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1984 &cmd->bind.pipeline.graphics->fs);
1985
1986 gen6_3DSTATE_CLIP(cmd);
1987 gen7_3DSTATE_SF(cmd);
1988 gen7_3DSTATE_SBE(cmd);
1989 gen7_3DSTATE_WM(cmd);
1990 gen7_3DSTATE_PS(cmd);
1991 } else {
1992 gen6_cc_states(cmd);
1993 gen6_viewport_states(cmd);
1994
1995 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1996 &cmd->bind.pipeline.graphics->vs);
1997 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1998 &cmd->bind.pipeline.graphics->fs);
1999
2000 gen6_3DSTATE_CLIP(cmd);
2001 gen6_3DSTATE_SF(cmd);
2002 gen6_3DSTATE_WM(cmd);
2003 }
2004
2005 emit_shader_resources(cmd);
2006
2007 cmd_wa_gen6_pre_depth_stall_write(cmd);
2008 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2009
2010 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2011 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2012
2013 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2014 gen6_3DSTATE_VS(cmd);
2015}
2016
Chia-I Wu6032b892014-10-17 14:47:18 +08002017static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2018{
2019 const struct intel_cmd_meta *meta = cmd->bind.meta;
2020 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2021
2022 CMD_ASSERT(cmd, 6, 7.5);
2023
2024 blend_offset = 0;
2025 ds_offset = 0;
2026 cc_offset = 0;
2027 cc_vp_offset = 0;
2028
2029 if (meta->dst.valid) {
2030 /* BLEND_STATE */
2031 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
2032 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2033 dw[0] = 0;
2034 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2035 }
2036
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002037 if (meta->ds.state) {
2038 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002039
2040 /* DEPTH_STENCIL_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002041 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002042
2043 /* COLOR_CALC_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002044 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2045 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002046
2047 /* CC_VIEWPORT */
2048 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
2049 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002050 dw[0] = u_fui(0.0f);
2051 dw[1] = u_fui(1.0f);
Chia-I Wua667c2b2014-10-28 11:40:29 +08002052 } else {
2053 /* DEPTH_STENCIL_STATE */
2054 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2055 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4,
2056 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2057 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
Chia-I Wu6032b892014-10-17 14:47:18 +08002058 }
2059
2060 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2061 gen7_3dstate_pointer(cmd,
2062 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2063 blend_offset);
2064 gen7_3dstate_pointer(cmd,
2065 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2066 ds_offset);
2067 gen7_3dstate_pointer(cmd,
2068 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2069
2070 gen7_3dstate_pointer(cmd,
2071 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2072 cc_vp_offset);
2073 } else {
2074 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002075 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002076
2077 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2078 cmd_batch_pointer(cmd, 4, &dw);
2079 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2080 GEN6_PTR_VP_DW0_CC_CHANGED;
2081 dw[1] = 0;
2082 dw[2] = 0;
2083 dw[3] = cc_vp_offset;
2084 }
2085}
2086
2087static void gen6_meta_surface_states(struct intel_cmd *cmd)
2088{
2089 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002090 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002091 uint32_t offset;
2092
2093 CMD_ASSERT(cmd, 6, 7.5);
2094
Chia-I Wu005c47c2014-10-22 13:49:13 +08002095 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002096 if (meta->src.valid) {
2097 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2098 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2099 meta->src.surface_len, meta->src.surface);
2100
2101 cmd_reserve_reloc(cmd, 1);
2102 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2103 cmd_surface_reloc_writer(cmd, offset, 1,
2104 meta->src.reloc_target, meta->src.reloc_offset);
2105 } else {
2106 cmd_surface_reloc(cmd, offset, 1,
2107 (struct intel_bo *) meta->src.reloc_target,
2108 meta->src.reloc_offset, meta->src.reloc_flags);
2109 }
2110
Chia-I Wu005c47c2014-10-22 13:49:13 +08002111 binding_table[0] = offset;
2112 }
2113 if (meta->dst.valid) {
2114 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2115 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2116 meta->dst.surface_len, meta->dst.surface);
2117
2118 cmd_reserve_reloc(cmd, 1);
2119 cmd_surface_reloc(cmd, offset, 1,
2120 (struct intel_bo *) meta->dst.reloc_target,
2121 meta->dst.reloc_offset, meta->dst.reloc_flags);
2122
2123 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002124 }
2125
2126 /* BINDING_TABLE */
2127 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
2128 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002129 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002130
2131 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2132 gen7_3dstate_pointer(cmd,
2133 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2134 offset);
2135 } else {
2136 /* 3DSTATE_BINDING_TABLE_POINTERS */
2137 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
2138 }
2139}
2140
2141static void gen6_meta_urb(struct intel_cmd *cmd)
2142{
2143 uint32_t *dw;
2144
2145 CMD_ASSERT(cmd, 6, 6);
2146
2147 /* 3DSTATE_URB */
2148 cmd_batch_pointer(cmd, 3, &dw);
2149 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
2150 dw[1] = 128 << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
2151 dw[2] = 0;
2152}
2153
2154static void gen7_meta_urb(struct intel_cmd *cmd)
2155{
2156 uint32_t *dw;
2157
2158 CMD_ASSERT(cmd, 7, 7.5);
2159
2160 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2161 cmd_batch_pointer(cmd, 10, &dw);
2162
2163 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
2164 dw[1] = 0;
2165 dw += 2;
2166
2167 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2168 dw[1] = 0;
2169 dw += 2;
2170
2171 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2172 dw[1] = 0;
2173 dw += 2;
2174
2175 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2176 dw[1] = 0;
2177 dw += 2;
2178
2179 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2180 dw[1] = 1;
2181
2182 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2183
2184 /* 3DSTATE_URB_x */
2185 cmd_batch_pointer(cmd, 8, &dw);
2186
2187 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2188 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
2189 512;
2190 dw += 2;
2191
2192 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2193 dw[1] = 0;
2194 dw += 2;
2195
2196 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2197 dw[1] = 0;
2198 dw += 2;
2199
2200 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2201 dw[1] = 0;
2202 dw += 2;
2203}
2204
2205static void gen6_meta_vf(struct intel_cmd *cmd)
2206{
2207 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002208 uint32_t vb_start, vb_end, vb_stride;
2209 int ve_format, ve_z_source;
2210 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002211 XGL_UINT pos;
2212
2213 CMD_ASSERT(cmd, 6, 7.5);
2214
2215 /* write vertices */
Chia-I Wu3adf7212014-10-24 15:34:07 +08002216 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2217 XGL_FLOAT vertices[3][3];
2218
2219 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2220 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2221 vertices[0][2] = u_uif(meta->clear_val[0]);
2222 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2223 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2224 vertices[1][2] = u_uif(meta->clear_val[0]);
2225 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2226 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2227 vertices[2][2] = u_uif(meta->clear_val[0]);
2228
2229 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2230 sizeof(vertices) / 4, (const uint32_t *) vertices);
2231
2232 vb_end = vb_start + sizeof(vertices) - 1;
2233 vb_stride = sizeof(vertices[0]);
2234 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2235 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2236 } else {
2237 XGL_UINT vertices[3][2];
2238
2239 vertices[0][0] = meta->dst.x + meta->width;
2240 vertices[0][1] = meta->dst.y + meta->height;
2241 vertices[1][0] = meta->dst.x;
2242 vertices[1][1] = meta->dst.y + meta->height;
2243 vertices[2][0] = meta->dst.x;
2244 vertices[2][1] = meta->dst.y;
2245
2246 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2247 sizeof(vertices) / 4, (const uint32_t *) vertices);
2248
2249 vb_end = vb_start + sizeof(vertices) - 1;
2250 vb_stride = sizeof(vertices[0]);
2251 ve_z_source = GEN6_VFCOMP_STORE_0;
2252 ve_format = GEN6_FORMAT_R32G32_USCALED;
2253 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002254
2255 /* 3DSTATE_VERTEX_BUFFERS */
2256 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002257
Chia-I Wu6032b892014-10-17 14:47:18 +08002258 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002259 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002260 if (cmd_gen(cmd) >= INTEL_GEN(7))
2261 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2262
2263 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002264 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2265 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002266
2267 dw[4] = 0;
2268
2269 /* 3DSTATE_VERTEX_ELEMENTS */
2270 cmd_batch_pointer(cmd, 5, &dw);
2271 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
2272 dw[1] = GEN6_VE_STATE_DW0_VALID,
2273 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2274 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2275 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2276 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2277 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002278 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002279 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2280 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002281 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002282 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2283}
2284
2285static void gen6_meta_disabled(struct intel_cmd *cmd)
2286{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002287 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002288 uint32_t *dw;
2289
2290 CMD_ASSERT(cmd, 6, 6);
2291
2292 /* 3DSTATE_CONSTANT_VS */
2293 cmd_batch_pointer(cmd, 5, &dw);
2294 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2);
2295 dw[1] = 0;
2296 dw[2] = 0;
2297 dw[3] = 0;
2298 dw[4] = 0;
2299
2300 /* 3DSTATE_VS */
2301 cmd_batch_pointer(cmd, 6, &dw);
2302 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2303 dw[1] = 0;
2304 dw[2] = 0;
2305 dw[3] = 0;
2306 dw[4] = 0;
2307 dw[5] = 0;
2308
2309 /* 3DSTATE_CONSTANT_GS */
2310 cmd_batch_pointer(cmd, 5, &dw);
2311 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2312 dw[1] = 0;
2313 dw[2] = 0;
2314 dw[3] = 0;
2315 dw[4] = 0;
2316
2317 /* 3DSTATE_GS */
2318 cmd_batch_pointer(cmd, 7, &dw);
2319 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2320 dw[1] = 0;
2321 dw[2] = 0;
2322 dw[3] = 0;
2323 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2324 dw[5] = GEN6_GS_DW5_STATISTICS;
2325 dw[6] = 0;
2326
2327 /* 3DSTATE_CLIP */
2328 cmd_batch_pointer(cmd, 4, &dw);
2329 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2330 dw[1] = 0;
2331 dw[2] = 0;
2332 dw[3] = 0;
2333
2334 /* 3DSTATE_SF */
2335 cmd_batch_pointer(cmd, 20, &dw);
2336 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2337 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2338 memset(&dw[2], 0, 18 * sizeof(*dw));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002339
2340 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2341 /* 3DSTATE_CONSTANT_PS */
2342 cmd_batch_pointer(cmd, 5, &dw);
2343 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2344 dw[1] = 0;
2345 dw[2] = 0;
2346 dw[3] = 0;
2347 dw[4] = 0;
2348
2349 /* 3DSTATE_WM */
2350 cmd_batch_pointer(cmd, 9, &dw);
2351 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2352 dw[1] = 0;
2353 dw[2] = 0;
2354 dw[3] = 0;
2355 dw[4] = 0;
2356 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
2357 dw[6] = 0;
2358 dw[7] = 0;
2359 dw[8] = 0;
2360 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002361}
2362
2363static void gen7_meta_disabled(struct intel_cmd *cmd)
2364{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002365 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002366 uint32_t *dw;
2367
2368 CMD_ASSERT(cmd, 7, 7.5);
2369
2370 /* 3DSTATE_CONSTANT_VS */
2371 cmd_batch_pointer(cmd, 7, &dw);
2372 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2373 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2374
2375 /* 3DSTATE_VS */
2376 cmd_batch_pointer(cmd, 6, &dw);
2377 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2378 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2379
2380 /* 3DSTATE_CONSTANT_HS */
2381 cmd_batch_pointer(cmd, 7, &dw);
2382 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2383 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2384
2385 /* 3DSTATE_HS */
2386 cmd_batch_pointer(cmd, 7, &dw);
2387 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2388 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2389
2390 /* 3DSTATE_TE */
2391 cmd_batch_pointer(cmd, 4, &dw);
2392 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2393 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2394
2395 /* 3DSTATE_CONSTANT_DS */
2396 cmd_batch_pointer(cmd, 7, &dw);
2397 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2398 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2399
2400 /* 3DSTATE_DS */
2401 cmd_batch_pointer(cmd, 6, &dw);
2402 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2403 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2404
2405 /* 3DSTATE_CONSTANT_GS */
2406 cmd_batch_pointer(cmd, 7, &dw);
2407 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2408 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2409
2410 /* 3DSTATE_GS */
2411 cmd_batch_pointer(cmd, 7, &dw);
2412 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2413 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2414
2415 /* 3DSTATE_STREAMOUT */
2416 cmd_batch_pointer(cmd, 3, &dw);
2417 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2418 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2419
2420 /* 3DSTATE_CLIP */
2421 cmd_batch_pointer(cmd, 4, &dw);
2422 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2423 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2424
2425 /* 3DSTATE_SF */
2426 cmd_batch_pointer(cmd, 7, &dw);
2427 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2428 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2429
2430 /* 3DSTATE_SBE */
2431 cmd_batch_pointer(cmd, 14, &dw);
2432 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2433 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2434 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002435
2436 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2437 /* 3DSTATE_WM */
2438 cmd_batch_pointer(cmd, 3, &dw);
2439 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2440 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2441
2442 /* 3DSTATE_CONSTANT_GS */
2443 cmd_batch_pointer(cmd, 7, &dw);
2444 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2445 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2446
2447 /* 3DSTATE_PS */
2448 cmd_batch_pointer(cmd, 8, &dw);
2449 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2450 dw[1] = 0;
2451 dw[2] = 0;
2452 dw[3] = 0;
2453 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
2454 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2455 dw[5] = 0;
2456 dw[6] = 0;
2457 dw[7] = 0;
2458 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002459}
2460
2461static void gen6_meta_wm(struct intel_cmd *cmd)
2462{
2463 const struct intel_cmd_meta *meta = cmd->bind.meta;
2464 uint32_t *dw;
2465
2466 CMD_ASSERT(cmd, 6, 7.5);
2467
2468 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2469
2470 /* 3DSTATE_MULTISAMPLE */
2471 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2472 cmd_batch_pointer(cmd, 4, &dw);
2473 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2474 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2475 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2476 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2477 dw[2] = 0;
2478 dw[3] = 0;
2479 } else {
2480 cmd_batch_pointer(cmd, 3, &dw);
2481 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2482 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2483 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2484 dw[2] = 0;
2485 }
2486
2487 /* 3DSTATE_SAMPLE_MASK */
2488 cmd_batch_pointer(cmd, 2, &dw);
2489 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2490 dw[1] = (1 << meta->samples) - 1;
2491
2492 /* 3DSTATE_DRAWING_RECTANGLE */
2493 cmd_batch_pointer(cmd, 4, &dw);
2494 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2495 dw[1] = meta->dst.y << 16 | meta->dst.x;
2496 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2497 (meta->dst.x + meta->width - 1);
2498 dw[3] = 0;
2499}
2500
2501static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2502{
2503 const struct intel_cmd_meta *meta = cmd->bind.meta;
2504 XGL_UINT offset_x, offset_y;
2505 /* one GPR */
2506 XGL_UINT consts[8];
2507 XGL_UINT const_count;
2508
2509 CMD_ASSERT(cmd, 6, 7.5);
2510
2511 /* underflow is fine here */
2512 offset_x = meta->src.x - meta->dst.x;
2513 offset_y = meta->src.y - meta->dst.y;
2514
2515 switch (meta->shader_id) {
2516 case INTEL_DEV_META_FS_COPY_MEM:
2517 case INTEL_DEV_META_FS_COPY_1D:
2518 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2519 case INTEL_DEV_META_FS_COPY_2D:
2520 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2521 case INTEL_DEV_META_FS_COPY_2D_MS:
2522 consts[0] = offset_x;
2523 consts[1] = offset_y;
2524 consts[2] = meta->src.layer;
2525 consts[3] = meta->src.lod;
2526 const_count = 4;
2527 break;
2528 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2529 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2530 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2531 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2532 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2533 consts[0] = offset_x;
2534 consts[1] = offset_y;
2535 consts[2] = meta->src.layer;
2536 consts[3] = meta->src.lod;
2537 consts[4] = meta->src.x;
2538 consts[5] = meta->width;
2539 const_count = 6;
2540 break;
2541 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2542 consts[0] = offset_x;
2543 consts[1] = offset_y;
2544 consts[2] = meta->width;
2545 const_count = 3;
2546 break;
2547 case INTEL_DEV_META_FS_CLEAR_COLOR:
2548 consts[0] = meta->clear_val[0];
2549 consts[1] = meta->clear_val[1];
2550 consts[2] = meta->clear_val[2];
2551 consts[3] = meta->clear_val[3];
2552 const_count = 4;
2553 break;
2554 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2555 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002556 consts[1] = meta->clear_val[1];
2557 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002558 break;
2559 case INTEL_DEV_META_FS_RESOLVE_2X:
2560 case INTEL_DEV_META_FS_RESOLVE_4X:
2561 case INTEL_DEV_META_FS_RESOLVE_8X:
2562 case INTEL_DEV_META_FS_RESOLVE_16X:
2563 consts[0] = offset_x;
2564 consts[1] = offset_y;
2565 const_count = 2;
2566 break;
2567 default:
2568 assert(!"unknown meta shader id");
2569 const_count = 0;
2570 break;
2571 }
2572
2573 /* this can be skipped but it makes state dumping prettier */
2574 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2575
2576 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2577}
2578
2579static void gen6_meta_ps(struct intel_cmd *cmd)
2580{
2581 const struct intel_cmd_meta *meta = cmd->bind.meta;
2582 const struct intel_pipeline_shader *sh =
2583 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2584 uint32_t offset, *dw;
2585
2586 CMD_ASSERT(cmd, 6, 6);
2587
Chia-I Wu3adf7212014-10-24 15:34:07 +08002588 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2589 return;
2590 /* a normal color write */
2591 assert(meta->dst.valid && !sh->uses);
2592
Chia-I Wu6032b892014-10-17 14:47:18 +08002593 /* 3DSTATE_CONSTANT_PS */
2594 offset = gen6_meta_ps_constants(cmd);
2595 cmd_batch_pointer(cmd, 5, &dw);
2596 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2597 GEN6_PCB_ANY_DW0_PCB0_VALID;
2598 dw[1] = offset;
2599 dw[2] = 0;
2600 dw[3] = 0;
2601 dw[4] = 0;
2602
2603 /* 3DSTATE_WM */
2604 offset = emit_shader(cmd, sh);
2605 cmd_batch_pointer(cmd, 9, &dw);
2606 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2607 dw[1] = offset;
2608 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2609 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2610 dw[3] = 0;
2611 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
2612 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
2613 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002614 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2615
Chia-I Wu6032b892014-10-17 14:47:18 +08002616 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2617 GEN6_WM_DW6_POSOFFSET_NONE |
2618 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2619 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2620 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2621 if (meta->samples > 1) {
2622 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2623 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2624 } else {
2625 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2626 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2627 }
2628 dw[7] = 0;
2629 dw[8] = 0;
2630}
2631
2632static void gen7_meta_ps(struct intel_cmd *cmd)
2633{
2634 const struct intel_cmd_meta *meta = cmd->bind.meta;
2635 const struct intel_pipeline_shader *sh =
2636 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2637 uint32_t offset, *dw;
2638
2639 CMD_ASSERT(cmd, 7, 7.5);
2640
Chia-I Wu3adf7212014-10-24 15:34:07 +08002641 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2642 return;
2643 /* a normal color write */
2644 assert(meta->dst.valid && !sh->uses);
2645
Chia-I Wu6032b892014-10-17 14:47:18 +08002646 /* 3DSTATE_WM */
2647 cmd_batch_pointer(cmd, 3, &dw);
2648 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2649 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2650 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2651 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2652 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2653 dw[2] = 0;
2654
2655 /* 3DSTATE_CONSTANT_PS */
2656 offset = gen6_meta_ps_constants(cmd);
2657 cmd_batch_pointer(cmd, 7, &dw);
2658 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2659 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2660 dw[2] = 0;
2661 dw[3] = offset;
2662 dw[4] = 0;
2663 dw[5] = 0;
2664 dw[6] = 0;
2665
2666 /* 3DSTATE_PS */
2667 offset = emit_shader(cmd, sh);
2668 cmd_batch_pointer(cmd, 8, &dw);
2669 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2670 dw[1] = offset;
2671 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2672 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2673 dw[3] = 0;
2674
2675 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2676 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002677 GEN7_PS_DW4_16_PIXEL_DISPATCH |
Chia-I Wu6032b892014-10-17 14:47:18 +08002678 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2679 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
2680 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
2681
2682 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2683 dw[6] = 0;
2684 dw[7] = 0;
2685}
2686
2687static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2688{
2689 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002690 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002691
2692 CMD_ASSERT(cmd, 6, 7.5);
2693
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002694 if (!ds) {
2695 /* all zeros */
2696 static const struct intel_ds_view null_ds;
2697 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002698 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002699
2700 cmd_wa_gen6_pre_ds_flush(cmd);
2701 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2702 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2703 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2704
2705 if (cmd_gen(cmd) >= INTEL_GEN(7))
2706 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2707 else
2708 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002709}
2710
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002711static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2712 const struct intel_pipeline *pipeline)
2713{
2714 cmd->bind.pipeline.graphics = pipeline;
2715}
2716
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002717static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2718 const struct intel_pipeline *pipeline)
2719{
2720 cmd->bind.pipeline.compute = pipeline;
2721}
2722
2723static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2724 const struct intel_pipeline_delta *delta)
2725{
2726 cmd->bind.pipeline.graphics_delta = delta;
2727}
2728
2729static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2730 const struct intel_pipeline_delta *delta)
2731{
2732 cmd->bind.pipeline.compute_delta = delta;
2733}
2734
2735static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2736 const struct intel_dset *dset,
2737 XGL_UINT slot_offset)
2738{
2739 cmd->bind.dset.graphics = dset;
2740 cmd->bind.dset.graphics_offset = slot_offset;
2741}
2742
2743static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2744 const struct intel_dset *dset,
2745 XGL_UINT slot_offset)
2746{
2747 cmd->bind.dset.compute = dset;
2748 cmd->bind.dset.compute_offset = slot_offset;
2749}
2750
2751static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2752 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2753{
2754 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2755}
2756
2757static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2758 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2759{
2760 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2761}
2762
2763static void cmd_bind_index_data(struct intel_cmd *cmd,
2764 const struct intel_mem *mem,
2765 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2766{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002767 cmd->bind.index.mem = mem;
2768 cmd->bind.index.offset = offset;
2769 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002770}
2771
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002772static void cmd_bind_attachments(struct intel_cmd *cmd,
2773 XGL_UINT rt_count,
2774 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2775 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002776{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002777 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002778 XGL_UINT i;
2779
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002780 for (i = 0; i < rt_count; i++) {
2781 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002782 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002783 const struct intel_layout *layout = &rt->img->layout;
2784
2785 if (i == 0) {
2786 width = layout->width0;
2787 height = layout->height0;
2788 } else {
2789 if (width > layout->width0)
2790 width = layout->width0;
2791 if (height > layout->height0)
2792 height = layout->height0;
2793 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002794
2795 cmd->bind.att.rt[i] = rt;
2796 }
2797
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002798 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002799
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002800 if (ds_info) {
2801 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002802
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002803 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2804 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002805
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002806 if (width > layout->width0)
2807 width = layout->width0;
2808 if (height > layout->height0)
2809 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002810 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002811 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002812 }
2813
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002814 cmd->bind.att.width = width;
2815 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002816}
2817
2818static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2819 const struct intel_viewport_state *state)
2820{
2821 cmd->bind.state.viewport = state;
2822}
2823
2824static void cmd_bind_raster_state(struct intel_cmd *cmd,
2825 const struct intel_raster_state *state)
2826{
2827 cmd->bind.state.raster = state;
2828}
2829
2830static void cmd_bind_ds_state(struct intel_cmd *cmd,
2831 const struct intel_ds_state *state)
2832{
2833 cmd->bind.state.ds = state;
2834}
2835
2836static void cmd_bind_blend_state(struct intel_cmd *cmd,
2837 const struct intel_blend_state *state)
2838{
2839 cmd->bind.state.blend = state;
2840}
2841
2842static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2843 const struct intel_msaa_state *state)
2844{
2845 cmd->bind.state.msaa = state;
2846}
2847
2848static void cmd_draw(struct intel_cmd *cmd,
2849 XGL_UINT vertex_start,
2850 XGL_UINT vertex_count,
2851 XGL_UINT instance_start,
2852 XGL_UINT instance_count,
2853 bool indexed,
2854 XGL_UINT vertex_base)
2855{
2856 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2857
2858 emit_bounded_states(cmd);
2859
2860 if (indexed) {
2861 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2862 cmd->result = XGL_ERROR_UNKNOWN;
2863
2864 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2865 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2866 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002867 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2868 cmd->bind.index.offset, cmd->bind.index.type,
2869 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002870 } else {
2871 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2872 cmd->bind.index.offset, cmd->bind.index.type,
2873 p->primitive_restart);
2874 }
2875 } else {
2876 assert(!vertex_base);
2877 }
2878
2879 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2880 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2881 vertex_start, instance_count, instance_start, vertex_base);
2882 } else {
2883 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2884 vertex_start, instance_count, instance_start, vertex_base);
2885 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002886
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002887 if (intel_debug & INTEL_DEBUG_NOCACHE)
2888 cmd_batch_flush_all(cmd);
2889
Chia-I Wu707a29e2014-08-27 12:51:47 +08002890 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002891 /* need to re-emit all workarounds */
2892 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002893}
2894
Chia-I Wuc14d1562014-10-17 09:49:22 +08002895void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2896{
Chia-I Wu6032b892014-10-17 14:47:18 +08002897 cmd->bind.meta = meta;
2898
2899 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08002900 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002901
2902 gen6_meta_dynamic_states(cmd);
2903 gen6_meta_surface_states(cmd);
2904
2905 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2906 gen7_meta_urb(cmd);
2907 gen6_meta_vf(cmd);
2908 gen7_meta_disabled(cmd);
2909 gen6_meta_wm(cmd);
2910 gen7_meta_ps(cmd);
2911 gen6_meta_depth_buffer(cmd);
2912
2913 cmd_wa_gen7_post_command_cs_stall(cmd);
2914 cmd_wa_gen7_post_command_depth_stall(cmd);
2915
2916 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2917 } else {
2918 gen6_meta_urb(cmd);
2919 gen6_meta_vf(cmd);
2920 gen6_meta_disabled(cmd);
2921 gen6_meta_wm(cmd);
2922 gen6_meta_ps(cmd);
2923 gen6_meta_depth_buffer(cmd);
2924
2925 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2926 }
2927
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002928 if (intel_debug & INTEL_DEBUG_NOCACHE)
2929 cmd_batch_flush_all(cmd);
2930
Chia-I Wu6032b892014-10-17 14:47:18 +08002931 cmd->bind.draw_count++;
2932 /* need to re-emit all workarounds */
2933 cmd->bind.wa_flags = 0;
2934
2935 cmd->bind.meta = NULL;
Chia-I Wuc14d1562014-10-17 09:49:22 +08002936}
2937
Chia-I Wub2755562014-08-20 13:38:52 +08002938XGL_VOID XGLAPI intelCmdBindPipeline(
2939 XGL_CMD_BUFFER cmdBuffer,
2940 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2941 XGL_PIPELINE pipeline)
2942{
2943 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2944
2945 switch (pipelineBindPoint) {
2946 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002947 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002948 break;
2949 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002950 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002951 break;
2952 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002953 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002954 break;
2955 }
2956}
2957
2958XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2959 XGL_CMD_BUFFER cmdBuffer,
2960 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2961 XGL_PIPELINE_DELTA delta)
2962{
2963 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2964
2965 switch (pipelineBindPoint) {
2966 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002967 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002968 break;
2969 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002970 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002971 break;
2972 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002973 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002974 break;
2975 }
2976}
2977
2978XGL_VOID XGLAPI intelCmdBindStateObject(
2979 XGL_CMD_BUFFER cmdBuffer,
2980 XGL_STATE_BIND_POINT stateBindPoint,
2981 XGL_STATE_OBJECT state)
2982{
2983 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2984
2985 switch (stateBindPoint) {
2986 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002987 cmd_bind_viewport_state(cmd,
2988 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002989 break;
2990 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002991 cmd_bind_raster_state(cmd,
2992 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002993 break;
2994 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002995 cmd_bind_ds_state(cmd,
2996 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002997 break;
2998 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002999 cmd_bind_blend_state(cmd,
3000 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003001 break;
3002 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003003 cmd_bind_msaa_state(cmd,
3004 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003005 break;
3006 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003007 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003008 break;
3009 }
3010}
3011
3012XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3013 XGL_CMD_BUFFER cmdBuffer,
3014 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3015 XGL_UINT index,
3016 XGL_DESCRIPTOR_SET descriptorSet,
3017 XGL_UINT slotOffset)
3018{
3019 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3020 struct intel_dset *dset = intel_dset(descriptorSet);
3021
3022 assert(!index);
3023
3024 switch (pipelineBindPoint) {
3025 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003026 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003027 break;
3028 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003029 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003030 break;
3031 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003032 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003033 break;
3034 }
3035}
3036
3037XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3038 XGL_CMD_BUFFER cmdBuffer,
3039 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3040 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3041{
3042 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3043
3044 switch (pipelineBindPoint) {
3045 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003046 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003047 break;
3048 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003049 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003050 break;
3051 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003052 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003053 break;
3054 }
3055}
3056
3057XGL_VOID XGLAPI intelCmdBindIndexData(
3058 XGL_CMD_BUFFER cmdBuffer,
3059 XGL_GPU_MEMORY mem_,
3060 XGL_GPU_SIZE offset,
3061 XGL_INDEX_TYPE indexType)
3062{
3063 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3064 struct intel_mem *mem = intel_mem(mem_);
3065
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003066 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003067}
3068
3069XGL_VOID XGLAPI intelCmdBindAttachments(
3070 XGL_CMD_BUFFER cmdBuffer,
3071 XGL_UINT colorAttachmentCount,
3072 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3073 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3074{
3075 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003076
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003077 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3078 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003079}
3080
3081XGL_VOID XGLAPI intelCmdDraw(
3082 XGL_CMD_BUFFER cmdBuffer,
3083 XGL_UINT firstVertex,
3084 XGL_UINT vertexCount,
3085 XGL_UINT firstInstance,
3086 XGL_UINT instanceCount)
3087{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003088 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003089
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003090 cmd_draw(cmd, firstVertex, vertexCount,
3091 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003092}
3093
3094XGL_VOID XGLAPI intelCmdDrawIndexed(
3095 XGL_CMD_BUFFER cmdBuffer,
3096 XGL_UINT firstIndex,
3097 XGL_UINT indexCount,
3098 XGL_INT vertexOffset,
3099 XGL_UINT firstInstance,
3100 XGL_UINT instanceCount)
3101{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003102 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003103
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003104 cmd_draw(cmd, firstIndex, indexCount,
3105 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003106}
3107
3108XGL_VOID XGLAPI intelCmdDrawIndirect(
3109 XGL_CMD_BUFFER cmdBuffer,
3110 XGL_GPU_MEMORY mem,
3111 XGL_GPU_SIZE offset,
3112 XGL_UINT32 count,
3113 XGL_UINT32 stride)
3114{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003115 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3116
3117 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003118}
3119
3120XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3121 XGL_CMD_BUFFER cmdBuffer,
3122 XGL_GPU_MEMORY mem,
3123 XGL_GPU_SIZE offset,
3124 XGL_UINT32 count,
3125 XGL_UINT32 stride)
3126{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003127 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3128
3129 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003130}
3131
3132XGL_VOID XGLAPI intelCmdDispatch(
3133 XGL_CMD_BUFFER cmdBuffer,
3134 XGL_UINT x,
3135 XGL_UINT y,
3136 XGL_UINT z)
3137{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003138 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3139
3140 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003141}
3142
3143XGL_VOID XGLAPI intelCmdDispatchIndirect(
3144 XGL_CMD_BUFFER cmdBuffer,
3145 XGL_GPU_MEMORY mem,
3146 XGL_GPU_SIZE offset)
3147{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003148 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3149
3150 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003151}