blob: 69809bdf76e48e3618b53e97404a2b3fafa88e32 [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 Wu72292b72014-09-09 10:48:33 +08001018 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
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 Wu72292b72014-09-09 10:48:33 +08001031 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
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 Wu72292b72014-09-09 10:48:33 +08001045 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
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,
1337 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1338 viewport->cmd);
1339
1340 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1341 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1342 &viewport->cmd[viewport->cmd_clip_pos]);
1343
1344 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1345 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1346 &viewport->cmd[viewport->cmd_cc_pos]);
1347
1348 if (viewport->scissor_enable) {
1349 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1350 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1351 &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,
1411 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1412 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,
1418 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1419 &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,
1426 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1427 &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 =
1475 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
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,
1488 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1489 border_stride * rmap->sampler_count, &border_dw);
1490
1491 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1492 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1493 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 Wu72292b72014-09-09 10:48:33 +08001582 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1583 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 Wu72292b72014-09-09 10:48:33 +08001596 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1597 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,
1616 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1617 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,
1627 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1628 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,
1640 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1641 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 Wu00b51a82014-09-09 12:07:37 +08001658 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
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,
2024 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2025 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,
2042 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
2043 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,
2048 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4,
2049 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,
2095 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2096 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,
2112 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2113 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,
2125 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
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{
2144 uint32_t *dw;
2145
2146 CMD_ASSERT(cmd, 6, 6);
2147
2148 /* 3DSTATE_URB */
2149 cmd_batch_pointer(cmd, 3, &dw);
2150 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
2151 dw[1] = 128 << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
2152 dw[2] = 0;
2153}
2154
2155static void gen7_meta_urb(struct intel_cmd *cmd)
2156{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002157 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002158 uint32_t *dw;
2159
2160 CMD_ASSERT(cmd, 7, 7.5);
2161
2162 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2163 cmd_batch_pointer(cmd, 10, &dw);
2164
2165 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002166 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002167 dw += 2;
2168
2169 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2170 dw[1] = 0;
2171 dw += 2;
2172
2173 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2174 dw[1] = 0;
2175 dw += 2;
2176
2177 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2178 dw[1] = 0;
2179 dw += 2;
2180
2181 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002182 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002183
2184 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2185
2186 /* 3DSTATE_URB_x */
2187 cmd_batch_pointer(cmd, 8, &dw);
2188
2189 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2190 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
2191 512;
2192 dw += 2;
2193
2194 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2195 dw[1] = 0;
2196 dw += 2;
2197
2198 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2199 dw[1] = 0;
2200 dw += 2;
2201
2202 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2203 dw[1] = 0;
2204 dw += 2;
2205}
2206
2207static void gen6_meta_vf(struct intel_cmd *cmd)
2208{
2209 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002210 uint32_t vb_start, vb_end, vb_stride;
2211 int ve_format, ve_z_source;
2212 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002213 XGL_UINT pos;
2214
2215 CMD_ASSERT(cmd, 6, 7.5);
2216
Chia-I Wu29e6f502014-11-24 14:27:29 +08002217 switch (meta->mode) {
2218 case INTEL_CMD_META_VS_POINTS:
2219 cmd_batch_pointer(cmd, 3, &dw);
2220 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2221 dw[1] = GEN6_VE_STATE_DW0_VALID;
2222 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2223 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2224 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2225 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2226 return;
2227 break;
2228 case INTEL_CMD_META_FS_RECT:
2229 {
2230 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002231
Chia-I Wu29e6f502014-11-24 14:27:29 +08002232 vertices[0][0] = meta->dst.x + meta->width;
2233 vertices[0][1] = meta->dst.y + meta->height;
2234 vertices[1][0] = meta->dst.x;
2235 vertices[1][1] = meta->dst.y + meta->height;
2236 vertices[2][0] = meta->dst.x;
2237 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002238
Chia-I Wu29e6f502014-11-24 14:27:29 +08002239 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2240 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002241
Chia-I Wu29e6f502014-11-24 14:27:29 +08002242 vb_end = vb_start + sizeof(vertices) - 1;
2243 vb_stride = sizeof(vertices[0]);
2244 ve_z_source = GEN6_VFCOMP_STORE_0;
2245 ve_format = GEN6_FORMAT_R32G32_USCALED;
2246 }
2247 break;
2248 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2249 {
2250 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002251
Chia-I Wu29e6f502014-11-24 14:27:29 +08002252 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2253 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2254 vertices[0][2] = u_uif(meta->clear_val[0]);
2255 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2256 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2257 vertices[1][2] = u_uif(meta->clear_val[0]);
2258 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2259 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2260 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002261
Chia-I Wu29e6f502014-11-24 14:27:29 +08002262 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2263 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002264
Chia-I Wu29e6f502014-11-24 14:27:29 +08002265 vb_end = vb_start + sizeof(vertices) - 1;
2266 vb_stride = sizeof(vertices[0]);
2267 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2268 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2269 }
2270 break;
2271 default:
2272 assert(!"unknown meta mode");
2273 return;
2274 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002275 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002276
2277 /* 3DSTATE_VERTEX_BUFFERS */
2278 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002279
Chia-I Wu6032b892014-10-17 14:47:18 +08002280 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002281 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002282 if (cmd_gen(cmd) >= INTEL_GEN(7))
2283 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2284
2285 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002286 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2287 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002288
2289 dw[4] = 0;
2290
2291 /* 3DSTATE_VERTEX_ELEMENTS */
2292 cmd_batch_pointer(cmd, 5, &dw);
2293 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002294 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002295 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2296 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2297 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2298 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2299 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002300 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002301 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2302 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002303 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002304 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2305}
2306
Chia-I Wu29e6f502014-11-24 14:27:29 +08002307static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002308{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002309 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002310 /* one GPR */
2311 XGL_UINT consts[8];
2312 XGL_UINT const_count;
2313
2314 CMD_ASSERT(cmd, 6, 7.5);
2315
2316 switch (meta->shader_id) {
2317 default:
2318 assert(!"unknown meta shader id");
2319 const_count = 0;
2320 break;
2321 }
2322
2323 /* this can be skipped but it makes state dumping prettier */
2324 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2325
2326 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2327}
2328
2329static void gen6_meta_vs(struct intel_cmd *cmd)
2330{
2331 const struct intel_cmd_meta *meta = cmd->bind.meta;
2332 const struct intel_pipeline_shader *sh =
2333 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002334 const int max_threads = cmd_vs_max_threads(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002335 uint32_t offset, *dw;
2336
2337 CMD_ASSERT(cmd, 6, 7.5);
2338
2339 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2340 XGL_UINT cmd_len;
2341
2342 /* 3DSTATE_CONSTANT_VS */
2343 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2344 cmd_batch_pointer(cmd, cmd_len, &dw);
2345 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2346 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2347
2348 /* 3DSTATE_VS */
2349 cmd_batch_pointer(cmd, 6, &dw);
2350 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2351 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2352
2353 return;
2354 }
2355
2356 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2357
2358 /* 3DSTATE_CONSTANT_VS */
2359 offset = gen6_meta_vs_constants(cmd);
2360 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2361 cmd_batch_pointer(cmd, 7, &dw);
2362 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2363 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2364 dw[2] = 0;
2365 dw[3] = offset;
2366 dw[4] = 0;
2367 dw[5] = 0;
2368 dw[6] = 0;
2369 } else {
2370 cmd_batch_pointer(cmd, 5, &dw);
2371 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2372 GEN6_PCB_ANY_DW0_PCB0_VALID;
2373 dw[1] = offset;
2374 dw[2] = 0;
2375 dw[3] = 0;
2376 dw[4] = 0;
2377 }
2378
2379 /* 3DSTATE_VS */
2380 offset = emit_shader(cmd, sh);
2381 cmd_batch_pointer(cmd, 6, &dw);
2382 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2383 dw[1] = offset;
2384 dw[2] = GEN6_THREADDISP_SPF |
2385 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2386 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2387 dw[3] = 0;
2388 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2389 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2390
2391 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2392 GEN6_VS_DW5_VS_ENABLE;
2393 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu05990612014-11-25 11:36:35 +08002394 dw[5] |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002395 else
Chia-I Wu05990612014-11-25 11:36:35 +08002396 dw[5] |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002397}
2398
2399static void gen6_meta_disabled(struct intel_cmd *cmd)
2400{
Chia-I Wu6032b892014-10-17 14:47:18 +08002401 uint32_t *dw;
2402
2403 CMD_ASSERT(cmd, 6, 6);
2404
Chia-I Wu6032b892014-10-17 14:47:18 +08002405 /* 3DSTATE_CONSTANT_GS */
2406 cmd_batch_pointer(cmd, 5, &dw);
2407 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2408 dw[1] = 0;
2409 dw[2] = 0;
2410 dw[3] = 0;
2411 dw[4] = 0;
2412
2413 /* 3DSTATE_GS */
2414 cmd_batch_pointer(cmd, 7, &dw);
2415 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2416 dw[1] = 0;
2417 dw[2] = 0;
2418 dw[3] = 0;
2419 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2420 dw[5] = GEN6_GS_DW5_STATISTICS;
2421 dw[6] = 0;
2422
Chia-I Wu6032b892014-10-17 14:47:18 +08002423 /* 3DSTATE_SF */
2424 cmd_batch_pointer(cmd, 20, &dw);
2425 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2426 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2427 memset(&dw[2], 0, 18 * sizeof(*dw));
2428}
2429
2430static void gen7_meta_disabled(struct intel_cmd *cmd)
2431{
2432 uint32_t *dw;
2433
2434 CMD_ASSERT(cmd, 7, 7.5);
2435
Chia-I Wu6032b892014-10-17 14:47:18 +08002436 /* 3DSTATE_CONSTANT_HS */
2437 cmd_batch_pointer(cmd, 7, &dw);
2438 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2439 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2440
2441 /* 3DSTATE_HS */
2442 cmd_batch_pointer(cmd, 7, &dw);
2443 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2444 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2445
2446 /* 3DSTATE_TE */
2447 cmd_batch_pointer(cmd, 4, &dw);
2448 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2449 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2450
2451 /* 3DSTATE_CONSTANT_DS */
2452 cmd_batch_pointer(cmd, 7, &dw);
2453 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2454 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2455
2456 /* 3DSTATE_DS */
2457 cmd_batch_pointer(cmd, 6, &dw);
2458 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2459 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2460
2461 /* 3DSTATE_CONSTANT_GS */
2462 cmd_batch_pointer(cmd, 7, &dw);
2463 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2464 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2465
2466 /* 3DSTATE_GS */
2467 cmd_batch_pointer(cmd, 7, &dw);
2468 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2469 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2470
2471 /* 3DSTATE_STREAMOUT */
2472 cmd_batch_pointer(cmd, 3, &dw);
2473 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2474 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2475
Chia-I Wu6032b892014-10-17 14:47:18 +08002476 /* 3DSTATE_SF */
2477 cmd_batch_pointer(cmd, 7, &dw);
2478 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2479 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2480
2481 /* 3DSTATE_SBE */
2482 cmd_batch_pointer(cmd, 14, &dw);
2483 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2484 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2485 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002486}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002487
Chia-I Wu29e6f502014-11-24 14:27:29 +08002488static void gen6_meta_clip(struct intel_cmd *cmd)
2489{
2490 const struct intel_cmd_meta *meta = cmd->bind.meta;
2491 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002492
Chia-I Wu29e6f502014-11-24 14:27:29 +08002493 /* 3DSTATE_CLIP */
2494 cmd_batch_pointer(cmd, 4, &dw);
2495 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2496 dw[1] = 0;
2497 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2498 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2499 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2500 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002501 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002502 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002503 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002504}
2505
2506static void gen6_meta_wm(struct intel_cmd *cmd)
2507{
2508 const struct intel_cmd_meta *meta = cmd->bind.meta;
2509 uint32_t *dw;
2510
2511 CMD_ASSERT(cmd, 6, 7.5);
2512
2513 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2514
2515 /* 3DSTATE_MULTISAMPLE */
2516 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2517 cmd_batch_pointer(cmd, 4, &dw);
2518 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2519 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2520 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2521 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2522 dw[2] = 0;
2523 dw[3] = 0;
2524 } else {
2525 cmd_batch_pointer(cmd, 3, &dw);
2526 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2527 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2528 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2529 dw[2] = 0;
2530 }
2531
2532 /* 3DSTATE_SAMPLE_MASK */
2533 cmd_batch_pointer(cmd, 2, &dw);
2534 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2535 dw[1] = (1 << meta->samples) - 1;
2536
2537 /* 3DSTATE_DRAWING_RECTANGLE */
2538 cmd_batch_pointer(cmd, 4, &dw);
2539 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2540 dw[1] = meta->dst.y << 16 | meta->dst.x;
2541 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2542 (meta->dst.x + meta->width - 1);
2543 dw[3] = 0;
2544}
2545
2546static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2547{
2548 const struct intel_cmd_meta *meta = cmd->bind.meta;
2549 XGL_UINT offset_x, offset_y;
2550 /* one GPR */
2551 XGL_UINT consts[8];
2552 XGL_UINT const_count;
2553
2554 CMD_ASSERT(cmd, 6, 7.5);
2555
2556 /* underflow is fine here */
2557 offset_x = meta->src.x - meta->dst.x;
2558 offset_y = meta->src.y - meta->dst.y;
2559
2560 switch (meta->shader_id) {
2561 case INTEL_DEV_META_FS_COPY_MEM:
2562 case INTEL_DEV_META_FS_COPY_1D:
2563 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2564 case INTEL_DEV_META_FS_COPY_2D:
2565 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2566 case INTEL_DEV_META_FS_COPY_2D_MS:
2567 consts[0] = offset_x;
2568 consts[1] = offset_y;
2569 consts[2] = meta->src.layer;
2570 consts[3] = meta->src.lod;
2571 const_count = 4;
2572 break;
2573 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2574 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2575 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2576 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2577 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2578 consts[0] = offset_x;
2579 consts[1] = offset_y;
2580 consts[2] = meta->src.layer;
2581 consts[3] = meta->src.lod;
2582 consts[4] = meta->src.x;
2583 consts[5] = meta->width;
2584 const_count = 6;
2585 break;
2586 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2587 consts[0] = offset_x;
2588 consts[1] = offset_y;
2589 consts[2] = meta->width;
2590 const_count = 3;
2591 break;
2592 case INTEL_DEV_META_FS_CLEAR_COLOR:
2593 consts[0] = meta->clear_val[0];
2594 consts[1] = meta->clear_val[1];
2595 consts[2] = meta->clear_val[2];
2596 consts[3] = meta->clear_val[3];
2597 const_count = 4;
2598 break;
2599 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2600 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002601 consts[1] = meta->clear_val[1];
2602 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002603 break;
2604 case INTEL_DEV_META_FS_RESOLVE_2X:
2605 case INTEL_DEV_META_FS_RESOLVE_4X:
2606 case INTEL_DEV_META_FS_RESOLVE_8X:
2607 case INTEL_DEV_META_FS_RESOLVE_16X:
2608 consts[0] = offset_x;
2609 consts[1] = offset_y;
2610 const_count = 2;
2611 break;
2612 default:
2613 assert(!"unknown meta shader id");
2614 const_count = 0;
2615 break;
2616 }
2617
2618 /* this can be skipped but it makes state dumping prettier */
2619 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2620
2621 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2622}
2623
2624static void gen6_meta_ps(struct intel_cmd *cmd)
2625{
2626 const struct intel_cmd_meta *meta = cmd->bind.meta;
2627 const struct intel_pipeline_shader *sh =
2628 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002629 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002630 uint32_t offset, *dw;
2631
2632 CMD_ASSERT(cmd, 6, 6);
2633
Chia-I Wu29e6f502014-11-24 14:27:29 +08002634 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2635 /* 3DSTATE_CONSTANT_PS */
2636 cmd_batch_pointer(cmd, 5, &dw);
2637 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2638 dw[1] = 0;
2639 dw[2] = 0;
2640 dw[3] = 0;
2641 dw[4] = 0;
2642
2643 /* 3DSTATE_WM */
2644 cmd_batch_pointer(cmd, 9, &dw);
2645 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2646 dw[1] = 0;
2647 dw[2] = 0;
2648 dw[3] = 0;
2649 dw[4] = 0;
Chia-I Wu05990612014-11-25 11:36:35 +08002650 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002651 dw[6] = 0;
2652 dw[7] = 0;
2653 dw[8] = 0;
2654
Chia-I Wu3adf7212014-10-24 15:34:07 +08002655 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002656 }
2657
Chia-I Wu3adf7212014-10-24 15:34:07 +08002658 /* a normal color write */
2659 assert(meta->dst.valid && !sh->uses);
2660
Chia-I Wu6032b892014-10-17 14:47:18 +08002661 /* 3DSTATE_CONSTANT_PS */
2662 offset = gen6_meta_ps_constants(cmd);
2663 cmd_batch_pointer(cmd, 5, &dw);
2664 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2665 GEN6_PCB_ANY_DW0_PCB0_VALID;
2666 dw[1] = offset;
2667 dw[2] = 0;
2668 dw[3] = 0;
2669 dw[4] = 0;
2670
2671 /* 3DSTATE_WM */
2672 offset = emit_shader(cmd, sh);
2673 cmd_batch_pointer(cmd, 9, &dw);
2674 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2675 dw[1] = offset;
2676 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2677 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2678 dw[3] = 0;
2679 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002680 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002681 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002682 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2683
Chia-I Wu6032b892014-10-17 14:47:18 +08002684 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2685 GEN6_WM_DW6_POSOFFSET_NONE |
2686 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2687 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2688 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2689 if (meta->samples > 1) {
2690 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2691 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2692 } else {
2693 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2694 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2695 }
2696 dw[7] = 0;
2697 dw[8] = 0;
2698}
2699
2700static void gen7_meta_ps(struct intel_cmd *cmd)
2701{
2702 const struct intel_cmd_meta *meta = cmd->bind.meta;
2703 const struct intel_pipeline_shader *sh =
2704 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002705 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002706 uint32_t offset, *dw;
2707
2708 CMD_ASSERT(cmd, 7, 7.5);
2709
Chia-I Wu29e6f502014-11-24 14:27:29 +08002710 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2711 /* 3DSTATE_WM */
2712 cmd_batch_pointer(cmd, 3, &dw);
2713 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2714 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2715
2716 /* 3DSTATE_CONSTANT_GS */
2717 cmd_batch_pointer(cmd, 7, &dw);
2718 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2719 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2720
2721 /* 3DSTATE_PS */
2722 cmd_batch_pointer(cmd, 8, &dw);
2723 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2724 dw[1] = 0;
2725 dw[2] = 0;
2726 dw[3] = 0;
2727 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu05990612014-11-25 11:36:35 +08002728 (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002729 dw[5] = 0;
2730 dw[6] = 0;
2731 dw[7] = 0;
2732
Chia-I Wu3adf7212014-10-24 15:34:07 +08002733 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002734 }
2735
Chia-I Wu3adf7212014-10-24 15:34:07 +08002736 /* a normal color write */
2737 assert(meta->dst.valid && !sh->uses);
2738
Chia-I Wu6032b892014-10-17 14:47:18 +08002739 /* 3DSTATE_WM */
2740 cmd_batch_pointer(cmd, 3, &dw);
2741 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2742 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2743 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2744 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2745 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2746 dw[2] = 0;
2747
2748 /* 3DSTATE_CONSTANT_PS */
2749 offset = gen6_meta_ps_constants(cmd);
2750 cmd_batch_pointer(cmd, 7, &dw);
2751 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2752 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2753 dw[2] = 0;
2754 dw[3] = offset;
2755 dw[4] = 0;
2756 dw[5] = 0;
2757 dw[6] = 0;
2758
2759 /* 3DSTATE_PS */
2760 offset = emit_shader(cmd, sh);
2761 cmd_batch_pointer(cmd, 8, &dw);
2762 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2763 dw[1] = offset;
2764 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2765 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2766 dw[3] = 0;
2767
2768 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2769 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002770 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2771
2772 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2773 dw[4] |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002774 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002775 } else {
2776 dw[4] |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2777 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002778
2779 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2780 dw[6] = 0;
2781 dw[7] = 0;
2782}
2783
2784static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2785{
2786 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002787 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002788
2789 CMD_ASSERT(cmd, 6, 7.5);
2790
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002791 if (!ds) {
2792 /* all zeros */
2793 static const struct intel_ds_view null_ds;
2794 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002795 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002796
2797 cmd_wa_gen6_pre_ds_flush(cmd);
2798 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2799 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2800 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2801
2802 if (cmd_gen(cmd) >= INTEL_GEN(7))
2803 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2804 else
2805 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002806}
2807
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002808static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2809 const struct intel_pipeline *pipeline)
2810{
2811 cmd->bind.pipeline.graphics = pipeline;
2812}
2813
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002814static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2815 const struct intel_pipeline *pipeline)
2816{
2817 cmd->bind.pipeline.compute = pipeline;
2818}
2819
2820static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2821 const struct intel_pipeline_delta *delta)
2822{
2823 cmd->bind.pipeline.graphics_delta = delta;
2824}
2825
2826static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2827 const struct intel_pipeline_delta *delta)
2828{
2829 cmd->bind.pipeline.compute_delta = delta;
2830}
2831
2832static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2833 const struct intel_dset *dset,
2834 XGL_UINT slot_offset)
2835{
2836 cmd->bind.dset.graphics = dset;
2837 cmd->bind.dset.graphics_offset = slot_offset;
2838}
2839
2840static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2841 const struct intel_dset *dset,
2842 XGL_UINT slot_offset)
2843{
2844 cmd->bind.dset.compute = dset;
2845 cmd->bind.dset.compute_offset = slot_offset;
2846}
2847
2848static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2849 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2850{
2851 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2852}
2853
2854static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2855 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2856{
2857 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2858}
2859
Chia-I Wu3b04af52014-11-08 10:48:20 +08002860static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2861 const struct intel_mem *mem,
2862 XGL_GPU_SIZE offset, XGL_UINT binding)
2863{
2864 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2865 cmd->result = XGL_ERROR_UNKNOWN;
2866 return;
2867 }
2868
2869 cmd->bind.vertex.mem[binding] = mem;
2870 cmd->bind.vertex.offset[binding] = offset;
2871}
2872
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002873static void cmd_bind_index_data(struct intel_cmd *cmd,
2874 const struct intel_mem *mem,
2875 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2876{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002877 cmd->bind.index.mem = mem;
2878 cmd->bind.index.offset = offset;
2879 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002880}
2881
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002882static void cmd_bind_attachments(struct intel_cmd *cmd,
2883 XGL_UINT rt_count,
2884 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2885 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002886{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002887 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002888 XGL_UINT i;
2889
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002890 for (i = 0; i < rt_count; i++) {
2891 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002892 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002893 const struct intel_layout *layout = &rt->img->layout;
2894
2895 if (i == 0) {
2896 width = layout->width0;
2897 height = layout->height0;
2898 } else {
2899 if (width > layout->width0)
2900 width = layout->width0;
2901 if (height > layout->height0)
2902 height = layout->height0;
2903 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002904
2905 cmd->bind.att.rt[i] = rt;
2906 }
2907
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002908 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002909
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002910 if (ds_info) {
2911 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002912
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002913 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2914 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002915
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002916 if (width > layout->width0)
2917 width = layout->width0;
2918 if (height > layout->height0)
2919 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002920 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002921 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002922 }
2923
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002924 cmd->bind.att.width = width;
2925 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002926}
2927
2928static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2929 const struct intel_viewport_state *state)
2930{
2931 cmd->bind.state.viewport = state;
2932}
2933
2934static void cmd_bind_raster_state(struct intel_cmd *cmd,
2935 const struct intel_raster_state *state)
2936{
2937 cmd->bind.state.raster = state;
2938}
2939
2940static void cmd_bind_ds_state(struct intel_cmd *cmd,
2941 const struct intel_ds_state *state)
2942{
2943 cmd->bind.state.ds = state;
2944}
2945
2946static void cmd_bind_blend_state(struct intel_cmd *cmd,
2947 const struct intel_blend_state *state)
2948{
2949 cmd->bind.state.blend = state;
2950}
2951
2952static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2953 const struct intel_msaa_state *state)
2954{
2955 cmd->bind.state.msaa = state;
2956}
2957
2958static void cmd_draw(struct intel_cmd *cmd,
2959 XGL_UINT vertex_start,
2960 XGL_UINT vertex_count,
2961 XGL_UINT instance_start,
2962 XGL_UINT instance_count,
2963 bool indexed,
2964 XGL_UINT vertex_base)
2965{
2966 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2967
2968 emit_bounded_states(cmd);
2969
2970 if (indexed) {
2971 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2972 cmd->result = XGL_ERROR_UNKNOWN;
2973
2974 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2975 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2976 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002977 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2978 cmd->bind.index.offset, cmd->bind.index.type,
2979 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002980 } else {
2981 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2982 cmd->bind.index.offset, cmd->bind.index.type,
2983 p->primitive_restart);
2984 }
2985 } else {
2986 assert(!vertex_base);
2987 }
2988
2989 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2990 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2991 vertex_start, instance_count, instance_start, vertex_base);
2992 } else {
2993 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2994 vertex_start, instance_count, instance_start, vertex_base);
2995 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002996
Chia-I Wu707a29e2014-08-27 12:51:47 +08002997 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002998 /* need to re-emit all workarounds */
2999 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003000
3001 if (intel_debug & INTEL_DEBUG_NOCACHE)
3002 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003003}
3004
Chia-I Wuc14d1562014-10-17 09:49:22 +08003005void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3006{
Chia-I Wu6032b892014-10-17 14:47:18 +08003007 cmd->bind.meta = meta;
3008
3009 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003010 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003011
3012 gen6_meta_dynamic_states(cmd);
3013 gen6_meta_surface_states(cmd);
3014
3015 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3016 gen7_meta_urb(cmd);
3017 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003018 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003019 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003020 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003021 gen6_meta_wm(cmd);
3022 gen7_meta_ps(cmd);
3023 gen6_meta_depth_buffer(cmd);
3024
3025 cmd_wa_gen7_post_command_cs_stall(cmd);
3026 cmd_wa_gen7_post_command_depth_stall(cmd);
3027
Chia-I Wu29e6f502014-11-24 14:27:29 +08003028 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3029 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3030 meta->width, 0, 1, 0, 0);
3031 } else {
3032 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3033 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003034 } else {
3035 gen6_meta_urb(cmd);
3036 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003037 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003038 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003039 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003040 gen6_meta_wm(cmd);
3041 gen6_meta_ps(cmd);
3042 gen6_meta_depth_buffer(cmd);
3043
Chia-I Wu29e6f502014-11-24 14:27:29 +08003044 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3045 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3046 meta->width, 0, 1, 0, 0);
3047 } else {
3048 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3049 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003050 }
3051
3052 cmd->bind.draw_count++;
3053 /* need to re-emit all workarounds */
3054 cmd->bind.wa_flags = 0;
3055
3056 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003057
3058 if (intel_debug & INTEL_DEBUG_NOCACHE)
3059 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003060}
3061
Chia-I Wub2755562014-08-20 13:38:52 +08003062XGL_VOID XGLAPI intelCmdBindPipeline(
3063 XGL_CMD_BUFFER cmdBuffer,
3064 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3065 XGL_PIPELINE pipeline)
3066{
3067 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3068
3069 switch (pipelineBindPoint) {
3070 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003071 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003072 break;
3073 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003074 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003075 break;
3076 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003077 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003078 break;
3079 }
3080}
3081
3082XGL_VOID XGLAPI intelCmdBindPipelineDelta(
3083 XGL_CMD_BUFFER cmdBuffer,
3084 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3085 XGL_PIPELINE_DELTA delta)
3086{
3087 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3088
3089 switch (pipelineBindPoint) {
3090 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003091 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003092 break;
3093 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003094 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003095 break;
3096 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003097 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003098 break;
3099 }
3100}
3101
3102XGL_VOID XGLAPI intelCmdBindStateObject(
3103 XGL_CMD_BUFFER cmdBuffer,
3104 XGL_STATE_BIND_POINT stateBindPoint,
3105 XGL_STATE_OBJECT state)
3106{
3107 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3108
3109 switch (stateBindPoint) {
3110 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003111 cmd_bind_viewport_state(cmd,
3112 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003113 break;
3114 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003115 cmd_bind_raster_state(cmd,
3116 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003117 break;
3118 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003119 cmd_bind_ds_state(cmd,
3120 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003121 break;
3122 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003123 cmd_bind_blend_state(cmd,
3124 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003125 break;
3126 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003127 cmd_bind_msaa_state(cmd,
3128 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003129 break;
3130 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003131 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003132 break;
3133 }
3134}
3135
3136XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3137 XGL_CMD_BUFFER cmdBuffer,
3138 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3139 XGL_UINT index,
3140 XGL_DESCRIPTOR_SET descriptorSet,
3141 XGL_UINT slotOffset)
3142{
3143 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3144 struct intel_dset *dset = intel_dset(descriptorSet);
3145
3146 assert(!index);
3147
3148 switch (pipelineBindPoint) {
3149 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003150 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003151 break;
3152 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003153 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003154 break;
3155 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003156 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003157 break;
3158 }
3159}
3160
3161XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3162 XGL_CMD_BUFFER cmdBuffer,
3163 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3164 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3165{
3166 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3167
3168 switch (pipelineBindPoint) {
3169 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003170 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003171 break;
3172 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003173 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003174 break;
3175 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003176 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003177 break;
3178 }
3179}
3180
Chia-I Wu3b04af52014-11-08 10:48:20 +08003181XGL_VOID XGLAPI intelCmdBindVertexData(
3182 XGL_CMD_BUFFER cmdBuffer,
3183 XGL_GPU_MEMORY mem_,
3184 XGL_GPU_SIZE offset,
3185 XGL_UINT binding)
3186{
3187 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3188 struct intel_mem *mem = intel_mem(mem_);
3189
3190 cmd_bind_vertex_data(cmd, mem, offset, binding);
3191}
3192
Chia-I Wub2755562014-08-20 13:38:52 +08003193XGL_VOID XGLAPI intelCmdBindIndexData(
3194 XGL_CMD_BUFFER cmdBuffer,
3195 XGL_GPU_MEMORY mem_,
3196 XGL_GPU_SIZE offset,
3197 XGL_INDEX_TYPE indexType)
3198{
3199 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3200 struct intel_mem *mem = intel_mem(mem_);
3201
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003202 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003203}
3204
3205XGL_VOID XGLAPI intelCmdBindAttachments(
3206 XGL_CMD_BUFFER cmdBuffer,
3207 XGL_UINT colorAttachmentCount,
3208 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3209 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3210{
3211 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003212
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003213 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3214 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003215}
3216
3217XGL_VOID XGLAPI intelCmdDraw(
3218 XGL_CMD_BUFFER cmdBuffer,
3219 XGL_UINT firstVertex,
3220 XGL_UINT vertexCount,
3221 XGL_UINT firstInstance,
3222 XGL_UINT instanceCount)
3223{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003224 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003225
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003226 cmd_draw(cmd, firstVertex, vertexCount,
3227 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003228}
3229
3230XGL_VOID XGLAPI intelCmdDrawIndexed(
3231 XGL_CMD_BUFFER cmdBuffer,
3232 XGL_UINT firstIndex,
3233 XGL_UINT indexCount,
3234 XGL_INT vertexOffset,
3235 XGL_UINT firstInstance,
3236 XGL_UINT instanceCount)
3237{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003238 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003239
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003240 cmd_draw(cmd, firstIndex, indexCount,
3241 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003242}
3243
3244XGL_VOID XGLAPI intelCmdDrawIndirect(
3245 XGL_CMD_BUFFER cmdBuffer,
3246 XGL_GPU_MEMORY mem,
3247 XGL_GPU_SIZE offset,
3248 XGL_UINT32 count,
3249 XGL_UINT32 stride)
3250{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003251 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3252
3253 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003254}
3255
3256XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3257 XGL_CMD_BUFFER cmdBuffer,
3258 XGL_GPU_MEMORY mem,
3259 XGL_GPU_SIZE offset,
3260 XGL_UINT32 count,
3261 XGL_UINT32 stride)
3262{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003263 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3264
3265 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003266}
3267
3268XGL_VOID XGLAPI intelCmdDispatch(
3269 XGL_CMD_BUFFER cmdBuffer,
3270 XGL_UINT x,
3271 XGL_UINT y,
3272 XGL_UINT z)
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 intelCmdDispatchIndirect(
3280 XGL_CMD_BUFFER cmdBuffer,
3281 XGL_GPU_MEMORY mem,
3282 XGL_GPU_SIZE offset)
3283{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003284 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3285
3286 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003287}