blob: 9e66cae295da6f305394ef73c34a71e264b45115 [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;
Steve K42652ba2014-10-07 10:44:41 -0600459 printf("%d %d\n", fs->in_count, attr_count);
Chia-I Wu8016a172014-08-29 18:31:32 +0800460 assert(fs->in_count == attr_count);
461 assert(fs->in_count <= 32);
462
463 vue_offset = attr_skip / 2;
464 vue_len = (attr_count + 1) / 2;
465 if (!vue_len)
466 vue_len = 1;
467
468 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
469 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
470 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
471
472 body[0] = dw1;
473
474 for (i = 0; i < 8; i++) {
475 uint16_t hi, lo;
476
477 /* no attr swizzles */
478 if (i * 2 + 1 < fs->in_count) {
479 hi = i * 2 + 1;
480 lo = i * 2;
481 } else if (i * 2 < fs->in_count) {
482 hi = 0;
483 lo = i * 2;
484 } else {
485 hi = 0;
486 lo = 0;
487 }
488
489 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
490 }
491
492 body[9] = 0; /* point sprite enables */
493 body[10] = 0; /* constant interpolation enables */
494 body[11] = 0; /* WrapShortest enables */
495 body[12] = 0;
496}
497
498static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
499{
500 const uint8_t cmd_len = 20;
501 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
502 (cmd_len - 2);
503 uint32_t sf[6];
504 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800505 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800506
507 CMD_ASSERT(cmd, 6, 6);
508
509 gen7_fill_3DSTATE_SF_body(cmd, sf);
510 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
511
Chia-I Wu72292b72014-09-09 10:48:33 +0800512 cmd_batch_pointer(cmd, cmd_len, &dw);
513 dw[0] = dw0;
514 dw[1] = sbe[0];
515 memcpy(&dw[2], sf, sizeof(sf));
516 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800517}
518
519static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
520{
521 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800522 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800523
524 CMD_ASSERT(cmd, 7, 7.5);
525
Chia-I Wu72292b72014-09-09 10:48:33 +0800526 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800527 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
528 (cmd_len - 2);
529 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800530}
531
532static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
533{
534 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800535 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800536
537 CMD_ASSERT(cmd, 7, 7.5);
538
Chia-I Wu72292b72014-09-09 10:48:33 +0800539 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800540 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
541 (cmd_len - 2);
542 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800543}
544
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800545static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
546{
547 const uint8_t cmd_len = 4;
548 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
549 (cmd_len - 2);
550 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800551 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800552 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
553 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800554 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800555
556 CMD_ASSERT(cmd, 6, 7.5);
557
558 dw1 = GEN6_CLIP_DW1_STATISTICS;
559 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
560 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
561 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
562 raster->cmd_clip_cull;
563 }
564
565 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
566 GEN6_CLIP_DW2_XY_TEST_ENABLE |
567 GEN6_CLIP_DW2_APIMODE_OGL |
568 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
569 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
570 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
571
572 if (pipeline->rasterizerDiscardEnable)
573 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
574 else
575 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
576
577 if (pipeline->depthClipEnable)
578 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
579
580 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
581 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
582 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
583 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
584
585 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
586 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
587 (viewport->viewport_count - 1);
588
Chia-I Wu72292b72014-09-09 10:48:33 +0800589 cmd_batch_pointer(cmd, cmd_len, &dw);
590 dw[0] = dw0;
591 dw[1] = dw1;
592 dw[2] = dw2;
593 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800594}
595
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
597{
598 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
599 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800600 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800601 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
602 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800603 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800604
605 CMD_ASSERT(cmd, 6, 6);
606
607 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
608
609 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
610 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
611
612 dw4 = GEN6_WM_DW4_STATISTICS |
613 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
614 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
615 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
616
617 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
618 GEN6_WM_DW5_PS_ENABLE |
619 GEN6_WM_DW5_8_PIXEL_DISPATCH;
620
621 if (fs->uses & INTEL_SHADER_USE_KILL ||
622 pipeline->cb_state.alphaToCoverageEnable)
623 dw5 |= GEN6_WM_DW5_PS_KILL;
624
625 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
626 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
627 if (fs->uses & INTEL_SHADER_USE_DEPTH)
628 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
629 if (fs->uses & INTEL_SHADER_USE_W)
630 dw5 |= GEN6_WM_DW5_PS_USE_W;
631
632 if (pipeline->cb_state.dualSourceBlendEnable)
633 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
634
635 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
636 GEN6_WM_DW6_POSOFFSET_NONE |
637 GEN6_WM_DW6_ZW_INTERP_PIXEL |
638 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
639 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
640
641 if (msaa->sample_count > 1) {
642 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
643 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
644 } else {
645 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
646 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
647 }
648
Chia-I Wu72292b72014-09-09 10:48:33 +0800649 cmd_batch_pointer(cmd, cmd_len, &dw);
650 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800651 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800652 dw[2] = dw2;
653 dw[3] = 0; /* scratch */
654 dw[4] = dw4;
655 dw[5] = dw5;
656 dw[6] = dw6;
657 dw[7] = 0; /* kernel 1 */
658 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800659}
660
661static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
662{
663 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800664 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800665 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
666 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800667 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668
669 CMD_ASSERT(cmd, 7, 7.5);
670
671 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
672
673 dw1 = GEN7_WM_DW1_STATISTICS |
674 GEN7_WM_DW1_PS_ENABLE |
675 GEN7_WM_DW1_ZW_INTERP_PIXEL |
676 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
677 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
678
679 if (fs->uses & INTEL_SHADER_USE_KILL ||
680 pipeline->cb_state.alphaToCoverageEnable)
681 dw1 |= GEN7_WM_DW1_PS_KILL;
682
683 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
684 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
685 if (fs->uses & INTEL_SHADER_USE_DEPTH)
686 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
687 if (fs->uses & INTEL_SHADER_USE_W)
688 dw1 |= GEN7_WM_DW1_PS_USE_W;
689
690 dw2 = 0;
691
692 if (msaa->sample_count > 1) {
693 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
694 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
695 } else {
696 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
697 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
698 }
699
Chia-I Wu72292b72014-09-09 10:48:33 +0800700 cmd_batch_pointer(cmd, cmd_len, &dw);
701 dw[0] = dw0;
702 dw[1] = dw1;
703 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704}
705
706static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
707{
708 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800709 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800710 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
711 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800712 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800713
714 CMD_ASSERT(cmd, 7, 7.5);
715
716 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
717
718 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
719 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
720
721 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
722 GEN7_PS_DW4_8_PIXEL_DISPATCH;
723
724 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
725 const int max_threads =
726 (cmd->dev->gpu->gt == 3) ? 408 :
727 (cmd->dev->gpu->gt == 2) ? 204 : 102;
728 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
729 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
730 } else {
731 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
732 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
733 }
734
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800735 if (fs->in_count)
736 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
737
738 if (pipeline->cb_state.dualSourceBlendEnable)
739 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
740
741 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
742 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
743 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
744
Chia-I Wu72292b72014-09-09 10:48:33 +0800745 cmd_batch_pointer(cmd, cmd_len, &dw);
746 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800747 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800748 dw[2] = dw2;
749 dw[3] = 0; /* scratch */
750 dw[4] = dw4;
751 dw[5] = dw5;
752 dw[6] = 0; /* kernel 1 */
753 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800754}
755
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800756static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
757 const struct intel_ds_view *view)
758{
759 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800760 uint32_t dw0, *dw;
761 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800762
763 CMD_ASSERT(cmd, 6, 7.5);
764
765 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800766 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
767 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800768 dw0 |= (cmd_len - 2);
769
Chia-I Wu72292b72014-09-09 10:48:33 +0800770 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
771 dw[0] = dw0;
772 dw[1] = view->cmd[0];
773 dw[2] = 0;
774 dw[3] = view->cmd[2];
775 dw[4] = view->cmd[3];
776 dw[5] = view->cmd[4];
777 dw[6] = view->cmd[5];
778
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600779 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800780 cmd_reserve_reloc(cmd, 1);
781 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
782 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600783 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800784}
785
786static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
787 const struct intel_ds_view *view)
788{
789 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 uint32_t dw0, *dw;
791 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800792
793 CMD_ASSERT(cmd, 6, 7.5);
794
795 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800796 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
797 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800798 dw0 |= (cmd_len - 2);
799
Chia-I Wu72292b72014-09-09 10:48:33 +0800800 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
801 dw[0] = dw0;
802 dw[1] = view->cmd[6];
803 dw[2] = 0;
804
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600805 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 cmd_reserve_reloc(cmd, 1);
807 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
808 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600809 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810}
811
812static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
813 const struct intel_ds_view *view)
814{
815 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800816 uint32_t dw0, *dw;
817 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800818
819 CMD_ASSERT(cmd, 6, 7.5);
820
821 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800822 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
823 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800824 dw0 |= (cmd_len - 2);
825
Chia-I Wu72292b72014-09-09 10:48:33 +0800826 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
827 dw[0] = dw0;
828 dw[1] = view->cmd[8];
829 dw[2] = 0;
830
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600831 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800832 cmd_reserve_reloc(cmd, 1);
833 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
834 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600835 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800836}
837
Chia-I Wuf8231032014-08-25 10:44:45 +0800838static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
839 uint32_t clear_val)
840{
841 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800842 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800843 GEN6_CLEAR_PARAMS_DW0_VALID |
844 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800846
847 CMD_ASSERT(cmd, 6, 6);
848
Chia-I Wu72292b72014-09-09 10:48:33 +0800849 cmd_batch_pointer(cmd, cmd_len, &dw);
850 dw[0] = dw0;
851 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800852}
853
854static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
855 uint32_t clear_val)
856{
857 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800858 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800859 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800860 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800861
862 CMD_ASSERT(cmd, 7, 7.5);
863
Chia-I Wu72292b72014-09-09 10:48:33 +0800864 cmd_batch_pointer(cmd, cmd_len, &dw);
865 dw[0] = dw0;
866 dw[1] = clear_val;
867 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800868}
869
Chia-I Wu302742d2014-08-22 10:28:29 +0800870static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800871 uint32_t blend_offset,
872 uint32_t ds_offset,
873 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800874{
875 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800876 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800877
878 CMD_ASSERT(cmd, 6, 6);
879
Chia-I Wu426072d2014-08-26 14:31:55 +0800880 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800881 (cmd_len - 2);
882
Chia-I Wu72292b72014-09-09 10:48:33 +0800883 cmd_batch_pointer(cmd, cmd_len, &dw);
884 dw[0] = dw0;
885 dw[1] = blend_offset | 1;
886 dw[2] = ds_offset | 1;
887 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800888}
889
Chia-I Wu1744cca2014-08-22 11:10:17 +0800890static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800891 uint32_t clip_offset,
892 uint32_t sf_offset,
893 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800894{
895 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800896 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800897
898 CMD_ASSERT(cmd, 6, 6);
899
Chia-I Wu426072d2014-08-26 14:31:55 +0800900 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800901 GEN6_PTR_VP_DW0_CLIP_CHANGED |
902 GEN6_PTR_VP_DW0_SF_CHANGED |
903 GEN6_PTR_VP_DW0_CC_CHANGED |
904 (cmd_len - 2);
905
Chia-I Wu72292b72014-09-09 10:48:33 +0800906 cmd_batch_pointer(cmd, cmd_len, &dw);
907 dw[0] = dw0;
908 dw[1] = clip_offset;
909 dw[2] = sf_offset;
910 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800911}
912
913static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800914 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800915{
916 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800917 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800918
919 CMD_ASSERT(cmd, 6, 6);
920
Chia-I Wu426072d2014-08-26 14:31:55 +0800921 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800922 (cmd_len - 2);
923
Chia-I Wu72292b72014-09-09 10:48:33 +0800924 cmd_batch_pointer(cmd, cmd_len, &dw);
925 dw[0] = dw0;
926 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800927}
928
Chia-I Wu42a56202014-08-23 16:47:48 +0800929static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800930 uint32_t vs_offset,
931 uint32_t gs_offset,
932 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800933{
934 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800935 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800936
937 CMD_ASSERT(cmd, 6, 6);
938
Chia-I Wu426072d2014-08-26 14:31:55 +0800939 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800940 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
941 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
942 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
943 (cmd_len - 2);
944
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 cmd_batch_pointer(cmd, cmd_len, &dw);
946 dw[0] = dw0;
947 dw[1] = vs_offset;
948 dw[2] = gs_offset;
949 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800950}
951
Chia-I Wu257e75e2014-08-29 14:06:35 +0800952static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 uint32_t vs_offset,
954 uint32_t gs_offset,
955 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800956{
957 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800958 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800959
960 CMD_ASSERT(cmd, 6, 6);
961
962 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
963 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
964 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
965 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
966 (cmd_len - 2);
967
Chia-I Wu72292b72014-09-09 10:48:33 +0800968 cmd_batch_pointer(cmd, cmd_len, &dw);
969 dw[0] = dw0;
970 dw[1] = vs_offset;
971 dw[2] = gs_offset;
972 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800973}
974
Chia-I Wu302742d2014-08-22 10:28:29 +0800975static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800976 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800977{
978 const uint8_t cmd_len = 2;
979 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
980 GEN6_RENDER_SUBTYPE_3D |
981 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800982 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800983
Chia-I Wu72292b72014-09-09 10:48:33 +0800984 cmd_batch_pointer(cmd, cmd_len, &dw);
985 dw[0] = dw0;
986 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987}
988
Chia-I Wu72292b72014-09-09 10:48:33 +0800989static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800990 const struct intel_blend_state *state)
991{
Chia-I Wu72292b72014-09-09 10:48:33 +0800992 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800993 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
994
995 CMD_ASSERT(cmd, 6, 7.5);
996 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
997
Chia-I Wu00b51a82014-09-09 12:07:37 +0800998 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
999 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001000}
1001
Chia-I Wu72292b72014-09-09 10:48:33 +08001002static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001003 const struct intel_ds_state *state)
1004{
Chia-I Wu72292b72014-09-09 10:48:33 +08001005 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001006 const uint8_t cmd_len = 3;
1007
1008 CMD_ASSERT(cmd, 6, 7.5);
1009 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1010
Chia-I Wu00b51a82014-09-09 12:07:37 +08001011 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1012 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001013}
1014
Chia-I Wu72292b72014-09-09 10:48:33 +08001015static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001016 uint32_t stencil_ref,
1017 const uint32_t blend_color[4])
1018{
Chia-I Wu72292b72014-09-09 10:48:33 +08001019 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001020 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001021 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001022
1023 CMD_ASSERT(cmd, 6, 7.5);
1024
Chia-I Wu00b51a82014-09-09 12:07:37 +08001025 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1026 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001027 dw[0] = stencil_ref;
1028 dw[1] = 0;
1029 dw[2] = blend_color[0];
1030 dw[3] = blend_color[1];
1031 dw[4] = blend_color[2];
1032 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001033
Chia-I Wu72292b72014-09-09 10:48:33 +08001034 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001035}
1036
Chia-I Wu8370b402014-08-29 12:28:37 +08001037static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001038{
Chia-I Wu8370b402014-08-29 12:28:37 +08001039 CMD_ASSERT(cmd, 6, 7.5);
1040
Chia-I Wu707a29e2014-08-27 12:51:47 +08001041 if (!cmd->bind.draw_count)
1042 return;
1043
Chia-I Wu8370b402014-08-29 12:28:37 +08001044 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001045 return;
1046
Chia-I Wu8370b402014-08-29 12:28:37 +08001047 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001048
1049 /*
1050 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1051 *
1052 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1053 * pipe-control with a post-sync op and no write-cache flushes."
1054 *
1055 * The workaround below necessitates this workaround.
1056 */
1057 gen6_PIPE_CONTROL(cmd,
1058 GEN6_PIPE_CONTROL_CS_STALL |
1059 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001060 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001061
Chia-I Wud6d079d2014-08-31 13:14:21 +08001062 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1063 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001064}
1065
Chia-I Wu8370b402014-08-29 12:28:37 +08001066static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001067{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001068 CMD_ASSERT(cmd, 6, 7.5);
1069
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001070 if (!cmd->bind.draw_count)
1071 return;
1072
Chia-I Wud6d079d2014-08-31 13:14:21 +08001073 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1074 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001075}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001076
Chia-I Wu8370b402014-08-29 12:28:37 +08001077static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1078{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001079 CMD_ASSERT(cmd, 7, 7.5);
1080
Chia-I Wu8370b402014-08-29 12:28:37 +08001081 if (!cmd->bind.draw_count)
1082 return;
1083
1084 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001085
1086 gen6_PIPE_CONTROL(cmd,
1087 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001088 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001089}
1090
Chia-I Wu8370b402014-08-29 12:28:37 +08001091static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1092{
1093 CMD_ASSERT(cmd, 7, 7.5);
1094
1095 if (!cmd->bind.draw_count)
1096 return;
1097
1098 /*
1099 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1100 *
1101 * "One of the following must also be set (when CS stall is set):
1102 *
1103 * * Render Target Cache Flush Enable ([12] of DW1)
1104 * * Depth Cache Flush Enable ([0] of DW1)
1105 * * Stall at Pixel Scoreboard ([1] of DW1)
1106 * * Depth Stall ([13] of DW1)
1107 * * Post-Sync Operation ([13] of DW1)"
1108 */
1109 gen6_PIPE_CONTROL(cmd,
1110 GEN6_PIPE_CONTROL_CS_STALL |
1111 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001112 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001113}
1114
1115static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1116{
1117 CMD_ASSERT(cmd, 7, 7.5);
1118
1119 if (!cmd->bind.draw_count)
1120 return;
1121
1122 cmd_wa_gen6_pre_depth_stall_write(cmd);
1123
Chia-I Wud6d079d2014-08-31 13:14:21 +08001124 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001125}
1126
1127static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1128{
1129 CMD_ASSERT(cmd, 6, 7.5);
1130
1131 if (!cmd->bind.draw_count)
1132 return;
1133
1134 /*
1135 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1136 *
1137 * "Driver must guarentee that all the caches in the depth pipe are
1138 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1139 * requires driver to send a PIPE_CONTROL with a CS stall along with
1140 * a Depth Flush prior to this command."
1141 *
1142 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1143 *
1144 * "Driver must ierarchi that all the caches in the depth pipe are
1145 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1146 * requires driver to send a PIPE_CONTROL with a CS stall along with
1147 * a Depth Flush prior to this command.
1148 */
1149 gen6_PIPE_CONTROL(cmd,
1150 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1151 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001152 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001153}
1154
1155static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1156{
1157 CMD_ASSERT(cmd, 6, 7.5);
1158
1159 if (!cmd->bind.draw_count)
1160 return;
1161
1162 /*
1163 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1164 *
1165 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1166 * and a post sync operation prior to the group of depth
1167 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1168 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1169 *
1170 * This workaround satifies all the conditions.
1171 */
1172 cmd_wa_gen6_pre_depth_stall_write(cmd);
1173
1174 /*
1175 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1176 *
1177 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1178 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1179 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1180 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1181 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1182 * Depth Flush Bit set, followed by another pipelined depth stall
1183 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1184 * guarantee that the pipeline from WM onwards is already flushed
1185 * (e.g., via a preceding MI_FLUSH)."
1186 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001187 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1188 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1189 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001190}
1191
Chia-I Wu525c6602014-08-27 10:22:34 +08001192void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1193{
1194 if (!cmd->bind.draw_count)
1195 return;
1196
1197 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1198
Chia-I Wu8370b402014-08-29 12:28:37 +08001199 /*
1200 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1201 *
1202 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1203 * PIPE_CONTROL with any non-zero post-sync-op is required."
1204 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001205 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001206 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001207
Chia-I Wu092279a2014-08-30 19:05:30 +08001208 /*
1209 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1210 *
1211 * "One of the following must also be set (when CS stall is set):
1212 *
1213 * * Render Target Cache Flush Enable ([12] of DW1)
1214 * * Depth Cache Flush Enable ([0] of DW1)
1215 * * Stall at Pixel Scoreboard ([1] of DW1)
1216 * * Depth Stall ([13] of DW1)
1217 * * Post-Sync Operation ([13] of DW1)"
1218 */
1219 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1220 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1221 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1222 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1223 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1224 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1225
Chia-I Wud6d079d2014-08-31 13:14:21 +08001226 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001227}
1228
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001229void cmd_batch_flush_all(struct intel_cmd *cmd)
1230{
1231 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1232 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1233 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1234 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1235 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1236 GEN6_PIPE_CONTROL_CS_STALL);
1237}
1238
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001239void cmd_batch_depth_count(struct intel_cmd *cmd,
1240 struct intel_bo *bo,
1241 XGL_GPU_SIZE offset)
1242{
1243 cmd_wa_gen6_pre_depth_stall_write(cmd);
1244
1245 gen6_PIPE_CONTROL(cmd,
1246 GEN6_PIPE_CONTROL_DEPTH_STALL |
1247 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001248 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001249}
1250
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001251void cmd_batch_timestamp(struct intel_cmd *cmd,
1252 struct intel_bo *bo,
1253 XGL_GPU_SIZE offset)
1254{
1255 /* need any WA or stall? */
1256 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1257}
1258
1259void cmd_batch_immediate(struct intel_cmd *cmd,
1260 struct intel_bo *bo,
1261 XGL_GPU_SIZE offset,
1262 uint64_t val)
1263{
1264 /* need any WA or stall? */
1265 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1266}
1267
Chia-I Wu302742d2014-08-22 10:28:29 +08001268static void gen6_cc_states(struct intel_cmd *cmd)
1269{
1270 const struct intel_blend_state *blend = cmd->bind.state.blend;
1271 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001272 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001273 uint32_t stencil_ref;
1274 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001275
1276 CMD_ASSERT(cmd, 6, 6);
1277
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001278 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001279 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001280 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1281 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001282 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001283 memset(blend_color, 0, sizeof(blend_color));
1284 }
1285
1286 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001287 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001288 stencil_ref = ds->cmd_stencil_ref;
1289 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001290 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001291 stencil_ref = 0;
1292 }
1293
Chia-I Wu72292b72014-09-09 10:48:33 +08001294 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001295
Chia-I Wu72292b72014-09-09 10:48:33 +08001296 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001297}
1298
Chia-I Wu1744cca2014-08-22 11:10:17 +08001299static void gen6_viewport_states(struct intel_cmd *cmd)
1300{
1301 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001302 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001303
1304 if (!viewport)
1305 return;
1306
Chia-I Wub1d450a2014-09-09 13:48:03 +08001307 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1308 viewport->viewport_count);
1309
1310 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1311 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1312 viewport->cmd);
1313
1314 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1315 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1316 &viewport->cmd[viewport->cmd_clip_pos]);
1317
1318 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1319 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1320 &viewport->cmd[viewport->cmd_cc_pos]);
1321
1322 if (viewport->scissor_enable) {
1323 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1324 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1325 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1326 } else {
1327 scissor_offset = 0;
1328 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001329
1330 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001331 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001332
Chia-I Wub1d450a2014-09-09 13:48:03 +08001333 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001334}
1335
Chia-I Wu302742d2014-08-22 10:28:29 +08001336static void gen7_cc_states(struct intel_cmd *cmd)
1337{
1338 const struct intel_blend_state *blend = cmd->bind.state.blend;
1339 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001340 uint32_t stencil_ref;
1341 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001342 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001343
1344 CMD_ASSERT(cmd, 7, 7.5);
1345
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001346 if (!blend && !ds)
1347 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001348
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001349 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001350 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001351 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001352 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001353
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001354 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1355 } else {
1356 memset(blend_color, 0, sizeof(blend_color));
1357 }
1358
1359 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001360 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001361 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001362 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1363 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001364 } else {
1365 stencil_ref = 0;
1366 }
1367
Chia-I Wu72292b72014-09-09 10:48:33 +08001368 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001369 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001370 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001371}
1372
Chia-I Wu1744cca2014-08-22 11:10:17 +08001373static void gen7_viewport_states(struct intel_cmd *cmd)
1374{
1375 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001376 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001377
1378 if (!viewport)
1379 return;
1380
Chia-I Wub1d450a2014-09-09 13:48:03 +08001381 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1382 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001383
Chia-I Wub1d450a2014-09-09 13:48:03 +08001384 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1385 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1386 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001387 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001388 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1389 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001390
1391 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1392 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1393 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001394 gen7_3dstate_pointer(cmd,
1395 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001396 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001397
Chia-I Wu1744cca2014-08-22 11:10:17 +08001398 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001399 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1400 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1401 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001402 gen7_3dstate_pointer(cmd,
1403 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001404 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001405 }
1406}
1407
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001408static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001409 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001410{
1411 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001412 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001413
Chia-I Wu72292b72014-09-09 10:48:33 +08001414 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001415
1416 dw[0] = GEN6_RENDER_TYPE_RENDER |
1417 GEN6_RENDER_SUBTYPE_3D |
1418 subop | (cmd_len - 2);
1419 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001420 dw[2] = 0;
1421 dw[3] = 0;
1422 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001423}
1424
1425static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001426 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001427{
1428 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001429 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001430
Chia-I Wu72292b72014-09-09 10:48:33 +08001431 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001432
1433 dw[0] = GEN6_RENDER_TYPE_RENDER |
1434 GEN6_RENDER_SUBTYPE_3D |
1435 subop | (cmd_len - 2);
1436 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001437 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001438 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001439 dw[4] = 0;
1440 dw[5] = 0;
1441 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001442}
1443
Chia-I Wu625105f2014-10-13 15:35:29 +08001444static uint32_t emit_samplers(struct intel_cmd *cmd,
1445 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001446{
1447 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1448 const XGL_UINT border_stride =
1449 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001450 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001451 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001452 XGL_UINT i;
1453
1454 CMD_ASSERT(cmd, 6, 7.5);
1455
Chia-I Wu625105f2014-10-13 15:35:29 +08001456 if (!rmap || !rmap->sampler_count)
1457 return 0;
1458
1459 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1460
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001461 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1462 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1463 border_stride * rmap->sampler_count, &border_dw);
1464
1465 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1466 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1467 4 * rmap->sampler_count, &sampler_dw);
1468
1469 for (i = 0; i < rmap->sampler_count; i++) {
1470 const struct intel_pipeline_rmap_slot *slot =
1471 &rmap->slots[surface_count + i];
1472 const struct intel_sampler *sampler;
1473
1474 switch (slot->path_len) {
1475 case 0:
1476 sampler = NULL;
1477 break;
1478 case INTEL_PIPELINE_RMAP_SLOT_RT:
1479 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1480 assert(!"unexpected rmap slot type");
1481 sampler = NULL;
1482 break;
1483 case 1:
1484 {
1485 const struct intel_dset *dset = cmd->bind.dset.graphics;
1486 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1487 const struct intel_dset_slot *dset_slot =
1488 &dset->slots[slot_offset + slot->u.index];
1489
1490 switch (dset_slot->type) {
1491 case INTEL_DSET_SLOT_SAMPLER:
1492 sampler = dset_slot->u.sampler;
1493 break;
1494 default:
1495 assert(!"unexpected dset slot type");
1496 sampler = NULL;
1497 break;
1498 }
1499 }
1500 break;
1501 default:
1502 assert(!"nested descriptor set unsupported");
1503 sampler = NULL;
1504 break;
1505 }
1506
1507 if (sampler) {
1508 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1509
1510 sampler_dw[0] = sampler->cmd[0];
1511 sampler_dw[1] = sampler->cmd[1];
1512 sampler_dw[2] = border_offset;
1513 sampler_dw[3] = sampler->cmd[2];
1514 } else {
1515 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1516 sampler_dw[1] = 0;
1517 sampler_dw[2] = 0;
1518 sampler_dw[3] = 0;
1519 }
1520
1521 border_offset += border_stride * 4;
1522 border_dw += border_stride;
1523 sampler_dw += 4;
1524 }
1525
Chia-I Wu625105f2014-10-13 15:35:29 +08001526 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001527}
1528
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001529static uint32_t emit_binding_table(struct intel_cmd *cmd,
1530 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001531{
Chia-I Wu72292b72014-09-09 10:48:33 +08001532 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001533 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001534
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001535 CMD_ASSERT(cmd, 6, 7.5);
1536
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001537 surface_count = (rmap) ?
1538 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1539 if (!surface_count)
1540 return 0;
1541
Chia-I Wu42a56202014-08-23 16:47:48 +08001542 assert(surface_count <= ARRAY_SIZE(binding_table));
1543
1544 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001545 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001546
1547 switch (slot->path_len) {
1548 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001549 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001550 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001551 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001552 {
1553 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1554
Chia-I Wu00b51a82014-09-09 12:07:37 +08001555 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001556 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1557 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001558
Chia-I Wu72292b72014-09-09 10:48:33 +08001559 cmd_reserve_reloc(cmd, 1);
1560 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1561 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001562 }
1563 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001564 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001565 {
1566 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001567 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001568
Chia-I Wu00b51a82014-09-09 12:07:37 +08001569 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001570 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1571 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001572
Chia-I Wu72292b72014-09-09 10:48:33 +08001573 cmd_reserve_reloc(cmd, 1);
1574 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1575 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001576 }
1577 break;
1578 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001579 {
1580 const struct intel_dset *dset = cmd->bind.dset.graphics;
1581 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1582 const struct intel_dset_slot *dset_slot =
1583 &dset->slots[slot_offset + slot->u.index];
1584
1585 switch (dset_slot->type) {
1586 case INTEL_DSET_SLOT_IMG_VIEW:
1587 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1588 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1589 dset_slot->u.img_view->cmd_len,
1590 dset_slot->u.img_view->cmd);
1591
1592 cmd_reserve_reloc(cmd, 1);
1593 cmd_surface_reloc(cmd, offset, 1,
1594 dset_slot->u.img_view->img->obj.mem->bo,
1595 dset_slot->u.img_view->cmd[1], 0);
1596 break;
1597 case INTEL_DSET_SLOT_MEM_VIEW:
1598 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1599 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1600 dset_slot->u.mem_view.cmd_len,
1601 dset_slot->u.mem_view.cmd);
1602
1603 cmd_reserve_reloc(cmd, 1);
1604 cmd_surface_reloc(cmd, offset, 1,
1605 dset_slot->u.mem_view.mem->bo,
1606 dset_slot->u.mem_view.cmd[1], 0);
1607 break;
1608 default:
1609 assert(!"unexpected dset slot type");
1610 break;
1611 }
1612 }
1613 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001614 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001615 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001616 break;
1617 }
1618
Chia-I Wu72292b72014-09-09 10:48:33 +08001619 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001620 }
1621
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001622 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001623 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001624 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001625}
1626
Chia-I Wu1d125092014-10-08 08:49:38 +08001627static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1628{
1629 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1630 const struct intel_pipeline_rmap *rmap = pipeline->vs.rmap;
1631 const struct intel_dset *dset = cmd->bind.dset.graphics;
1632 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1633 uint32_t *dw;
1634 XGL_UINT pos, i;
1635
1636 CMD_ASSERT(cmd, 6, 7.5);
1637
1638 if (!pipeline->vb_count)
1639 return;
1640
1641 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1642
1643 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1644 dw++;
1645 pos++;
1646
1647 for (i = 0; i < pipeline->vb_count; i++) {
1648 const XGL_UINT vb_offset = rmap->rt_count + rmap->resource_count +
1649 rmap->uav_count + rmap->sampler_count;
1650 const struct intel_pipeline_rmap_slot *slot = (i < rmap->vb_count) ?
1651 &rmap->slots[vb_offset + i] : NULL;
1652 struct intel_mem_view *view = NULL;
1653
1654 if (slot) {
1655 switch (slot->path_len) {
1656 case 1:
1657 view = (dset->slots[slot->u.index].type ==
1658 INTEL_DSET_SLOT_MEM_VIEW) ?
1659 &dset->slots[slot->u.index].u.mem_view : NULL;
1660 break;
1661 default:
1662 break;
1663 }
1664 }
1665
1666 assert(pipeline->vb[i].strideInBytes <= 2048);
1667
1668 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1669 pipeline->vb[i].strideInBytes;
1670
1671 if (cmd_gen(cmd) >= INTEL_GEN(7))
1672 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1673
1674 switch (pipeline->vb[i].stepRate) {
1675 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1676 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1677 dw[3] = 0;
1678 break;
1679 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1680 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1681 dw[3] = 1;
1682 break;
1683 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1684 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1685 dw[3] = 0;
1686 break;
1687 default:
1688 assert(!"unknown step rate");
1689 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1690 dw[3] = 0;
1691 break;
1692 }
1693
1694 if (view) {
1695 const uint32_t begin = view->cmd[1];
1696 const uint32_t end = view->mem->size - 1;
1697
1698 cmd_reserve_reloc(cmd, 2);
1699 cmd_batch_reloc(cmd, pos + 1, view->mem->bo, begin, 0);
1700 cmd_batch_reloc(cmd, pos + 2, view->mem->bo, end, 0);
1701 } else {
1702 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1703 dw[1] = 0;
1704 dw[2] = 0;
1705 }
1706
1707 dw += 4;
1708 pos += 4;
1709 }
1710}
1711
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001712static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1713{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001714 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1715 const struct intel_pipeline_shader *vs = &pipeline->vs;
1716 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001717 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001718 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001719 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001720
1721 CMD_ASSERT(cmd, 6, 7.5);
1722
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001723 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001724 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1725 *
1726 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1727 * 128-bit vertex elements to be passed into the payload for each
1728 * vertex."
1729 *
1730 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1731 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001732 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001733 vue_read_len = (vs->in_count + 1) / 2;
1734 if (!vue_read_len)
1735 vue_read_len = 1;
1736
1737 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1738 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1739
1740 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1741 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1742 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001743
1744 dw5 = GEN6_VS_DW5_STATISTICS |
1745 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001746
1747 switch (cmd_gen(cmd)) {
1748 case INTEL_GEN(7.5):
1749 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1750 break;
1751 case INTEL_GEN(7):
1752 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1753 break;
1754 case INTEL_GEN(6):
1755 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1756 break;
1757 default:
1758 max_threads = 1;
1759 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001760 }
1761
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001762 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1763 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1764 else
1765 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1766
Chia-I Wube0a3d92014-09-02 13:20:59 +08001767 if (pipeline->disable_vs_cache)
1768 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1769
Chia-I Wu72292b72014-09-09 10:48:33 +08001770 cmd_batch_pointer(cmd, cmd_len, &dw);
1771 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001772 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001773 dw[2] = dw2;
1774 dw[3] = 0; /* scratch */
1775 dw[4] = dw4;
1776 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001777}
1778
Chia-I Wu625105f2014-10-13 15:35:29 +08001779static void emit_shader_resources(struct intel_cmd *cmd)
1780{
1781 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001782 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001783
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001784 binding_tables[0] = emit_binding_table(cmd,
1785 cmd->bind.pipeline.graphics->vs.rmap);
1786 binding_tables[1] = emit_binding_table(cmd,
1787 cmd->bind.pipeline.graphics->tcs.rmap);
1788 binding_tables[2] = emit_binding_table(cmd,
1789 cmd->bind.pipeline.graphics->tes.rmap);
1790 binding_tables[3] = emit_binding_table(cmd,
1791 cmd->bind.pipeline.graphics->gs.rmap);
1792 binding_tables[4] = emit_binding_table(cmd,
1793 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001794
1795 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1796 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1797 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1798 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1799 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1800
1801 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1802 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001803 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1804 binding_tables[0]);
1805 gen7_3dstate_pointer(cmd,
1806 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1807 binding_tables[1]);
1808 gen7_3dstate_pointer(cmd,
1809 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1810 binding_tables[2]);
1811 gen7_3dstate_pointer(cmd,
1812 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1813 binding_tables[3]);
1814 gen7_3dstate_pointer(cmd,
1815 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1816 binding_tables[4]);
1817
1818 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001819 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1820 samplers[0]);
1821 gen7_3dstate_pointer(cmd,
1822 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1823 samplers[1]);
1824 gen7_3dstate_pointer(cmd,
1825 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1826 samplers[2]);
1827 gen7_3dstate_pointer(cmd,
1828 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1829 samplers[3]);
1830 gen7_3dstate_pointer(cmd,
1831 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1832 samplers[4]);
1833 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001834 assert(!binding_tables[1] && !binding_tables[2]);
1835 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1836 binding_tables[0], binding_tables[3], binding_tables[4]);
1837
Chia-I Wu625105f2014-10-13 15:35:29 +08001838 assert(!samplers[1] && !samplers[2]);
1839 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1840 samplers[0], samplers[3], samplers[4]);
1841 }
1842}
1843
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001844static void emit_rt(struct intel_cmd *cmd)
1845{
1846 cmd_wa_gen6_pre_depth_stall_write(cmd);
1847 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1848 cmd->bind.att.height);
1849}
1850
1851static void emit_ds(struct intel_cmd *cmd)
1852{
1853 const struct intel_ds_view *ds = cmd->bind.att.ds;
1854
1855 if (!ds) {
1856 /* all zeros */
1857 static const struct intel_ds_view null_ds;
1858 ds = &null_ds;
1859 }
1860
1861 cmd_wa_gen6_pre_ds_flush(cmd);
1862 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1863 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1864 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1865
1866 if (cmd_gen(cmd) >= INTEL_GEN(7))
1867 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1868 else
1869 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1870}
1871
Chia-I Wua57761b2014-10-14 14:27:44 +08001872static uint32_t emit_shader(struct intel_cmd *cmd,
1873 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001874{
Chia-I Wua57761b2014-10-14 14:27:44 +08001875 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1876 uint32_t offset;
1877 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001878
Chia-I Wua57761b2014-10-14 14:27:44 +08001879 /* see if the shader is already in the cache */
1880 for (i = 0; i < cache->used; i++) {
1881 if (cache->entries[i].shader == (const void *) shader)
1882 return cache->entries[i].kernel_offset;
1883 }
1884
1885 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1886
1887 /* grow the cache if full */
1888 if (cache->used >= cache->count) {
1889 const XGL_UINT count = cache->count + 16;
1890 void *entries;
1891
1892 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1893 XGL_SYSTEM_ALLOC_INTERNAL);
1894 if (entries) {
1895 if (cache->entries) {
1896 memcpy(entries, cache->entries,
1897 sizeof(cache->entries[0]) * cache->used);
1898 icd_free(cache->entries);
1899 }
1900
1901 cache->entries = entries;
1902 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001903 }
1904 }
1905
Chia-I Wua57761b2014-10-14 14:27:44 +08001906 /* add the shader to the cache */
1907 if (cache->used < cache->count) {
1908 cache->entries[cache->used].shader = (const void *) shader;
1909 cache->entries[cache->used].kernel_offset = offset;
1910 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001911 }
1912
Chia-I Wua57761b2014-10-14 14:27:44 +08001913 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001914}
1915
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001916static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001917{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001918 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001919
Chia-I Wu8370b402014-08-29 12:28:37 +08001920 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1921 cmd_wa_gen6_pre_depth_stall_write(cmd);
1922 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1923 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1924 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1925 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001926
1927 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001928 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001929 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001930
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001931 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001932 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001933 }
1934 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001935 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001936 }
1937 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001938 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1939 }
1940 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1941 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1942 }
1943 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1944 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001945 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001946
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001947 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1948 gen7_3DSTATE_GS(cmd);
1949 } else {
1950 gen6_3DSTATE_GS(cmd);
1951 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001952
Chia-I Wu8370b402014-08-29 12:28:37 +08001953 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1954 cmd_wa_gen7_post_command_cs_stall(cmd);
1955 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1956 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001957}
1958
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001959static void emit_bounded_states(struct intel_cmd *cmd)
1960{
1961 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1962
1963 emit_graphics_pipeline(cmd);
1964
1965 emit_rt(cmd);
1966 emit_ds(cmd);
1967
1968 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1969 gen7_cc_states(cmd);
1970 gen7_viewport_states(cmd);
1971
1972 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1973 &cmd->bind.pipeline.graphics->vs);
1974 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1975 &cmd->bind.pipeline.graphics->fs);
1976
1977 gen6_3DSTATE_CLIP(cmd);
1978 gen7_3DSTATE_SF(cmd);
1979 gen7_3DSTATE_SBE(cmd);
1980 gen7_3DSTATE_WM(cmd);
1981 gen7_3DSTATE_PS(cmd);
1982 } else {
1983 gen6_cc_states(cmd);
1984 gen6_viewport_states(cmd);
1985
1986 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1987 &cmd->bind.pipeline.graphics->vs);
1988 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1989 &cmd->bind.pipeline.graphics->fs);
1990
1991 gen6_3DSTATE_CLIP(cmd);
1992 gen6_3DSTATE_SF(cmd);
1993 gen6_3DSTATE_WM(cmd);
1994 }
1995
1996 emit_shader_resources(cmd);
1997
1998 cmd_wa_gen6_pre_depth_stall_write(cmd);
1999 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2000
2001 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2002 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2003
2004 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2005 gen6_3DSTATE_VS(cmd);
2006}
2007
Chia-I Wu6032b892014-10-17 14:47:18 +08002008static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2009{
2010 const struct intel_cmd_meta *meta = cmd->bind.meta;
2011 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2012
2013 CMD_ASSERT(cmd, 6, 7.5);
2014
2015 blend_offset = 0;
2016 ds_offset = 0;
2017 cc_offset = 0;
2018 cc_vp_offset = 0;
2019
2020 if (meta->dst.valid) {
2021 /* BLEND_STATE */
2022 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
2023 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2024 dw[0] = 0;
2025 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2026 }
2027
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002028 if (meta->ds.state) {
2029 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002030
2031 /* DEPTH_STENCIL_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002032 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002033
2034 /* COLOR_CALC_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002035 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2036 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002037
2038 /* CC_VIEWPORT */
2039 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
2040 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002041 dw[0] = u_fui(0.0f);
2042 dw[1] = u_fui(1.0f);
Chia-I Wua667c2b2014-10-28 11:40:29 +08002043 } else {
2044 /* DEPTH_STENCIL_STATE */
2045 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2046 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4,
2047 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2048 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
Chia-I Wu6032b892014-10-17 14:47:18 +08002049 }
2050
2051 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2052 gen7_3dstate_pointer(cmd,
2053 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2054 blend_offset);
2055 gen7_3dstate_pointer(cmd,
2056 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2057 ds_offset);
2058 gen7_3dstate_pointer(cmd,
2059 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2060
2061 gen7_3dstate_pointer(cmd,
2062 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2063 cc_vp_offset);
2064 } else {
2065 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002066 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002067
2068 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2069 cmd_batch_pointer(cmd, 4, &dw);
2070 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2071 GEN6_PTR_VP_DW0_CC_CHANGED;
2072 dw[1] = 0;
2073 dw[2] = 0;
2074 dw[3] = cc_vp_offset;
2075 }
2076}
2077
2078static void gen6_meta_surface_states(struct intel_cmd *cmd)
2079{
2080 const struct intel_cmd_meta *meta = cmd->bind.meta;
2081 uint32_t binding_table[2];
2082 XGL_UINT surface_count = 0;
2083 uint32_t offset;
2084
2085 CMD_ASSERT(cmd, 6, 7.5);
2086
2087 /* SURFACE_STATE */
2088 if (meta->dst.valid) {
2089 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2090 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2091 meta->dst.surface_len, meta->dst.surface);
2092
2093 cmd_reserve_reloc(cmd, 1);
2094 cmd_surface_reloc(cmd, offset, 1,
2095 (struct intel_bo *) meta->dst.reloc_target,
2096 meta->dst.reloc_offset, meta->dst.reloc_flags);
2097
2098 binding_table[surface_count++] = offset;
2099 }
2100 if (meta->src.valid) {
2101 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2102 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2103 meta->src.surface_len, meta->src.surface);
2104
2105 cmd_reserve_reloc(cmd, 1);
2106 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2107 cmd_surface_reloc_writer(cmd, offset, 1,
2108 meta->src.reloc_target, meta->src.reloc_offset);
2109 } else {
2110 cmd_surface_reloc(cmd, offset, 1,
2111 (struct intel_bo *) meta->src.reloc_target,
2112 meta->src.reloc_offset, meta->src.reloc_flags);
2113 }
2114
2115 binding_table[surface_count++] = offset;
2116 }
2117
2118 /* BINDING_TABLE */
2119 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
2120 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
2121 surface_count, binding_table);
2122
2123 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2124 gen7_3dstate_pointer(cmd,
2125 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2126 offset);
2127 } else {
2128 /* 3DSTATE_BINDING_TABLE_POINTERS */
2129 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
2130 }
2131}
2132
2133static void gen6_meta_urb(struct intel_cmd *cmd)
2134{
2135 uint32_t *dw;
2136
2137 CMD_ASSERT(cmd, 6, 6);
2138
2139 /* 3DSTATE_URB */
2140 cmd_batch_pointer(cmd, 3, &dw);
2141 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
2142 dw[1] = 128 << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
2143 dw[2] = 0;
2144}
2145
2146static void gen7_meta_urb(struct intel_cmd *cmd)
2147{
2148 uint32_t *dw;
2149
2150 CMD_ASSERT(cmd, 7, 7.5);
2151
2152 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2153 cmd_batch_pointer(cmd, 10, &dw);
2154
2155 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
2156 dw[1] = 0;
2157 dw += 2;
2158
2159 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2160 dw[1] = 0;
2161 dw += 2;
2162
2163 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2164 dw[1] = 0;
2165 dw += 2;
2166
2167 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2168 dw[1] = 0;
2169 dw += 2;
2170
2171 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2172 dw[1] = 1;
2173
2174 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2175
2176 /* 3DSTATE_URB_x */
2177 cmd_batch_pointer(cmd, 8, &dw);
2178
2179 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2180 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
2181 512;
2182 dw += 2;
2183
2184 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2185 dw[1] = 0;
2186 dw += 2;
2187
2188 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2189 dw[1] = 0;
2190 dw += 2;
2191
2192 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2193 dw[1] = 0;
2194 dw += 2;
2195}
2196
2197static void gen6_meta_vf(struct intel_cmd *cmd)
2198{
2199 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002200 uint32_t vb_start, vb_end, vb_stride;
2201 int ve_format, ve_z_source;
2202 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002203 XGL_UINT pos;
2204
2205 CMD_ASSERT(cmd, 6, 7.5);
2206
2207 /* write vertices */
Chia-I Wu3adf7212014-10-24 15:34:07 +08002208 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2209 XGL_FLOAT vertices[3][3];
2210
2211 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2212 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2213 vertices[0][2] = u_uif(meta->clear_val[0]);
2214 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2215 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2216 vertices[1][2] = u_uif(meta->clear_val[0]);
2217 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2218 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2219 vertices[2][2] = u_uif(meta->clear_val[0]);
2220
2221 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2222 sizeof(vertices) / 4, (const uint32_t *) vertices);
2223
2224 vb_end = vb_start + sizeof(vertices) - 1;
2225 vb_stride = sizeof(vertices[0]);
2226 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2227 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2228 } else {
2229 XGL_UINT vertices[3][2];
2230
2231 vertices[0][0] = meta->dst.x + meta->width;
2232 vertices[0][1] = meta->dst.y + meta->height;
2233 vertices[1][0] = meta->dst.x;
2234 vertices[1][1] = meta->dst.y + meta->height;
2235 vertices[2][0] = meta->dst.x;
2236 vertices[2][1] = meta->dst.y;
2237
2238 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2239 sizeof(vertices) / 4, (const uint32_t *) vertices);
2240
2241 vb_end = vb_start + sizeof(vertices) - 1;
2242 vb_stride = sizeof(vertices[0]);
2243 ve_z_source = GEN6_VFCOMP_STORE_0;
2244 ve_format = GEN6_FORMAT_R32G32_USCALED;
2245 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002246
2247 /* 3DSTATE_VERTEX_BUFFERS */
2248 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002249
Chia-I Wu6032b892014-10-17 14:47:18 +08002250 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002251 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002252 if (cmd_gen(cmd) >= INTEL_GEN(7))
2253 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2254
2255 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002256 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2257 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002258
2259 dw[4] = 0;
2260
2261 /* 3DSTATE_VERTEX_ELEMENTS */
2262 cmd_batch_pointer(cmd, 5, &dw);
2263 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
2264 dw[1] = GEN6_VE_STATE_DW0_VALID,
2265 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2266 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2267 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2268 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2269 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002270 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002271 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2272 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002273 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002274 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2275}
2276
2277static void gen6_meta_disabled(struct intel_cmd *cmd)
2278{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002279 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002280 uint32_t *dw;
2281
2282 CMD_ASSERT(cmd, 6, 6);
2283
2284 /* 3DSTATE_CONSTANT_VS */
2285 cmd_batch_pointer(cmd, 5, &dw);
2286 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2);
2287 dw[1] = 0;
2288 dw[2] = 0;
2289 dw[3] = 0;
2290 dw[4] = 0;
2291
2292 /* 3DSTATE_VS */
2293 cmd_batch_pointer(cmd, 6, &dw);
2294 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2295 dw[1] = 0;
2296 dw[2] = 0;
2297 dw[3] = 0;
2298 dw[4] = 0;
2299 dw[5] = 0;
2300
2301 /* 3DSTATE_CONSTANT_GS */
2302 cmd_batch_pointer(cmd, 5, &dw);
2303 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2304 dw[1] = 0;
2305 dw[2] = 0;
2306 dw[3] = 0;
2307 dw[4] = 0;
2308
2309 /* 3DSTATE_GS */
2310 cmd_batch_pointer(cmd, 7, &dw);
2311 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2312 dw[1] = 0;
2313 dw[2] = 0;
2314 dw[3] = 0;
2315 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2316 dw[5] = GEN6_GS_DW5_STATISTICS;
2317 dw[6] = 0;
2318
2319 /* 3DSTATE_CLIP */
2320 cmd_batch_pointer(cmd, 4, &dw);
2321 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2322 dw[1] = 0;
2323 dw[2] = 0;
2324 dw[3] = 0;
2325
2326 /* 3DSTATE_SF */
2327 cmd_batch_pointer(cmd, 20, &dw);
2328 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2329 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2330 memset(&dw[2], 0, 18 * sizeof(*dw));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002331
2332 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2333 /* 3DSTATE_CONSTANT_PS */
2334 cmd_batch_pointer(cmd, 5, &dw);
2335 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2336 dw[1] = 0;
2337 dw[2] = 0;
2338 dw[3] = 0;
2339 dw[4] = 0;
2340
2341 /* 3DSTATE_WM */
2342 cmd_batch_pointer(cmd, 9, &dw);
2343 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2344 dw[1] = 0;
2345 dw[2] = 0;
2346 dw[3] = 0;
2347 dw[4] = 0;
2348 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
2349 dw[6] = 0;
2350 dw[7] = 0;
2351 dw[8] = 0;
2352 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002353}
2354
2355static void gen7_meta_disabled(struct intel_cmd *cmd)
2356{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002357 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002358 uint32_t *dw;
2359
2360 CMD_ASSERT(cmd, 7, 7.5);
2361
2362 /* 3DSTATE_CONSTANT_VS */
2363 cmd_batch_pointer(cmd, 7, &dw);
2364 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2365 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2366
2367 /* 3DSTATE_VS */
2368 cmd_batch_pointer(cmd, 6, &dw);
2369 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2370 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2371
2372 /* 3DSTATE_CONSTANT_HS */
2373 cmd_batch_pointer(cmd, 7, &dw);
2374 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2375 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2376
2377 /* 3DSTATE_HS */
2378 cmd_batch_pointer(cmd, 7, &dw);
2379 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2380 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2381
2382 /* 3DSTATE_TE */
2383 cmd_batch_pointer(cmd, 4, &dw);
2384 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2385 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2386
2387 /* 3DSTATE_CONSTANT_DS */
2388 cmd_batch_pointer(cmd, 7, &dw);
2389 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2390 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2391
2392 /* 3DSTATE_DS */
2393 cmd_batch_pointer(cmd, 6, &dw);
2394 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2395 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2396
2397 /* 3DSTATE_CONSTANT_GS */
2398 cmd_batch_pointer(cmd, 7, &dw);
2399 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2400 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2401
2402 /* 3DSTATE_GS */
2403 cmd_batch_pointer(cmd, 7, &dw);
2404 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2405 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2406
2407 /* 3DSTATE_STREAMOUT */
2408 cmd_batch_pointer(cmd, 3, &dw);
2409 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2410 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2411
2412 /* 3DSTATE_CLIP */
2413 cmd_batch_pointer(cmd, 4, &dw);
2414 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2415 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2416
2417 /* 3DSTATE_SF */
2418 cmd_batch_pointer(cmd, 7, &dw);
2419 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2420 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2421
2422 /* 3DSTATE_SBE */
2423 cmd_batch_pointer(cmd, 14, &dw);
2424 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2425 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2426 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002427
2428 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2429 /* 3DSTATE_WM */
2430 cmd_batch_pointer(cmd, 3, &dw);
2431 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2432 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2433
2434 /* 3DSTATE_CONSTANT_GS */
2435 cmd_batch_pointer(cmd, 7, &dw);
2436 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2437 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2438
2439 /* 3DSTATE_PS */
2440 cmd_batch_pointer(cmd, 8, &dw);
2441 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2442 dw[1] = 0;
2443 dw[2] = 0;
2444 dw[3] = 0;
2445 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
2446 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2447 dw[5] = 0;
2448 dw[6] = 0;
2449 dw[7] = 0;
2450 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002451}
2452
2453static void gen6_meta_wm(struct intel_cmd *cmd)
2454{
2455 const struct intel_cmd_meta *meta = cmd->bind.meta;
2456 uint32_t *dw;
2457
2458 CMD_ASSERT(cmd, 6, 7.5);
2459
2460 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2461
2462 /* 3DSTATE_MULTISAMPLE */
2463 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2464 cmd_batch_pointer(cmd, 4, &dw);
2465 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2466 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2467 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2468 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2469 dw[2] = 0;
2470 dw[3] = 0;
2471 } else {
2472 cmd_batch_pointer(cmd, 3, &dw);
2473 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2474 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2475 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2476 dw[2] = 0;
2477 }
2478
2479 /* 3DSTATE_SAMPLE_MASK */
2480 cmd_batch_pointer(cmd, 2, &dw);
2481 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2482 dw[1] = (1 << meta->samples) - 1;
2483
2484 /* 3DSTATE_DRAWING_RECTANGLE */
2485 cmd_batch_pointer(cmd, 4, &dw);
2486 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2487 dw[1] = meta->dst.y << 16 | meta->dst.x;
2488 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2489 (meta->dst.x + meta->width - 1);
2490 dw[3] = 0;
2491}
2492
2493static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2494{
2495 const struct intel_cmd_meta *meta = cmd->bind.meta;
2496 XGL_UINT offset_x, offset_y;
2497 /* one GPR */
2498 XGL_UINT consts[8];
2499 XGL_UINT const_count;
2500
2501 CMD_ASSERT(cmd, 6, 7.5);
2502
2503 /* underflow is fine here */
2504 offset_x = meta->src.x - meta->dst.x;
2505 offset_y = meta->src.y - meta->dst.y;
2506
2507 switch (meta->shader_id) {
2508 case INTEL_DEV_META_FS_COPY_MEM:
2509 case INTEL_DEV_META_FS_COPY_1D:
2510 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2511 case INTEL_DEV_META_FS_COPY_2D:
2512 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2513 case INTEL_DEV_META_FS_COPY_2D_MS:
2514 consts[0] = offset_x;
2515 consts[1] = offset_y;
2516 consts[2] = meta->src.layer;
2517 consts[3] = meta->src.lod;
2518 const_count = 4;
2519 break;
2520 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2521 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2522 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2523 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2524 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2525 consts[0] = offset_x;
2526 consts[1] = offset_y;
2527 consts[2] = meta->src.layer;
2528 consts[3] = meta->src.lod;
2529 consts[4] = meta->src.x;
2530 consts[5] = meta->width;
2531 const_count = 6;
2532 break;
2533 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2534 consts[0] = offset_x;
2535 consts[1] = offset_y;
2536 consts[2] = meta->width;
2537 const_count = 3;
2538 break;
2539 case INTEL_DEV_META_FS_CLEAR_COLOR:
2540 consts[0] = meta->clear_val[0];
2541 consts[1] = meta->clear_val[1];
2542 consts[2] = meta->clear_val[2];
2543 consts[3] = meta->clear_val[3];
2544 const_count = 4;
2545 break;
2546 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2547 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002548 consts[1] = meta->clear_val[1];
2549 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002550 break;
2551 case INTEL_DEV_META_FS_RESOLVE_2X:
2552 case INTEL_DEV_META_FS_RESOLVE_4X:
2553 case INTEL_DEV_META_FS_RESOLVE_8X:
2554 case INTEL_DEV_META_FS_RESOLVE_16X:
2555 consts[0] = offset_x;
2556 consts[1] = offset_y;
2557 const_count = 2;
2558 break;
2559 default:
2560 assert(!"unknown meta shader id");
2561 const_count = 0;
2562 break;
2563 }
2564
2565 /* this can be skipped but it makes state dumping prettier */
2566 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2567
2568 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2569}
2570
2571static void gen6_meta_ps(struct intel_cmd *cmd)
2572{
2573 const struct intel_cmd_meta *meta = cmd->bind.meta;
2574 const struct intel_pipeline_shader *sh =
2575 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2576 uint32_t offset, *dw;
2577
2578 CMD_ASSERT(cmd, 6, 6);
2579
Chia-I Wu3adf7212014-10-24 15:34:07 +08002580 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2581 return;
2582 /* a normal color write */
2583 assert(meta->dst.valid && !sh->uses);
2584
Chia-I Wu6032b892014-10-17 14:47:18 +08002585 /* 3DSTATE_CONSTANT_PS */
2586 offset = gen6_meta_ps_constants(cmd);
2587 cmd_batch_pointer(cmd, 5, &dw);
2588 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2589 GEN6_PCB_ANY_DW0_PCB0_VALID;
2590 dw[1] = offset;
2591 dw[2] = 0;
2592 dw[3] = 0;
2593 dw[4] = 0;
2594
2595 /* 3DSTATE_WM */
2596 offset = emit_shader(cmd, sh);
2597 cmd_batch_pointer(cmd, 9, &dw);
2598 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2599 dw[1] = offset;
2600 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2601 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2602 dw[3] = 0;
2603 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
2604 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
2605 GEN6_WM_DW5_PS_ENABLE |
2606 GEN6_WM_DW5_8_PIXEL_DISPATCH;
2607 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2608 GEN6_WM_DW6_POSOFFSET_NONE |
2609 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2610 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2611 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2612 if (meta->samples > 1) {
2613 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2614 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2615 } else {
2616 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2617 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2618 }
2619 dw[7] = 0;
2620 dw[8] = 0;
2621}
2622
2623static void gen7_meta_ps(struct intel_cmd *cmd)
2624{
2625 const struct intel_cmd_meta *meta = cmd->bind.meta;
2626 const struct intel_pipeline_shader *sh =
2627 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2628 uint32_t offset, *dw;
2629
2630 CMD_ASSERT(cmd, 7, 7.5);
2631
Chia-I Wu3adf7212014-10-24 15:34:07 +08002632 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2633 return;
2634 /* a normal color write */
2635 assert(meta->dst.valid && !sh->uses);
2636
Chia-I Wu6032b892014-10-17 14:47:18 +08002637 /* 3DSTATE_WM */
2638 cmd_batch_pointer(cmd, 3, &dw);
2639 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2640 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2641 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2642 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2643 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2644 dw[2] = 0;
2645
2646 /* 3DSTATE_CONSTANT_PS */
2647 offset = gen6_meta_ps_constants(cmd);
2648 cmd_batch_pointer(cmd, 7, &dw);
2649 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2650 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2651 dw[2] = 0;
2652 dw[3] = offset;
2653 dw[4] = 0;
2654 dw[5] = 0;
2655 dw[6] = 0;
2656
2657 /* 3DSTATE_PS */
2658 offset = emit_shader(cmd, sh);
2659 cmd_batch_pointer(cmd, 8, &dw);
2660 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2661 dw[1] = offset;
2662 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2663 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2664 dw[3] = 0;
2665
2666 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2667 GEN7_PS_DW4_POSOFFSET_NONE |
2668 GEN7_PS_DW4_8_PIXEL_DISPATCH |
2669 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2670 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
2671 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
2672
2673 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2674 dw[6] = 0;
2675 dw[7] = 0;
2676}
2677
2678static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2679{
2680 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002681 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002682
2683 CMD_ASSERT(cmd, 6, 7.5);
2684
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002685 if (!ds) {
2686 /* all zeros */
2687 static const struct intel_ds_view null_ds;
2688 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002689 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002690
2691 cmd_wa_gen6_pre_ds_flush(cmd);
2692 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2693 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2694 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2695
2696 if (cmd_gen(cmd) >= INTEL_GEN(7))
2697 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2698 else
2699 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002700}
2701
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002702static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2703 const struct intel_pipeline *pipeline)
2704{
2705 cmd->bind.pipeline.graphics = pipeline;
2706}
2707
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002708static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2709 const struct intel_pipeline *pipeline)
2710{
2711 cmd->bind.pipeline.compute = pipeline;
2712}
2713
2714static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2715 const struct intel_pipeline_delta *delta)
2716{
2717 cmd->bind.pipeline.graphics_delta = delta;
2718}
2719
2720static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2721 const struct intel_pipeline_delta *delta)
2722{
2723 cmd->bind.pipeline.compute_delta = delta;
2724}
2725
2726static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2727 const struct intel_dset *dset,
2728 XGL_UINT slot_offset)
2729{
2730 cmd->bind.dset.graphics = dset;
2731 cmd->bind.dset.graphics_offset = slot_offset;
2732}
2733
2734static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2735 const struct intel_dset *dset,
2736 XGL_UINT slot_offset)
2737{
2738 cmd->bind.dset.compute = dset;
2739 cmd->bind.dset.compute_offset = slot_offset;
2740}
2741
2742static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2743 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2744{
2745 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2746}
2747
2748static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2749 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2750{
2751 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2752}
2753
2754static void cmd_bind_index_data(struct intel_cmd *cmd,
2755 const struct intel_mem *mem,
2756 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2757{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002758 cmd->bind.index.mem = mem;
2759 cmd->bind.index.offset = offset;
2760 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002761}
2762
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002763static void cmd_bind_attachments(struct intel_cmd *cmd,
2764 XGL_UINT rt_count,
2765 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2766 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002767{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002768 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002769 XGL_UINT i;
2770
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002771 for (i = 0; i < rt_count; i++) {
2772 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002773 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002774 const struct intel_layout *layout = &rt->img->layout;
2775
2776 if (i == 0) {
2777 width = layout->width0;
2778 height = layout->height0;
2779 } else {
2780 if (width > layout->width0)
2781 width = layout->width0;
2782 if (height > layout->height0)
2783 height = layout->height0;
2784 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002785
2786 cmd->bind.att.rt[i] = rt;
2787 }
2788
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002789 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002790
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002791 if (ds_info) {
2792 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002793
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002794 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2795 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002796
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002797 if (width > layout->width0)
2798 width = layout->width0;
2799 if (height > layout->height0)
2800 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002801 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002802 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002803 }
2804
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002805 cmd->bind.att.width = width;
2806 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002807}
2808
2809static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2810 const struct intel_viewport_state *state)
2811{
2812 cmd->bind.state.viewport = state;
2813}
2814
2815static void cmd_bind_raster_state(struct intel_cmd *cmd,
2816 const struct intel_raster_state *state)
2817{
2818 cmd->bind.state.raster = state;
2819}
2820
2821static void cmd_bind_ds_state(struct intel_cmd *cmd,
2822 const struct intel_ds_state *state)
2823{
2824 cmd->bind.state.ds = state;
2825}
2826
2827static void cmd_bind_blend_state(struct intel_cmd *cmd,
2828 const struct intel_blend_state *state)
2829{
2830 cmd->bind.state.blend = state;
2831}
2832
2833static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2834 const struct intel_msaa_state *state)
2835{
2836 cmd->bind.state.msaa = state;
2837}
2838
2839static void cmd_draw(struct intel_cmd *cmd,
2840 XGL_UINT vertex_start,
2841 XGL_UINT vertex_count,
2842 XGL_UINT instance_start,
2843 XGL_UINT instance_count,
2844 bool indexed,
2845 XGL_UINT vertex_base)
2846{
2847 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2848
2849 emit_bounded_states(cmd);
2850
2851 if (indexed) {
2852 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2853 cmd->result = XGL_ERROR_UNKNOWN;
2854
2855 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2856 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2857 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002858 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2859 cmd->bind.index.offset, cmd->bind.index.type,
2860 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002861 } else {
2862 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2863 cmd->bind.index.offset, cmd->bind.index.type,
2864 p->primitive_restart);
2865 }
2866 } else {
2867 assert(!vertex_base);
2868 }
2869
2870 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2871 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2872 vertex_start, instance_count, instance_start, vertex_base);
2873 } else {
2874 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2875 vertex_start, instance_count, instance_start, vertex_base);
2876 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002877
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002878 if (intel_debug & INTEL_DEBUG_NOCACHE)
2879 cmd_batch_flush_all(cmd);
2880
Chia-I Wu707a29e2014-08-27 12:51:47 +08002881 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002882 /* need to re-emit all workarounds */
2883 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002884}
2885
Chia-I Wuc14d1562014-10-17 09:49:22 +08002886void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2887{
Chia-I Wu6032b892014-10-17 14:47:18 +08002888 cmd->bind.meta = meta;
2889
2890 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08002891 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002892
2893 gen6_meta_dynamic_states(cmd);
2894 gen6_meta_surface_states(cmd);
2895
2896 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2897 gen7_meta_urb(cmd);
2898 gen6_meta_vf(cmd);
2899 gen7_meta_disabled(cmd);
2900 gen6_meta_wm(cmd);
2901 gen7_meta_ps(cmd);
2902 gen6_meta_depth_buffer(cmd);
2903
2904 cmd_wa_gen7_post_command_cs_stall(cmd);
2905 cmd_wa_gen7_post_command_depth_stall(cmd);
2906
2907 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2908 } else {
2909 gen6_meta_urb(cmd);
2910 gen6_meta_vf(cmd);
2911 gen6_meta_disabled(cmd);
2912 gen6_meta_wm(cmd);
2913 gen6_meta_ps(cmd);
2914 gen6_meta_depth_buffer(cmd);
2915
2916 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2917 }
2918
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002919 if (intel_debug & INTEL_DEBUG_NOCACHE)
2920 cmd_batch_flush_all(cmd);
2921
Chia-I Wu6032b892014-10-17 14:47:18 +08002922 cmd->bind.draw_count++;
2923 /* need to re-emit all workarounds */
2924 cmd->bind.wa_flags = 0;
2925
2926 cmd->bind.meta = NULL;
Chia-I Wuc14d1562014-10-17 09:49:22 +08002927}
2928
Chia-I Wub2755562014-08-20 13:38:52 +08002929XGL_VOID XGLAPI intelCmdBindPipeline(
2930 XGL_CMD_BUFFER cmdBuffer,
2931 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2932 XGL_PIPELINE pipeline)
2933{
2934 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2935
2936 switch (pipelineBindPoint) {
2937 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002938 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002939 break;
2940 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002941 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002942 break;
2943 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002944 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002945 break;
2946 }
2947}
2948
2949XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2950 XGL_CMD_BUFFER cmdBuffer,
2951 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2952 XGL_PIPELINE_DELTA delta)
2953{
2954 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2955
2956 switch (pipelineBindPoint) {
2957 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002958 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002959 break;
2960 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002961 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002962 break;
2963 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002964 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002965 break;
2966 }
2967}
2968
2969XGL_VOID XGLAPI intelCmdBindStateObject(
2970 XGL_CMD_BUFFER cmdBuffer,
2971 XGL_STATE_BIND_POINT stateBindPoint,
2972 XGL_STATE_OBJECT state)
2973{
2974 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2975
2976 switch (stateBindPoint) {
2977 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002978 cmd_bind_viewport_state(cmd,
2979 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002980 break;
2981 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002982 cmd_bind_raster_state(cmd,
2983 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002984 break;
2985 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002986 cmd_bind_ds_state(cmd,
2987 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002988 break;
2989 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002990 cmd_bind_blend_state(cmd,
2991 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002992 break;
2993 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002994 cmd_bind_msaa_state(cmd,
2995 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002996 break;
2997 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002998 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002999 break;
3000 }
3001}
3002
3003XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3004 XGL_CMD_BUFFER cmdBuffer,
3005 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3006 XGL_UINT index,
3007 XGL_DESCRIPTOR_SET descriptorSet,
3008 XGL_UINT slotOffset)
3009{
3010 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3011 struct intel_dset *dset = intel_dset(descriptorSet);
3012
3013 assert(!index);
3014
3015 switch (pipelineBindPoint) {
3016 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003017 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003018 break;
3019 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003020 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003021 break;
3022 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003023 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003024 break;
3025 }
3026}
3027
3028XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3029 XGL_CMD_BUFFER cmdBuffer,
3030 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3031 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3032{
3033 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3034
3035 switch (pipelineBindPoint) {
3036 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003037 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003038 break;
3039 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003040 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003041 break;
3042 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003043 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003044 break;
3045 }
3046}
3047
3048XGL_VOID XGLAPI intelCmdBindIndexData(
3049 XGL_CMD_BUFFER cmdBuffer,
3050 XGL_GPU_MEMORY mem_,
3051 XGL_GPU_SIZE offset,
3052 XGL_INDEX_TYPE indexType)
3053{
3054 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3055 struct intel_mem *mem = intel_mem(mem_);
3056
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003057 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003058}
3059
3060XGL_VOID XGLAPI intelCmdBindAttachments(
3061 XGL_CMD_BUFFER cmdBuffer,
3062 XGL_UINT colorAttachmentCount,
3063 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3064 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3065{
3066 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003067
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003068 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3069 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003070}
3071
3072XGL_VOID XGLAPI intelCmdDraw(
3073 XGL_CMD_BUFFER cmdBuffer,
3074 XGL_UINT firstVertex,
3075 XGL_UINT vertexCount,
3076 XGL_UINT firstInstance,
3077 XGL_UINT instanceCount)
3078{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003079 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003080
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003081 cmd_draw(cmd, firstVertex, vertexCount,
3082 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003083}
3084
3085XGL_VOID XGLAPI intelCmdDrawIndexed(
3086 XGL_CMD_BUFFER cmdBuffer,
3087 XGL_UINT firstIndex,
3088 XGL_UINT indexCount,
3089 XGL_INT vertexOffset,
3090 XGL_UINT firstInstance,
3091 XGL_UINT instanceCount)
3092{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003093 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003094
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003095 cmd_draw(cmd, firstIndex, indexCount,
3096 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003097}
3098
3099XGL_VOID XGLAPI intelCmdDrawIndirect(
3100 XGL_CMD_BUFFER cmdBuffer,
3101 XGL_GPU_MEMORY mem,
3102 XGL_GPU_SIZE offset,
3103 XGL_UINT32 count,
3104 XGL_UINT32 stride)
3105{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003106 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3107
3108 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003109}
3110
3111XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3112 XGL_CMD_BUFFER cmdBuffer,
3113 XGL_GPU_MEMORY mem,
3114 XGL_GPU_SIZE offset,
3115 XGL_UINT32 count,
3116 XGL_UINT32 stride)
3117{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003118 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3119
3120 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003121}
3122
3123XGL_VOID XGLAPI intelCmdDispatch(
3124 XGL_CMD_BUFFER cmdBuffer,
3125 XGL_UINT x,
3126 XGL_UINT y,
3127 XGL_UINT z)
3128{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003129 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3130
3131 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003132}
3133
3134XGL_VOID XGLAPI intelCmdDispatchIndirect(
3135 XGL_CMD_BUFFER cmdBuffer,
3136 XGL_GPU_MEMORY mem,
3137 XGL_GPU_SIZE offset)
3138{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003139 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3140
3141 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003142}