blob: ec85aa3a4bc5679dcfeb7e7086c7a750b0d3464d [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 Wu784d3042014-12-19 14:30:04 +0800546static void gen6_add_scratch_space(struct intel_cmd *cmd,
547 XGL_UINT batch_pos,
548 const struct intel_pipeline *pipeline,
549 const struct intel_pipeline_shader *sh)
550{
551 int scratch_space;
552
553 CMD_ASSERT(cmd, 6, 7.5);
554
555 assert(sh->per_thread_scratch_size &&
556 sh->per_thread_scratch_size % 1024 == 0 &&
557 u_is_pow2(sh->per_thread_scratch_size) &&
558 sh->scratch_offset % 1024 == 0);
559 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
560
561 cmd_reserve_reloc(cmd, 1);
562 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
563 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
564}
565
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800566static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
567{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800568 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800569 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800570 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
571 const uint8_t cmd_len = 9;
Chia-I Wu784d3042014-12-19 14:30:04 +0800572 XGL_UINT pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800573 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800574
575 CMD_ASSERT(cmd, 6, 6);
576
577 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
578
579 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
580 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
581
582 dw4 = GEN6_WM_DW4_STATISTICS |
583 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
584 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
585 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
586
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800587 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800588 GEN6_WM_DW5_PS_ENABLE |
589 GEN6_WM_DW5_8_PIXEL_DISPATCH;
590
591 if (fs->uses & INTEL_SHADER_USE_KILL ||
592 pipeline->cb_state.alphaToCoverageEnable)
593 dw5 |= GEN6_WM_DW5_PS_KILL;
594
595 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
596 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
597 if (fs->uses & INTEL_SHADER_USE_DEPTH)
598 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
599 if (fs->uses & INTEL_SHADER_USE_W)
600 dw5 |= GEN6_WM_DW5_PS_USE_W;
601
602 if (pipeline->cb_state.dualSourceBlendEnable)
603 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
604
605 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
606 GEN6_WM_DW6_POSOFFSET_NONE |
607 GEN6_WM_DW6_ZW_INTERP_PIXEL |
608 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
609 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
610
611 if (msaa->sample_count > 1) {
612 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
613 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
614 } else {
615 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
616 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
617 }
618
Chia-I Wu784d3042014-12-19 14:30:04 +0800619 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800620 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800621 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800622 dw[2] = dw2;
623 dw[3] = 0; /* scratch */
624 dw[4] = dw4;
625 dw[5] = dw5;
626 dw[6] = dw6;
627 dw[7] = 0; /* kernel 1 */
628 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800629
630 if (fs->per_thread_scratch_size)
631 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800632}
633
634static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
635{
636 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800637 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
639 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800640 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800641
642 CMD_ASSERT(cmd, 7, 7.5);
643
644 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
645
646 dw1 = GEN7_WM_DW1_STATISTICS |
647 GEN7_WM_DW1_PS_ENABLE |
648 GEN7_WM_DW1_ZW_INTERP_PIXEL |
649 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
650 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
651
652 if (fs->uses & INTEL_SHADER_USE_KILL ||
653 pipeline->cb_state.alphaToCoverageEnable)
654 dw1 |= GEN7_WM_DW1_PS_KILL;
655
656 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
657 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
658 if (fs->uses & INTEL_SHADER_USE_DEPTH)
659 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
660 if (fs->uses & INTEL_SHADER_USE_W)
661 dw1 |= GEN7_WM_DW1_PS_USE_W;
662
663 dw2 = 0;
664
665 if (msaa->sample_count > 1) {
666 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
667 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
668 } else {
669 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
670 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
671 }
672
Chia-I Wu72292b72014-09-09 10:48:33 +0800673 cmd_batch_pointer(cmd, cmd_len, &dw);
674 dw[0] = dw0;
675 dw[1] = dw1;
676 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800677}
678
679static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
680{
681 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800682 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800683 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
684 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800685 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +0800686 XGL_UINT pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800687
688 CMD_ASSERT(cmd, 7, 7.5);
689
690 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
691
692 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
693 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
694
695 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
696 GEN7_PS_DW4_8_PIXEL_DISPATCH;
697
698 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800699 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800700 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
701 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800702 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800703 }
704
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800705 if (fs->in_count)
706 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
707
708 if (pipeline->cb_state.dualSourceBlendEnable)
709 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
710
711 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
712 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
713 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
714
Chia-I Wu784d3042014-12-19 14:30:04 +0800715 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800716 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800717 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800718 dw[2] = dw2;
719 dw[3] = 0; /* scratch */
720 dw[4] = dw4;
721 dw[5] = dw5;
722 dw[6] = 0; /* kernel 1 */
723 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800724
725 if (fs->per_thread_scratch_size)
726 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800727}
728
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800729static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
730 const struct intel_ds_view *view)
731{
732 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800733 uint32_t dw0, *dw;
734 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800735
736 CMD_ASSERT(cmd, 6, 7.5);
737
738 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800739 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
740 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800741 dw0 |= (cmd_len - 2);
742
Chia-I Wu72292b72014-09-09 10:48:33 +0800743 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
744 dw[0] = dw0;
745 dw[1] = view->cmd[0];
746 dw[2] = 0;
747 dw[3] = view->cmd[2];
748 dw[4] = view->cmd[3];
749 dw[5] = view->cmd[4];
750 dw[6] = view->cmd[5];
751
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600752 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800753 cmd_reserve_reloc(cmd, 1);
754 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
755 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600756 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800757}
758
759static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
760 const struct intel_ds_view *view)
761{
762 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800763 uint32_t dw0, *dw;
764 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800765
766 CMD_ASSERT(cmd, 6, 7.5);
767
768 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800769 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
770 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800771 dw0 |= (cmd_len - 2);
772
Chia-I Wu72292b72014-09-09 10:48:33 +0800773 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
774 dw[0] = dw0;
775 dw[1] = view->cmd[6];
776 dw[2] = 0;
777
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600778 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800779 cmd_reserve_reloc(cmd, 1);
780 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
781 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600782 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800783}
784
785static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
786 const struct intel_ds_view *view)
787{
788 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800789 uint32_t dw0, *dw;
790 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800791
792 CMD_ASSERT(cmd, 6, 7.5);
793
794 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800795 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
796 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797 dw0 |= (cmd_len - 2);
798
Chia-I Wu72292b72014-09-09 10:48:33 +0800799 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
800 dw[0] = dw0;
801 dw[1] = view->cmd[8];
802 dw[2] = 0;
803
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600804 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800805 cmd_reserve_reloc(cmd, 1);
806 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
807 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600808 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800809}
810
Chia-I Wuf8231032014-08-25 10:44:45 +0800811static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
812 uint32_t clear_val)
813{
814 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800815 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800816 GEN6_CLEAR_PARAMS_DW0_VALID |
817 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800818 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800819
820 CMD_ASSERT(cmd, 6, 6);
821
Chia-I Wu72292b72014-09-09 10:48:33 +0800822 cmd_batch_pointer(cmd, cmd_len, &dw);
823 dw[0] = dw0;
824 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800825}
826
827static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
828 uint32_t clear_val)
829{
830 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800831 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800832 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800833 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800834
835 CMD_ASSERT(cmd, 7, 7.5);
836
Chia-I Wu72292b72014-09-09 10:48:33 +0800837 cmd_batch_pointer(cmd, cmd_len, &dw);
838 dw[0] = dw0;
839 dw[1] = clear_val;
840 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800841}
842
Chia-I Wu302742d2014-08-22 10:28:29 +0800843static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800844 uint32_t blend_offset,
845 uint32_t ds_offset,
846 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800847{
848 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800849 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800850
851 CMD_ASSERT(cmd, 6, 6);
852
Chia-I Wu426072d2014-08-26 14:31:55 +0800853 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800854 (cmd_len - 2);
855
Chia-I Wu72292b72014-09-09 10:48:33 +0800856 cmd_batch_pointer(cmd, cmd_len, &dw);
857 dw[0] = dw0;
858 dw[1] = blend_offset | 1;
859 dw[2] = ds_offset | 1;
860 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800861}
862
Chia-I Wu1744cca2014-08-22 11:10:17 +0800863static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800864 uint32_t clip_offset,
865 uint32_t sf_offset,
866 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800867{
868 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800869 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800870
871 CMD_ASSERT(cmd, 6, 6);
872
Chia-I Wu426072d2014-08-26 14:31:55 +0800873 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800874 GEN6_PTR_VP_DW0_CLIP_CHANGED |
875 GEN6_PTR_VP_DW0_SF_CHANGED |
876 GEN6_PTR_VP_DW0_CC_CHANGED |
877 (cmd_len - 2);
878
Chia-I Wu72292b72014-09-09 10:48:33 +0800879 cmd_batch_pointer(cmd, cmd_len, &dw);
880 dw[0] = dw0;
881 dw[1] = clip_offset;
882 dw[2] = sf_offset;
883 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800884}
885
886static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800887 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800888{
889 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800890 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800891
892 CMD_ASSERT(cmd, 6, 6);
893
Chia-I Wu426072d2014-08-26 14:31:55 +0800894 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800895 (cmd_len - 2);
896
Chia-I Wu72292b72014-09-09 10:48:33 +0800897 cmd_batch_pointer(cmd, cmd_len, &dw);
898 dw[0] = dw0;
899 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800900}
901
Chia-I Wu42a56202014-08-23 16:47:48 +0800902static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800903 uint32_t vs_offset,
904 uint32_t gs_offset,
905 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800906{
907 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800908 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800909
910 CMD_ASSERT(cmd, 6, 6);
911
Chia-I Wu426072d2014-08-26 14:31:55 +0800912 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800913 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
914 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
915 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
916 (cmd_len - 2);
917
Chia-I Wu72292b72014-09-09 10:48:33 +0800918 cmd_batch_pointer(cmd, cmd_len, &dw);
919 dw[0] = dw0;
920 dw[1] = vs_offset;
921 dw[2] = gs_offset;
922 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800923}
924
Chia-I Wu257e75e2014-08-29 14:06:35 +0800925static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800926 uint32_t vs_offset,
927 uint32_t gs_offset,
928 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800929{
930 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800931 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800932
933 CMD_ASSERT(cmd, 6, 6);
934
935 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
936 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
937 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
938 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
939 (cmd_len - 2);
940
Chia-I Wu72292b72014-09-09 10:48:33 +0800941 cmd_batch_pointer(cmd, cmd_len, &dw);
942 dw[0] = dw0;
943 dw[1] = vs_offset;
944 dw[2] = gs_offset;
945 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800946}
947
Chia-I Wu302742d2014-08-22 10:28:29 +0800948static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800949 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800950{
951 const uint8_t cmd_len = 2;
952 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
953 GEN6_RENDER_SUBTYPE_3D |
954 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800956
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 cmd_batch_pointer(cmd, cmd_len, &dw);
958 dw[0] = dw0;
959 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800960}
961
Chia-I Wua6c4f152014-12-02 04:19:58 +0800962static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800963{
Chia-I Wue6073342014-11-30 09:43:42 +0800964 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800965 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
Chia-I Wua6c4f152014-12-02 04:19:58 +0800966 const XGL_PIPELINE_CB_STATE *cb = &cmd->bind.pipeline.graphics->cb_state;
967 const struct intel_blend_state *blend = cmd->bind.state.blend;
968 uint32_t dw[XGL_MAX_COLOR_ATTACHMENTS * 2];
969 int i;
Chia-I Wu302742d2014-08-22 10:28:29 +0800970
971 CMD_ASSERT(cmd, 6, 7.5);
Chia-I Wua6c4f152014-12-02 04:19:58 +0800972 STATIC_ASSERT(ARRAY_SIZE(blend->cmd_blend) >= XGL_MAX_COLOR_ATTACHMENTS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800973
Chia-I Wua6c4f152014-12-02 04:19:58 +0800974 for (i = 0; i < XGL_MAX_COLOR_ATTACHMENTS; i++) {
975 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &cb->attachment[i];
976 uint32_t dw0, dw1;
977
978 dw0 = 0;
979 dw1 = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
980 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
981 GEN6_BLEND_DW1_POST_BLEND_CLAMP;
982
983 if (cb->logicOp != XGL_LOGIC_OP_COPY) {
984 int logicop;
985
986 switch (cb->logicOp) {
987 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
988 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
989 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
990 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
991 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
992 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
993 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
994 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
995 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
996 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
997 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
998 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
999 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1000 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1001 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1002 default:
1003 assert(!"unknown logic op");
1004 logicop = GEN6_LOGICOP_CLEAR;
1005 break;
1006 }
1007
1008 dw1 |= GEN6_BLEND_DW1_LOGICOP_ENABLE |
1009 logicop << GEN6_BLEND_DW1_LOGICOP_FUNC__SHIFT;
1010 } else if (att->blendEnable && blend) {
1011 dw0 |= blend->cmd_blend[i];
1012 }
1013
1014 if (!(att->channelWriteMask & 0x1))
1015 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_R;
1016 if (!(att->channelWriteMask & 0x2))
1017 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_G;
1018 if (!(att->channelWriteMask & 0x4))
1019 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_B;
1020 if (!(att->channelWriteMask & 0x8))
1021 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_A;
1022
1023 dw[2 * i] = dw0;
1024 dw[2 * i + 1] = dw1;
1025 }
1026
1027 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001028}
1029
Chia-I Wu72292b72014-09-09 10:48:33 +08001030static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001031 const struct intel_ds_state *state)
1032{
Chia-I Wue6073342014-11-30 09:43:42 +08001033 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001034 const uint8_t cmd_len = 3;
1035
1036 CMD_ASSERT(cmd, 6, 7.5);
1037 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1038
Chia-I Wu00b51a82014-09-09 12:07:37 +08001039 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1040 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001041}
1042
Chia-I Wu72292b72014-09-09 10:48:33 +08001043static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001044 uint32_t stencil_ref,
1045 const uint32_t blend_color[4])
1046{
Chia-I Wue6073342014-11-30 09:43:42 +08001047 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001048 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001049 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001050
1051 CMD_ASSERT(cmd, 6, 7.5);
1052
Chia-I Wu00b51a82014-09-09 12:07:37 +08001053 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1054 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001055 dw[0] = stencil_ref;
1056 dw[1] = 0;
1057 dw[2] = blend_color[0];
1058 dw[3] = blend_color[1];
1059 dw[4] = blend_color[2];
1060 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001061
Chia-I Wu72292b72014-09-09 10:48:33 +08001062 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001063}
1064
Chia-I Wu8370b402014-08-29 12:28:37 +08001065static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001066{
Chia-I Wu8370b402014-08-29 12:28:37 +08001067 CMD_ASSERT(cmd, 6, 7.5);
1068
Chia-I Wu707a29e2014-08-27 12:51:47 +08001069 if (!cmd->bind.draw_count)
1070 return;
1071
Chia-I Wu8370b402014-08-29 12:28:37 +08001072 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001073 return;
1074
Chia-I Wu8370b402014-08-29 12:28:37 +08001075 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001076
1077 /*
1078 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1079 *
1080 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1081 * pipe-control with a post-sync op and no write-cache flushes."
1082 *
1083 * The workaround below necessitates this workaround.
1084 */
1085 gen6_PIPE_CONTROL(cmd,
1086 GEN6_PIPE_CONTROL_CS_STALL |
1087 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001088 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001089
Chia-I Wud6d079d2014-08-31 13:14:21 +08001090 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1091 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001092}
1093
Chia-I Wu8370b402014-08-29 12:28:37 +08001094static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001095{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001096 CMD_ASSERT(cmd, 6, 7.5);
1097
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001098 if (!cmd->bind.draw_count)
1099 return;
1100
Chia-I Wud6d079d2014-08-31 13:14:21 +08001101 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1102 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001103}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001104
Chia-I Wu8370b402014-08-29 12:28:37 +08001105static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1106{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001107 CMD_ASSERT(cmd, 7, 7.5);
1108
Chia-I Wu8370b402014-08-29 12:28:37 +08001109 if (!cmd->bind.draw_count)
1110 return;
1111
1112 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001113
1114 gen6_PIPE_CONTROL(cmd,
1115 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001116 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001117}
1118
Chia-I Wu8370b402014-08-29 12:28:37 +08001119static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1120{
1121 CMD_ASSERT(cmd, 7, 7.5);
1122
1123 if (!cmd->bind.draw_count)
1124 return;
1125
1126 /*
1127 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1128 *
1129 * "One of the following must also be set (when CS stall is set):
1130 *
1131 * * Render Target Cache Flush Enable ([12] of DW1)
1132 * * Depth Cache Flush Enable ([0] of DW1)
1133 * * Stall at Pixel Scoreboard ([1] of DW1)
1134 * * Depth Stall ([13] of DW1)
1135 * * Post-Sync Operation ([13] of DW1)"
1136 */
1137 gen6_PIPE_CONTROL(cmd,
1138 GEN6_PIPE_CONTROL_CS_STALL |
1139 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001140 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001141}
1142
1143static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1144{
1145 CMD_ASSERT(cmd, 7, 7.5);
1146
1147 if (!cmd->bind.draw_count)
1148 return;
1149
1150 cmd_wa_gen6_pre_depth_stall_write(cmd);
1151
Chia-I Wud6d079d2014-08-31 13:14:21 +08001152 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001153}
1154
1155static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1156{
1157 CMD_ASSERT(cmd, 6, 7.5);
1158
1159 if (!cmd->bind.draw_count)
1160 return;
1161
1162 /*
1163 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1164 *
1165 * "Driver must guarentee that all the caches in the depth pipe are
1166 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1167 * requires driver to send a PIPE_CONTROL with a CS stall along with
1168 * a Depth Flush prior to this command."
1169 *
1170 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1171 *
1172 * "Driver must ierarchi that all the caches in the depth pipe are
1173 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1174 * requires driver to send a PIPE_CONTROL with a CS stall along with
1175 * a Depth Flush prior to this command.
1176 */
1177 gen6_PIPE_CONTROL(cmd,
1178 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1179 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001180 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001181}
1182
1183static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1184{
1185 CMD_ASSERT(cmd, 6, 7.5);
1186
1187 if (!cmd->bind.draw_count)
1188 return;
1189
1190 /*
1191 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1192 *
1193 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1194 * and a post sync operation prior to the group of depth
1195 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1196 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1197 *
1198 * This workaround satifies all the conditions.
1199 */
1200 cmd_wa_gen6_pre_depth_stall_write(cmd);
1201
1202 /*
1203 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1204 *
1205 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1206 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1207 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1208 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1209 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1210 * Depth Flush Bit set, followed by another pipelined depth stall
1211 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1212 * guarantee that the pipeline from WM onwards is already flushed
1213 * (e.g., via a preceding MI_FLUSH)."
1214 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001215 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1216 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1217 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001218}
1219
Chia-I Wu525c6602014-08-27 10:22:34 +08001220void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1221{
1222 if (!cmd->bind.draw_count)
1223 return;
1224
1225 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1226
Chia-I Wu8370b402014-08-29 12:28:37 +08001227 /*
1228 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1229 *
1230 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1231 * PIPE_CONTROL with any non-zero post-sync-op is required."
1232 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001233 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001234 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001235
Chia-I Wu092279a2014-08-30 19:05:30 +08001236 /*
1237 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1238 *
1239 * "One of the following must also be set (when CS stall is set):
1240 *
1241 * * Render Target Cache Flush Enable ([12] of DW1)
1242 * * Depth Cache Flush Enable ([0] of DW1)
1243 * * Stall at Pixel Scoreboard ([1] of DW1)
1244 * * Depth Stall ([13] of DW1)
1245 * * Post-Sync Operation ([13] of DW1)"
1246 */
1247 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1248 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1249 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1250 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1251 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1252 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1253
Chia-I Wud6d079d2014-08-31 13:14:21 +08001254 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001255}
1256
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001257void cmd_batch_flush_all(struct intel_cmd *cmd)
1258{
1259 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1260 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1261 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1262 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1263 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1264 GEN6_PIPE_CONTROL_CS_STALL);
1265}
1266
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001267void cmd_batch_depth_count(struct intel_cmd *cmd,
1268 struct intel_bo *bo,
1269 XGL_GPU_SIZE offset)
1270{
1271 cmd_wa_gen6_pre_depth_stall_write(cmd);
1272
1273 gen6_PIPE_CONTROL(cmd,
1274 GEN6_PIPE_CONTROL_DEPTH_STALL |
1275 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001276 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001277}
1278
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001279void cmd_batch_timestamp(struct intel_cmd *cmd,
1280 struct intel_bo *bo,
1281 XGL_GPU_SIZE offset)
1282{
1283 /* need any WA or stall? */
1284 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1285}
1286
1287void cmd_batch_immediate(struct intel_cmd *cmd,
1288 struct intel_bo *bo,
1289 XGL_GPU_SIZE offset,
1290 uint64_t val)
1291{
1292 /* need any WA or stall? */
1293 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1294}
1295
Chia-I Wu302742d2014-08-22 10:28:29 +08001296static void gen6_cc_states(struct intel_cmd *cmd)
1297{
1298 const struct intel_blend_state *blend = cmd->bind.state.blend;
1299 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001300 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001301 uint32_t stencil_ref;
1302 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001303
1304 CMD_ASSERT(cmd, 6, 6);
1305
Chia-I Wua6c4f152014-12-02 04:19:58 +08001306 blend_offset = gen6_BLEND_STATE(cmd);
1307
1308 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001309 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001310 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001311 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001312
1313 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001314 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001315 stencil_ref = ds->cmd_stencil_ref;
1316 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001317 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001318 stencil_ref = 0;
1319 }
1320
Chia-I Wu72292b72014-09-09 10:48:33 +08001321 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001322
Chia-I Wu72292b72014-09-09 10:48:33 +08001323 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001324}
1325
Chia-I Wu1744cca2014-08-22 11:10:17 +08001326static void gen6_viewport_states(struct intel_cmd *cmd)
1327{
1328 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001329 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001330
1331 if (!viewport)
1332 return;
1333
Chia-I Wub1d450a2014-09-09 13:48:03 +08001334 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1335 viewport->viewport_count);
1336
1337 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001338 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001339 viewport->cmd);
1340
1341 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001342 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001343 &viewport->cmd[viewport->cmd_clip_pos]);
1344
1345 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001346 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001347 &viewport->cmd[viewport->cmd_cc_pos]);
1348
1349 if (viewport->scissor_enable) {
1350 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001351 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001352 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1353 } else {
1354 scissor_offset = 0;
1355 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001356
1357 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001358 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001359
Chia-I Wub1d450a2014-09-09 13:48:03 +08001360 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001361}
1362
Chia-I Wu302742d2014-08-22 10:28:29 +08001363static void gen7_cc_states(struct intel_cmd *cmd)
1364{
1365 const struct intel_blend_state *blend = cmd->bind.state.blend;
1366 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001367 uint32_t stencil_ref;
1368 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001369 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001370
1371 CMD_ASSERT(cmd, 7, 7.5);
1372
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001373 if (!blend && !ds)
1374 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001375
Chia-I Wua6c4f152014-12-02 04:19:58 +08001376 offset = gen6_BLEND_STATE(cmd);
1377 gen7_3dstate_pointer(cmd,
1378 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001379
Chia-I Wua6c4f152014-12-02 04:19:58 +08001380 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001381 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001382 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001383 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001384
1385 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001386 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001387 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001388 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1389 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001390 } else {
1391 stencil_ref = 0;
1392 }
1393
Chia-I Wu72292b72014-09-09 10:48:33 +08001394 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001395 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001396 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001397}
1398
Chia-I Wu1744cca2014-08-22 11:10:17 +08001399static void gen7_viewport_states(struct intel_cmd *cmd)
1400{
1401 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001402 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001403
1404 if (!viewport)
1405 return;
1406
Chia-I Wub1d450a2014-09-09 13:48:03 +08001407 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1408 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001409
Chia-I Wub1d450a2014-09-09 13:48:03 +08001410 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001411 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001413 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001414 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1415 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001416
1417 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001418 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001419 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001420 gen7_3dstate_pointer(cmd,
1421 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001422 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001423
Chia-I Wu1744cca2014-08-22 11:10:17 +08001424 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001425 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001426 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001428 gen7_3dstate_pointer(cmd,
1429 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001430 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001431 }
1432}
1433
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001434static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001435 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001436{
1437 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001438 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001439
Chia-I Wu72292b72014-09-09 10:48:33 +08001440 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001441
1442 dw[0] = GEN6_RENDER_TYPE_RENDER |
1443 GEN6_RENDER_SUBTYPE_3D |
1444 subop | (cmd_len - 2);
1445 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001446 dw[2] = 0;
1447 dw[3] = 0;
1448 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001449}
1450
1451static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001452 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001453{
1454 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001455 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001456
Chia-I Wu72292b72014-09-09 10:48:33 +08001457 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001458
1459 dw[0] = GEN6_RENDER_TYPE_RENDER |
1460 GEN6_RENDER_SUBTYPE_3D |
1461 subop | (cmd_len - 2);
1462 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001463 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001464 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001465 dw[4] = 0;
1466 dw[5] = 0;
1467 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001468}
1469
Chia-I Wu625105f2014-10-13 15:35:29 +08001470static uint32_t emit_samplers(struct intel_cmd *cmd,
1471 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001472{
1473 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1474 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001475 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001476 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001477 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001478 XGL_UINT i;
1479
1480 CMD_ASSERT(cmd, 6, 7.5);
1481
Chia-I Wu625105f2014-10-13 15:35:29 +08001482 if (!rmap || !rmap->sampler_count)
1483 return 0;
1484
Cody Northrop40316a32014-12-09 19:08:33 -07001485 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001486
Chia-I Wudcb509d2014-12-10 08:53:10 +08001487 /*
1488 * note that we cannot call cmd_state_pointer() here as the following
1489 * cmd_state_pointer() would invalidate the pointer
1490 */
1491 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001492 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001493 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001494
1495 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001496 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001497 4 * rmap->sampler_count, &sampler_dw);
1498
Chia-I Wudcb509d2014-12-10 08:53:10 +08001499 cmd_state_update(cmd, border_offset,
1500 border_stride * rmap->sampler_count, &border_dw);
1501
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001502 for (i = 0; i < rmap->sampler_count; i++) {
1503 const struct intel_pipeline_rmap_slot *slot =
1504 &rmap->slots[surface_count + i];
1505 const struct intel_sampler *sampler;
1506
1507 switch (slot->path_len) {
1508 case 0:
1509 sampler = NULL;
1510 break;
1511 case INTEL_PIPELINE_RMAP_SLOT_RT:
1512 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1513 assert(!"unexpected rmap slot type");
1514 sampler = NULL;
1515 break;
1516 case 1:
1517 {
1518 const struct intel_dset *dset = cmd->bind.dset.graphics;
1519 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1520 const struct intel_dset_slot *dset_slot =
1521 &dset->slots[slot_offset + slot->u.index];
1522
1523 switch (dset_slot->type) {
1524 case INTEL_DSET_SLOT_SAMPLER:
1525 sampler = dset_slot->u.sampler;
1526 break;
1527 default:
1528 assert(!"unexpected dset slot type");
1529 sampler = NULL;
1530 break;
1531 }
1532 }
1533 break;
1534 default:
1535 assert(!"nested descriptor set unsupported");
1536 sampler = NULL;
1537 break;
1538 }
1539
1540 if (sampler) {
1541 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1542
1543 sampler_dw[0] = sampler->cmd[0];
1544 sampler_dw[1] = sampler->cmd[1];
1545 sampler_dw[2] = border_offset;
1546 sampler_dw[3] = sampler->cmd[2];
1547 } else {
1548 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1549 sampler_dw[1] = 0;
1550 sampler_dw[2] = 0;
1551 sampler_dw[3] = 0;
1552 }
1553
1554 border_offset += border_stride * 4;
1555 border_dw += border_stride;
1556 sampler_dw += 4;
1557 }
1558
Chia-I Wu625105f2014-10-13 15:35:29 +08001559 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001560}
1561
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001562static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001563 const struct intel_pipeline_rmap *rmap,
1564 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001565{
Chia-I Wu72292b72014-09-09 10:48:33 +08001566 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001567 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001568
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001569 CMD_ASSERT(cmd, 6, 7.5);
1570
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001571 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001572 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001573 if (!surface_count)
1574 return 0;
1575
Chia-I Wu42a56202014-08-23 16:47:48 +08001576 assert(surface_count <= ARRAY_SIZE(binding_table));
1577
1578 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001579 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001580
1581 switch (slot->path_len) {
1582 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001583 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001584 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001585 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001586 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001587 const struct intel_rt_view *view =
1588 (slot->u.index < cmd->bind.att.rt_count) ?
1589 cmd->bind.att.rt[slot->u.index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001590
Chia-I Wu787a05b2014-12-05 11:02:20 +08001591 if (view) {
1592 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1593 GEN6_ALIGNMENT_SURFACE_STATE,
1594 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001595
Chia-I Wu787a05b2014-12-05 11:02:20 +08001596 cmd_reserve_reloc(cmd, 1);
1597 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1598 view->cmd[1], INTEL_RELOC_WRITE);
1599 } else {
1600 struct intel_null_view null_view;
1601 intel_null_view_init(&null_view, cmd->dev);
1602
1603 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1604 GEN6_ALIGNMENT_SURFACE_STATE,
1605 null_view.cmd_len, null_view.cmd);
1606 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001607 }
1608 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001609 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001610 {
1611 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001612 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001613
Chia-I Wu00b51a82014-09-09 12:07:37 +08001614 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001615 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001616 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001617
Chia-I Wu72292b72014-09-09 10:48:33 +08001618 cmd_reserve_reloc(cmd, 1);
1619 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1620 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001621 }
1622 break;
1623 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001624 {
1625 const struct intel_dset *dset = cmd->bind.dset.graphics;
1626 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1627 const struct intel_dset_slot *dset_slot =
1628 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001629 const uint32_t reloc_flags =
1630 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001631
1632 switch (dset_slot->type) {
1633 case INTEL_DSET_SLOT_IMG_VIEW:
1634 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001635 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001636 dset_slot->u.img_view->cmd_len,
1637 dset_slot->u.img_view->cmd);
1638
1639 cmd_reserve_reloc(cmd, 1);
1640 cmd_surface_reloc(cmd, offset, 1,
1641 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001642 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001643 break;
1644 case INTEL_DSET_SLOT_MEM_VIEW:
Cody Northrop7c76f302014-12-18 11:52:58 -07001645 {
1646 XGL_MEMORY_VIEW_ATTACH_INFO tmp_info = dset_slot->u.mem_view.info;
1647 struct intel_mem_view tmp;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001648
Cody Northrop7c76f302014-12-18 11:52:58 -07001649 memset(&tmp, 0, sizeof(tmp));
1650
1651 /* The compiler expects uniform buffers to have pitch of
1652 * 4 for fragment shaders, but 16 for other stages.
1653 */
1654 if (XGL_SHADER_STAGE_FRAGMENT == stage) {
1655 tmp_info.stride = 4;
1656 } else {
1657 tmp_info.stride = 16;
1658 }
1659
1660 intel_mem_view_init(&tmp, cmd->dev, &tmp_info);
1661
1662 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1663 GEN6_ALIGNMENT_SURFACE_STATE,
1664 tmp.cmd_len,
1665 tmp.cmd);
1666
1667 cmd_reserve_reloc(cmd, 1);
1668 cmd_surface_reloc(cmd, offset, 1,
1669 dset_slot->u.mem_view.mem->bo,
1670 tmp.cmd[1], reloc_flags);
1671 }
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001672 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001673 case INTEL_DSET_SLOT_SAMPLER:
1674 assert(0 == cmd->bind.dset.graphics_offset);
1675
1676 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001677 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001678 16, dset_slot->u.sampler->cmd);
1679 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001680 default:
1681 assert(!"unexpected dset slot type");
1682 break;
1683 }
1684 }
1685 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001686 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001687 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001688 break;
1689 }
1690
Chia-I Wu72292b72014-09-09 10:48:33 +08001691 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001692 }
1693
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001694 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001695 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001696 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001697}
1698
Chia-I Wu1d125092014-10-08 08:49:38 +08001699static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1700{
1701 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001702 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1703 uint32_t *dw;
1704 XGL_UINT pos, i;
1705
1706 CMD_ASSERT(cmd, 6, 7.5);
1707
1708 if (!pipeline->vb_count)
1709 return;
1710
1711 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1712
1713 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1714 dw++;
1715 pos++;
1716
1717 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001718 assert(pipeline->vb[i].strideInBytes <= 2048);
1719
1720 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1721 pipeline->vb[i].strideInBytes;
1722
1723 if (cmd_gen(cmd) >= INTEL_GEN(7))
1724 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1725
1726 switch (pipeline->vb[i].stepRate) {
1727 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1728 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1729 dw[3] = 0;
1730 break;
1731 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1732 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1733 dw[3] = 1;
1734 break;
1735 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1736 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1737 dw[3] = 0;
1738 break;
1739 default:
1740 assert(!"unknown step rate");
1741 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1742 dw[3] = 0;
1743 break;
1744 }
1745
Chia-I Wu3b04af52014-11-08 10:48:20 +08001746 if (cmd->bind.vertex.mem[i]) {
1747 const struct intel_mem *mem = cmd->bind.vertex.mem[i];
1748 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001749
1750 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3b04af52014-11-08 10:48:20 +08001751 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
1752 cmd_batch_reloc(cmd, pos + 2, mem->bo, mem->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001753 } else {
1754 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1755 dw[1] = 0;
1756 dw[2] = 0;
1757 }
1758
1759 dw += 4;
1760 pos += 4;
1761 }
1762}
1763
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001764static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1765{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001766 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1767 const struct intel_pipeline_shader *vs = &pipeline->vs;
1768 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001769 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001770 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001771 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001772 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001773
1774 CMD_ASSERT(cmd, 6, 7.5);
1775
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001776 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001777 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1778 *
1779 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1780 * 128-bit vertex elements to be passed into the payload for each
1781 * vertex."
1782 *
1783 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1784 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001785 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001786 vue_read_len = (vs->in_count + 1) / 2;
1787 if (!vue_read_len)
1788 vue_read_len = 1;
1789
1790 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1791 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1792
1793 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1794 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1795 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001796
1797 dw5 = GEN6_VS_DW5_STATISTICS |
1798 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001799
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001800 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001801 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001802 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001803 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001804
Chia-I Wube0a3d92014-09-02 13:20:59 +08001805 if (pipeline->disable_vs_cache)
1806 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1807
Chia-I Wu784d3042014-12-19 14:30:04 +08001808 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001809 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001810 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001811 dw[2] = dw2;
1812 dw[3] = 0; /* scratch */
1813 dw[4] = dw4;
1814 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001815
1816 if (vs->per_thread_scratch_size)
1817 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001818}
1819
Chia-I Wu625105f2014-10-13 15:35:29 +08001820static void emit_shader_resources(struct intel_cmd *cmd)
1821{
1822 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001823 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001824
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001825 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001826 cmd->bind.pipeline.graphics->vs.rmap,
1827 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001828 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001829 cmd->bind.pipeline.graphics->tcs.rmap,
1830 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001831 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001832 cmd->bind.pipeline.graphics->tes.rmap,
1833 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001834 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001835 cmd->bind.pipeline.graphics->gs.rmap,
1836 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001837 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001838 cmd->bind.pipeline.graphics->fs.rmap,
1839 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001840
1841 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1842 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1843 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1844 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1845 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1846
1847 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1848 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001849 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1850 binding_tables[0]);
1851 gen7_3dstate_pointer(cmd,
1852 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1853 binding_tables[1]);
1854 gen7_3dstate_pointer(cmd,
1855 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1856 binding_tables[2]);
1857 gen7_3dstate_pointer(cmd,
1858 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1859 binding_tables[3]);
1860 gen7_3dstate_pointer(cmd,
1861 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1862 binding_tables[4]);
1863
1864 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001865 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1866 samplers[0]);
1867 gen7_3dstate_pointer(cmd,
1868 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1869 samplers[1]);
1870 gen7_3dstate_pointer(cmd,
1871 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1872 samplers[2]);
1873 gen7_3dstate_pointer(cmd,
1874 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1875 samplers[3]);
1876 gen7_3dstate_pointer(cmd,
1877 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1878 samplers[4]);
1879 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001880 assert(!binding_tables[1] && !binding_tables[2]);
1881 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1882 binding_tables[0], binding_tables[3], binding_tables[4]);
1883
Chia-I Wu625105f2014-10-13 15:35:29 +08001884 assert(!samplers[1] && !samplers[2]);
1885 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1886 samplers[0], samplers[3], samplers[4]);
1887 }
1888}
1889
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001890static void emit_rt(struct intel_cmd *cmd)
1891{
1892 cmd_wa_gen6_pre_depth_stall_write(cmd);
1893 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1894 cmd->bind.att.height);
1895}
1896
1897static void emit_ds(struct intel_cmd *cmd)
1898{
1899 const struct intel_ds_view *ds = cmd->bind.att.ds;
1900
1901 if (!ds) {
1902 /* all zeros */
1903 static const struct intel_ds_view null_ds;
1904 ds = &null_ds;
1905 }
1906
1907 cmd_wa_gen6_pre_ds_flush(cmd);
1908 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1909 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1910 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1911
1912 if (cmd_gen(cmd) >= INTEL_GEN(7))
1913 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1914 else
1915 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1916}
1917
Chia-I Wua57761b2014-10-14 14:27:44 +08001918static uint32_t emit_shader(struct intel_cmd *cmd,
1919 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001920{
Chia-I Wua57761b2014-10-14 14:27:44 +08001921 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1922 uint32_t offset;
1923 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001924
Chia-I Wua57761b2014-10-14 14:27:44 +08001925 /* see if the shader is already in the cache */
1926 for (i = 0; i < cache->used; i++) {
1927 if (cache->entries[i].shader == (const void *) shader)
1928 return cache->entries[i].kernel_offset;
1929 }
1930
1931 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1932
1933 /* grow the cache if full */
1934 if (cache->used >= cache->count) {
1935 const XGL_UINT count = cache->count + 16;
1936 void *entries;
1937
1938 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1939 XGL_SYSTEM_ALLOC_INTERNAL);
1940 if (entries) {
1941 if (cache->entries) {
1942 memcpy(entries, cache->entries,
1943 sizeof(cache->entries[0]) * cache->used);
1944 icd_free(cache->entries);
1945 }
1946
1947 cache->entries = entries;
1948 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001949 }
1950 }
1951
Chia-I Wua57761b2014-10-14 14:27:44 +08001952 /* add the shader to the cache */
1953 if (cache->used < cache->count) {
1954 cache->entries[cache->used].shader = (const void *) shader;
1955 cache->entries[cache->used].kernel_offset = offset;
1956 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001957 }
1958
Chia-I Wua57761b2014-10-14 14:27:44 +08001959 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001960}
1961
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001962static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001963{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001964 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001965
Chia-I Wu8370b402014-08-29 12:28:37 +08001966 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1967 cmd_wa_gen6_pre_depth_stall_write(cmd);
1968 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1969 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1970 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1971 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001972
1973 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001974 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001975 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001976
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001977 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001978 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001979 }
1980 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001981 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001982 }
1983 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001984 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1985 }
1986 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1987 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1988 }
1989 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1990 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001991 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001992
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001993 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1994 gen7_3DSTATE_GS(cmd);
1995 } else {
1996 gen6_3DSTATE_GS(cmd);
1997 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001998
Chia-I Wu8370b402014-08-29 12:28:37 +08001999 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2000 cmd_wa_gen7_post_command_cs_stall(cmd);
2001 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2002 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002003}
2004
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002005static void emit_bounded_states(struct intel_cmd *cmd)
2006{
2007 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
2008
2009 emit_graphics_pipeline(cmd);
2010
2011 emit_rt(cmd);
2012 emit_ds(cmd);
2013
2014 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2015 gen7_cc_states(cmd);
2016 gen7_viewport_states(cmd);
2017
2018 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2019 &cmd->bind.pipeline.graphics->vs);
2020 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2021 &cmd->bind.pipeline.graphics->fs);
2022
2023 gen6_3DSTATE_CLIP(cmd);
2024 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002025 gen7_3DSTATE_WM(cmd);
2026 gen7_3DSTATE_PS(cmd);
2027 } else {
2028 gen6_cc_states(cmd);
2029 gen6_viewport_states(cmd);
2030
2031 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2032 &cmd->bind.pipeline.graphics->vs);
2033 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2034 &cmd->bind.pipeline.graphics->fs);
2035
2036 gen6_3DSTATE_CLIP(cmd);
2037 gen6_3DSTATE_SF(cmd);
2038 gen6_3DSTATE_WM(cmd);
2039 }
2040
2041 emit_shader_resources(cmd);
2042
2043 cmd_wa_gen6_pre_depth_stall_write(cmd);
2044 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2045
2046 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2047 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2048
2049 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2050 gen6_3DSTATE_VS(cmd);
2051}
2052
Chia-I Wu6032b892014-10-17 14:47:18 +08002053static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2054{
2055 const struct intel_cmd_meta *meta = cmd->bind.meta;
2056 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2057
2058 CMD_ASSERT(cmd, 6, 7.5);
2059
2060 blend_offset = 0;
2061 ds_offset = 0;
2062 cc_offset = 0;
2063 cc_vp_offset = 0;
2064
Chia-I Wu29e6f502014-11-24 14:27:29 +08002065 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002066 /* BLEND_STATE */
2067 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002068 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002069 dw[0] = 0;
2070 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2071 }
2072
Chia-I Wu29e6f502014-11-24 14:27:29 +08002073 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2074 if (meta->ds.state) {
2075 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002076
Chia-I Wu29e6f502014-11-24 14:27:29 +08002077 /* DEPTH_STENCIL_STATE */
2078 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002079
Chia-I Wu29e6f502014-11-24 14:27:29 +08002080 /* COLOR_CALC_STATE */
2081 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2082 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002083
Chia-I Wu29e6f502014-11-24 14:27:29 +08002084 /* CC_VIEWPORT */
2085 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002086 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002087 dw[0] = u_fui(0.0f);
2088 dw[1] = u_fui(1.0f);
2089 } else {
2090 /* DEPTH_STENCIL_STATE */
2091 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002092 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002093 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2094 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2095 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002096 }
2097
2098 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2099 gen7_3dstate_pointer(cmd,
2100 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2101 blend_offset);
2102 gen7_3dstate_pointer(cmd,
2103 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2104 ds_offset);
2105 gen7_3dstate_pointer(cmd,
2106 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2107
2108 gen7_3dstate_pointer(cmd,
2109 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2110 cc_vp_offset);
2111 } else {
2112 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002113 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002114
2115 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2116 cmd_batch_pointer(cmd, 4, &dw);
2117 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2118 GEN6_PTR_VP_DW0_CC_CHANGED;
2119 dw[1] = 0;
2120 dw[2] = 0;
2121 dw[3] = cc_vp_offset;
2122 }
2123}
2124
2125static void gen6_meta_surface_states(struct intel_cmd *cmd)
2126{
2127 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002128 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002129 uint32_t offset;
2130
2131 CMD_ASSERT(cmd, 6, 7.5);
2132
Chia-I Wu29e6f502014-11-24 14:27:29 +08002133 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2134 return;
2135
Chia-I Wu005c47c2014-10-22 13:49:13 +08002136 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002137 if (meta->src.valid) {
2138 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002139 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002140 meta->src.surface_len, meta->src.surface);
2141
2142 cmd_reserve_reloc(cmd, 1);
2143 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2144 cmd_surface_reloc_writer(cmd, offset, 1,
2145 meta->src.reloc_target, meta->src.reloc_offset);
2146 } else {
2147 cmd_surface_reloc(cmd, offset, 1,
2148 (struct intel_bo *) meta->src.reloc_target,
2149 meta->src.reloc_offset, meta->src.reloc_flags);
2150 }
2151
Chia-I Wu005c47c2014-10-22 13:49:13 +08002152 binding_table[0] = offset;
2153 }
2154 if (meta->dst.valid) {
2155 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002156 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002157 meta->dst.surface_len, meta->dst.surface);
2158
2159 cmd_reserve_reloc(cmd, 1);
2160 cmd_surface_reloc(cmd, offset, 1,
2161 (struct intel_bo *) meta->dst.reloc_target,
2162 meta->dst.reloc_offset, meta->dst.reloc_flags);
2163
2164 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002165 }
2166
2167 /* BINDING_TABLE */
2168 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002169 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002170 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002171
2172 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002173 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2174 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2175 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2176 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002177 } else {
2178 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002179 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2180 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2181 else
2182 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002183 }
2184}
2185
2186static void gen6_meta_urb(struct intel_cmd *cmd)
2187{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002188 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002189 uint32_t *dw;
2190
2191 CMD_ASSERT(cmd, 6, 6);
2192
2193 /* 3DSTATE_URB */
2194 cmd_batch_pointer(cmd, 3, &dw);
2195 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002196 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002197 dw[2] = 0;
2198}
2199
2200static void gen7_meta_urb(struct intel_cmd *cmd)
2201{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002202 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002203 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002204 uint32_t *dw;
2205
2206 CMD_ASSERT(cmd, 7, 7.5);
2207
2208 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2209 cmd_batch_pointer(cmd, 10, &dw);
2210
2211 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002212 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002213 dw += 2;
2214
2215 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2216 dw[1] = 0;
2217 dw += 2;
2218
2219 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2220 dw[1] = 0;
2221 dw += 2;
2222
2223 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2224 dw[1] = 0;
2225 dw += 2;
2226
2227 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002228 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002229
2230 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2231
Chia-I Wu24aa1022014-11-25 11:53:19 +08002232 switch (cmd_gen(cmd)) {
2233 case INTEL_GEN(7.5):
2234 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2235 break;
2236 case INTEL_GEN(7):
2237 default:
2238 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2239 break;
2240 }
2241
Chia-I Wu6032b892014-10-17 14:47:18 +08002242 /* 3DSTATE_URB_x */
2243 cmd_batch_pointer(cmd, 8, &dw);
2244
2245 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2246 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002247 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002248 dw += 2;
2249
2250 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2251 dw[1] = 0;
2252 dw += 2;
2253
2254 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2255 dw[1] = 0;
2256 dw += 2;
2257
2258 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2259 dw[1] = 0;
2260 dw += 2;
2261}
2262
2263static void gen6_meta_vf(struct intel_cmd *cmd)
2264{
2265 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002266 uint32_t vb_start, vb_end, vb_stride;
2267 int ve_format, ve_z_source;
2268 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002269 XGL_UINT pos;
2270
2271 CMD_ASSERT(cmd, 6, 7.5);
2272
Chia-I Wu29e6f502014-11-24 14:27:29 +08002273 switch (meta->mode) {
2274 case INTEL_CMD_META_VS_POINTS:
2275 cmd_batch_pointer(cmd, 3, &dw);
2276 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2277 dw[1] = GEN6_VE_STATE_DW0_VALID;
2278 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2279 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2280 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2281 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2282 return;
2283 break;
2284 case INTEL_CMD_META_FS_RECT:
2285 {
2286 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002287
Chia-I Wu29e6f502014-11-24 14:27:29 +08002288 vertices[0][0] = meta->dst.x + meta->width;
2289 vertices[0][1] = meta->dst.y + meta->height;
2290 vertices[1][0] = meta->dst.x;
2291 vertices[1][1] = meta->dst.y + meta->height;
2292 vertices[2][0] = meta->dst.x;
2293 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002294
Chia-I Wu29e6f502014-11-24 14:27:29 +08002295 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2296 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002297
Chia-I Wu29e6f502014-11-24 14:27:29 +08002298 vb_end = vb_start + sizeof(vertices) - 1;
2299 vb_stride = sizeof(vertices[0]);
2300 ve_z_source = GEN6_VFCOMP_STORE_0;
2301 ve_format = GEN6_FORMAT_R32G32_USCALED;
2302 }
2303 break;
2304 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2305 {
2306 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002307
Chia-I Wu29e6f502014-11-24 14:27:29 +08002308 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2309 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2310 vertices[0][2] = u_uif(meta->clear_val[0]);
2311 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2312 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2313 vertices[1][2] = u_uif(meta->clear_val[0]);
2314 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2315 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2316 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002317
Chia-I Wu29e6f502014-11-24 14:27:29 +08002318 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2319 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002320
Chia-I Wu29e6f502014-11-24 14:27:29 +08002321 vb_end = vb_start + sizeof(vertices) - 1;
2322 vb_stride = sizeof(vertices[0]);
2323 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2324 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2325 }
2326 break;
2327 default:
2328 assert(!"unknown meta mode");
2329 return;
2330 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002331 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002332
2333 /* 3DSTATE_VERTEX_BUFFERS */
2334 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002335
Chia-I Wu6032b892014-10-17 14:47:18 +08002336 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002337 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002338 if (cmd_gen(cmd) >= INTEL_GEN(7))
2339 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2340
2341 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002342 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2343 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002344
2345 dw[4] = 0;
2346
2347 /* 3DSTATE_VERTEX_ELEMENTS */
2348 cmd_batch_pointer(cmd, 5, &dw);
2349 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002350 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002351 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2352 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2353 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2354 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2355 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002356 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002357 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2358 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002359 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002360 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2361}
2362
Chia-I Wu29e6f502014-11-24 14:27:29 +08002363static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002364{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002365 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002366 /* one GPR */
2367 XGL_UINT consts[8];
2368 XGL_UINT const_count;
2369
2370 CMD_ASSERT(cmd, 6, 7.5);
2371
2372 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002373 case INTEL_DEV_META_VS_FILL_MEM:
2374 consts[0] = meta->dst.x;
2375 consts[1] = meta->clear_val[0];
2376 const_count = 2;
2377 break;
2378 case INTEL_DEV_META_VS_COPY_MEM:
2379 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2380 consts[0] = meta->dst.x;
2381 consts[1] = meta->src.x;
2382 const_count = 2;
2383 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002384 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2385 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2386 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2387 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2388 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2389 consts[0] = meta->src.x;
2390 consts[1] = meta->src.y;
2391 consts[2] = meta->width;
2392 consts[3] = meta->dst.x;
2393 const_count = 4;
2394 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002395 default:
2396 assert(!"unknown meta shader id");
2397 const_count = 0;
2398 break;
2399 }
2400
2401 /* this can be skipped but it makes state dumping prettier */
2402 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2403
2404 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2405}
2406
2407static void gen6_meta_vs(struct intel_cmd *cmd)
2408{
2409 const struct intel_cmd_meta *meta = cmd->bind.meta;
2410 const struct intel_pipeline_shader *sh =
2411 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2412 uint32_t offset, *dw;
2413
2414 CMD_ASSERT(cmd, 6, 7.5);
2415
2416 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2417 XGL_UINT cmd_len;
2418
2419 /* 3DSTATE_CONSTANT_VS */
2420 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2421 cmd_batch_pointer(cmd, cmd_len, &dw);
2422 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2423 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2424
2425 /* 3DSTATE_VS */
2426 cmd_batch_pointer(cmd, 6, &dw);
2427 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2428 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2429
2430 return;
2431 }
2432
2433 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2434
2435 /* 3DSTATE_CONSTANT_VS */
2436 offset = gen6_meta_vs_constants(cmd);
2437 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2438 cmd_batch_pointer(cmd, 7, &dw);
2439 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2440 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2441 dw[2] = 0;
2442 dw[3] = offset;
2443 dw[4] = 0;
2444 dw[5] = 0;
2445 dw[6] = 0;
2446 } else {
2447 cmd_batch_pointer(cmd, 5, &dw);
2448 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2449 GEN6_PCB_ANY_DW0_PCB0_VALID;
2450 dw[1] = offset;
2451 dw[2] = 0;
2452 dw[3] = 0;
2453 dw[4] = 0;
2454 }
2455
2456 /* 3DSTATE_VS */
2457 offset = emit_shader(cmd, sh);
2458 cmd_batch_pointer(cmd, 6, &dw);
2459 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2460 dw[1] = offset;
2461 dw[2] = GEN6_THREADDISP_SPF |
2462 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2463 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002464 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002465 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2466 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2467
2468 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2469 GEN6_VS_DW5_VS_ENABLE;
2470 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002471 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002472 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002473 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002474
2475 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002476}
2477
2478static void gen6_meta_disabled(struct intel_cmd *cmd)
2479{
Chia-I Wu6032b892014-10-17 14:47:18 +08002480 uint32_t *dw;
2481
2482 CMD_ASSERT(cmd, 6, 6);
2483
Chia-I Wu6032b892014-10-17 14:47:18 +08002484 /* 3DSTATE_CONSTANT_GS */
2485 cmd_batch_pointer(cmd, 5, &dw);
2486 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2487 dw[1] = 0;
2488 dw[2] = 0;
2489 dw[3] = 0;
2490 dw[4] = 0;
2491
2492 /* 3DSTATE_GS */
2493 cmd_batch_pointer(cmd, 7, &dw);
2494 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2495 dw[1] = 0;
2496 dw[2] = 0;
2497 dw[3] = 0;
2498 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2499 dw[5] = GEN6_GS_DW5_STATISTICS;
2500 dw[6] = 0;
2501
Chia-I Wu6032b892014-10-17 14:47:18 +08002502 /* 3DSTATE_SF */
2503 cmd_batch_pointer(cmd, 20, &dw);
2504 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2505 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2506 memset(&dw[2], 0, 18 * sizeof(*dw));
2507}
2508
2509static void gen7_meta_disabled(struct intel_cmd *cmd)
2510{
2511 uint32_t *dw;
2512
2513 CMD_ASSERT(cmd, 7, 7.5);
2514
Chia-I Wu6032b892014-10-17 14:47:18 +08002515 /* 3DSTATE_CONSTANT_HS */
2516 cmd_batch_pointer(cmd, 7, &dw);
2517 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2518 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2519
2520 /* 3DSTATE_HS */
2521 cmd_batch_pointer(cmd, 7, &dw);
2522 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2523 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2524
2525 /* 3DSTATE_TE */
2526 cmd_batch_pointer(cmd, 4, &dw);
2527 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2528 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2529
2530 /* 3DSTATE_CONSTANT_DS */
2531 cmd_batch_pointer(cmd, 7, &dw);
2532 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2533 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2534
2535 /* 3DSTATE_DS */
2536 cmd_batch_pointer(cmd, 6, &dw);
2537 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2538 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2539
2540 /* 3DSTATE_CONSTANT_GS */
2541 cmd_batch_pointer(cmd, 7, &dw);
2542 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2543 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2544
2545 /* 3DSTATE_GS */
2546 cmd_batch_pointer(cmd, 7, &dw);
2547 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2548 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2549
2550 /* 3DSTATE_STREAMOUT */
2551 cmd_batch_pointer(cmd, 3, &dw);
2552 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2553 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2554
Chia-I Wu6032b892014-10-17 14:47:18 +08002555 /* 3DSTATE_SF */
2556 cmd_batch_pointer(cmd, 7, &dw);
2557 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2558 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2559
2560 /* 3DSTATE_SBE */
2561 cmd_batch_pointer(cmd, 14, &dw);
2562 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2563 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2564 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002565}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002566
Chia-I Wu29e6f502014-11-24 14:27:29 +08002567static void gen6_meta_clip(struct intel_cmd *cmd)
2568{
2569 const struct intel_cmd_meta *meta = cmd->bind.meta;
2570 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002571
Chia-I Wu29e6f502014-11-24 14:27:29 +08002572 /* 3DSTATE_CLIP */
2573 cmd_batch_pointer(cmd, 4, &dw);
2574 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2575 dw[1] = 0;
2576 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2577 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2578 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2579 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002580 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002581 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002582 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002583}
2584
2585static void gen6_meta_wm(struct intel_cmd *cmd)
2586{
2587 const struct intel_cmd_meta *meta = cmd->bind.meta;
2588 uint32_t *dw;
2589
2590 CMD_ASSERT(cmd, 6, 7.5);
2591
2592 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2593
2594 /* 3DSTATE_MULTISAMPLE */
2595 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2596 cmd_batch_pointer(cmd, 4, &dw);
2597 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2598 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2599 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2600 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2601 dw[2] = 0;
2602 dw[3] = 0;
2603 } else {
2604 cmd_batch_pointer(cmd, 3, &dw);
2605 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2606 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2607 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2608 dw[2] = 0;
2609 }
2610
2611 /* 3DSTATE_SAMPLE_MASK */
2612 cmd_batch_pointer(cmd, 2, &dw);
2613 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2614 dw[1] = (1 << meta->samples) - 1;
2615
2616 /* 3DSTATE_DRAWING_RECTANGLE */
2617 cmd_batch_pointer(cmd, 4, &dw);
2618 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2619 dw[1] = meta->dst.y << 16 | meta->dst.x;
2620 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2621 (meta->dst.x + meta->width - 1);
2622 dw[3] = 0;
2623}
2624
2625static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2626{
2627 const struct intel_cmd_meta *meta = cmd->bind.meta;
2628 XGL_UINT offset_x, offset_y;
2629 /* one GPR */
2630 XGL_UINT consts[8];
2631 XGL_UINT const_count;
2632
2633 CMD_ASSERT(cmd, 6, 7.5);
2634
2635 /* underflow is fine here */
2636 offset_x = meta->src.x - meta->dst.x;
2637 offset_y = meta->src.y - meta->dst.y;
2638
2639 switch (meta->shader_id) {
2640 case INTEL_DEV_META_FS_COPY_MEM:
2641 case INTEL_DEV_META_FS_COPY_1D:
2642 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2643 case INTEL_DEV_META_FS_COPY_2D:
2644 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2645 case INTEL_DEV_META_FS_COPY_2D_MS:
2646 consts[0] = offset_x;
2647 consts[1] = offset_y;
2648 consts[2] = meta->src.layer;
2649 consts[3] = meta->src.lod;
2650 const_count = 4;
2651 break;
2652 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2653 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2654 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2655 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2656 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2657 consts[0] = offset_x;
2658 consts[1] = offset_y;
2659 consts[2] = meta->src.layer;
2660 consts[3] = meta->src.lod;
2661 consts[4] = meta->src.x;
2662 consts[5] = meta->width;
2663 const_count = 6;
2664 break;
2665 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2666 consts[0] = offset_x;
2667 consts[1] = offset_y;
2668 consts[2] = meta->width;
2669 const_count = 3;
2670 break;
2671 case INTEL_DEV_META_FS_CLEAR_COLOR:
2672 consts[0] = meta->clear_val[0];
2673 consts[1] = meta->clear_val[1];
2674 consts[2] = meta->clear_val[2];
2675 consts[3] = meta->clear_val[3];
2676 const_count = 4;
2677 break;
2678 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2679 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002680 consts[1] = meta->clear_val[1];
2681 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002682 break;
2683 case INTEL_DEV_META_FS_RESOLVE_2X:
2684 case INTEL_DEV_META_FS_RESOLVE_4X:
2685 case INTEL_DEV_META_FS_RESOLVE_8X:
2686 case INTEL_DEV_META_FS_RESOLVE_16X:
2687 consts[0] = offset_x;
2688 consts[1] = offset_y;
2689 const_count = 2;
2690 break;
2691 default:
2692 assert(!"unknown meta shader id");
2693 const_count = 0;
2694 break;
2695 }
2696
2697 /* this can be skipped but it makes state dumping prettier */
2698 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2699
2700 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2701}
2702
2703static void gen6_meta_ps(struct intel_cmd *cmd)
2704{
2705 const struct intel_cmd_meta *meta = cmd->bind.meta;
2706 const struct intel_pipeline_shader *sh =
2707 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2708 uint32_t offset, *dw;
2709
2710 CMD_ASSERT(cmd, 6, 6);
2711
Chia-I Wu29e6f502014-11-24 14:27:29 +08002712 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2713 /* 3DSTATE_CONSTANT_PS */
2714 cmd_batch_pointer(cmd, 5, &dw);
2715 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2716 dw[1] = 0;
2717 dw[2] = 0;
2718 dw[3] = 0;
2719 dw[4] = 0;
2720
2721 /* 3DSTATE_WM */
2722 cmd_batch_pointer(cmd, 9, &dw);
2723 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2724 dw[1] = 0;
2725 dw[2] = 0;
2726 dw[3] = 0;
2727 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002728 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002729 dw[6] = 0;
2730 dw[7] = 0;
2731 dw[8] = 0;
2732
Chia-I Wu3adf7212014-10-24 15:34:07 +08002733 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002734 }
2735
Chia-I Wu3adf7212014-10-24 15:34:07 +08002736 /* a normal color write */
2737 assert(meta->dst.valid && !sh->uses);
2738
Chia-I Wu6032b892014-10-17 14:47:18 +08002739 /* 3DSTATE_CONSTANT_PS */
2740 offset = gen6_meta_ps_constants(cmd);
2741 cmd_batch_pointer(cmd, 5, &dw);
2742 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2743 GEN6_PCB_ANY_DW0_PCB0_VALID;
2744 dw[1] = offset;
2745 dw[2] = 0;
2746 dw[3] = 0;
2747 dw[4] = 0;
2748
2749 /* 3DSTATE_WM */
2750 offset = emit_shader(cmd, sh);
2751 cmd_batch_pointer(cmd, 9, &dw);
2752 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2753 dw[1] = offset;
2754 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2755 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002756 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002757 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002758 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002759 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002760 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2761
Chia-I Wu6032b892014-10-17 14:47:18 +08002762 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2763 GEN6_WM_DW6_POSOFFSET_NONE |
2764 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2765 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2766 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2767 if (meta->samples > 1) {
2768 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2769 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2770 } else {
2771 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2772 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2773 }
2774 dw[7] = 0;
2775 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002776
2777 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002778}
2779
2780static void gen7_meta_ps(struct intel_cmd *cmd)
2781{
2782 const struct intel_cmd_meta *meta = cmd->bind.meta;
2783 const struct intel_pipeline_shader *sh =
2784 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2785 uint32_t offset, *dw;
2786
2787 CMD_ASSERT(cmd, 7, 7.5);
2788
Chia-I Wu29e6f502014-11-24 14:27:29 +08002789 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2790 /* 3DSTATE_WM */
2791 cmd_batch_pointer(cmd, 3, &dw);
2792 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2793 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2794
2795 /* 3DSTATE_CONSTANT_GS */
2796 cmd_batch_pointer(cmd, 7, &dw);
2797 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2798 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2799
2800 /* 3DSTATE_PS */
2801 cmd_batch_pointer(cmd, 8, &dw);
2802 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2803 dw[1] = 0;
2804 dw[2] = 0;
2805 dw[3] = 0;
2806 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002807 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002808 dw[5] = 0;
2809 dw[6] = 0;
2810 dw[7] = 0;
2811
Chia-I Wu3adf7212014-10-24 15:34:07 +08002812 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002813 }
2814
Chia-I Wu3adf7212014-10-24 15:34:07 +08002815 /* a normal color write */
2816 assert(meta->dst.valid && !sh->uses);
2817
Chia-I Wu6032b892014-10-17 14:47:18 +08002818 /* 3DSTATE_WM */
2819 cmd_batch_pointer(cmd, 3, &dw);
2820 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2821 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2822 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2823 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2824 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2825 dw[2] = 0;
2826
2827 /* 3DSTATE_CONSTANT_PS */
2828 offset = gen6_meta_ps_constants(cmd);
2829 cmd_batch_pointer(cmd, 7, &dw);
2830 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2831 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2832 dw[2] = 0;
2833 dw[3] = offset;
2834 dw[4] = 0;
2835 dw[5] = 0;
2836 dw[6] = 0;
2837
2838 /* 3DSTATE_PS */
2839 offset = emit_shader(cmd, sh);
2840 cmd_batch_pointer(cmd, 8, &dw);
2841 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2842 dw[1] = offset;
2843 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2844 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002845 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002846
2847 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2848 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002849 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2850
2851 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002852 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002853 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002854 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002855 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002856 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002857
2858 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2859 dw[6] = 0;
2860 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002861
2862 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002863}
2864
2865static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2866{
2867 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002868 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002869
2870 CMD_ASSERT(cmd, 6, 7.5);
2871
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002872 if (!ds) {
2873 /* all zeros */
2874 static const struct intel_ds_view null_ds;
2875 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002876 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002877
2878 cmd_wa_gen6_pre_ds_flush(cmd);
2879 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2880 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2881 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2882
2883 if (cmd_gen(cmd) >= INTEL_GEN(7))
2884 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2885 else
2886 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002887}
2888
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002889static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2890 const struct intel_pipeline *pipeline)
2891{
2892 cmd->bind.pipeline.graphics = pipeline;
2893}
2894
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002895static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2896 const struct intel_pipeline *pipeline)
2897{
2898 cmd->bind.pipeline.compute = pipeline;
2899}
2900
2901static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2902 const struct intel_pipeline_delta *delta)
2903{
2904 cmd->bind.pipeline.graphics_delta = delta;
2905}
2906
2907static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2908 const struct intel_pipeline_delta *delta)
2909{
2910 cmd->bind.pipeline.compute_delta = delta;
2911}
2912
2913static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2914 const struct intel_dset *dset,
2915 XGL_UINT slot_offset)
2916{
2917 cmd->bind.dset.graphics = dset;
2918 cmd->bind.dset.graphics_offset = slot_offset;
2919}
2920
2921static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2922 const struct intel_dset *dset,
2923 XGL_UINT slot_offset)
2924{
2925 cmd->bind.dset.compute = dset;
2926 cmd->bind.dset.compute_offset = slot_offset;
2927}
2928
2929static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2930 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2931{
2932 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2933}
2934
2935static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2936 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2937{
2938 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2939}
2940
Chia-I Wu3b04af52014-11-08 10:48:20 +08002941static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2942 const struct intel_mem *mem,
2943 XGL_GPU_SIZE offset, XGL_UINT binding)
2944{
2945 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2946 cmd->result = XGL_ERROR_UNKNOWN;
2947 return;
2948 }
2949
2950 cmd->bind.vertex.mem[binding] = mem;
2951 cmd->bind.vertex.offset[binding] = offset;
2952}
2953
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002954static void cmd_bind_index_data(struct intel_cmd *cmd,
2955 const struct intel_mem *mem,
2956 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2957{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002958 cmd->bind.index.mem = mem;
2959 cmd->bind.index.offset = offset;
2960 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002961}
2962
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002963static void cmd_bind_attachments(struct intel_cmd *cmd,
2964 XGL_UINT rt_count,
2965 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2966 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002967{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002968 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002969 XGL_UINT i;
2970
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002971 for (i = 0; i < rt_count; i++) {
2972 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002973 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002974 const struct intel_layout *layout = &rt->img->layout;
2975
2976 if (i == 0) {
2977 width = layout->width0;
2978 height = layout->height0;
2979 } else {
2980 if (width > layout->width0)
2981 width = layout->width0;
2982 if (height > layout->height0)
2983 height = layout->height0;
2984 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002985
2986 cmd->bind.att.rt[i] = rt;
2987 }
2988
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002989 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002990
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002991 if (ds_info) {
2992 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002993
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002994 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2995 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002996
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002997 if (width > layout->width0)
2998 width = layout->width0;
2999 if (height > layout->height0)
3000 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003001 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003002 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003003 }
3004
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003005 cmd->bind.att.width = width;
3006 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003007}
3008
3009static void cmd_bind_viewport_state(struct intel_cmd *cmd,
3010 const struct intel_viewport_state *state)
3011{
3012 cmd->bind.state.viewport = state;
3013}
3014
3015static void cmd_bind_raster_state(struct intel_cmd *cmd,
3016 const struct intel_raster_state *state)
3017{
3018 cmd->bind.state.raster = state;
3019}
3020
3021static void cmd_bind_ds_state(struct intel_cmd *cmd,
3022 const struct intel_ds_state *state)
3023{
3024 cmd->bind.state.ds = state;
3025}
3026
3027static void cmd_bind_blend_state(struct intel_cmd *cmd,
3028 const struct intel_blend_state *state)
3029{
3030 cmd->bind.state.blend = state;
3031}
3032
3033static void cmd_bind_msaa_state(struct intel_cmd *cmd,
3034 const struct intel_msaa_state *state)
3035{
3036 cmd->bind.state.msaa = state;
3037}
3038
3039static void cmd_draw(struct intel_cmd *cmd,
3040 XGL_UINT vertex_start,
3041 XGL_UINT vertex_count,
3042 XGL_UINT instance_start,
3043 XGL_UINT instance_count,
3044 bool indexed,
3045 XGL_UINT vertex_base)
3046{
3047 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
3048
3049 emit_bounded_states(cmd);
3050
3051 if (indexed) {
3052 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3053 cmd->result = XGL_ERROR_UNKNOWN;
3054
3055 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3056 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3057 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003058 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3059 cmd->bind.index.offset, cmd->bind.index.type,
3060 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003061 } else {
3062 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3063 cmd->bind.index.offset, cmd->bind.index.type,
3064 p->primitive_restart);
3065 }
3066 } else {
3067 assert(!vertex_base);
3068 }
3069
3070 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3071 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3072 vertex_start, instance_count, instance_start, vertex_base);
3073 } else {
3074 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3075 vertex_start, instance_count, instance_start, vertex_base);
3076 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003077
Chia-I Wu707a29e2014-08-27 12:51:47 +08003078 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003079 /* need to re-emit all workarounds */
3080 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003081
3082 if (intel_debug & INTEL_DEBUG_NOCACHE)
3083 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003084}
3085
Chia-I Wuc14d1562014-10-17 09:49:22 +08003086void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3087{
Chia-I Wu6032b892014-10-17 14:47:18 +08003088 cmd->bind.meta = meta;
3089
3090 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003091 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003092
3093 gen6_meta_dynamic_states(cmd);
3094 gen6_meta_surface_states(cmd);
3095
3096 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3097 gen7_meta_urb(cmd);
3098 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003099 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003100 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003101 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003102 gen6_meta_wm(cmd);
3103 gen7_meta_ps(cmd);
3104 gen6_meta_depth_buffer(cmd);
3105
3106 cmd_wa_gen7_post_command_cs_stall(cmd);
3107 cmd_wa_gen7_post_command_depth_stall(cmd);
3108
Chia-I Wu29e6f502014-11-24 14:27:29 +08003109 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3110 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003111 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003112 } else {
3113 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3114 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003115 } else {
3116 gen6_meta_urb(cmd);
3117 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003118 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003119 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003120 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003121 gen6_meta_wm(cmd);
3122 gen6_meta_ps(cmd);
3123 gen6_meta_depth_buffer(cmd);
3124
Chia-I Wu29e6f502014-11-24 14:27:29 +08003125 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3126 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003127 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003128 } else {
3129 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3130 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003131 }
3132
3133 cmd->bind.draw_count++;
3134 /* need to re-emit all workarounds */
3135 cmd->bind.wa_flags = 0;
3136
3137 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003138
3139 if (intel_debug & INTEL_DEBUG_NOCACHE)
3140 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003141}
3142
Chia-I Wu96177272015-01-03 15:27:41 +08003143ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003144 XGL_CMD_BUFFER cmdBuffer,
3145 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3146 XGL_PIPELINE pipeline)
3147{
3148 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3149
3150 switch (pipelineBindPoint) {
3151 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003152 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003153 break;
3154 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003155 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003156 break;
3157 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003158 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003159 break;
3160 }
3161}
3162
Chia-I Wu96177272015-01-03 15:27:41 +08003163ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003164 XGL_CMD_BUFFER cmdBuffer,
3165 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3166 XGL_PIPELINE_DELTA delta)
3167{
3168 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3169
3170 switch (pipelineBindPoint) {
3171 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003172 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003173 break;
3174 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003175 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003176 break;
3177 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003178 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003179 break;
3180 }
3181}
3182
Chia-I Wu96177272015-01-03 15:27:41 +08003183ICD_EXPORT XGL_VOID XGLAPI xglCmdBindStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003184 XGL_CMD_BUFFER cmdBuffer,
3185 XGL_STATE_BIND_POINT stateBindPoint,
3186 XGL_STATE_OBJECT state)
3187{
3188 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3189
3190 switch (stateBindPoint) {
3191 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003192 cmd_bind_viewport_state(cmd,
3193 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003194 break;
3195 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003196 cmd_bind_raster_state(cmd,
3197 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003198 break;
3199 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003200 cmd_bind_ds_state(cmd,
3201 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003202 break;
3203 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003204 cmd_bind_blend_state(cmd,
3205 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003206 break;
3207 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003208 cmd_bind_msaa_state(cmd,
3209 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003210 break;
3211 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003212 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003213 break;
3214 }
3215}
3216
Chia-I Wu96177272015-01-03 15:27:41 +08003217ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003218 XGL_CMD_BUFFER cmdBuffer,
3219 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3220 XGL_UINT index,
3221 XGL_DESCRIPTOR_SET descriptorSet,
3222 XGL_UINT slotOffset)
3223{
3224 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3225 struct intel_dset *dset = intel_dset(descriptorSet);
3226
3227 assert(!index);
3228
3229 switch (pipelineBindPoint) {
3230 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003231 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003232 break;
3233 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003234 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003235 break;
3236 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003237 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003238 break;
3239 }
3240}
3241
Chia-I Wu96177272015-01-03 15:27:41 +08003242ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicMemoryView(
Chia-I Wub2755562014-08-20 13:38:52 +08003243 XGL_CMD_BUFFER cmdBuffer,
3244 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3245 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3246{
3247 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3248
3249 switch (pipelineBindPoint) {
3250 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003251 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003252 break;
3253 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003254 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003255 break;
3256 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003257 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003258 break;
3259 }
3260}
3261
Chia-I Wu96177272015-01-03 15:27:41 +08003262ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexData(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003263 XGL_CMD_BUFFER cmdBuffer,
3264 XGL_GPU_MEMORY mem_,
3265 XGL_GPU_SIZE offset,
3266 XGL_UINT binding)
3267{
3268 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3269 struct intel_mem *mem = intel_mem(mem_);
3270
3271 cmd_bind_vertex_data(cmd, mem, offset, binding);
3272}
3273
Chia-I Wu96177272015-01-03 15:27:41 +08003274ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexData(
Chia-I Wub2755562014-08-20 13:38:52 +08003275 XGL_CMD_BUFFER cmdBuffer,
3276 XGL_GPU_MEMORY mem_,
3277 XGL_GPU_SIZE offset,
3278 XGL_INDEX_TYPE indexType)
3279{
3280 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3281 struct intel_mem *mem = intel_mem(mem_);
3282
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003283 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003284}
3285
Chia-I Wu96177272015-01-03 15:27:41 +08003286ICD_EXPORT XGL_VOID XGLAPI xglCmdBindAttachments(
Chia-I Wub2755562014-08-20 13:38:52 +08003287 XGL_CMD_BUFFER cmdBuffer,
3288 XGL_UINT colorAttachmentCount,
3289 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3290 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3291{
3292 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003293
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003294 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3295 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003296}
3297
Chia-I Wu96177272015-01-03 15:27:41 +08003298ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003299 XGL_CMD_BUFFER cmdBuffer,
3300 XGL_UINT firstVertex,
3301 XGL_UINT vertexCount,
3302 XGL_UINT firstInstance,
3303 XGL_UINT instanceCount)
3304{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003305 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003306
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003307 cmd_draw(cmd, firstVertex, vertexCount,
3308 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003309}
3310
Chia-I Wu96177272015-01-03 15:27:41 +08003311ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003312 XGL_CMD_BUFFER cmdBuffer,
3313 XGL_UINT firstIndex,
3314 XGL_UINT indexCount,
3315 XGL_INT vertexOffset,
3316 XGL_UINT firstInstance,
3317 XGL_UINT instanceCount)
3318{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003319 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003320
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003321 cmd_draw(cmd, firstIndex, indexCount,
3322 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003323}
3324
Chia-I Wu96177272015-01-03 15:27:41 +08003325ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003326 XGL_CMD_BUFFER cmdBuffer,
3327 XGL_GPU_MEMORY mem,
3328 XGL_GPU_SIZE offset,
3329 XGL_UINT32 count,
3330 XGL_UINT32 stride)
3331{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003332 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3333
3334 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003335}
3336
Chia-I Wu96177272015-01-03 15:27:41 +08003337ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003338 XGL_CMD_BUFFER cmdBuffer,
3339 XGL_GPU_MEMORY mem,
3340 XGL_GPU_SIZE offset,
3341 XGL_UINT32 count,
3342 XGL_UINT32 stride)
3343{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003344 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3345
3346 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003347}
3348
Chia-I Wu96177272015-01-03 15:27:41 +08003349ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003350 XGL_CMD_BUFFER cmdBuffer,
3351 XGL_UINT x,
3352 XGL_UINT y,
3353 XGL_UINT z)
3354{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003355 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3356
3357 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003358}
3359
Chia-I Wu96177272015-01-03 15:27:41 +08003360ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003361 XGL_CMD_BUFFER cmdBuffer,
3362 XGL_GPU_MEMORY mem,
3363 XGL_GPU_SIZE offset)
3364{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003365 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3366
3367 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003368}