blob: 94b7f69e2e11dfdba92ef9ee180d329581632fcb [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080030#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080031#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080032#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080033#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080034#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080035#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080036#include "state.h"
37#include "view.h"
38#include "cmd_priv.h"
39
Chia-I Wu59c097e2014-08-21 10:51:07 +080040static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080041 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080042 uint32_t vertex_count,
43 uint32_t vertex_start,
44 uint32_t instance_count,
45 uint32_t instance_start,
46 uint32_t vertex_base)
47{
48 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080049 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080050
51 CMD_ASSERT(cmd, 6, 6);
52
Chia-I Wu426072d2014-08-26 14:31:55 +080053 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080054 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080055 (cmd_len - 2);
56
57 if (indexed)
58 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
59
Chia-I Wu72292b72014-09-09 10:48:33 +080060 cmd_batch_pointer(cmd, cmd_len, &dw);
61 dw[0] = dw0;
62 dw[1] = vertex_count;
63 dw[2] = vertex_start;
64 dw[3] = instance_count;
65 dw[4] = instance_start;
66 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080067}
68
69static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080070 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080071 uint32_t vertex_count,
72 uint32_t vertex_start,
73 uint32_t instance_count,
74 uint32_t instance_start,
75 uint32_t vertex_base)
76{
77 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080078 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080079
80 CMD_ASSERT(cmd, 7, 7.5);
81
Chia-I Wu426072d2014-08-26 14:31:55 +080082 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080083 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080084
85 if (indexed)
86 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
87
Chia-I Wu72292b72014-09-09 10:48:33 +080088 cmd_batch_pointer(cmd, cmd_len, &dw);
89 dw[0] = dw0;
90 dw[1] = dw1;
91 dw[2] = vertex_count;
92 dw[3] = vertex_start;
93 dw[4] = instance_count;
94 dw[5] = instance_start;
95 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080096}
97
Chia-I Wu270b1e82014-08-25 15:53:39 +080098static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +080099 struct intel_bo *bo, uint32_t bo_offset,
100 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800101{
102 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800103 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800104 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800105 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800106 uint32_t *dw;
107 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800108
109 CMD_ASSERT(cmd, 6, 7.5);
110
111 assert(bo_offset % 8 == 0);
112
113 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
114 /*
115 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
116 *
117 * "1 of the following must also be set (when CS stall is set):
118 *
119 * * Depth Cache Flush Enable ([0] of DW1)
120 * * Stall at Pixel Scoreboard ([1] of DW1)
121 * * Depth Stall ([13] of DW1)
122 * * Post-Sync Operation ([13] of DW1)
123 * * Render Target Cache Flush Enable ([12] of DW1)
124 * * Notify Enable ([8] of DW1)"
125 *
126 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
127 *
128 * "One of the following must also be set (when CS stall is set):
129 *
130 * * Render Target Cache Flush Enable ([12] of DW1)
131 * * Depth Cache Flush Enable ([0] of DW1)
132 * * Stall at Pixel Scoreboard ([1] of DW1)
133 * * Depth Stall ([13] of DW1)
134 * * Post-Sync Operation ([13] of DW1)"
135 */
136 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
137 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
138 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
139 GEN6_PIPE_CONTROL_DEPTH_STALL;
140
141 /* post-sync op */
142 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
143 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
144 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
145
146 if (cmd_gen(cmd) == INTEL_GEN(6))
147 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
148
149 assert(dw1 & bit_test);
150 }
151
152 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
153 /*
154 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
155 *
156 * "Following bits must be clear (when Depth Stall is set):
157 *
158 * * Render Target Cache Flush Enable ([12] of DW1)
159 * * Depth Cache Flush Enable ([0] of DW1)"
160 */
161 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
162 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
163 }
164
165 /*
166 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
167 *
168 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
169 * and PIPE_CONTROL are not supported."
170 *
171 * The kernel will add the mapping automatically (when write domain is
172 * INTEL_DOMAIN_INSTRUCTION).
173 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800174 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800175 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 reloc_flags |= INTEL_RELOC_GGTT;
177 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800178
Chia-I Wu72292b72014-09-09 10:48:33 +0800179 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
180 dw[0] = dw0;
181 dw[1] = dw1;
182 dw[2] = 0;
183 dw[3] = (uint32_t) imm;
184 dw[4] = (uint32_t) (imm >> 32);
185
186 if (bo) {
187 cmd_reserve_reloc(cmd, 1);
188 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
189 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800190}
191
Chia-I Wu254db422014-08-21 11:54:29 +0800192static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
193{
194 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
195 bool supported;
196
197 CMD_ASSERT(cmd, 6, 7.5);
198
199 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
200 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
201
202 switch (p->prim_type) {
203 case GEN6_3DPRIM_POINTLIST:
204 case GEN6_3DPRIM_LINELIST:
205 case GEN6_3DPRIM_LINESTRIP:
206 case GEN6_3DPRIM_TRILIST:
207 case GEN6_3DPRIM_TRISTRIP:
208 supported = true;
209 break;
210 default:
211 supported = false;
212 break;
213 }
214
215 if (!supported)
216 return false;
217
218 switch (cmd->bind.index.type) {
219 case XGL_INDEX_8:
220 supported = (p->primitive_restart_index != 0xffu);
221 break;
222 case XGL_INDEX_16:
223 supported = (p->primitive_restart_index != 0xffffu);
224 break;
225 case XGL_INDEX_32:
226 supported = (p->primitive_restart_index != 0xffffffffu);
227 break;
228 default:
229 supported = false;
230 break;
231 }
232
233 return supported;
234}
235
Chia-I Wu59c097e2014-08-21 10:51:07 +0800236static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800237 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238 XGL_GPU_SIZE offset,
239 XGL_INDEX_TYPE type,
240 bool enable_cut_index)
241{
242 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800243 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800244 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246
247 CMD_ASSERT(cmd, 6, 7.5);
248
Chia-I Wu426072d2014-08-26 14:31:55 +0800249 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800250
251 /* the bit is moved to 3DSTATE_VF */
252 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
253 assert(!enable_cut_index);
254 if (enable_cut_index)
255 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
256
257 switch (type) {
258 case XGL_INDEX_8:
259 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
260 offset_align = 1;
261 break;
262 case XGL_INDEX_16:
263 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
264 offset_align = 2;
265 break;
266 case XGL_INDEX_32:
267 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
268 offset_align = 4;
269 break;
270 default:
271 cmd->result = XGL_ERROR_INVALID_VALUE;
272 return;
273 break;
274 }
275
276 if (offset % offset_align) {
277 cmd->result = XGL_ERROR_INVALID_VALUE;
278 return;
279 }
280
281 /* aligned and inclusive */
282 end_offset = mem->size - (mem->size % offset_align) - 1;
283
Chia-I Wu72292b72014-09-09 10:48:33 +0800284 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
285 dw[0] = dw0;
286
287 cmd_reserve_reloc(cmd, 2);
288 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
289 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800290}
291
Chia-I Wu62a7f252014-08-29 11:31:16 +0800292static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
293 bool enable_cut_index,
294 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800295{
296 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800297 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800298
299 CMD_ASSERT(cmd, 7.5, 7.5);
300
Chia-I Wu426072d2014-08-26 14:31:55 +0800301 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800302 if (enable_cut_index)
303 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
304
Chia-I Wu72292b72014-09-09 10:48:33 +0800305 cmd_batch_pointer(cmd, cmd_len, &dw);
306 dw[0] = dw0;
307 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800308}
309
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600310
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800311static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
312{
313 const uint8_t cmd_len = 7;
314 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800315 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800316
317 CMD_ASSERT(cmd, 6, 6);
318
Chia-I Wu72292b72014-09-09 10:48:33 +0800319 cmd_batch_pointer(cmd, cmd_len, &dw);
320 dw[0] = dw0;
321 dw[1] = 0;
322 dw[2] = 0;
323 dw[3] = 0;
324 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
325 dw[5] = GEN6_GS_DW5_STATISTICS;
326 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800327}
328
Chia-I Wu62a7f252014-08-29 11:31:16 +0800329static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
330{
331 const uint8_t cmd_len = 7;
332 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800333 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800334
335 CMD_ASSERT(cmd, 7, 7.5);
336
Chia-I Wu72292b72014-09-09 10:48:33 +0800337 cmd_batch_pointer(cmd, cmd_len, &dw);
338 dw[0] = dw0;
339 dw[1] = 0;
340 dw[2] = 0;
341 dw[3] = 0;
342 dw[4] = 0;
343 dw[5] = GEN6_GS_DW5_STATISTICS;
344 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800345}
346
Chia-I Wud88e02d2014-08-25 10:56:13 +0800347static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
348 XGL_UINT width, XGL_UINT height)
349{
350 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800351 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800352 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800353 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354
355 CMD_ASSERT(cmd, 6, 7.5);
356
Chia-I Wu72292b72014-09-09 10:48:33 +0800357 cmd_batch_pointer(cmd, cmd_len, &dw);
358 dw[0] = dw0;
359
Chia-I Wud88e02d2014-08-25 10:56:13 +0800360 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800361 dw[1] = 0;
362 dw[2] = (height - 1) << 16 |
363 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800364 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800365 dw[1] = 1;
366 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800367 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800368
369 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800370}
371
Chia-I Wu8016a172014-08-29 18:31:32 +0800372static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
373 uint32_t body[6])
374{
375 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
376 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
377 const struct intel_raster_state *raster = cmd->bind.state.raster;
378 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
389 raster->cmd_sf_fill;
390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
394 switch (pipeline->db_format.channelFormat) {
395 case XGL_CH_FMT_R16:
396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
398 case XGL_CH_FMT_R32:
399 case XGL_CH_FMT_R32G8:
400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
403 assert(!"unknown depth format");
404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
411 dw2 = raster->cmd_sf_cull;
412
413 if (msaa->sample_count > 1) {
414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
421 if (viewport->scissor_enable)
422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
425 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
438 body[3] = raster->cmd_depth_offset_const;
439 body[4] = raster->cmd_depth_offset_scale;
440 body[5] = raster->cmd_depth_offset_clamp;
441}
442
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800446 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
447 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448 XGL_UINT attr_skip, attr_count;
449 XGL_UINT vue_offset, vue_len;
450 XGL_UINT i;
451 uint32_t dw1;
452
453 CMD_ASSERT(cmd, 6, 7.5);
454
455 /* VS outputs VUE header and position additionally */
456 assert(vs->out_count >= 2);
457 attr_skip = 2;
458 attr_count = vs->out_count - attr_skip;
459 assert(fs->in_count == attr_count);
460 assert(fs->in_count <= 32);
461
462 vue_offset = attr_skip / 2;
463 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;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800550 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800551 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
552 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800553 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800554
555 CMD_ASSERT(cmd, 6, 7.5);
556
557 dw1 = GEN6_CLIP_DW1_STATISTICS;
558 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
559 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
560 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
561 raster->cmd_clip_cull;
562 }
563
564 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
565 GEN6_CLIP_DW2_XY_TEST_ENABLE |
566 GEN6_CLIP_DW2_APIMODE_OGL |
567 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
568 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
569 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
570
571 if (pipeline->rasterizerDiscardEnable)
572 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
573 else
574 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
575
576 if (pipeline->depthClipEnable)
577 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
578
579 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
580 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
581 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
582 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
583
584 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
585 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
586 (viewport->viewport_count - 1);
587
Chia-I Wu72292b72014-09-09 10:48:33 +0800588 cmd_batch_pointer(cmd, cmd_len, &dw);
589 dw[0] = dw0;
590 dw[1] = dw1;
591 dw[2] = dw2;
592 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800593}
594
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800595static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
596{
597 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
598 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800599 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800600 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
601 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800602 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800603
604 CMD_ASSERT(cmd, 6, 6);
605
606 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
607
608 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
609 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
610
611 dw4 = GEN6_WM_DW4_STATISTICS |
612 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
613 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
614 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
615
616 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
617 GEN6_WM_DW5_PS_ENABLE |
618 GEN6_WM_DW5_8_PIXEL_DISPATCH;
619
620 if (fs->uses & INTEL_SHADER_USE_KILL ||
621 pipeline->cb_state.alphaToCoverageEnable)
622 dw5 |= GEN6_WM_DW5_PS_KILL;
623
624 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
625 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
626 if (fs->uses & INTEL_SHADER_USE_DEPTH)
627 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
628 if (fs->uses & INTEL_SHADER_USE_W)
629 dw5 |= GEN6_WM_DW5_PS_USE_W;
630
631 if (pipeline->cb_state.dualSourceBlendEnable)
632 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
633
634 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
635 GEN6_WM_DW6_POSOFFSET_NONE |
636 GEN6_WM_DW6_ZW_INTERP_PIXEL |
637 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
638 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
639
640 if (msaa->sample_count > 1) {
641 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
642 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
643 } else {
644 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
645 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
646 }
647
Chia-I Wu72292b72014-09-09 10:48:33 +0800648 cmd_batch_pointer(cmd, cmd_len, &dw);
649 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800650 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800651 dw[2] = dw2;
652 dw[3] = 0; /* scratch */
653 dw[4] = dw4;
654 dw[5] = dw5;
655 dw[6] = dw6;
656 dw[7] = 0; /* kernel 1 */
657 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800658}
659
660static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
661{
662 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800663 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800664 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
665 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800666 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667
668 CMD_ASSERT(cmd, 7, 7.5);
669
670 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
671
672 dw1 = GEN7_WM_DW1_STATISTICS |
673 GEN7_WM_DW1_PS_ENABLE |
674 GEN7_WM_DW1_ZW_INTERP_PIXEL |
675 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
676 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
677
678 if (fs->uses & INTEL_SHADER_USE_KILL ||
679 pipeline->cb_state.alphaToCoverageEnable)
680 dw1 |= GEN7_WM_DW1_PS_KILL;
681
682 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
683 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
684 if (fs->uses & INTEL_SHADER_USE_DEPTH)
685 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
686 if (fs->uses & INTEL_SHADER_USE_W)
687 dw1 |= GEN7_WM_DW1_PS_USE_W;
688
689 dw2 = 0;
690
691 if (msaa->sample_count > 1) {
692 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
693 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
694 } else {
695 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
696 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
697 }
698
Chia-I Wu72292b72014-09-09 10:48:33 +0800699 cmd_batch_pointer(cmd, cmd_len, &dw);
700 dw[0] = dw0;
701 dw[1] = dw1;
702 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800703}
704
705static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
706{
707 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800708 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800709 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
710 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800711 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800712
713 CMD_ASSERT(cmd, 7, 7.5);
714
715 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
716
717 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
718 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
719
720 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
721 GEN7_PS_DW4_8_PIXEL_DISPATCH;
722
723 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
724 const int max_threads =
725 (cmd->dev->gpu->gt == 3) ? 408 :
726 (cmd->dev->gpu->gt == 2) ? 204 : 102;
727 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
728 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
729 } else {
730 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
731 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
732 }
733
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800734 if (fs->in_count)
735 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
736
737 if (pipeline->cb_state.dualSourceBlendEnable)
738 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
739
740 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
741 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
742 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
743
Chia-I Wu72292b72014-09-09 10:48:33 +0800744 cmd_batch_pointer(cmd, cmd_len, &dw);
745 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800746 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800747 dw[2] = dw2;
748 dw[3] = 0; /* scratch */
749 dw[4] = dw4;
750 dw[5] = dw5;
751 dw[6] = 0; /* kernel 1 */
752 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800753}
754
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800755static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
756 const struct intel_ds_view *view)
757{
758 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800759 uint32_t dw0, *dw;
760 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800761
762 CMD_ASSERT(cmd, 6, 7.5);
763
764 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800765 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
766 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767 dw0 |= (cmd_len - 2);
768
Chia-I Wu72292b72014-09-09 10:48:33 +0800769 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
770 dw[0] = dw0;
771 dw[1] = view->cmd[0];
772 dw[2] = 0;
773 dw[3] = view->cmd[2];
774 dw[4] = view->cmd[3];
775 dw[5] = view->cmd[4];
776 dw[6] = view->cmd[5];
777
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600778 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800779 cmd_reserve_reloc(cmd, 1);
780 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
781 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600782 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800783}
784
785static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
786 const struct intel_ds_view *view)
787{
788 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800789 uint32_t dw0, *dw;
790 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800791
792 CMD_ASSERT(cmd, 6, 7.5);
793
794 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800795 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
796 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797 dw0 |= (cmd_len - 2);
798
Chia-I Wu72292b72014-09-09 10:48:33 +0800799 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
800 dw[0] = dw0;
801 dw[1] = view->cmd[6];
802 dw[2] = 0;
803
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600804 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800805 cmd_reserve_reloc(cmd, 1);
806 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
807 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600808 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800809}
810
811static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
812 const struct intel_ds_view *view)
813{
814 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800815 uint32_t dw0, *dw;
816 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800817
818 CMD_ASSERT(cmd, 6, 7.5);
819
820 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800821 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
822 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800823 dw0 |= (cmd_len - 2);
824
Chia-I Wu72292b72014-09-09 10:48:33 +0800825 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
826 dw[0] = dw0;
827 dw[1] = view->cmd[8];
828 dw[2] = 0;
829
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600830 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800831 cmd_reserve_reloc(cmd, 1);
832 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
833 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600834 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800835}
836
Chia-I Wuf8231032014-08-25 10:44:45 +0800837static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
838 uint32_t clear_val)
839{
840 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800841 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800842 GEN6_CLEAR_PARAMS_DW0_VALID |
843 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800844 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800845
846 CMD_ASSERT(cmd, 6, 6);
847
Chia-I Wu72292b72014-09-09 10:48:33 +0800848 cmd_batch_pointer(cmd, cmd_len, &dw);
849 dw[0] = dw0;
850 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800851}
852
853static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
854 uint32_t clear_val)
855{
856 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800857 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800858 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800859 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800860
861 CMD_ASSERT(cmd, 7, 7.5);
862
Chia-I Wu72292b72014-09-09 10:48:33 +0800863 cmd_batch_pointer(cmd, cmd_len, &dw);
864 dw[0] = dw0;
865 dw[1] = clear_val;
866 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800867}
868
Chia-I Wu302742d2014-08-22 10:28:29 +0800869static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t blend_offset,
871 uint32_t ds_offset,
872 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800873{
874 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800876
877 CMD_ASSERT(cmd, 6, 6);
878
Chia-I Wu426072d2014-08-26 14:31:55 +0800879 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800880 (cmd_len - 2);
881
Chia-I Wu72292b72014-09-09 10:48:33 +0800882 cmd_batch_pointer(cmd, cmd_len, &dw);
883 dw[0] = dw0;
884 dw[1] = blend_offset | 1;
885 dw[2] = ds_offset | 1;
886 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800887}
888
Chia-I Wu1744cca2014-08-22 11:10:17 +0800889static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800890 uint32_t clip_offset,
891 uint32_t sf_offset,
892 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800893{
894 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800895 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896
897 CMD_ASSERT(cmd, 6, 6);
898
Chia-I Wu426072d2014-08-26 14:31:55 +0800899 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800900 GEN6_PTR_VP_DW0_CLIP_CHANGED |
901 GEN6_PTR_VP_DW0_SF_CHANGED |
902 GEN6_PTR_VP_DW0_CC_CHANGED |
903 (cmd_len - 2);
904
Chia-I Wu72292b72014-09-09 10:48:33 +0800905 cmd_batch_pointer(cmd, cmd_len, &dw);
906 dw[0] = dw0;
907 dw[1] = clip_offset;
908 dw[2] = sf_offset;
909 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800910}
911
912static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800913 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800914{
915 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800917
918 CMD_ASSERT(cmd, 6, 6);
919
Chia-I Wu426072d2014-08-26 14:31:55 +0800920 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800921 (cmd_len - 2);
922
Chia-I Wu72292b72014-09-09 10:48:33 +0800923 cmd_batch_pointer(cmd, cmd_len, &dw);
924 dw[0] = dw0;
925 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800926}
927
Chia-I Wu42a56202014-08-23 16:47:48 +0800928static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800929 uint32_t vs_offset,
930 uint32_t gs_offset,
931 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800932{
933 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800934 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800935
936 CMD_ASSERT(cmd, 6, 6);
937
Chia-I Wu426072d2014-08-26 14:31:55 +0800938 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800939 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
940 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
941 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
942 (cmd_len - 2);
943
Chia-I Wu72292b72014-09-09 10:48:33 +0800944 cmd_batch_pointer(cmd, cmd_len, &dw);
945 dw[0] = dw0;
946 dw[1] = vs_offset;
947 dw[2] = gs_offset;
948 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800949}
950
Chia-I Wu257e75e2014-08-29 14:06:35 +0800951static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800952 uint32_t vs_offset,
953 uint32_t gs_offset,
954 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800955{
956 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800958
959 CMD_ASSERT(cmd, 6, 6);
960
961 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
962 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
963 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
964 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
965 (cmd_len - 2);
966
Chia-I Wu72292b72014-09-09 10:48:33 +0800967 cmd_batch_pointer(cmd, cmd_len, &dw);
968 dw[0] = dw0;
969 dw[1] = vs_offset;
970 dw[2] = gs_offset;
971 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800972}
973
Chia-I Wu302742d2014-08-22 10:28:29 +0800974static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800975 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800976{
977 const uint8_t cmd_len = 2;
978 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
979 GEN6_RENDER_SUBTYPE_3D |
980 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800981 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800982
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 cmd_batch_pointer(cmd, cmd_len, &dw);
984 dw[0] = dw0;
985 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800986}
987
Chia-I Wu72292b72014-09-09 10:48:33 +0800988static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800989 const struct intel_blend_state *state)
990{
Chia-I Wu72292b72014-09-09 10:48:33 +0800991 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800992 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
993
994 CMD_ASSERT(cmd, 6, 7.5);
995 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
996
Chia-I Wu00b51a82014-09-09 12:07:37 +0800997 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
998 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +0800999}
1000
Chia-I Wu72292b72014-09-09 10:48:33 +08001001static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001002 const struct intel_ds_state *state)
1003{
Chia-I Wu72292b72014-09-09 10:48:33 +08001004 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001005 const uint8_t cmd_len = 3;
1006
1007 CMD_ASSERT(cmd, 6, 7.5);
1008 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1009
Chia-I Wu00b51a82014-09-09 12:07:37 +08001010 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1011 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001012}
1013
Chia-I Wu72292b72014-09-09 10:48:33 +08001014static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001015 uint32_t stencil_ref,
1016 const uint32_t blend_color[4])
1017{
Chia-I Wu72292b72014-09-09 10:48:33 +08001018 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001019 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001020 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001021
1022 CMD_ASSERT(cmd, 6, 7.5);
1023
Chia-I Wu00b51a82014-09-09 12:07:37 +08001024 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1025 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001026 dw[0] = stencil_ref;
1027 dw[1] = 0;
1028 dw[2] = blend_color[0];
1029 dw[3] = blend_color[1];
1030 dw[4] = blend_color[2];
1031 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001032
Chia-I Wu72292b72014-09-09 10:48:33 +08001033 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001034}
1035
Chia-I Wu8370b402014-08-29 12:28:37 +08001036static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001037{
Chia-I Wu8370b402014-08-29 12:28:37 +08001038 CMD_ASSERT(cmd, 6, 7.5);
1039
Chia-I Wu707a29e2014-08-27 12:51:47 +08001040 if (!cmd->bind.draw_count)
1041 return;
1042
Chia-I Wu8370b402014-08-29 12:28:37 +08001043 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001044 return;
1045
Chia-I Wu8370b402014-08-29 12:28:37 +08001046 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001047
1048 /*
1049 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1050 *
1051 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1052 * pipe-control with a post-sync op and no write-cache flushes."
1053 *
1054 * The workaround below necessitates this workaround.
1055 */
1056 gen6_PIPE_CONTROL(cmd,
1057 GEN6_PIPE_CONTROL_CS_STALL |
1058 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001059 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001060
Chia-I Wud6d079d2014-08-31 13:14:21 +08001061 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1062 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001063}
1064
Chia-I Wu8370b402014-08-29 12:28:37 +08001065static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001066{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001067 CMD_ASSERT(cmd, 6, 7.5);
1068
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001069 if (!cmd->bind.draw_count)
1070 return;
1071
Chia-I Wud6d079d2014-08-31 13:14:21 +08001072 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1073 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001074}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1077{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001078 CMD_ASSERT(cmd, 7, 7.5);
1079
Chia-I Wu8370b402014-08-29 12:28:37 +08001080 if (!cmd->bind.draw_count)
1081 return;
1082
1083 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001084
1085 gen6_PIPE_CONTROL(cmd,
1086 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001087 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001088}
1089
Chia-I Wu8370b402014-08-29 12:28:37 +08001090static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1091{
1092 CMD_ASSERT(cmd, 7, 7.5);
1093
1094 if (!cmd->bind.draw_count)
1095 return;
1096
1097 /*
1098 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1099 *
1100 * "One of the following must also be set (when CS stall is set):
1101 *
1102 * * Render Target Cache Flush Enable ([12] of DW1)
1103 * * Depth Cache Flush Enable ([0] of DW1)
1104 * * Stall at Pixel Scoreboard ([1] of DW1)
1105 * * Depth Stall ([13] of DW1)
1106 * * Post-Sync Operation ([13] of DW1)"
1107 */
1108 gen6_PIPE_CONTROL(cmd,
1109 GEN6_PIPE_CONTROL_CS_STALL |
1110 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001111 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001112}
1113
1114static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1115{
1116 CMD_ASSERT(cmd, 7, 7.5);
1117
1118 if (!cmd->bind.draw_count)
1119 return;
1120
1121 cmd_wa_gen6_pre_depth_stall_write(cmd);
1122
Chia-I Wud6d079d2014-08-31 13:14:21 +08001123 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001124}
1125
1126static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1127{
1128 CMD_ASSERT(cmd, 6, 7.5);
1129
1130 if (!cmd->bind.draw_count)
1131 return;
1132
1133 /*
1134 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1135 *
1136 * "Driver must guarentee that all the caches in the depth pipe are
1137 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1138 * requires driver to send a PIPE_CONTROL with a CS stall along with
1139 * a Depth Flush prior to this command."
1140 *
1141 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1142 *
1143 * "Driver must ierarchi that all the caches in the depth pipe are
1144 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1145 * requires driver to send a PIPE_CONTROL with a CS stall along with
1146 * a Depth Flush prior to this command.
1147 */
1148 gen6_PIPE_CONTROL(cmd,
1149 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1150 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001151 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001152}
1153
1154static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1155{
1156 CMD_ASSERT(cmd, 6, 7.5);
1157
1158 if (!cmd->bind.draw_count)
1159 return;
1160
1161 /*
1162 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1163 *
1164 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1165 * and a post sync operation prior to the group of depth
1166 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1167 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1168 *
1169 * This workaround satifies all the conditions.
1170 */
1171 cmd_wa_gen6_pre_depth_stall_write(cmd);
1172
1173 /*
1174 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1175 *
1176 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1177 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1178 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1179 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1180 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1181 * Depth Flush Bit set, followed by another pipelined depth stall
1182 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1183 * guarantee that the pipeline from WM onwards is already flushed
1184 * (e.g., via a preceding MI_FLUSH)."
1185 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001186 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1187 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1188 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001189}
1190
Chia-I Wu525c6602014-08-27 10:22:34 +08001191void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1192{
1193 if (!cmd->bind.draw_count)
1194 return;
1195
1196 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1197
Chia-I Wu8370b402014-08-29 12:28:37 +08001198 /*
1199 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1200 *
1201 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1202 * PIPE_CONTROL with any non-zero post-sync-op is required."
1203 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001204 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001205 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001206
Chia-I Wu092279a2014-08-30 19:05:30 +08001207 /*
1208 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1209 *
1210 * "One of the following must also be set (when CS stall is set):
1211 *
1212 * * Render Target Cache Flush Enable ([12] of DW1)
1213 * * Depth Cache Flush Enable ([0] of DW1)
1214 * * Stall at Pixel Scoreboard ([1] of DW1)
1215 * * Depth Stall ([13] of DW1)
1216 * * Post-Sync Operation ([13] of DW1)"
1217 */
1218 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1219 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1220 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1221 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1222 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1223 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1224
Chia-I Wud6d079d2014-08-31 13:14:21 +08001225 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001226}
1227
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001228void cmd_batch_depth_count(struct intel_cmd *cmd,
1229 struct intel_bo *bo,
1230 XGL_GPU_SIZE offset)
1231{
1232 cmd_wa_gen6_pre_depth_stall_write(cmd);
1233
1234 gen6_PIPE_CONTROL(cmd,
1235 GEN6_PIPE_CONTROL_DEPTH_STALL |
1236 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001237 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001238}
1239
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001240void cmd_batch_timestamp(struct intel_cmd *cmd,
1241 struct intel_bo *bo,
1242 XGL_GPU_SIZE offset)
1243{
1244 /* need any WA or stall? */
1245 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1246}
1247
1248void cmd_batch_immediate(struct intel_cmd *cmd,
1249 struct intel_bo *bo,
1250 XGL_GPU_SIZE offset,
1251 uint64_t val)
1252{
1253 /* need any WA or stall? */
1254 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1255}
1256
Chia-I Wu302742d2014-08-22 10:28:29 +08001257static void gen6_cc_states(struct intel_cmd *cmd)
1258{
1259 const struct intel_blend_state *blend = cmd->bind.state.blend;
1260 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001261 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001262 uint32_t stencil_ref;
1263 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001264
1265 CMD_ASSERT(cmd, 6, 6);
1266
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001267 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001268 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001269 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1270 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001271 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001272 memset(blend_color, 0, sizeof(blend_color));
1273 }
1274
1275 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001276 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001277 stencil_ref = ds->cmd_stencil_ref;
1278 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001279 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001280 stencil_ref = 0;
1281 }
1282
Chia-I Wu72292b72014-09-09 10:48:33 +08001283 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001284
Chia-I Wu72292b72014-09-09 10:48:33 +08001285 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001286}
1287
Chia-I Wu1744cca2014-08-22 11:10:17 +08001288static void gen6_viewport_states(struct intel_cmd *cmd)
1289{
1290 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001291 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001292
1293 if (!viewport)
1294 return;
1295
Chia-I Wub1d450a2014-09-09 13:48:03 +08001296 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1297 viewport->viewport_count);
1298
1299 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1300 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1301 viewport->cmd);
1302
1303 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1304 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1305 &viewport->cmd[viewport->cmd_clip_pos]);
1306
1307 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1308 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1309 &viewport->cmd[viewport->cmd_cc_pos]);
1310
1311 if (viewport->scissor_enable) {
1312 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1313 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1314 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1315 } else {
1316 scissor_offset = 0;
1317 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001318
1319 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001320 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001321
Chia-I Wub1d450a2014-09-09 13:48:03 +08001322 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001323}
1324
Chia-I Wu302742d2014-08-22 10:28:29 +08001325static void gen7_cc_states(struct intel_cmd *cmd)
1326{
1327 const struct intel_blend_state *blend = cmd->bind.state.blend;
1328 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001329 uint32_t stencil_ref;
1330 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001331 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001332
1333 CMD_ASSERT(cmd, 7, 7.5);
1334
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001335 if (!blend && !ds)
1336 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001337
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001338 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001339 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001340 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001341 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001342
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001343 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1344 } else {
1345 memset(blend_color, 0, sizeof(blend_color));
1346 }
1347
1348 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001349 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001350 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001351 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1352 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001353 } else {
1354 stencil_ref = 0;
1355 }
1356
Chia-I Wu72292b72014-09-09 10:48:33 +08001357 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001358 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001359 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001360}
1361
Chia-I Wu1744cca2014-08-22 11:10:17 +08001362static void gen7_viewport_states(struct intel_cmd *cmd)
1363{
1364 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001365 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001366
1367 if (!viewport)
1368 return;
1369
Chia-I Wub1d450a2014-09-09 13:48:03 +08001370 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1371 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001372
Chia-I Wub1d450a2014-09-09 13:48:03 +08001373 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1374 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1375 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001376 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001377 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1378 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001379
1380 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1381 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1382 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001383 gen7_3dstate_pointer(cmd,
1384 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001385 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001386
Chia-I Wu1744cca2014-08-22 11:10:17 +08001387 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001388 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1389 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1390 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001391 gen7_3dstate_pointer(cmd,
1392 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001393 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001394 }
1395}
1396
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001397static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001398 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001399{
1400 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001401 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001402
Chia-I Wu72292b72014-09-09 10:48:33 +08001403 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001404
1405 dw[0] = GEN6_RENDER_TYPE_RENDER |
1406 GEN6_RENDER_SUBTYPE_3D |
1407 subop | (cmd_len - 2);
1408 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001409 dw[2] = 0;
1410 dw[3] = 0;
1411 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001412}
1413
1414static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001415 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001416{
1417 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001418 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001419
Chia-I Wu72292b72014-09-09 10:48:33 +08001420 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001421
1422 dw[0] = GEN6_RENDER_TYPE_RENDER |
1423 GEN6_RENDER_SUBTYPE_3D |
1424 subop | (cmd_len - 2);
1425 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001426 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001427 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001428 dw[4] = 0;
1429 dw[5] = 0;
1430 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001431}
1432
Chia-I Wu625105f2014-10-13 15:35:29 +08001433static uint32_t emit_samplers(struct intel_cmd *cmd,
1434 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001435{
1436 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1437 const XGL_UINT border_stride =
1438 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001439 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001440 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001441 XGL_UINT i;
1442
1443 CMD_ASSERT(cmd, 6, 7.5);
1444
Chia-I Wu625105f2014-10-13 15:35:29 +08001445 if (!rmap || !rmap->sampler_count)
1446 return 0;
1447
1448 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1449
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001450 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1451 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1452 border_stride * rmap->sampler_count, &border_dw);
1453
1454 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1455 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1456 4 * rmap->sampler_count, &sampler_dw);
1457
1458 for (i = 0; i < rmap->sampler_count; i++) {
1459 const struct intel_pipeline_rmap_slot *slot =
1460 &rmap->slots[surface_count + i];
1461 const struct intel_sampler *sampler;
1462
1463 switch (slot->path_len) {
1464 case 0:
1465 sampler = NULL;
1466 break;
1467 case INTEL_PIPELINE_RMAP_SLOT_RT:
1468 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1469 assert(!"unexpected rmap slot type");
1470 sampler = NULL;
1471 break;
1472 case 1:
1473 {
1474 const struct intel_dset *dset = cmd->bind.dset.graphics;
1475 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1476 const struct intel_dset_slot *dset_slot =
1477 &dset->slots[slot_offset + slot->u.index];
1478
1479 switch (dset_slot->type) {
1480 case INTEL_DSET_SLOT_SAMPLER:
1481 sampler = dset_slot->u.sampler;
1482 break;
1483 default:
1484 assert(!"unexpected dset slot type");
1485 sampler = NULL;
1486 break;
1487 }
1488 }
1489 break;
1490 default:
1491 assert(!"nested descriptor set unsupported");
1492 sampler = NULL;
1493 break;
1494 }
1495
1496 if (sampler) {
1497 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1498
1499 sampler_dw[0] = sampler->cmd[0];
1500 sampler_dw[1] = sampler->cmd[1];
1501 sampler_dw[2] = border_offset;
1502 sampler_dw[3] = sampler->cmd[2];
1503 } else {
1504 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1505 sampler_dw[1] = 0;
1506 sampler_dw[2] = 0;
1507 sampler_dw[3] = 0;
1508 }
1509
1510 border_offset += border_stride * 4;
1511 border_dw += border_stride;
1512 sampler_dw += 4;
1513 }
1514
Chia-I Wu625105f2014-10-13 15:35:29 +08001515 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001516}
1517
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001518static uint32_t emit_binding_table(struct intel_cmd *cmd,
1519 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001520{
Chia-I Wu72292b72014-09-09 10:48:33 +08001521 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001522 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001523
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001524 CMD_ASSERT(cmd, 6, 7.5);
1525
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001526 surface_count = (rmap) ?
1527 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1528 if (!surface_count)
1529 return 0;
1530
Chia-I Wu42a56202014-08-23 16:47:48 +08001531 assert(surface_count <= ARRAY_SIZE(binding_table));
1532
1533 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001534 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001535
1536 switch (slot->path_len) {
1537 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001538 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001539 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001540 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001541 {
1542 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1543
Chia-I Wu00b51a82014-09-09 12:07:37 +08001544 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1546 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001547
Chia-I Wu72292b72014-09-09 10:48:33 +08001548 cmd_reserve_reloc(cmd, 1);
1549 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1550 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001551 }
1552 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001553 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001554 {
1555 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001556 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001557
Chia-I Wu00b51a82014-09-09 12:07:37 +08001558 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001559 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1560 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001561
Chia-I Wu72292b72014-09-09 10:48:33 +08001562 cmd_reserve_reloc(cmd, 1);
1563 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1564 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001565 }
1566 break;
1567 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001568 {
1569 const struct intel_dset *dset = cmd->bind.dset.graphics;
1570 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1571 const struct intel_dset_slot *dset_slot =
1572 &dset->slots[slot_offset + slot->u.index];
1573
1574 switch (dset_slot->type) {
1575 case INTEL_DSET_SLOT_IMG_VIEW:
1576 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1577 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1578 dset_slot->u.img_view->cmd_len,
1579 dset_slot->u.img_view->cmd);
1580
1581 cmd_reserve_reloc(cmd, 1);
1582 cmd_surface_reloc(cmd, offset, 1,
1583 dset_slot->u.img_view->img->obj.mem->bo,
1584 dset_slot->u.img_view->cmd[1], 0);
1585 break;
1586 case INTEL_DSET_SLOT_MEM_VIEW:
1587 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1588 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1589 dset_slot->u.mem_view.cmd_len,
1590 dset_slot->u.mem_view.cmd);
1591
1592 cmd_reserve_reloc(cmd, 1);
1593 cmd_surface_reloc(cmd, offset, 1,
1594 dset_slot->u.mem_view.mem->bo,
1595 dset_slot->u.mem_view.cmd[1], 0);
1596 break;
1597 default:
1598 assert(!"unexpected dset slot type");
1599 break;
1600 }
1601 }
1602 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001603 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001604 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001605 break;
1606 }
1607
Chia-I Wu72292b72014-09-09 10:48:33 +08001608 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001609 }
1610
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001611 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001612 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001613 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001614}
1615
Chia-I Wu1d125092014-10-08 08:49:38 +08001616static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1617{
1618 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1619 const struct intel_pipeline_rmap *rmap = pipeline->vs.rmap;
1620 const struct intel_dset *dset = cmd->bind.dset.graphics;
1621 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1622 uint32_t *dw;
1623 XGL_UINT pos, i;
1624
1625 CMD_ASSERT(cmd, 6, 7.5);
1626
1627 if (!pipeline->vb_count)
1628 return;
1629
1630 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1631
1632 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1633 dw++;
1634 pos++;
1635
1636 for (i = 0; i < pipeline->vb_count; i++) {
1637 const XGL_UINT vb_offset = rmap->rt_count + rmap->resource_count +
1638 rmap->uav_count + rmap->sampler_count;
1639 const struct intel_pipeline_rmap_slot *slot = (i < rmap->vb_count) ?
1640 &rmap->slots[vb_offset + i] : NULL;
1641 struct intel_mem_view *view = NULL;
1642
1643 if (slot) {
1644 switch (slot->path_len) {
1645 case 1:
1646 view = (dset->slots[slot->u.index].type ==
1647 INTEL_DSET_SLOT_MEM_VIEW) ?
1648 &dset->slots[slot->u.index].u.mem_view : NULL;
1649 break;
1650 default:
1651 break;
1652 }
1653 }
1654
1655 assert(pipeline->vb[i].strideInBytes <= 2048);
1656
1657 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1658 pipeline->vb[i].strideInBytes;
1659
1660 if (cmd_gen(cmd) >= INTEL_GEN(7))
1661 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1662
1663 switch (pipeline->vb[i].stepRate) {
1664 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1665 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1666 dw[3] = 0;
1667 break;
1668 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1669 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1670 dw[3] = 1;
1671 break;
1672 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1673 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1674 dw[3] = 0;
1675 break;
1676 default:
1677 assert(!"unknown step rate");
1678 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1679 dw[3] = 0;
1680 break;
1681 }
1682
1683 if (view) {
1684 const uint32_t begin = view->cmd[1];
1685 const uint32_t end = view->mem->size - 1;
1686
1687 cmd_reserve_reloc(cmd, 2);
1688 cmd_batch_reloc(cmd, pos + 1, view->mem->bo, begin, 0);
1689 cmd_batch_reloc(cmd, pos + 2, view->mem->bo, end, 0);
1690 } else {
1691 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1692 dw[1] = 0;
1693 dw[2] = 0;
1694 }
1695
1696 dw += 4;
1697 pos += 4;
1698 }
1699}
1700
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001701static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1702{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001703 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1704 const struct intel_pipeline_shader *vs = &pipeline->vs;
1705 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001706 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001707 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001708 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001709
1710 CMD_ASSERT(cmd, 6, 7.5);
1711
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001712 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001713 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1714 *
1715 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1716 * 128-bit vertex elements to be passed into the payload for each
1717 * vertex."
1718 *
1719 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1720 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001721 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001722 vue_read_len = (vs->in_count + 1) / 2;
1723 if (!vue_read_len)
1724 vue_read_len = 1;
1725
1726 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1727 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1728
1729 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1730 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1731 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001732
1733 dw5 = GEN6_VS_DW5_STATISTICS |
1734 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001735
1736 switch (cmd_gen(cmd)) {
1737 case INTEL_GEN(7.5):
1738 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1739 break;
1740 case INTEL_GEN(7):
1741 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1742 break;
1743 case INTEL_GEN(6):
1744 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1745 break;
1746 default:
1747 max_threads = 1;
1748 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001749 }
1750
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001751 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1752 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1753 else
1754 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1755
Chia-I Wube0a3d92014-09-02 13:20:59 +08001756 if (pipeline->disable_vs_cache)
1757 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1758
Chia-I Wu72292b72014-09-09 10:48:33 +08001759 cmd_batch_pointer(cmd, cmd_len, &dw);
1760 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001761 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001762 dw[2] = dw2;
1763 dw[3] = 0; /* scratch */
1764 dw[4] = dw4;
1765 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001766}
1767
Chia-I Wu625105f2014-10-13 15:35:29 +08001768static void emit_shader_resources(struct intel_cmd *cmd)
1769{
1770 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001771 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001772
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001773 binding_tables[0] = emit_binding_table(cmd,
1774 cmd->bind.pipeline.graphics->vs.rmap);
1775 binding_tables[1] = emit_binding_table(cmd,
1776 cmd->bind.pipeline.graphics->tcs.rmap);
1777 binding_tables[2] = emit_binding_table(cmd,
1778 cmd->bind.pipeline.graphics->tes.rmap);
1779 binding_tables[3] = emit_binding_table(cmd,
1780 cmd->bind.pipeline.graphics->gs.rmap);
1781 binding_tables[4] = emit_binding_table(cmd,
1782 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001783
1784 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1785 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1786 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1787 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1788 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1789
1790 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1791 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001792 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1793 binding_tables[0]);
1794 gen7_3dstate_pointer(cmd,
1795 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1796 binding_tables[1]);
1797 gen7_3dstate_pointer(cmd,
1798 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1799 binding_tables[2]);
1800 gen7_3dstate_pointer(cmd,
1801 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1802 binding_tables[3]);
1803 gen7_3dstate_pointer(cmd,
1804 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1805 binding_tables[4]);
1806
1807 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001808 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1809 samplers[0]);
1810 gen7_3dstate_pointer(cmd,
1811 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1812 samplers[1]);
1813 gen7_3dstate_pointer(cmd,
1814 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1815 samplers[2]);
1816 gen7_3dstate_pointer(cmd,
1817 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1818 samplers[3]);
1819 gen7_3dstate_pointer(cmd,
1820 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1821 samplers[4]);
1822 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001823 assert(!binding_tables[1] && !binding_tables[2]);
1824 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1825 binding_tables[0], binding_tables[3], binding_tables[4]);
1826
Chia-I Wu625105f2014-10-13 15:35:29 +08001827 assert(!samplers[1] && !samplers[2]);
1828 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1829 samplers[0], samplers[3], samplers[4]);
1830 }
1831}
1832
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001833static void emit_rt(struct intel_cmd *cmd)
1834{
1835 cmd_wa_gen6_pre_depth_stall_write(cmd);
1836 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1837 cmd->bind.att.height);
1838}
1839
1840static void emit_ds(struct intel_cmd *cmd)
1841{
1842 const struct intel_ds_view *ds = cmd->bind.att.ds;
1843
1844 if (!ds) {
1845 /* all zeros */
1846 static const struct intel_ds_view null_ds;
1847 ds = &null_ds;
1848 }
1849
1850 cmd_wa_gen6_pre_ds_flush(cmd);
1851 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1852 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1853 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1854
1855 if (cmd_gen(cmd) >= INTEL_GEN(7))
1856 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1857 else
1858 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1859}
1860
Chia-I Wua57761b2014-10-14 14:27:44 +08001861static uint32_t emit_shader(struct intel_cmd *cmd,
1862 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001863{
Chia-I Wua57761b2014-10-14 14:27:44 +08001864 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1865 uint32_t offset;
1866 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001867
Chia-I Wua57761b2014-10-14 14:27:44 +08001868 /* see if the shader is already in the cache */
1869 for (i = 0; i < cache->used; i++) {
1870 if (cache->entries[i].shader == (const void *) shader)
1871 return cache->entries[i].kernel_offset;
1872 }
1873
1874 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1875
1876 /* grow the cache if full */
1877 if (cache->used >= cache->count) {
1878 const XGL_UINT count = cache->count + 16;
1879 void *entries;
1880
1881 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1882 XGL_SYSTEM_ALLOC_INTERNAL);
1883 if (entries) {
1884 if (cache->entries) {
1885 memcpy(entries, cache->entries,
1886 sizeof(cache->entries[0]) * cache->used);
1887 icd_free(cache->entries);
1888 }
1889
1890 cache->entries = entries;
1891 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001892 }
1893 }
1894
Chia-I Wua57761b2014-10-14 14:27:44 +08001895 /* add the shader to the cache */
1896 if (cache->used < cache->count) {
1897 cache->entries[cache->used].shader = (const void *) shader;
1898 cache->entries[cache->used].kernel_offset = offset;
1899 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001900 }
1901
Chia-I Wua57761b2014-10-14 14:27:44 +08001902 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001903}
1904
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001905static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001906{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001907 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001908
Chia-I Wu8370b402014-08-29 12:28:37 +08001909 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1910 cmd_wa_gen6_pre_depth_stall_write(cmd);
1911 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1912 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1913 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1914 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001915
1916 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001917 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001918 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001919
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001920 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001921 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001922 }
1923 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001924 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001925 }
1926 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001927 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1928 }
1929 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1930 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1931 }
1932 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1933 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001934 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001935
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001936 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1937 gen7_3DSTATE_GS(cmd);
1938 } else {
1939 gen6_3DSTATE_GS(cmd);
1940 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001941
Chia-I Wu8370b402014-08-29 12:28:37 +08001942 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1943 cmd_wa_gen7_post_command_cs_stall(cmd);
1944 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1945 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001946}
1947
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001948static void emit_bounded_states(struct intel_cmd *cmd)
1949{
1950 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1951
1952 emit_graphics_pipeline(cmd);
1953
1954 emit_rt(cmd);
1955 emit_ds(cmd);
1956
1957 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1958 gen7_cc_states(cmd);
1959 gen7_viewport_states(cmd);
1960
1961 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1962 &cmd->bind.pipeline.graphics->vs);
1963 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1964 &cmd->bind.pipeline.graphics->fs);
1965
1966 gen6_3DSTATE_CLIP(cmd);
1967 gen7_3DSTATE_SF(cmd);
1968 gen7_3DSTATE_SBE(cmd);
1969 gen7_3DSTATE_WM(cmd);
1970 gen7_3DSTATE_PS(cmd);
1971 } else {
1972 gen6_cc_states(cmd);
1973 gen6_viewport_states(cmd);
1974
1975 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1976 &cmd->bind.pipeline.graphics->vs);
1977 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1978 &cmd->bind.pipeline.graphics->fs);
1979
1980 gen6_3DSTATE_CLIP(cmd);
1981 gen6_3DSTATE_SF(cmd);
1982 gen6_3DSTATE_WM(cmd);
1983 }
1984
1985 emit_shader_resources(cmd);
1986
1987 cmd_wa_gen6_pre_depth_stall_write(cmd);
1988 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1989
1990 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
1991 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
1992
1993 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1994 gen6_3DSTATE_VS(cmd);
1995}
1996
Chia-I Wu6032b892014-10-17 14:47:18 +08001997static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
1998{
1999 const struct intel_cmd_meta *meta = cmd->bind.meta;
2000 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2001
2002 CMD_ASSERT(cmd, 6, 7.5);
2003
2004 blend_offset = 0;
2005 ds_offset = 0;
2006 cc_offset = 0;
2007 cc_vp_offset = 0;
2008
2009 if (meta->dst.valid) {
2010 /* BLEND_STATE */
2011 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
2012 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2013 dw[0] = 0;
2014 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2015 }
2016
2017 if (meta->ds) {
2018 assert(!"depth/stencil clear unsupported");
2019
2020 /* DEPTH_STENCIL_STATE */
2021 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2022 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4, 3, &dw);
2023 dw[0] = 0;
2024 dw[1] = 0;
2025 dw[2] = 0;
2026
2027 /* COLOR_CALC_STATE */
2028 cc_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
2029 GEN6_ALIGNMENT_COLOR_CALC_STATE * 4, 6, &dw);
2030 dw[0] = 0;
2031 dw[1] = 0;
2032 dw[2] = 0;
2033 dw[3] = 0;
2034 dw[4] = 0;
2035 dw[5] = 0;
2036
2037 /* CC_VIEWPORT */
2038 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
2039 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
2040 dw[0] = 0;
2041 dw[1] = 0;
2042 }
2043
2044 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2045 gen7_3dstate_pointer(cmd,
2046 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2047 blend_offset);
2048 gen7_3dstate_pointer(cmd,
2049 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2050 ds_offset);
2051 gen7_3dstate_pointer(cmd,
2052 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2053
2054 gen7_3dstate_pointer(cmd,
2055 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2056 cc_vp_offset);
2057 } else {
2058 /* 3DSTATE_CC_STATE_POINTERS */
2059 cmd_batch_pointer(cmd, 4, &dw);
2060 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) | (4 - 2);
2061 dw[1] = blend_offset | GEN6_PTR_CC_DW1_BLEND_CHANGED;
2062 dw[2] = ds_offset | GEN6_PTR_CC_DW2_ZS_CHANGED;
2063 dw[3] = cc_offset | GEN6_PTR_CC_DW3_CC_CHANGED;
2064
2065 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2066 cmd_batch_pointer(cmd, 4, &dw);
2067 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2068 GEN6_PTR_VP_DW0_CC_CHANGED;
2069 dw[1] = 0;
2070 dw[2] = 0;
2071 dw[3] = cc_vp_offset;
2072 }
2073}
2074
2075static void gen6_meta_surface_states(struct intel_cmd *cmd)
2076{
2077 const struct intel_cmd_meta *meta = cmd->bind.meta;
2078 uint32_t binding_table[2];
2079 XGL_UINT surface_count = 0;
2080 uint32_t offset;
2081
2082 CMD_ASSERT(cmd, 6, 7.5);
2083
2084 /* SURFACE_STATE */
2085 if (meta->dst.valid) {
2086 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2087 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2088 meta->dst.surface_len, meta->dst.surface);
2089
2090 cmd_reserve_reloc(cmd, 1);
2091 cmd_surface_reloc(cmd, offset, 1,
2092 (struct intel_bo *) meta->dst.reloc_target,
2093 meta->dst.reloc_offset, meta->dst.reloc_flags);
2094
2095 binding_table[surface_count++] = offset;
2096 }
2097 if (meta->src.valid) {
2098 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2099 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2100 meta->src.surface_len, meta->src.surface);
2101
2102 cmd_reserve_reloc(cmd, 1);
2103 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2104 cmd_surface_reloc_writer(cmd, offset, 1,
2105 meta->src.reloc_target, meta->src.reloc_offset);
2106 } else {
2107 cmd_surface_reloc(cmd, offset, 1,
2108 (struct intel_bo *) meta->src.reloc_target,
2109 meta->src.reloc_offset, meta->src.reloc_flags);
2110 }
2111
2112 binding_table[surface_count++] = offset;
2113 }
2114
2115 /* BINDING_TABLE */
2116 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
2117 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
2118 surface_count, binding_table);
2119
2120 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2121 gen7_3dstate_pointer(cmd,
2122 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2123 offset);
2124 } else {
2125 /* 3DSTATE_BINDING_TABLE_POINTERS */
2126 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
2127 }
2128}
2129
2130static void gen6_meta_urb(struct intel_cmd *cmd)
2131{
2132 uint32_t *dw;
2133
2134 CMD_ASSERT(cmd, 6, 6);
2135
2136 /* 3DSTATE_URB */
2137 cmd_batch_pointer(cmd, 3, &dw);
2138 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
2139 dw[1] = 128 << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
2140 dw[2] = 0;
2141}
2142
2143static void gen7_meta_urb(struct intel_cmd *cmd)
2144{
2145 uint32_t *dw;
2146
2147 CMD_ASSERT(cmd, 7, 7.5);
2148
2149 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2150 cmd_batch_pointer(cmd, 10, &dw);
2151
2152 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
2153 dw[1] = 0;
2154 dw += 2;
2155
2156 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2157 dw[1] = 0;
2158 dw += 2;
2159
2160 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2161 dw[1] = 0;
2162 dw += 2;
2163
2164 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2165 dw[1] = 0;
2166 dw += 2;
2167
2168 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2169 dw[1] = 1;
2170
2171 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2172
2173 /* 3DSTATE_URB_x */
2174 cmd_batch_pointer(cmd, 8, &dw);
2175
2176 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2177 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
2178 512;
2179 dw += 2;
2180
2181 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2182 dw[1] = 0;
2183 dw += 2;
2184
2185 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2186 dw[1] = 0;
2187 dw += 2;
2188
2189 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2190 dw[1] = 0;
2191 dw += 2;
2192}
2193
2194static void gen6_meta_vf(struct intel_cmd *cmd)
2195{
2196 const struct intel_cmd_meta *meta = cmd->bind.meta;
2197 XGL_UINT vertices[3][2];
2198 uint32_t offset, *dw;
2199 XGL_UINT pos;
2200
2201 CMD_ASSERT(cmd, 6, 7.5);
2202
2203 /* write vertices */
2204 vertices[0][0] = meta->dst.x + meta->width;
2205 vertices[0][1] = meta->dst.y + meta->height;
2206 vertices[1][0] = meta->dst.x;
2207 vertices[1][1] = meta->dst.y + meta->height;
2208 vertices[2][0] = meta->dst.x;
2209 vertices[2][1] = meta->dst.y;
2210 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2211 sizeof(vertices) / 4, (const uint32_t *) vertices);
2212
2213 /* 3DSTATE_VERTEX_BUFFERS */
2214 pos = cmd_batch_pointer(cmd, 5, &dw);
2215 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
2216 dw[1] = sizeof(vertices[0]);
2217 if (cmd_gen(cmd) >= INTEL_GEN(7))
2218 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2219
2220 cmd_reserve_reloc(cmd, 2);
2221 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, offset);
2222 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
2223 offset + sizeof(vertices) - 1);
2224
2225 dw[4] = 0;
2226
2227 /* 3DSTATE_VERTEX_ELEMENTS */
2228 cmd_batch_pointer(cmd, 5, &dw);
2229 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
2230 dw[1] = GEN6_VE_STATE_DW0_VALID,
2231 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2232 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2233 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2234 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2235 dw[3] = GEN6_VE_STATE_DW0_VALID |
2236 GEN6_FORMAT_R32G32_USCALED << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
2237 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2238 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2239 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2240 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2241}
2242
2243static void gen6_meta_disabled(struct intel_cmd *cmd)
2244{
2245 uint32_t *dw;
2246
2247 CMD_ASSERT(cmd, 6, 6);
2248
2249 /* 3DSTATE_CONSTANT_VS */
2250 cmd_batch_pointer(cmd, 5, &dw);
2251 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2);
2252 dw[1] = 0;
2253 dw[2] = 0;
2254 dw[3] = 0;
2255 dw[4] = 0;
2256
2257 /* 3DSTATE_VS */
2258 cmd_batch_pointer(cmd, 6, &dw);
2259 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2260 dw[1] = 0;
2261 dw[2] = 0;
2262 dw[3] = 0;
2263 dw[4] = 0;
2264 dw[5] = 0;
2265
2266 /* 3DSTATE_CONSTANT_GS */
2267 cmd_batch_pointer(cmd, 5, &dw);
2268 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2269 dw[1] = 0;
2270 dw[2] = 0;
2271 dw[3] = 0;
2272 dw[4] = 0;
2273
2274 /* 3DSTATE_GS */
2275 cmd_batch_pointer(cmd, 7, &dw);
2276 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2277 dw[1] = 0;
2278 dw[2] = 0;
2279 dw[3] = 0;
2280 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2281 dw[5] = GEN6_GS_DW5_STATISTICS;
2282 dw[6] = 0;
2283
2284 /* 3DSTATE_CLIP */
2285 cmd_batch_pointer(cmd, 4, &dw);
2286 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2287 dw[1] = 0;
2288 dw[2] = 0;
2289 dw[3] = 0;
2290
2291 /* 3DSTATE_SF */
2292 cmd_batch_pointer(cmd, 20, &dw);
2293 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2294 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2295 memset(&dw[2], 0, 18 * sizeof(*dw));
2296}
2297
2298static void gen7_meta_disabled(struct intel_cmd *cmd)
2299{
2300 uint32_t *dw;
2301
2302 CMD_ASSERT(cmd, 7, 7.5);
2303
2304 /* 3DSTATE_CONSTANT_VS */
2305 cmd_batch_pointer(cmd, 7, &dw);
2306 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2307 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2308
2309 /* 3DSTATE_VS */
2310 cmd_batch_pointer(cmd, 6, &dw);
2311 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2312 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2313
2314 /* 3DSTATE_CONSTANT_HS */
2315 cmd_batch_pointer(cmd, 7, &dw);
2316 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2317 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2318
2319 /* 3DSTATE_HS */
2320 cmd_batch_pointer(cmd, 7, &dw);
2321 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2322 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2323
2324 /* 3DSTATE_TE */
2325 cmd_batch_pointer(cmd, 4, &dw);
2326 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2327 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2328
2329 /* 3DSTATE_CONSTANT_DS */
2330 cmd_batch_pointer(cmd, 7, &dw);
2331 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2332 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2333
2334 /* 3DSTATE_DS */
2335 cmd_batch_pointer(cmd, 6, &dw);
2336 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2337 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2338
2339 /* 3DSTATE_CONSTANT_GS */
2340 cmd_batch_pointer(cmd, 7, &dw);
2341 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2342 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2343
2344 /* 3DSTATE_GS */
2345 cmd_batch_pointer(cmd, 7, &dw);
2346 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2347 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2348
2349 /* 3DSTATE_STREAMOUT */
2350 cmd_batch_pointer(cmd, 3, &dw);
2351 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2352 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2353
2354 /* 3DSTATE_CLIP */
2355 cmd_batch_pointer(cmd, 4, &dw);
2356 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2357 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2358
2359 /* 3DSTATE_SF */
2360 cmd_batch_pointer(cmd, 7, &dw);
2361 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2362 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2363
2364 /* 3DSTATE_SBE */
2365 cmd_batch_pointer(cmd, 14, &dw);
2366 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2367 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2368 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
2369}
2370
2371static void gen6_meta_wm(struct intel_cmd *cmd)
2372{
2373 const struct intel_cmd_meta *meta = cmd->bind.meta;
2374 uint32_t *dw;
2375
2376 CMD_ASSERT(cmd, 6, 7.5);
2377
2378 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2379
2380 /* 3DSTATE_MULTISAMPLE */
2381 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2382 cmd_batch_pointer(cmd, 4, &dw);
2383 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2384 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2385 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2386 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2387 dw[2] = 0;
2388 dw[3] = 0;
2389 } else {
2390 cmd_batch_pointer(cmd, 3, &dw);
2391 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2392 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2393 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2394 dw[2] = 0;
2395 }
2396
2397 /* 3DSTATE_SAMPLE_MASK */
2398 cmd_batch_pointer(cmd, 2, &dw);
2399 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2400 dw[1] = (1 << meta->samples) - 1;
2401
2402 /* 3DSTATE_DRAWING_RECTANGLE */
2403 cmd_batch_pointer(cmd, 4, &dw);
2404 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2405 dw[1] = meta->dst.y << 16 | meta->dst.x;
2406 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2407 (meta->dst.x + meta->width - 1);
2408 dw[3] = 0;
2409}
2410
2411static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2412{
2413 const struct intel_cmd_meta *meta = cmd->bind.meta;
2414 XGL_UINT offset_x, offset_y;
2415 /* one GPR */
2416 XGL_UINT consts[8];
2417 XGL_UINT const_count;
2418
2419 CMD_ASSERT(cmd, 6, 7.5);
2420
2421 /* underflow is fine here */
2422 offset_x = meta->src.x - meta->dst.x;
2423 offset_y = meta->src.y - meta->dst.y;
2424
2425 switch (meta->shader_id) {
2426 case INTEL_DEV_META_FS_COPY_MEM:
2427 case INTEL_DEV_META_FS_COPY_1D:
2428 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2429 case INTEL_DEV_META_FS_COPY_2D:
2430 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2431 case INTEL_DEV_META_FS_COPY_2D_MS:
2432 consts[0] = offset_x;
2433 consts[1] = offset_y;
2434 consts[2] = meta->src.layer;
2435 consts[3] = meta->src.lod;
2436 const_count = 4;
2437 break;
2438 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2439 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2440 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2441 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2442 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2443 consts[0] = offset_x;
2444 consts[1] = offset_y;
2445 consts[2] = meta->src.layer;
2446 consts[3] = meta->src.lod;
2447 consts[4] = meta->src.x;
2448 consts[5] = meta->width;
2449 const_count = 6;
2450 break;
2451 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2452 consts[0] = offset_x;
2453 consts[1] = offset_y;
2454 consts[2] = meta->width;
2455 const_count = 3;
2456 break;
2457 case INTEL_DEV_META_FS_CLEAR_COLOR:
2458 consts[0] = meta->clear_val[0];
2459 consts[1] = meta->clear_val[1];
2460 consts[2] = meta->clear_val[2];
2461 consts[3] = meta->clear_val[3];
2462 const_count = 4;
2463 break;
2464 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2465 consts[0] = meta->clear_val[0];
2466 const_count = 1;
2467 break;
2468 case INTEL_DEV_META_FS_RESOLVE_2X:
2469 case INTEL_DEV_META_FS_RESOLVE_4X:
2470 case INTEL_DEV_META_FS_RESOLVE_8X:
2471 case INTEL_DEV_META_FS_RESOLVE_16X:
2472 consts[0] = offset_x;
2473 consts[1] = offset_y;
2474 const_count = 2;
2475 break;
2476 default:
2477 assert(!"unknown meta shader id");
2478 const_count = 0;
2479 break;
2480 }
2481
2482 /* this can be skipped but it makes state dumping prettier */
2483 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2484
2485 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2486}
2487
2488static void gen6_meta_ps(struct intel_cmd *cmd)
2489{
2490 const struct intel_cmd_meta *meta = cmd->bind.meta;
2491 const struct intel_pipeline_shader *sh =
2492 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2493 uint32_t offset, *dw;
2494
2495 CMD_ASSERT(cmd, 6, 6);
2496
2497 /* 3DSTATE_CONSTANT_PS */
2498 offset = gen6_meta_ps_constants(cmd);
2499 cmd_batch_pointer(cmd, 5, &dw);
2500 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2501 GEN6_PCB_ANY_DW0_PCB0_VALID;
2502 dw[1] = offset;
2503 dw[2] = 0;
2504 dw[3] = 0;
2505 dw[4] = 0;
2506
2507 /* 3DSTATE_WM */
2508 offset = emit_shader(cmd, sh);
2509 cmd_batch_pointer(cmd, 9, &dw);
2510 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2511 dw[1] = offset;
2512 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2513 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2514 dw[3] = 0;
2515 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
2516 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
2517 GEN6_WM_DW5_PS_ENABLE |
2518 GEN6_WM_DW5_8_PIXEL_DISPATCH;
2519 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2520 GEN6_WM_DW6_POSOFFSET_NONE |
2521 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2522 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2523 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2524 if (meta->samples > 1) {
2525 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2526 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2527 } else {
2528 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2529 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2530 }
2531 dw[7] = 0;
2532 dw[8] = 0;
2533}
2534
2535static void gen7_meta_ps(struct intel_cmd *cmd)
2536{
2537 const struct intel_cmd_meta *meta = cmd->bind.meta;
2538 const struct intel_pipeline_shader *sh =
2539 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2540 uint32_t offset, *dw;
2541
2542 CMD_ASSERT(cmd, 7, 7.5);
2543
2544 /* 3DSTATE_WM */
2545 cmd_batch_pointer(cmd, 3, &dw);
2546 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2547 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2548 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2549 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2550 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2551 dw[2] = 0;
2552
2553 /* 3DSTATE_CONSTANT_PS */
2554 offset = gen6_meta_ps_constants(cmd);
2555 cmd_batch_pointer(cmd, 7, &dw);
2556 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2557 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2558 dw[2] = 0;
2559 dw[3] = offset;
2560 dw[4] = 0;
2561 dw[5] = 0;
2562 dw[6] = 0;
2563
2564 /* 3DSTATE_PS */
2565 offset = emit_shader(cmd, sh);
2566 cmd_batch_pointer(cmd, 8, &dw);
2567 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2568 dw[1] = offset;
2569 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2570 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2571 dw[3] = 0;
2572
2573 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2574 GEN7_PS_DW4_POSOFFSET_NONE |
2575 GEN7_PS_DW4_8_PIXEL_DISPATCH |
2576 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2577 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
2578 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
2579
2580 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2581 dw[6] = 0;
2582 dw[7] = 0;
2583}
2584
2585static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2586{
2587 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002588 const struct intel_ds_view *ds = meta->ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002589
2590 CMD_ASSERT(cmd, 6, 7.5);
2591
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002592 if (!ds) {
2593 /* all zeros */
2594 static const struct intel_ds_view null_ds;
2595 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002596 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002597
2598 cmd_wa_gen6_pre_ds_flush(cmd);
2599 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2600 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2601 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2602
2603 if (cmd_gen(cmd) >= INTEL_GEN(7))
2604 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2605 else
2606 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002607}
2608
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002609static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2610 const struct intel_pipeline *pipeline)
2611{
2612 cmd->bind.pipeline.graphics = pipeline;
2613}
2614
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002615static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2616 const struct intel_pipeline *pipeline)
2617{
2618 cmd->bind.pipeline.compute = pipeline;
2619}
2620
2621static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2622 const struct intel_pipeline_delta *delta)
2623{
2624 cmd->bind.pipeline.graphics_delta = delta;
2625}
2626
2627static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2628 const struct intel_pipeline_delta *delta)
2629{
2630 cmd->bind.pipeline.compute_delta = delta;
2631}
2632
2633static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2634 const struct intel_dset *dset,
2635 XGL_UINT slot_offset)
2636{
2637 cmd->bind.dset.graphics = dset;
2638 cmd->bind.dset.graphics_offset = slot_offset;
2639}
2640
2641static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2642 const struct intel_dset *dset,
2643 XGL_UINT slot_offset)
2644{
2645 cmd->bind.dset.compute = dset;
2646 cmd->bind.dset.compute_offset = slot_offset;
2647}
2648
2649static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2650 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2651{
2652 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2653}
2654
2655static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2656 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2657{
2658 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2659}
2660
2661static void cmd_bind_index_data(struct intel_cmd *cmd,
2662 const struct intel_mem *mem,
2663 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2664{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002665 cmd->bind.index.mem = mem;
2666 cmd->bind.index.offset = offset;
2667 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002668}
2669
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002670static void cmd_bind_attachments(struct intel_cmd *cmd,
2671 XGL_UINT rt_count,
2672 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2673 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002674{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002675 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002676 XGL_UINT i;
2677
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002678 for (i = 0; i < rt_count; i++) {
2679 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002680 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002681 const struct intel_layout *layout = &rt->img->layout;
2682
2683 if (i == 0) {
2684 width = layout->width0;
2685 height = layout->height0;
2686 } else {
2687 if (width > layout->width0)
2688 width = layout->width0;
2689 if (height > layout->height0)
2690 height = layout->height0;
2691 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002692
2693 cmd->bind.att.rt[i] = rt;
2694 }
2695
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002696 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002697
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002698 if (ds_info) {
2699 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002700
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002701 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2702 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002703
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002704 if (width > layout->width0)
2705 width = layout->width0;
2706 if (height > layout->height0)
2707 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002708 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002709 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002710 }
2711
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002712 cmd->bind.att.width = width;
2713 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002714}
2715
2716static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2717 const struct intel_viewport_state *state)
2718{
2719 cmd->bind.state.viewport = state;
2720}
2721
2722static void cmd_bind_raster_state(struct intel_cmd *cmd,
2723 const struct intel_raster_state *state)
2724{
2725 cmd->bind.state.raster = state;
2726}
2727
2728static void cmd_bind_ds_state(struct intel_cmd *cmd,
2729 const struct intel_ds_state *state)
2730{
2731 cmd->bind.state.ds = state;
2732}
2733
2734static void cmd_bind_blend_state(struct intel_cmd *cmd,
2735 const struct intel_blend_state *state)
2736{
2737 cmd->bind.state.blend = state;
2738}
2739
2740static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2741 const struct intel_msaa_state *state)
2742{
2743 cmd->bind.state.msaa = state;
2744}
2745
2746static void cmd_draw(struct intel_cmd *cmd,
2747 XGL_UINT vertex_start,
2748 XGL_UINT vertex_count,
2749 XGL_UINT instance_start,
2750 XGL_UINT instance_count,
2751 bool indexed,
2752 XGL_UINT vertex_base)
2753{
2754 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2755
2756 emit_bounded_states(cmd);
2757
2758 if (indexed) {
2759 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2760 cmd->result = XGL_ERROR_UNKNOWN;
2761
2762 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2763 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2764 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002765 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2766 cmd->bind.index.offset, cmd->bind.index.type,
2767 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002768 } else {
2769 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2770 cmd->bind.index.offset, cmd->bind.index.type,
2771 p->primitive_restart);
2772 }
2773 } else {
2774 assert(!vertex_base);
2775 }
2776
2777 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2778 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2779 vertex_start, instance_count, instance_start, vertex_base);
2780 } else {
2781 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2782 vertex_start, instance_count, instance_start, vertex_base);
2783 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002784
Chia-I Wu707a29e2014-08-27 12:51:47 +08002785 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002786 /* need to re-emit all workarounds */
2787 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002788}
2789
Chia-I Wuc14d1562014-10-17 09:49:22 +08002790void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2791{
Chia-I Wu6032b892014-10-17 14:47:18 +08002792 cmd->bind.meta = meta;
2793
2794 cmd_wa_gen6_pre_depth_stall_write(cmd);
2795
2796 gen6_meta_dynamic_states(cmd);
2797 gen6_meta_surface_states(cmd);
2798
2799 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2800 gen7_meta_urb(cmd);
2801 gen6_meta_vf(cmd);
2802 gen7_meta_disabled(cmd);
2803 gen6_meta_wm(cmd);
2804 gen7_meta_ps(cmd);
2805 gen6_meta_depth_buffer(cmd);
2806
2807 cmd_wa_gen7_post_command_cs_stall(cmd);
2808 cmd_wa_gen7_post_command_depth_stall(cmd);
2809
2810 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2811 } else {
2812 gen6_meta_urb(cmd);
2813 gen6_meta_vf(cmd);
2814 gen6_meta_disabled(cmd);
2815 gen6_meta_wm(cmd);
2816 gen6_meta_ps(cmd);
2817 gen6_meta_depth_buffer(cmd);
2818
2819 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2820 }
2821
2822 cmd->bind.draw_count++;
2823 /* need to re-emit all workarounds */
2824 cmd->bind.wa_flags = 0;
2825
2826 cmd->bind.meta = NULL;
Chia-I Wuc14d1562014-10-17 09:49:22 +08002827}
2828
Chia-I Wub2755562014-08-20 13:38:52 +08002829XGL_VOID XGLAPI intelCmdBindPipeline(
2830 XGL_CMD_BUFFER cmdBuffer,
2831 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2832 XGL_PIPELINE pipeline)
2833{
2834 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2835
2836 switch (pipelineBindPoint) {
2837 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002838 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002839 break;
2840 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002841 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002842 break;
2843 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002844 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002845 break;
2846 }
2847}
2848
2849XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2850 XGL_CMD_BUFFER cmdBuffer,
2851 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2852 XGL_PIPELINE_DELTA delta)
2853{
2854 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2855
2856 switch (pipelineBindPoint) {
2857 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002858 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002859 break;
2860 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002861 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002862 break;
2863 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002864 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002865 break;
2866 }
2867}
2868
2869XGL_VOID XGLAPI intelCmdBindStateObject(
2870 XGL_CMD_BUFFER cmdBuffer,
2871 XGL_STATE_BIND_POINT stateBindPoint,
2872 XGL_STATE_OBJECT state)
2873{
2874 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2875
2876 switch (stateBindPoint) {
2877 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002878 cmd_bind_viewport_state(cmd,
2879 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002880 break;
2881 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002882 cmd_bind_raster_state(cmd,
2883 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002884 break;
2885 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002886 cmd_bind_ds_state(cmd,
2887 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002888 break;
2889 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002890 cmd_bind_blend_state(cmd,
2891 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002892 break;
2893 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002894 cmd_bind_msaa_state(cmd,
2895 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002896 break;
2897 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002898 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002899 break;
2900 }
2901}
2902
2903XGL_VOID XGLAPI intelCmdBindDescriptorSet(
2904 XGL_CMD_BUFFER cmdBuffer,
2905 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2906 XGL_UINT index,
2907 XGL_DESCRIPTOR_SET descriptorSet,
2908 XGL_UINT slotOffset)
2909{
2910 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2911 struct intel_dset *dset = intel_dset(descriptorSet);
2912
2913 assert(!index);
2914
2915 switch (pipelineBindPoint) {
2916 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002917 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002918 break;
2919 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002920 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002921 break;
2922 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002923 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002924 break;
2925 }
2926}
2927
2928XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
2929 XGL_CMD_BUFFER cmdBuffer,
2930 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2931 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
2932{
2933 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2934
2935 switch (pipelineBindPoint) {
2936 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002937 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002938 break;
2939 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002940 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08002941 break;
2942 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002943 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002944 break;
2945 }
2946}
2947
2948XGL_VOID XGLAPI intelCmdBindIndexData(
2949 XGL_CMD_BUFFER cmdBuffer,
2950 XGL_GPU_MEMORY mem_,
2951 XGL_GPU_SIZE offset,
2952 XGL_INDEX_TYPE indexType)
2953{
2954 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2955 struct intel_mem *mem = intel_mem(mem_);
2956
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002957 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08002958}
2959
2960XGL_VOID XGLAPI intelCmdBindAttachments(
2961 XGL_CMD_BUFFER cmdBuffer,
2962 XGL_UINT colorAttachmentCount,
2963 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
2964 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
2965{
2966 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08002967
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002968 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
2969 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08002970}
2971
2972XGL_VOID XGLAPI intelCmdDraw(
2973 XGL_CMD_BUFFER cmdBuffer,
2974 XGL_UINT firstVertex,
2975 XGL_UINT vertexCount,
2976 XGL_UINT firstInstance,
2977 XGL_UINT instanceCount)
2978{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002979 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002980
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002981 cmd_draw(cmd, firstVertex, vertexCount,
2982 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08002983}
2984
2985XGL_VOID XGLAPI intelCmdDrawIndexed(
2986 XGL_CMD_BUFFER cmdBuffer,
2987 XGL_UINT firstIndex,
2988 XGL_UINT indexCount,
2989 XGL_INT vertexOffset,
2990 XGL_UINT firstInstance,
2991 XGL_UINT instanceCount)
2992{
Chia-I Wu59c097e2014-08-21 10:51:07 +08002993 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08002994
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002995 cmd_draw(cmd, firstIndex, indexCount,
2996 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002997}
2998
2999XGL_VOID XGLAPI intelCmdDrawIndirect(
3000 XGL_CMD_BUFFER cmdBuffer,
3001 XGL_GPU_MEMORY mem,
3002 XGL_GPU_SIZE offset,
3003 XGL_UINT32 count,
3004 XGL_UINT32 stride)
3005{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003006 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3007
3008 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003009}
3010
3011XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3012 XGL_CMD_BUFFER cmdBuffer,
3013 XGL_GPU_MEMORY mem,
3014 XGL_GPU_SIZE offset,
3015 XGL_UINT32 count,
3016 XGL_UINT32 stride)
3017{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003018 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3019
3020 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003021}
3022
3023XGL_VOID XGLAPI intelCmdDispatch(
3024 XGL_CMD_BUFFER cmdBuffer,
3025 XGL_UINT x,
3026 XGL_UINT y,
3027 XGL_UINT z)
3028{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003029 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3030
3031 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003032}
3033
3034XGL_VOID XGLAPI intelCmdDispatchIndirect(
3035 XGL_CMD_BUFFER cmdBuffer,
3036 XGL_GPU_MEMORY mem,
3037 XGL_GPU_SIZE offset)
3038{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003039 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3040
3041 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003042}