blob: 6df92b2e79f154da0545c3429991e639ec659668 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wua4d1b392014-10-10 13:57:29 +080029#include <stdio.h> /* for printf */
Chia-I Wu9f039862014-08-20 15:39:56 +080030#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080031#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
40
Chia-I Wu59c097e2014-08-21 10:51:07 +080041static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080042 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080043 uint32_t vertex_count,
44 uint32_t vertex_start,
45 uint32_t instance_count,
46 uint32_t instance_start,
47 uint32_t vertex_base)
48{
49 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080050 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080051
52 CMD_ASSERT(cmd, 6, 6);
53
Chia-I Wu426072d2014-08-26 14:31:55 +080054 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080055 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080056 (cmd_len - 2);
57
58 if (indexed)
59 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
60
Chia-I Wu72292b72014-09-09 10:48:33 +080061 cmd_batch_pointer(cmd, cmd_len, &dw);
62 dw[0] = dw0;
63 dw[1] = vertex_count;
64 dw[2] = vertex_start;
65 dw[3] = instance_count;
66 dw[4] = instance_start;
67 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080068}
69
70static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080071 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080072 uint32_t vertex_count,
73 uint32_t vertex_start,
74 uint32_t instance_count,
75 uint32_t instance_start,
76 uint32_t vertex_base)
77{
78 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080079 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080080
81 CMD_ASSERT(cmd, 7, 7.5);
82
Chia-I Wu426072d2014-08-26 14:31:55 +080083 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080084 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080085
86 if (indexed)
87 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
88
Chia-I Wu72292b72014-09-09 10:48:33 +080089 cmd_batch_pointer(cmd, cmd_len, &dw);
90 dw[0] = dw0;
91 dw[1] = dw1;
92 dw[2] = vertex_count;
93 dw[3] = vertex_start;
94 dw[4] = instance_count;
95 dw[5] = instance_start;
96 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080097}
98
Chia-I Wu270b1e82014-08-25 15:53:39 +080099static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800100 struct intel_bo *bo, uint32_t bo_offset,
101 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800102{
103 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800104 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800105 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800106 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800107 uint32_t *dw;
108 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800109
110 CMD_ASSERT(cmd, 6, 7.5);
111
112 assert(bo_offset % 8 == 0);
113
114 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
115 /*
116 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
117 *
118 * "1 of the following must also be set (when CS stall is set):
119 *
120 * * Depth Cache Flush Enable ([0] of DW1)
121 * * Stall at Pixel Scoreboard ([1] of DW1)
122 * * Depth Stall ([13] of DW1)
123 * * Post-Sync Operation ([13] of DW1)
124 * * Render Target Cache Flush Enable ([12] of DW1)
125 * * Notify Enable ([8] of DW1)"
126 *
127 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
128 *
129 * "One of the following must also be set (when CS stall is set):
130 *
131 * * Render Target Cache Flush Enable ([12] of DW1)
132 * * Depth Cache Flush Enable ([0] of DW1)
133 * * Stall at Pixel Scoreboard ([1] of DW1)
134 * * Depth Stall ([13] of DW1)
135 * * Post-Sync Operation ([13] of DW1)"
136 */
137 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
138 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
140 GEN6_PIPE_CONTROL_DEPTH_STALL;
141
142 /* post-sync op */
143 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
144 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
145 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
146
147 if (cmd_gen(cmd) == INTEL_GEN(6))
148 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
149
150 assert(dw1 & bit_test);
151 }
152
153 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
154 /*
155 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
156 *
157 * "Following bits must be clear (when Depth Stall is set):
158 *
159 * * Render Target Cache Flush Enable ([12] of DW1)
160 * * Depth Cache Flush Enable ([0] of DW1)"
161 */
162 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
163 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
164 }
165
166 /*
167 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
168 *
169 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
170 * and PIPE_CONTROL are not supported."
171 *
172 * The kernel will add the mapping automatically (when write domain is
173 * INTEL_DOMAIN_INSTRUCTION).
174 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800175 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800176 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800177 reloc_flags |= INTEL_RELOC_GGTT;
178 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800179
Chia-I Wu72292b72014-09-09 10:48:33 +0800180 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
181 dw[0] = dw0;
182 dw[1] = dw1;
183 dw[2] = 0;
184 dw[3] = (uint32_t) imm;
185 dw[4] = (uint32_t) (imm >> 32);
186
187 if (bo) {
188 cmd_reserve_reloc(cmd, 1);
189 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
190 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800191}
192
Chia-I Wu254db422014-08-21 11:54:29 +0800193static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
194{
195 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
196 bool supported;
197
198 CMD_ASSERT(cmd, 6, 7.5);
199
200 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
201 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
202
203 switch (p->prim_type) {
204 case GEN6_3DPRIM_POINTLIST:
205 case GEN6_3DPRIM_LINELIST:
206 case GEN6_3DPRIM_LINESTRIP:
207 case GEN6_3DPRIM_TRILIST:
208 case GEN6_3DPRIM_TRISTRIP:
209 supported = true;
210 break;
211 default:
212 supported = false;
213 break;
214 }
215
216 if (!supported)
217 return false;
218
219 switch (cmd->bind.index.type) {
220 case XGL_INDEX_8:
221 supported = (p->primitive_restart_index != 0xffu);
222 break;
223 case XGL_INDEX_16:
224 supported = (p->primitive_restart_index != 0xffffu);
225 break;
226 case XGL_INDEX_32:
227 supported = (p->primitive_restart_index != 0xffffffffu);
228 break;
229 default:
230 supported = false;
231 break;
232 }
233
234 return supported;
235}
236
Chia-I Wu59c097e2014-08-21 10:51:07 +0800237static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800238 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 XGL_GPU_SIZE offset,
240 XGL_INDEX_TYPE type,
241 bool enable_cut_index)
242{
243 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800244 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800246 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800247
248 CMD_ASSERT(cmd, 6, 7.5);
249
Chia-I Wu426072d2014-08-26 14:31:55 +0800250 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800251
252 /* the bit is moved to 3DSTATE_VF */
253 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
254 assert(!enable_cut_index);
255 if (enable_cut_index)
256 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
257
258 switch (type) {
259 case XGL_INDEX_8:
260 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
261 offset_align = 1;
262 break;
263 case XGL_INDEX_16:
264 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
265 offset_align = 2;
266 break;
267 case XGL_INDEX_32:
268 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
269 offset_align = 4;
270 break;
271 default:
272 cmd->result = XGL_ERROR_INVALID_VALUE;
273 return;
274 break;
275 }
276
277 if (offset % offset_align) {
278 cmd->result = XGL_ERROR_INVALID_VALUE;
279 return;
280 }
281
282 /* aligned and inclusive */
283 end_offset = mem->size - (mem->size % offset_align) - 1;
284
Chia-I Wu72292b72014-09-09 10:48:33 +0800285 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
286 dw[0] = dw0;
287
288 cmd_reserve_reloc(cmd, 2);
289 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
290 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800291}
292
Chia-I Wu62a7f252014-08-29 11:31:16 +0800293static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
294 bool enable_cut_index,
295 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800296{
297 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800298 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800299
300 CMD_ASSERT(cmd, 7.5, 7.5);
301
Chia-I Wu426072d2014-08-26 14:31:55 +0800302 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800303 if (enable_cut_index)
304 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
305
Chia-I Wu72292b72014-09-09 10:48:33 +0800306 cmd_batch_pointer(cmd, cmd_len, &dw);
307 dw[0] = dw0;
308 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800309}
310
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600311
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800312static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
313{
314 const uint8_t cmd_len = 7;
315 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800316 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800317
318 CMD_ASSERT(cmd, 6, 6);
319
Chia-I Wu72292b72014-09-09 10:48:33 +0800320 cmd_batch_pointer(cmd, cmd_len, &dw);
321 dw[0] = dw0;
322 dw[1] = 0;
323 dw[2] = 0;
324 dw[3] = 0;
325 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
326 dw[5] = GEN6_GS_DW5_STATISTICS;
327 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800328}
329
Chia-I Wu62a7f252014-08-29 11:31:16 +0800330static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
331{
332 const uint8_t cmd_len = 7;
333 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800334 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800335
336 CMD_ASSERT(cmd, 7, 7.5);
337
Chia-I Wu72292b72014-09-09 10:48:33 +0800338 cmd_batch_pointer(cmd, cmd_len, &dw);
339 dw[0] = dw0;
340 dw[1] = 0;
341 dw[2] = 0;
342 dw[3] = 0;
343 dw[4] = 0;
344 dw[5] = GEN6_GS_DW5_STATISTICS;
345 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800346}
347
Chia-I Wud88e02d2014-08-25 10:56:13 +0800348static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
349 XGL_UINT width, XGL_UINT height)
350{
351 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800352 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800353 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800354 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800355
356 CMD_ASSERT(cmd, 6, 7.5);
357
Chia-I Wu72292b72014-09-09 10:48:33 +0800358 cmd_batch_pointer(cmd, cmd_len, &dw);
359 dw[0] = dw0;
360
Chia-I Wud88e02d2014-08-25 10:56:13 +0800361 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800362 dw[1] = 0;
363 dw[2] = (height - 1) << 16 |
364 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800365 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800366 dw[1] = 1;
367 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800368 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800369
370 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800371}
372
Chia-I Wu8016a172014-08-29 18:31:32 +0800373static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
374 uint32_t body[6])
375{
376 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
377 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
378 const struct intel_raster_state *raster = cmd->bind.state.raster;
379 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
380 uint32_t dw1, dw2, dw3;
381 int point_width;
382
383 CMD_ASSERT(cmd, 6, 7.5);
384
385 dw1 = GEN7_SF_DW1_STATISTICS |
386 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
387 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
388 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
389 GEN7_SF_DW1_VIEWPORT_ENABLE |
390 raster->cmd_sf_fill;
391
392 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
393 int format;
394
395 switch (pipeline->db_format.channelFormat) {
396 case XGL_CH_FMT_R16:
397 format = GEN6_ZFORMAT_D16_UNORM;
398 break;
399 case XGL_CH_FMT_R32:
400 case XGL_CH_FMT_R32G8:
401 format = GEN6_ZFORMAT_D32_FLOAT;
402 break;
403 default:
404 assert(!"unknown depth format");
405 format = 0;
406 break;
407 }
408
409 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
410 }
411
412 dw2 = raster->cmd_sf_cull;
413
414 if (msaa->sample_count > 1) {
415 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
416 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
417 } else {
418 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
419 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
420 }
421
422 if (viewport->scissor_enable)
423 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
424
425 /* in U8.3 */
426 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
427 point_width = U_CLAMP(point_width, 1, 2047);
428
429 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
431 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
432 GEN7_SF_DW3_SUBPIXEL_8BITS |
433 GEN7_SF_DW3_USE_POINT_WIDTH |
434 point_width;
435
436 body[0] = dw1;
437 body[1] = dw2;
438 body[2] = dw3;
439 body[3] = raster->cmd_depth_offset_const;
440 body[4] = raster->cmd_depth_offset_scale;
441 body[5] = raster->cmd_depth_offset_clamp;
442}
443
444static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
445 uint32_t body[13])
446{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800447 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
448 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449 XGL_UINT attr_skip, attr_count;
450 XGL_UINT vue_offset, vue_len;
451 XGL_UINT i;
452 uint32_t dw1;
453
454 CMD_ASSERT(cmd, 6, 7.5);
455
456 /* VS outputs VUE header and position additionally */
GregFbcbe19a2014-11-07 11:01:01 -0700457 assert(vs->out_count >= fs->in_count + 2);
458 attr_skip = vs->out_count - fs->in_count;
Chia-I Wu8016a172014-08-29 18:31:32 +0800459 attr_count = vs->out_count - attr_skip;
Chia-I Wu8016a172014-08-29 18:31:32 +0800460 assert(fs->in_count <= 32);
461
GregFbcbe19a2014-11-07 11:01:01 -0700462 vue_offset = (attr_skip + 1) / 2;
Chia-I Wu8016a172014-08-29 18:31:32 +0800463 vue_len = (attr_count + 1) / 2;
464 if (!vue_len)
465 vue_len = 1;
466
467 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
468 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
469 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
470
471 body[0] = dw1;
472
473 for (i = 0; i < 8; i++) {
474 uint16_t hi, lo;
475
476 /* no attr swizzles */
477 if (i * 2 + 1 < fs->in_count) {
478 hi = i * 2 + 1;
479 lo = i * 2;
480 } else if (i * 2 < fs->in_count) {
481 hi = 0;
482 lo = i * 2;
483 } else {
484 hi = 0;
485 lo = 0;
486 }
487
488 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
489 }
490
491 body[9] = 0; /* point sprite enables */
492 body[10] = 0; /* constant interpolation enables */
493 body[11] = 0; /* WrapShortest enables */
494 body[12] = 0;
495}
496
497static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
498{
499 const uint8_t cmd_len = 20;
500 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
501 (cmd_len - 2);
502 uint32_t sf[6];
503 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800504 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800505
506 CMD_ASSERT(cmd, 6, 6);
507
508 gen7_fill_3DSTATE_SF_body(cmd, sf);
509 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
510
Chia-I Wu72292b72014-09-09 10:48:33 +0800511 cmd_batch_pointer(cmd, cmd_len, &dw);
512 dw[0] = dw0;
513 dw[1] = sbe[0];
514 memcpy(&dw[2], sf, sizeof(sf));
515 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800516}
517
518static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
519{
520 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800521 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800522
523 CMD_ASSERT(cmd, 7, 7.5);
524
Chia-I Wu72292b72014-09-09 10:48:33 +0800525 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800526 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
527 (cmd_len - 2);
528 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800529}
530
531static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
532{
533 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800534 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800535
536 CMD_ASSERT(cmd, 7, 7.5);
537
Chia-I Wu72292b72014-09-09 10:48:33 +0800538 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800539 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
540 (cmd_len - 2);
541 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800542}
543
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800544static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
545{
546 const uint8_t cmd_len = 4;
547 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
548 (cmd_len - 2);
549 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700550 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800551 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800552 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
553 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800554 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800555
556 CMD_ASSERT(cmd, 6, 7.5);
557
558 dw1 = GEN6_CLIP_DW1_STATISTICS;
559 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
560 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
561 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
562 raster->cmd_clip_cull;
563 }
564
565 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
566 GEN6_CLIP_DW2_XY_TEST_ENABLE |
567 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700568 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800569 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
570 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
571 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
572
573 if (pipeline->rasterizerDiscardEnable)
574 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
575 else
576 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
577
578 if (pipeline->depthClipEnable)
579 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
580
581 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
582 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
583 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
584 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
585
586 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
587 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
588 (viewport->viewport_count - 1);
589
Chia-I Wu72292b72014-09-09 10:48:33 +0800590 cmd_batch_pointer(cmd, cmd_len, &dw);
591 dw[0] = dw0;
592 dw[1] = dw1;
593 dw[2] = dw2;
594 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800595}
596
Chia-I Wu05990612014-11-25 11:36:35 +0800597static int cmd_vs_max_threads(const struct intel_cmd *cmd)
598{
599 switch (cmd_gen(cmd)) {
600 case INTEL_GEN(7.5):
601 return (cmd->dev->gpu->gt >= 2) ? 280 : 70;
602 case INTEL_GEN(7):
603 return (cmd->dev->gpu->gt == 2) ? 128 : 36;
604 case INTEL_GEN(6):
605 return (cmd->dev->gpu->gt == 2) ? 60 : 24;
606 default:
607 return 1;
608 }
609}
610
611static int cmd_ps_max_threads(const struct intel_cmd *cmd)
612{
613 switch (cmd_gen(cmd)) {
614 case INTEL_GEN(7.5):
615 return (cmd->dev->gpu->gt == 3) ? 408 :
616 (cmd->dev->gpu->gt == 2) ? 204 : 102;
617 case INTEL_GEN(7):
618 return (cmd->dev->gpu->gt == 2) ? 172 : 48;
619 case INTEL_GEN(6):
620 return (cmd->dev->gpu->gt == 2) ? 80 : 40;
621 default:
622 return 4;
623 }
624}
625
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800626static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
627{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800628 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800629 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800630 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
631 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800632 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800633
634 CMD_ASSERT(cmd, 6, 6);
635
636 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
637
638 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
639 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
640
641 dw4 = GEN6_WM_DW4_STATISTICS |
642 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
643 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
644 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
645
Chia-I Wu05990612014-11-25 11:36:35 +0800646 dw5 = (cmd_ps_max_threads(cmd) - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800647 GEN6_WM_DW5_PS_ENABLE |
648 GEN6_WM_DW5_8_PIXEL_DISPATCH;
649
650 if (fs->uses & INTEL_SHADER_USE_KILL ||
651 pipeline->cb_state.alphaToCoverageEnable)
652 dw5 |= GEN6_WM_DW5_PS_KILL;
653
654 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
655 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
656 if (fs->uses & INTEL_SHADER_USE_DEPTH)
657 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
658 if (fs->uses & INTEL_SHADER_USE_W)
659 dw5 |= GEN6_WM_DW5_PS_USE_W;
660
661 if (pipeline->cb_state.dualSourceBlendEnable)
662 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
663
664 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
665 GEN6_WM_DW6_POSOFFSET_NONE |
666 GEN6_WM_DW6_ZW_INTERP_PIXEL |
667 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
668 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
669
670 if (msaa->sample_count > 1) {
671 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
672 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
673 } else {
674 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
675 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
676 }
677
Chia-I Wu72292b72014-09-09 10:48:33 +0800678 cmd_batch_pointer(cmd, cmd_len, &dw);
679 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800680 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800681 dw[2] = dw2;
682 dw[3] = 0; /* scratch */
683 dw[4] = dw4;
684 dw[5] = dw5;
685 dw[6] = dw6;
686 dw[7] = 0; /* kernel 1 */
687 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688}
689
690static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
691{
692 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800693 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800694 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
695 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800696 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697
698 CMD_ASSERT(cmd, 7, 7.5);
699
700 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
701
702 dw1 = GEN7_WM_DW1_STATISTICS |
703 GEN7_WM_DW1_PS_ENABLE |
704 GEN7_WM_DW1_ZW_INTERP_PIXEL |
705 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
706 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
707
708 if (fs->uses & INTEL_SHADER_USE_KILL ||
709 pipeline->cb_state.alphaToCoverageEnable)
710 dw1 |= GEN7_WM_DW1_PS_KILL;
711
712 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
713 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
714 if (fs->uses & INTEL_SHADER_USE_DEPTH)
715 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
716 if (fs->uses & INTEL_SHADER_USE_W)
717 dw1 |= GEN7_WM_DW1_PS_USE_W;
718
719 dw2 = 0;
720
721 if (msaa->sample_count > 1) {
722 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
723 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
724 } else {
725 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
726 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
727 }
728
Chia-I Wu72292b72014-09-09 10:48:33 +0800729 cmd_batch_pointer(cmd, cmd_len, &dw);
730 dw[0] = dw0;
731 dw[1] = dw1;
732 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800733}
734
735static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
736{
737 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800738 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800739 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
Chia-I Wu05990612014-11-25 11:36:35 +0800740 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800741 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800742 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800743
744 CMD_ASSERT(cmd, 7, 7.5);
745
746 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
747
748 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
749 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
750
751 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
752 GEN7_PS_DW4_8_PIXEL_DISPATCH;
753
754 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800755 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
756 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
757 } else {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800758 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
759 }
760
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800761 if (fs->in_count)
762 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
763
764 if (pipeline->cb_state.dualSourceBlendEnable)
765 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
766
767 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
768 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
769 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
770
Chia-I Wu72292b72014-09-09 10:48:33 +0800771 cmd_batch_pointer(cmd, cmd_len, &dw);
772 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800773 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800774 dw[2] = dw2;
775 dw[3] = 0; /* scratch */
776 dw[4] = dw4;
777 dw[5] = dw5;
778 dw[6] = 0; /* kernel 1 */
779 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800780}
781
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800782static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
783 const struct intel_ds_view *view)
784{
785 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800786 uint32_t dw0, *dw;
787 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800788
789 CMD_ASSERT(cmd, 6, 7.5);
790
791 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800792 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
793 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800794 dw0 |= (cmd_len - 2);
795
Chia-I Wu72292b72014-09-09 10:48:33 +0800796 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
797 dw[0] = dw0;
798 dw[1] = view->cmd[0];
799 dw[2] = 0;
800 dw[3] = view->cmd[2];
801 dw[4] = view->cmd[3];
802 dw[5] = view->cmd[4];
803 dw[6] = view->cmd[5];
804
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600805 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 cmd_reserve_reloc(cmd, 1);
807 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
808 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600809 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810}
811
812static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
813 const struct intel_ds_view *view)
814{
815 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800816 uint32_t dw0, *dw;
817 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800818
819 CMD_ASSERT(cmd, 6, 7.5);
820
821 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800822 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
823 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800824 dw0 |= (cmd_len - 2);
825
Chia-I Wu72292b72014-09-09 10:48:33 +0800826 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
827 dw[0] = dw0;
828 dw[1] = view->cmd[6];
829 dw[2] = 0;
830
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600831 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800832 cmd_reserve_reloc(cmd, 1);
833 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
834 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600835 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800836}
837
838static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
839 const struct intel_ds_view *view)
840{
841 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800842 uint32_t dw0, *dw;
843 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800844
845 CMD_ASSERT(cmd, 6, 7.5);
846
847 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800848 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
849 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800850 dw0 |= (cmd_len - 2);
851
Chia-I Wu72292b72014-09-09 10:48:33 +0800852 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
853 dw[0] = dw0;
854 dw[1] = view->cmd[8];
855 dw[2] = 0;
856
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600857 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800858 cmd_reserve_reloc(cmd, 1);
859 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
860 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600861 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800862}
863
Chia-I Wuf8231032014-08-25 10:44:45 +0800864static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
865 uint32_t clear_val)
866{
867 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800868 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800869 GEN6_CLEAR_PARAMS_DW0_VALID |
870 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800871 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800872
873 CMD_ASSERT(cmd, 6, 6);
874
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 cmd_batch_pointer(cmd, cmd_len, &dw);
876 dw[0] = dw0;
877 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800878}
879
880static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
881 uint32_t clear_val)
882{
883 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800884 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800885 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800886 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800887
888 CMD_ASSERT(cmd, 7, 7.5);
889
Chia-I Wu72292b72014-09-09 10:48:33 +0800890 cmd_batch_pointer(cmd, cmd_len, &dw);
891 dw[0] = dw0;
892 dw[1] = clear_val;
893 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800894}
895
Chia-I Wu302742d2014-08-22 10:28:29 +0800896static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800897 uint32_t blend_offset,
898 uint32_t ds_offset,
899 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800900{
901 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800902 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800903
904 CMD_ASSERT(cmd, 6, 6);
905
Chia-I Wu426072d2014-08-26 14:31:55 +0800906 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800907 (cmd_len - 2);
908
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 cmd_batch_pointer(cmd, cmd_len, &dw);
910 dw[0] = dw0;
911 dw[1] = blend_offset | 1;
912 dw[2] = ds_offset | 1;
913 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800914}
915
Chia-I Wu1744cca2014-08-22 11:10:17 +0800916static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800917 uint32_t clip_offset,
918 uint32_t sf_offset,
919 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800920{
921 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800923
924 CMD_ASSERT(cmd, 6, 6);
925
Chia-I Wu426072d2014-08-26 14:31:55 +0800926 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800927 GEN6_PTR_VP_DW0_CLIP_CHANGED |
928 GEN6_PTR_VP_DW0_SF_CHANGED |
929 GEN6_PTR_VP_DW0_CC_CHANGED |
930 (cmd_len - 2);
931
Chia-I Wu72292b72014-09-09 10:48:33 +0800932 cmd_batch_pointer(cmd, cmd_len, &dw);
933 dw[0] = dw0;
934 dw[1] = clip_offset;
935 dw[2] = sf_offset;
936 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800937}
938
939static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800940 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800941{
942 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800943 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800944
945 CMD_ASSERT(cmd, 6, 6);
946
Chia-I Wu426072d2014-08-26 14:31:55 +0800947 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800948 (cmd_len - 2);
949
Chia-I Wu72292b72014-09-09 10:48:33 +0800950 cmd_batch_pointer(cmd, cmd_len, &dw);
951 dw[0] = dw0;
952 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800953}
954
Chia-I Wu42a56202014-08-23 16:47:48 +0800955static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 uint32_t vs_offset,
957 uint32_t gs_offset,
958 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800959{
960 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800961 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800962
963 CMD_ASSERT(cmd, 6, 6);
964
Chia-I Wu426072d2014-08-26 14:31:55 +0800965 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800966 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
967 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
968 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
969 (cmd_len - 2);
970
Chia-I Wu72292b72014-09-09 10:48:33 +0800971 cmd_batch_pointer(cmd, cmd_len, &dw);
972 dw[0] = dw0;
973 dw[1] = vs_offset;
974 dw[2] = gs_offset;
975 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800976}
977
Chia-I Wu257e75e2014-08-29 14:06:35 +0800978static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800979 uint32_t vs_offset,
980 uint32_t gs_offset,
981 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800982{
983 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800984 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800985
986 CMD_ASSERT(cmd, 6, 6);
987
988 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
989 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
990 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
991 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
992 (cmd_len - 2);
993
Chia-I Wu72292b72014-09-09 10:48:33 +0800994 cmd_batch_pointer(cmd, cmd_len, &dw);
995 dw[0] = dw0;
996 dw[1] = vs_offset;
997 dw[2] = gs_offset;
998 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800999}
1000
Chia-I Wu302742d2014-08-22 10:28:29 +08001001static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001002 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001003{
1004 const uint8_t cmd_len = 2;
1005 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1006 GEN6_RENDER_SUBTYPE_3D |
1007 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001008 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001009
Chia-I Wu72292b72014-09-09 10:48:33 +08001010 cmd_batch_pointer(cmd, cmd_len, &dw);
1011 dw[0] = dw0;
1012 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001013}
1014
Chia-I Wu72292b72014-09-09 10:48:33 +08001015static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001016 const struct intel_blend_state *state)
1017{
Chia-I Wue6073342014-11-30 09:43:42 +08001018 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001019 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
1020
1021 CMD_ASSERT(cmd, 6, 7.5);
1022 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1023
Chia-I Wu00b51a82014-09-09 12:07:37 +08001024 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
1025 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001026}
1027
Chia-I Wu72292b72014-09-09 10:48:33 +08001028static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001029 const struct intel_ds_state *state)
1030{
Chia-I Wue6073342014-11-30 09:43:42 +08001031 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001032 const uint8_t cmd_len = 3;
1033
1034 CMD_ASSERT(cmd, 6, 7.5);
1035 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1036
Chia-I Wu00b51a82014-09-09 12:07:37 +08001037 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1038 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001039}
1040
Chia-I Wu72292b72014-09-09 10:48:33 +08001041static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001042 uint32_t stencil_ref,
1043 const uint32_t blend_color[4])
1044{
Chia-I Wue6073342014-11-30 09:43:42 +08001045 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001046 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001047 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001048
1049 CMD_ASSERT(cmd, 6, 7.5);
1050
Chia-I Wu00b51a82014-09-09 12:07:37 +08001051 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1052 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001053 dw[0] = stencil_ref;
1054 dw[1] = 0;
1055 dw[2] = blend_color[0];
1056 dw[3] = blend_color[1];
1057 dw[4] = blend_color[2];
1058 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001059
Chia-I Wu72292b72014-09-09 10:48:33 +08001060 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001061}
1062
Chia-I Wu8370b402014-08-29 12:28:37 +08001063static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001064{
Chia-I Wu8370b402014-08-29 12:28:37 +08001065 CMD_ASSERT(cmd, 6, 7.5);
1066
Chia-I Wu707a29e2014-08-27 12:51:47 +08001067 if (!cmd->bind.draw_count)
1068 return;
1069
Chia-I Wu8370b402014-08-29 12:28:37 +08001070 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001071 return;
1072
Chia-I Wu8370b402014-08-29 12:28:37 +08001073 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001074
1075 /*
1076 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1077 *
1078 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1079 * pipe-control with a post-sync op and no write-cache flushes."
1080 *
1081 * The workaround below necessitates this workaround.
1082 */
1083 gen6_PIPE_CONTROL(cmd,
1084 GEN6_PIPE_CONTROL_CS_STALL |
1085 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001086 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001087
Chia-I Wud6d079d2014-08-31 13:14:21 +08001088 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1089 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001090}
1091
Chia-I Wu8370b402014-08-29 12:28:37 +08001092static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001093{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001094 CMD_ASSERT(cmd, 6, 7.5);
1095
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001096 if (!cmd->bind.draw_count)
1097 return;
1098
Chia-I Wud6d079d2014-08-31 13:14:21 +08001099 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1100 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001101}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001102
Chia-I Wu8370b402014-08-29 12:28:37 +08001103static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1104{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001105 CMD_ASSERT(cmd, 7, 7.5);
1106
Chia-I Wu8370b402014-08-29 12:28:37 +08001107 if (!cmd->bind.draw_count)
1108 return;
1109
1110 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001111
1112 gen6_PIPE_CONTROL(cmd,
1113 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001114 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001115}
1116
Chia-I Wu8370b402014-08-29 12:28:37 +08001117static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1118{
1119 CMD_ASSERT(cmd, 7, 7.5);
1120
1121 if (!cmd->bind.draw_count)
1122 return;
1123
1124 /*
1125 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1126 *
1127 * "One of the following must also be set (when CS stall is set):
1128 *
1129 * * Render Target Cache Flush Enable ([12] of DW1)
1130 * * Depth Cache Flush Enable ([0] of DW1)
1131 * * Stall at Pixel Scoreboard ([1] of DW1)
1132 * * Depth Stall ([13] of DW1)
1133 * * Post-Sync Operation ([13] of DW1)"
1134 */
1135 gen6_PIPE_CONTROL(cmd,
1136 GEN6_PIPE_CONTROL_CS_STALL |
1137 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001138 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001139}
1140
1141static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1142{
1143 CMD_ASSERT(cmd, 7, 7.5);
1144
1145 if (!cmd->bind.draw_count)
1146 return;
1147
1148 cmd_wa_gen6_pre_depth_stall_write(cmd);
1149
Chia-I Wud6d079d2014-08-31 13:14:21 +08001150 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001151}
1152
1153static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1154{
1155 CMD_ASSERT(cmd, 6, 7.5);
1156
1157 if (!cmd->bind.draw_count)
1158 return;
1159
1160 /*
1161 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1162 *
1163 * "Driver must guarentee that all the caches in the depth pipe are
1164 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1165 * requires driver to send a PIPE_CONTROL with a CS stall along with
1166 * a Depth Flush prior to this command."
1167 *
1168 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1169 *
1170 * "Driver must ierarchi that all the caches in the depth pipe are
1171 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1172 * requires driver to send a PIPE_CONTROL with a CS stall along with
1173 * a Depth Flush prior to this command.
1174 */
1175 gen6_PIPE_CONTROL(cmd,
1176 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1177 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001178 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001179}
1180
1181static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1182{
1183 CMD_ASSERT(cmd, 6, 7.5);
1184
1185 if (!cmd->bind.draw_count)
1186 return;
1187
1188 /*
1189 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1190 *
1191 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1192 * and a post sync operation prior to the group of depth
1193 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1194 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1195 *
1196 * This workaround satifies all the conditions.
1197 */
1198 cmd_wa_gen6_pre_depth_stall_write(cmd);
1199
1200 /*
1201 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1202 *
1203 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1204 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1205 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1206 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1207 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1208 * Depth Flush Bit set, followed by another pipelined depth stall
1209 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1210 * guarantee that the pipeline from WM onwards is already flushed
1211 * (e.g., via a preceding MI_FLUSH)."
1212 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001213 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1214 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1215 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001216}
1217
Chia-I Wu525c6602014-08-27 10:22:34 +08001218void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1219{
1220 if (!cmd->bind.draw_count)
1221 return;
1222
1223 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1224
Chia-I Wu8370b402014-08-29 12:28:37 +08001225 /*
1226 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1227 *
1228 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1229 * PIPE_CONTROL with any non-zero post-sync-op is required."
1230 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001231 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001232 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001233
Chia-I Wu092279a2014-08-30 19:05:30 +08001234 /*
1235 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1236 *
1237 * "One of the following must also be set (when CS stall is set):
1238 *
1239 * * Render Target Cache Flush Enable ([12] of DW1)
1240 * * Depth Cache Flush Enable ([0] of DW1)
1241 * * Stall at Pixel Scoreboard ([1] of DW1)
1242 * * Depth Stall ([13] of DW1)
1243 * * Post-Sync Operation ([13] of DW1)"
1244 */
1245 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1246 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1247 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1248 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1249 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1250 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1251
Chia-I Wud6d079d2014-08-31 13:14:21 +08001252 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001253}
1254
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001255void cmd_batch_flush_all(struct intel_cmd *cmd)
1256{
1257 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1258 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1259 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1260 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1261 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1262 GEN6_PIPE_CONTROL_CS_STALL);
1263}
1264
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001265void cmd_batch_depth_count(struct intel_cmd *cmd,
1266 struct intel_bo *bo,
1267 XGL_GPU_SIZE offset)
1268{
1269 cmd_wa_gen6_pre_depth_stall_write(cmd);
1270
1271 gen6_PIPE_CONTROL(cmd,
1272 GEN6_PIPE_CONTROL_DEPTH_STALL |
1273 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001274 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001275}
1276
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001277void cmd_batch_timestamp(struct intel_cmd *cmd,
1278 struct intel_bo *bo,
1279 XGL_GPU_SIZE offset)
1280{
1281 /* need any WA or stall? */
1282 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1283}
1284
1285void cmd_batch_immediate(struct intel_cmd *cmd,
1286 struct intel_bo *bo,
1287 XGL_GPU_SIZE offset,
1288 uint64_t val)
1289{
1290 /* need any WA or stall? */
1291 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1292}
1293
Chia-I Wu302742d2014-08-22 10:28:29 +08001294static void gen6_cc_states(struct intel_cmd *cmd)
1295{
1296 const struct intel_blend_state *blend = cmd->bind.state.blend;
1297 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001298 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001299 uint32_t stencil_ref;
1300 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001301
1302 CMD_ASSERT(cmd, 6, 6);
1303
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001304 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001305 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001306 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1307 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001308 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001309 memset(blend_color, 0, sizeof(blend_color));
1310 }
1311
1312 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001313 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001314 stencil_ref = ds->cmd_stencil_ref;
1315 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001316 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001317 stencil_ref = 0;
1318 }
1319
Chia-I Wu72292b72014-09-09 10:48:33 +08001320 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001321
Chia-I Wu72292b72014-09-09 10:48:33 +08001322 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001323}
1324
Chia-I Wu1744cca2014-08-22 11:10:17 +08001325static void gen6_viewport_states(struct intel_cmd *cmd)
1326{
1327 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001328 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001329
1330 if (!viewport)
1331 return;
1332
Chia-I Wub1d450a2014-09-09 13:48:03 +08001333 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1334 viewport->viewport_count);
1335
1336 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001337 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001338 viewport->cmd);
1339
1340 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001341 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001342 &viewport->cmd[viewport->cmd_clip_pos]);
1343
1344 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001345 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001346 &viewport->cmd[viewport->cmd_cc_pos]);
1347
1348 if (viewport->scissor_enable) {
1349 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001350 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001351 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1352 } else {
1353 scissor_offset = 0;
1354 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001355
1356 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001357 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001358
Chia-I Wub1d450a2014-09-09 13:48:03 +08001359 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001360}
1361
Chia-I Wu302742d2014-08-22 10:28:29 +08001362static void gen7_cc_states(struct intel_cmd *cmd)
1363{
1364 const struct intel_blend_state *blend = cmd->bind.state.blend;
1365 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001366 uint32_t stencil_ref;
1367 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001368 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001369
1370 CMD_ASSERT(cmd, 7, 7.5);
1371
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001372 if (!blend && !ds)
1373 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001374
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001375 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001376 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001377 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001378 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001379
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001380 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1381 } else {
1382 memset(blend_color, 0, sizeof(blend_color));
1383 }
1384
1385 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001386 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001387 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001388 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1389 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001390 } else {
1391 stencil_ref = 0;
1392 }
1393
Chia-I Wu72292b72014-09-09 10:48:33 +08001394 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001395 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001396 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001397}
1398
Chia-I Wu1744cca2014-08-22 11:10:17 +08001399static void gen7_viewport_states(struct intel_cmd *cmd)
1400{
1401 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001402 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001403
1404 if (!viewport)
1405 return;
1406
Chia-I Wub1d450a2014-09-09 13:48:03 +08001407 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1408 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001409
Chia-I Wub1d450a2014-09-09 13:48:03 +08001410 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001411 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001413 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001414 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1415 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001416
1417 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001418 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001419 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001420 gen7_3dstate_pointer(cmd,
1421 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001422 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001423
Chia-I Wu1744cca2014-08-22 11:10:17 +08001424 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001425 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001426 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001428 gen7_3dstate_pointer(cmd,
1429 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001430 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001431 }
1432}
1433
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001434static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001435 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001436{
1437 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001438 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001439
Chia-I Wu72292b72014-09-09 10:48:33 +08001440 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001441
1442 dw[0] = GEN6_RENDER_TYPE_RENDER |
1443 GEN6_RENDER_SUBTYPE_3D |
1444 subop | (cmd_len - 2);
1445 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001446 dw[2] = 0;
1447 dw[3] = 0;
1448 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001449}
1450
1451static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001452 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001453{
1454 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001455 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001456
Chia-I Wu72292b72014-09-09 10:48:33 +08001457 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001458
1459 dw[0] = GEN6_RENDER_TYPE_RENDER |
1460 GEN6_RENDER_SUBTYPE_3D |
1461 subop | (cmd_len - 2);
1462 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001463 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001464 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001465 dw[4] = 0;
1466 dw[5] = 0;
1467 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001468}
1469
Chia-I Wu625105f2014-10-13 15:35:29 +08001470static uint32_t emit_samplers(struct intel_cmd *cmd,
1471 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001472{
1473 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1474 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001475 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001476 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001477 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001478 XGL_UINT i;
1479
1480 CMD_ASSERT(cmd, 6, 7.5);
1481
Chia-I Wu625105f2014-10-13 15:35:29 +08001482 if (!rmap || !rmap->sampler_count)
1483 return 0;
1484
1485 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1486
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001487 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001488 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001489 border_stride * rmap->sampler_count, &border_dw);
1490
1491 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001492 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001493 4 * rmap->sampler_count, &sampler_dw);
1494
1495 for (i = 0; i < rmap->sampler_count; i++) {
1496 const struct intel_pipeline_rmap_slot *slot =
1497 &rmap->slots[surface_count + i];
1498 const struct intel_sampler *sampler;
1499
1500 switch (slot->path_len) {
1501 case 0:
1502 sampler = NULL;
1503 break;
1504 case INTEL_PIPELINE_RMAP_SLOT_RT:
1505 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1506 assert(!"unexpected rmap slot type");
1507 sampler = NULL;
1508 break;
1509 case 1:
1510 {
1511 const struct intel_dset *dset = cmd->bind.dset.graphics;
1512 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1513 const struct intel_dset_slot *dset_slot =
1514 &dset->slots[slot_offset + slot->u.index];
1515
1516 switch (dset_slot->type) {
1517 case INTEL_DSET_SLOT_SAMPLER:
1518 sampler = dset_slot->u.sampler;
1519 break;
1520 default:
1521 assert(!"unexpected dset slot type");
1522 sampler = NULL;
1523 break;
1524 }
1525 }
1526 break;
1527 default:
1528 assert(!"nested descriptor set unsupported");
1529 sampler = NULL;
1530 break;
1531 }
1532
1533 if (sampler) {
1534 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1535
1536 sampler_dw[0] = sampler->cmd[0];
1537 sampler_dw[1] = sampler->cmd[1];
1538 sampler_dw[2] = border_offset;
1539 sampler_dw[3] = sampler->cmd[2];
1540 } else {
1541 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1542 sampler_dw[1] = 0;
1543 sampler_dw[2] = 0;
1544 sampler_dw[3] = 0;
1545 }
1546
1547 border_offset += border_stride * 4;
1548 border_dw += border_stride;
1549 sampler_dw += 4;
1550 }
1551
Chia-I Wu625105f2014-10-13 15:35:29 +08001552 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001553}
1554
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001555static uint32_t emit_binding_table(struct intel_cmd *cmd,
1556 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001557{
Chia-I Wu72292b72014-09-09 10:48:33 +08001558 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001559 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001560
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001561 CMD_ASSERT(cmd, 6, 7.5);
1562
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001563 surface_count = (rmap) ?
1564 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1565 if (!surface_count)
1566 return 0;
1567
Chia-I Wu42a56202014-08-23 16:47:48 +08001568 assert(surface_count <= ARRAY_SIZE(binding_table));
1569
1570 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001571 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001572
1573 switch (slot->path_len) {
1574 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001575 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001576 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001577 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001578 {
1579 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1580
Chia-I Wu00b51a82014-09-09 12:07:37 +08001581 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001582 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001583 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001584
Chia-I Wu72292b72014-09-09 10:48:33 +08001585 cmd_reserve_reloc(cmd, 1);
1586 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1587 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001588 }
1589 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001590 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001591 {
1592 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001593 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001594
Chia-I Wu00b51a82014-09-09 12:07:37 +08001595 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001596 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001597 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001598
Chia-I Wu72292b72014-09-09 10:48:33 +08001599 cmd_reserve_reloc(cmd, 1);
1600 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1601 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001602 }
1603 break;
1604 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001605 {
1606 const struct intel_dset *dset = cmd->bind.dset.graphics;
1607 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1608 const struct intel_dset_slot *dset_slot =
1609 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001610 const uint32_t reloc_flags =
1611 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001612
1613 switch (dset_slot->type) {
1614 case INTEL_DSET_SLOT_IMG_VIEW:
1615 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001616 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001617 dset_slot->u.img_view->cmd_len,
1618 dset_slot->u.img_view->cmd);
1619
1620 cmd_reserve_reloc(cmd, 1);
1621 cmd_surface_reloc(cmd, offset, 1,
1622 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001623 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001624 break;
1625 case INTEL_DSET_SLOT_MEM_VIEW:
1626 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001627 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001628 dset_slot->u.mem_view.cmd_len,
1629 dset_slot->u.mem_view.cmd);
1630
1631 cmd_reserve_reloc(cmd, 1);
1632 cmd_surface_reloc(cmd, offset, 1,
1633 dset_slot->u.mem_view.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001634 dset_slot->u.mem_view.cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001635 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001636 case INTEL_DSET_SLOT_SAMPLER:
1637 assert(0 == cmd->bind.dset.graphics_offset);
1638
1639 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001640 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001641 16, dset_slot->u.sampler->cmd);
1642 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001643 default:
1644 assert(!"unexpected dset slot type");
1645 break;
1646 }
1647 }
1648 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001649 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001650 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001651 break;
1652 }
1653
Chia-I Wu72292b72014-09-09 10:48:33 +08001654 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001655 }
1656
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001657 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001658 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001659 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001660}
1661
Chia-I Wu1d125092014-10-08 08:49:38 +08001662static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1663{
1664 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001665 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1666 uint32_t *dw;
1667 XGL_UINT pos, i;
1668
1669 CMD_ASSERT(cmd, 6, 7.5);
1670
1671 if (!pipeline->vb_count)
1672 return;
1673
1674 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1675
1676 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1677 dw++;
1678 pos++;
1679
1680 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001681 assert(pipeline->vb[i].strideInBytes <= 2048);
1682
1683 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1684 pipeline->vb[i].strideInBytes;
1685
1686 if (cmd_gen(cmd) >= INTEL_GEN(7))
1687 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1688
1689 switch (pipeline->vb[i].stepRate) {
1690 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1691 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1692 dw[3] = 0;
1693 break;
1694 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1695 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1696 dw[3] = 1;
1697 break;
1698 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1699 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1700 dw[3] = 0;
1701 break;
1702 default:
1703 assert(!"unknown step rate");
1704 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1705 dw[3] = 0;
1706 break;
1707 }
1708
Chia-I Wu3b04af52014-11-08 10:48:20 +08001709 if (cmd->bind.vertex.mem[i]) {
1710 const struct intel_mem *mem = cmd->bind.vertex.mem[i];
1711 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001712
1713 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3b04af52014-11-08 10:48:20 +08001714 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
1715 cmd_batch_reloc(cmd, pos + 2, mem->bo, mem->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001716 } else {
1717 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1718 dw[1] = 0;
1719 dw[2] = 0;
1720 }
1721
1722 dw += 4;
1723 pos += 4;
1724 }
1725}
1726
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001727static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1728{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001729 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1730 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu05990612014-11-25 11:36:35 +08001731 const int max_threads = cmd_vs_max_threads(cmd);
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001732 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001733 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001734 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu05990612014-11-25 11:36:35 +08001735 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001736
1737 CMD_ASSERT(cmd, 6, 7.5);
1738
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001739 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001740 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1741 *
1742 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1743 * 128-bit vertex elements to be passed into the payload for each
1744 * vertex."
1745 *
1746 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1747 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001748 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001749 vue_read_len = (vs->in_count + 1) / 2;
1750 if (!vue_read_len)
1751 vue_read_len = 1;
1752
1753 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1754 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1755
1756 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1757 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1758 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001759
1760 dw5 = GEN6_VS_DW5_STATISTICS |
1761 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001762
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001763 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1764 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1765 else
1766 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1767
Chia-I Wube0a3d92014-09-02 13:20:59 +08001768 if (pipeline->disable_vs_cache)
1769 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1770
Chia-I Wu72292b72014-09-09 10:48:33 +08001771 cmd_batch_pointer(cmd, cmd_len, &dw);
1772 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001773 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001774 dw[2] = dw2;
1775 dw[3] = 0; /* scratch */
1776 dw[4] = dw4;
1777 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001778}
1779
Chia-I Wu625105f2014-10-13 15:35:29 +08001780static void emit_shader_resources(struct intel_cmd *cmd)
1781{
1782 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001783 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001784
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001785 binding_tables[0] = emit_binding_table(cmd,
1786 cmd->bind.pipeline.graphics->vs.rmap);
1787 binding_tables[1] = emit_binding_table(cmd,
1788 cmd->bind.pipeline.graphics->tcs.rmap);
1789 binding_tables[2] = emit_binding_table(cmd,
1790 cmd->bind.pipeline.graphics->tes.rmap);
1791 binding_tables[3] = emit_binding_table(cmd,
1792 cmd->bind.pipeline.graphics->gs.rmap);
1793 binding_tables[4] = emit_binding_table(cmd,
1794 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001795
1796 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1797 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1798 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1799 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1800 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1801
1802 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1803 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001804 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1805 binding_tables[0]);
1806 gen7_3dstate_pointer(cmd,
1807 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1808 binding_tables[1]);
1809 gen7_3dstate_pointer(cmd,
1810 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1811 binding_tables[2]);
1812 gen7_3dstate_pointer(cmd,
1813 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1814 binding_tables[3]);
1815 gen7_3dstate_pointer(cmd,
1816 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1817 binding_tables[4]);
1818
1819 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001820 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1821 samplers[0]);
1822 gen7_3dstate_pointer(cmd,
1823 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1824 samplers[1]);
1825 gen7_3dstate_pointer(cmd,
1826 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1827 samplers[2]);
1828 gen7_3dstate_pointer(cmd,
1829 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1830 samplers[3]);
1831 gen7_3dstate_pointer(cmd,
1832 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1833 samplers[4]);
1834 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001835 assert(!binding_tables[1] && !binding_tables[2]);
1836 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1837 binding_tables[0], binding_tables[3], binding_tables[4]);
1838
Chia-I Wu625105f2014-10-13 15:35:29 +08001839 assert(!samplers[1] && !samplers[2]);
1840 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1841 samplers[0], samplers[3], samplers[4]);
1842 }
1843}
1844
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001845static void emit_rt(struct intel_cmd *cmd)
1846{
1847 cmd_wa_gen6_pre_depth_stall_write(cmd);
1848 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1849 cmd->bind.att.height);
1850}
1851
1852static void emit_ds(struct intel_cmd *cmd)
1853{
1854 const struct intel_ds_view *ds = cmd->bind.att.ds;
1855
1856 if (!ds) {
1857 /* all zeros */
1858 static const struct intel_ds_view null_ds;
1859 ds = &null_ds;
1860 }
1861
1862 cmd_wa_gen6_pre_ds_flush(cmd);
1863 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1864 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1865 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1866
1867 if (cmd_gen(cmd) >= INTEL_GEN(7))
1868 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1869 else
1870 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1871}
1872
Chia-I Wua57761b2014-10-14 14:27:44 +08001873static uint32_t emit_shader(struct intel_cmd *cmd,
1874 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001875{
Chia-I Wua57761b2014-10-14 14:27:44 +08001876 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1877 uint32_t offset;
1878 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001879
Chia-I Wua57761b2014-10-14 14:27:44 +08001880 /* see if the shader is already in the cache */
1881 for (i = 0; i < cache->used; i++) {
1882 if (cache->entries[i].shader == (const void *) shader)
1883 return cache->entries[i].kernel_offset;
1884 }
1885
1886 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1887
1888 /* grow the cache if full */
1889 if (cache->used >= cache->count) {
1890 const XGL_UINT count = cache->count + 16;
1891 void *entries;
1892
1893 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1894 XGL_SYSTEM_ALLOC_INTERNAL);
1895 if (entries) {
1896 if (cache->entries) {
1897 memcpy(entries, cache->entries,
1898 sizeof(cache->entries[0]) * cache->used);
1899 icd_free(cache->entries);
1900 }
1901
1902 cache->entries = entries;
1903 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001904 }
1905 }
1906
Chia-I Wua57761b2014-10-14 14:27:44 +08001907 /* add the shader to the cache */
1908 if (cache->used < cache->count) {
1909 cache->entries[cache->used].shader = (const void *) shader;
1910 cache->entries[cache->used].kernel_offset = offset;
1911 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001912 }
1913
Chia-I Wua57761b2014-10-14 14:27:44 +08001914 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001915}
1916
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001917static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001918{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001919 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001920
Chia-I Wu8370b402014-08-29 12:28:37 +08001921 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1922 cmd_wa_gen6_pre_depth_stall_write(cmd);
1923 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1924 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1925 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1926 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001927
1928 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001929 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001930 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001931
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001932 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001933 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001934 }
1935 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001936 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001937 }
1938 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001939 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1940 }
1941 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1942 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1943 }
1944 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1945 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001946 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001947
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001948 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1949 gen7_3DSTATE_GS(cmd);
1950 } else {
1951 gen6_3DSTATE_GS(cmd);
1952 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001953
Chia-I Wu8370b402014-08-29 12:28:37 +08001954 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1955 cmd_wa_gen7_post_command_cs_stall(cmd);
1956 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1957 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001958}
1959
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001960static void emit_bounded_states(struct intel_cmd *cmd)
1961{
1962 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1963
1964 emit_graphics_pipeline(cmd);
1965
1966 emit_rt(cmd);
1967 emit_ds(cmd);
1968
1969 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1970 gen7_cc_states(cmd);
1971 gen7_viewport_states(cmd);
1972
1973 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1974 &cmd->bind.pipeline.graphics->vs);
1975 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1976 &cmd->bind.pipeline.graphics->fs);
1977
1978 gen6_3DSTATE_CLIP(cmd);
1979 gen7_3DSTATE_SF(cmd);
1980 gen7_3DSTATE_SBE(cmd);
1981 gen7_3DSTATE_WM(cmd);
1982 gen7_3DSTATE_PS(cmd);
1983 } else {
1984 gen6_cc_states(cmd);
1985 gen6_viewport_states(cmd);
1986
1987 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1988 &cmd->bind.pipeline.graphics->vs);
1989 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1990 &cmd->bind.pipeline.graphics->fs);
1991
1992 gen6_3DSTATE_CLIP(cmd);
1993 gen6_3DSTATE_SF(cmd);
1994 gen6_3DSTATE_WM(cmd);
1995 }
1996
1997 emit_shader_resources(cmd);
1998
1999 cmd_wa_gen6_pre_depth_stall_write(cmd);
2000 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2001
2002 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2003 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2004
2005 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2006 gen6_3DSTATE_VS(cmd);
2007}
2008
Chia-I Wu6032b892014-10-17 14:47:18 +08002009static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2010{
2011 const struct intel_cmd_meta *meta = cmd->bind.meta;
2012 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2013
2014 CMD_ASSERT(cmd, 6, 7.5);
2015
2016 blend_offset = 0;
2017 ds_offset = 0;
2018 cc_offset = 0;
2019 cc_vp_offset = 0;
2020
Chia-I Wu29e6f502014-11-24 14:27:29 +08002021 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002022 /* BLEND_STATE */
2023 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002024 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002025 dw[0] = 0;
2026 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2027 }
2028
Chia-I Wu29e6f502014-11-24 14:27:29 +08002029 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2030 if (meta->ds.state) {
2031 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002032
Chia-I Wu29e6f502014-11-24 14:27:29 +08002033 /* DEPTH_STENCIL_STATE */
2034 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002035
Chia-I Wu29e6f502014-11-24 14:27:29 +08002036 /* COLOR_CALC_STATE */
2037 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2038 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002039
Chia-I Wu29e6f502014-11-24 14:27:29 +08002040 /* CC_VIEWPORT */
2041 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002042 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002043 dw[0] = u_fui(0.0f);
2044 dw[1] = u_fui(1.0f);
2045 } else {
2046 /* DEPTH_STENCIL_STATE */
2047 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002048 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002049 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2050 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2051 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002052 }
2053
2054 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2055 gen7_3dstate_pointer(cmd,
2056 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2057 blend_offset);
2058 gen7_3dstate_pointer(cmd,
2059 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2060 ds_offset);
2061 gen7_3dstate_pointer(cmd,
2062 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2063
2064 gen7_3dstate_pointer(cmd,
2065 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2066 cc_vp_offset);
2067 } else {
2068 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002069 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002070
2071 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2072 cmd_batch_pointer(cmd, 4, &dw);
2073 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2074 GEN6_PTR_VP_DW0_CC_CHANGED;
2075 dw[1] = 0;
2076 dw[2] = 0;
2077 dw[3] = cc_vp_offset;
2078 }
2079}
2080
2081static void gen6_meta_surface_states(struct intel_cmd *cmd)
2082{
2083 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002084 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002085 uint32_t offset;
2086
2087 CMD_ASSERT(cmd, 6, 7.5);
2088
Chia-I Wu29e6f502014-11-24 14:27:29 +08002089 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2090 return;
2091
Chia-I Wu005c47c2014-10-22 13:49:13 +08002092 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002093 if (meta->src.valid) {
2094 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002095 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002096 meta->src.surface_len, meta->src.surface);
2097
2098 cmd_reserve_reloc(cmd, 1);
2099 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2100 cmd_surface_reloc_writer(cmd, offset, 1,
2101 meta->src.reloc_target, meta->src.reloc_offset);
2102 } else {
2103 cmd_surface_reloc(cmd, offset, 1,
2104 (struct intel_bo *) meta->src.reloc_target,
2105 meta->src.reloc_offset, meta->src.reloc_flags);
2106 }
2107
Chia-I Wu005c47c2014-10-22 13:49:13 +08002108 binding_table[0] = offset;
2109 }
2110 if (meta->dst.valid) {
2111 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002112 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002113 meta->dst.surface_len, meta->dst.surface);
2114
2115 cmd_reserve_reloc(cmd, 1);
2116 cmd_surface_reloc(cmd, offset, 1,
2117 (struct intel_bo *) meta->dst.reloc_target,
2118 meta->dst.reloc_offset, meta->dst.reloc_flags);
2119
2120 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002121 }
2122
2123 /* BINDING_TABLE */
2124 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002125 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002126 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002127
2128 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002129 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2130 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2131 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2132 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002133 } else {
2134 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002135 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2136 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2137 else
2138 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002139 }
2140}
2141
2142static void gen6_meta_urb(struct intel_cmd *cmd)
2143{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002144 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002145 uint32_t *dw;
2146
2147 CMD_ASSERT(cmd, 6, 6);
2148
2149 /* 3DSTATE_URB */
2150 cmd_batch_pointer(cmd, 3, &dw);
2151 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002152 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002153 dw[2] = 0;
2154}
2155
2156static void gen7_meta_urb(struct intel_cmd *cmd)
2157{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002158 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002159 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002160 uint32_t *dw;
2161
2162 CMD_ASSERT(cmd, 7, 7.5);
2163
2164 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2165 cmd_batch_pointer(cmd, 10, &dw);
2166
2167 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002168 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002169 dw += 2;
2170
2171 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2172 dw[1] = 0;
2173 dw += 2;
2174
2175 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2176 dw[1] = 0;
2177 dw += 2;
2178
2179 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2180 dw[1] = 0;
2181 dw += 2;
2182
2183 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002184 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002185
2186 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2187
Chia-I Wu24aa1022014-11-25 11:53:19 +08002188 switch (cmd_gen(cmd)) {
2189 case INTEL_GEN(7.5):
2190 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2191 break;
2192 case INTEL_GEN(7):
2193 default:
2194 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2195 break;
2196 }
2197
Chia-I Wu6032b892014-10-17 14:47:18 +08002198 /* 3DSTATE_URB_x */
2199 cmd_batch_pointer(cmd, 8, &dw);
2200
2201 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2202 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002203 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002204 dw += 2;
2205
2206 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2207 dw[1] = 0;
2208 dw += 2;
2209
2210 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2211 dw[1] = 0;
2212 dw += 2;
2213
2214 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2215 dw[1] = 0;
2216 dw += 2;
2217}
2218
2219static void gen6_meta_vf(struct intel_cmd *cmd)
2220{
2221 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002222 uint32_t vb_start, vb_end, vb_stride;
2223 int ve_format, ve_z_source;
2224 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002225 XGL_UINT pos;
2226
2227 CMD_ASSERT(cmd, 6, 7.5);
2228
Chia-I Wu29e6f502014-11-24 14:27:29 +08002229 switch (meta->mode) {
2230 case INTEL_CMD_META_VS_POINTS:
2231 cmd_batch_pointer(cmd, 3, &dw);
2232 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2233 dw[1] = GEN6_VE_STATE_DW0_VALID;
2234 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2235 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2236 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2237 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2238 return;
2239 break;
2240 case INTEL_CMD_META_FS_RECT:
2241 {
2242 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002243
Chia-I Wu29e6f502014-11-24 14:27:29 +08002244 vertices[0][0] = meta->dst.x + meta->width;
2245 vertices[0][1] = meta->dst.y + meta->height;
2246 vertices[1][0] = meta->dst.x;
2247 vertices[1][1] = meta->dst.y + meta->height;
2248 vertices[2][0] = meta->dst.x;
2249 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002250
Chia-I Wu29e6f502014-11-24 14:27:29 +08002251 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2252 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002253
Chia-I Wu29e6f502014-11-24 14:27:29 +08002254 vb_end = vb_start + sizeof(vertices) - 1;
2255 vb_stride = sizeof(vertices[0]);
2256 ve_z_source = GEN6_VFCOMP_STORE_0;
2257 ve_format = GEN6_FORMAT_R32G32_USCALED;
2258 }
2259 break;
2260 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2261 {
2262 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002263
Chia-I Wu29e6f502014-11-24 14:27:29 +08002264 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2265 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2266 vertices[0][2] = u_uif(meta->clear_val[0]);
2267 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2268 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2269 vertices[1][2] = u_uif(meta->clear_val[0]);
2270 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2271 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2272 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002273
Chia-I Wu29e6f502014-11-24 14:27:29 +08002274 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2275 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002276
Chia-I Wu29e6f502014-11-24 14:27:29 +08002277 vb_end = vb_start + sizeof(vertices) - 1;
2278 vb_stride = sizeof(vertices[0]);
2279 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2280 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2281 }
2282 break;
2283 default:
2284 assert(!"unknown meta mode");
2285 return;
2286 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002287 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002288
2289 /* 3DSTATE_VERTEX_BUFFERS */
2290 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002291
Chia-I Wu6032b892014-10-17 14:47:18 +08002292 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002293 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002294 if (cmd_gen(cmd) >= INTEL_GEN(7))
2295 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2296
2297 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002298 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2299 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002300
2301 dw[4] = 0;
2302
2303 /* 3DSTATE_VERTEX_ELEMENTS */
2304 cmd_batch_pointer(cmd, 5, &dw);
2305 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002306 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002307 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2308 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2309 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2310 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2311 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002312 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002313 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2314 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002315 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002316 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2317}
2318
Chia-I Wu29e6f502014-11-24 14:27:29 +08002319static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002320{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002321 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002322 /* one GPR */
2323 XGL_UINT consts[8];
2324 XGL_UINT const_count;
2325
2326 CMD_ASSERT(cmd, 6, 7.5);
2327
2328 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002329 case INTEL_DEV_META_VS_FILL_MEM:
2330 consts[0] = meta->dst.x;
2331 consts[1] = meta->clear_val[0];
2332 const_count = 2;
2333 break;
2334 case INTEL_DEV_META_VS_COPY_MEM:
2335 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2336 consts[0] = meta->dst.x;
2337 consts[1] = meta->src.x;
2338 const_count = 2;
2339 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002340 default:
2341 assert(!"unknown meta shader id");
2342 const_count = 0;
2343 break;
2344 }
2345
2346 /* this can be skipped but it makes state dumping prettier */
2347 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2348
2349 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2350}
2351
2352static void gen6_meta_vs(struct intel_cmd *cmd)
2353{
2354 const struct intel_cmd_meta *meta = cmd->bind.meta;
2355 const struct intel_pipeline_shader *sh =
2356 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002357 const int max_threads = cmd_vs_max_threads(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002358 uint32_t offset, *dw;
2359
2360 CMD_ASSERT(cmd, 6, 7.5);
2361
2362 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2363 XGL_UINT cmd_len;
2364
2365 /* 3DSTATE_CONSTANT_VS */
2366 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2367 cmd_batch_pointer(cmd, cmd_len, &dw);
2368 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2369 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2370
2371 /* 3DSTATE_VS */
2372 cmd_batch_pointer(cmd, 6, &dw);
2373 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2374 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2375
2376 return;
2377 }
2378
2379 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2380
2381 /* 3DSTATE_CONSTANT_VS */
2382 offset = gen6_meta_vs_constants(cmd);
2383 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2384 cmd_batch_pointer(cmd, 7, &dw);
2385 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2386 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2387 dw[2] = 0;
2388 dw[3] = offset;
2389 dw[4] = 0;
2390 dw[5] = 0;
2391 dw[6] = 0;
2392 } else {
2393 cmd_batch_pointer(cmd, 5, &dw);
2394 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2395 GEN6_PCB_ANY_DW0_PCB0_VALID;
2396 dw[1] = offset;
2397 dw[2] = 0;
2398 dw[3] = 0;
2399 dw[4] = 0;
2400 }
2401
2402 /* 3DSTATE_VS */
2403 offset = emit_shader(cmd, sh);
2404 cmd_batch_pointer(cmd, 6, &dw);
2405 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2406 dw[1] = offset;
2407 dw[2] = GEN6_THREADDISP_SPF |
2408 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2409 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2410 dw[3] = 0;
2411 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2412 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2413
2414 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2415 GEN6_VS_DW5_VS_ENABLE;
2416 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu05990612014-11-25 11:36:35 +08002417 dw[5] |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002418 else
Chia-I Wu05990612014-11-25 11:36:35 +08002419 dw[5] |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002420}
2421
2422static void gen6_meta_disabled(struct intel_cmd *cmd)
2423{
Chia-I Wu6032b892014-10-17 14:47:18 +08002424 uint32_t *dw;
2425
2426 CMD_ASSERT(cmd, 6, 6);
2427
Chia-I Wu6032b892014-10-17 14:47:18 +08002428 /* 3DSTATE_CONSTANT_GS */
2429 cmd_batch_pointer(cmd, 5, &dw);
2430 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2431 dw[1] = 0;
2432 dw[2] = 0;
2433 dw[3] = 0;
2434 dw[4] = 0;
2435
2436 /* 3DSTATE_GS */
2437 cmd_batch_pointer(cmd, 7, &dw);
2438 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2439 dw[1] = 0;
2440 dw[2] = 0;
2441 dw[3] = 0;
2442 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2443 dw[5] = GEN6_GS_DW5_STATISTICS;
2444 dw[6] = 0;
2445
Chia-I Wu6032b892014-10-17 14:47:18 +08002446 /* 3DSTATE_SF */
2447 cmd_batch_pointer(cmd, 20, &dw);
2448 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2449 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2450 memset(&dw[2], 0, 18 * sizeof(*dw));
2451}
2452
2453static void gen7_meta_disabled(struct intel_cmd *cmd)
2454{
2455 uint32_t *dw;
2456
2457 CMD_ASSERT(cmd, 7, 7.5);
2458
Chia-I Wu6032b892014-10-17 14:47:18 +08002459 /* 3DSTATE_CONSTANT_HS */
2460 cmd_batch_pointer(cmd, 7, &dw);
2461 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2462 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2463
2464 /* 3DSTATE_HS */
2465 cmd_batch_pointer(cmd, 7, &dw);
2466 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2467 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2468
2469 /* 3DSTATE_TE */
2470 cmd_batch_pointer(cmd, 4, &dw);
2471 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2472 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2473
2474 /* 3DSTATE_CONSTANT_DS */
2475 cmd_batch_pointer(cmd, 7, &dw);
2476 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2477 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2478
2479 /* 3DSTATE_DS */
2480 cmd_batch_pointer(cmd, 6, &dw);
2481 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2482 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2483
2484 /* 3DSTATE_CONSTANT_GS */
2485 cmd_batch_pointer(cmd, 7, &dw);
2486 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2487 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2488
2489 /* 3DSTATE_GS */
2490 cmd_batch_pointer(cmd, 7, &dw);
2491 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2492 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2493
2494 /* 3DSTATE_STREAMOUT */
2495 cmd_batch_pointer(cmd, 3, &dw);
2496 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2497 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2498
Chia-I Wu6032b892014-10-17 14:47:18 +08002499 /* 3DSTATE_SF */
2500 cmd_batch_pointer(cmd, 7, &dw);
2501 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2502 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2503
2504 /* 3DSTATE_SBE */
2505 cmd_batch_pointer(cmd, 14, &dw);
2506 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2507 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2508 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002509}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002510
Chia-I Wu29e6f502014-11-24 14:27:29 +08002511static void gen6_meta_clip(struct intel_cmd *cmd)
2512{
2513 const struct intel_cmd_meta *meta = cmd->bind.meta;
2514 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002515
Chia-I Wu29e6f502014-11-24 14:27:29 +08002516 /* 3DSTATE_CLIP */
2517 cmd_batch_pointer(cmd, 4, &dw);
2518 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2519 dw[1] = 0;
2520 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2521 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2522 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2523 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002524 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002525 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002526 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002527}
2528
2529static void gen6_meta_wm(struct intel_cmd *cmd)
2530{
2531 const struct intel_cmd_meta *meta = cmd->bind.meta;
2532 uint32_t *dw;
2533
2534 CMD_ASSERT(cmd, 6, 7.5);
2535
2536 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2537
2538 /* 3DSTATE_MULTISAMPLE */
2539 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2540 cmd_batch_pointer(cmd, 4, &dw);
2541 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2542 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2543 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2544 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2545 dw[2] = 0;
2546 dw[3] = 0;
2547 } else {
2548 cmd_batch_pointer(cmd, 3, &dw);
2549 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2550 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2551 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2552 dw[2] = 0;
2553 }
2554
2555 /* 3DSTATE_SAMPLE_MASK */
2556 cmd_batch_pointer(cmd, 2, &dw);
2557 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2558 dw[1] = (1 << meta->samples) - 1;
2559
2560 /* 3DSTATE_DRAWING_RECTANGLE */
2561 cmd_batch_pointer(cmd, 4, &dw);
2562 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2563 dw[1] = meta->dst.y << 16 | meta->dst.x;
2564 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2565 (meta->dst.x + meta->width - 1);
2566 dw[3] = 0;
2567}
2568
2569static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2570{
2571 const struct intel_cmd_meta *meta = cmd->bind.meta;
2572 XGL_UINT offset_x, offset_y;
2573 /* one GPR */
2574 XGL_UINT consts[8];
2575 XGL_UINT const_count;
2576
2577 CMD_ASSERT(cmd, 6, 7.5);
2578
2579 /* underflow is fine here */
2580 offset_x = meta->src.x - meta->dst.x;
2581 offset_y = meta->src.y - meta->dst.y;
2582
2583 switch (meta->shader_id) {
2584 case INTEL_DEV_META_FS_COPY_MEM:
2585 case INTEL_DEV_META_FS_COPY_1D:
2586 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2587 case INTEL_DEV_META_FS_COPY_2D:
2588 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2589 case INTEL_DEV_META_FS_COPY_2D_MS:
2590 consts[0] = offset_x;
2591 consts[1] = offset_y;
2592 consts[2] = meta->src.layer;
2593 consts[3] = meta->src.lod;
2594 const_count = 4;
2595 break;
2596 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2597 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2598 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2599 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2600 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2601 consts[0] = offset_x;
2602 consts[1] = offset_y;
2603 consts[2] = meta->src.layer;
2604 consts[3] = meta->src.lod;
2605 consts[4] = meta->src.x;
2606 consts[5] = meta->width;
2607 const_count = 6;
2608 break;
2609 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2610 consts[0] = offset_x;
2611 consts[1] = offset_y;
2612 consts[2] = meta->width;
2613 const_count = 3;
2614 break;
2615 case INTEL_DEV_META_FS_CLEAR_COLOR:
2616 consts[0] = meta->clear_val[0];
2617 consts[1] = meta->clear_val[1];
2618 consts[2] = meta->clear_val[2];
2619 consts[3] = meta->clear_val[3];
2620 const_count = 4;
2621 break;
2622 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2623 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002624 consts[1] = meta->clear_val[1];
2625 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002626 break;
2627 case INTEL_DEV_META_FS_RESOLVE_2X:
2628 case INTEL_DEV_META_FS_RESOLVE_4X:
2629 case INTEL_DEV_META_FS_RESOLVE_8X:
2630 case INTEL_DEV_META_FS_RESOLVE_16X:
2631 consts[0] = offset_x;
2632 consts[1] = offset_y;
2633 const_count = 2;
2634 break;
2635 default:
2636 assert(!"unknown meta shader id");
2637 const_count = 0;
2638 break;
2639 }
2640
2641 /* this can be skipped but it makes state dumping prettier */
2642 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2643
2644 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2645}
2646
2647static void gen6_meta_ps(struct intel_cmd *cmd)
2648{
2649 const struct intel_cmd_meta *meta = cmd->bind.meta;
2650 const struct intel_pipeline_shader *sh =
2651 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002652 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002653 uint32_t offset, *dw;
2654
2655 CMD_ASSERT(cmd, 6, 6);
2656
Chia-I Wu29e6f502014-11-24 14:27:29 +08002657 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2658 /* 3DSTATE_CONSTANT_PS */
2659 cmd_batch_pointer(cmd, 5, &dw);
2660 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2661 dw[1] = 0;
2662 dw[2] = 0;
2663 dw[3] = 0;
2664 dw[4] = 0;
2665
2666 /* 3DSTATE_WM */
2667 cmd_batch_pointer(cmd, 9, &dw);
2668 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2669 dw[1] = 0;
2670 dw[2] = 0;
2671 dw[3] = 0;
2672 dw[4] = 0;
Chia-I Wu05990612014-11-25 11:36:35 +08002673 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002674 dw[6] = 0;
2675 dw[7] = 0;
2676 dw[8] = 0;
2677
Chia-I Wu3adf7212014-10-24 15:34:07 +08002678 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002679 }
2680
Chia-I Wu3adf7212014-10-24 15:34:07 +08002681 /* a normal color write */
2682 assert(meta->dst.valid && !sh->uses);
2683
Chia-I Wu6032b892014-10-17 14:47:18 +08002684 /* 3DSTATE_CONSTANT_PS */
2685 offset = gen6_meta_ps_constants(cmd);
2686 cmd_batch_pointer(cmd, 5, &dw);
2687 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2688 GEN6_PCB_ANY_DW0_PCB0_VALID;
2689 dw[1] = offset;
2690 dw[2] = 0;
2691 dw[3] = 0;
2692 dw[4] = 0;
2693
2694 /* 3DSTATE_WM */
2695 offset = emit_shader(cmd, sh);
2696 cmd_batch_pointer(cmd, 9, &dw);
2697 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2698 dw[1] = offset;
2699 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2700 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2701 dw[3] = 0;
2702 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002703 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002704 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002705 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2706
Chia-I Wu6032b892014-10-17 14:47:18 +08002707 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2708 GEN6_WM_DW6_POSOFFSET_NONE |
2709 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2710 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2711 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2712 if (meta->samples > 1) {
2713 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2714 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2715 } else {
2716 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2717 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2718 }
2719 dw[7] = 0;
2720 dw[8] = 0;
2721}
2722
2723static void gen7_meta_ps(struct intel_cmd *cmd)
2724{
2725 const struct intel_cmd_meta *meta = cmd->bind.meta;
2726 const struct intel_pipeline_shader *sh =
2727 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002728 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002729 uint32_t offset, *dw;
2730
2731 CMD_ASSERT(cmd, 7, 7.5);
2732
Chia-I Wu29e6f502014-11-24 14:27:29 +08002733 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2734 /* 3DSTATE_WM */
2735 cmd_batch_pointer(cmd, 3, &dw);
2736 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2737 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2738
2739 /* 3DSTATE_CONSTANT_GS */
2740 cmd_batch_pointer(cmd, 7, &dw);
2741 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2742 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2743
2744 /* 3DSTATE_PS */
2745 cmd_batch_pointer(cmd, 8, &dw);
2746 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2747 dw[1] = 0;
2748 dw[2] = 0;
2749 dw[3] = 0;
2750 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu05990612014-11-25 11:36:35 +08002751 (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002752 dw[5] = 0;
2753 dw[6] = 0;
2754 dw[7] = 0;
2755
Chia-I Wu3adf7212014-10-24 15:34:07 +08002756 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002757 }
2758
Chia-I Wu3adf7212014-10-24 15:34:07 +08002759 /* a normal color write */
2760 assert(meta->dst.valid && !sh->uses);
2761
Chia-I Wu6032b892014-10-17 14:47:18 +08002762 /* 3DSTATE_WM */
2763 cmd_batch_pointer(cmd, 3, &dw);
2764 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2765 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2766 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2767 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2768 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2769 dw[2] = 0;
2770
2771 /* 3DSTATE_CONSTANT_PS */
2772 offset = gen6_meta_ps_constants(cmd);
2773 cmd_batch_pointer(cmd, 7, &dw);
2774 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2775 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2776 dw[2] = 0;
2777 dw[3] = offset;
2778 dw[4] = 0;
2779 dw[5] = 0;
2780 dw[6] = 0;
2781
2782 /* 3DSTATE_PS */
2783 offset = emit_shader(cmd, sh);
2784 cmd_batch_pointer(cmd, 8, &dw);
2785 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2786 dw[1] = offset;
2787 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2788 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2789 dw[3] = 0;
2790
2791 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2792 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002793 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2794
2795 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2796 dw[4] |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002797 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002798 } else {
2799 dw[4] |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2800 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002801
2802 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2803 dw[6] = 0;
2804 dw[7] = 0;
2805}
2806
2807static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2808{
2809 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002810 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002811
2812 CMD_ASSERT(cmd, 6, 7.5);
2813
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002814 if (!ds) {
2815 /* all zeros */
2816 static const struct intel_ds_view null_ds;
2817 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002818 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002819
2820 cmd_wa_gen6_pre_ds_flush(cmd);
2821 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2822 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2823 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2824
2825 if (cmd_gen(cmd) >= INTEL_GEN(7))
2826 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2827 else
2828 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002829}
2830
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002831static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2832 const struct intel_pipeline *pipeline)
2833{
2834 cmd->bind.pipeline.graphics = pipeline;
2835}
2836
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002837static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2838 const struct intel_pipeline *pipeline)
2839{
2840 cmd->bind.pipeline.compute = pipeline;
2841}
2842
2843static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2844 const struct intel_pipeline_delta *delta)
2845{
2846 cmd->bind.pipeline.graphics_delta = delta;
2847}
2848
2849static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2850 const struct intel_pipeline_delta *delta)
2851{
2852 cmd->bind.pipeline.compute_delta = delta;
2853}
2854
2855static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2856 const struct intel_dset *dset,
2857 XGL_UINT slot_offset)
2858{
2859 cmd->bind.dset.graphics = dset;
2860 cmd->bind.dset.graphics_offset = slot_offset;
2861}
2862
2863static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2864 const struct intel_dset *dset,
2865 XGL_UINT slot_offset)
2866{
2867 cmd->bind.dset.compute = dset;
2868 cmd->bind.dset.compute_offset = slot_offset;
2869}
2870
2871static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2872 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2873{
2874 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2875}
2876
2877static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2878 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2879{
2880 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2881}
2882
Chia-I Wu3b04af52014-11-08 10:48:20 +08002883static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2884 const struct intel_mem *mem,
2885 XGL_GPU_SIZE offset, XGL_UINT binding)
2886{
2887 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2888 cmd->result = XGL_ERROR_UNKNOWN;
2889 return;
2890 }
2891
2892 cmd->bind.vertex.mem[binding] = mem;
2893 cmd->bind.vertex.offset[binding] = offset;
2894}
2895
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002896static void cmd_bind_index_data(struct intel_cmd *cmd,
2897 const struct intel_mem *mem,
2898 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2899{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002900 cmd->bind.index.mem = mem;
2901 cmd->bind.index.offset = offset;
2902 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002903}
2904
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002905static void cmd_bind_attachments(struct intel_cmd *cmd,
2906 XGL_UINT rt_count,
2907 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2908 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002909{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002910 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002911 XGL_UINT i;
2912
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002913 for (i = 0; i < rt_count; i++) {
2914 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002915 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002916 const struct intel_layout *layout = &rt->img->layout;
2917
2918 if (i == 0) {
2919 width = layout->width0;
2920 height = layout->height0;
2921 } else {
2922 if (width > layout->width0)
2923 width = layout->width0;
2924 if (height > layout->height0)
2925 height = layout->height0;
2926 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002927
2928 cmd->bind.att.rt[i] = rt;
2929 }
2930
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002931 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002932
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002933 if (ds_info) {
2934 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002935
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002936 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2937 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002938
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002939 if (width > layout->width0)
2940 width = layout->width0;
2941 if (height > layout->height0)
2942 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002943 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002944 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002945 }
2946
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002947 cmd->bind.att.width = width;
2948 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002949}
2950
2951static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2952 const struct intel_viewport_state *state)
2953{
2954 cmd->bind.state.viewport = state;
2955}
2956
2957static void cmd_bind_raster_state(struct intel_cmd *cmd,
2958 const struct intel_raster_state *state)
2959{
2960 cmd->bind.state.raster = state;
2961}
2962
2963static void cmd_bind_ds_state(struct intel_cmd *cmd,
2964 const struct intel_ds_state *state)
2965{
2966 cmd->bind.state.ds = state;
2967}
2968
2969static void cmd_bind_blend_state(struct intel_cmd *cmd,
2970 const struct intel_blend_state *state)
2971{
2972 cmd->bind.state.blend = state;
2973}
2974
2975static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2976 const struct intel_msaa_state *state)
2977{
2978 cmd->bind.state.msaa = state;
2979}
2980
2981static void cmd_draw(struct intel_cmd *cmd,
2982 XGL_UINT vertex_start,
2983 XGL_UINT vertex_count,
2984 XGL_UINT instance_start,
2985 XGL_UINT instance_count,
2986 bool indexed,
2987 XGL_UINT vertex_base)
2988{
2989 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2990
2991 emit_bounded_states(cmd);
2992
2993 if (indexed) {
2994 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2995 cmd->result = XGL_ERROR_UNKNOWN;
2996
2997 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2998 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2999 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003000 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3001 cmd->bind.index.offset, cmd->bind.index.type,
3002 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003003 } else {
3004 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3005 cmd->bind.index.offset, cmd->bind.index.type,
3006 p->primitive_restart);
3007 }
3008 } else {
3009 assert(!vertex_base);
3010 }
3011
3012 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3013 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3014 vertex_start, instance_count, instance_start, vertex_base);
3015 } else {
3016 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3017 vertex_start, instance_count, instance_start, vertex_base);
3018 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003019
Chia-I Wu707a29e2014-08-27 12:51:47 +08003020 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003021 /* need to re-emit all workarounds */
3022 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003023
3024 if (intel_debug & INTEL_DEBUG_NOCACHE)
3025 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003026}
3027
Chia-I Wuc14d1562014-10-17 09:49:22 +08003028void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3029{
Chia-I Wu6032b892014-10-17 14:47:18 +08003030 cmd->bind.meta = meta;
3031
3032 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003033 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003034
3035 gen6_meta_dynamic_states(cmd);
3036 gen6_meta_surface_states(cmd);
3037
3038 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3039 gen7_meta_urb(cmd);
3040 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003041 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003042 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003043 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003044 gen6_meta_wm(cmd);
3045 gen7_meta_ps(cmd);
3046 gen6_meta_depth_buffer(cmd);
3047
3048 cmd_wa_gen7_post_command_cs_stall(cmd);
3049 cmd_wa_gen7_post_command_depth_stall(cmd);
3050
Chia-I Wu29e6f502014-11-24 14:27:29 +08003051 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3052 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3053 meta->width, 0, 1, 0, 0);
3054 } else {
3055 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3056 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003057 } else {
3058 gen6_meta_urb(cmd);
3059 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003060 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003061 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003062 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003063 gen6_meta_wm(cmd);
3064 gen6_meta_ps(cmd);
3065 gen6_meta_depth_buffer(cmd);
3066
Chia-I Wu29e6f502014-11-24 14:27:29 +08003067 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3068 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3069 meta->width, 0, 1, 0, 0);
3070 } else {
3071 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3072 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003073 }
3074
3075 cmd->bind.draw_count++;
3076 /* need to re-emit all workarounds */
3077 cmd->bind.wa_flags = 0;
3078
3079 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003080
3081 if (intel_debug & INTEL_DEBUG_NOCACHE)
3082 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003083}
3084
Chia-I Wub2755562014-08-20 13:38:52 +08003085XGL_VOID XGLAPI intelCmdBindPipeline(
3086 XGL_CMD_BUFFER cmdBuffer,
3087 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3088 XGL_PIPELINE pipeline)
3089{
3090 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3091
3092 switch (pipelineBindPoint) {
3093 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003094 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003095 break;
3096 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003097 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003098 break;
3099 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003100 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003101 break;
3102 }
3103}
3104
3105XGL_VOID XGLAPI intelCmdBindPipelineDelta(
3106 XGL_CMD_BUFFER cmdBuffer,
3107 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3108 XGL_PIPELINE_DELTA delta)
3109{
3110 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3111
3112 switch (pipelineBindPoint) {
3113 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003114 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003115 break;
3116 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003117 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003118 break;
3119 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003120 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003121 break;
3122 }
3123}
3124
3125XGL_VOID XGLAPI intelCmdBindStateObject(
3126 XGL_CMD_BUFFER cmdBuffer,
3127 XGL_STATE_BIND_POINT stateBindPoint,
3128 XGL_STATE_OBJECT state)
3129{
3130 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3131
3132 switch (stateBindPoint) {
3133 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003134 cmd_bind_viewport_state(cmd,
3135 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003136 break;
3137 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003138 cmd_bind_raster_state(cmd,
3139 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003140 break;
3141 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003142 cmd_bind_ds_state(cmd,
3143 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003144 break;
3145 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003146 cmd_bind_blend_state(cmd,
3147 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003148 break;
3149 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003150 cmd_bind_msaa_state(cmd,
3151 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003152 break;
3153 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003154 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003155 break;
3156 }
3157}
3158
3159XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3160 XGL_CMD_BUFFER cmdBuffer,
3161 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3162 XGL_UINT index,
3163 XGL_DESCRIPTOR_SET descriptorSet,
3164 XGL_UINT slotOffset)
3165{
3166 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3167 struct intel_dset *dset = intel_dset(descriptorSet);
3168
3169 assert(!index);
3170
3171 switch (pipelineBindPoint) {
3172 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003173 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003174 break;
3175 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003176 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003177 break;
3178 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003179 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003180 break;
3181 }
3182}
3183
3184XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3185 XGL_CMD_BUFFER cmdBuffer,
3186 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3187 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3188{
3189 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3190
3191 switch (pipelineBindPoint) {
3192 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003193 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003194 break;
3195 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003196 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003197 break;
3198 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003199 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003200 break;
3201 }
3202}
3203
Chia-I Wu3b04af52014-11-08 10:48:20 +08003204XGL_VOID XGLAPI intelCmdBindVertexData(
3205 XGL_CMD_BUFFER cmdBuffer,
3206 XGL_GPU_MEMORY mem_,
3207 XGL_GPU_SIZE offset,
3208 XGL_UINT binding)
3209{
3210 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3211 struct intel_mem *mem = intel_mem(mem_);
3212
3213 cmd_bind_vertex_data(cmd, mem, offset, binding);
3214}
3215
Chia-I Wub2755562014-08-20 13:38:52 +08003216XGL_VOID XGLAPI intelCmdBindIndexData(
3217 XGL_CMD_BUFFER cmdBuffer,
3218 XGL_GPU_MEMORY mem_,
3219 XGL_GPU_SIZE offset,
3220 XGL_INDEX_TYPE indexType)
3221{
3222 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3223 struct intel_mem *mem = intel_mem(mem_);
3224
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003225 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003226}
3227
3228XGL_VOID XGLAPI intelCmdBindAttachments(
3229 XGL_CMD_BUFFER cmdBuffer,
3230 XGL_UINT colorAttachmentCount,
3231 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3232 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3233{
3234 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003235
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003236 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3237 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003238}
3239
3240XGL_VOID XGLAPI intelCmdDraw(
3241 XGL_CMD_BUFFER cmdBuffer,
3242 XGL_UINT firstVertex,
3243 XGL_UINT vertexCount,
3244 XGL_UINT firstInstance,
3245 XGL_UINT instanceCount)
3246{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003247 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003248
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003249 cmd_draw(cmd, firstVertex, vertexCount,
3250 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003251}
3252
3253XGL_VOID XGLAPI intelCmdDrawIndexed(
3254 XGL_CMD_BUFFER cmdBuffer,
3255 XGL_UINT firstIndex,
3256 XGL_UINT indexCount,
3257 XGL_INT vertexOffset,
3258 XGL_UINT firstInstance,
3259 XGL_UINT instanceCount)
3260{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003261 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003262
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003263 cmd_draw(cmd, firstIndex, indexCount,
3264 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003265}
3266
3267XGL_VOID XGLAPI intelCmdDrawIndirect(
3268 XGL_CMD_BUFFER cmdBuffer,
3269 XGL_GPU_MEMORY mem,
3270 XGL_GPU_SIZE offset,
3271 XGL_UINT32 count,
3272 XGL_UINT32 stride)
3273{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003274 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3275
3276 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003277}
3278
3279XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3280 XGL_CMD_BUFFER cmdBuffer,
3281 XGL_GPU_MEMORY mem,
3282 XGL_GPU_SIZE offset,
3283 XGL_UINT32 count,
3284 XGL_UINT32 stride)
3285{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003286 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3287
3288 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003289}
3290
3291XGL_VOID XGLAPI intelCmdDispatch(
3292 XGL_CMD_BUFFER cmdBuffer,
3293 XGL_UINT x,
3294 XGL_UINT y,
3295 XGL_UINT z)
3296{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003297 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3298
3299 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003300}
3301
3302XGL_VOID XGLAPI intelCmdDispatchIndirect(
3303 XGL_CMD_BUFFER cmdBuffer,
3304 XGL_GPU_MEMORY mem,
3305 XGL_GPU_SIZE offset)
3306{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003307 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3308
3309 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003310}