blob: c951334c8b6e80c4576d6f1b7fea4b1d8a792d85 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080030#include "dset.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080031#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080032#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080033#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080034#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080035#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080036#include "state.h"
37#include "view.h"
38#include "cmd_priv.h"
39
Chia-I Wu59c097e2014-08-21 10:51:07 +080040static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080041 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080042 uint32_t vertex_count,
43 uint32_t vertex_start,
44 uint32_t instance_count,
45 uint32_t instance_start,
46 uint32_t vertex_base)
47{
48 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080049 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080050
51 CMD_ASSERT(cmd, 6, 6);
52
Chia-I Wu426072d2014-08-26 14:31:55 +080053 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080054 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080055 (cmd_len - 2);
56
57 if (indexed)
58 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
59
Chia-I Wu72292b72014-09-09 10:48:33 +080060 cmd_batch_pointer(cmd, cmd_len, &dw);
61 dw[0] = dw0;
62 dw[1] = vertex_count;
63 dw[2] = vertex_start;
64 dw[3] = instance_count;
65 dw[4] = instance_start;
66 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080067}
68
69static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080070 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080071 uint32_t vertex_count,
72 uint32_t vertex_start,
73 uint32_t instance_count,
74 uint32_t instance_start,
75 uint32_t vertex_base)
76{
77 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080078 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080079
80 CMD_ASSERT(cmd, 7, 7.5);
81
Chia-I Wu426072d2014-08-26 14:31:55 +080082 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080083 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080084
85 if (indexed)
86 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
87
Chia-I Wu72292b72014-09-09 10:48:33 +080088 cmd_batch_pointer(cmd, cmd_len, &dw);
89 dw[0] = dw0;
90 dw[1] = dw1;
91 dw[2] = vertex_count;
92 dw[3] = vertex_start;
93 dw[4] = instance_count;
94 dw[5] = instance_start;
95 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080096}
97
Chia-I Wu270b1e82014-08-25 15:53:39 +080098static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +080099 struct intel_bo *bo, uint32_t bo_offset,
100 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800101{
102 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800103 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800104 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800105 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800106 uint32_t *dw;
107 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800108
109 CMD_ASSERT(cmd, 6, 7.5);
110
111 assert(bo_offset % 8 == 0);
112
113 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
114 /*
115 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
116 *
117 * "1 of the following must also be set (when CS stall is set):
118 *
119 * * Depth Cache Flush Enable ([0] of DW1)
120 * * Stall at Pixel Scoreboard ([1] of DW1)
121 * * Depth Stall ([13] of DW1)
122 * * Post-Sync Operation ([13] of DW1)
123 * * Render Target Cache Flush Enable ([12] of DW1)
124 * * Notify Enable ([8] of DW1)"
125 *
126 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
127 *
128 * "One of the following must also be set (when CS stall is set):
129 *
130 * * Render Target Cache Flush Enable ([12] of DW1)
131 * * Depth Cache Flush Enable ([0] of DW1)
132 * * Stall at Pixel Scoreboard ([1] of DW1)
133 * * Depth Stall ([13] of DW1)
134 * * Post-Sync Operation ([13] of DW1)"
135 */
136 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
137 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
138 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
139 GEN6_PIPE_CONTROL_DEPTH_STALL;
140
141 /* post-sync op */
142 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
143 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
144 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
145
146 if (cmd_gen(cmd) == INTEL_GEN(6))
147 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
148
149 assert(dw1 & bit_test);
150 }
151
152 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
153 /*
154 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
155 *
156 * "Following bits must be clear (when Depth Stall is set):
157 *
158 * * Render Target Cache Flush Enable ([12] of DW1)
159 * * Depth Cache Flush Enable ([0] of DW1)"
160 */
161 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
162 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
163 }
164
165 /*
166 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
167 *
168 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
169 * and PIPE_CONTROL are not supported."
170 *
171 * The kernel will add the mapping automatically (when write domain is
172 * INTEL_DOMAIN_INSTRUCTION).
173 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800174 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800175 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 reloc_flags |= INTEL_RELOC_GGTT;
177 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800178
Chia-I Wu72292b72014-09-09 10:48:33 +0800179 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
180 dw[0] = dw0;
181 dw[1] = dw1;
182 dw[2] = 0;
183 dw[3] = (uint32_t) imm;
184 dw[4] = (uint32_t) (imm >> 32);
185
186 if (bo) {
187 cmd_reserve_reloc(cmd, 1);
188 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
189 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800190}
191
Chia-I Wu254db422014-08-21 11:54:29 +0800192static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
193{
194 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
195 bool supported;
196
197 CMD_ASSERT(cmd, 6, 7.5);
198
199 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
200 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
201
202 switch (p->prim_type) {
203 case GEN6_3DPRIM_POINTLIST:
204 case GEN6_3DPRIM_LINELIST:
205 case GEN6_3DPRIM_LINESTRIP:
206 case GEN6_3DPRIM_TRILIST:
207 case GEN6_3DPRIM_TRISTRIP:
208 supported = true;
209 break;
210 default:
211 supported = false;
212 break;
213 }
214
215 if (!supported)
216 return false;
217
218 switch (cmd->bind.index.type) {
219 case XGL_INDEX_8:
220 supported = (p->primitive_restart_index != 0xffu);
221 break;
222 case XGL_INDEX_16:
223 supported = (p->primitive_restart_index != 0xffffu);
224 break;
225 case XGL_INDEX_32:
226 supported = (p->primitive_restart_index != 0xffffffffu);
227 break;
228 default:
229 supported = false;
230 break;
231 }
232
233 return supported;
234}
235
Chia-I Wu59c097e2014-08-21 10:51:07 +0800236static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800237 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238 XGL_GPU_SIZE offset,
239 XGL_INDEX_TYPE type,
240 bool enable_cut_index)
241{
242 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800243 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800244 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246
247 CMD_ASSERT(cmd, 6, 7.5);
248
Chia-I Wu426072d2014-08-26 14:31:55 +0800249 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800250
251 /* the bit is moved to 3DSTATE_VF */
252 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
253 assert(!enable_cut_index);
254 if (enable_cut_index)
255 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
256
257 switch (type) {
258 case XGL_INDEX_8:
259 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
260 offset_align = 1;
261 break;
262 case XGL_INDEX_16:
263 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
264 offset_align = 2;
265 break;
266 case XGL_INDEX_32:
267 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
268 offset_align = 4;
269 break;
270 default:
271 cmd->result = XGL_ERROR_INVALID_VALUE;
272 return;
273 break;
274 }
275
276 if (offset % offset_align) {
277 cmd->result = XGL_ERROR_INVALID_VALUE;
278 return;
279 }
280
281 /* aligned and inclusive */
282 end_offset = mem->size - (mem->size % offset_align) - 1;
283
Chia-I Wu72292b72014-09-09 10:48:33 +0800284 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
285 dw[0] = dw0;
286
287 cmd_reserve_reloc(cmd, 2);
288 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
289 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800290}
291
Chia-I Wu62a7f252014-08-29 11:31:16 +0800292static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
293 bool enable_cut_index,
294 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800295{
296 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800297 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800298
299 CMD_ASSERT(cmd, 7.5, 7.5);
300
Chia-I Wu426072d2014-08-26 14:31:55 +0800301 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800302 if (enable_cut_index)
303 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
304
Chia-I Wu72292b72014-09-09 10:48:33 +0800305 cmd_batch_pointer(cmd, cmd_len, &dw);
306 dw[0] = dw0;
307 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800308}
309
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600310
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800311static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
312{
313 const uint8_t cmd_len = 7;
314 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800315 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800316
317 CMD_ASSERT(cmd, 6, 6);
318
Chia-I Wu72292b72014-09-09 10:48:33 +0800319 cmd_batch_pointer(cmd, cmd_len, &dw);
320 dw[0] = dw0;
321 dw[1] = 0;
322 dw[2] = 0;
323 dw[3] = 0;
324 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
325 dw[5] = GEN6_GS_DW5_STATISTICS;
326 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800327}
328
Chia-I Wu62a7f252014-08-29 11:31:16 +0800329static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
330{
331 const uint8_t cmd_len = 7;
332 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800333 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800334
335 CMD_ASSERT(cmd, 7, 7.5);
336
Chia-I Wu72292b72014-09-09 10:48:33 +0800337 cmd_batch_pointer(cmd, cmd_len, &dw);
338 dw[0] = dw0;
339 dw[1] = 0;
340 dw[2] = 0;
341 dw[3] = 0;
342 dw[4] = 0;
343 dw[5] = GEN6_GS_DW5_STATISTICS;
344 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800345}
346
Chia-I Wud88e02d2014-08-25 10:56:13 +0800347static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
348 XGL_UINT width, XGL_UINT height)
349{
350 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800351 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800352 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800353 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354
355 CMD_ASSERT(cmd, 6, 7.5);
356
Chia-I Wu72292b72014-09-09 10:48:33 +0800357 cmd_batch_pointer(cmd, cmd_len, &dw);
358 dw[0] = dw0;
359
Chia-I Wud88e02d2014-08-25 10:56:13 +0800360 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800361 dw[1] = 0;
362 dw[2] = (height - 1) << 16 |
363 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800364 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800365 dw[1] = 1;
366 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800367 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800368
369 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800370}
371
Chia-I Wu8016a172014-08-29 18:31:32 +0800372static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
373 uint32_t body[6])
374{
375 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
376 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
377 const struct intel_raster_state *raster = cmd->bind.state.raster;
378 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
389 raster->cmd_sf_fill;
390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
394 switch (pipeline->db_format.channelFormat) {
395 case XGL_CH_FMT_R16:
396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
398 case XGL_CH_FMT_R32:
399 case XGL_CH_FMT_R32G8:
400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
403 assert(!"unknown depth format");
404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
411 dw2 = raster->cmd_sf_cull;
412
413 if (msaa->sample_count > 1) {
414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
421 if (viewport->scissor_enable)
422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
425 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
438 body[3] = raster->cmd_depth_offset_const;
439 body[4] = raster->cmd_depth_offset_scale;
440 body[5] = raster->cmd_depth_offset_clamp;
441}
442
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
GregF8cd81832014-11-18 18:01:01 -0700446 XGL_UINT sbe_offset;
447 XGL_INT i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448
449 CMD_ASSERT(cmd, 6, 7.5);
450
GregF8cd81832014-11-18 18:01:01 -0700451 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452
GregF8cd81832014-11-18 18:01:01 -0700453 for (i = 0; i < 13; i++) {
454 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
455 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800456 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800457}
458
459static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
460{
461 const uint8_t cmd_len = 20;
462 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
463 (cmd_len - 2);
464 uint32_t sf[6];
465 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 6, 6);
469
470 gen7_fill_3DSTATE_SF_body(cmd, sf);
471 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
474 dw[0] = dw0;
475 dw[1] = sbe[0];
476 memcpy(&dw[2], sf, sizeof(sf));
477 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800478}
479
480static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
481{
482 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800483 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800484
485 CMD_ASSERT(cmd, 7, 7.5);
486
Chia-I Wu72292b72014-09-09 10:48:33 +0800487 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
489 (cmd_len - 2);
490 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800491}
492
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800493static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
494{
495 const uint8_t cmd_len = 4;
496 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
497 (cmd_len - 2);
498 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700499 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800500 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800501 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
502 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800503 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800504
505 CMD_ASSERT(cmd, 6, 7.5);
506
507 dw1 = GEN6_CLIP_DW1_STATISTICS;
508 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
509 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
510 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
511 raster->cmd_clip_cull;
512 }
513
514 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
515 GEN6_CLIP_DW2_XY_TEST_ENABLE |
516 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700517 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800518 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
519 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
520 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
521
522 if (pipeline->rasterizerDiscardEnable)
523 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
524 else
525 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
526
527 if (pipeline->depthClipEnable)
528 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
529
530 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
531 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
532 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
533 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
534
535 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
536 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
537 (viewport->viewport_count - 1);
538
Chia-I Wu72292b72014-09-09 10:48:33 +0800539 cmd_batch_pointer(cmd, cmd_len, &dw);
540 dw[0] = dw0;
541 dw[1] = dw1;
542 dw[2] = dw2;
543 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800544}
545
Chia-I Wu784d3042014-12-19 14:30:04 +0800546static void gen6_add_scratch_space(struct intel_cmd *cmd,
547 XGL_UINT batch_pos,
548 const struct intel_pipeline *pipeline,
549 const struct intel_pipeline_shader *sh)
550{
551 int scratch_space;
552
553 CMD_ASSERT(cmd, 6, 7.5);
554
555 assert(sh->per_thread_scratch_size &&
556 sh->per_thread_scratch_size % 1024 == 0 &&
557 u_is_pow2(sh->per_thread_scratch_size) &&
558 sh->scratch_offset % 1024 == 0);
559 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
560
561 cmd_reserve_reloc(cmd, 1);
562 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
563 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
564}
565
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800566static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
567{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800568 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800569 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800570 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
571 const uint8_t cmd_len = 9;
Chia-I Wu784d3042014-12-19 14:30:04 +0800572 XGL_UINT pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800573 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800574
575 CMD_ASSERT(cmd, 6, 6);
576
577 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
578
579 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
580 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
581
582 dw4 = GEN6_WM_DW4_STATISTICS |
583 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
584 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
585 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
586
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800587 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800588 GEN6_WM_DW5_PS_ENABLE |
589 GEN6_WM_DW5_8_PIXEL_DISPATCH;
590
591 if (fs->uses & INTEL_SHADER_USE_KILL ||
592 pipeline->cb_state.alphaToCoverageEnable)
593 dw5 |= GEN6_WM_DW5_PS_KILL;
594
595 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
596 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
597 if (fs->uses & INTEL_SHADER_USE_DEPTH)
598 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
599 if (fs->uses & INTEL_SHADER_USE_W)
600 dw5 |= GEN6_WM_DW5_PS_USE_W;
601
602 if (pipeline->cb_state.dualSourceBlendEnable)
603 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
604
605 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
606 GEN6_WM_DW6_POSOFFSET_NONE |
607 GEN6_WM_DW6_ZW_INTERP_PIXEL |
608 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
609 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
610
611 if (msaa->sample_count > 1) {
612 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
613 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
614 } else {
615 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
616 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
617 }
618
Chia-I Wu784d3042014-12-19 14:30:04 +0800619 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800620 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800621 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800622 dw[2] = dw2;
623 dw[3] = 0; /* scratch */
624 dw[4] = dw4;
625 dw[5] = dw5;
626 dw[6] = dw6;
627 dw[7] = 0; /* kernel 1 */
628 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800629
630 if (fs->per_thread_scratch_size)
631 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800632}
633
634static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
635{
636 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800637 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
639 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800640 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800641
642 CMD_ASSERT(cmd, 7, 7.5);
643
644 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
645
646 dw1 = GEN7_WM_DW1_STATISTICS |
647 GEN7_WM_DW1_PS_ENABLE |
648 GEN7_WM_DW1_ZW_INTERP_PIXEL |
649 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
650 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
651
652 if (fs->uses & INTEL_SHADER_USE_KILL ||
653 pipeline->cb_state.alphaToCoverageEnable)
654 dw1 |= GEN7_WM_DW1_PS_KILL;
655
656 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
657 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
658 if (fs->uses & INTEL_SHADER_USE_DEPTH)
659 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
660 if (fs->uses & INTEL_SHADER_USE_W)
661 dw1 |= GEN7_WM_DW1_PS_USE_W;
662
663 dw2 = 0;
664
665 if (msaa->sample_count > 1) {
666 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
667 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
668 } else {
669 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
670 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
671 }
672
Chia-I Wu72292b72014-09-09 10:48:33 +0800673 cmd_batch_pointer(cmd, cmd_len, &dw);
674 dw[0] = dw0;
675 dw[1] = dw1;
676 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800677}
678
679static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
680{
681 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800682 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800683 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
684 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800685 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +0800686 XGL_UINT pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800687
688 CMD_ASSERT(cmd, 7, 7.5);
689
690 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
691
692 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
693 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
694
695 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
696 GEN7_PS_DW4_8_PIXEL_DISPATCH;
697
698 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800699 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800700 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
701 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800702 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800703 }
704
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800705 if (fs->in_count)
706 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
707
708 if (pipeline->cb_state.dualSourceBlendEnable)
709 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
710
711 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
712 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
713 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
714
Chia-I Wu784d3042014-12-19 14:30:04 +0800715 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800716 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800717 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800718 dw[2] = dw2;
719 dw[3] = 0; /* scratch */
720 dw[4] = dw4;
721 dw[5] = dw5;
722 dw[6] = 0; /* kernel 1 */
723 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800724
725 if (fs->per_thread_scratch_size)
726 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800727}
728
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800729static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
730 const struct intel_ds_view *view)
731{
732 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800733 uint32_t dw0, *dw;
734 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800735
736 CMD_ASSERT(cmd, 6, 7.5);
737
738 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800739 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
740 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800741 dw0 |= (cmd_len - 2);
742
Chia-I Wu72292b72014-09-09 10:48:33 +0800743 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
744 dw[0] = dw0;
745 dw[1] = view->cmd[0];
746 dw[2] = 0;
747 dw[3] = view->cmd[2];
748 dw[4] = view->cmd[3];
749 dw[5] = view->cmd[4];
750 dw[6] = view->cmd[5];
751
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600752 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800753 cmd_reserve_reloc(cmd, 1);
754 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
755 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600756 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800757}
758
759static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
760 const struct intel_ds_view *view)
761{
762 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800763 uint32_t dw0, *dw;
764 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800765
766 CMD_ASSERT(cmd, 6, 7.5);
767
768 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800769 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
770 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800771 dw0 |= (cmd_len - 2);
772
Chia-I Wu72292b72014-09-09 10:48:33 +0800773 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
774 dw[0] = dw0;
775 dw[1] = view->cmd[6];
776 dw[2] = 0;
777
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600778 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800779 cmd_reserve_reloc(cmd, 1);
780 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
781 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600782 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800783}
784
785static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
786 const struct intel_ds_view *view)
787{
788 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800789 uint32_t dw0, *dw;
790 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800791
792 CMD_ASSERT(cmd, 6, 7.5);
793
794 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800795 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
796 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797 dw0 |= (cmd_len - 2);
798
Chia-I Wu72292b72014-09-09 10:48:33 +0800799 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
800 dw[0] = dw0;
801 dw[1] = view->cmd[8];
802 dw[2] = 0;
803
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600804 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800805 cmd_reserve_reloc(cmd, 1);
806 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
807 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600808 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800809}
810
Chia-I Wuf8231032014-08-25 10:44:45 +0800811static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
812 uint32_t clear_val)
813{
814 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800815 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800816 GEN6_CLEAR_PARAMS_DW0_VALID |
817 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800818 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800819
820 CMD_ASSERT(cmd, 6, 6);
821
Chia-I Wu72292b72014-09-09 10:48:33 +0800822 cmd_batch_pointer(cmd, cmd_len, &dw);
823 dw[0] = dw0;
824 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800825}
826
827static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
828 uint32_t clear_val)
829{
830 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800831 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800832 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800833 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800834
835 CMD_ASSERT(cmd, 7, 7.5);
836
Chia-I Wu72292b72014-09-09 10:48:33 +0800837 cmd_batch_pointer(cmd, cmd_len, &dw);
838 dw[0] = dw0;
839 dw[1] = clear_val;
840 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800841}
842
Chia-I Wu302742d2014-08-22 10:28:29 +0800843static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800844 uint32_t blend_offset,
845 uint32_t ds_offset,
846 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800847{
848 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800849 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800850
851 CMD_ASSERT(cmd, 6, 6);
852
Chia-I Wu426072d2014-08-26 14:31:55 +0800853 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800854 (cmd_len - 2);
855
Chia-I Wu72292b72014-09-09 10:48:33 +0800856 cmd_batch_pointer(cmd, cmd_len, &dw);
857 dw[0] = dw0;
858 dw[1] = blend_offset | 1;
859 dw[2] = ds_offset | 1;
860 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800861}
862
Chia-I Wu1744cca2014-08-22 11:10:17 +0800863static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800864 uint32_t clip_offset,
865 uint32_t sf_offset,
866 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800867{
868 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800869 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800870
871 CMD_ASSERT(cmd, 6, 6);
872
Chia-I Wu426072d2014-08-26 14:31:55 +0800873 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800874 GEN6_PTR_VP_DW0_CLIP_CHANGED |
875 GEN6_PTR_VP_DW0_SF_CHANGED |
876 GEN6_PTR_VP_DW0_CC_CHANGED |
877 (cmd_len - 2);
878
Chia-I Wu72292b72014-09-09 10:48:33 +0800879 cmd_batch_pointer(cmd, cmd_len, &dw);
880 dw[0] = dw0;
881 dw[1] = clip_offset;
882 dw[2] = sf_offset;
883 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800884}
885
886static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800887 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800888{
889 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800890 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800891
892 CMD_ASSERT(cmd, 6, 6);
893
Chia-I Wu426072d2014-08-26 14:31:55 +0800894 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800895 (cmd_len - 2);
896
Chia-I Wu72292b72014-09-09 10:48:33 +0800897 cmd_batch_pointer(cmd, cmd_len, &dw);
898 dw[0] = dw0;
899 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800900}
901
Chia-I Wu42a56202014-08-23 16:47:48 +0800902static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800903 uint32_t vs_offset,
904 uint32_t gs_offset,
905 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800906{
907 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800908 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800909
910 CMD_ASSERT(cmd, 6, 6);
911
Chia-I Wu426072d2014-08-26 14:31:55 +0800912 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800913 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
914 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
915 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
916 (cmd_len - 2);
917
Chia-I Wu72292b72014-09-09 10:48:33 +0800918 cmd_batch_pointer(cmd, cmd_len, &dw);
919 dw[0] = dw0;
920 dw[1] = vs_offset;
921 dw[2] = gs_offset;
922 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800923}
924
Chia-I Wu257e75e2014-08-29 14:06:35 +0800925static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800926 uint32_t vs_offset,
927 uint32_t gs_offset,
928 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800929{
930 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800931 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800932
933 CMD_ASSERT(cmd, 6, 6);
934
935 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
936 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
937 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
938 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
939 (cmd_len - 2);
940
Chia-I Wu72292b72014-09-09 10:48:33 +0800941 cmd_batch_pointer(cmd, cmd_len, &dw);
942 dw[0] = dw0;
943 dw[1] = vs_offset;
944 dw[2] = gs_offset;
945 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800946}
947
Chia-I Wu302742d2014-08-22 10:28:29 +0800948static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800949 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800950{
951 const uint8_t cmd_len = 2;
952 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
953 GEN6_RENDER_SUBTYPE_3D |
954 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800956
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 cmd_batch_pointer(cmd, cmd_len, &dw);
958 dw[0] = dw0;
959 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800960}
961
Chia-I Wua6c4f152014-12-02 04:19:58 +0800962static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800963{
Chia-I Wue6073342014-11-30 09:43:42 +0800964 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800965 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
Chia-I Wua6c4f152014-12-02 04:19:58 +0800966 const XGL_PIPELINE_CB_STATE *cb = &cmd->bind.pipeline.graphics->cb_state;
967 const struct intel_blend_state *blend = cmd->bind.state.blend;
968 uint32_t dw[XGL_MAX_COLOR_ATTACHMENTS * 2];
969 int i;
Chia-I Wu302742d2014-08-22 10:28:29 +0800970
971 CMD_ASSERT(cmd, 6, 7.5);
Chia-I Wua6c4f152014-12-02 04:19:58 +0800972 STATIC_ASSERT(ARRAY_SIZE(blend->cmd_blend) >= XGL_MAX_COLOR_ATTACHMENTS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800973
Chia-I Wua6c4f152014-12-02 04:19:58 +0800974 for (i = 0; i < XGL_MAX_COLOR_ATTACHMENTS; i++) {
975 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &cb->attachment[i];
976 uint32_t dw0, dw1;
977
978 dw0 = 0;
979 dw1 = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
980 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
981 GEN6_BLEND_DW1_POST_BLEND_CLAMP;
982
983 if (cb->logicOp != XGL_LOGIC_OP_COPY) {
984 int logicop;
985
986 switch (cb->logicOp) {
987 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
988 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
989 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
990 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
991 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
992 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
993 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
994 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
995 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
996 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
997 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
998 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
999 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1000 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1001 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1002 default:
1003 assert(!"unknown logic op");
1004 logicop = GEN6_LOGICOP_CLEAR;
1005 break;
1006 }
1007
1008 dw1 |= GEN6_BLEND_DW1_LOGICOP_ENABLE |
1009 logicop << GEN6_BLEND_DW1_LOGICOP_FUNC__SHIFT;
1010 } else if (att->blendEnable && blend) {
1011 dw0 |= blend->cmd_blend[i];
1012 }
1013
1014 if (!(att->channelWriteMask & 0x1))
1015 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_R;
1016 if (!(att->channelWriteMask & 0x2))
1017 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_G;
1018 if (!(att->channelWriteMask & 0x4))
1019 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_B;
1020 if (!(att->channelWriteMask & 0x8))
1021 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_A;
1022
1023 dw[2 * i] = dw0;
1024 dw[2 * i + 1] = dw1;
1025 }
1026
1027 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001028}
1029
Chia-I Wu72292b72014-09-09 10:48:33 +08001030static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001031 const struct intel_ds_state *state)
1032{
Chia-I Wue6073342014-11-30 09:43:42 +08001033 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001034 const uint8_t cmd_len = 3;
1035
1036 CMD_ASSERT(cmd, 6, 7.5);
1037 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1038
Chia-I Wu00b51a82014-09-09 12:07:37 +08001039 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1040 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001041}
1042
Chia-I Wu72292b72014-09-09 10:48:33 +08001043static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001044 uint32_t stencil_ref,
1045 const uint32_t blend_color[4])
1046{
Chia-I Wue6073342014-11-30 09:43:42 +08001047 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001048 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001049 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001050
1051 CMD_ASSERT(cmd, 6, 7.5);
1052
Chia-I Wu00b51a82014-09-09 12:07:37 +08001053 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1054 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001055 dw[0] = stencil_ref;
1056 dw[1] = 0;
1057 dw[2] = blend_color[0];
1058 dw[3] = blend_color[1];
1059 dw[4] = blend_color[2];
1060 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001061
Chia-I Wu72292b72014-09-09 10:48:33 +08001062 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001063}
1064
Chia-I Wu8370b402014-08-29 12:28:37 +08001065static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001066{
Chia-I Wu8370b402014-08-29 12:28:37 +08001067 CMD_ASSERT(cmd, 6, 7.5);
1068
Chia-I Wu707a29e2014-08-27 12:51:47 +08001069 if (!cmd->bind.draw_count)
1070 return;
1071
Chia-I Wu8370b402014-08-29 12:28:37 +08001072 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001073 return;
1074
Chia-I Wu8370b402014-08-29 12:28:37 +08001075 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001076
1077 /*
1078 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1079 *
1080 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1081 * pipe-control with a post-sync op and no write-cache flushes."
1082 *
1083 * The workaround below necessitates this workaround.
1084 */
1085 gen6_PIPE_CONTROL(cmd,
1086 GEN6_PIPE_CONTROL_CS_STALL |
1087 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001088 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001089
Chia-I Wud6d079d2014-08-31 13:14:21 +08001090 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1091 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001092}
1093
Chia-I Wu8370b402014-08-29 12:28:37 +08001094static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001095{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001096 CMD_ASSERT(cmd, 6, 7.5);
1097
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001098 if (!cmd->bind.draw_count)
1099 return;
1100
Chia-I Wud6d079d2014-08-31 13:14:21 +08001101 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1102 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001103}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001104
Chia-I Wu8370b402014-08-29 12:28:37 +08001105static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1106{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001107 CMD_ASSERT(cmd, 7, 7.5);
1108
Chia-I Wu8370b402014-08-29 12:28:37 +08001109 if (!cmd->bind.draw_count)
1110 return;
1111
1112 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001113
1114 gen6_PIPE_CONTROL(cmd,
1115 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001116 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001117}
1118
Chia-I Wu8370b402014-08-29 12:28:37 +08001119static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1120{
1121 CMD_ASSERT(cmd, 7, 7.5);
1122
1123 if (!cmd->bind.draw_count)
1124 return;
1125
1126 /*
1127 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1128 *
1129 * "One of the following must also be set (when CS stall is set):
1130 *
1131 * * Render Target Cache Flush Enable ([12] of DW1)
1132 * * Depth Cache Flush Enable ([0] of DW1)
1133 * * Stall at Pixel Scoreboard ([1] of DW1)
1134 * * Depth Stall ([13] of DW1)
1135 * * Post-Sync Operation ([13] of DW1)"
1136 */
1137 gen6_PIPE_CONTROL(cmd,
1138 GEN6_PIPE_CONTROL_CS_STALL |
1139 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001140 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001141}
1142
1143static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1144{
1145 CMD_ASSERT(cmd, 7, 7.5);
1146
1147 if (!cmd->bind.draw_count)
1148 return;
1149
1150 cmd_wa_gen6_pre_depth_stall_write(cmd);
1151
Chia-I Wud6d079d2014-08-31 13:14:21 +08001152 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001153}
1154
1155static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1156{
1157 CMD_ASSERT(cmd, 6, 7.5);
1158
1159 if (!cmd->bind.draw_count)
1160 return;
1161
1162 /*
1163 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1164 *
1165 * "Driver must guarentee that all the caches in the depth pipe are
1166 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1167 * requires driver to send a PIPE_CONTROL with a CS stall along with
1168 * a Depth Flush prior to this command."
1169 *
1170 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1171 *
1172 * "Driver must ierarchi that all the caches in the depth pipe are
1173 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1174 * requires driver to send a PIPE_CONTROL with a CS stall along with
1175 * a Depth Flush prior to this command.
1176 */
1177 gen6_PIPE_CONTROL(cmd,
1178 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1179 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001180 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001181}
1182
1183static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1184{
1185 CMD_ASSERT(cmd, 6, 7.5);
1186
1187 if (!cmd->bind.draw_count)
1188 return;
1189
1190 /*
1191 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1192 *
1193 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1194 * and a post sync operation prior to the group of depth
1195 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1196 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1197 *
1198 * This workaround satifies all the conditions.
1199 */
1200 cmd_wa_gen6_pre_depth_stall_write(cmd);
1201
1202 /*
1203 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1204 *
1205 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1206 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1207 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1208 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1209 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1210 * Depth Flush Bit set, followed by another pipelined depth stall
1211 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1212 * guarantee that the pipeline from WM onwards is already flushed
1213 * (e.g., via a preceding MI_FLUSH)."
1214 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001215 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1216 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1217 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001218}
1219
Chia-I Wu525c6602014-08-27 10:22:34 +08001220void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1221{
1222 if (!cmd->bind.draw_count)
1223 return;
1224
1225 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1226
Chia-I Wu8370b402014-08-29 12:28:37 +08001227 /*
1228 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1229 *
1230 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1231 * PIPE_CONTROL with any non-zero post-sync-op is required."
1232 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001233 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001234 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001235
Chia-I Wu092279a2014-08-30 19:05:30 +08001236 /*
1237 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1238 *
1239 * "One of the following must also be set (when CS stall is set):
1240 *
1241 * * Render Target Cache Flush Enable ([12] of DW1)
1242 * * Depth Cache Flush Enable ([0] of DW1)
1243 * * Stall at Pixel Scoreboard ([1] of DW1)
1244 * * Depth Stall ([13] of DW1)
1245 * * Post-Sync Operation ([13] of DW1)"
1246 */
1247 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1248 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1249 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1250 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1251 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1252 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1253
Chia-I Wud6d079d2014-08-31 13:14:21 +08001254 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001255}
1256
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001257void cmd_batch_flush_all(struct intel_cmd *cmd)
1258{
1259 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1260 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1261 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1262 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1263 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1264 GEN6_PIPE_CONTROL_CS_STALL);
1265}
1266
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001267void cmd_batch_depth_count(struct intel_cmd *cmd,
1268 struct intel_bo *bo,
1269 XGL_GPU_SIZE offset)
1270{
1271 cmd_wa_gen6_pre_depth_stall_write(cmd);
1272
1273 gen6_PIPE_CONTROL(cmd,
1274 GEN6_PIPE_CONTROL_DEPTH_STALL |
1275 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001276 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001277}
1278
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001279void cmd_batch_timestamp(struct intel_cmd *cmd,
1280 struct intel_bo *bo,
1281 XGL_GPU_SIZE offset)
1282{
1283 /* need any WA or stall? */
1284 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1285}
1286
1287void cmd_batch_immediate(struct intel_cmd *cmd,
1288 struct intel_bo *bo,
1289 XGL_GPU_SIZE offset,
1290 uint64_t val)
1291{
1292 /* need any WA or stall? */
1293 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1294}
1295
Chia-I Wu302742d2014-08-22 10:28:29 +08001296static void gen6_cc_states(struct intel_cmd *cmd)
1297{
1298 const struct intel_blend_state *blend = cmd->bind.state.blend;
1299 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001300 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001301 uint32_t stencil_ref;
1302 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001303
1304 CMD_ASSERT(cmd, 6, 6);
1305
Chia-I Wua6c4f152014-12-02 04:19:58 +08001306 blend_offset = gen6_BLEND_STATE(cmd);
1307
1308 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001309 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001310 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001311 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001312
1313 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001314 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001315 stencil_ref = ds->cmd_stencil_ref;
1316 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001317 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001318 stencil_ref = 0;
1319 }
1320
Chia-I Wu72292b72014-09-09 10:48:33 +08001321 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001322
Chia-I Wu72292b72014-09-09 10:48:33 +08001323 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001324}
1325
Chia-I Wu1744cca2014-08-22 11:10:17 +08001326static void gen6_viewport_states(struct intel_cmd *cmd)
1327{
1328 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001329 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001330
1331 if (!viewport)
1332 return;
1333
Chia-I Wub1d450a2014-09-09 13:48:03 +08001334 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1335 viewport->viewport_count);
1336
1337 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001338 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001339 viewport->cmd);
1340
1341 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001342 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001343 &viewport->cmd[viewport->cmd_clip_pos]);
1344
1345 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001346 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001347 &viewport->cmd[viewport->cmd_cc_pos]);
1348
1349 if (viewport->scissor_enable) {
1350 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001351 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001352 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1353 } else {
1354 scissor_offset = 0;
1355 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001356
1357 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001358 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001359
Chia-I Wub1d450a2014-09-09 13:48:03 +08001360 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001361}
1362
Chia-I Wu302742d2014-08-22 10:28:29 +08001363static void gen7_cc_states(struct intel_cmd *cmd)
1364{
1365 const struct intel_blend_state *blend = cmd->bind.state.blend;
1366 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001367 uint32_t stencil_ref;
1368 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001369 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001370
1371 CMD_ASSERT(cmd, 7, 7.5);
1372
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001373 if (!blend && !ds)
1374 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001375
Chia-I Wua6c4f152014-12-02 04:19:58 +08001376 offset = gen6_BLEND_STATE(cmd);
1377 gen7_3dstate_pointer(cmd,
1378 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001379
Chia-I Wua6c4f152014-12-02 04:19:58 +08001380 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001381 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001382 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001383 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001384
1385 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001386 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001387 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001388 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1389 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001390 } else {
1391 stencil_ref = 0;
1392 }
1393
Chia-I Wu72292b72014-09-09 10:48:33 +08001394 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001395 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001396 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001397}
1398
Chia-I Wu1744cca2014-08-22 11:10:17 +08001399static void gen7_viewport_states(struct intel_cmd *cmd)
1400{
1401 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001402 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001403
1404 if (!viewport)
1405 return;
1406
Chia-I Wub1d450a2014-09-09 13:48:03 +08001407 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1408 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001409
Chia-I Wub1d450a2014-09-09 13:48:03 +08001410 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001411 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001413 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001414 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1415 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001416
1417 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001418 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001419 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001420 gen7_3dstate_pointer(cmd,
1421 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001422 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001423
Chia-I Wu1744cca2014-08-22 11:10:17 +08001424 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001425 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001426 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001428 gen7_3dstate_pointer(cmd,
1429 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001430 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001431 }
1432}
1433
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001434static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001435 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001436{
1437 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001438 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001439
Chia-I Wu72292b72014-09-09 10:48:33 +08001440 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001441
1442 dw[0] = GEN6_RENDER_TYPE_RENDER |
1443 GEN6_RENDER_SUBTYPE_3D |
1444 subop | (cmd_len - 2);
1445 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001446 dw[2] = 0;
1447 dw[3] = 0;
1448 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001449}
1450
1451static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001452 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001453{
1454 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001455 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001456
Chia-I Wu72292b72014-09-09 10:48:33 +08001457 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001458
1459 dw[0] = GEN6_RENDER_TYPE_RENDER |
1460 GEN6_RENDER_SUBTYPE_3D |
1461 subop | (cmd_len - 2);
1462 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001463 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001464 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001465 dw[4] = 0;
1466 dw[5] = 0;
1467 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001468}
1469
Chia-I Wu625105f2014-10-13 15:35:29 +08001470static uint32_t emit_samplers(struct intel_cmd *cmd,
1471 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001472{
1473 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1474 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001475 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001476 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001477 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001478 XGL_UINT i;
1479
1480 CMD_ASSERT(cmd, 6, 7.5);
1481
Chia-I Wu625105f2014-10-13 15:35:29 +08001482 if (!rmap || !rmap->sampler_count)
1483 return 0;
1484
Cody Northrop40316a32014-12-09 19:08:33 -07001485 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001486
Chia-I Wudcb509d2014-12-10 08:53:10 +08001487 /*
1488 * note that we cannot call cmd_state_pointer() here as the following
1489 * cmd_state_pointer() would invalidate the pointer
1490 */
1491 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001492 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001493 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001494
1495 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001496 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001497 4 * rmap->sampler_count, &sampler_dw);
1498
Chia-I Wudcb509d2014-12-10 08:53:10 +08001499 cmd_state_update(cmd, border_offset,
1500 border_stride * rmap->sampler_count, &border_dw);
1501
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001502 for (i = 0; i < rmap->sampler_count; i++) {
1503 const struct intel_pipeline_rmap_slot *slot =
1504 &rmap->slots[surface_count + i];
1505 const struct intel_sampler *sampler;
1506
1507 switch (slot->path_len) {
1508 case 0:
1509 sampler = NULL;
1510 break;
1511 case INTEL_PIPELINE_RMAP_SLOT_RT:
1512 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1513 assert(!"unexpected rmap slot type");
1514 sampler = NULL;
1515 break;
1516 case 1:
1517 {
1518 const struct intel_dset *dset = cmd->bind.dset.graphics;
1519 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1520 const struct intel_dset_slot *dset_slot =
1521 &dset->slots[slot_offset + slot->u.index];
1522
1523 switch (dset_slot->type) {
1524 case INTEL_DSET_SLOT_SAMPLER:
1525 sampler = dset_slot->u.sampler;
1526 break;
1527 default:
1528 assert(!"unexpected dset slot type");
1529 sampler = NULL;
1530 break;
1531 }
1532 }
1533 break;
1534 default:
1535 assert(!"nested descriptor set unsupported");
1536 sampler = NULL;
1537 break;
1538 }
1539
1540 if (sampler) {
1541 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1542
1543 sampler_dw[0] = sampler->cmd[0];
1544 sampler_dw[1] = sampler->cmd[1];
1545 sampler_dw[2] = border_offset;
1546 sampler_dw[3] = sampler->cmd[2];
1547 } else {
1548 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1549 sampler_dw[1] = 0;
1550 sampler_dw[2] = 0;
1551 sampler_dw[3] = 0;
1552 }
1553
1554 border_offset += border_stride * 4;
1555 border_dw += border_stride;
1556 sampler_dw += 4;
1557 }
1558
Chia-I Wu625105f2014-10-13 15:35:29 +08001559 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001560}
1561
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001562static uint32_t emit_binding_table(struct intel_cmd *cmd,
1563 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001564{
Chia-I Wu72292b72014-09-09 10:48:33 +08001565 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001566 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001567
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001568 CMD_ASSERT(cmd, 6, 7.5);
1569
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001570 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001571 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001572 if (!surface_count)
1573 return 0;
1574
Chia-I Wu42a56202014-08-23 16:47:48 +08001575 assert(surface_count <= ARRAY_SIZE(binding_table));
1576
1577 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001578 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001579
1580 switch (slot->path_len) {
1581 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001582 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001583 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001584 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001585 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001586 const struct intel_rt_view *view =
1587 (slot->u.index < cmd->bind.att.rt_count) ?
1588 cmd->bind.att.rt[slot->u.index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001589
Chia-I Wu787a05b2014-12-05 11:02:20 +08001590 if (view) {
1591 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1592 GEN6_ALIGNMENT_SURFACE_STATE,
1593 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001594
Chia-I Wu787a05b2014-12-05 11:02:20 +08001595 cmd_reserve_reloc(cmd, 1);
1596 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1597 view->cmd[1], INTEL_RELOC_WRITE);
1598 } else {
1599 struct intel_null_view null_view;
1600 intel_null_view_init(&null_view, cmd->dev);
1601
1602 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1603 GEN6_ALIGNMENT_SURFACE_STATE,
1604 null_view.cmd_len, null_view.cmd);
1605 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001606 }
1607 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001608 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001609 {
1610 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001611 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001612
Chia-I Wu00b51a82014-09-09 12:07:37 +08001613 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001614 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001615 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001616
Chia-I Wu72292b72014-09-09 10:48:33 +08001617 cmd_reserve_reloc(cmd, 1);
1618 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1619 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001620 }
1621 break;
1622 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001623 {
1624 const struct intel_dset *dset = cmd->bind.dset.graphics;
1625 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1626 const struct intel_dset_slot *dset_slot =
1627 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001628 const uint32_t reloc_flags =
1629 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001630
1631 switch (dset_slot->type) {
1632 case INTEL_DSET_SLOT_IMG_VIEW:
1633 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001634 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001635 dset_slot->u.img_view->cmd_len,
1636 dset_slot->u.img_view->cmd);
1637
1638 cmd_reserve_reloc(cmd, 1);
1639 cmd_surface_reloc(cmd, offset, 1,
1640 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001641 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001642 break;
1643 case INTEL_DSET_SLOT_MEM_VIEW:
1644 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001645 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001646 dset_slot->u.mem_view.cmd_len,
1647 dset_slot->u.mem_view.cmd);
1648
1649 cmd_reserve_reloc(cmd, 1);
1650 cmd_surface_reloc(cmd, offset, 1,
1651 dset_slot->u.mem_view.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001652 dset_slot->u.mem_view.cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001653 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001654 case INTEL_DSET_SLOT_SAMPLER:
1655 assert(0 == cmd->bind.dset.graphics_offset);
1656
1657 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001658 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001659 16, dset_slot->u.sampler->cmd);
1660 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001661 default:
1662 assert(!"unexpected dset slot type");
1663 break;
1664 }
1665 }
1666 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001667 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001668 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001669 break;
1670 }
1671
Chia-I Wu72292b72014-09-09 10:48:33 +08001672 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001673 }
1674
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001675 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001676 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001677 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001678}
1679
Chia-I Wu1d125092014-10-08 08:49:38 +08001680static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1681{
1682 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001683 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1684 uint32_t *dw;
1685 XGL_UINT pos, i;
1686
1687 CMD_ASSERT(cmd, 6, 7.5);
1688
1689 if (!pipeline->vb_count)
1690 return;
1691
1692 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1693
1694 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1695 dw++;
1696 pos++;
1697
1698 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001699 assert(pipeline->vb[i].strideInBytes <= 2048);
1700
1701 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1702 pipeline->vb[i].strideInBytes;
1703
1704 if (cmd_gen(cmd) >= INTEL_GEN(7))
1705 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1706
1707 switch (pipeline->vb[i].stepRate) {
1708 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1709 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1710 dw[3] = 0;
1711 break;
1712 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1713 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1714 dw[3] = 1;
1715 break;
1716 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1717 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1718 dw[3] = 0;
1719 break;
1720 default:
1721 assert(!"unknown step rate");
1722 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1723 dw[3] = 0;
1724 break;
1725 }
1726
Chia-I Wu3b04af52014-11-08 10:48:20 +08001727 if (cmd->bind.vertex.mem[i]) {
1728 const struct intel_mem *mem = cmd->bind.vertex.mem[i];
1729 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001730
1731 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3b04af52014-11-08 10:48:20 +08001732 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
1733 cmd_batch_reloc(cmd, pos + 2, mem->bo, mem->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001734 } else {
1735 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1736 dw[1] = 0;
1737 dw[2] = 0;
1738 }
1739
1740 dw += 4;
1741 pos += 4;
1742 }
1743}
1744
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001745static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1746{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001747 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1748 const struct intel_pipeline_shader *vs = &pipeline->vs;
1749 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001750 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001751 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001752 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001753 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001754
1755 CMD_ASSERT(cmd, 6, 7.5);
1756
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001757 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001758 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1759 *
1760 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1761 * 128-bit vertex elements to be passed into the payload for each
1762 * vertex."
1763 *
1764 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1765 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001766 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001767 vue_read_len = (vs->in_count + 1) / 2;
1768 if (!vue_read_len)
1769 vue_read_len = 1;
1770
1771 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1772 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1773
1774 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1775 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1776 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001777
1778 dw5 = GEN6_VS_DW5_STATISTICS |
1779 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001780
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001781 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001782 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001783 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001784 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001785
Chia-I Wube0a3d92014-09-02 13:20:59 +08001786 if (pipeline->disable_vs_cache)
1787 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1788
Chia-I Wu784d3042014-12-19 14:30:04 +08001789 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001790 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001791 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001792 dw[2] = dw2;
1793 dw[3] = 0; /* scratch */
1794 dw[4] = dw4;
1795 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001796
1797 if (vs->per_thread_scratch_size)
1798 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001799}
1800
Chia-I Wu625105f2014-10-13 15:35:29 +08001801static void emit_shader_resources(struct intel_cmd *cmd)
1802{
1803 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001804 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001805
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001806 binding_tables[0] = emit_binding_table(cmd,
1807 cmd->bind.pipeline.graphics->vs.rmap);
1808 binding_tables[1] = emit_binding_table(cmd,
1809 cmd->bind.pipeline.graphics->tcs.rmap);
1810 binding_tables[2] = emit_binding_table(cmd,
1811 cmd->bind.pipeline.graphics->tes.rmap);
1812 binding_tables[3] = emit_binding_table(cmd,
1813 cmd->bind.pipeline.graphics->gs.rmap);
1814 binding_tables[4] = emit_binding_table(cmd,
1815 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001816
1817 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1818 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1819 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1820 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1821 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1822
1823 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1824 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001825 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1826 binding_tables[0]);
1827 gen7_3dstate_pointer(cmd,
1828 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1829 binding_tables[1]);
1830 gen7_3dstate_pointer(cmd,
1831 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1832 binding_tables[2]);
1833 gen7_3dstate_pointer(cmd,
1834 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1835 binding_tables[3]);
1836 gen7_3dstate_pointer(cmd,
1837 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1838 binding_tables[4]);
1839
1840 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001841 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1842 samplers[0]);
1843 gen7_3dstate_pointer(cmd,
1844 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1845 samplers[1]);
1846 gen7_3dstate_pointer(cmd,
1847 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1848 samplers[2]);
1849 gen7_3dstate_pointer(cmd,
1850 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1851 samplers[3]);
1852 gen7_3dstate_pointer(cmd,
1853 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1854 samplers[4]);
1855 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001856 assert(!binding_tables[1] && !binding_tables[2]);
1857 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1858 binding_tables[0], binding_tables[3], binding_tables[4]);
1859
Chia-I Wu625105f2014-10-13 15:35:29 +08001860 assert(!samplers[1] && !samplers[2]);
1861 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1862 samplers[0], samplers[3], samplers[4]);
1863 }
1864}
1865
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001866static void emit_rt(struct intel_cmd *cmd)
1867{
1868 cmd_wa_gen6_pre_depth_stall_write(cmd);
1869 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1870 cmd->bind.att.height);
1871}
1872
1873static void emit_ds(struct intel_cmd *cmd)
1874{
1875 const struct intel_ds_view *ds = cmd->bind.att.ds;
1876
1877 if (!ds) {
1878 /* all zeros */
1879 static const struct intel_ds_view null_ds;
1880 ds = &null_ds;
1881 }
1882
1883 cmd_wa_gen6_pre_ds_flush(cmd);
1884 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1885 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1886 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1887
1888 if (cmd_gen(cmd) >= INTEL_GEN(7))
1889 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1890 else
1891 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1892}
1893
Chia-I Wua57761b2014-10-14 14:27:44 +08001894static uint32_t emit_shader(struct intel_cmd *cmd,
1895 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001896{
Chia-I Wua57761b2014-10-14 14:27:44 +08001897 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1898 uint32_t offset;
1899 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001900
Chia-I Wua57761b2014-10-14 14:27:44 +08001901 /* see if the shader is already in the cache */
1902 for (i = 0; i < cache->used; i++) {
1903 if (cache->entries[i].shader == (const void *) shader)
1904 return cache->entries[i].kernel_offset;
1905 }
1906
1907 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1908
1909 /* grow the cache if full */
1910 if (cache->used >= cache->count) {
1911 const XGL_UINT count = cache->count + 16;
1912 void *entries;
1913
1914 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1915 XGL_SYSTEM_ALLOC_INTERNAL);
1916 if (entries) {
1917 if (cache->entries) {
1918 memcpy(entries, cache->entries,
1919 sizeof(cache->entries[0]) * cache->used);
1920 icd_free(cache->entries);
1921 }
1922
1923 cache->entries = entries;
1924 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001925 }
1926 }
1927
Chia-I Wua57761b2014-10-14 14:27:44 +08001928 /* add the shader to the cache */
1929 if (cache->used < cache->count) {
1930 cache->entries[cache->used].shader = (const void *) shader;
1931 cache->entries[cache->used].kernel_offset = offset;
1932 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001933 }
1934
Chia-I Wua57761b2014-10-14 14:27:44 +08001935 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001936}
1937
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001938static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001939{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001940 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001941
Chia-I Wu8370b402014-08-29 12:28:37 +08001942 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1943 cmd_wa_gen6_pre_depth_stall_write(cmd);
1944 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1945 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1946 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1947 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001948
1949 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001950 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001951 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001952
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001953 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001954 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001955 }
1956 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001957 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001958 }
1959 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001960 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1961 }
1962 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1963 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1964 }
1965 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1966 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001967 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001968
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001969 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1970 gen7_3DSTATE_GS(cmd);
1971 } else {
1972 gen6_3DSTATE_GS(cmd);
1973 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001974
Chia-I Wu8370b402014-08-29 12:28:37 +08001975 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1976 cmd_wa_gen7_post_command_cs_stall(cmd);
1977 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1978 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001979}
1980
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001981static void emit_bounded_states(struct intel_cmd *cmd)
1982{
1983 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1984
1985 emit_graphics_pipeline(cmd);
1986
1987 emit_rt(cmd);
1988 emit_ds(cmd);
1989
1990 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1991 gen7_cc_states(cmd);
1992 gen7_viewport_states(cmd);
1993
1994 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1995 &cmd->bind.pipeline.graphics->vs);
1996 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1997 &cmd->bind.pipeline.graphics->fs);
1998
1999 gen6_3DSTATE_CLIP(cmd);
2000 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002001 gen7_3DSTATE_WM(cmd);
2002 gen7_3DSTATE_PS(cmd);
2003 } else {
2004 gen6_cc_states(cmd);
2005 gen6_viewport_states(cmd);
2006
2007 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2008 &cmd->bind.pipeline.graphics->vs);
2009 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2010 &cmd->bind.pipeline.graphics->fs);
2011
2012 gen6_3DSTATE_CLIP(cmd);
2013 gen6_3DSTATE_SF(cmd);
2014 gen6_3DSTATE_WM(cmd);
2015 }
2016
2017 emit_shader_resources(cmd);
2018
2019 cmd_wa_gen6_pre_depth_stall_write(cmd);
2020 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2021
2022 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2023 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2024
2025 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2026 gen6_3DSTATE_VS(cmd);
2027}
2028
Chia-I Wu6032b892014-10-17 14:47:18 +08002029static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2030{
2031 const struct intel_cmd_meta *meta = cmd->bind.meta;
2032 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2033
2034 CMD_ASSERT(cmd, 6, 7.5);
2035
2036 blend_offset = 0;
2037 ds_offset = 0;
2038 cc_offset = 0;
2039 cc_vp_offset = 0;
2040
Chia-I Wu29e6f502014-11-24 14:27:29 +08002041 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002042 /* BLEND_STATE */
2043 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002044 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002045 dw[0] = 0;
2046 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2047 }
2048
Chia-I Wu29e6f502014-11-24 14:27:29 +08002049 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2050 if (meta->ds.state) {
2051 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002052
Chia-I Wu29e6f502014-11-24 14:27:29 +08002053 /* DEPTH_STENCIL_STATE */
2054 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002055
Chia-I Wu29e6f502014-11-24 14:27:29 +08002056 /* COLOR_CALC_STATE */
2057 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2058 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002059
Chia-I Wu29e6f502014-11-24 14:27:29 +08002060 /* CC_VIEWPORT */
2061 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002062 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002063 dw[0] = u_fui(0.0f);
2064 dw[1] = u_fui(1.0f);
2065 } else {
2066 /* DEPTH_STENCIL_STATE */
2067 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002068 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002069 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2070 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2071 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002072 }
2073
2074 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2075 gen7_3dstate_pointer(cmd,
2076 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2077 blend_offset);
2078 gen7_3dstate_pointer(cmd,
2079 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2080 ds_offset);
2081 gen7_3dstate_pointer(cmd,
2082 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2083
2084 gen7_3dstate_pointer(cmd,
2085 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2086 cc_vp_offset);
2087 } else {
2088 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002089 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002090
2091 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2092 cmd_batch_pointer(cmd, 4, &dw);
2093 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2094 GEN6_PTR_VP_DW0_CC_CHANGED;
2095 dw[1] = 0;
2096 dw[2] = 0;
2097 dw[3] = cc_vp_offset;
2098 }
2099}
2100
2101static void gen6_meta_surface_states(struct intel_cmd *cmd)
2102{
2103 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002104 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002105 uint32_t offset;
2106
2107 CMD_ASSERT(cmd, 6, 7.5);
2108
Chia-I Wu29e6f502014-11-24 14:27:29 +08002109 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2110 return;
2111
Chia-I Wu005c47c2014-10-22 13:49:13 +08002112 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002113 if (meta->src.valid) {
2114 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002115 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002116 meta->src.surface_len, meta->src.surface);
2117
2118 cmd_reserve_reloc(cmd, 1);
2119 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2120 cmd_surface_reloc_writer(cmd, offset, 1,
2121 meta->src.reloc_target, meta->src.reloc_offset);
2122 } else {
2123 cmd_surface_reloc(cmd, offset, 1,
2124 (struct intel_bo *) meta->src.reloc_target,
2125 meta->src.reloc_offset, meta->src.reloc_flags);
2126 }
2127
Chia-I Wu005c47c2014-10-22 13:49:13 +08002128 binding_table[0] = offset;
2129 }
2130 if (meta->dst.valid) {
2131 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002132 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002133 meta->dst.surface_len, meta->dst.surface);
2134
2135 cmd_reserve_reloc(cmd, 1);
2136 cmd_surface_reloc(cmd, offset, 1,
2137 (struct intel_bo *) meta->dst.reloc_target,
2138 meta->dst.reloc_offset, meta->dst.reloc_flags);
2139
2140 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002141 }
2142
2143 /* BINDING_TABLE */
2144 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002145 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002146 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002147
2148 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002149 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2150 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2151 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2152 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002153 } else {
2154 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002155 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2156 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2157 else
2158 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002159 }
2160}
2161
2162static void gen6_meta_urb(struct intel_cmd *cmd)
2163{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002164 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002165 uint32_t *dw;
2166
2167 CMD_ASSERT(cmd, 6, 6);
2168
2169 /* 3DSTATE_URB */
2170 cmd_batch_pointer(cmd, 3, &dw);
2171 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002172 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002173 dw[2] = 0;
2174}
2175
2176static void gen7_meta_urb(struct intel_cmd *cmd)
2177{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002178 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002179 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002180 uint32_t *dw;
2181
2182 CMD_ASSERT(cmd, 7, 7.5);
2183
2184 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2185 cmd_batch_pointer(cmd, 10, &dw);
2186
2187 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002188 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002189 dw += 2;
2190
2191 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2192 dw[1] = 0;
2193 dw += 2;
2194
2195 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2196 dw[1] = 0;
2197 dw += 2;
2198
2199 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2200 dw[1] = 0;
2201 dw += 2;
2202
2203 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002204 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002205
2206 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2207
Chia-I Wu24aa1022014-11-25 11:53:19 +08002208 switch (cmd_gen(cmd)) {
2209 case INTEL_GEN(7.5):
2210 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2211 break;
2212 case INTEL_GEN(7):
2213 default:
2214 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2215 break;
2216 }
2217
Chia-I Wu6032b892014-10-17 14:47:18 +08002218 /* 3DSTATE_URB_x */
2219 cmd_batch_pointer(cmd, 8, &dw);
2220
2221 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2222 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002223 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002224 dw += 2;
2225
2226 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2227 dw[1] = 0;
2228 dw += 2;
2229
2230 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2231 dw[1] = 0;
2232 dw += 2;
2233
2234 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2235 dw[1] = 0;
2236 dw += 2;
2237}
2238
2239static void gen6_meta_vf(struct intel_cmd *cmd)
2240{
2241 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002242 uint32_t vb_start, vb_end, vb_stride;
2243 int ve_format, ve_z_source;
2244 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002245 XGL_UINT pos;
2246
2247 CMD_ASSERT(cmd, 6, 7.5);
2248
Chia-I Wu29e6f502014-11-24 14:27:29 +08002249 switch (meta->mode) {
2250 case INTEL_CMD_META_VS_POINTS:
2251 cmd_batch_pointer(cmd, 3, &dw);
2252 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2253 dw[1] = GEN6_VE_STATE_DW0_VALID;
2254 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2255 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2256 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2257 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2258 return;
2259 break;
2260 case INTEL_CMD_META_FS_RECT:
2261 {
2262 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002263
Chia-I Wu29e6f502014-11-24 14:27:29 +08002264 vertices[0][0] = meta->dst.x + meta->width;
2265 vertices[0][1] = meta->dst.y + meta->height;
2266 vertices[1][0] = meta->dst.x;
2267 vertices[1][1] = meta->dst.y + meta->height;
2268 vertices[2][0] = meta->dst.x;
2269 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002270
Chia-I Wu29e6f502014-11-24 14:27:29 +08002271 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2272 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002273
Chia-I Wu29e6f502014-11-24 14:27:29 +08002274 vb_end = vb_start + sizeof(vertices) - 1;
2275 vb_stride = sizeof(vertices[0]);
2276 ve_z_source = GEN6_VFCOMP_STORE_0;
2277 ve_format = GEN6_FORMAT_R32G32_USCALED;
2278 }
2279 break;
2280 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2281 {
2282 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002283
Chia-I Wu29e6f502014-11-24 14:27:29 +08002284 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2285 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2286 vertices[0][2] = u_uif(meta->clear_val[0]);
2287 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2288 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2289 vertices[1][2] = u_uif(meta->clear_val[0]);
2290 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2291 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2292 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002293
Chia-I Wu29e6f502014-11-24 14:27:29 +08002294 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2295 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002296
Chia-I Wu29e6f502014-11-24 14:27:29 +08002297 vb_end = vb_start + sizeof(vertices) - 1;
2298 vb_stride = sizeof(vertices[0]);
2299 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2300 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2301 }
2302 break;
2303 default:
2304 assert(!"unknown meta mode");
2305 return;
2306 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002307 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002308
2309 /* 3DSTATE_VERTEX_BUFFERS */
2310 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002311
Chia-I Wu6032b892014-10-17 14:47:18 +08002312 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002313 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002314 if (cmd_gen(cmd) >= INTEL_GEN(7))
2315 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2316
2317 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002318 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2319 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002320
2321 dw[4] = 0;
2322
2323 /* 3DSTATE_VERTEX_ELEMENTS */
2324 cmd_batch_pointer(cmd, 5, &dw);
2325 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002326 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002327 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2328 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2329 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2330 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2331 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002332 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002333 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2334 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002335 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002336 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2337}
2338
Chia-I Wu29e6f502014-11-24 14:27:29 +08002339static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002340{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002341 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002342 /* one GPR */
2343 XGL_UINT consts[8];
2344 XGL_UINT const_count;
2345
2346 CMD_ASSERT(cmd, 6, 7.5);
2347
2348 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002349 case INTEL_DEV_META_VS_FILL_MEM:
2350 consts[0] = meta->dst.x;
2351 consts[1] = meta->clear_val[0];
2352 const_count = 2;
2353 break;
2354 case INTEL_DEV_META_VS_COPY_MEM:
2355 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2356 consts[0] = meta->dst.x;
2357 consts[1] = meta->src.x;
2358 const_count = 2;
2359 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002360 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2361 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2362 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2363 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2364 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2365 consts[0] = meta->src.x;
2366 consts[1] = meta->src.y;
2367 consts[2] = meta->width;
2368 consts[3] = meta->dst.x;
2369 const_count = 4;
2370 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002371 default:
2372 assert(!"unknown meta shader id");
2373 const_count = 0;
2374 break;
2375 }
2376
2377 /* this can be skipped but it makes state dumping prettier */
2378 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2379
2380 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2381}
2382
2383static void gen6_meta_vs(struct intel_cmd *cmd)
2384{
2385 const struct intel_cmd_meta *meta = cmd->bind.meta;
2386 const struct intel_pipeline_shader *sh =
2387 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2388 uint32_t offset, *dw;
2389
2390 CMD_ASSERT(cmd, 6, 7.5);
2391
2392 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2393 XGL_UINT cmd_len;
2394
2395 /* 3DSTATE_CONSTANT_VS */
2396 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2397 cmd_batch_pointer(cmd, cmd_len, &dw);
2398 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2399 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2400
2401 /* 3DSTATE_VS */
2402 cmd_batch_pointer(cmd, 6, &dw);
2403 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2404 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2405
2406 return;
2407 }
2408
2409 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2410
2411 /* 3DSTATE_CONSTANT_VS */
2412 offset = gen6_meta_vs_constants(cmd);
2413 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2414 cmd_batch_pointer(cmd, 7, &dw);
2415 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2416 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2417 dw[2] = 0;
2418 dw[3] = offset;
2419 dw[4] = 0;
2420 dw[5] = 0;
2421 dw[6] = 0;
2422 } else {
2423 cmd_batch_pointer(cmd, 5, &dw);
2424 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2425 GEN6_PCB_ANY_DW0_PCB0_VALID;
2426 dw[1] = offset;
2427 dw[2] = 0;
2428 dw[3] = 0;
2429 dw[4] = 0;
2430 }
2431
2432 /* 3DSTATE_VS */
2433 offset = emit_shader(cmd, sh);
2434 cmd_batch_pointer(cmd, 6, &dw);
2435 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2436 dw[1] = offset;
2437 dw[2] = GEN6_THREADDISP_SPF |
2438 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2439 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002440 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002441 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2442 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2443
2444 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2445 GEN6_VS_DW5_VS_ENABLE;
2446 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002447 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002448 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002449 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002450
2451 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002452}
2453
2454static void gen6_meta_disabled(struct intel_cmd *cmd)
2455{
Chia-I Wu6032b892014-10-17 14:47:18 +08002456 uint32_t *dw;
2457
2458 CMD_ASSERT(cmd, 6, 6);
2459
Chia-I Wu6032b892014-10-17 14:47:18 +08002460 /* 3DSTATE_CONSTANT_GS */
2461 cmd_batch_pointer(cmd, 5, &dw);
2462 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2463 dw[1] = 0;
2464 dw[2] = 0;
2465 dw[3] = 0;
2466 dw[4] = 0;
2467
2468 /* 3DSTATE_GS */
2469 cmd_batch_pointer(cmd, 7, &dw);
2470 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2471 dw[1] = 0;
2472 dw[2] = 0;
2473 dw[3] = 0;
2474 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2475 dw[5] = GEN6_GS_DW5_STATISTICS;
2476 dw[6] = 0;
2477
Chia-I Wu6032b892014-10-17 14:47:18 +08002478 /* 3DSTATE_SF */
2479 cmd_batch_pointer(cmd, 20, &dw);
2480 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2481 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2482 memset(&dw[2], 0, 18 * sizeof(*dw));
2483}
2484
2485static void gen7_meta_disabled(struct intel_cmd *cmd)
2486{
2487 uint32_t *dw;
2488
2489 CMD_ASSERT(cmd, 7, 7.5);
2490
Chia-I Wu6032b892014-10-17 14:47:18 +08002491 /* 3DSTATE_CONSTANT_HS */
2492 cmd_batch_pointer(cmd, 7, &dw);
2493 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2494 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2495
2496 /* 3DSTATE_HS */
2497 cmd_batch_pointer(cmd, 7, &dw);
2498 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2499 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2500
2501 /* 3DSTATE_TE */
2502 cmd_batch_pointer(cmd, 4, &dw);
2503 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2504 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2505
2506 /* 3DSTATE_CONSTANT_DS */
2507 cmd_batch_pointer(cmd, 7, &dw);
2508 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2509 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2510
2511 /* 3DSTATE_DS */
2512 cmd_batch_pointer(cmd, 6, &dw);
2513 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2514 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2515
2516 /* 3DSTATE_CONSTANT_GS */
2517 cmd_batch_pointer(cmd, 7, &dw);
2518 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2519 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2520
2521 /* 3DSTATE_GS */
2522 cmd_batch_pointer(cmd, 7, &dw);
2523 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2524 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2525
2526 /* 3DSTATE_STREAMOUT */
2527 cmd_batch_pointer(cmd, 3, &dw);
2528 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2529 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2530
Chia-I Wu6032b892014-10-17 14:47:18 +08002531 /* 3DSTATE_SF */
2532 cmd_batch_pointer(cmd, 7, &dw);
2533 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2534 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2535
2536 /* 3DSTATE_SBE */
2537 cmd_batch_pointer(cmd, 14, &dw);
2538 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2539 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2540 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002541}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002542
Chia-I Wu29e6f502014-11-24 14:27:29 +08002543static void gen6_meta_clip(struct intel_cmd *cmd)
2544{
2545 const struct intel_cmd_meta *meta = cmd->bind.meta;
2546 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002547
Chia-I Wu29e6f502014-11-24 14:27:29 +08002548 /* 3DSTATE_CLIP */
2549 cmd_batch_pointer(cmd, 4, &dw);
2550 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2551 dw[1] = 0;
2552 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2553 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2554 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2555 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002556 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002557 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002558 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002559}
2560
2561static void gen6_meta_wm(struct intel_cmd *cmd)
2562{
2563 const struct intel_cmd_meta *meta = cmd->bind.meta;
2564 uint32_t *dw;
2565
2566 CMD_ASSERT(cmd, 6, 7.5);
2567
2568 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2569
2570 /* 3DSTATE_MULTISAMPLE */
2571 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2572 cmd_batch_pointer(cmd, 4, &dw);
2573 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2574 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2575 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2576 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2577 dw[2] = 0;
2578 dw[3] = 0;
2579 } else {
2580 cmd_batch_pointer(cmd, 3, &dw);
2581 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2582 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2583 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2584 dw[2] = 0;
2585 }
2586
2587 /* 3DSTATE_SAMPLE_MASK */
2588 cmd_batch_pointer(cmd, 2, &dw);
2589 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2590 dw[1] = (1 << meta->samples) - 1;
2591
2592 /* 3DSTATE_DRAWING_RECTANGLE */
2593 cmd_batch_pointer(cmd, 4, &dw);
2594 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2595 dw[1] = meta->dst.y << 16 | meta->dst.x;
2596 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2597 (meta->dst.x + meta->width - 1);
2598 dw[3] = 0;
2599}
2600
2601static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2602{
2603 const struct intel_cmd_meta *meta = cmd->bind.meta;
2604 XGL_UINT offset_x, offset_y;
2605 /* one GPR */
2606 XGL_UINT consts[8];
2607 XGL_UINT const_count;
2608
2609 CMD_ASSERT(cmd, 6, 7.5);
2610
2611 /* underflow is fine here */
2612 offset_x = meta->src.x - meta->dst.x;
2613 offset_y = meta->src.y - meta->dst.y;
2614
2615 switch (meta->shader_id) {
2616 case INTEL_DEV_META_FS_COPY_MEM:
2617 case INTEL_DEV_META_FS_COPY_1D:
2618 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2619 case INTEL_DEV_META_FS_COPY_2D:
2620 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2621 case INTEL_DEV_META_FS_COPY_2D_MS:
2622 consts[0] = offset_x;
2623 consts[1] = offset_y;
2624 consts[2] = meta->src.layer;
2625 consts[3] = meta->src.lod;
2626 const_count = 4;
2627 break;
2628 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2629 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2630 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2631 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2632 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2633 consts[0] = offset_x;
2634 consts[1] = offset_y;
2635 consts[2] = meta->src.layer;
2636 consts[3] = meta->src.lod;
2637 consts[4] = meta->src.x;
2638 consts[5] = meta->width;
2639 const_count = 6;
2640 break;
2641 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2642 consts[0] = offset_x;
2643 consts[1] = offset_y;
2644 consts[2] = meta->width;
2645 const_count = 3;
2646 break;
2647 case INTEL_DEV_META_FS_CLEAR_COLOR:
2648 consts[0] = meta->clear_val[0];
2649 consts[1] = meta->clear_val[1];
2650 consts[2] = meta->clear_val[2];
2651 consts[3] = meta->clear_val[3];
2652 const_count = 4;
2653 break;
2654 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2655 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002656 consts[1] = meta->clear_val[1];
2657 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002658 break;
2659 case INTEL_DEV_META_FS_RESOLVE_2X:
2660 case INTEL_DEV_META_FS_RESOLVE_4X:
2661 case INTEL_DEV_META_FS_RESOLVE_8X:
2662 case INTEL_DEV_META_FS_RESOLVE_16X:
2663 consts[0] = offset_x;
2664 consts[1] = offset_y;
2665 const_count = 2;
2666 break;
2667 default:
2668 assert(!"unknown meta shader id");
2669 const_count = 0;
2670 break;
2671 }
2672
2673 /* this can be skipped but it makes state dumping prettier */
2674 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2675
2676 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2677}
2678
2679static void gen6_meta_ps(struct intel_cmd *cmd)
2680{
2681 const struct intel_cmd_meta *meta = cmd->bind.meta;
2682 const struct intel_pipeline_shader *sh =
2683 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2684 uint32_t offset, *dw;
2685
2686 CMD_ASSERT(cmd, 6, 6);
2687
Chia-I Wu29e6f502014-11-24 14:27:29 +08002688 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2689 /* 3DSTATE_CONSTANT_PS */
2690 cmd_batch_pointer(cmd, 5, &dw);
2691 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2692 dw[1] = 0;
2693 dw[2] = 0;
2694 dw[3] = 0;
2695 dw[4] = 0;
2696
2697 /* 3DSTATE_WM */
2698 cmd_batch_pointer(cmd, 9, &dw);
2699 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2700 dw[1] = 0;
2701 dw[2] = 0;
2702 dw[3] = 0;
2703 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002704 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002705 dw[6] = 0;
2706 dw[7] = 0;
2707 dw[8] = 0;
2708
Chia-I Wu3adf7212014-10-24 15:34:07 +08002709 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002710 }
2711
Chia-I Wu3adf7212014-10-24 15:34:07 +08002712 /* a normal color write */
2713 assert(meta->dst.valid && !sh->uses);
2714
Chia-I Wu6032b892014-10-17 14:47:18 +08002715 /* 3DSTATE_CONSTANT_PS */
2716 offset = gen6_meta_ps_constants(cmd);
2717 cmd_batch_pointer(cmd, 5, &dw);
2718 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2719 GEN6_PCB_ANY_DW0_PCB0_VALID;
2720 dw[1] = offset;
2721 dw[2] = 0;
2722 dw[3] = 0;
2723 dw[4] = 0;
2724
2725 /* 3DSTATE_WM */
2726 offset = emit_shader(cmd, sh);
2727 cmd_batch_pointer(cmd, 9, &dw);
2728 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2729 dw[1] = offset;
2730 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2731 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002732 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002733 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002734 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002735 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002736 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2737
Chia-I Wu6032b892014-10-17 14:47:18 +08002738 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2739 GEN6_WM_DW6_POSOFFSET_NONE |
2740 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2741 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2742 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2743 if (meta->samples > 1) {
2744 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2745 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2746 } else {
2747 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2748 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2749 }
2750 dw[7] = 0;
2751 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002752
2753 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002754}
2755
2756static void gen7_meta_ps(struct intel_cmd *cmd)
2757{
2758 const struct intel_cmd_meta *meta = cmd->bind.meta;
2759 const struct intel_pipeline_shader *sh =
2760 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2761 uint32_t offset, *dw;
2762
2763 CMD_ASSERT(cmd, 7, 7.5);
2764
Chia-I Wu29e6f502014-11-24 14:27:29 +08002765 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2766 /* 3DSTATE_WM */
2767 cmd_batch_pointer(cmd, 3, &dw);
2768 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2769 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2770
2771 /* 3DSTATE_CONSTANT_GS */
2772 cmd_batch_pointer(cmd, 7, &dw);
2773 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2774 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2775
2776 /* 3DSTATE_PS */
2777 cmd_batch_pointer(cmd, 8, &dw);
2778 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2779 dw[1] = 0;
2780 dw[2] = 0;
2781 dw[3] = 0;
2782 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002783 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002784 dw[5] = 0;
2785 dw[6] = 0;
2786 dw[7] = 0;
2787
Chia-I Wu3adf7212014-10-24 15:34:07 +08002788 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002789 }
2790
Chia-I Wu3adf7212014-10-24 15:34:07 +08002791 /* a normal color write */
2792 assert(meta->dst.valid && !sh->uses);
2793
Chia-I Wu6032b892014-10-17 14:47:18 +08002794 /* 3DSTATE_WM */
2795 cmd_batch_pointer(cmd, 3, &dw);
2796 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2797 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2798 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2799 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2800 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2801 dw[2] = 0;
2802
2803 /* 3DSTATE_CONSTANT_PS */
2804 offset = gen6_meta_ps_constants(cmd);
2805 cmd_batch_pointer(cmd, 7, &dw);
2806 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2807 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2808 dw[2] = 0;
2809 dw[3] = offset;
2810 dw[4] = 0;
2811 dw[5] = 0;
2812 dw[6] = 0;
2813
2814 /* 3DSTATE_PS */
2815 offset = emit_shader(cmd, sh);
2816 cmd_batch_pointer(cmd, 8, &dw);
2817 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2818 dw[1] = offset;
2819 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2820 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002821 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002822
2823 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2824 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002825 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2826
2827 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002828 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002829 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002830 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002831 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002832 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002833
2834 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2835 dw[6] = 0;
2836 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002837
2838 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002839}
2840
2841static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2842{
2843 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002844 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002845
2846 CMD_ASSERT(cmd, 6, 7.5);
2847
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002848 if (!ds) {
2849 /* all zeros */
2850 static const struct intel_ds_view null_ds;
2851 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002852 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002853
2854 cmd_wa_gen6_pre_ds_flush(cmd);
2855 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2856 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2857 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2858
2859 if (cmd_gen(cmd) >= INTEL_GEN(7))
2860 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2861 else
2862 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002863}
2864
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002865static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2866 const struct intel_pipeline *pipeline)
2867{
2868 cmd->bind.pipeline.graphics = pipeline;
2869}
2870
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002871static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2872 const struct intel_pipeline *pipeline)
2873{
2874 cmd->bind.pipeline.compute = pipeline;
2875}
2876
2877static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2878 const struct intel_pipeline_delta *delta)
2879{
2880 cmd->bind.pipeline.graphics_delta = delta;
2881}
2882
2883static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2884 const struct intel_pipeline_delta *delta)
2885{
2886 cmd->bind.pipeline.compute_delta = delta;
2887}
2888
2889static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2890 const struct intel_dset *dset,
2891 XGL_UINT slot_offset)
2892{
2893 cmd->bind.dset.graphics = dset;
2894 cmd->bind.dset.graphics_offset = slot_offset;
2895}
2896
2897static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2898 const struct intel_dset *dset,
2899 XGL_UINT slot_offset)
2900{
2901 cmd->bind.dset.compute = dset;
2902 cmd->bind.dset.compute_offset = slot_offset;
2903}
2904
2905static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2906 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2907{
2908 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2909}
2910
2911static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2912 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2913{
2914 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2915}
2916
Chia-I Wu3b04af52014-11-08 10:48:20 +08002917static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2918 const struct intel_mem *mem,
2919 XGL_GPU_SIZE offset, XGL_UINT binding)
2920{
2921 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2922 cmd->result = XGL_ERROR_UNKNOWN;
2923 return;
2924 }
2925
2926 cmd->bind.vertex.mem[binding] = mem;
2927 cmd->bind.vertex.offset[binding] = offset;
2928}
2929
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002930static void cmd_bind_index_data(struct intel_cmd *cmd,
2931 const struct intel_mem *mem,
2932 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2933{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002934 cmd->bind.index.mem = mem;
2935 cmd->bind.index.offset = offset;
2936 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002937}
2938
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002939static void cmd_bind_attachments(struct intel_cmd *cmd,
2940 XGL_UINT rt_count,
2941 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2942 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002943{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002944 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002945 XGL_UINT i;
2946
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002947 for (i = 0; i < rt_count; i++) {
2948 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002949 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002950 const struct intel_layout *layout = &rt->img->layout;
2951
2952 if (i == 0) {
2953 width = layout->width0;
2954 height = layout->height0;
2955 } else {
2956 if (width > layout->width0)
2957 width = layout->width0;
2958 if (height > layout->height0)
2959 height = layout->height0;
2960 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002961
2962 cmd->bind.att.rt[i] = rt;
2963 }
2964
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002965 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002966
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002967 if (ds_info) {
2968 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002969
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002970 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2971 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002972
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002973 if (width > layout->width0)
2974 width = layout->width0;
2975 if (height > layout->height0)
2976 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002977 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002978 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002979 }
2980
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002981 cmd->bind.att.width = width;
2982 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002983}
2984
2985static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2986 const struct intel_viewport_state *state)
2987{
2988 cmd->bind.state.viewport = state;
2989}
2990
2991static void cmd_bind_raster_state(struct intel_cmd *cmd,
2992 const struct intel_raster_state *state)
2993{
2994 cmd->bind.state.raster = state;
2995}
2996
2997static void cmd_bind_ds_state(struct intel_cmd *cmd,
2998 const struct intel_ds_state *state)
2999{
3000 cmd->bind.state.ds = state;
3001}
3002
3003static void cmd_bind_blend_state(struct intel_cmd *cmd,
3004 const struct intel_blend_state *state)
3005{
3006 cmd->bind.state.blend = state;
3007}
3008
3009static void cmd_bind_msaa_state(struct intel_cmd *cmd,
3010 const struct intel_msaa_state *state)
3011{
3012 cmd->bind.state.msaa = state;
3013}
3014
3015static void cmd_draw(struct intel_cmd *cmd,
3016 XGL_UINT vertex_start,
3017 XGL_UINT vertex_count,
3018 XGL_UINT instance_start,
3019 XGL_UINT instance_count,
3020 bool indexed,
3021 XGL_UINT vertex_base)
3022{
3023 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
3024
3025 emit_bounded_states(cmd);
3026
3027 if (indexed) {
3028 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3029 cmd->result = XGL_ERROR_UNKNOWN;
3030
3031 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3032 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3033 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003034 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3035 cmd->bind.index.offset, cmd->bind.index.type,
3036 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003037 } else {
3038 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3039 cmd->bind.index.offset, cmd->bind.index.type,
3040 p->primitive_restart);
3041 }
3042 } else {
3043 assert(!vertex_base);
3044 }
3045
3046 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3047 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3048 vertex_start, instance_count, instance_start, vertex_base);
3049 } else {
3050 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3051 vertex_start, instance_count, instance_start, vertex_base);
3052 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003053
Chia-I Wu707a29e2014-08-27 12:51:47 +08003054 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003055 /* need to re-emit all workarounds */
3056 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003057
3058 if (intel_debug & INTEL_DEBUG_NOCACHE)
3059 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003060}
3061
Chia-I Wuc14d1562014-10-17 09:49:22 +08003062void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3063{
Chia-I Wu6032b892014-10-17 14:47:18 +08003064 cmd->bind.meta = meta;
3065
3066 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003067 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003068
3069 gen6_meta_dynamic_states(cmd);
3070 gen6_meta_surface_states(cmd);
3071
3072 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3073 gen7_meta_urb(cmd);
3074 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003075 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003076 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003077 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003078 gen6_meta_wm(cmd);
3079 gen7_meta_ps(cmd);
3080 gen6_meta_depth_buffer(cmd);
3081
3082 cmd_wa_gen7_post_command_cs_stall(cmd);
3083 cmd_wa_gen7_post_command_depth_stall(cmd);
3084
Chia-I Wu29e6f502014-11-24 14:27:29 +08003085 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3086 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003087 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003088 } else {
3089 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3090 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003091 } else {
3092 gen6_meta_urb(cmd);
3093 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003094 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003095 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003096 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003097 gen6_meta_wm(cmd);
3098 gen6_meta_ps(cmd);
3099 gen6_meta_depth_buffer(cmd);
3100
Chia-I Wu29e6f502014-11-24 14:27:29 +08003101 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3102 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003103 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003104 } else {
3105 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3106 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003107 }
3108
3109 cmd->bind.draw_count++;
3110 /* need to re-emit all workarounds */
3111 cmd->bind.wa_flags = 0;
3112
3113 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003114
3115 if (intel_debug & INTEL_DEBUG_NOCACHE)
3116 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003117}
3118
Chia-I Wub2755562014-08-20 13:38:52 +08003119XGL_VOID XGLAPI intelCmdBindPipeline(
3120 XGL_CMD_BUFFER cmdBuffer,
3121 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3122 XGL_PIPELINE pipeline)
3123{
3124 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3125
3126 switch (pipelineBindPoint) {
3127 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003128 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003129 break;
3130 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003131 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003132 break;
3133 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003134 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003135 break;
3136 }
3137}
3138
3139XGL_VOID XGLAPI intelCmdBindPipelineDelta(
3140 XGL_CMD_BUFFER cmdBuffer,
3141 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3142 XGL_PIPELINE_DELTA delta)
3143{
3144 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3145
3146 switch (pipelineBindPoint) {
3147 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003148 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003149 break;
3150 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003151 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003152 break;
3153 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003154 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003155 break;
3156 }
3157}
3158
3159XGL_VOID XGLAPI intelCmdBindStateObject(
3160 XGL_CMD_BUFFER cmdBuffer,
3161 XGL_STATE_BIND_POINT stateBindPoint,
3162 XGL_STATE_OBJECT state)
3163{
3164 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3165
3166 switch (stateBindPoint) {
3167 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003168 cmd_bind_viewport_state(cmd,
3169 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003170 break;
3171 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003172 cmd_bind_raster_state(cmd,
3173 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003174 break;
3175 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003176 cmd_bind_ds_state(cmd,
3177 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003178 break;
3179 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003180 cmd_bind_blend_state(cmd,
3181 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003182 break;
3183 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003184 cmd_bind_msaa_state(cmd,
3185 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003186 break;
3187 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003188 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003189 break;
3190 }
3191}
3192
3193XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3194 XGL_CMD_BUFFER cmdBuffer,
3195 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3196 XGL_UINT index,
3197 XGL_DESCRIPTOR_SET descriptorSet,
3198 XGL_UINT slotOffset)
3199{
3200 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3201 struct intel_dset *dset = intel_dset(descriptorSet);
3202
3203 assert(!index);
3204
3205 switch (pipelineBindPoint) {
3206 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003207 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003208 break;
3209 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003210 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003211 break;
3212 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003213 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003214 break;
3215 }
3216}
3217
3218XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3219 XGL_CMD_BUFFER cmdBuffer,
3220 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3221 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3222{
3223 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3224
3225 switch (pipelineBindPoint) {
3226 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003227 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003228 break;
3229 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003230 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003231 break;
3232 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003233 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003234 break;
3235 }
3236}
3237
Chia-I Wu3b04af52014-11-08 10:48:20 +08003238XGL_VOID XGLAPI intelCmdBindVertexData(
3239 XGL_CMD_BUFFER cmdBuffer,
3240 XGL_GPU_MEMORY mem_,
3241 XGL_GPU_SIZE offset,
3242 XGL_UINT binding)
3243{
3244 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3245 struct intel_mem *mem = intel_mem(mem_);
3246
3247 cmd_bind_vertex_data(cmd, mem, offset, binding);
3248}
3249
Chia-I Wub2755562014-08-20 13:38:52 +08003250XGL_VOID XGLAPI intelCmdBindIndexData(
3251 XGL_CMD_BUFFER cmdBuffer,
3252 XGL_GPU_MEMORY mem_,
3253 XGL_GPU_SIZE offset,
3254 XGL_INDEX_TYPE indexType)
3255{
3256 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3257 struct intel_mem *mem = intel_mem(mem_);
3258
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003259 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003260}
3261
3262XGL_VOID XGLAPI intelCmdBindAttachments(
3263 XGL_CMD_BUFFER cmdBuffer,
3264 XGL_UINT colorAttachmentCount,
3265 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3266 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3267{
3268 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003269
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003270 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3271 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003272}
3273
3274XGL_VOID XGLAPI intelCmdDraw(
3275 XGL_CMD_BUFFER cmdBuffer,
3276 XGL_UINT firstVertex,
3277 XGL_UINT vertexCount,
3278 XGL_UINT firstInstance,
3279 XGL_UINT instanceCount)
3280{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003281 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003282
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003283 cmd_draw(cmd, firstVertex, vertexCount,
3284 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003285}
3286
3287XGL_VOID XGLAPI intelCmdDrawIndexed(
3288 XGL_CMD_BUFFER cmdBuffer,
3289 XGL_UINT firstIndex,
3290 XGL_UINT indexCount,
3291 XGL_INT vertexOffset,
3292 XGL_UINT firstInstance,
3293 XGL_UINT instanceCount)
3294{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003295 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003296
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003297 cmd_draw(cmd, firstIndex, indexCount,
3298 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003299}
3300
3301XGL_VOID XGLAPI intelCmdDrawIndirect(
3302 XGL_CMD_BUFFER cmdBuffer,
3303 XGL_GPU_MEMORY mem,
3304 XGL_GPU_SIZE offset,
3305 XGL_UINT32 count,
3306 XGL_UINT32 stride)
3307{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003308 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3309
3310 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003311}
3312
3313XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3314 XGL_CMD_BUFFER cmdBuffer,
3315 XGL_GPU_MEMORY mem,
3316 XGL_GPU_SIZE offset,
3317 XGL_UINT32 count,
3318 XGL_UINT32 stride)
3319{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003320 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3321
3322 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003323}
3324
3325XGL_VOID XGLAPI intelCmdDispatch(
3326 XGL_CMD_BUFFER cmdBuffer,
3327 XGL_UINT x,
3328 XGL_UINT y,
3329 XGL_UINT z)
3330{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003331 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3332
3333 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003334}
3335
3336XGL_VOID XGLAPI intelCmdDispatchIndirect(
3337 XGL_CMD_BUFFER cmdBuffer,
3338 XGL_GPU_MEMORY mem,
3339 XGL_GPU_SIZE offset)
3340{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003341 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3342
3343 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003344}