blob: b1416bd411aee0fba9504412707a6c7dc2829d2d [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{
GregF8cd81832014-11-18 18:01:01 -0700446 XGL_UINT sbe_offset;
447 XGL_INT i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448
449 CMD_ASSERT(cmd, 6, 7.5);
450
GregF8cd81832014-11-18 18:01:01 -0700451 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452
GregF8cd81832014-11-18 18:01:01 -0700453 for (i = 0; i < 13; i++) {
454 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
455 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800456 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800457}
458
459static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
460{
461 const uint8_t cmd_len = 20;
462 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
463 (cmd_len - 2);
464 uint32_t sf[6];
465 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 6, 6);
469
470 gen7_fill_3DSTATE_SF_body(cmd, sf);
471 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
474 dw[0] = dw0;
475 dw[1] = sbe[0];
476 memcpy(&dw[2], sf, sizeof(sf));
477 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800478}
479
480static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
481{
482 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800483 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800484
485 CMD_ASSERT(cmd, 7, 7.5);
486
Chia-I Wu72292b72014-09-09 10:48:33 +0800487 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
489 (cmd_len - 2);
490 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800491}
492
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800493static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
494{
495 const uint8_t cmd_len = 4;
496 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
497 (cmd_len - 2);
498 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700499 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800500 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800501 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
502 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800503 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800504
505 CMD_ASSERT(cmd, 6, 7.5);
506
507 dw1 = GEN6_CLIP_DW1_STATISTICS;
508 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
509 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
510 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
511 raster->cmd_clip_cull;
512 }
513
514 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
515 GEN6_CLIP_DW2_XY_TEST_ENABLE |
516 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700517 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800518 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
519 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
520 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
521
522 if (pipeline->rasterizerDiscardEnable)
523 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
524 else
525 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
526
527 if (pipeline->depthClipEnable)
528 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
529
530 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
531 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
532 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
533 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
534
535 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
536 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
537 (viewport->viewport_count - 1);
538
Chia-I Wu72292b72014-09-09 10:48:33 +0800539 cmd_batch_pointer(cmd, cmd_len, &dw);
540 dw[0] = dw0;
541 dw[1] = dw1;
542 dw[2] = dw2;
543 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800544}
545
Chia-I Wu05990612014-11-25 11:36:35 +0800546static int cmd_vs_max_threads(const struct intel_cmd *cmd)
547{
548 switch (cmd_gen(cmd)) {
549 case INTEL_GEN(7.5):
550 return (cmd->dev->gpu->gt >= 2) ? 280 : 70;
551 case INTEL_GEN(7):
552 return (cmd->dev->gpu->gt == 2) ? 128 : 36;
553 case INTEL_GEN(6):
554 return (cmd->dev->gpu->gt == 2) ? 60 : 24;
555 default:
556 return 1;
557 }
558}
559
560static int cmd_ps_max_threads(const struct intel_cmd *cmd)
561{
562 switch (cmd_gen(cmd)) {
563 case INTEL_GEN(7.5):
564 return (cmd->dev->gpu->gt == 3) ? 408 :
565 (cmd->dev->gpu->gt == 2) ? 204 : 102;
566 case INTEL_GEN(7):
567 return (cmd->dev->gpu->gt == 2) ? 172 : 48;
568 case INTEL_GEN(6):
569 return (cmd->dev->gpu->gt == 2) ? 80 : 40;
570 default:
571 return 4;
572 }
573}
574
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800575static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
576{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800577 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800578 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800579 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
580 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800581 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800582
583 CMD_ASSERT(cmd, 6, 6);
584
585 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
586
587 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
588 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
589
590 dw4 = GEN6_WM_DW4_STATISTICS |
591 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
592 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
593 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
594
Chia-I Wu05990612014-11-25 11:36:35 +0800595 dw5 = (cmd_ps_max_threads(cmd) - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596 GEN6_WM_DW5_PS_ENABLE |
597 GEN6_WM_DW5_8_PIXEL_DISPATCH;
598
599 if (fs->uses & INTEL_SHADER_USE_KILL ||
600 pipeline->cb_state.alphaToCoverageEnable)
601 dw5 |= GEN6_WM_DW5_PS_KILL;
602
603 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
604 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
605 if (fs->uses & INTEL_SHADER_USE_DEPTH)
606 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
607 if (fs->uses & INTEL_SHADER_USE_W)
608 dw5 |= GEN6_WM_DW5_PS_USE_W;
609
610 if (pipeline->cb_state.dualSourceBlendEnable)
611 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
612
613 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
614 GEN6_WM_DW6_POSOFFSET_NONE |
615 GEN6_WM_DW6_ZW_INTERP_PIXEL |
616 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
617 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
618
619 if (msaa->sample_count > 1) {
620 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
621 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
622 } else {
623 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
624 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
625 }
626
Chia-I Wu72292b72014-09-09 10:48:33 +0800627 cmd_batch_pointer(cmd, cmd_len, &dw);
628 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800629 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800630 dw[2] = dw2;
631 dw[3] = 0; /* scratch */
632 dw[4] = dw4;
633 dw[5] = dw5;
634 dw[6] = dw6;
635 dw[7] = 0; /* kernel 1 */
636 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800637}
638
639static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
640{
641 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800642 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800643 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
644 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800645 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800646
647 CMD_ASSERT(cmd, 7, 7.5);
648
649 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
650
651 dw1 = GEN7_WM_DW1_STATISTICS |
652 GEN7_WM_DW1_PS_ENABLE |
653 GEN7_WM_DW1_ZW_INTERP_PIXEL |
654 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
655 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
656
657 if (fs->uses & INTEL_SHADER_USE_KILL ||
658 pipeline->cb_state.alphaToCoverageEnable)
659 dw1 |= GEN7_WM_DW1_PS_KILL;
660
661 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
662 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
663 if (fs->uses & INTEL_SHADER_USE_DEPTH)
664 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
665 if (fs->uses & INTEL_SHADER_USE_W)
666 dw1 |= GEN7_WM_DW1_PS_USE_W;
667
668 dw2 = 0;
669
670 if (msaa->sample_count > 1) {
671 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
672 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
673 } else {
674 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
675 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
676 }
677
Chia-I Wu72292b72014-09-09 10:48:33 +0800678 cmd_batch_pointer(cmd, cmd_len, &dw);
679 dw[0] = dw0;
680 dw[1] = dw1;
681 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800682}
683
684static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
685{
686 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800687 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
Chia-I Wu05990612014-11-25 11:36:35 +0800689 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800690 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800691 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800692
693 CMD_ASSERT(cmd, 7, 7.5);
694
695 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
696
697 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
698 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
699
700 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
701 GEN7_PS_DW4_8_PIXEL_DISPATCH;
702
703 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
705 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
706 } else {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800707 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
708 }
709
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800710 if (fs->in_count)
711 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
712
713 if (pipeline->cb_state.dualSourceBlendEnable)
714 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
715
716 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
717 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
718 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
719
Chia-I Wu72292b72014-09-09 10:48:33 +0800720 cmd_batch_pointer(cmd, cmd_len, &dw);
721 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800722 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800723 dw[2] = dw2;
724 dw[3] = 0; /* scratch */
725 dw[4] = dw4;
726 dw[5] = dw5;
727 dw[6] = 0; /* kernel 1 */
728 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800729}
730
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800731static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
732 const struct intel_ds_view *view)
733{
734 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800735 uint32_t dw0, *dw;
736 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800737
738 CMD_ASSERT(cmd, 6, 7.5);
739
740 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800741 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
742 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800743 dw0 |= (cmd_len - 2);
744
Chia-I Wu72292b72014-09-09 10:48:33 +0800745 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
746 dw[0] = dw0;
747 dw[1] = view->cmd[0];
748 dw[2] = 0;
749 dw[3] = view->cmd[2];
750 dw[4] = view->cmd[3];
751 dw[5] = view->cmd[4];
752 dw[6] = view->cmd[5];
753
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600754 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800755 cmd_reserve_reloc(cmd, 1);
756 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
757 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600758 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800759}
760
761static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
762 const struct intel_ds_view *view)
763{
764 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800765 uint32_t dw0, *dw;
766 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767
768 CMD_ASSERT(cmd, 6, 7.5);
769
770 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800771 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
772 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800773 dw0 |= (cmd_len - 2);
774
Chia-I Wu72292b72014-09-09 10:48:33 +0800775 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
776 dw[0] = dw0;
777 dw[1] = view->cmd[6];
778 dw[2] = 0;
779
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600780 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800781 cmd_reserve_reloc(cmd, 1);
782 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
783 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600784 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800785}
786
787static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
788 const struct intel_ds_view *view)
789{
790 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800791 uint32_t dw0, *dw;
792 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793
794 CMD_ASSERT(cmd, 6, 7.5);
795
796 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800797 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
798 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800799 dw0 |= (cmd_len - 2);
800
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
802 dw[0] = dw0;
803 dw[1] = view->cmd[8];
804 dw[2] = 0;
805
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600806 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800807 cmd_reserve_reloc(cmd, 1);
808 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
809 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600810 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800811}
812
Chia-I Wuf8231032014-08-25 10:44:45 +0800813static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
814 uint32_t clear_val)
815{
816 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800817 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800818 GEN6_CLEAR_PARAMS_DW0_VALID |
819 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800820 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800821
822 CMD_ASSERT(cmd, 6, 6);
823
Chia-I Wu72292b72014-09-09 10:48:33 +0800824 cmd_batch_pointer(cmd, cmd_len, &dw);
825 dw[0] = dw0;
826 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800827}
828
829static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
830 uint32_t clear_val)
831{
832 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800833 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800834 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800835 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800836
837 CMD_ASSERT(cmd, 7, 7.5);
838
Chia-I Wu72292b72014-09-09 10:48:33 +0800839 cmd_batch_pointer(cmd, cmd_len, &dw);
840 dw[0] = dw0;
841 dw[1] = clear_val;
842 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800843}
844
Chia-I Wu302742d2014-08-22 10:28:29 +0800845static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800846 uint32_t blend_offset,
847 uint32_t ds_offset,
848 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800849{
850 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800851 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800852
853 CMD_ASSERT(cmd, 6, 6);
854
Chia-I Wu426072d2014-08-26 14:31:55 +0800855 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800856 (cmd_len - 2);
857
Chia-I Wu72292b72014-09-09 10:48:33 +0800858 cmd_batch_pointer(cmd, cmd_len, &dw);
859 dw[0] = dw0;
860 dw[1] = blend_offset | 1;
861 dw[2] = ds_offset | 1;
862 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800863}
864
Chia-I Wu1744cca2014-08-22 11:10:17 +0800865static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800866 uint32_t clip_offset,
867 uint32_t sf_offset,
868 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800869{
870 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800871 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800872
873 CMD_ASSERT(cmd, 6, 6);
874
Chia-I Wu426072d2014-08-26 14:31:55 +0800875 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800876 GEN6_PTR_VP_DW0_CLIP_CHANGED |
877 GEN6_PTR_VP_DW0_SF_CHANGED |
878 GEN6_PTR_VP_DW0_CC_CHANGED |
879 (cmd_len - 2);
880
Chia-I Wu72292b72014-09-09 10:48:33 +0800881 cmd_batch_pointer(cmd, cmd_len, &dw);
882 dw[0] = dw0;
883 dw[1] = clip_offset;
884 dw[2] = sf_offset;
885 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800886}
887
888static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800889 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800890{
891 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800893
894 CMD_ASSERT(cmd, 6, 6);
895
Chia-I Wu426072d2014-08-26 14:31:55 +0800896 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800897 (cmd_len - 2);
898
Chia-I Wu72292b72014-09-09 10:48:33 +0800899 cmd_batch_pointer(cmd, cmd_len, &dw);
900 dw[0] = dw0;
901 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800902}
903
Chia-I Wu42a56202014-08-23 16:47:48 +0800904static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800905 uint32_t vs_offset,
906 uint32_t gs_offset,
907 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800908{
909 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800910 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800911
912 CMD_ASSERT(cmd, 6, 6);
913
Chia-I Wu426072d2014-08-26 14:31:55 +0800914 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800915 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
916 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
917 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
918 (cmd_len - 2);
919
Chia-I Wu72292b72014-09-09 10:48:33 +0800920 cmd_batch_pointer(cmd, cmd_len, &dw);
921 dw[0] = dw0;
922 dw[1] = vs_offset;
923 dw[2] = gs_offset;
924 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800925}
926
Chia-I Wu257e75e2014-08-29 14:06:35 +0800927static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800928 uint32_t vs_offset,
929 uint32_t gs_offset,
930 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800931{
932 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800933 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800934
935 CMD_ASSERT(cmd, 6, 6);
936
937 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
938 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
939 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
940 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
941 (cmd_len - 2);
942
Chia-I Wu72292b72014-09-09 10:48:33 +0800943 cmd_batch_pointer(cmd, cmd_len, &dw);
944 dw[0] = dw0;
945 dw[1] = vs_offset;
946 dw[2] = gs_offset;
947 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800948}
949
Chia-I Wu302742d2014-08-22 10:28:29 +0800950static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800951 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800952{
953 const uint8_t cmd_len = 2;
954 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
955 GEN6_RENDER_SUBTYPE_3D |
956 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800958
Chia-I Wu72292b72014-09-09 10:48:33 +0800959 cmd_batch_pointer(cmd, cmd_len, &dw);
960 dw[0] = dw0;
961 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800962}
963
Chia-I Wua6c4f152014-12-02 04:19:58 +0800964static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800965{
Chia-I Wue6073342014-11-30 09:43:42 +0800966 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800967 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
Chia-I Wua6c4f152014-12-02 04:19:58 +0800968 const XGL_PIPELINE_CB_STATE *cb = &cmd->bind.pipeline.graphics->cb_state;
969 const struct intel_blend_state *blend = cmd->bind.state.blend;
970 uint32_t dw[XGL_MAX_COLOR_ATTACHMENTS * 2];
971 int i;
Chia-I Wu302742d2014-08-22 10:28:29 +0800972
973 CMD_ASSERT(cmd, 6, 7.5);
Chia-I Wua6c4f152014-12-02 04:19:58 +0800974 STATIC_ASSERT(ARRAY_SIZE(blend->cmd_blend) >= XGL_MAX_COLOR_ATTACHMENTS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800975
Chia-I Wua6c4f152014-12-02 04:19:58 +0800976 for (i = 0; i < XGL_MAX_COLOR_ATTACHMENTS; i++) {
977 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &cb->attachment[i];
978 uint32_t dw0, dw1;
979
980 dw0 = 0;
981 dw1 = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
982 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
983 GEN6_BLEND_DW1_POST_BLEND_CLAMP;
984
985 if (cb->logicOp != XGL_LOGIC_OP_COPY) {
986 int logicop;
987
988 switch (cb->logicOp) {
989 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
990 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
991 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
992 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
993 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
994 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
995 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
996 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
997 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
998 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
999 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1000 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1001 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1002 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1003 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1004 default:
1005 assert(!"unknown logic op");
1006 logicop = GEN6_LOGICOP_CLEAR;
1007 break;
1008 }
1009
1010 dw1 |= GEN6_BLEND_DW1_LOGICOP_ENABLE |
1011 logicop << GEN6_BLEND_DW1_LOGICOP_FUNC__SHIFT;
1012 } else if (att->blendEnable && blend) {
1013 dw0 |= blend->cmd_blend[i];
1014 }
1015
1016 if (!(att->channelWriteMask & 0x1))
1017 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_R;
1018 if (!(att->channelWriteMask & 0x2))
1019 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_G;
1020 if (!(att->channelWriteMask & 0x4))
1021 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_B;
1022 if (!(att->channelWriteMask & 0x8))
1023 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_A;
1024
1025 dw[2 * i] = dw0;
1026 dw[2 * i + 1] = dw1;
1027 }
1028
1029 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001030}
1031
Chia-I Wu72292b72014-09-09 10:48:33 +08001032static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001033 const struct intel_ds_state *state)
1034{
Chia-I Wue6073342014-11-30 09:43:42 +08001035 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001036 const uint8_t cmd_len = 3;
1037
1038 CMD_ASSERT(cmd, 6, 7.5);
1039 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1040
Chia-I Wu00b51a82014-09-09 12:07:37 +08001041 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1042 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001043}
1044
Chia-I Wu72292b72014-09-09 10:48:33 +08001045static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001046 uint32_t stencil_ref,
1047 const uint32_t blend_color[4])
1048{
Chia-I Wue6073342014-11-30 09:43:42 +08001049 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001050 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001051 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001052
1053 CMD_ASSERT(cmd, 6, 7.5);
1054
Chia-I Wu00b51a82014-09-09 12:07:37 +08001055 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1056 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001057 dw[0] = stencil_ref;
1058 dw[1] = 0;
1059 dw[2] = blend_color[0];
1060 dw[3] = blend_color[1];
1061 dw[4] = blend_color[2];
1062 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001063
Chia-I Wu72292b72014-09-09 10:48:33 +08001064 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001065}
1066
Chia-I Wu8370b402014-08-29 12:28:37 +08001067static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001068{
Chia-I Wu8370b402014-08-29 12:28:37 +08001069 CMD_ASSERT(cmd, 6, 7.5);
1070
Chia-I Wu707a29e2014-08-27 12:51:47 +08001071 if (!cmd->bind.draw_count)
1072 return;
1073
Chia-I Wu8370b402014-08-29 12:28:37 +08001074 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001075 return;
1076
Chia-I Wu8370b402014-08-29 12:28:37 +08001077 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001078
1079 /*
1080 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1081 *
1082 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1083 * pipe-control with a post-sync op and no write-cache flushes."
1084 *
1085 * The workaround below necessitates this workaround.
1086 */
1087 gen6_PIPE_CONTROL(cmd,
1088 GEN6_PIPE_CONTROL_CS_STALL |
1089 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001090 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001091
Chia-I Wud6d079d2014-08-31 13:14:21 +08001092 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1093 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001094}
1095
Chia-I Wu8370b402014-08-29 12:28:37 +08001096static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001097{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001098 CMD_ASSERT(cmd, 6, 7.5);
1099
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001100 if (!cmd->bind.draw_count)
1101 return;
1102
Chia-I Wud6d079d2014-08-31 13:14:21 +08001103 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1104 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001105}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001106
Chia-I Wu8370b402014-08-29 12:28:37 +08001107static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1108{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001109 CMD_ASSERT(cmd, 7, 7.5);
1110
Chia-I Wu8370b402014-08-29 12:28:37 +08001111 if (!cmd->bind.draw_count)
1112 return;
1113
1114 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001115
1116 gen6_PIPE_CONTROL(cmd,
1117 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001118 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001119}
1120
Chia-I Wu8370b402014-08-29 12:28:37 +08001121static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1122{
1123 CMD_ASSERT(cmd, 7, 7.5);
1124
1125 if (!cmd->bind.draw_count)
1126 return;
1127
1128 /*
1129 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1130 *
1131 * "One of the following must also be set (when CS stall is set):
1132 *
1133 * * Render Target Cache Flush Enable ([12] of DW1)
1134 * * Depth Cache Flush Enable ([0] of DW1)
1135 * * Stall at Pixel Scoreboard ([1] of DW1)
1136 * * Depth Stall ([13] of DW1)
1137 * * Post-Sync Operation ([13] of DW1)"
1138 */
1139 gen6_PIPE_CONTROL(cmd,
1140 GEN6_PIPE_CONTROL_CS_STALL |
1141 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001142 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001143}
1144
1145static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1146{
1147 CMD_ASSERT(cmd, 7, 7.5);
1148
1149 if (!cmd->bind.draw_count)
1150 return;
1151
1152 cmd_wa_gen6_pre_depth_stall_write(cmd);
1153
Chia-I Wud6d079d2014-08-31 13:14:21 +08001154 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001155}
1156
1157static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1158{
1159 CMD_ASSERT(cmd, 6, 7.5);
1160
1161 if (!cmd->bind.draw_count)
1162 return;
1163
1164 /*
1165 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1166 *
1167 * "Driver must guarentee that all the caches in the depth pipe are
1168 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1169 * requires driver to send a PIPE_CONTROL with a CS stall along with
1170 * a Depth Flush prior to this command."
1171 *
1172 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1173 *
1174 * "Driver must ierarchi that all the caches in the depth pipe are
1175 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1176 * requires driver to send a PIPE_CONTROL with a CS stall along with
1177 * a Depth Flush prior to this command.
1178 */
1179 gen6_PIPE_CONTROL(cmd,
1180 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1181 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001182 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001183}
1184
1185static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1186{
1187 CMD_ASSERT(cmd, 6, 7.5);
1188
1189 if (!cmd->bind.draw_count)
1190 return;
1191
1192 /*
1193 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1194 *
1195 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1196 * and a post sync operation prior to the group of depth
1197 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1198 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1199 *
1200 * This workaround satifies all the conditions.
1201 */
1202 cmd_wa_gen6_pre_depth_stall_write(cmd);
1203
1204 /*
1205 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1206 *
1207 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1208 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1209 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1210 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1211 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1212 * Depth Flush Bit set, followed by another pipelined depth stall
1213 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1214 * guarantee that the pipeline from WM onwards is already flushed
1215 * (e.g., via a preceding MI_FLUSH)."
1216 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001217 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1218 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1219 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001220}
1221
Chia-I Wu525c6602014-08-27 10:22:34 +08001222void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1223{
1224 if (!cmd->bind.draw_count)
1225 return;
1226
1227 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1228
Chia-I Wu8370b402014-08-29 12:28:37 +08001229 /*
1230 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1231 *
1232 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1233 * PIPE_CONTROL with any non-zero post-sync-op is required."
1234 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001235 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001236 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001237
Chia-I Wu092279a2014-08-30 19:05:30 +08001238 /*
1239 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1240 *
1241 * "One of the following must also be set (when CS stall is set):
1242 *
1243 * * Render Target Cache Flush Enable ([12] of DW1)
1244 * * Depth Cache Flush Enable ([0] of DW1)
1245 * * Stall at Pixel Scoreboard ([1] of DW1)
1246 * * Depth Stall ([13] of DW1)
1247 * * Post-Sync Operation ([13] of DW1)"
1248 */
1249 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1250 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1251 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1252 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1253 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1254 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1255
Chia-I Wud6d079d2014-08-31 13:14:21 +08001256 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001257}
1258
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001259void cmd_batch_flush_all(struct intel_cmd *cmd)
1260{
1261 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1262 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1263 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1264 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1265 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1266 GEN6_PIPE_CONTROL_CS_STALL);
1267}
1268
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001269void cmd_batch_depth_count(struct intel_cmd *cmd,
1270 struct intel_bo *bo,
1271 XGL_GPU_SIZE offset)
1272{
1273 cmd_wa_gen6_pre_depth_stall_write(cmd);
1274
1275 gen6_PIPE_CONTROL(cmd,
1276 GEN6_PIPE_CONTROL_DEPTH_STALL |
1277 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001278 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001279}
1280
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001281void cmd_batch_timestamp(struct intel_cmd *cmd,
1282 struct intel_bo *bo,
1283 XGL_GPU_SIZE offset)
1284{
1285 /* need any WA or stall? */
1286 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1287}
1288
1289void cmd_batch_immediate(struct intel_cmd *cmd,
1290 struct intel_bo *bo,
1291 XGL_GPU_SIZE offset,
1292 uint64_t val)
1293{
1294 /* need any WA or stall? */
1295 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1296}
1297
Chia-I Wu302742d2014-08-22 10:28:29 +08001298static void gen6_cc_states(struct intel_cmd *cmd)
1299{
1300 const struct intel_blend_state *blend = cmd->bind.state.blend;
1301 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001302 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001303 uint32_t stencil_ref;
1304 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001305
1306 CMD_ASSERT(cmd, 6, 6);
1307
Chia-I Wua6c4f152014-12-02 04:19:58 +08001308 blend_offset = gen6_BLEND_STATE(cmd);
1309
1310 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001311 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001312 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001313 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001314
1315 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001316 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001317 stencil_ref = ds->cmd_stencil_ref;
1318 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001319 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001320 stencil_ref = 0;
1321 }
1322
Chia-I Wu72292b72014-09-09 10:48:33 +08001323 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001324
Chia-I Wu72292b72014-09-09 10:48:33 +08001325 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001326}
1327
Chia-I Wu1744cca2014-08-22 11:10:17 +08001328static void gen6_viewport_states(struct intel_cmd *cmd)
1329{
1330 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001331 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001332
1333 if (!viewport)
1334 return;
1335
Chia-I Wub1d450a2014-09-09 13:48:03 +08001336 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1337 viewport->viewport_count);
1338
1339 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001340 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001341 viewport->cmd);
1342
1343 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001344 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001345 &viewport->cmd[viewport->cmd_clip_pos]);
1346
1347 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001348 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001349 &viewport->cmd[viewport->cmd_cc_pos]);
1350
1351 if (viewport->scissor_enable) {
1352 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001353 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001354 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1355 } else {
1356 scissor_offset = 0;
1357 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001358
1359 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001360 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001361
Chia-I Wub1d450a2014-09-09 13:48:03 +08001362 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001363}
1364
Chia-I Wu302742d2014-08-22 10:28:29 +08001365static void gen7_cc_states(struct intel_cmd *cmd)
1366{
1367 const struct intel_blend_state *blend = cmd->bind.state.blend;
1368 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001369 uint32_t stencil_ref;
1370 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001371 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001372
1373 CMD_ASSERT(cmd, 7, 7.5);
1374
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001375 if (!blend && !ds)
1376 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001377
Chia-I Wua6c4f152014-12-02 04:19:58 +08001378 offset = gen6_BLEND_STATE(cmd);
1379 gen7_3dstate_pointer(cmd,
1380 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001381
Chia-I Wua6c4f152014-12-02 04:19:58 +08001382 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001383 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001384 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001385 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001386
1387 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001388 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001389 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001390 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1391 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001392 } else {
1393 stencil_ref = 0;
1394 }
1395
Chia-I Wu72292b72014-09-09 10:48:33 +08001396 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001397 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001398 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001399}
1400
Chia-I Wu1744cca2014-08-22 11:10:17 +08001401static void gen7_viewport_states(struct intel_cmd *cmd)
1402{
1403 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001404 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001405
1406 if (!viewport)
1407 return;
1408
Chia-I Wub1d450a2014-09-09 13:48:03 +08001409 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1410 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001411
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001413 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001414 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001415 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001416 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1417 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001418
1419 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001420 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001421 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001422 gen7_3dstate_pointer(cmd,
1423 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001424 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001425
Chia-I Wu1744cca2014-08-22 11:10:17 +08001426 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001428 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001429 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001430 gen7_3dstate_pointer(cmd,
1431 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001432 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001433 }
1434}
1435
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001436static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001437 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001438{
1439 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001440 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001441
Chia-I Wu72292b72014-09-09 10:48:33 +08001442 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001443
1444 dw[0] = GEN6_RENDER_TYPE_RENDER |
1445 GEN6_RENDER_SUBTYPE_3D |
1446 subop | (cmd_len - 2);
1447 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001448 dw[2] = 0;
1449 dw[3] = 0;
1450 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001451}
1452
1453static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001454 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001455{
1456 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001457 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001458
Chia-I Wu72292b72014-09-09 10:48:33 +08001459 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001460
1461 dw[0] = GEN6_RENDER_TYPE_RENDER |
1462 GEN6_RENDER_SUBTYPE_3D |
1463 subop | (cmd_len - 2);
1464 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001465 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001466 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001467 dw[4] = 0;
1468 dw[5] = 0;
1469 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001470}
1471
Chia-I Wu625105f2014-10-13 15:35:29 +08001472static uint32_t emit_samplers(struct intel_cmd *cmd,
1473 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001474{
1475 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1476 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001477 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001478 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001479 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001480 XGL_UINT i;
1481
1482 CMD_ASSERT(cmd, 6, 7.5);
1483
Chia-I Wu625105f2014-10-13 15:35:29 +08001484 if (!rmap || !rmap->sampler_count)
1485 return 0;
1486
1487 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1488
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001489 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001490 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001491 border_stride * rmap->sampler_count, &border_dw);
1492
1493 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001494 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001495 4 * rmap->sampler_count, &sampler_dw);
1496
1497 for (i = 0; i < rmap->sampler_count; i++) {
1498 const struct intel_pipeline_rmap_slot *slot =
1499 &rmap->slots[surface_count + i];
1500 const struct intel_sampler *sampler;
1501
1502 switch (slot->path_len) {
1503 case 0:
1504 sampler = NULL;
1505 break;
1506 case INTEL_PIPELINE_RMAP_SLOT_RT:
1507 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1508 assert(!"unexpected rmap slot type");
1509 sampler = NULL;
1510 break;
1511 case 1:
1512 {
1513 const struct intel_dset *dset = cmd->bind.dset.graphics;
1514 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1515 const struct intel_dset_slot *dset_slot =
1516 &dset->slots[slot_offset + slot->u.index];
1517
1518 switch (dset_slot->type) {
1519 case INTEL_DSET_SLOT_SAMPLER:
1520 sampler = dset_slot->u.sampler;
1521 break;
1522 default:
1523 assert(!"unexpected dset slot type");
1524 sampler = NULL;
1525 break;
1526 }
1527 }
1528 break;
1529 default:
1530 assert(!"nested descriptor set unsupported");
1531 sampler = NULL;
1532 break;
1533 }
1534
1535 if (sampler) {
1536 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1537
1538 sampler_dw[0] = sampler->cmd[0];
1539 sampler_dw[1] = sampler->cmd[1];
1540 sampler_dw[2] = border_offset;
1541 sampler_dw[3] = sampler->cmd[2];
1542 } else {
1543 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1544 sampler_dw[1] = 0;
1545 sampler_dw[2] = 0;
1546 sampler_dw[3] = 0;
1547 }
1548
1549 border_offset += border_stride * 4;
1550 border_dw += border_stride;
1551 sampler_dw += 4;
1552 }
1553
Chia-I Wu625105f2014-10-13 15:35:29 +08001554 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001555}
1556
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001557static uint32_t emit_binding_table(struct intel_cmd *cmd,
1558 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001559{
Chia-I Wu72292b72014-09-09 10:48:33 +08001560 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001561 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001562
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001563 CMD_ASSERT(cmd, 6, 7.5);
1564
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001565 surface_count = (rmap) ?
1566 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1567 if (!surface_count)
1568 return 0;
1569
Chia-I Wu42a56202014-08-23 16:47:48 +08001570 assert(surface_count <= ARRAY_SIZE(binding_table));
1571
1572 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001573 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001574
1575 switch (slot->path_len) {
1576 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001577 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001578 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001579 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001580 {
1581 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1582
Chia-I Wu00b51a82014-09-09 12:07:37 +08001583 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001584 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001585 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001586
Chia-I Wu72292b72014-09-09 10:48:33 +08001587 cmd_reserve_reloc(cmd, 1);
1588 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1589 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001590 }
1591 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001592 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001593 {
1594 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001595 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001596
Chia-I Wu00b51a82014-09-09 12:07:37 +08001597 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001598 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001599 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001600
Chia-I Wu72292b72014-09-09 10:48:33 +08001601 cmd_reserve_reloc(cmd, 1);
1602 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1603 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001604 }
1605 break;
1606 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001607 {
1608 const struct intel_dset *dset = cmd->bind.dset.graphics;
1609 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1610 const struct intel_dset_slot *dset_slot =
1611 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001612 const uint32_t reloc_flags =
1613 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001614
1615 switch (dset_slot->type) {
1616 case INTEL_DSET_SLOT_IMG_VIEW:
1617 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001618 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001619 dset_slot->u.img_view->cmd_len,
1620 dset_slot->u.img_view->cmd);
1621
1622 cmd_reserve_reloc(cmd, 1);
1623 cmd_surface_reloc(cmd, offset, 1,
1624 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001625 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001626 break;
1627 case INTEL_DSET_SLOT_MEM_VIEW:
1628 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001629 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001630 dset_slot->u.mem_view.cmd_len,
1631 dset_slot->u.mem_view.cmd);
1632
1633 cmd_reserve_reloc(cmd, 1);
1634 cmd_surface_reloc(cmd, offset, 1,
1635 dset_slot->u.mem_view.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001636 dset_slot->u.mem_view.cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001637 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001638 case INTEL_DSET_SLOT_SAMPLER:
1639 assert(0 == cmd->bind.dset.graphics_offset);
1640
1641 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001642 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001643 16, dset_slot->u.sampler->cmd);
1644 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001645 default:
1646 assert(!"unexpected dset slot type");
1647 break;
1648 }
1649 }
1650 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001651 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001652 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001653 break;
1654 }
1655
Chia-I Wu72292b72014-09-09 10:48:33 +08001656 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001657 }
1658
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001659 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001660 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001661 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001662}
1663
Chia-I Wu1d125092014-10-08 08:49:38 +08001664static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1665{
1666 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001667 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1668 uint32_t *dw;
1669 XGL_UINT pos, i;
1670
1671 CMD_ASSERT(cmd, 6, 7.5);
1672
1673 if (!pipeline->vb_count)
1674 return;
1675
1676 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1677
1678 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1679 dw++;
1680 pos++;
1681
1682 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001683 assert(pipeline->vb[i].strideInBytes <= 2048);
1684
1685 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1686 pipeline->vb[i].strideInBytes;
1687
1688 if (cmd_gen(cmd) >= INTEL_GEN(7))
1689 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1690
1691 switch (pipeline->vb[i].stepRate) {
1692 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1693 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1694 dw[3] = 0;
1695 break;
1696 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1697 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1698 dw[3] = 1;
1699 break;
1700 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1701 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1702 dw[3] = 0;
1703 break;
1704 default:
1705 assert(!"unknown step rate");
1706 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1707 dw[3] = 0;
1708 break;
1709 }
1710
Chia-I Wu3b04af52014-11-08 10:48:20 +08001711 if (cmd->bind.vertex.mem[i]) {
1712 const struct intel_mem *mem = cmd->bind.vertex.mem[i];
1713 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001714
1715 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3b04af52014-11-08 10:48:20 +08001716 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
1717 cmd_batch_reloc(cmd, pos + 2, mem->bo, mem->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001718 } else {
1719 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1720 dw[1] = 0;
1721 dw[2] = 0;
1722 }
1723
1724 dw += 4;
1725 pos += 4;
1726 }
1727}
1728
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001729static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1730{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001731 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1732 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu05990612014-11-25 11:36:35 +08001733 const int max_threads = cmd_vs_max_threads(cmd);
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001734 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001735 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001736 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu05990612014-11-25 11:36:35 +08001737 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001738
1739 CMD_ASSERT(cmd, 6, 7.5);
1740
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001741 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001742 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1743 *
1744 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1745 * 128-bit vertex elements to be passed into the payload for each
1746 * vertex."
1747 *
1748 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1749 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001750 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001751 vue_read_len = (vs->in_count + 1) / 2;
1752 if (!vue_read_len)
1753 vue_read_len = 1;
1754
1755 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1756 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1757
1758 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1759 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1760 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001761
1762 dw5 = GEN6_VS_DW5_STATISTICS |
1763 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001764
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001765 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1766 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1767 else
1768 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1769
Chia-I Wube0a3d92014-09-02 13:20:59 +08001770 if (pipeline->disable_vs_cache)
1771 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1772
Chia-I Wu72292b72014-09-09 10:48:33 +08001773 cmd_batch_pointer(cmd, cmd_len, &dw);
1774 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001775 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001776 dw[2] = dw2;
1777 dw[3] = 0; /* scratch */
1778 dw[4] = dw4;
1779 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001780}
1781
Chia-I Wu625105f2014-10-13 15:35:29 +08001782static void emit_shader_resources(struct intel_cmd *cmd)
1783{
1784 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001785 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001786
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001787 binding_tables[0] = emit_binding_table(cmd,
1788 cmd->bind.pipeline.graphics->vs.rmap);
1789 binding_tables[1] = emit_binding_table(cmd,
1790 cmd->bind.pipeline.graphics->tcs.rmap);
1791 binding_tables[2] = emit_binding_table(cmd,
1792 cmd->bind.pipeline.graphics->tes.rmap);
1793 binding_tables[3] = emit_binding_table(cmd,
1794 cmd->bind.pipeline.graphics->gs.rmap);
1795 binding_tables[4] = emit_binding_table(cmd,
1796 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001797
1798 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1799 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1800 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1801 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1802 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1803
1804 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1805 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001806 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1807 binding_tables[0]);
1808 gen7_3dstate_pointer(cmd,
1809 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1810 binding_tables[1]);
1811 gen7_3dstate_pointer(cmd,
1812 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1813 binding_tables[2]);
1814 gen7_3dstate_pointer(cmd,
1815 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1816 binding_tables[3]);
1817 gen7_3dstate_pointer(cmd,
1818 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1819 binding_tables[4]);
1820
1821 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001822 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1823 samplers[0]);
1824 gen7_3dstate_pointer(cmd,
1825 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1826 samplers[1]);
1827 gen7_3dstate_pointer(cmd,
1828 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1829 samplers[2]);
1830 gen7_3dstate_pointer(cmd,
1831 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1832 samplers[3]);
1833 gen7_3dstate_pointer(cmd,
1834 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1835 samplers[4]);
1836 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001837 assert(!binding_tables[1] && !binding_tables[2]);
1838 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1839 binding_tables[0], binding_tables[3], binding_tables[4]);
1840
Chia-I Wu625105f2014-10-13 15:35:29 +08001841 assert(!samplers[1] && !samplers[2]);
1842 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1843 samplers[0], samplers[3], samplers[4]);
1844 }
1845}
1846
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001847static void emit_rt(struct intel_cmd *cmd)
1848{
1849 cmd_wa_gen6_pre_depth_stall_write(cmd);
1850 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1851 cmd->bind.att.height);
1852}
1853
1854static void emit_ds(struct intel_cmd *cmd)
1855{
1856 const struct intel_ds_view *ds = cmd->bind.att.ds;
1857
1858 if (!ds) {
1859 /* all zeros */
1860 static const struct intel_ds_view null_ds;
1861 ds = &null_ds;
1862 }
1863
1864 cmd_wa_gen6_pre_ds_flush(cmd);
1865 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1866 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1867 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1868
1869 if (cmd_gen(cmd) >= INTEL_GEN(7))
1870 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1871 else
1872 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1873}
1874
Chia-I Wua57761b2014-10-14 14:27:44 +08001875static uint32_t emit_shader(struct intel_cmd *cmd,
1876 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001877{
Chia-I Wua57761b2014-10-14 14:27:44 +08001878 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1879 uint32_t offset;
1880 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001881
Chia-I Wua57761b2014-10-14 14:27:44 +08001882 /* see if the shader is already in the cache */
1883 for (i = 0; i < cache->used; i++) {
1884 if (cache->entries[i].shader == (const void *) shader)
1885 return cache->entries[i].kernel_offset;
1886 }
1887
1888 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1889
1890 /* grow the cache if full */
1891 if (cache->used >= cache->count) {
1892 const XGL_UINT count = cache->count + 16;
1893 void *entries;
1894
1895 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1896 XGL_SYSTEM_ALLOC_INTERNAL);
1897 if (entries) {
1898 if (cache->entries) {
1899 memcpy(entries, cache->entries,
1900 sizeof(cache->entries[0]) * cache->used);
1901 icd_free(cache->entries);
1902 }
1903
1904 cache->entries = entries;
1905 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001906 }
1907 }
1908
Chia-I Wua57761b2014-10-14 14:27:44 +08001909 /* add the shader to the cache */
1910 if (cache->used < cache->count) {
1911 cache->entries[cache->used].shader = (const void *) shader;
1912 cache->entries[cache->used].kernel_offset = offset;
1913 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001914 }
1915
Chia-I Wua57761b2014-10-14 14:27:44 +08001916 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001917}
1918
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001919static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001920{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001921 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001922
Chia-I Wu8370b402014-08-29 12:28:37 +08001923 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1924 cmd_wa_gen6_pre_depth_stall_write(cmd);
1925 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1926 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1927 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1928 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001929
1930 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001931 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001932 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001933
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001934 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001935 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001936 }
1937 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001938 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001939 }
1940 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001941 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1942 }
1943 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1944 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1945 }
1946 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1947 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001948 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001949
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001950 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1951 gen7_3DSTATE_GS(cmd);
1952 } else {
1953 gen6_3DSTATE_GS(cmd);
1954 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001955
Chia-I Wu8370b402014-08-29 12:28:37 +08001956 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1957 cmd_wa_gen7_post_command_cs_stall(cmd);
1958 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1959 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001960}
1961
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001962static void emit_bounded_states(struct intel_cmd *cmd)
1963{
1964 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1965
1966 emit_graphics_pipeline(cmd);
1967
1968 emit_rt(cmd);
1969 emit_ds(cmd);
1970
1971 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1972 gen7_cc_states(cmd);
1973 gen7_viewport_states(cmd);
1974
1975 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1976 &cmd->bind.pipeline.graphics->vs);
1977 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1978 &cmd->bind.pipeline.graphics->fs);
1979
1980 gen6_3DSTATE_CLIP(cmd);
1981 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001982 gen7_3DSTATE_WM(cmd);
1983 gen7_3DSTATE_PS(cmd);
1984 } else {
1985 gen6_cc_states(cmd);
1986 gen6_viewport_states(cmd);
1987
1988 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1989 &cmd->bind.pipeline.graphics->vs);
1990 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1991 &cmd->bind.pipeline.graphics->fs);
1992
1993 gen6_3DSTATE_CLIP(cmd);
1994 gen6_3DSTATE_SF(cmd);
1995 gen6_3DSTATE_WM(cmd);
1996 }
1997
1998 emit_shader_resources(cmd);
1999
2000 cmd_wa_gen6_pre_depth_stall_write(cmd);
2001 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2002
2003 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2004 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2005
2006 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2007 gen6_3DSTATE_VS(cmd);
2008}
2009
Chia-I Wu6032b892014-10-17 14:47:18 +08002010static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2011{
2012 const struct intel_cmd_meta *meta = cmd->bind.meta;
2013 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2014
2015 CMD_ASSERT(cmd, 6, 7.5);
2016
2017 blend_offset = 0;
2018 ds_offset = 0;
2019 cc_offset = 0;
2020 cc_vp_offset = 0;
2021
Chia-I Wu29e6f502014-11-24 14:27:29 +08002022 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002023 /* BLEND_STATE */
2024 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002025 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002026 dw[0] = 0;
2027 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2028 }
2029
Chia-I Wu29e6f502014-11-24 14:27:29 +08002030 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2031 if (meta->ds.state) {
2032 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002033
Chia-I Wu29e6f502014-11-24 14:27:29 +08002034 /* DEPTH_STENCIL_STATE */
2035 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002036
Chia-I Wu29e6f502014-11-24 14:27:29 +08002037 /* COLOR_CALC_STATE */
2038 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2039 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002040
Chia-I Wu29e6f502014-11-24 14:27:29 +08002041 /* CC_VIEWPORT */
2042 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002043 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002044 dw[0] = u_fui(0.0f);
2045 dw[1] = u_fui(1.0f);
2046 } else {
2047 /* DEPTH_STENCIL_STATE */
2048 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002049 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002050 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2051 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2052 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002053 }
2054
2055 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2056 gen7_3dstate_pointer(cmd,
2057 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2058 blend_offset);
2059 gen7_3dstate_pointer(cmd,
2060 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2061 ds_offset);
2062 gen7_3dstate_pointer(cmd,
2063 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2064
2065 gen7_3dstate_pointer(cmd,
2066 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2067 cc_vp_offset);
2068 } else {
2069 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002070 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002071
2072 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2073 cmd_batch_pointer(cmd, 4, &dw);
2074 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2075 GEN6_PTR_VP_DW0_CC_CHANGED;
2076 dw[1] = 0;
2077 dw[2] = 0;
2078 dw[3] = cc_vp_offset;
2079 }
2080}
2081
2082static void gen6_meta_surface_states(struct intel_cmd *cmd)
2083{
2084 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002085 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002086 uint32_t offset;
2087
2088 CMD_ASSERT(cmd, 6, 7.5);
2089
Chia-I Wu29e6f502014-11-24 14:27:29 +08002090 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2091 return;
2092
Chia-I Wu005c47c2014-10-22 13:49:13 +08002093 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002094 if (meta->src.valid) {
2095 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002096 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002097 meta->src.surface_len, meta->src.surface);
2098
2099 cmd_reserve_reloc(cmd, 1);
2100 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2101 cmd_surface_reloc_writer(cmd, offset, 1,
2102 meta->src.reloc_target, meta->src.reloc_offset);
2103 } else {
2104 cmd_surface_reloc(cmd, offset, 1,
2105 (struct intel_bo *) meta->src.reloc_target,
2106 meta->src.reloc_offset, meta->src.reloc_flags);
2107 }
2108
Chia-I Wu005c47c2014-10-22 13:49:13 +08002109 binding_table[0] = offset;
2110 }
2111 if (meta->dst.valid) {
2112 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002113 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002114 meta->dst.surface_len, meta->dst.surface);
2115
2116 cmd_reserve_reloc(cmd, 1);
2117 cmd_surface_reloc(cmd, offset, 1,
2118 (struct intel_bo *) meta->dst.reloc_target,
2119 meta->dst.reloc_offset, meta->dst.reloc_flags);
2120
2121 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002122 }
2123
2124 /* BINDING_TABLE */
2125 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002126 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002127 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002128
2129 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002130 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2131 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2132 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2133 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002134 } else {
2135 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002136 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2137 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2138 else
2139 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002140 }
2141}
2142
2143static void gen6_meta_urb(struct intel_cmd *cmd)
2144{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002145 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002146 uint32_t *dw;
2147
2148 CMD_ASSERT(cmd, 6, 6);
2149
2150 /* 3DSTATE_URB */
2151 cmd_batch_pointer(cmd, 3, &dw);
2152 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002153 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002154 dw[2] = 0;
2155}
2156
2157static void gen7_meta_urb(struct intel_cmd *cmd)
2158{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002159 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002160 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002161 uint32_t *dw;
2162
2163 CMD_ASSERT(cmd, 7, 7.5);
2164
2165 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2166 cmd_batch_pointer(cmd, 10, &dw);
2167
2168 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002169 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002170 dw += 2;
2171
2172 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2173 dw[1] = 0;
2174 dw += 2;
2175
2176 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2177 dw[1] = 0;
2178 dw += 2;
2179
2180 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2181 dw[1] = 0;
2182 dw += 2;
2183
2184 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002185 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002186
2187 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2188
Chia-I Wu24aa1022014-11-25 11:53:19 +08002189 switch (cmd_gen(cmd)) {
2190 case INTEL_GEN(7.5):
2191 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2192 break;
2193 case INTEL_GEN(7):
2194 default:
2195 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2196 break;
2197 }
2198
Chia-I Wu6032b892014-10-17 14:47:18 +08002199 /* 3DSTATE_URB_x */
2200 cmd_batch_pointer(cmd, 8, &dw);
2201
2202 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2203 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002204 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002205 dw += 2;
2206
2207 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2208 dw[1] = 0;
2209 dw += 2;
2210
2211 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2212 dw[1] = 0;
2213 dw += 2;
2214
2215 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2216 dw[1] = 0;
2217 dw += 2;
2218}
2219
2220static void gen6_meta_vf(struct intel_cmd *cmd)
2221{
2222 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002223 uint32_t vb_start, vb_end, vb_stride;
2224 int ve_format, ve_z_source;
2225 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002226 XGL_UINT pos;
2227
2228 CMD_ASSERT(cmd, 6, 7.5);
2229
Chia-I Wu29e6f502014-11-24 14:27:29 +08002230 switch (meta->mode) {
2231 case INTEL_CMD_META_VS_POINTS:
2232 cmd_batch_pointer(cmd, 3, &dw);
2233 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2234 dw[1] = GEN6_VE_STATE_DW0_VALID;
2235 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2236 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2237 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2238 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2239 return;
2240 break;
2241 case INTEL_CMD_META_FS_RECT:
2242 {
2243 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002244
Chia-I Wu29e6f502014-11-24 14:27:29 +08002245 vertices[0][0] = meta->dst.x + meta->width;
2246 vertices[0][1] = meta->dst.y + meta->height;
2247 vertices[1][0] = meta->dst.x;
2248 vertices[1][1] = meta->dst.y + meta->height;
2249 vertices[2][0] = meta->dst.x;
2250 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002251
Chia-I Wu29e6f502014-11-24 14:27:29 +08002252 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2253 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002254
Chia-I Wu29e6f502014-11-24 14:27:29 +08002255 vb_end = vb_start + sizeof(vertices) - 1;
2256 vb_stride = sizeof(vertices[0]);
2257 ve_z_source = GEN6_VFCOMP_STORE_0;
2258 ve_format = GEN6_FORMAT_R32G32_USCALED;
2259 }
2260 break;
2261 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2262 {
2263 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002264
Chia-I Wu29e6f502014-11-24 14:27:29 +08002265 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2266 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2267 vertices[0][2] = u_uif(meta->clear_val[0]);
2268 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2269 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2270 vertices[1][2] = u_uif(meta->clear_val[0]);
2271 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2272 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2273 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002274
Chia-I Wu29e6f502014-11-24 14:27:29 +08002275 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2276 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002277
Chia-I Wu29e6f502014-11-24 14:27:29 +08002278 vb_end = vb_start + sizeof(vertices) - 1;
2279 vb_stride = sizeof(vertices[0]);
2280 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2281 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2282 }
2283 break;
2284 default:
2285 assert(!"unknown meta mode");
2286 return;
2287 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002288 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002289
2290 /* 3DSTATE_VERTEX_BUFFERS */
2291 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002292
Chia-I Wu6032b892014-10-17 14:47:18 +08002293 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002294 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002295 if (cmd_gen(cmd) >= INTEL_GEN(7))
2296 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2297
2298 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002299 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2300 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002301
2302 dw[4] = 0;
2303
2304 /* 3DSTATE_VERTEX_ELEMENTS */
2305 cmd_batch_pointer(cmd, 5, &dw);
2306 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002307 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002308 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2309 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2310 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2311 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2312 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002313 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002314 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2315 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002316 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002317 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2318}
2319
Chia-I Wu29e6f502014-11-24 14:27:29 +08002320static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002321{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002322 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002323 /* one GPR */
2324 XGL_UINT consts[8];
2325 XGL_UINT const_count;
2326
2327 CMD_ASSERT(cmd, 6, 7.5);
2328
2329 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002330 case INTEL_DEV_META_VS_FILL_MEM:
2331 consts[0] = meta->dst.x;
2332 consts[1] = meta->clear_val[0];
2333 const_count = 2;
2334 break;
2335 case INTEL_DEV_META_VS_COPY_MEM:
2336 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2337 consts[0] = meta->dst.x;
2338 consts[1] = meta->src.x;
2339 const_count = 2;
2340 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002341 default:
2342 assert(!"unknown meta shader id");
2343 const_count = 0;
2344 break;
2345 }
2346
2347 /* this can be skipped but it makes state dumping prettier */
2348 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2349
2350 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2351}
2352
2353static void gen6_meta_vs(struct intel_cmd *cmd)
2354{
2355 const struct intel_cmd_meta *meta = cmd->bind.meta;
2356 const struct intel_pipeline_shader *sh =
2357 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002358 const int max_threads = cmd_vs_max_threads(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002359 uint32_t offset, *dw;
2360
2361 CMD_ASSERT(cmd, 6, 7.5);
2362
2363 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2364 XGL_UINT cmd_len;
2365
2366 /* 3DSTATE_CONSTANT_VS */
2367 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2368 cmd_batch_pointer(cmd, cmd_len, &dw);
2369 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2370 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2371
2372 /* 3DSTATE_VS */
2373 cmd_batch_pointer(cmd, 6, &dw);
2374 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2375 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2376
2377 return;
2378 }
2379
2380 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2381
2382 /* 3DSTATE_CONSTANT_VS */
2383 offset = gen6_meta_vs_constants(cmd);
2384 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2385 cmd_batch_pointer(cmd, 7, &dw);
2386 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2387 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2388 dw[2] = 0;
2389 dw[3] = offset;
2390 dw[4] = 0;
2391 dw[5] = 0;
2392 dw[6] = 0;
2393 } else {
2394 cmd_batch_pointer(cmd, 5, &dw);
2395 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2396 GEN6_PCB_ANY_DW0_PCB0_VALID;
2397 dw[1] = offset;
2398 dw[2] = 0;
2399 dw[3] = 0;
2400 dw[4] = 0;
2401 }
2402
2403 /* 3DSTATE_VS */
2404 offset = emit_shader(cmd, sh);
2405 cmd_batch_pointer(cmd, 6, &dw);
2406 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2407 dw[1] = offset;
2408 dw[2] = GEN6_THREADDISP_SPF |
2409 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2410 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2411 dw[3] = 0;
2412 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2413 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2414
2415 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2416 GEN6_VS_DW5_VS_ENABLE;
2417 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu05990612014-11-25 11:36:35 +08002418 dw[5] |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002419 else
Chia-I Wu05990612014-11-25 11:36:35 +08002420 dw[5] |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002421}
2422
2423static void gen6_meta_disabled(struct intel_cmd *cmd)
2424{
Chia-I Wu6032b892014-10-17 14:47:18 +08002425 uint32_t *dw;
2426
2427 CMD_ASSERT(cmd, 6, 6);
2428
Chia-I Wu6032b892014-10-17 14:47:18 +08002429 /* 3DSTATE_CONSTANT_GS */
2430 cmd_batch_pointer(cmd, 5, &dw);
2431 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2432 dw[1] = 0;
2433 dw[2] = 0;
2434 dw[3] = 0;
2435 dw[4] = 0;
2436
2437 /* 3DSTATE_GS */
2438 cmd_batch_pointer(cmd, 7, &dw);
2439 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2440 dw[1] = 0;
2441 dw[2] = 0;
2442 dw[3] = 0;
2443 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2444 dw[5] = GEN6_GS_DW5_STATISTICS;
2445 dw[6] = 0;
2446
Chia-I Wu6032b892014-10-17 14:47:18 +08002447 /* 3DSTATE_SF */
2448 cmd_batch_pointer(cmd, 20, &dw);
2449 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2450 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2451 memset(&dw[2], 0, 18 * sizeof(*dw));
2452}
2453
2454static void gen7_meta_disabled(struct intel_cmd *cmd)
2455{
2456 uint32_t *dw;
2457
2458 CMD_ASSERT(cmd, 7, 7.5);
2459
Chia-I Wu6032b892014-10-17 14:47:18 +08002460 /* 3DSTATE_CONSTANT_HS */
2461 cmd_batch_pointer(cmd, 7, &dw);
2462 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2463 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2464
2465 /* 3DSTATE_HS */
2466 cmd_batch_pointer(cmd, 7, &dw);
2467 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2468 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2469
2470 /* 3DSTATE_TE */
2471 cmd_batch_pointer(cmd, 4, &dw);
2472 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2473 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2474
2475 /* 3DSTATE_CONSTANT_DS */
2476 cmd_batch_pointer(cmd, 7, &dw);
2477 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2478 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2479
2480 /* 3DSTATE_DS */
2481 cmd_batch_pointer(cmd, 6, &dw);
2482 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2483 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2484
2485 /* 3DSTATE_CONSTANT_GS */
2486 cmd_batch_pointer(cmd, 7, &dw);
2487 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2488 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2489
2490 /* 3DSTATE_GS */
2491 cmd_batch_pointer(cmd, 7, &dw);
2492 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2493 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2494
2495 /* 3DSTATE_STREAMOUT */
2496 cmd_batch_pointer(cmd, 3, &dw);
2497 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2498 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2499
Chia-I Wu6032b892014-10-17 14:47:18 +08002500 /* 3DSTATE_SF */
2501 cmd_batch_pointer(cmd, 7, &dw);
2502 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2503 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2504
2505 /* 3DSTATE_SBE */
2506 cmd_batch_pointer(cmd, 14, &dw);
2507 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2508 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2509 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002510}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002511
Chia-I Wu29e6f502014-11-24 14:27:29 +08002512static void gen6_meta_clip(struct intel_cmd *cmd)
2513{
2514 const struct intel_cmd_meta *meta = cmd->bind.meta;
2515 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002516
Chia-I Wu29e6f502014-11-24 14:27:29 +08002517 /* 3DSTATE_CLIP */
2518 cmd_batch_pointer(cmd, 4, &dw);
2519 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2520 dw[1] = 0;
2521 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2522 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2523 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2524 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002525 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002526 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002527 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002528}
2529
2530static void gen6_meta_wm(struct intel_cmd *cmd)
2531{
2532 const struct intel_cmd_meta *meta = cmd->bind.meta;
2533 uint32_t *dw;
2534
2535 CMD_ASSERT(cmd, 6, 7.5);
2536
2537 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2538
2539 /* 3DSTATE_MULTISAMPLE */
2540 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2541 cmd_batch_pointer(cmd, 4, &dw);
2542 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2543 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2544 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2545 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2546 dw[2] = 0;
2547 dw[3] = 0;
2548 } else {
2549 cmd_batch_pointer(cmd, 3, &dw);
2550 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2551 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2552 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2553 dw[2] = 0;
2554 }
2555
2556 /* 3DSTATE_SAMPLE_MASK */
2557 cmd_batch_pointer(cmd, 2, &dw);
2558 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2559 dw[1] = (1 << meta->samples) - 1;
2560
2561 /* 3DSTATE_DRAWING_RECTANGLE */
2562 cmd_batch_pointer(cmd, 4, &dw);
2563 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2564 dw[1] = meta->dst.y << 16 | meta->dst.x;
2565 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2566 (meta->dst.x + meta->width - 1);
2567 dw[3] = 0;
2568}
2569
2570static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2571{
2572 const struct intel_cmd_meta *meta = cmd->bind.meta;
2573 XGL_UINT offset_x, offset_y;
2574 /* one GPR */
2575 XGL_UINT consts[8];
2576 XGL_UINT const_count;
2577
2578 CMD_ASSERT(cmd, 6, 7.5);
2579
2580 /* underflow is fine here */
2581 offset_x = meta->src.x - meta->dst.x;
2582 offset_y = meta->src.y - meta->dst.y;
2583
2584 switch (meta->shader_id) {
2585 case INTEL_DEV_META_FS_COPY_MEM:
2586 case INTEL_DEV_META_FS_COPY_1D:
2587 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2588 case INTEL_DEV_META_FS_COPY_2D:
2589 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2590 case INTEL_DEV_META_FS_COPY_2D_MS:
2591 consts[0] = offset_x;
2592 consts[1] = offset_y;
2593 consts[2] = meta->src.layer;
2594 consts[3] = meta->src.lod;
2595 const_count = 4;
2596 break;
2597 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2598 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2599 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2600 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2601 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2602 consts[0] = offset_x;
2603 consts[1] = offset_y;
2604 consts[2] = meta->src.layer;
2605 consts[3] = meta->src.lod;
2606 consts[4] = meta->src.x;
2607 consts[5] = meta->width;
2608 const_count = 6;
2609 break;
2610 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2611 consts[0] = offset_x;
2612 consts[1] = offset_y;
2613 consts[2] = meta->width;
2614 const_count = 3;
2615 break;
2616 case INTEL_DEV_META_FS_CLEAR_COLOR:
2617 consts[0] = meta->clear_val[0];
2618 consts[1] = meta->clear_val[1];
2619 consts[2] = meta->clear_val[2];
2620 consts[3] = meta->clear_val[3];
2621 const_count = 4;
2622 break;
2623 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2624 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002625 consts[1] = meta->clear_val[1];
2626 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002627 break;
2628 case INTEL_DEV_META_FS_RESOLVE_2X:
2629 case INTEL_DEV_META_FS_RESOLVE_4X:
2630 case INTEL_DEV_META_FS_RESOLVE_8X:
2631 case INTEL_DEV_META_FS_RESOLVE_16X:
2632 consts[0] = offset_x;
2633 consts[1] = offset_y;
2634 const_count = 2;
2635 break;
2636 default:
2637 assert(!"unknown meta shader id");
2638 const_count = 0;
2639 break;
2640 }
2641
2642 /* this can be skipped but it makes state dumping prettier */
2643 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2644
2645 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2646}
2647
2648static void gen6_meta_ps(struct intel_cmd *cmd)
2649{
2650 const struct intel_cmd_meta *meta = cmd->bind.meta;
2651 const struct intel_pipeline_shader *sh =
2652 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002653 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002654 uint32_t offset, *dw;
2655
2656 CMD_ASSERT(cmd, 6, 6);
2657
Chia-I Wu29e6f502014-11-24 14:27:29 +08002658 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2659 /* 3DSTATE_CONSTANT_PS */
2660 cmd_batch_pointer(cmd, 5, &dw);
2661 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2662 dw[1] = 0;
2663 dw[2] = 0;
2664 dw[3] = 0;
2665 dw[4] = 0;
2666
2667 /* 3DSTATE_WM */
2668 cmd_batch_pointer(cmd, 9, &dw);
2669 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2670 dw[1] = 0;
2671 dw[2] = 0;
2672 dw[3] = 0;
2673 dw[4] = 0;
Chia-I Wu05990612014-11-25 11:36:35 +08002674 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002675 dw[6] = 0;
2676 dw[7] = 0;
2677 dw[8] = 0;
2678
Chia-I Wu3adf7212014-10-24 15:34:07 +08002679 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002680 }
2681
Chia-I Wu3adf7212014-10-24 15:34:07 +08002682 /* a normal color write */
2683 assert(meta->dst.valid && !sh->uses);
2684
Chia-I Wu6032b892014-10-17 14:47:18 +08002685 /* 3DSTATE_CONSTANT_PS */
2686 offset = gen6_meta_ps_constants(cmd);
2687 cmd_batch_pointer(cmd, 5, &dw);
2688 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2689 GEN6_PCB_ANY_DW0_PCB0_VALID;
2690 dw[1] = offset;
2691 dw[2] = 0;
2692 dw[3] = 0;
2693 dw[4] = 0;
2694
2695 /* 3DSTATE_WM */
2696 offset = emit_shader(cmd, sh);
2697 cmd_batch_pointer(cmd, 9, &dw);
2698 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2699 dw[1] = offset;
2700 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2701 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2702 dw[3] = 0;
2703 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002704 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002705 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002706 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2707
Chia-I Wu6032b892014-10-17 14:47:18 +08002708 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2709 GEN6_WM_DW6_POSOFFSET_NONE |
2710 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2711 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2712 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2713 if (meta->samples > 1) {
2714 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2715 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2716 } else {
2717 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2718 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2719 }
2720 dw[7] = 0;
2721 dw[8] = 0;
2722}
2723
2724static void gen7_meta_ps(struct intel_cmd *cmd)
2725{
2726 const struct intel_cmd_meta *meta = cmd->bind.meta;
2727 const struct intel_pipeline_shader *sh =
2728 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002729 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002730 uint32_t offset, *dw;
2731
2732 CMD_ASSERT(cmd, 7, 7.5);
2733
Chia-I Wu29e6f502014-11-24 14:27:29 +08002734 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2735 /* 3DSTATE_WM */
2736 cmd_batch_pointer(cmd, 3, &dw);
2737 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2738 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2739
2740 /* 3DSTATE_CONSTANT_GS */
2741 cmd_batch_pointer(cmd, 7, &dw);
2742 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2743 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2744
2745 /* 3DSTATE_PS */
2746 cmd_batch_pointer(cmd, 8, &dw);
2747 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2748 dw[1] = 0;
2749 dw[2] = 0;
2750 dw[3] = 0;
2751 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu05990612014-11-25 11:36:35 +08002752 (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002753 dw[5] = 0;
2754 dw[6] = 0;
2755 dw[7] = 0;
2756
Chia-I Wu3adf7212014-10-24 15:34:07 +08002757 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002758 }
2759
Chia-I Wu3adf7212014-10-24 15:34:07 +08002760 /* a normal color write */
2761 assert(meta->dst.valid && !sh->uses);
2762
Chia-I Wu6032b892014-10-17 14:47:18 +08002763 /* 3DSTATE_WM */
2764 cmd_batch_pointer(cmd, 3, &dw);
2765 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2766 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2767 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2768 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2769 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2770 dw[2] = 0;
2771
2772 /* 3DSTATE_CONSTANT_PS */
2773 offset = gen6_meta_ps_constants(cmd);
2774 cmd_batch_pointer(cmd, 7, &dw);
2775 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2776 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2777 dw[2] = 0;
2778 dw[3] = offset;
2779 dw[4] = 0;
2780 dw[5] = 0;
2781 dw[6] = 0;
2782
2783 /* 3DSTATE_PS */
2784 offset = emit_shader(cmd, sh);
2785 cmd_batch_pointer(cmd, 8, &dw);
2786 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2787 dw[1] = offset;
2788 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2789 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2790 dw[3] = 0;
2791
2792 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2793 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002794 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2795
2796 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2797 dw[4] |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002798 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002799 } else {
2800 dw[4] |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2801 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002802
2803 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2804 dw[6] = 0;
2805 dw[7] = 0;
2806}
2807
2808static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2809{
2810 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002811 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002812
2813 CMD_ASSERT(cmd, 6, 7.5);
2814
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002815 if (!ds) {
2816 /* all zeros */
2817 static const struct intel_ds_view null_ds;
2818 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002819 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002820
2821 cmd_wa_gen6_pre_ds_flush(cmd);
2822 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2823 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2824 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2825
2826 if (cmd_gen(cmd) >= INTEL_GEN(7))
2827 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2828 else
2829 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002830}
2831
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002832static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2833 const struct intel_pipeline *pipeline)
2834{
2835 cmd->bind.pipeline.graphics = pipeline;
2836}
2837
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002838static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2839 const struct intel_pipeline *pipeline)
2840{
2841 cmd->bind.pipeline.compute = pipeline;
2842}
2843
2844static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2845 const struct intel_pipeline_delta *delta)
2846{
2847 cmd->bind.pipeline.graphics_delta = delta;
2848}
2849
2850static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2851 const struct intel_pipeline_delta *delta)
2852{
2853 cmd->bind.pipeline.compute_delta = delta;
2854}
2855
2856static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2857 const struct intel_dset *dset,
2858 XGL_UINT slot_offset)
2859{
2860 cmd->bind.dset.graphics = dset;
2861 cmd->bind.dset.graphics_offset = slot_offset;
2862}
2863
2864static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2865 const struct intel_dset *dset,
2866 XGL_UINT slot_offset)
2867{
2868 cmd->bind.dset.compute = dset;
2869 cmd->bind.dset.compute_offset = slot_offset;
2870}
2871
2872static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2873 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2874{
2875 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2876}
2877
2878static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2879 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2880{
2881 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2882}
2883
Chia-I Wu3b04af52014-11-08 10:48:20 +08002884static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2885 const struct intel_mem *mem,
2886 XGL_GPU_SIZE offset, XGL_UINT binding)
2887{
2888 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2889 cmd->result = XGL_ERROR_UNKNOWN;
2890 return;
2891 }
2892
2893 cmd->bind.vertex.mem[binding] = mem;
2894 cmd->bind.vertex.offset[binding] = offset;
2895}
2896
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002897static void cmd_bind_index_data(struct intel_cmd *cmd,
2898 const struct intel_mem *mem,
2899 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2900{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002901 cmd->bind.index.mem = mem;
2902 cmd->bind.index.offset = offset;
2903 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002904}
2905
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002906static void cmd_bind_attachments(struct intel_cmd *cmd,
2907 XGL_UINT rt_count,
2908 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2909 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002910{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002911 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002912 XGL_UINT i;
2913
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002914 for (i = 0; i < rt_count; i++) {
2915 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002916 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002917 const struct intel_layout *layout = &rt->img->layout;
2918
2919 if (i == 0) {
2920 width = layout->width0;
2921 height = layout->height0;
2922 } else {
2923 if (width > layout->width0)
2924 width = layout->width0;
2925 if (height > layout->height0)
2926 height = layout->height0;
2927 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002928
2929 cmd->bind.att.rt[i] = rt;
2930 }
2931
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002932 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002933
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002934 if (ds_info) {
2935 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002936
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002937 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2938 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002939
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002940 if (width > layout->width0)
2941 width = layout->width0;
2942 if (height > layout->height0)
2943 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002944 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002945 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002946 }
2947
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002948 cmd->bind.att.width = width;
2949 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002950}
2951
2952static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2953 const struct intel_viewport_state *state)
2954{
2955 cmd->bind.state.viewport = state;
2956}
2957
2958static void cmd_bind_raster_state(struct intel_cmd *cmd,
2959 const struct intel_raster_state *state)
2960{
2961 cmd->bind.state.raster = state;
2962}
2963
2964static void cmd_bind_ds_state(struct intel_cmd *cmd,
2965 const struct intel_ds_state *state)
2966{
2967 cmd->bind.state.ds = state;
2968}
2969
2970static void cmd_bind_blend_state(struct intel_cmd *cmd,
2971 const struct intel_blend_state *state)
2972{
2973 cmd->bind.state.blend = state;
2974}
2975
2976static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2977 const struct intel_msaa_state *state)
2978{
2979 cmd->bind.state.msaa = state;
2980}
2981
2982static void cmd_draw(struct intel_cmd *cmd,
2983 XGL_UINT vertex_start,
2984 XGL_UINT vertex_count,
2985 XGL_UINT instance_start,
2986 XGL_UINT instance_count,
2987 bool indexed,
2988 XGL_UINT vertex_base)
2989{
2990 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2991
2992 emit_bounded_states(cmd);
2993
2994 if (indexed) {
2995 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2996 cmd->result = XGL_ERROR_UNKNOWN;
2997
2998 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2999 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3000 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003001 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3002 cmd->bind.index.offset, cmd->bind.index.type,
3003 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003004 } else {
3005 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3006 cmd->bind.index.offset, cmd->bind.index.type,
3007 p->primitive_restart);
3008 }
3009 } else {
3010 assert(!vertex_base);
3011 }
3012
3013 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3014 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3015 vertex_start, instance_count, instance_start, vertex_base);
3016 } else {
3017 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3018 vertex_start, instance_count, instance_start, vertex_base);
3019 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003020
Chia-I Wu707a29e2014-08-27 12:51:47 +08003021 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003022 /* need to re-emit all workarounds */
3023 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003024
3025 if (intel_debug & INTEL_DEBUG_NOCACHE)
3026 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003027}
3028
Chia-I Wuc14d1562014-10-17 09:49:22 +08003029void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3030{
Chia-I Wu6032b892014-10-17 14:47:18 +08003031 cmd->bind.meta = meta;
3032
3033 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003034 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003035
3036 gen6_meta_dynamic_states(cmd);
3037 gen6_meta_surface_states(cmd);
3038
3039 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3040 gen7_meta_urb(cmd);
3041 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003042 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003043 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003044 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003045 gen6_meta_wm(cmd);
3046 gen7_meta_ps(cmd);
3047 gen6_meta_depth_buffer(cmd);
3048
3049 cmd_wa_gen7_post_command_cs_stall(cmd);
3050 cmd_wa_gen7_post_command_depth_stall(cmd);
3051
Chia-I Wu29e6f502014-11-24 14:27:29 +08003052 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3053 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3054 meta->width, 0, 1, 0, 0);
3055 } else {
3056 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3057 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003058 } else {
3059 gen6_meta_urb(cmd);
3060 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003061 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003062 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003063 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003064 gen6_meta_wm(cmd);
3065 gen6_meta_ps(cmd);
3066 gen6_meta_depth_buffer(cmd);
3067
Chia-I Wu29e6f502014-11-24 14:27:29 +08003068 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3069 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3070 meta->width, 0, 1, 0, 0);
3071 } else {
3072 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3073 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003074 }
3075
3076 cmd->bind.draw_count++;
3077 /* need to re-emit all workarounds */
3078 cmd->bind.wa_flags = 0;
3079
3080 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003081
3082 if (intel_debug & INTEL_DEBUG_NOCACHE)
3083 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003084}
3085
Chia-I Wub2755562014-08-20 13:38:52 +08003086XGL_VOID XGLAPI intelCmdBindPipeline(
3087 XGL_CMD_BUFFER cmdBuffer,
3088 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3089 XGL_PIPELINE pipeline)
3090{
3091 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3092
3093 switch (pipelineBindPoint) {
3094 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003095 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003096 break;
3097 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003098 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003099 break;
3100 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003101 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003102 break;
3103 }
3104}
3105
3106XGL_VOID XGLAPI intelCmdBindPipelineDelta(
3107 XGL_CMD_BUFFER cmdBuffer,
3108 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3109 XGL_PIPELINE_DELTA delta)
3110{
3111 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3112
3113 switch (pipelineBindPoint) {
3114 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003115 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003116 break;
3117 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003118 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003119 break;
3120 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003121 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003122 break;
3123 }
3124}
3125
3126XGL_VOID XGLAPI intelCmdBindStateObject(
3127 XGL_CMD_BUFFER cmdBuffer,
3128 XGL_STATE_BIND_POINT stateBindPoint,
3129 XGL_STATE_OBJECT state)
3130{
3131 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3132
3133 switch (stateBindPoint) {
3134 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003135 cmd_bind_viewport_state(cmd,
3136 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003137 break;
3138 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003139 cmd_bind_raster_state(cmd,
3140 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003141 break;
3142 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003143 cmd_bind_ds_state(cmd,
3144 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003145 break;
3146 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003147 cmd_bind_blend_state(cmd,
3148 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003149 break;
3150 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003151 cmd_bind_msaa_state(cmd,
3152 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003153 break;
3154 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003155 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003156 break;
3157 }
3158}
3159
3160XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3161 XGL_CMD_BUFFER cmdBuffer,
3162 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3163 XGL_UINT index,
3164 XGL_DESCRIPTOR_SET descriptorSet,
3165 XGL_UINT slotOffset)
3166{
3167 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3168 struct intel_dset *dset = intel_dset(descriptorSet);
3169
3170 assert(!index);
3171
3172 switch (pipelineBindPoint) {
3173 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003174 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003175 break;
3176 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003177 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003178 break;
3179 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003180 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003181 break;
3182 }
3183}
3184
3185XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3186 XGL_CMD_BUFFER cmdBuffer,
3187 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3188 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3189{
3190 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3191
3192 switch (pipelineBindPoint) {
3193 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003194 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003195 break;
3196 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003197 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003198 break;
3199 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003200 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003201 break;
3202 }
3203}
3204
Chia-I Wu3b04af52014-11-08 10:48:20 +08003205XGL_VOID XGLAPI intelCmdBindVertexData(
3206 XGL_CMD_BUFFER cmdBuffer,
3207 XGL_GPU_MEMORY mem_,
3208 XGL_GPU_SIZE offset,
3209 XGL_UINT binding)
3210{
3211 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3212 struct intel_mem *mem = intel_mem(mem_);
3213
3214 cmd_bind_vertex_data(cmd, mem, offset, binding);
3215}
3216
Chia-I Wub2755562014-08-20 13:38:52 +08003217XGL_VOID XGLAPI intelCmdBindIndexData(
3218 XGL_CMD_BUFFER cmdBuffer,
3219 XGL_GPU_MEMORY mem_,
3220 XGL_GPU_SIZE offset,
3221 XGL_INDEX_TYPE indexType)
3222{
3223 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3224 struct intel_mem *mem = intel_mem(mem_);
3225
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003226 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003227}
3228
3229XGL_VOID XGLAPI intelCmdBindAttachments(
3230 XGL_CMD_BUFFER cmdBuffer,
3231 XGL_UINT colorAttachmentCount,
3232 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3233 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3234{
3235 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003236
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003237 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3238 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003239}
3240
3241XGL_VOID XGLAPI intelCmdDraw(
3242 XGL_CMD_BUFFER cmdBuffer,
3243 XGL_UINT firstVertex,
3244 XGL_UINT vertexCount,
3245 XGL_UINT firstInstance,
3246 XGL_UINT instanceCount)
3247{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003248 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003249
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003250 cmd_draw(cmd, firstVertex, vertexCount,
3251 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003252}
3253
3254XGL_VOID XGLAPI intelCmdDrawIndexed(
3255 XGL_CMD_BUFFER cmdBuffer,
3256 XGL_UINT firstIndex,
3257 XGL_UINT indexCount,
3258 XGL_INT vertexOffset,
3259 XGL_UINT firstInstance,
3260 XGL_UINT instanceCount)
3261{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003262 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003263
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003264 cmd_draw(cmd, firstIndex, indexCount,
3265 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003266}
3267
3268XGL_VOID XGLAPI intelCmdDrawIndirect(
3269 XGL_CMD_BUFFER cmdBuffer,
3270 XGL_GPU_MEMORY mem,
3271 XGL_GPU_SIZE offset,
3272 XGL_UINT32 count,
3273 XGL_UINT32 stride)
3274{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003275 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3276
3277 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003278}
3279
3280XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3281 XGL_CMD_BUFFER cmdBuffer,
3282 XGL_GPU_MEMORY mem,
3283 XGL_GPU_SIZE offset,
3284 XGL_UINT32 count,
3285 XGL_UINT32 stride)
3286{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003287 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3288
3289 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003290}
3291
3292XGL_VOID XGLAPI intelCmdDispatch(
3293 XGL_CMD_BUFFER cmdBuffer,
3294 XGL_UINT x,
3295 XGL_UINT y,
3296 XGL_UINT z)
3297{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003298 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3299
3300 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003301}
3302
3303XGL_VOID XGLAPI intelCmdDispatchIndirect(
3304 XGL_CMD_BUFFER cmdBuffer,
3305 XGL_GPU_MEMORY mem,
3306 XGL_GPU_SIZE offset)
3307{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003308 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3309
3310 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003311}