blob: 4c02ebcdabc9c438cba1579d45237a4d31067d6d [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:
Courtney Goeltzenleuchterd65a16f2015-01-06 15:19:38 -0700403 assert(!cmd->bind.att.ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800404 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
Cody Northrope238deb2015-01-26 14:41:36 -0700595 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596 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
Cody Northrope238deb2015-01-26 14:41:36 -0700656 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
657
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800658 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);
Mike Stroyan214ad462015-01-15 11:27:12 -07001387 stencil_ref = ds->cmd_stencil_ref;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001388 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001389 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1390 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001391 } else {
1392 stencil_ref = 0;
1393 }
1394
Chia-I Wu72292b72014-09-09 10:48:33 +08001395 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001396 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001397 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001398}
1399
Chia-I Wu1744cca2014-08-22 11:10:17 +08001400static void gen7_viewport_states(struct intel_cmd *cmd)
1401{
1402 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001403 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001404
1405 if (!viewport)
1406 return;
1407
Chia-I Wub1d450a2014-09-09 13:48:03 +08001408 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1409 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001410
Chia-I Wub1d450a2014-09-09 13:48:03 +08001411 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001412 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001413 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001414 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001415 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1416 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001417
1418 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001419 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001420 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001421 gen7_3dstate_pointer(cmd,
1422 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001423 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001424
Chia-I Wu1744cca2014-08-22 11:10:17 +08001425 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001426 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001427 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001428 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001429 gen7_3dstate_pointer(cmd,
1430 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001431 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001432 }
1433}
1434
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001435static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001436 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001437{
1438 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001439 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001440
Chia-I Wu72292b72014-09-09 10:48:33 +08001441 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001442
1443 dw[0] = GEN6_RENDER_TYPE_RENDER |
1444 GEN6_RENDER_SUBTYPE_3D |
1445 subop | (cmd_len - 2);
1446 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001447 dw[2] = 0;
1448 dw[3] = 0;
1449 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001450}
1451
1452static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001453 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001454{
1455 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001456 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001457
Chia-I Wu72292b72014-09-09 10:48:33 +08001458 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001459
1460 dw[0] = GEN6_RENDER_TYPE_RENDER |
1461 GEN6_RENDER_SUBTYPE_3D |
1462 subop | (cmd_len - 2);
1463 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001464 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001465 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001466 dw[4] = 0;
1467 dw[5] = 0;
1468 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001469}
1470
Chia-I Wu625105f2014-10-13 15:35:29 +08001471static uint32_t emit_samplers(struct intel_cmd *cmd,
1472 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001473{
1474 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1475 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001476 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001477 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001478 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001479 XGL_UINT i;
1480
1481 CMD_ASSERT(cmd, 6, 7.5);
1482
Chia-I Wu625105f2014-10-13 15:35:29 +08001483 if (!rmap || !rmap->sampler_count)
1484 return 0;
1485
Cody Northrop40316a32014-12-09 19:08:33 -07001486 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001487
Chia-I Wudcb509d2014-12-10 08:53:10 +08001488 /*
1489 * note that we cannot call cmd_state_pointer() here as the following
1490 * cmd_state_pointer() would invalidate the pointer
1491 */
1492 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001493 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001494 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001495
1496 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001497 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001498 4 * rmap->sampler_count, &sampler_dw);
1499
Chia-I Wudcb509d2014-12-10 08:53:10 +08001500 cmd_state_update(cmd, border_offset,
1501 border_stride * rmap->sampler_count, &border_dw);
1502
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001503 for (i = 0; i < rmap->sampler_count; i++) {
1504 const struct intel_pipeline_rmap_slot *slot =
1505 &rmap->slots[surface_count + i];
1506 const struct intel_sampler *sampler;
1507
1508 switch (slot->path_len) {
1509 case 0:
1510 sampler = NULL;
1511 break;
1512 case INTEL_PIPELINE_RMAP_SLOT_RT:
1513 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1514 assert(!"unexpected rmap slot type");
1515 sampler = NULL;
1516 break;
1517 case 1:
1518 {
1519 const struct intel_dset *dset = cmd->bind.dset.graphics;
1520 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1521 const struct intel_dset_slot *dset_slot =
1522 &dset->slots[slot_offset + slot->u.index];
1523
1524 switch (dset_slot->type) {
1525 case INTEL_DSET_SLOT_SAMPLER:
1526 sampler = dset_slot->u.sampler;
1527 break;
1528 default:
1529 assert(!"unexpected dset slot type");
1530 sampler = NULL;
1531 break;
1532 }
1533 }
1534 break;
1535 default:
1536 assert(!"nested descriptor set unsupported");
1537 sampler = NULL;
1538 break;
1539 }
1540
1541 if (sampler) {
1542 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1543
1544 sampler_dw[0] = sampler->cmd[0];
1545 sampler_dw[1] = sampler->cmd[1];
1546 sampler_dw[2] = border_offset;
1547 sampler_dw[3] = sampler->cmd[2];
1548 } else {
1549 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1550 sampler_dw[1] = 0;
1551 sampler_dw[2] = 0;
1552 sampler_dw[3] = 0;
1553 }
1554
1555 border_offset += border_stride * 4;
1556 border_dw += border_stride;
1557 sampler_dw += 4;
1558 }
1559
Chia-I Wu625105f2014-10-13 15:35:29 +08001560 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001561}
1562
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001563static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001564 const struct intel_pipeline_rmap *rmap,
1565 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001566{
Chia-I Wu72292b72014-09-09 10:48:33 +08001567 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001568 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001569
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001570 CMD_ASSERT(cmd, 6, 7.5);
1571
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001572 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001573 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001574 if (!surface_count)
1575 return 0;
1576
Chia-I Wu42a56202014-08-23 16:47:48 +08001577 assert(surface_count <= ARRAY_SIZE(binding_table));
1578
1579 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001580 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001581
1582 switch (slot->path_len) {
1583 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001584 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001585 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001586 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001587 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001588 const struct intel_rt_view *view =
1589 (slot->u.index < cmd->bind.att.rt_count) ?
1590 cmd->bind.att.rt[slot->u.index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001591
Chia-I Wu787a05b2014-12-05 11:02:20 +08001592 if (view) {
1593 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1594 GEN6_ALIGNMENT_SURFACE_STATE,
1595 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001596
Chia-I Wu787a05b2014-12-05 11:02:20 +08001597 cmd_reserve_reloc(cmd, 1);
1598 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1599 view->cmd[1], INTEL_RELOC_WRITE);
1600 } else {
1601 struct intel_null_view null_view;
1602 intel_null_view_init(&null_view, cmd->dev);
1603
1604 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1605 GEN6_ALIGNMENT_SURFACE_STATE,
1606 null_view.cmd_len, null_view.cmd);
1607 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001608 }
1609 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001610 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001611 {
1612 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001613 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001614
Chia-I Wu00b51a82014-09-09 12:07:37 +08001615 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001616 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001617 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001618
Chia-I Wu72292b72014-09-09 10:48:33 +08001619 cmd_reserve_reloc(cmd, 1);
1620 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1621 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001622 }
1623 break;
1624 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001625 {
1626 const struct intel_dset *dset = cmd->bind.dset.graphics;
1627 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1628 const struct intel_dset_slot *dset_slot =
1629 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001630 const uint32_t reloc_flags =
1631 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001632
1633 switch (dset_slot->type) {
1634 case INTEL_DSET_SLOT_IMG_VIEW:
1635 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001636 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001637 dset_slot->u.img_view->cmd_len,
1638 dset_slot->u.img_view->cmd);
1639
1640 cmd_reserve_reloc(cmd, 1);
1641 cmd_surface_reloc(cmd, offset, 1,
1642 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001643 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001644 break;
1645 case INTEL_DSET_SLOT_MEM_VIEW:
Cody Northrop7c76f302014-12-18 11:52:58 -07001646 {
1647 XGL_MEMORY_VIEW_ATTACH_INFO tmp_info = dset_slot->u.mem_view.info;
1648 struct intel_mem_view tmp;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001649
Cody Northrop7c76f302014-12-18 11:52:58 -07001650 memset(&tmp, 0, sizeof(tmp));
1651
1652 /* The compiler expects uniform buffers to have pitch of
1653 * 4 for fragment shaders, but 16 for other stages.
1654 */
Cody Northropbef0e552015-01-13 12:13:46 -07001655 tmp_info.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
1656 tmp_info.format.numericFormat = XGL_NUM_FMT_FLOAT;
Cody Northrop7c76f302014-12-18 11:52:58 -07001657 if (XGL_SHADER_STAGE_FRAGMENT == stage) {
1658 tmp_info.stride = 4;
1659 } else {
1660 tmp_info.stride = 16;
1661 }
1662
1663 intel_mem_view_init(&tmp, cmd->dev, &tmp_info);
1664
1665 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1666 GEN6_ALIGNMENT_SURFACE_STATE,
1667 tmp.cmd_len,
1668 tmp.cmd);
1669
1670 cmd_reserve_reloc(cmd, 1);
1671 cmd_surface_reloc(cmd, offset, 1,
1672 dset_slot->u.mem_view.mem->bo,
1673 tmp.cmd[1], reloc_flags);
1674 }
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001675 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001676 case INTEL_DSET_SLOT_SAMPLER:
1677 assert(0 == cmd->bind.dset.graphics_offset);
1678
1679 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001680 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001681 16, dset_slot->u.sampler->cmd);
1682 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001683 default:
1684 assert(!"unexpected dset slot type");
1685 break;
1686 }
1687 }
1688 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001689 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001690 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001691 break;
1692 }
1693
Chia-I Wu72292b72014-09-09 10:48:33 +08001694 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001695 }
1696
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001697 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001698 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001699 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001700}
1701
Chia-I Wu1d125092014-10-08 08:49:38 +08001702static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1703{
1704 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001705 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1706 uint32_t *dw;
1707 XGL_UINT pos, i;
1708
1709 CMD_ASSERT(cmd, 6, 7.5);
1710
1711 if (!pipeline->vb_count)
1712 return;
1713
1714 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1715
1716 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1717 dw++;
1718 pos++;
1719
1720 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001721 assert(pipeline->vb[i].strideInBytes <= 2048);
1722
1723 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1724 pipeline->vb[i].strideInBytes;
1725
1726 if (cmd_gen(cmd) >= INTEL_GEN(7))
1727 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1728
1729 switch (pipeline->vb[i].stepRate) {
1730 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1731 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1732 dw[3] = 0;
1733 break;
1734 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1735 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1736 dw[3] = 1;
1737 break;
1738 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1739 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1740 dw[3] = 0;
1741 break;
1742 default:
1743 assert(!"unknown step rate");
1744 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1745 dw[3] = 0;
1746 break;
1747 }
1748
Chia-I Wu3b04af52014-11-08 10:48:20 +08001749 if (cmd->bind.vertex.mem[i]) {
1750 const struct intel_mem *mem = cmd->bind.vertex.mem[i];
1751 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001752
1753 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3b04af52014-11-08 10:48:20 +08001754 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
1755 cmd_batch_reloc(cmd, pos + 2, mem->bo, mem->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001756 } else {
1757 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1758 dw[1] = 0;
1759 dw[2] = 0;
1760 }
1761
1762 dw += 4;
1763 pos += 4;
1764 }
1765}
1766
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001767static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1768{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001769 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1770 const struct intel_pipeline_shader *vs = &pipeline->vs;
1771 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001772 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001773 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001774 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001775 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001776
1777 CMD_ASSERT(cmd, 6, 7.5);
1778
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001779 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001780 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1781 *
1782 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1783 * 128-bit vertex elements to be passed into the payload for each
1784 * vertex."
1785 *
1786 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1787 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001788 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001789 vue_read_len = (vs->in_count + 1) / 2;
1790 if (!vue_read_len)
1791 vue_read_len = 1;
1792
1793 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1794 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1795
1796 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1797 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1798 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001799
1800 dw5 = GEN6_VS_DW5_STATISTICS |
1801 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001802
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001803 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001804 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001805 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001806 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001807
Chia-I Wube0a3d92014-09-02 13:20:59 +08001808 if (pipeline->disable_vs_cache)
1809 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1810
Chia-I Wu784d3042014-12-19 14:30:04 +08001811 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001812 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001813 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001814 dw[2] = dw2;
1815 dw[3] = 0; /* scratch */
1816 dw[4] = dw4;
1817 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001818
1819 if (vs->per_thread_scratch_size)
1820 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001821}
1822
Chia-I Wu625105f2014-10-13 15:35:29 +08001823static void emit_shader_resources(struct intel_cmd *cmd)
1824{
1825 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001826 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001827
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001828 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001829 cmd->bind.pipeline.graphics->vs.rmap,
1830 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001831 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001832 cmd->bind.pipeline.graphics->tcs.rmap,
1833 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001834 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001835 cmd->bind.pipeline.graphics->tes.rmap,
1836 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001837 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001838 cmd->bind.pipeline.graphics->gs.rmap,
1839 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001840 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001841 cmd->bind.pipeline.graphics->fs.rmap,
1842 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001843
1844 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1845 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1846 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1847 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1848 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1849
1850 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1851 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001852 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1853 binding_tables[0]);
1854 gen7_3dstate_pointer(cmd,
1855 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1856 binding_tables[1]);
1857 gen7_3dstate_pointer(cmd,
1858 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1859 binding_tables[2]);
1860 gen7_3dstate_pointer(cmd,
1861 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1862 binding_tables[3]);
1863 gen7_3dstate_pointer(cmd,
1864 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1865 binding_tables[4]);
1866
1867 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001868 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1869 samplers[0]);
1870 gen7_3dstate_pointer(cmd,
1871 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1872 samplers[1]);
1873 gen7_3dstate_pointer(cmd,
1874 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1875 samplers[2]);
1876 gen7_3dstate_pointer(cmd,
1877 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1878 samplers[3]);
1879 gen7_3dstate_pointer(cmd,
1880 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1881 samplers[4]);
1882 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001883 assert(!binding_tables[1] && !binding_tables[2]);
1884 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1885 binding_tables[0], binding_tables[3], binding_tables[4]);
1886
Chia-I Wu625105f2014-10-13 15:35:29 +08001887 assert(!samplers[1] && !samplers[2]);
1888 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1889 samplers[0], samplers[3], samplers[4]);
1890 }
1891}
1892
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001893static void emit_rt(struct intel_cmd *cmd)
1894{
1895 cmd_wa_gen6_pre_depth_stall_write(cmd);
1896 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1897 cmd->bind.att.height);
1898}
1899
1900static void emit_ds(struct intel_cmd *cmd)
1901{
1902 const struct intel_ds_view *ds = cmd->bind.att.ds;
1903
1904 if (!ds) {
1905 /* all zeros */
1906 static const struct intel_ds_view null_ds;
1907 ds = &null_ds;
1908 }
1909
1910 cmd_wa_gen6_pre_ds_flush(cmd);
1911 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1912 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1913 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1914
1915 if (cmd_gen(cmd) >= INTEL_GEN(7))
1916 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1917 else
1918 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1919}
1920
Chia-I Wua57761b2014-10-14 14:27:44 +08001921static uint32_t emit_shader(struct intel_cmd *cmd,
1922 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001923{
Chia-I Wua57761b2014-10-14 14:27:44 +08001924 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1925 uint32_t offset;
1926 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001927
Chia-I Wua57761b2014-10-14 14:27:44 +08001928 /* see if the shader is already in the cache */
1929 for (i = 0; i < cache->used; i++) {
1930 if (cache->entries[i].shader == (const void *) shader)
1931 return cache->entries[i].kernel_offset;
1932 }
1933
1934 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1935
1936 /* grow the cache if full */
1937 if (cache->used >= cache->count) {
1938 const XGL_UINT count = cache->count + 16;
1939 void *entries;
1940
1941 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1942 XGL_SYSTEM_ALLOC_INTERNAL);
1943 if (entries) {
1944 if (cache->entries) {
1945 memcpy(entries, cache->entries,
1946 sizeof(cache->entries[0]) * cache->used);
1947 icd_free(cache->entries);
1948 }
1949
1950 cache->entries = entries;
1951 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001952 }
1953 }
1954
Chia-I Wua57761b2014-10-14 14:27:44 +08001955 /* add the shader to the cache */
1956 if (cache->used < cache->count) {
1957 cache->entries[cache->used].shader = (const void *) shader;
1958 cache->entries[cache->used].kernel_offset = offset;
1959 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001960 }
1961
Chia-I Wua57761b2014-10-14 14:27:44 +08001962 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001963}
1964
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001965static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001966{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001967 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001968
Chia-I Wu8370b402014-08-29 12:28:37 +08001969 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1970 cmd_wa_gen6_pre_depth_stall_write(cmd);
1971 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1972 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1973 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1974 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001975
1976 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001977 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001978 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001979
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001980 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001981 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001982 }
1983 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001984 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001985 }
1986 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001987 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1988 }
1989 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1990 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1991 }
1992 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1993 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001994 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001995
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001996 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1997 gen7_3DSTATE_GS(cmd);
1998 } else {
1999 gen6_3DSTATE_GS(cmd);
2000 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002001
Chia-I Wu8370b402014-08-29 12:28:37 +08002002 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2003 cmd_wa_gen7_post_command_cs_stall(cmd);
2004 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2005 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002006}
2007
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002008static void emit_bounded_states(struct intel_cmd *cmd)
2009{
2010 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
2011
2012 emit_graphics_pipeline(cmd);
2013
2014 emit_rt(cmd);
2015 emit_ds(cmd);
2016
2017 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2018 gen7_cc_states(cmd);
2019 gen7_viewport_states(cmd);
2020
2021 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2022 &cmd->bind.pipeline.graphics->vs);
2023 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2024 &cmd->bind.pipeline.graphics->fs);
2025
2026 gen6_3DSTATE_CLIP(cmd);
2027 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002028 gen7_3DSTATE_WM(cmd);
2029 gen7_3DSTATE_PS(cmd);
2030 } else {
2031 gen6_cc_states(cmd);
2032 gen6_viewport_states(cmd);
2033
2034 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2035 &cmd->bind.pipeline.graphics->vs);
2036 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2037 &cmd->bind.pipeline.graphics->fs);
2038
2039 gen6_3DSTATE_CLIP(cmd);
2040 gen6_3DSTATE_SF(cmd);
2041 gen6_3DSTATE_WM(cmd);
2042 }
2043
2044 emit_shader_resources(cmd);
2045
2046 cmd_wa_gen6_pre_depth_stall_write(cmd);
2047 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2048
2049 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2050 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2051
2052 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2053 gen6_3DSTATE_VS(cmd);
2054}
2055
Chia-I Wu6032b892014-10-17 14:47:18 +08002056static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2057{
2058 const struct intel_cmd_meta *meta = cmd->bind.meta;
2059 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2060
2061 CMD_ASSERT(cmd, 6, 7.5);
2062
2063 blend_offset = 0;
2064 ds_offset = 0;
2065 cc_offset = 0;
2066 cc_vp_offset = 0;
2067
Chia-I Wu29e6f502014-11-24 14:27:29 +08002068 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002069 /* BLEND_STATE */
2070 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002071 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002072 dw[0] = 0;
2073 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2074 }
2075
Chia-I Wu29e6f502014-11-24 14:27:29 +08002076 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2077 if (meta->ds.state) {
2078 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002079
Chia-I Wu29e6f502014-11-24 14:27:29 +08002080 /* DEPTH_STENCIL_STATE */
2081 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002082
Chia-I Wu29e6f502014-11-24 14:27:29 +08002083 /* COLOR_CALC_STATE */
2084 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2085 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002086
Chia-I Wu29e6f502014-11-24 14:27:29 +08002087 /* CC_VIEWPORT */
2088 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002089 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002090 dw[0] = u_fui(0.0f);
2091 dw[1] = u_fui(1.0f);
2092 } else {
2093 /* DEPTH_STENCIL_STATE */
2094 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002095 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002096 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2097 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2098 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002099 }
2100
2101 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2102 gen7_3dstate_pointer(cmd,
2103 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2104 blend_offset);
2105 gen7_3dstate_pointer(cmd,
2106 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2107 ds_offset);
2108 gen7_3dstate_pointer(cmd,
2109 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2110
2111 gen7_3dstate_pointer(cmd,
2112 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2113 cc_vp_offset);
2114 } else {
2115 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002116 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002117
2118 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2119 cmd_batch_pointer(cmd, 4, &dw);
2120 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2121 GEN6_PTR_VP_DW0_CC_CHANGED;
2122 dw[1] = 0;
2123 dw[2] = 0;
2124 dw[3] = cc_vp_offset;
2125 }
2126}
2127
2128static void gen6_meta_surface_states(struct intel_cmd *cmd)
2129{
2130 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002131 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002132 uint32_t offset;
2133
2134 CMD_ASSERT(cmd, 6, 7.5);
2135
Chia-I Wu29e6f502014-11-24 14:27:29 +08002136 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2137 return;
2138
Chia-I Wu005c47c2014-10-22 13:49:13 +08002139 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002140 if (meta->src.valid) {
2141 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002142 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002143 meta->src.surface_len, meta->src.surface);
2144
2145 cmd_reserve_reloc(cmd, 1);
2146 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2147 cmd_surface_reloc_writer(cmd, offset, 1,
2148 meta->src.reloc_target, meta->src.reloc_offset);
2149 } else {
2150 cmd_surface_reloc(cmd, offset, 1,
2151 (struct intel_bo *) meta->src.reloc_target,
2152 meta->src.reloc_offset, meta->src.reloc_flags);
2153 }
2154
Chia-I Wu005c47c2014-10-22 13:49:13 +08002155 binding_table[0] = offset;
2156 }
2157 if (meta->dst.valid) {
2158 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002159 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002160 meta->dst.surface_len, meta->dst.surface);
2161
2162 cmd_reserve_reloc(cmd, 1);
2163 cmd_surface_reloc(cmd, offset, 1,
2164 (struct intel_bo *) meta->dst.reloc_target,
2165 meta->dst.reloc_offset, meta->dst.reloc_flags);
2166
2167 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002168 }
2169
2170 /* BINDING_TABLE */
2171 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002172 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002173 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002174
2175 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002176 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2177 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2178 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2179 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002180 } else {
2181 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002182 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2183 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2184 else
2185 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002186 }
2187}
2188
2189static void gen6_meta_urb(struct intel_cmd *cmd)
2190{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002191 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002192 uint32_t *dw;
2193
2194 CMD_ASSERT(cmd, 6, 6);
2195
2196 /* 3DSTATE_URB */
2197 cmd_batch_pointer(cmd, 3, &dw);
2198 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002199 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002200 dw[2] = 0;
2201}
2202
2203static void gen7_meta_urb(struct intel_cmd *cmd)
2204{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002205 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002206 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002207 uint32_t *dw;
2208
2209 CMD_ASSERT(cmd, 7, 7.5);
2210
2211 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2212 cmd_batch_pointer(cmd, 10, &dw);
2213
2214 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002215 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002216 dw += 2;
2217
2218 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2219 dw[1] = 0;
2220 dw += 2;
2221
2222 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2223 dw[1] = 0;
2224 dw += 2;
2225
2226 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2227 dw[1] = 0;
2228 dw += 2;
2229
2230 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002231 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002232
2233 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2234
Chia-I Wu24aa1022014-11-25 11:53:19 +08002235 switch (cmd_gen(cmd)) {
2236 case INTEL_GEN(7.5):
2237 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2238 break;
2239 case INTEL_GEN(7):
2240 default:
2241 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2242 break;
2243 }
2244
Chia-I Wu6032b892014-10-17 14:47:18 +08002245 /* 3DSTATE_URB_x */
2246 cmd_batch_pointer(cmd, 8, &dw);
2247
2248 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2249 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002250 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002251 dw += 2;
2252
2253 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2254 dw[1] = 0;
2255 dw += 2;
2256
2257 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2258 dw[1] = 0;
2259 dw += 2;
2260
2261 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2262 dw[1] = 0;
2263 dw += 2;
2264}
2265
2266static void gen6_meta_vf(struct intel_cmd *cmd)
2267{
2268 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002269 uint32_t vb_start, vb_end, vb_stride;
2270 int ve_format, ve_z_source;
2271 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002272 XGL_UINT pos;
2273
2274 CMD_ASSERT(cmd, 6, 7.5);
2275
Chia-I Wu29e6f502014-11-24 14:27:29 +08002276 switch (meta->mode) {
2277 case INTEL_CMD_META_VS_POINTS:
2278 cmd_batch_pointer(cmd, 3, &dw);
2279 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2280 dw[1] = GEN6_VE_STATE_DW0_VALID;
2281 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2282 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2283 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2284 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2285 return;
2286 break;
2287 case INTEL_CMD_META_FS_RECT:
2288 {
2289 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002290
Chia-I Wu29e6f502014-11-24 14:27:29 +08002291 vertices[0][0] = meta->dst.x + meta->width;
2292 vertices[0][1] = meta->dst.y + meta->height;
2293 vertices[1][0] = meta->dst.x;
2294 vertices[1][1] = meta->dst.y + meta->height;
2295 vertices[2][0] = meta->dst.x;
2296 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002297
Chia-I Wu29e6f502014-11-24 14:27:29 +08002298 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2299 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002300
Chia-I Wu29e6f502014-11-24 14:27:29 +08002301 vb_end = vb_start + sizeof(vertices) - 1;
2302 vb_stride = sizeof(vertices[0]);
2303 ve_z_source = GEN6_VFCOMP_STORE_0;
2304 ve_format = GEN6_FORMAT_R32G32_USCALED;
2305 }
2306 break;
2307 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2308 {
2309 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002310
Chia-I Wu29e6f502014-11-24 14:27:29 +08002311 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2312 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2313 vertices[0][2] = u_uif(meta->clear_val[0]);
2314 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2315 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2316 vertices[1][2] = u_uif(meta->clear_val[0]);
2317 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2318 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2319 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002320
Chia-I Wu29e6f502014-11-24 14:27:29 +08002321 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2322 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002323
Chia-I Wu29e6f502014-11-24 14:27:29 +08002324 vb_end = vb_start + sizeof(vertices) - 1;
2325 vb_stride = sizeof(vertices[0]);
2326 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2327 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2328 }
2329 break;
2330 default:
2331 assert(!"unknown meta mode");
2332 return;
2333 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002334 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002335
2336 /* 3DSTATE_VERTEX_BUFFERS */
2337 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002338
Chia-I Wu6032b892014-10-17 14:47:18 +08002339 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002340 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002341 if (cmd_gen(cmd) >= INTEL_GEN(7))
2342 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2343
2344 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002345 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2346 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002347
2348 dw[4] = 0;
2349
2350 /* 3DSTATE_VERTEX_ELEMENTS */
2351 cmd_batch_pointer(cmd, 5, &dw);
2352 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002353 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002354 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2355 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2356 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2357 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2358 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002359 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002360 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2361 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002362 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002363 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2364}
2365
Chia-I Wu29e6f502014-11-24 14:27:29 +08002366static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002367{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002368 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002369 /* one GPR */
2370 XGL_UINT consts[8];
2371 XGL_UINT const_count;
2372
2373 CMD_ASSERT(cmd, 6, 7.5);
2374
2375 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002376 case INTEL_DEV_META_VS_FILL_MEM:
2377 consts[0] = meta->dst.x;
2378 consts[1] = meta->clear_val[0];
2379 const_count = 2;
2380 break;
2381 case INTEL_DEV_META_VS_COPY_MEM:
2382 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2383 consts[0] = meta->dst.x;
2384 consts[1] = meta->src.x;
2385 const_count = 2;
2386 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002387 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2388 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2389 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2390 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2391 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2392 consts[0] = meta->src.x;
2393 consts[1] = meta->src.y;
2394 consts[2] = meta->width;
2395 consts[3] = meta->dst.x;
2396 const_count = 4;
2397 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002398 default:
2399 assert(!"unknown meta shader id");
2400 const_count = 0;
2401 break;
2402 }
2403
2404 /* this can be skipped but it makes state dumping prettier */
2405 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2406
2407 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2408}
2409
2410static void gen6_meta_vs(struct intel_cmd *cmd)
2411{
2412 const struct intel_cmd_meta *meta = cmd->bind.meta;
2413 const struct intel_pipeline_shader *sh =
2414 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2415 uint32_t offset, *dw;
2416
2417 CMD_ASSERT(cmd, 6, 7.5);
2418
2419 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2420 XGL_UINT cmd_len;
2421
2422 /* 3DSTATE_CONSTANT_VS */
2423 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2424 cmd_batch_pointer(cmd, cmd_len, &dw);
2425 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2426 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2427
2428 /* 3DSTATE_VS */
2429 cmd_batch_pointer(cmd, 6, &dw);
2430 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2431 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2432
2433 return;
2434 }
2435
2436 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2437
2438 /* 3DSTATE_CONSTANT_VS */
2439 offset = gen6_meta_vs_constants(cmd);
2440 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2441 cmd_batch_pointer(cmd, 7, &dw);
2442 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2443 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2444 dw[2] = 0;
2445 dw[3] = offset;
2446 dw[4] = 0;
2447 dw[5] = 0;
2448 dw[6] = 0;
2449 } else {
2450 cmd_batch_pointer(cmd, 5, &dw);
2451 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2452 GEN6_PCB_ANY_DW0_PCB0_VALID;
2453 dw[1] = offset;
2454 dw[2] = 0;
2455 dw[3] = 0;
2456 dw[4] = 0;
2457 }
2458
2459 /* 3DSTATE_VS */
2460 offset = emit_shader(cmd, sh);
2461 cmd_batch_pointer(cmd, 6, &dw);
2462 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2463 dw[1] = offset;
2464 dw[2] = GEN6_THREADDISP_SPF |
2465 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2466 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002467 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002468 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2469 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2470
2471 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2472 GEN6_VS_DW5_VS_ENABLE;
2473 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002474 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002475 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002476 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002477
2478 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002479}
2480
2481static void gen6_meta_disabled(struct intel_cmd *cmd)
2482{
Chia-I Wu6032b892014-10-17 14:47:18 +08002483 uint32_t *dw;
2484
2485 CMD_ASSERT(cmd, 6, 6);
2486
Chia-I Wu6032b892014-10-17 14:47:18 +08002487 /* 3DSTATE_CONSTANT_GS */
2488 cmd_batch_pointer(cmd, 5, &dw);
2489 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2490 dw[1] = 0;
2491 dw[2] = 0;
2492 dw[3] = 0;
2493 dw[4] = 0;
2494
2495 /* 3DSTATE_GS */
2496 cmd_batch_pointer(cmd, 7, &dw);
2497 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2498 dw[1] = 0;
2499 dw[2] = 0;
2500 dw[3] = 0;
2501 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2502 dw[5] = GEN6_GS_DW5_STATISTICS;
2503 dw[6] = 0;
2504
Chia-I Wu6032b892014-10-17 14:47:18 +08002505 /* 3DSTATE_SF */
2506 cmd_batch_pointer(cmd, 20, &dw);
2507 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2508 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2509 memset(&dw[2], 0, 18 * sizeof(*dw));
2510}
2511
2512static void gen7_meta_disabled(struct intel_cmd *cmd)
2513{
2514 uint32_t *dw;
2515
2516 CMD_ASSERT(cmd, 7, 7.5);
2517
Chia-I Wu6032b892014-10-17 14:47:18 +08002518 /* 3DSTATE_CONSTANT_HS */
2519 cmd_batch_pointer(cmd, 7, &dw);
2520 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2521 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2522
2523 /* 3DSTATE_HS */
2524 cmd_batch_pointer(cmd, 7, &dw);
2525 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2526 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2527
2528 /* 3DSTATE_TE */
2529 cmd_batch_pointer(cmd, 4, &dw);
2530 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2531 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2532
2533 /* 3DSTATE_CONSTANT_DS */
2534 cmd_batch_pointer(cmd, 7, &dw);
2535 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2536 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2537
2538 /* 3DSTATE_DS */
2539 cmd_batch_pointer(cmd, 6, &dw);
2540 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2541 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2542
2543 /* 3DSTATE_CONSTANT_GS */
2544 cmd_batch_pointer(cmd, 7, &dw);
2545 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2546 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2547
2548 /* 3DSTATE_GS */
2549 cmd_batch_pointer(cmd, 7, &dw);
2550 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2551 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2552
2553 /* 3DSTATE_STREAMOUT */
2554 cmd_batch_pointer(cmd, 3, &dw);
2555 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2556 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2557
Chia-I Wu6032b892014-10-17 14:47:18 +08002558 /* 3DSTATE_SF */
2559 cmd_batch_pointer(cmd, 7, &dw);
2560 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2561 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2562
2563 /* 3DSTATE_SBE */
2564 cmd_batch_pointer(cmd, 14, &dw);
2565 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2566 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2567 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002568}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002569
Chia-I Wu29e6f502014-11-24 14:27:29 +08002570static void gen6_meta_clip(struct intel_cmd *cmd)
2571{
2572 const struct intel_cmd_meta *meta = cmd->bind.meta;
2573 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002574
Chia-I Wu29e6f502014-11-24 14:27:29 +08002575 /* 3DSTATE_CLIP */
2576 cmd_batch_pointer(cmd, 4, &dw);
2577 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2578 dw[1] = 0;
2579 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2580 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2581 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2582 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002583 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002584 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002585 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002586}
2587
2588static void gen6_meta_wm(struct intel_cmd *cmd)
2589{
2590 const struct intel_cmd_meta *meta = cmd->bind.meta;
2591 uint32_t *dw;
2592
2593 CMD_ASSERT(cmd, 6, 7.5);
2594
2595 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2596
2597 /* 3DSTATE_MULTISAMPLE */
2598 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2599 cmd_batch_pointer(cmd, 4, &dw);
2600 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2601 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2602 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2603 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2604 dw[2] = 0;
2605 dw[3] = 0;
2606 } else {
2607 cmd_batch_pointer(cmd, 3, &dw);
2608 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2609 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2610 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2611 dw[2] = 0;
2612 }
2613
2614 /* 3DSTATE_SAMPLE_MASK */
2615 cmd_batch_pointer(cmd, 2, &dw);
2616 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2617 dw[1] = (1 << meta->samples) - 1;
2618
2619 /* 3DSTATE_DRAWING_RECTANGLE */
2620 cmd_batch_pointer(cmd, 4, &dw);
2621 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2622 dw[1] = meta->dst.y << 16 | meta->dst.x;
2623 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2624 (meta->dst.x + meta->width - 1);
2625 dw[3] = 0;
2626}
2627
2628static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2629{
2630 const struct intel_cmd_meta *meta = cmd->bind.meta;
2631 XGL_UINT offset_x, offset_y;
2632 /* one GPR */
2633 XGL_UINT consts[8];
2634 XGL_UINT const_count;
2635
2636 CMD_ASSERT(cmd, 6, 7.5);
2637
2638 /* underflow is fine here */
2639 offset_x = meta->src.x - meta->dst.x;
2640 offset_y = meta->src.y - meta->dst.y;
2641
2642 switch (meta->shader_id) {
2643 case INTEL_DEV_META_FS_COPY_MEM:
2644 case INTEL_DEV_META_FS_COPY_1D:
2645 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2646 case INTEL_DEV_META_FS_COPY_2D:
2647 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2648 case INTEL_DEV_META_FS_COPY_2D_MS:
2649 consts[0] = offset_x;
2650 consts[1] = offset_y;
2651 consts[2] = meta->src.layer;
2652 consts[3] = meta->src.lod;
2653 const_count = 4;
2654 break;
2655 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2656 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2657 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2658 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2659 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2660 consts[0] = offset_x;
2661 consts[1] = offset_y;
2662 consts[2] = meta->src.layer;
2663 consts[3] = meta->src.lod;
2664 consts[4] = meta->src.x;
2665 consts[5] = meta->width;
2666 const_count = 6;
2667 break;
2668 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2669 consts[0] = offset_x;
2670 consts[1] = offset_y;
2671 consts[2] = meta->width;
2672 const_count = 3;
2673 break;
2674 case INTEL_DEV_META_FS_CLEAR_COLOR:
2675 consts[0] = meta->clear_val[0];
2676 consts[1] = meta->clear_val[1];
2677 consts[2] = meta->clear_val[2];
2678 consts[3] = meta->clear_val[3];
2679 const_count = 4;
2680 break;
2681 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2682 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002683 consts[1] = meta->clear_val[1];
2684 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002685 break;
2686 case INTEL_DEV_META_FS_RESOLVE_2X:
2687 case INTEL_DEV_META_FS_RESOLVE_4X:
2688 case INTEL_DEV_META_FS_RESOLVE_8X:
2689 case INTEL_DEV_META_FS_RESOLVE_16X:
2690 consts[0] = offset_x;
2691 consts[1] = offset_y;
2692 const_count = 2;
2693 break;
2694 default:
2695 assert(!"unknown meta shader id");
2696 const_count = 0;
2697 break;
2698 }
2699
2700 /* this can be skipped but it makes state dumping prettier */
2701 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2702
2703 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2704}
2705
2706static void gen6_meta_ps(struct intel_cmd *cmd)
2707{
2708 const struct intel_cmd_meta *meta = cmd->bind.meta;
2709 const struct intel_pipeline_shader *sh =
2710 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2711 uint32_t offset, *dw;
2712
2713 CMD_ASSERT(cmd, 6, 6);
2714
Chia-I Wu29e6f502014-11-24 14:27:29 +08002715 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2716 /* 3DSTATE_CONSTANT_PS */
2717 cmd_batch_pointer(cmd, 5, &dw);
2718 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2719 dw[1] = 0;
2720 dw[2] = 0;
2721 dw[3] = 0;
2722 dw[4] = 0;
2723
2724 /* 3DSTATE_WM */
2725 cmd_batch_pointer(cmd, 9, &dw);
2726 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2727 dw[1] = 0;
2728 dw[2] = 0;
2729 dw[3] = 0;
2730 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002731 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002732 dw[6] = 0;
2733 dw[7] = 0;
2734 dw[8] = 0;
2735
Chia-I Wu3adf7212014-10-24 15:34:07 +08002736 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002737 }
2738
Chia-I Wu3adf7212014-10-24 15:34:07 +08002739 /* a normal color write */
2740 assert(meta->dst.valid && !sh->uses);
2741
Chia-I Wu6032b892014-10-17 14:47:18 +08002742 /* 3DSTATE_CONSTANT_PS */
2743 offset = gen6_meta_ps_constants(cmd);
2744 cmd_batch_pointer(cmd, 5, &dw);
2745 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2746 GEN6_PCB_ANY_DW0_PCB0_VALID;
2747 dw[1] = offset;
2748 dw[2] = 0;
2749 dw[3] = 0;
2750 dw[4] = 0;
2751
2752 /* 3DSTATE_WM */
2753 offset = emit_shader(cmd, sh);
2754 cmd_batch_pointer(cmd, 9, &dw);
2755 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2756 dw[1] = offset;
2757 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2758 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002759 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002760 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002761 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002762 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002763 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2764
Chia-I Wu6032b892014-10-17 14:47:18 +08002765 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2766 GEN6_WM_DW6_POSOFFSET_NONE |
2767 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2768 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2769 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2770 if (meta->samples > 1) {
2771 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2772 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2773 } else {
2774 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2775 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2776 }
2777 dw[7] = 0;
2778 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002779
2780 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002781}
2782
2783static void gen7_meta_ps(struct intel_cmd *cmd)
2784{
2785 const struct intel_cmd_meta *meta = cmd->bind.meta;
2786 const struct intel_pipeline_shader *sh =
2787 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2788 uint32_t offset, *dw;
2789
2790 CMD_ASSERT(cmd, 7, 7.5);
2791
Chia-I Wu29e6f502014-11-24 14:27:29 +08002792 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2793 /* 3DSTATE_WM */
2794 cmd_batch_pointer(cmd, 3, &dw);
2795 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2796 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2797
2798 /* 3DSTATE_CONSTANT_GS */
2799 cmd_batch_pointer(cmd, 7, &dw);
2800 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2801 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2802
2803 /* 3DSTATE_PS */
2804 cmd_batch_pointer(cmd, 8, &dw);
2805 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2806 dw[1] = 0;
2807 dw[2] = 0;
2808 dw[3] = 0;
2809 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002810 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002811 dw[5] = 0;
2812 dw[6] = 0;
2813 dw[7] = 0;
2814
Chia-I Wu3adf7212014-10-24 15:34:07 +08002815 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002816 }
2817
Chia-I Wu3adf7212014-10-24 15:34:07 +08002818 /* a normal color write */
2819 assert(meta->dst.valid && !sh->uses);
2820
Chia-I Wu6032b892014-10-17 14:47:18 +08002821 /* 3DSTATE_WM */
2822 cmd_batch_pointer(cmd, 3, &dw);
2823 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2824 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2825 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2826 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2827 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2828 dw[2] = 0;
2829
2830 /* 3DSTATE_CONSTANT_PS */
2831 offset = gen6_meta_ps_constants(cmd);
2832 cmd_batch_pointer(cmd, 7, &dw);
2833 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2834 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2835 dw[2] = 0;
2836 dw[3] = offset;
2837 dw[4] = 0;
2838 dw[5] = 0;
2839 dw[6] = 0;
2840
2841 /* 3DSTATE_PS */
2842 offset = emit_shader(cmd, sh);
2843 cmd_batch_pointer(cmd, 8, &dw);
2844 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2845 dw[1] = offset;
2846 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2847 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002848 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002849
2850 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2851 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002852 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2853
2854 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002855 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002856 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002857 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002858 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002859 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002860
2861 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2862 dw[6] = 0;
2863 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002864
2865 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002866}
2867
2868static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2869{
2870 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002871 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002872
2873 CMD_ASSERT(cmd, 6, 7.5);
2874
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002875 if (!ds) {
2876 /* all zeros */
2877 static const struct intel_ds_view null_ds;
2878 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002879 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002880
2881 cmd_wa_gen6_pre_ds_flush(cmd);
2882 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2883 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2884 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2885
2886 if (cmd_gen(cmd) >= INTEL_GEN(7))
2887 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2888 else
2889 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002890}
2891
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002892static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2893 const struct intel_pipeline *pipeline)
2894{
2895 cmd->bind.pipeline.graphics = pipeline;
2896}
2897
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002898static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2899 const struct intel_pipeline *pipeline)
2900{
2901 cmd->bind.pipeline.compute = pipeline;
2902}
2903
2904static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2905 const struct intel_pipeline_delta *delta)
2906{
2907 cmd->bind.pipeline.graphics_delta = delta;
2908}
2909
2910static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2911 const struct intel_pipeline_delta *delta)
2912{
2913 cmd->bind.pipeline.compute_delta = delta;
2914}
2915
2916static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2917 const struct intel_dset *dset,
2918 XGL_UINT slot_offset)
2919{
2920 cmd->bind.dset.graphics = dset;
2921 cmd->bind.dset.graphics_offset = slot_offset;
2922}
2923
2924static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2925 const struct intel_dset *dset,
2926 XGL_UINT slot_offset)
2927{
2928 cmd->bind.dset.compute = dset;
2929 cmd->bind.dset.compute_offset = slot_offset;
2930}
2931
2932static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2933 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2934{
2935 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2936}
2937
2938static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2939 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2940{
2941 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2942}
2943
Chia-I Wu3b04af52014-11-08 10:48:20 +08002944static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2945 const struct intel_mem *mem,
2946 XGL_GPU_SIZE offset, XGL_UINT binding)
2947{
2948 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2949 cmd->result = XGL_ERROR_UNKNOWN;
2950 return;
2951 }
2952
2953 cmd->bind.vertex.mem[binding] = mem;
2954 cmd->bind.vertex.offset[binding] = offset;
2955}
2956
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002957static void cmd_bind_index_data(struct intel_cmd *cmd,
2958 const struct intel_mem *mem,
2959 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2960{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002961 cmd->bind.index.mem = mem;
2962 cmd->bind.index.offset = offset;
2963 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002964}
2965
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002966static void cmd_bind_attachments(struct intel_cmd *cmd,
2967 XGL_UINT rt_count,
2968 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2969 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002970{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002971 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002972 XGL_UINT i;
2973
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002974 for (i = 0; i < rt_count; i++) {
2975 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002976 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002977 const struct intel_layout *layout = &rt->img->layout;
2978
2979 if (i == 0) {
2980 width = layout->width0;
2981 height = layout->height0;
2982 } else {
2983 if (width > layout->width0)
2984 width = layout->width0;
2985 if (height > layout->height0)
2986 height = layout->height0;
2987 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002988
2989 cmd->bind.att.rt[i] = rt;
2990 }
2991
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002992 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002993
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002994 if (ds_info) {
2995 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002996
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002997 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2998 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002999
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003000 if (width > layout->width0)
3001 width = layout->width0;
3002 if (height > layout->height0)
3003 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003004 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003005 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003006 }
3007
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003008 cmd->bind.att.width = width;
3009 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003010}
3011
3012static void cmd_bind_viewport_state(struct intel_cmd *cmd,
3013 const struct intel_viewport_state *state)
3014{
3015 cmd->bind.state.viewport = state;
3016}
3017
3018static void cmd_bind_raster_state(struct intel_cmd *cmd,
3019 const struct intel_raster_state *state)
3020{
3021 cmd->bind.state.raster = state;
3022}
3023
3024static void cmd_bind_ds_state(struct intel_cmd *cmd,
3025 const struct intel_ds_state *state)
3026{
3027 cmd->bind.state.ds = state;
3028}
3029
3030static void cmd_bind_blend_state(struct intel_cmd *cmd,
3031 const struct intel_blend_state *state)
3032{
3033 cmd->bind.state.blend = state;
3034}
3035
3036static void cmd_bind_msaa_state(struct intel_cmd *cmd,
3037 const struct intel_msaa_state *state)
3038{
3039 cmd->bind.state.msaa = state;
3040}
3041
3042static void cmd_draw(struct intel_cmd *cmd,
3043 XGL_UINT vertex_start,
3044 XGL_UINT vertex_count,
3045 XGL_UINT instance_start,
3046 XGL_UINT instance_count,
3047 bool indexed,
3048 XGL_UINT vertex_base)
3049{
3050 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
3051
3052 emit_bounded_states(cmd);
3053
3054 if (indexed) {
3055 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3056 cmd->result = XGL_ERROR_UNKNOWN;
3057
3058 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3059 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3060 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003061 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3062 cmd->bind.index.offset, cmd->bind.index.type,
3063 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003064 } else {
3065 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3066 cmd->bind.index.offset, cmd->bind.index.type,
3067 p->primitive_restart);
3068 }
3069 } else {
3070 assert(!vertex_base);
3071 }
3072
3073 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3074 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3075 vertex_start, instance_count, instance_start, vertex_base);
3076 } else {
3077 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3078 vertex_start, instance_count, instance_start, vertex_base);
3079 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003080
Chia-I Wu707a29e2014-08-27 12:51:47 +08003081 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003082 /* need to re-emit all workarounds */
3083 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003084
3085 if (intel_debug & INTEL_DEBUG_NOCACHE)
3086 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003087}
3088
Chia-I Wuc14d1562014-10-17 09:49:22 +08003089void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3090{
Chia-I Wu6032b892014-10-17 14:47:18 +08003091 cmd->bind.meta = meta;
3092
3093 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003094 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003095
3096 gen6_meta_dynamic_states(cmd);
3097 gen6_meta_surface_states(cmd);
3098
3099 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3100 gen7_meta_urb(cmd);
3101 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003102 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003103 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003104 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003105 gen6_meta_wm(cmd);
3106 gen7_meta_ps(cmd);
3107 gen6_meta_depth_buffer(cmd);
3108
3109 cmd_wa_gen7_post_command_cs_stall(cmd);
3110 cmd_wa_gen7_post_command_depth_stall(cmd);
3111
Chia-I Wu29e6f502014-11-24 14:27:29 +08003112 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3113 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003114 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003115 } else {
3116 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3117 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003118 } else {
3119 gen6_meta_urb(cmd);
3120 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003121 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003122 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003123 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003124 gen6_meta_wm(cmd);
3125 gen6_meta_ps(cmd);
3126 gen6_meta_depth_buffer(cmd);
3127
Chia-I Wu29e6f502014-11-24 14:27:29 +08003128 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3129 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003130 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003131 } else {
3132 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3133 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003134 }
3135
3136 cmd->bind.draw_count++;
3137 /* need to re-emit all workarounds */
3138 cmd->bind.wa_flags = 0;
3139
3140 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003141
3142 if (intel_debug & INTEL_DEBUG_NOCACHE)
3143 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003144}
3145
Chia-I Wu96177272015-01-03 15:27:41 +08003146ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003147 XGL_CMD_BUFFER cmdBuffer,
3148 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3149 XGL_PIPELINE pipeline)
3150{
3151 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3152
3153 switch (pipelineBindPoint) {
3154 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003155 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003156 break;
3157 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003158 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003159 break;
3160 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003161 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003162 break;
3163 }
3164}
3165
Chia-I Wu96177272015-01-03 15:27:41 +08003166ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003167 XGL_CMD_BUFFER cmdBuffer,
3168 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3169 XGL_PIPELINE_DELTA delta)
3170{
3171 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3172
3173 switch (pipelineBindPoint) {
3174 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003175 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003176 break;
3177 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003178 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003179 break;
3180 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003181 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003182 break;
3183 }
3184}
3185
Chia-I Wu96177272015-01-03 15:27:41 +08003186ICD_EXPORT XGL_VOID XGLAPI xglCmdBindStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003187 XGL_CMD_BUFFER cmdBuffer,
3188 XGL_STATE_BIND_POINT stateBindPoint,
3189 XGL_STATE_OBJECT state)
3190{
3191 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3192
3193 switch (stateBindPoint) {
3194 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003195 cmd_bind_viewport_state(cmd,
3196 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003197 break;
3198 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003199 cmd_bind_raster_state(cmd,
3200 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003201 break;
3202 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003203 cmd_bind_ds_state(cmd,
3204 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003205 break;
3206 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003207 cmd_bind_blend_state(cmd,
3208 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003209 break;
3210 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003211 cmd_bind_msaa_state(cmd,
3212 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003213 break;
3214 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003215 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003216 break;
3217 }
3218}
3219
Chia-I Wu96177272015-01-03 15:27:41 +08003220ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003221 XGL_CMD_BUFFER cmdBuffer,
3222 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3223 XGL_UINT index,
3224 XGL_DESCRIPTOR_SET descriptorSet,
3225 XGL_UINT slotOffset)
3226{
3227 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3228 struct intel_dset *dset = intel_dset(descriptorSet);
3229
3230 assert(!index);
3231
3232 switch (pipelineBindPoint) {
3233 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003234 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003235 break;
3236 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003237 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003238 break;
3239 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003240 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003241 break;
3242 }
3243}
3244
Chia-I Wu96177272015-01-03 15:27:41 +08003245ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicMemoryView(
Chia-I Wub2755562014-08-20 13:38:52 +08003246 XGL_CMD_BUFFER cmdBuffer,
3247 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3248 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3249{
3250 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3251
3252 switch (pipelineBindPoint) {
3253 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003254 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003255 break;
3256 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003257 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003258 break;
3259 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003260 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003261 break;
3262 }
3263}
3264
Chia-I Wu96177272015-01-03 15:27:41 +08003265ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexData(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003266 XGL_CMD_BUFFER cmdBuffer,
3267 XGL_GPU_MEMORY mem_,
3268 XGL_GPU_SIZE offset,
3269 XGL_UINT binding)
3270{
3271 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3272 struct intel_mem *mem = intel_mem(mem_);
3273
3274 cmd_bind_vertex_data(cmd, mem, offset, binding);
3275}
3276
Chia-I Wu96177272015-01-03 15:27:41 +08003277ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexData(
Chia-I Wub2755562014-08-20 13:38:52 +08003278 XGL_CMD_BUFFER cmdBuffer,
3279 XGL_GPU_MEMORY mem_,
3280 XGL_GPU_SIZE offset,
3281 XGL_INDEX_TYPE indexType)
3282{
3283 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3284 struct intel_mem *mem = intel_mem(mem_);
3285
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003286 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003287}
3288
Chia-I Wu96177272015-01-03 15:27:41 +08003289ICD_EXPORT XGL_VOID XGLAPI xglCmdBindAttachments(
Chia-I Wub2755562014-08-20 13:38:52 +08003290 XGL_CMD_BUFFER cmdBuffer,
3291 XGL_UINT colorAttachmentCount,
3292 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3293 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3294{
3295 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003296
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003297 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3298 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003299}
3300
Chia-I Wu96177272015-01-03 15:27:41 +08003301ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003302 XGL_CMD_BUFFER cmdBuffer,
3303 XGL_UINT firstVertex,
3304 XGL_UINT vertexCount,
3305 XGL_UINT firstInstance,
3306 XGL_UINT instanceCount)
3307{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003308 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003309
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003310 cmd_draw(cmd, firstVertex, vertexCount,
3311 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003312}
3313
Chia-I Wu96177272015-01-03 15:27:41 +08003314ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003315 XGL_CMD_BUFFER cmdBuffer,
3316 XGL_UINT firstIndex,
3317 XGL_UINT indexCount,
3318 XGL_INT vertexOffset,
3319 XGL_UINT firstInstance,
3320 XGL_UINT instanceCount)
3321{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003322 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003323
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003324 cmd_draw(cmd, firstIndex, indexCount,
3325 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003326}
3327
Chia-I Wu96177272015-01-03 15:27:41 +08003328ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003329 XGL_CMD_BUFFER cmdBuffer,
3330 XGL_GPU_MEMORY mem,
3331 XGL_GPU_SIZE offset,
3332 XGL_UINT32 count,
3333 XGL_UINT32 stride)
3334{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003335 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3336
3337 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003338}
3339
Chia-I Wu96177272015-01-03 15:27:41 +08003340ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003341 XGL_CMD_BUFFER cmdBuffer,
3342 XGL_GPU_MEMORY mem,
3343 XGL_GPU_SIZE offset,
3344 XGL_UINT32 count,
3345 XGL_UINT32 stride)
3346{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003347 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3348
3349 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003350}
3351
Chia-I Wu96177272015-01-03 15:27:41 +08003352ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003353 XGL_CMD_BUFFER cmdBuffer,
3354 XGL_UINT x,
3355 XGL_UINT y,
3356 XGL_UINT z)
3357{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003358 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3359
3360 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003361}
3362
Chia-I Wu96177272015-01-03 15:27:41 +08003363ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003364 XGL_CMD_BUFFER cmdBuffer,
3365 XGL_GPU_MEMORY mem,
3366 XGL_GPU_SIZE offset)
3367{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003368 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3369
3370 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003371}