blob: ccf238720ff684ed73b2ad547a44e775017c36e2 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080030#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080031#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080032#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080033#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080034#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080035#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080036#include "state.h"
37#include "view.h"
38#include "cmd_priv.h"
39
Chia-I Wu59c097e2014-08-21 10:51:07 +080040static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080041 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080042 uint32_t vertex_count,
43 uint32_t vertex_start,
44 uint32_t instance_count,
45 uint32_t instance_start,
46 uint32_t vertex_base)
47{
48 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080049 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080050
51 CMD_ASSERT(cmd, 6, 6);
52
Chia-I Wu426072d2014-08-26 14:31:55 +080053 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080054 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080055 (cmd_len - 2);
56
57 if (indexed)
58 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
59
Chia-I Wu72292b72014-09-09 10:48:33 +080060 cmd_batch_pointer(cmd, cmd_len, &dw);
61 dw[0] = dw0;
62 dw[1] = vertex_count;
63 dw[2] = vertex_start;
64 dw[3] = instance_count;
65 dw[4] = instance_start;
66 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080067}
68
69static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080070 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080071 uint32_t vertex_count,
72 uint32_t vertex_start,
73 uint32_t instance_count,
74 uint32_t instance_start,
75 uint32_t vertex_base)
76{
77 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080078 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080079
80 CMD_ASSERT(cmd, 7, 7.5);
81
Chia-I Wu426072d2014-08-26 14:31:55 +080082 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080083 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080084
85 if (indexed)
86 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
87
Chia-I Wu72292b72014-09-09 10:48:33 +080088 cmd_batch_pointer(cmd, cmd_len, &dw);
89 dw[0] = dw0;
90 dw[1] = dw1;
91 dw[2] = vertex_count;
92 dw[3] = vertex_start;
93 dw[4] = instance_count;
94 dw[5] = instance_start;
95 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080096}
97
Chia-I Wu270b1e82014-08-25 15:53:39 +080098static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +080099 struct intel_bo *bo, uint32_t bo_offset,
100 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800101{
102 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800103 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800104 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800105 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800106 uint32_t *dw;
107 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800108
109 CMD_ASSERT(cmd, 6, 7.5);
110
111 assert(bo_offset % 8 == 0);
112
113 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
114 /*
115 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
116 *
117 * "1 of the following must also be set (when CS stall is set):
118 *
119 * * Depth Cache Flush Enable ([0] of DW1)
120 * * Stall at Pixel Scoreboard ([1] of DW1)
121 * * Depth Stall ([13] of DW1)
122 * * Post-Sync Operation ([13] of DW1)
123 * * Render Target Cache Flush Enable ([12] of DW1)
124 * * Notify Enable ([8] of DW1)"
125 *
126 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
127 *
128 * "One of the following must also be set (when CS stall is set):
129 *
130 * * Render Target Cache Flush Enable ([12] of DW1)
131 * * Depth Cache Flush Enable ([0] of DW1)
132 * * Stall at Pixel Scoreboard ([1] of DW1)
133 * * Depth Stall ([13] of DW1)
134 * * Post-Sync Operation ([13] of DW1)"
135 */
136 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
137 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
138 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
139 GEN6_PIPE_CONTROL_DEPTH_STALL;
140
141 /* post-sync op */
142 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
143 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
144 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
145
146 if (cmd_gen(cmd) == INTEL_GEN(6))
147 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
148
149 assert(dw1 & bit_test);
150 }
151
152 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
153 /*
154 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
155 *
156 * "Following bits must be clear (when Depth Stall is set):
157 *
158 * * Render Target Cache Flush Enable ([12] of DW1)
159 * * Depth Cache Flush Enable ([0] of DW1)"
160 */
161 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
162 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
163 }
164
165 /*
166 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
167 *
168 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
169 * and PIPE_CONTROL are not supported."
170 *
171 * The kernel will add the mapping automatically (when write domain is
172 * INTEL_DOMAIN_INSTRUCTION).
173 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800174 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800175 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 reloc_flags |= INTEL_RELOC_GGTT;
177 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800178
Chia-I Wu72292b72014-09-09 10:48:33 +0800179 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
180 dw[0] = dw0;
181 dw[1] = dw1;
182 dw[2] = 0;
183 dw[3] = (uint32_t) imm;
184 dw[4] = (uint32_t) (imm >> 32);
185
186 if (bo) {
187 cmd_reserve_reloc(cmd, 1);
188 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
189 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800190}
191
Chia-I Wu254db422014-08-21 11:54:29 +0800192static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
193{
194 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
195 bool supported;
196
197 CMD_ASSERT(cmd, 6, 7.5);
198
199 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
200 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
201
202 switch (p->prim_type) {
203 case GEN6_3DPRIM_POINTLIST:
204 case GEN6_3DPRIM_LINELIST:
205 case GEN6_3DPRIM_LINESTRIP:
206 case GEN6_3DPRIM_TRILIST:
207 case GEN6_3DPRIM_TRISTRIP:
208 supported = true;
209 break;
210 default:
211 supported = false;
212 break;
213 }
214
215 if (!supported)
216 return false;
217
218 switch (cmd->bind.index.type) {
219 case XGL_INDEX_8:
220 supported = (p->primitive_restart_index != 0xffu);
221 break;
222 case XGL_INDEX_16:
223 supported = (p->primitive_restart_index != 0xffffu);
224 break;
225 case XGL_INDEX_32:
226 supported = (p->primitive_restart_index != 0xffffffffu);
227 break;
228 default:
229 supported = false;
230 break;
231 }
232
233 return supported;
234}
235
Chia-I Wu59c097e2014-08-21 10:51:07 +0800236static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800237 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238 XGL_GPU_SIZE offset,
239 XGL_INDEX_TYPE type,
240 bool enable_cut_index)
241{
242 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800243 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800244 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246
247 CMD_ASSERT(cmd, 6, 7.5);
248
Chia-I Wu426072d2014-08-26 14:31:55 +0800249 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800250
251 /* the bit is moved to 3DSTATE_VF */
252 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
253 assert(!enable_cut_index);
254 if (enable_cut_index)
255 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
256
257 switch (type) {
258 case XGL_INDEX_8:
259 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
260 offset_align = 1;
261 break;
262 case XGL_INDEX_16:
263 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
264 offset_align = 2;
265 break;
266 case XGL_INDEX_32:
267 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
268 offset_align = 4;
269 break;
270 default:
271 cmd->result = XGL_ERROR_INVALID_VALUE;
272 return;
273 break;
274 }
275
276 if (offset % offset_align) {
277 cmd->result = XGL_ERROR_INVALID_VALUE;
278 return;
279 }
280
281 /* aligned and inclusive */
282 end_offset = mem->size - (mem->size % offset_align) - 1;
283
Chia-I Wu72292b72014-09-09 10:48:33 +0800284 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
285 dw[0] = dw0;
286
287 cmd_reserve_reloc(cmd, 2);
288 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
289 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800290}
291
Chia-I Wu62a7f252014-08-29 11:31:16 +0800292static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
293 bool enable_cut_index,
294 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800295{
296 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800297 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800298
299 CMD_ASSERT(cmd, 7.5, 7.5);
300
Chia-I Wu426072d2014-08-26 14:31:55 +0800301 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800302 if (enable_cut_index)
303 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
304
Chia-I Wu72292b72014-09-09 10:48:33 +0800305 cmd_batch_pointer(cmd, cmd_len, &dw);
306 dw[0] = dw0;
307 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800308}
309
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600310
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800311static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
312{
313 const uint8_t cmd_len = 7;
314 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800315 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800316
317 CMD_ASSERT(cmd, 6, 6);
318
Chia-I Wu72292b72014-09-09 10:48:33 +0800319 cmd_batch_pointer(cmd, cmd_len, &dw);
320 dw[0] = dw0;
321 dw[1] = 0;
322 dw[2] = 0;
323 dw[3] = 0;
324 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
325 dw[5] = GEN6_GS_DW5_STATISTICS;
326 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800327}
328
Chia-I Wu62a7f252014-08-29 11:31:16 +0800329static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
330{
331 const uint8_t cmd_len = 7;
332 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800333 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800334
335 CMD_ASSERT(cmd, 7, 7.5);
336
Chia-I Wu72292b72014-09-09 10:48:33 +0800337 cmd_batch_pointer(cmd, cmd_len, &dw);
338 dw[0] = dw0;
339 dw[1] = 0;
340 dw[2] = 0;
341 dw[3] = 0;
342 dw[4] = 0;
343 dw[5] = GEN6_GS_DW5_STATISTICS;
344 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800345}
346
Chia-I Wud88e02d2014-08-25 10:56:13 +0800347static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
348 XGL_UINT width, XGL_UINT height)
349{
350 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800351 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800352 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800353 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354
355 CMD_ASSERT(cmd, 6, 7.5);
356
Chia-I Wu72292b72014-09-09 10:48:33 +0800357 cmd_batch_pointer(cmd, cmd_len, &dw);
358 dw[0] = dw0;
359
Chia-I Wud88e02d2014-08-25 10:56:13 +0800360 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800361 dw[1] = 0;
362 dw[2] = (height - 1) << 16 |
363 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800364 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800365 dw[1] = 1;
366 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800367 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800368
369 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800370}
371
Chia-I Wu8016a172014-08-29 18:31:32 +0800372static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
373 uint32_t body[6])
374{
375 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
376 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
377 const struct intel_raster_state *raster = cmd->bind.state.raster;
378 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
389 raster->cmd_sf_fill;
390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
394 switch (pipeline->db_format.channelFormat) {
395 case XGL_CH_FMT_R16:
396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
398 case XGL_CH_FMT_R32:
399 case XGL_CH_FMT_R32G8:
400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
403 assert(!"unknown depth format");
404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
411 dw2 = raster->cmd_sf_cull;
412
413 if (msaa->sample_count > 1) {
414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
421 if (viewport->scissor_enable)
422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
425 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
438 body[3] = raster->cmd_depth_offset_const;
439 body[4] = raster->cmd_depth_offset_scale;
440 body[5] = raster->cmd_depth_offset_clamp;
441}
442
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800446 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
447 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448 XGL_UINT attr_skip, attr_count;
449 XGL_UINT vue_offset, vue_len;
450 XGL_UINT i;
451 uint32_t dw1;
452
453 CMD_ASSERT(cmd, 6, 7.5);
454
455 /* VS outputs VUE header and position additionally */
456 assert(vs->out_count >= 2);
457 attr_skip = 2;
458 attr_count = vs->out_count - attr_skip;
459 assert(fs->in_count == attr_count);
460 assert(fs->in_count <= 32);
461
462 vue_offset = attr_skip / 2;
463 vue_len = (attr_count + 1) / 2;
464 if (!vue_len)
465 vue_len = 1;
466
467 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
468 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
469 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
470
471 body[0] = dw1;
472
473 for (i = 0; i < 8; i++) {
474 uint16_t hi, lo;
475
476 /* no attr swizzles */
477 if (i * 2 + 1 < fs->in_count) {
478 hi = i * 2 + 1;
479 lo = i * 2;
480 } else if (i * 2 < fs->in_count) {
481 hi = 0;
482 lo = i * 2;
483 } else {
484 hi = 0;
485 lo = 0;
486 }
487
488 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
489 }
490
491 body[9] = 0; /* point sprite enables */
492 body[10] = 0; /* constant interpolation enables */
493 body[11] = 0; /* WrapShortest enables */
494 body[12] = 0;
495}
496
497static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
498{
499 const uint8_t cmd_len = 20;
500 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
501 (cmd_len - 2);
502 uint32_t sf[6];
503 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800504 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800505
506 CMD_ASSERT(cmd, 6, 6);
507
508 gen7_fill_3DSTATE_SF_body(cmd, sf);
509 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
510
Chia-I Wu72292b72014-09-09 10:48:33 +0800511 cmd_batch_pointer(cmd, cmd_len, &dw);
512 dw[0] = dw0;
513 dw[1] = sbe[0];
514 memcpy(&dw[2], sf, sizeof(sf));
515 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800516}
517
518static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
519{
520 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800521 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800522
523 CMD_ASSERT(cmd, 7, 7.5);
524
Chia-I Wu72292b72014-09-09 10:48:33 +0800525 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800526 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
527 (cmd_len - 2);
528 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800529}
530
531static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
532{
533 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800534 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800535
536 CMD_ASSERT(cmd, 7, 7.5);
537
Chia-I Wu72292b72014-09-09 10:48:33 +0800538 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800539 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
540 (cmd_len - 2);
541 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800542}
543
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800544static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
545{
546 const uint8_t cmd_len = 4;
547 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
548 (cmd_len - 2);
549 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800550 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800551 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
552 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800553 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800554
555 CMD_ASSERT(cmd, 6, 7.5);
556
557 dw1 = GEN6_CLIP_DW1_STATISTICS;
558 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
559 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
560 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
561 raster->cmd_clip_cull;
562 }
563
564 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
565 GEN6_CLIP_DW2_XY_TEST_ENABLE |
566 GEN6_CLIP_DW2_APIMODE_OGL |
567 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
568 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
569 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
570
571 if (pipeline->rasterizerDiscardEnable)
572 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
573 else
574 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
575
576 if (pipeline->depthClipEnable)
577 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
578
579 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
580 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
581 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
582 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
583
584 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
585 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
586 (viewport->viewport_count - 1);
587
Chia-I Wu72292b72014-09-09 10:48:33 +0800588 cmd_batch_pointer(cmd, cmd_len, &dw);
589 dw[0] = dw0;
590 dw[1] = dw1;
591 dw[2] = dw2;
592 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800593}
594
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800595static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
596{
597 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
598 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800599 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800600 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
601 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800602 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800603
604 CMD_ASSERT(cmd, 6, 6);
605
606 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
607
608 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
609 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
610
611 dw4 = GEN6_WM_DW4_STATISTICS |
612 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
613 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
614 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
615
616 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
617 GEN6_WM_DW5_PS_ENABLE |
618 GEN6_WM_DW5_8_PIXEL_DISPATCH;
619
620 if (fs->uses & INTEL_SHADER_USE_KILL ||
621 pipeline->cb_state.alphaToCoverageEnable)
622 dw5 |= GEN6_WM_DW5_PS_KILL;
623
624 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
625 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
626 if (fs->uses & INTEL_SHADER_USE_DEPTH)
627 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
628 if (fs->uses & INTEL_SHADER_USE_W)
629 dw5 |= GEN6_WM_DW5_PS_USE_W;
630
631 if (pipeline->cb_state.dualSourceBlendEnable)
632 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
633
634 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
635 GEN6_WM_DW6_POSOFFSET_NONE |
636 GEN6_WM_DW6_ZW_INTERP_PIXEL |
637 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
638 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
639
640 if (msaa->sample_count > 1) {
641 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
642 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
643 } else {
644 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
645 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
646 }
647
Chia-I Wu72292b72014-09-09 10:48:33 +0800648 cmd_batch_pointer(cmd, cmd_len, &dw);
649 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800650 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800651 dw[2] = dw2;
652 dw[3] = 0; /* scratch */
653 dw[4] = dw4;
654 dw[5] = dw5;
655 dw[6] = dw6;
656 dw[7] = 0; /* kernel 1 */
657 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800658}
659
660static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
661{
662 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800663 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800664 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
665 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800666 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667
668 CMD_ASSERT(cmd, 7, 7.5);
669
670 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
671
672 dw1 = GEN7_WM_DW1_STATISTICS |
673 GEN7_WM_DW1_PS_ENABLE |
674 GEN7_WM_DW1_ZW_INTERP_PIXEL |
675 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
676 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
677
678 if (fs->uses & INTEL_SHADER_USE_KILL ||
679 pipeline->cb_state.alphaToCoverageEnable)
680 dw1 |= GEN7_WM_DW1_PS_KILL;
681
682 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
683 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
684 if (fs->uses & INTEL_SHADER_USE_DEPTH)
685 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
686 if (fs->uses & INTEL_SHADER_USE_W)
687 dw1 |= GEN7_WM_DW1_PS_USE_W;
688
689 dw2 = 0;
690
691 if (msaa->sample_count > 1) {
692 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
693 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
694 } else {
695 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
696 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
697 }
698
Chia-I Wu72292b72014-09-09 10:48:33 +0800699 cmd_batch_pointer(cmd, cmd_len, &dw);
700 dw[0] = dw0;
701 dw[1] = dw1;
702 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800703}
704
705static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
706{
707 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800708 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800709 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
710 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800711 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800712
713 CMD_ASSERT(cmd, 7, 7.5);
714
715 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
716
717 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
718 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
719
720 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
721 GEN7_PS_DW4_8_PIXEL_DISPATCH;
722
723 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
724 const int max_threads =
725 (cmd->dev->gpu->gt == 3) ? 408 :
726 (cmd->dev->gpu->gt == 2) ? 204 : 102;
727 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
728 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
729 } else {
730 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
731 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
732 }
733
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800734 if (fs->in_count)
735 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
736
737 if (pipeline->cb_state.dualSourceBlendEnable)
738 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
739
740 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
741 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
742 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
743
Chia-I Wu72292b72014-09-09 10:48:33 +0800744 cmd_batch_pointer(cmd, cmd_len, &dw);
745 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800746 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800747 dw[2] = dw2;
748 dw[3] = 0; /* scratch */
749 dw[4] = dw4;
750 dw[5] = dw5;
751 dw[6] = 0; /* kernel 1 */
752 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800753}
754
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800755static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
756 const struct intel_ds_view *view)
757{
758 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800759 uint32_t dw0, *dw;
760 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800761
762 CMD_ASSERT(cmd, 6, 7.5);
763
764 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800765 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
766 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767 dw0 |= (cmd_len - 2);
768
Chia-I Wu72292b72014-09-09 10:48:33 +0800769 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
770 dw[0] = dw0;
771 dw[1] = view->cmd[0];
772 dw[2] = 0;
773 dw[3] = view->cmd[2];
774 dw[4] = view->cmd[3];
775 dw[5] = view->cmd[4];
776 dw[6] = view->cmd[5];
777
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600778 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800779 cmd_reserve_reloc(cmd, 1);
780 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
781 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600782 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800783}
784
785static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
786 const struct intel_ds_view *view)
787{
788 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800789 uint32_t dw0, *dw;
790 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800791
792 CMD_ASSERT(cmd, 6, 7.5);
793
794 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800795 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
796 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797 dw0 |= (cmd_len - 2);
798
Chia-I Wu72292b72014-09-09 10:48:33 +0800799 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
800 dw[0] = dw0;
801 dw[1] = view->cmd[6];
802 dw[2] = 0;
803
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600804 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800805 cmd_reserve_reloc(cmd, 1);
806 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
807 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600808 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800809}
810
811static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
812 const struct intel_ds_view *view)
813{
814 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800815 uint32_t dw0, *dw;
816 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800817
818 CMD_ASSERT(cmd, 6, 7.5);
819
820 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800821 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
822 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800823 dw0 |= (cmd_len - 2);
824
Chia-I Wu72292b72014-09-09 10:48:33 +0800825 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
826 dw[0] = dw0;
827 dw[1] = view->cmd[8];
828 dw[2] = 0;
829
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600830 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800831 cmd_reserve_reloc(cmd, 1);
832 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
833 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600834 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800835}
836
Chia-I Wuf8231032014-08-25 10:44:45 +0800837static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
838 uint32_t clear_val)
839{
840 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800841 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800842 GEN6_CLEAR_PARAMS_DW0_VALID |
843 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800844 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800845
846 CMD_ASSERT(cmd, 6, 6);
847
Chia-I Wu72292b72014-09-09 10:48:33 +0800848 cmd_batch_pointer(cmd, cmd_len, &dw);
849 dw[0] = dw0;
850 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800851}
852
853static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
854 uint32_t clear_val)
855{
856 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800857 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800858 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800859 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800860
861 CMD_ASSERT(cmd, 7, 7.5);
862
Chia-I Wu72292b72014-09-09 10:48:33 +0800863 cmd_batch_pointer(cmd, cmd_len, &dw);
864 dw[0] = dw0;
865 dw[1] = clear_val;
866 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800867}
868
Chia-I Wu302742d2014-08-22 10:28:29 +0800869static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t blend_offset,
871 uint32_t ds_offset,
872 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800873{
874 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800876
877 CMD_ASSERT(cmd, 6, 6);
878
Chia-I Wu426072d2014-08-26 14:31:55 +0800879 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800880 (cmd_len - 2);
881
Chia-I Wu72292b72014-09-09 10:48:33 +0800882 cmd_batch_pointer(cmd, cmd_len, &dw);
883 dw[0] = dw0;
884 dw[1] = blend_offset | 1;
885 dw[2] = ds_offset | 1;
886 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800887}
888
Chia-I Wu1744cca2014-08-22 11:10:17 +0800889static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800890 uint32_t clip_offset,
891 uint32_t sf_offset,
892 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800893{
894 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800895 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896
897 CMD_ASSERT(cmd, 6, 6);
898
Chia-I Wu426072d2014-08-26 14:31:55 +0800899 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800900 GEN6_PTR_VP_DW0_CLIP_CHANGED |
901 GEN6_PTR_VP_DW0_SF_CHANGED |
902 GEN6_PTR_VP_DW0_CC_CHANGED |
903 (cmd_len - 2);
904
Chia-I Wu72292b72014-09-09 10:48:33 +0800905 cmd_batch_pointer(cmd, cmd_len, &dw);
906 dw[0] = dw0;
907 dw[1] = clip_offset;
908 dw[2] = sf_offset;
909 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800910}
911
912static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800913 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800914{
915 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800917
918 CMD_ASSERT(cmd, 6, 6);
919
Chia-I Wu426072d2014-08-26 14:31:55 +0800920 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800921 (cmd_len - 2);
922
Chia-I Wu72292b72014-09-09 10:48:33 +0800923 cmd_batch_pointer(cmd, cmd_len, &dw);
924 dw[0] = dw0;
925 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800926}
927
Chia-I Wu42a56202014-08-23 16:47:48 +0800928static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800929 uint32_t vs_offset,
930 uint32_t gs_offset,
931 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800932{
933 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800934 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800935
936 CMD_ASSERT(cmd, 6, 6);
937
Chia-I Wu426072d2014-08-26 14:31:55 +0800938 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800939 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
940 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
941 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
942 (cmd_len - 2);
943
Chia-I Wu72292b72014-09-09 10:48:33 +0800944 cmd_batch_pointer(cmd, cmd_len, &dw);
945 dw[0] = dw0;
946 dw[1] = vs_offset;
947 dw[2] = gs_offset;
948 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800949}
950
Chia-I Wu257e75e2014-08-29 14:06:35 +0800951static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800952 uint32_t vs_offset,
953 uint32_t gs_offset,
954 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800955{
956 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800958
959 CMD_ASSERT(cmd, 6, 6);
960
961 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
962 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
963 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
964 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
965 (cmd_len - 2);
966
Chia-I Wu72292b72014-09-09 10:48:33 +0800967 cmd_batch_pointer(cmd, cmd_len, &dw);
968 dw[0] = dw0;
969 dw[1] = vs_offset;
970 dw[2] = gs_offset;
971 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800972}
973
Chia-I Wu302742d2014-08-22 10:28:29 +0800974static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800975 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800976{
977 const uint8_t cmd_len = 2;
978 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
979 GEN6_RENDER_SUBTYPE_3D |
980 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800981 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800982
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 cmd_batch_pointer(cmd, cmd_len, &dw);
984 dw[0] = dw0;
985 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800986}
987
Chia-I Wu72292b72014-09-09 10:48:33 +0800988static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800989 const struct intel_blend_state *state)
990{
Chia-I Wu72292b72014-09-09 10:48:33 +0800991 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800992 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
993
994 CMD_ASSERT(cmd, 6, 7.5);
995 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
996
Chia-I Wu00b51a82014-09-09 12:07:37 +0800997 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
998 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +0800999}
1000
Chia-I Wu72292b72014-09-09 10:48:33 +08001001static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001002 const struct intel_ds_state *state)
1003{
Chia-I Wu72292b72014-09-09 10:48:33 +08001004 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001005 const uint8_t cmd_len = 3;
1006
1007 CMD_ASSERT(cmd, 6, 7.5);
1008 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1009
Chia-I Wu00b51a82014-09-09 12:07:37 +08001010 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1011 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001012}
1013
Chia-I Wu72292b72014-09-09 10:48:33 +08001014static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001015 uint32_t stencil_ref,
1016 const uint32_t blend_color[4])
1017{
Chia-I Wu72292b72014-09-09 10:48:33 +08001018 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001019 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001020 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001021
1022 CMD_ASSERT(cmd, 6, 7.5);
1023
Chia-I Wu00b51a82014-09-09 12:07:37 +08001024 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1025 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001026 dw[0] = stencil_ref;
1027 dw[1] = 0;
1028 dw[2] = blend_color[0];
1029 dw[3] = blend_color[1];
1030 dw[4] = blend_color[2];
1031 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001032
Chia-I Wu72292b72014-09-09 10:48:33 +08001033 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001034}
1035
Chia-I Wu8370b402014-08-29 12:28:37 +08001036static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001037{
Chia-I Wu8370b402014-08-29 12:28:37 +08001038 CMD_ASSERT(cmd, 6, 7.5);
1039
Chia-I Wu707a29e2014-08-27 12:51:47 +08001040 if (!cmd->bind.draw_count)
1041 return;
1042
Chia-I Wu8370b402014-08-29 12:28:37 +08001043 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001044 return;
1045
Chia-I Wu8370b402014-08-29 12:28:37 +08001046 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001047
1048 /*
1049 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1050 *
1051 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1052 * pipe-control with a post-sync op and no write-cache flushes."
1053 *
1054 * The workaround below necessitates this workaround.
1055 */
1056 gen6_PIPE_CONTROL(cmd,
1057 GEN6_PIPE_CONTROL_CS_STALL |
1058 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001059 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001060
Chia-I Wud6d079d2014-08-31 13:14:21 +08001061 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1062 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001063}
1064
Chia-I Wu8370b402014-08-29 12:28:37 +08001065static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001066{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001067 CMD_ASSERT(cmd, 6, 7.5);
1068
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001069 if (!cmd->bind.draw_count)
1070 return;
1071
Chia-I Wud6d079d2014-08-31 13:14:21 +08001072 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1073 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001074}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1077{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001078 CMD_ASSERT(cmd, 7, 7.5);
1079
Chia-I Wu8370b402014-08-29 12:28:37 +08001080 if (!cmd->bind.draw_count)
1081 return;
1082
1083 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001084
1085 gen6_PIPE_CONTROL(cmd,
1086 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001087 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001088}
1089
Chia-I Wu8370b402014-08-29 12:28:37 +08001090static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1091{
1092 CMD_ASSERT(cmd, 7, 7.5);
1093
1094 if (!cmd->bind.draw_count)
1095 return;
1096
1097 /*
1098 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1099 *
1100 * "One of the following must also be set (when CS stall is set):
1101 *
1102 * * Render Target Cache Flush Enable ([12] of DW1)
1103 * * Depth Cache Flush Enable ([0] of DW1)
1104 * * Stall at Pixel Scoreboard ([1] of DW1)
1105 * * Depth Stall ([13] of DW1)
1106 * * Post-Sync Operation ([13] of DW1)"
1107 */
1108 gen6_PIPE_CONTROL(cmd,
1109 GEN6_PIPE_CONTROL_CS_STALL |
1110 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001111 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001112}
1113
1114static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1115{
1116 CMD_ASSERT(cmd, 7, 7.5);
1117
1118 if (!cmd->bind.draw_count)
1119 return;
1120
1121 cmd_wa_gen6_pre_depth_stall_write(cmd);
1122
Chia-I Wud6d079d2014-08-31 13:14:21 +08001123 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001124}
1125
1126static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1127{
1128 CMD_ASSERT(cmd, 6, 7.5);
1129
1130 if (!cmd->bind.draw_count)
1131 return;
1132
1133 /*
1134 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1135 *
1136 * "Driver must guarentee that all the caches in the depth pipe are
1137 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1138 * requires driver to send a PIPE_CONTROL with a CS stall along with
1139 * a Depth Flush prior to this command."
1140 *
1141 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1142 *
1143 * "Driver must ierarchi that all the caches in the depth pipe are
1144 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1145 * requires driver to send a PIPE_CONTROL with a CS stall along with
1146 * a Depth Flush prior to this command.
1147 */
1148 gen6_PIPE_CONTROL(cmd,
1149 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1150 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001151 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001152}
1153
1154static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1155{
1156 CMD_ASSERT(cmd, 6, 7.5);
1157
1158 if (!cmd->bind.draw_count)
1159 return;
1160
1161 /*
1162 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1163 *
1164 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1165 * and a post sync operation prior to the group of depth
1166 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1167 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1168 *
1169 * This workaround satifies all the conditions.
1170 */
1171 cmd_wa_gen6_pre_depth_stall_write(cmd);
1172
1173 /*
1174 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1175 *
1176 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1177 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1178 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1179 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1180 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1181 * Depth Flush Bit set, followed by another pipelined depth stall
1182 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1183 * guarantee that the pipeline from WM onwards is already flushed
1184 * (e.g., via a preceding MI_FLUSH)."
1185 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001186 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1187 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1188 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001189}
1190
Chia-I Wu525c6602014-08-27 10:22:34 +08001191void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1192{
1193 if (!cmd->bind.draw_count)
1194 return;
1195
1196 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1197
Chia-I Wu8370b402014-08-29 12:28:37 +08001198 /*
1199 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1200 *
1201 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1202 * PIPE_CONTROL with any non-zero post-sync-op is required."
1203 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001204 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001205 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001206
Chia-I Wu092279a2014-08-30 19:05:30 +08001207 /*
1208 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1209 *
1210 * "One of the following must also be set (when CS stall is set):
1211 *
1212 * * Render Target Cache Flush Enable ([12] of DW1)
1213 * * Depth Cache Flush Enable ([0] of DW1)
1214 * * Stall at Pixel Scoreboard ([1] of DW1)
1215 * * Depth Stall ([13] of DW1)
1216 * * Post-Sync Operation ([13] of DW1)"
1217 */
1218 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1219 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1220 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1221 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1222 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1223 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1224
Chia-I Wud6d079d2014-08-31 13:14:21 +08001225 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001226}
1227
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001228void cmd_batch_flush_all(struct intel_cmd *cmd)
1229{
1230 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1231 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1232 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1233 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1234 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1235 GEN6_PIPE_CONTROL_CS_STALL);
1236}
1237
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001238void cmd_batch_depth_count(struct intel_cmd *cmd,
1239 struct intel_bo *bo,
1240 XGL_GPU_SIZE offset)
1241{
1242 cmd_wa_gen6_pre_depth_stall_write(cmd);
1243
1244 gen6_PIPE_CONTROL(cmd,
1245 GEN6_PIPE_CONTROL_DEPTH_STALL |
1246 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001247 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001248}
1249
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001250void cmd_batch_timestamp(struct intel_cmd *cmd,
1251 struct intel_bo *bo,
1252 XGL_GPU_SIZE offset)
1253{
1254 /* need any WA or stall? */
1255 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1256}
1257
1258void cmd_batch_immediate(struct intel_cmd *cmd,
1259 struct intel_bo *bo,
1260 XGL_GPU_SIZE offset,
1261 uint64_t val)
1262{
1263 /* need any WA or stall? */
1264 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1265}
1266
Chia-I Wu302742d2014-08-22 10:28:29 +08001267static void gen6_cc_states(struct intel_cmd *cmd)
1268{
1269 const struct intel_blend_state *blend = cmd->bind.state.blend;
1270 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001271 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001272 uint32_t stencil_ref;
1273 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001274
1275 CMD_ASSERT(cmd, 6, 6);
1276
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001277 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001278 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001279 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1280 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001281 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001282 memset(blend_color, 0, sizeof(blend_color));
1283 }
1284
1285 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001286 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001287 stencil_ref = ds->cmd_stencil_ref;
1288 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001289 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001290 stencil_ref = 0;
1291 }
1292
Chia-I Wu72292b72014-09-09 10:48:33 +08001293 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001294
Chia-I Wu72292b72014-09-09 10:48:33 +08001295 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001296}
1297
Chia-I Wu1744cca2014-08-22 11:10:17 +08001298static void gen6_viewport_states(struct intel_cmd *cmd)
1299{
1300 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001301 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001302
1303 if (!viewport)
1304 return;
1305
Chia-I Wub1d450a2014-09-09 13:48:03 +08001306 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1307 viewport->viewport_count);
1308
1309 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1310 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1311 viewport->cmd);
1312
1313 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1314 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1315 &viewport->cmd[viewport->cmd_clip_pos]);
1316
1317 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1318 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1319 &viewport->cmd[viewport->cmd_cc_pos]);
1320
1321 if (viewport->scissor_enable) {
1322 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1323 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1324 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1325 } else {
1326 scissor_offset = 0;
1327 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001328
1329 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001330 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001331
Chia-I Wub1d450a2014-09-09 13:48:03 +08001332 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001333}
1334
Chia-I Wu302742d2014-08-22 10:28:29 +08001335static void gen7_cc_states(struct intel_cmd *cmd)
1336{
1337 const struct intel_blend_state *blend = cmd->bind.state.blend;
1338 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001339 uint32_t stencil_ref;
1340 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001341 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001342
1343 CMD_ASSERT(cmd, 7, 7.5);
1344
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001345 if (!blend && !ds)
1346 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001347
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001348 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001349 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001350 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001351 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001352
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001353 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1354 } else {
1355 memset(blend_color, 0, sizeof(blend_color));
1356 }
1357
1358 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001359 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001360 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001361 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1362 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001363 } else {
1364 stencil_ref = 0;
1365 }
1366
Chia-I Wu72292b72014-09-09 10:48:33 +08001367 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001368 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001369 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001370}
1371
Chia-I Wu1744cca2014-08-22 11:10:17 +08001372static void gen7_viewport_states(struct intel_cmd *cmd)
1373{
1374 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001375 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001376
1377 if (!viewport)
1378 return;
1379
Chia-I Wub1d450a2014-09-09 13:48:03 +08001380 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1381 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001382
Chia-I Wub1d450a2014-09-09 13:48:03 +08001383 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1384 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1385 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001386 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001387 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1388 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001389
1390 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1391 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1392 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001393 gen7_3dstate_pointer(cmd,
1394 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001395 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001396
Chia-I Wu1744cca2014-08-22 11:10:17 +08001397 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001398 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1399 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1400 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001401 gen7_3dstate_pointer(cmd,
1402 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001403 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001404 }
1405}
1406
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001407static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001408 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001409{
1410 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001411 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001412
Chia-I Wu72292b72014-09-09 10:48:33 +08001413 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001414
1415 dw[0] = GEN6_RENDER_TYPE_RENDER |
1416 GEN6_RENDER_SUBTYPE_3D |
1417 subop | (cmd_len - 2);
1418 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001419 dw[2] = 0;
1420 dw[3] = 0;
1421 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001422}
1423
1424static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001425 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001426{
1427 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001428 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001429
Chia-I Wu72292b72014-09-09 10:48:33 +08001430 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001431
1432 dw[0] = GEN6_RENDER_TYPE_RENDER |
1433 GEN6_RENDER_SUBTYPE_3D |
1434 subop | (cmd_len - 2);
1435 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001436 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001437 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001438 dw[4] = 0;
1439 dw[5] = 0;
1440 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001441}
1442
Chia-I Wu625105f2014-10-13 15:35:29 +08001443static uint32_t emit_samplers(struct intel_cmd *cmd,
1444 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001445{
1446 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1447 const XGL_UINT border_stride =
1448 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001449 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001450 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001451 XGL_UINT i;
1452
1453 CMD_ASSERT(cmd, 6, 7.5);
1454
Chia-I Wu625105f2014-10-13 15:35:29 +08001455 if (!rmap || !rmap->sampler_count)
1456 return 0;
1457
1458 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1459
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001460 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1461 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1462 border_stride * rmap->sampler_count, &border_dw);
1463
1464 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1465 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1466 4 * rmap->sampler_count, &sampler_dw);
1467
1468 for (i = 0; i < rmap->sampler_count; i++) {
1469 const struct intel_pipeline_rmap_slot *slot =
1470 &rmap->slots[surface_count + i];
1471 const struct intel_sampler *sampler;
1472
1473 switch (slot->path_len) {
1474 case 0:
1475 sampler = NULL;
1476 break;
1477 case INTEL_PIPELINE_RMAP_SLOT_RT:
1478 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1479 assert(!"unexpected rmap slot type");
1480 sampler = NULL;
1481 break;
1482 case 1:
1483 {
1484 const struct intel_dset *dset = cmd->bind.dset.graphics;
1485 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1486 const struct intel_dset_slot *dset_slot =
1487 &dset->slots[slot_offset + slot->u.index];
1488
1489 switch (dset_slot->type) {
1490 case INTEL_DSET_SLOT_SAMPLER:
1491 sampler = dset_slot->u.sampler;
1492 break;
1493 default:
1494 assert(!"unexpected dset slot type");
1495 sampler = NULL;
1496 break;
1497 }
1498 }
1499 break;
1500 default:
1501 assert(!"nested descriptor set unsupported");
1502 sampler = NULL;
1503 break;
1504 }
1505
1506 if (sampler) {
1507 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1508
1509 sampler_dw[0] = sampler->cmd[0];
1510 sampler_dw[1] = sampler->cmd[1];
1511 sampler_dw[2] = border_offset;
1512 sampler_dw[3] = sampler->cmd[2];
1513 } else {
1514 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1515 sampler_dw[1] = 0;
1516 sampler_dw[2] = 0;
1517 sampler_dw[3] = 0;
1518 }
1519
1520 border_offset += border_stride * 4;
1521 border_dw += border_stride;
1522 sampler_dw += 4;
1523 }
1524
Chia-I Wu625105f2014-10-13 15:35:29 +08001525 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001526}
1527
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001528static uint32_t emit_binding_table(struct intel_cmd *cmd,
1529 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001530{
Chia-I Wu72292b72014-09-09 10:48:33 +08001531 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001532 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001533
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001534 CMD_ASSERT(cmd, 6, 7.5);
1535
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001536 surface_count = (rmap) ?
1537 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1538 if (!surface_count)
1539 return 0;
1540
Chia-I Wu42a56202014-08-23 16:47:48 +08001541 assert(surface_count <= ARRAY_SIZE(binding_table));
1542
1543 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001544 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001545
1546 switch (slot->path_len) {
1547 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001548 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001549 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001550 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001551 {
1552 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1553
Chia-I Wu00b51a82014-09-09 12:07:37 +08001554 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001555 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1556 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001557
Chia-I Wu72292b72014-09-09 10:48:33 +08001558 cmd_reserve_reloc(cmd, 1);
1559 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1560 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001561 }
1562 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001563 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001564 {
1565 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001566 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001567
Chia-I Wu00b51a82014-09-09 12:07:37 +08001568 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001569 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1570 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001571
Chia-I Wu72292b72014-09-09 10:48:33 +08001572 cmd_reserve_reloc(cmd, 1);
1573 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1574 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001575 }
1576 break;
1577 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001578 {
1579 const struct intel_dset *dset = cmd->bind.dset.graphics;
1580 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1581 const struct intel_dset_slot *dset_slot =
1582 &dset->slots[slot_offset + slot->u.index];
1583
1584 switch (dset_slot->type) {
1585 case INTEL_DSET_SLOT_IMG_VIEW:
1586 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1587 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1588 dset_slot->u.img_view->cmd_len,
1589 dset_slot->u.img_view->cmd);
1590
1591 cmd_reserve_reloc(cmd, 1);
1592 cmd_surface_reloc(cmd, offset, 1,
1593 dset_slot->u.img_view->img->obj.mem->bo,
1594 dset_slot->u.img_view->cmd[1], 0);
1595 break;
1596 case INTEL_DSET_SLOT_MEM_VIEW:
1597 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1598 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1599 dset_slot->u.mem_view.cmd_len,
1600 dset_slot->u.mem_view.cmd);
1601
1602 cmd_reserve_reloc(cmd, 1);
1603 cmd_surface_reloc(cmd, offset, 1,
1604 dset_slot->u.mem_view.mem->bo,
1605 dset_slot->u.mem_view.cmd[1], 0);
1606 break;
1607 default:
1608 assert(!"unexpected dset slot type");
1609 break;
1610 }
1611 }
1612 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001613 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001614 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001615 break;
1616 }
1617
Chia-I Wu72292b72014-09-09 10:48:33 +08001618 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001619 }
1620
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001621 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001622 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001623 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001624}
1625
Chia-I Wu1d125092014-10-08 08:49:38 +08001626static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1627{
1628 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1629 const struct intel_pipeline_rmap *rmap = pipeline->vs.rmap;
1630 const struct intel_dset *dset = cmd->bind.dset.graphics;
1631 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1632 uint32_t *dw;
1633 XGL_UINT pos, i;
1634
1635 CMD_ASSERT(cmd, 6, 7.5);
1636
1637 if (!pipeline->vb_count)
1638 return;
1639
1640 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1641
1642 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1643 dw++;
1644 pos++;
1645
1646 for (i = 0; i < pipeline->vb_count; i++) {
1647 const XGL_UINT vb_offset = rmap->rt_count + rmap->resource_count +
1648 rmap->uav_count + rmap->sampler_count;
1649 const struct intel_pipeline_rmap_slot *slot = (i < rmap->vb_count) ?
1650 &rmap->slots[vb_offset + i] : NULL;
1651 struct intel_mem_view *view = NULL;
1652
1653 if (slot) {
1654 switch (slot->path_len) {
1655 case 1:
1656 view = (dset->slots[slot->u.index].type ==
1657 INTEL_DSET_SLOT_MEM_VIEW) ?
1658 &dset->slots[slot->u.index].u.mem_view : NULL;
1659 break;
1660 default:
1661 break;
1662 }
1663 }
1664
1665 assert(pipeline->vb[i].strideInBytes <= 2048);
1666
1667 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1668 pipeline->vb[i].strideInBytes;
1669
1670 if (cmd_gen(cmd) >= INTEL_GEN(7))
1671 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1672
1673 switch (pipeline->vb[i].stepRate) {
1674 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1675 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1676 dw[3] = 0;
1677 break;
1678 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1679 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1680 dw[3] = 1;
1681 break;
1682 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1683 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1684 dw[3] = 0;
1685 break;
1686 default:
1687 assert(!"unknown step rate");
1688 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1689 dw[3] = 0;
1690 break;
1691 }
1692
1693 if (view) {
1694 const uint32_t begin = view->cmd[1];
1695 const uint32_t end = view->mem->size - 1;
1696
1697 cmd_reserve_reloc(cmd, 2);
1698 cmd_batch_reloc(cmd, pos + 1, view->mem->bo, begin, 0);
1699 cmd_batch_reloc(cmd, pos + 2, view->mem->bo, end, 0);
1700 } else {
1701 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1702 dw[1] = 0;
1703 dw[2] = 0;
1704 }
1705
1706 dw += 4;
1707 pos += 4;
1708 }
1709}
1710
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001711static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1712{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001713 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1714 const struct intel_pipeline_shader *vs = &pipeline->vs;
1715 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001716 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001717 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001718 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001719
1720 CMD_ASSERT(cmd, 6, 7.5);
1721
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001722 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001723 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1724 *
1725 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1726 * 128-bit vertex elements to be passed into the payload for each
1727 * vertex."
1728 *
1729 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1730 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001731 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001732 vue_read_len = (vs->in_count + 1) / 2;
1733 if (!vue_read_len)
1734 vue_read_len = 1;
1735
1736 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1737 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1738
1739 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1740 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1741 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001742
1743 dw5 = GEN6_VS_DW5_STATISTICS |
1744 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001745
1746 switch (cmd_gen(cmd)) {
1747 case INTEL_GEN(7.5):
1748 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1749 break;
1750 case INTEL_GEN(7):
1751 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1752 break;
1753 case INTEL_GEN(6):
1754 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1755 break;
1756 default:
1757 max_threads = 1;
1758 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001759 }
1760
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001761 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1762 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1763 else
1764 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1765
Chia-I Wube0a3d92014-09-02 13:20:59 +08001766 if (pipeline->disable_vs_cache)
1767 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1768
Chia-I Wu72292b72014-09-09 10:48:33 +08001769 cmd_batch_pointer(cmd, cmd_len, &dw);
1770 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001771 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001772 dw[2] = dw2;
1773 dw[3] = 0; /* scratch */
1774 dw[4] = dw4;
1775 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001776}
1777
Chia-I Wu625105f2014-10-13 15:35:29 +08001778static void emit_shader_resources(struct intel_cmd *cmd)
1779{
1780 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001781 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001782
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001783 binding_tables[0] = emit_binding_table(cmd,
1784 cmd->bind.pipeline.graphics->vs.rmap);
1785 binding_tables[1] = emit_binding_table(cmd,
1786 cmd->bind.pipeline.graphics->tcs.rmap);
1787 binding_tables[2] = emit_binding_table(cmd,
1788 cmd->bind.pipeline.graphics->tes.rmap);
1789 binding_tables[3] = emit_binding_table(cmd,
1790 cmd->bind.pipeline.graphics->gs.rmap);
1791 binding_tables[4] = emit_binding_table(cmd,
1792 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001793
1794 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1795 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1796 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1797 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1798 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1799
1800 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1801 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001802 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1803 binding_tables[0]);
1804 gen7_3dstate_pointer(cmd,
1805 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1806 binding_tables[1]);
1807 gen7_3dstate_pointer(cmd,
1808 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1809 binding_tables[2]);
1810 gen7_3dstate_pointer(cmd,
1811 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1812 binding_tables[3]);
1813 gen7_3dstate_pointer(cmd,
1814 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1815 binding_tables[4]);
1816
1817 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001818 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1819 samplers[0]);
1820 gen7_3dstate_pointer(cmd,
1821 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1822 samplers[1]);
1823 gen7_3dstate_pointer(cmd,
1824 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1825 samplers[2]);
1826 gen7_3dstate_pointer(cmd,
1827 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1828 samplers[3]);
1829 gen7_3dstate_pointer(cmd,
1830 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1831 samplers[4]);
1832 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001833 assert(!binding_tables[1] && !binding_tables[2]);
1834 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1835 binding_tables[0], binding_tables[3], binding_tables[4]);
1836
Chia-I Wu625105f2014-10-13 15:35:29 +08001837 assert(!samplers[1] && !samplers[2]);
1838 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1839 samplers[0], samplers[3], samplers[4]);
1840 }
1841}
1842
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001843static void emit_rt(struct intel_cmd *cmd)
1844{
1845 cmd_wa_gen6_pre_depth_stall_write(cmd);
1846 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1847 cmd->bind.att.height);
1848}
1849
1850static void emit_ds(struct intel_cmd *cmd)
1851{
1852 const struct intel_ds_view *ds = cmd->bind.att.ds;
1853
1854 if (!ds) {
1855 /* all zeros */
1856 static const struct intel_ds_view null_ds;
1857 ds = &null_ds;
1858 }
1859
1860 cmd_wa_gen6_pre_ds_flush(cmd);
1861 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1862 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1863 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1864
1865 if (cmd_gen(cmd) >= INTEL_GEN(7))
1866 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1867 else
1868 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1869}
1870
Chia-I Wua57761b2014-10-14 14:27:44 +08001871static uint32_t emit_shader(struct intel_cmd *cmd,
1872 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001873{
Chia-I Wua57761b2014-10-14 14:27:44 +08001874 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1875 uint32_t offset;
1876 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001877
Chia-I Wua57761b2014-10-14 14:27:44 +08001878 /* see if the shader is already in the cache */
1879 for (i = 0; i < cache->used; i++) {
1880 if (cache->entries[i].shader == (const void *) shader)
1881 return cache->entries[i].kernel_offset;
1882 }
1883
1884 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1885
1886 /* grow the cache if full */
1887 if (cache->used >= cache->count) {
1888 const XGL_UINT count = cache->count + 16;
1889 void *entries;
1890
1891 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1892 XGL_SYSTEM_ALLOC_INTERNAL);
1893 if (entries) {
1894 if (cache->entries) {
1895 memcpy(entries, cache->entries,
1896 sizeof(cache->entries[0]) * cache->used);
1897 icd_free(cache->entries);
1898 }
1899
1900 cache->entries = entries;
1901 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001902 }
1903 }
1904
Chia-I Wua57761b2014-10-14 14:27:44 +08001905 /* add the shader to the cache */
1906 if (cache->used < cache->count) {
1907 cache->entries[cache->used].shader = (const void *) shader;
1908 cache->entries[cache->used].kernel_offset = offset;
1909 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001910 }
1911
Chia-I Wua57761b2014-10-14 14:27:44 +08001912 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001913}
1914
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001915static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001916{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001917 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001918
Chia-I Wu8370b402014-08-29 12:28:37 +08001919 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1920 cmd_wa_gen6_pre_depth_stall_write(cmd);
1921 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1922 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1923 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1924 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001925
1926 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001927 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001928 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001929
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001930 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001931 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001932 }
1933 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001934 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001935 }
1936 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001937 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1938 }
1939 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1940 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1941 }
1942 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1943 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001944 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001945
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001946 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1947 gen7_3DSTATE_GS(cmd);
1948 } else {
1949 gen6_3DSTATE_GS(cmd);
1950 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001951
Chia-I Wu8370b402014-08-29 12:28:37 +08001952 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1953 cmd_wa_gen7_post_command_cs_stall(cmd);
1954 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1955 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001956}
1957
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001958static void emit_bounded_states(struct intel_cmd *cmd)
1959{
1960 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1961
1962 emit_graphics_pipeline(cmd);
1963
1964 emit_rt(cmd);
1965 emit_ds(cmd);
1966
1967 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1968 gen7_cc_states(cmd);
1969 gen7_viewport_states(cmd);
1970
1971 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1972 &cmd->bind.pipeline.graphics->vs);
1973 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1974 &cmd->bind.pipeline.graphics->fs);
1975
1976 gen6_3DSTATE_CLIP(cmd);
1977 gen7_3DSTATE_SF(cmd);
1978 gen7_3DSTATE_SBE(cmd);
1979 gen7_3DSTATE_WM(cmd);
1980 gen7_3DSTATE_PS(cmd);
1981 } else {
1982 gen6_cc_states(cmd);
1983 gen6_viewport_states(cmd);
1984
1985 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1986 &cmd->bind.pipeline.graphics->vs);
1987 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1988 &cmd->bind.pipeline.graphics->fs);
1989
1990 gen6_3DSTATE_CLIP(cmd);
1991 gen6_3DSTATE_SF(cmd);
1992 gen6_3DSTATE_WM(cmd);
1993 }
1994
1995 emit_shader_resources(cmd);
1996
1997 cmd_wa_gen6_pre_depth_stall_write(cmd);
1998 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1999
2000 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2001 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2002
2003 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2004 gen6_3DSTATE_VS(cmd);
2005}
2006
Chia-I Wu6032b892014-10-17 14:47:18 +08002007static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2008{
2009 const struct intel_cmd_meta *meta = cmd->bind.meta;
2010 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2011
2012 CMD_ASSERT(cmd, 6, 7.5);
2013
2014 blend_offset = 0;
2015 ds_offset = 0;
2016 cc_offset = 0;
2017 cc_vp_offset = 0;
2018
2019 if (meta->dst.valid) {
2020 /* BLEND_STATE */
2021 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
2022 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2023 dw[0] = 0;
2024 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2025 }
2026
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002027 if (meta->ds.state) {
2028 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002029
2030 /* DEPTH_STENCIL_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002031 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002032
2033 /* COLOR_CALC_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002034 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2035 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002036
2037 /* CC_VIEWPORT */
2038 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
2039 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002040 dw[0] = u_fui(0.0f);
2041 dw[1] = u_fui(1.0f);
Chia-I Wua667c2b2014-10-28 11:40:29 +08002042 } else {
2043 /* DEPTH_STENCIL_STATE */
2044 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2045 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4,
2046 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2047 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
Chia-I Wu6032b892014-10-17 14:47:18 +08002048 }
2049
2050 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2051 gen7_3dstate_pointer(cmd,
2052 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2053 blend_offset);
2054 gen7_3dstate_pointer(cmd,
2055 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2056 ds_offset);
2057 gen7_3dstate_pointer(cmd,
2058 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2059
2060 gen7_3dstate_pointer(cmd,
2061 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2062 cc_vp_offset);
2063 } else {
2064 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002065 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002066
2067 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2068 cmd_batch_pointer(cmd, 4, &dw);
2069 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2070 GEN6_PTR_VP_DW0_CC_CHANGED;
2071 dw[1] = 0;
2072 dw[2] = 0;
2073 dw[3] = cc_vp_offset;
2074 }
2075}
2076
2077static void gen6_meta_surface_states(struct intel_cmd *cmd)
2078{
2079 const struct intel_cmd_meta *meta = cmd->bind.meta;
2080 uint32_t binding_table[2];
2081 XGL_UINT surface_count = 0;
2082 uint32_t offset;
2083
2084 CMD_ASSERT(cmd, 6, 7.5);
2085
2086 /* SURFACE_STATE */
2087 if (meta->dst.valid) {
2088 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2089 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2090 meta->dst.surface_len, meta->dst.surface);
2091
2092 cmd_reserve_reloc(cmd, 1);
2093 cmd_surface_reloc(cmd, offset, 1,
2094 (struct intel_bo *) meta->dst.reloc_target,
2095 meta->dst.reloc_offset, meta->dst.reloc_flags);
2096
2097 binding_table[surface_count++] = offset;
2098 }
2099 if (meta->src.valid) {
2100 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2101 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2102 meta->src.surface_len, meta->src.surface);
2103
2104 cmd_reserve_reloc(cmd, 1);
2105 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2106 cmd_surface_reloc_writer(cmd, offset, 1,
2107 meta->src.reloc_target, meta->src.reloc_offset);
2108 } else {
2109 cmd_surface_reloc(cmd, offset, 1,
2110 (struct intel_bo *) meta->src.reloc_target,
2111 meta->src.reloc_offset, meta->src.reloc_flags);
2112 }
2113
2114 binding_table[surface_count++] = offset;
2115 }
2116
2117 /* BINDING_TABLE */
2118 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
2119 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
2120 surface_count, binding_table);
2121
2122 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2123 gen7_3dstate_pointer(cmd,
2124 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2125 offset);
2126 } else {
2127 /* 3DSTATE_BINDING_TABLE_POINTERS */
2128 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
2129 }
2130}
2131
2132static void gen6_meta_urb(struct intel_cmd *cmd)
2133{
2134 uint32_t *dw;
2135
2136 CMD_ASSERT(cmd, 6, 6);
2137
2138 /* 3DSTATE_URB */
2139 cmd_batch_pointer(cmd, 3, &dw);
2140 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
2141 dw[1] = 128 << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
2142 dw[2] = 0;
2143}
2144
2145static void gen7_meta_urb(struct intel_cmd *cmd)
2146{
2147 uint32_t *dw;
2148
2149 CMD_ASSERT(cmd, 7, 7.5);
2150
2151 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2152 cmd_batch_pointer(cmd, 10, &dw);
2153
2154 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
2155 dw[1] = 0;
2156 dw += 2;
2157
2158 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2159 dw[1] = 0;
2160 dw += 2;
2161
2162 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2163 dw[1] = 0;
2164 dw += 2;
2165
2166 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2167 dw[1] = 0;
2168 dw += 2;
2169
2170 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2171 dw[1] = 1;
2172
2173 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2174
2175 /* 3DSTATE_URB_x */
2176 cmd_batch_pointer(cmd, 8, &dw);
2177
2178 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2179 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
2180 512;
2181 dw += 2;
2182
2183 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2184 dw[1] = 0;
2185 dw += 2;
2186
2187 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2188 dw[1] = 0;
2189 dw += 2;
2190
2191 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2192 dw[1] = 0;
2193 dw += 2;
2194}
2195
2196static void gen6_meta_vf(struct intel_cmd *cmd)
2197{
2198 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002199 uint32_t vb_start, vb_end, vb_stride;
2200 int ve_format, ve_z_source;
2201 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002202 XGL_UINT pos;
2203
2204 CMD_ASSERT(cmd, 6, 7.5);
2205
2206 /* write vertices */
Chia-I Wu3adf7212014-10-24 15:34:07 +08002207 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2208 XGL_FLOAT vertices[3][3];
2209
2210 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2211 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2212 vertices[0][2] = u_uif(meta->clear_val[0]);
2213 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2214 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2215 vertices[1][2] = u_uif(meta->clear_val[0]);
2216 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2217 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2218 vertices[2][2] = u_uif(meta->clear_val[0]);
2219
2220 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2221 sizeof(vertices) / 4, (const uint32_t *) vertices);
2222
2223 vb_end = vb_start + sizeof(vertices) - 1;
2224 vb_stride = sizeof(vertices[0]);
2225 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2226 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2227 } else {
2228 XGL_UINT vertices[3][2];
2229
2230 vertices[0][0] = meta->dst.x + meta->width;
2231 vertices[0][1] = meta->dst.y + meta->height;
2232 vertices[1][0] = meta->dst.x;
2233 vertices[1][1] = meta->dst.y + meta->height;
2234 vertices[2][0] = meta->dst.x;
2235 vertices[2][1] = meta->dst.y;
2236
2237 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2238 sizeof(vertices) / 4, (const uint32_t *) vertices);
2239
2240 vb_end = vb_start + sizeof(vertices) - 1;
2241 vb_stride = sizeof(vertices[0]);
2242 ve_z_source = GEN6_VFCOMP_STORE_0;
2243 ve_format = GEN6_FORMAT_R32G32_USCALED;
2244 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002245
2246 /* 3DSTATE_VERTEX_BUFFERS */
2247 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002248
Chia-I Wu6032b892014-10-17 14:47:18 +08002249 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002250 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002251 if (cmd_gen(cmd) >= INTEL_GEN(7))
2252 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2253
2254 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002255 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2256 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002257
2258 dw[4] = 0;
2259
2260 /* 3DSTATE_VERTEX_ELEMENTS */
2261 cmd_batch_pointer(cmd, 5, &dw);
2262 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
2263 dw[1] = GEN6_VE_STATE_DW0_VALID,
2264 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2265 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2266 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2267 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2268 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002269 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002270 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2271 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002272 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002273 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2274}
2275
2276static void gen6_meta_disabled(struct intel_cmd *cmd)
2277{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002278 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002279 uint32_t *dw;
2280
2281 CMD_ASSERT(cmd, 6, 6);
2282
2283 /* 3DSTATE_CONSTANT_VS */
2284 cmd_batch_pointer(cmd, 5, &dw);
2285 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2);
2286 dw[1] = 0;
2287 dw[2] = 0;
2288 dw[3] = 0;
2289 dw[4] = 0;
2290
2291 /* 3DSTATE_VS */
2292 cmd_batch_pointer(cmd, 6, &dw);
2293 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2294 dw[1] = 0;
2295 dw[2] = 0;
2296 dw[3] = 0;
2297 dw[4] = 0;
2298 dw[5] = 0;
2299
2300 /* 3DSTATE_CONSTANT_GS */
2301 cmd_batch_pointer(cmd, 5, &dw);
2302 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2303 dw[1] = 0;
2304 dw[2] = 0;
2305 dw[3] = 0;
2306 dw[4] = 0;
2307
2308 /* 3DSTATE_GS */
2309 cmd_batch_pointer(cmd, 7, &dw);
2310 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2311 dw[1] = 0;
2312 dw[2] = 0;
2313 dw[3] = 0;
2314 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2315 dw[5] = GEN6_GS_DW5_STATISTICS;
2316 dw[6] = 0;
2317
2318 /* 3DSTATE_CLIP */
2319 cmd_batch_pointer(cmd, 4, &dw);
2320 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2321 dw[1] = 0;
2322 dw[2] = 0;
2323 dw[3] = 0;
2324
2325 /* 3DSTATE_SF */
2326 cmd_batch_pointer(cmd, 20, &dw);
2327 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2328 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2329 memset(&dw[2], 0, 18 * sizeof(*dw));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002330
2331 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2332 /* 3DSTATE_CONSTANT_PS */
2333 cmd_batch_pointer(cmd, 5, &dw);
2334 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2335 dw[1] = 0;
2336 dw[2] = 0;
2337 dw[3] = 0;
2338 dw[4] = 0;
2339
2340 /* 3DSTATE_WM */
2341 cmd_batch_pointer(cmd, 9, &dw);
2342 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2343 dw[1] = 0;
2344 dw[2] = 0;
2345 dw[3] = 0;
2346 dw[4] = 0;
2347 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
2348 dw[6] = 0;
2349 dw[7] = 0;
2350 dw[8] = 0;
2351 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002352}
2353
2354static void gen7_meta_disabled(struct intel_cmd *cmd)
2355{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002356 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002357 uint32_t *dw;
2358
2359 CMD_ASSERT(cmd, 7, 7.5);
2360
2361 /* 3DSTATE_CONSTANT_VS */
2362 cmd_batch_pointer(cmd, 7, &dw);
2363 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2364 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2365
2366 /* 3DSTATE_VS */
2367 cmd_batch_pointer(cmd, 6, &dw);
2368 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2369 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2370
2371 /* 3DSTATE_CONSTANT_HS */
2372 cmd_batch_pointer(cmd, 7, &dw);
2373 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2374 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2375
2376 /* 3DSTATE_HS */
2377 cmd_batch_pointer(cmd, 7, &dw);
2378 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2379 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2380
2381 /* 3DSTATE_TE */
2382 cmd_batch_pointer(cmd, 4, &dw);
2383 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2384 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2385
2386 /* 3DSTATE_CONSTANT_DS */
2387 cmd_batch_pointer(cmd, 7, &dw);
2388 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2389 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2390
2391 /* 3DSTATE_DS */
2392 cmd_batch_pointer(cmd, 6, &dw);
2393 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2394 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2395
2396 /* 3DSTATE_CONSTANT_GS */
2397 cmd_batch_pointer(cmd, 7, &dw);
2398 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2399 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2400
2401 /* 3DSTATE_GS */
2402 cmd_batch_pointer(cmd, 7, &dw);
2403 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2404 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2405
2406 /* 3DSTATE_STREAMOUT */
2407 cmd_batch_pointer(cmd, 3, &dw);
2408 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2409 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2410
2411 /* 3DSTATE_CLIP */
2412 cmd_batch_pointer(cmd, 4, &dw);
2413 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2414 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2415
2416 /* 3DSTATE_SF */
2417 cmd_batch_pointer(cmd, 7, &dw);
2418 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2419 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2420
2421 /* 3DSTATE_SBE */
2422 cmd_batch_pointer(cmd, 14, &dw);
2423 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2424 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2425 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002426
2427 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2428 /* 3DSTATE_WM */
2429 cmd_batch_pointer(cmd, 3, &dw);
2430 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2431 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2432
2433 /* 3DSTATE_CONSTANT_GS */
2434 cmd_batch_pointer(cmd, 7, &dw);
2435 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2436 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2437
2438 /* 3DSTATE_PS */
2439 cmd_batch_pointer(cmd, 8, &dw);
2440 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2441 dw[1] = 0;
2442 dw[2] = 0;
2443 dw[3] = 0;
2444 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
2445 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2446 dw[5] = 0;
2447 dw[6] = 0;
2448 dw[7] = 0;
2449 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002450}
2451
2452static void gen6_meta_wm(struct intel_cmd *cmd)
2453{
2454 const struct intel_cmd_meta *meta = cmd->bind.meta;
2455 uint32_t *dw;
2456
2457 CMD_ASSERT(cmd, 6, 7.5);
2458
2459 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2460
2461 /* 3DSTATE_MULTISAMPLE */
2462 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2463 cmd_batch_pointer(cmd, 4, &dw);
2464 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2465 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2466 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2467 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2468 dw[2] = 0;
2469 dw[3] = 0;
2470 } else {
2471 cmd_batch_pointer(cmd, 3, &dw);
2472 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2473 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2474 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2475 dw[2] = 0;
2476 }
2477
2478 /* 3DSTATE_SAMPLE_MASK */
2479 cmd_batch_pointer(cmd, 2, &dw);
2480 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2481 dw[1] = (1 << meta->samples) - 1;
2482
2483 /* 3DSTATE_DRAWING_RECTANGLE */
2484 cmd_batch_pointer(cmd, 4, &dw);
2485 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2486 dw[1] = meta->dst.y << 16 | meta->dst.x;
2487 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2488 (meta->dst.x + meta->width - 1);
2489 dw[3] = 0;
2490}
2491
2492static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2493{
2494 const struct intel_cmd_meta *meta = cmd->bind.meta;
2495 XGL_UINT offset_x, offset_y;
2496 /* one GPR */
2497 XGL_UINT consts[8];
2498 XGL_UINT const_count;
2499
2500 CMD_ASSERT(cmd, 6, 7.5);
2501
2502 /* underflow is fine here */
2503 offset_x = meta->src.x - meta->dst.x;
2504 offset_y = meta->src.y - meta->dst.y;
2505
2506 switch (meta->shader_id) {
2507 case INTEL_DEV_META_FS_COPY_MEM:
2508 case INTEL_DEV_META_FS_COPY_1D:
2509 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2510 case INTEL_DEV_META_FS_COPY_2D:
2511 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2512 case INTEL_DEV_META_FS_COPY_2D_MS:
2513 consts[0] = offset_x;
2514 consts[1] = offset_y;
2515 consts[2] = meta->src.layer;
2516 consts[3] = meta->src.lod;
2517 const_count = 4;
2518 break;
2519 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2520 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2521 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2522 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2523 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2524 consts[0] = offset_x;
2525 consts[1] = offset_y;
2526 consts[2] = meta->src.layer;
2527 consts[3] = meta->src.lod;
2528 consts[4] = meta->src.x;
2529 consts[5] = meta->width;
2530 const_count = 6;
2531 break;
2532 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2533 consts[0] = offset_x;
2534 consts[1] = offset_y;
2535 consts[2] = meta->width;
2536 const_count = 3;
2537 break;
2538 case INTEL_DEV_META_FS_CLEAR_COLOR:
2539 consts[0] = meta->clear_val[0];
2540 consts[1] = meta->clear_val[1];
2541 consts[2] = meta->clear_val[2];
2542 consts[3] = meta->clear_val[3];
2543 const_count = 4;
2544 break;
2545 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2546 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002547 consts[1] = meta->clear_val[1];
2548 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002549 break;
2550 case INTEL_DEV_META_FS_RESOLVE_2X:
2551 case INTEL_DEV_META_FS_RESOLVE_4X:
2552 case INTEL_DEV_META_FS_RESOLVE_8X:
2553 case INTEL_DEV_META_FS_RESOLVE_16X:
2554 consts[0] = offset_x;
2555 consts[1] = offset_y;
2556 const_count = 2;
2557 break;
2558 default:
2559 assert(!"unknown meta shader id");
2560 const_count = 0;
2561 break;
2562 }
2563
2564 /* this can be skipped but it makes state dumping prettier */
2565 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2566
2567 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2568}
2569
2570static void gen6_meta_ps(struct intel_cmd *cmd)
2571{
2572 const struct intel_cmd_meta *meta = cmd->bind.meta;
2573 const struct intel_pipeline_shader *sh =
2574 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2575 uint32_t offset, *dw;
2576
2577 CMD_ASSERT(cmd, 6, 6);
2578
Chia-I Wu3adf7212014-10-24 15:34:07 +08002579 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2580 return;
2581 /* a normal color write */
2582 assert(meta->dst.valid && !sh->uses);
2583
Chia-I Wu6032b892014-10-17 14:47:18 +08002584 /* 3DSTATE_CONSTANT_PS */
2585 offset = gen6_meta_ps_constants(cmd);
2586 cmd_batch_pointer(cmd, 5, &dw);
2587 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2588 GEN6_PCB_ANY_DW0_PCB0_VALID;
2589 dw[1] = offset;
2590 dw[2] = 0;
2591 dw[3] = 0;
2592 dw[4] = 0;
2593
2594 /* 3DSTATE_WM */
2595 offset = emit_shader(cmd, sh);
2596 cmd_batch_pointer(cmd, 9, &dw);
2597 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2598 dw[1] = offset;
2599 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2600 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2601 dw[3] = 0;
2602 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
2603 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
2604 GEN6_WM_DW5_PS_ENABLE |
2605 GEN6_WM_DW5_8_PIXEL_DISPATCH;
2606 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2607 GEN6_WM_DW6_POSOFFSET_NONE |
2608 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2609 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2610 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2611 if (meta->samples > 1) {
2612 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2613 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2614 } else {
2615 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2616 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2617 }
2618 dw[7] = 0;
2619 dw[8] = 0;
2620}
2621
2622static void gen7_meta_ps(struct intel_cmd *cmd)
2623{
2624 const struct intel_cmd_meta *meta = cmd->bind.meta;
2625 const struct intel_pipeline_shader *sh =
2626 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2627 uint32_t offset, *dw;
2628
2629 CMD_ASSERT(cmd, 7, 7.5);
2630
Chia-I Wu3adf7212014-10-24 15:34:07 +08002631 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2632 return;
2633 /* a normal color write */
2634 assert(meta->dst.valid && !sh->uses);
2635
Chia-I Wu6032b892014-10-17 14:47:18 +08002636 /* 3DSTATE_WM */
2637 cmd_batch_pointer(cmd, 3, &dw);
2638 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2639 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2640 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2641 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2642 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2643 dw[2] = 0;
2644
2645 /* 3DSTATE_CONSTANT_PS */
2646 offset = gen6_meta_ps_constants(cmd);
2647 cmd_batch_pointer(cmd, 7, &dw);
2648 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2649 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2650 dw[2] = 0;
2651 dw[3] = offset;
2652 dw[4] = 0;
2653 dw[5] = 0;
2654 dw[6] = 0;
2655
2656 /* 3DSTATE_PS */
2657 offset = emit_shader(cmd, sh);
2658 cmd_batch_pointer(cmd, 8, &dw);
2659 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2660 dw[1] = offset;
2661 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2662 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2663 dw[3] = 0;
2664
2665 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2666 GEN7_PS_DW4_POSOFFSET_NONE |
2667 GEN7_PS_DW4_8_PIXEL_DISPATCH |
2668 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2669 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
2670 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
2671
2672 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2673 dw[6] = 0;
2674 dw[7] = 0;
2675}
2676
2677static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2678{
2679 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002680 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002681
2682 CMD_ASSERT(cmd, 6, 7.5);
2683
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002684 if (!ds) {
2685 /* all zeros */
2686 static const struct intel_ds_view null_ds;
2687 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002688 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002689
2690 cmd_wa_gen6_pre_ds_flush(cmd);
2691 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2692 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2693 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2694
2695 if (cmd_gen(cmd) >= INTEL_GEN(7))
2696 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2697 else
2698 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002699}
2700
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002701static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2702 const struct intel_pipeline *pipeline)
2703{
2704 cmd->bind.pipeline.graphics = pipeline;
2705}
2706
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002707static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2708 const struct intel_pipeline *pipeline)
2709{
2710 cmd->bind.pipeline.compute = pipeline;
2711}
2712
2713static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2714 const struct intel_pipeline_delta *delta)
2715{
2716 cmd->bind.pipeline.graphics_delta = delta;
2717}
2718
2719static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2720 const struct intel_pipeline_delta *delta)
2721{
2722 cmd->bind.pipeline.compute_delta = delta;
2723}
2724
2725static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2726 const struct intel_dset *dset,
2727 XGL_UINT slot_offset)
2728{
2729 cmd->bind.dset.graphics = dset;
2730 cmd->bind.dset.graphics_offset = slot_offset;
2731}
2732
2733static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2734 const struct intel_dset *dset,
2735 XGL_UINT slot_offset)
2736{
2737 cmd->bind.dset.compute = dset;
2738 cmd->bind.dset.compute_offset = slot_offset;
2739}
2740
2741static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2742 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2743{
2744 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2745}
2746
2747static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2748 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2749{
2750 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2751}
2752
2753static void cmd_bind_index_data(struct intel_cmd *cmd,
2754 const struct intel_mem *mem,
2755 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2756{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002757 cmd->bind.index.mem = mem;
2758 cmd->bind.index.offset = offset;
2759 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002760}
2761
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002762static void cmd_bind_attachments(struct intel_cmd *cmd,
2763 XGL_UINT rt_count,
2764 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2765 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002766{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002767 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002768 XGL_UINT i;
2769
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002770 for (i = 0; i < rt_count; i++) {
2771 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002772 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002773 const struct intel_layout *layout = &rt->img->layout;
2774
2775 if (i == 0) {
2776 width = layout->width0;
2777 height = layout->height0;
2778 } else {
2779 if (width > layout->width0)
2780 width = layout->width0;
2781 if (height > layout->height0)
2782 height = layout->height0;
2783 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002784
2785 cmd->bind.att.rt[i] = rt;
2786 }
2787
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002788 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002789
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002790 if (ds_info) {
2791 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002792
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002793 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2794 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002795
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002796 if (width > layout->width0)
2797 width = layout->width0;
2798 if (height > layout->height0)
2799 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002800 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002801 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002802 }
2803
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002804 cmd->bind.att.width = width;
2805 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002806}
2807
2808static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2809 const struct intel_viewport_state *state)
2810{
2811 cmd->bind.state.viewport = state;
2812}
2813
2814static void cmd_bind_raster_state(struct intel_cmd *cmd,
2815 const struct intel_raster_state *state)
2816{
2817 cmd->bind.state.raster = state;
2818}
2819
2820static void cmd_bind_ds_state(struct intel_cmd *cmd,
2821 const struct intel_ds_state *state)
2822{
2823 cmd->bind.state.ds = state;
2824}
2825
2826static void cmd_bind_blend_state(struct intel_cmd *cmd,
2827 const struct intel_blend_state *state)
2828{
2829 cmd->bind.state.blend = state;
2830}
2831
2832static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2833 const struct intel_msaa_state *state)
2834{
2835 cmd->bind.state.msaa = state;
2836}
2837
2838static void cmd_draw(struct intel_cmd *cmd,
2839 XGL_UINT vertex_start,
2840 XGL_UINT vertex_count,
2841 XGL_UINT instance_start,
2842 XGL_UINT instance_count,
2843 bool indexed,
2844 XGL_UINT vertex_base)
2845{
2846 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2847
2848 emit_bounded_states(cmd);
2849
2850 if (indexed) {
2851 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2852 cmd->result = XGL_ERROR_UNKNOWN;
2853
2854 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2855 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2856 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002857 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2858 cmd->bind.index.offset, cmd->bind.index.type,
2859 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002860 } else {
2861 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2862 cmd->bind.index.offset, cmd->bind.index.type,
2863 p->primitive_restart);
2864 }
2865 } else {
2866 assert(!vertex_base);
2867 }
2868
2869 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2870 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2871 vertex_start, instance_count, instance_start, vertex_base);
2872 } else {
2873 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2874 vertex_start, instance_count, instance_start, vertex_base);
2875 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002876
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002877 if (intel_debug & INTEL_DEBUG_NOCACHE)
2878 cmd_batch_flush_all(cmd);
2879
Chia-I Wu707a29e2014-08-27 12:51:47 +08002880 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002881 /* need to re-emit all workarounds */
2882 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002883}
2884
Chia-I Wuc14d1562014-10-17 09:49:22 +08002885void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2886{
Chia-I Wu6032b892014-10-17 14:47:18 +08002887 cmd->bind.meta = meta;
2888
2889 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08002890 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002891
2892 gen6_meta_dynamic_states(cmd);
2893 gen6_meta_surface_states(cmd);
2894
2895 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2896 gen7_meta_urb(cmd);
2897 gen6_meta_vf(cmd);
2898 gen7_meta_disabled(cmd);
2899 gen6_meta_wm(cmd);
2900 gen7_meta_ps(cmd);
2901 gen6_meta_depth_buffer(cmd);
2902
2903 cmd_wa_gen7_post_command_cs_stall(cmd);
2904 cmd_wa_gen7_post_command_depth_stall(cmd);
2905
2906 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2907 } else {
2908 gen6_meta_urb(cmd);
2909 gen6_meta_vf(cmd);
2910 gen6_meta_disabled(cmd);
2911 gen6_meta_wm(cmd);
2912 gen6_meta_ps(cmd);
2913 gen6_meta_depth_buffer(cmd);
2914
2915 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2916 }
2917
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08002918 if (intel_debug & INTEL_DEBUG_NOCACHE)
2919 cmd_batch_flush_all(cmd);
2920
Chia-I Wu6032b892014-10-17 14:47:18 +08002921 cmd->bind.draw_count++;
2922 /* need to re-emit all workarounds */
2923 cmd->bind.wa_flags = 0;
2924
2925 cmd->bind.meta = NULL;
Chia-I Wuc14d1562014-10-17 09:49:22 +08002926}
2927
Chia-I Wub2755562014-08-20 13:38:52 +08002928XGL_VOID XGLAPI intelCmdBindPipeline(
2929 XGL_CMD_BUFFER cmdBuffer,
2930 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2931 XGL_PIPELINE pipeline)
2932{
2933 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2934
2935 switch (pipelineBindPoint) {
2936 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002937 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002938 break;
2939 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002940 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002941 break;
2942 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002943 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002944 break;
2945 }
2946}
2947
2948XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2949 XGL_CMD_BUFFER cmdBuffer,
2950 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2951 XGL_PIPELINE_DELTA delta)
2952{
2953 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2954
2955 switch (pipelineBindPoint) {
2956 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002957 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002958 break;
2959 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002960 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002961 break;
2962 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002963 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002964 break;
2965 }
2966}
2967
2968XGL_VOID XGLAPI intelCmdBindStateObject(
2969 XGL_CMD_BUFFER cmdBuffer,
2970 XGL_STATE_BIND_POINT stateBindPoint,
2971 XGL_STATE_OBJECT state)
2972{
2973 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2974
2975 switch (stateBindPoint) {
2976 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002977 cmd_bind_viewport_state(cmd,
2978 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002979 break;
2980 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002981 cmd_bind_raster_state(cmd,
2982 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002983 break;
2984 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002985 cmd_bind_ds_state(cmd,
2986 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002987 break;
2988 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002989 cmd_bind_blend_state(cmd,
2990 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002991 break;
2992 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002993 cmd_bind_msaa_state(cmd,
2994 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002995 break;
2996 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002997 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002998 break;
2999 }
3000}
3001
3002XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3003 XGL_CMD_BUFFER cmdBuffer,
3004 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3005 XGL_UINT index,
3006 XGL_DESCRIPTOR_SET descriptorSet,
3007 XGL_UINT slotOffset)
3008{
3009 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3010 struct intel_dset *dset = intel_dset(descriptorSet);
3011
3012 assert(!index);
3013
3014 switch (pipelineBindPoint) {
3015 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003016 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003017 break;
3018 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003019 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003020 break;
3021 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003022 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003023 break;
3024 }
3025}
3026
3027XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3028 XGL_CMD_BUFFER cmdBuffer,
3029 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3030 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3031{
3032 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3033
3034 switch (pipelineBindPoint) {
3035 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003036 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003037 break;
3038 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003039 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003040 break;
3041 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003042 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003043 break;
3044 }
3045}
3046
3047XGL_VOID XGLAPI intelCmdBindIndexData(
3048 XGL_CMD_BUFFER cmdBuffer,
3049 XGL_GPU_MEMORY mem_,
3050 XGL_GPU_SIZE offset,
3051 XGL_INDEX_TYPE indexType)
3052{
3053 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3054 struct intel_mem *mem = intel_mem(mem_);
3055
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003056 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003057}
3058
3059XGL_VOID XGLAPI intelCmdBindAttachments(
3060 XGL_CMD_BUFFER cmdBuffer,
3061 XGL_UINT colorAttachmentCount,
3062 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3063 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3064{
3065 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003066
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003067 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3068 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003069}
3070
3071XGL_VOID XGLAPI intelCmdDraw(
3072 XGL_CMD_BUFFER cmdBuffer,
3073 XGL_UINT firstVertex,
3074 XGL_UINT vertexCount,
3075 XGL_UINT firstInstance,
3076 XGL_UINT instanceCount)
3077{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003078 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003079
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003080 cmd_draw(cmd, firstVertex, vertexCount,
3081 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003082}
3083
3084XGL_VOID XGLAPI intelCmdDrawIndexed(
3085 XGL_CMD_BUFFER cmdBuffer,
3086 XGL_UINT firstIndex,
3087 XGL_UINT indexCount,
3088 XGL_INT vertexOffset,
3089 XGL_UINT firstInstance,
3090 XGL_UINT instanceCount)
3091{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003092 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003093
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003094 cmd_draw(cmd, firstIndex, indexCount,
3095 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003096}
3097
3098XGL_VOID XGLAPI intelCmdDrawIndirect(
3099 XGL_CMD_BUFFER cmdBuffer,
3100 XGL_GPU_MEMORY mem,
3101 XGL_GPU_SIZE offset,
3102 XGL_UINT32 count,
3103 XGL_UINT32 stride)
3104{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003105 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3106
3107 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003108}
3109
3110XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3111 XGL_CMD_BUFFER cmdBuffer,
3112 XGL_GPU_MEMORY mem,
3113 XGL_GPU_SIZE offset,
3114 XGL_UINT32 count,
3115 XGL_UINT32 stride)
3116{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003117 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3118
3119 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003120}
3121
3122XGL_VOID XGLAPI intelCmdDispatch(
3123 XGL_CMD_BUFFER cmdBuffer,
3124 XGL_UINT x,
3125 XGL_UINT y,
3126 XGL_UINT z)
3127{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003128 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3129
3130 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003131}
3132
3133XGL_VOID XGLAPI intelCmdDispatchIndirect(
3134 XGL_CMD_BUFFER cmdBuffer,
3135 XGL_GPU_MEMORY mem,
3136 XGL_GPU_SIZE offset)
3137{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003138 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3139
3140 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003141}