blob: d986d90339cf632c8a5b580f01e33c558921526c [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 Wu714df452015-01-01 07:55:04 +080031#include "buf.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
109 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
221 case XGL_INDEX_8:
222 supported = (p->primitive_restart_index != 0xffu);
223 break;
224 case XGL_INDEX_16:
225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
227 case XGL_INDEX_32:
228 supported = (p->primitive_restart_index != 0xffffffffu);
229 break;
230 default:
231 supported = false;
232 break;
233 }
234
235 return supported;
236}
237
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800239 const struct intel_buf *buf,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800240 XGL_GPU_SIZE offset,
241 XGL_INDEX_TYPE type,
242 bool enable_cut_index)
243{
244 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800247 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
260 case XGL_INDEX_8:
261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
264 case XGL_INDEX_16:
265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
268 case XGL_INDEX_32:
269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
273 cmd->result = XGL_ERROR_INVALID_VALUE;
274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
279 cmd->result = XGL_ERROR_INVALID_VALUE;
280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600312
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800313static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
314{
315 const uint8_t cmd_len = 7;
316 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800318
319 CMD_ASSERT(cmd, 6, 6);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 cmd_batch_pointer(cmd, cmd_len, &dw);
340 dw[0] = dw0;
341 dw[1] = 0;
342 dw[2] = 0;
343 dw[3] = 0;
344 dw[4] = 0;
345 dw[5] = GEN6_GS_DW5_STATISTICS;
346 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800347}
348
Chia-I Wud88e02d2014-08-25 10:56:13 +0800349static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
350 XGL_UINT width, XGL_UINT height)
351{
352 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800353 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800355 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800356
357 CMD_ASSERT(cmd, 6, 7.5);
358
Chia-I Wu72292b72014-09-09 10:48:33 +0800359 cmd_batch_pointer(cmd, cmd_len, &dw);
360 dw[0] = dw0;
361
Chia-I Wud88e02d2014-08-25 10:56:13 +0800362 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 dw[1] = 0;
364 dw[2] = (height - 1) << 16 |
365 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800366 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800367 dw[1] = 1;
368 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800369 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800370
371 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800372}
373
Chia-I Wu8016a172014-08-29 18:31:32 +0800374static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
375 uint32_t body[6])
376{
377 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800379 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 |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700389 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800390
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:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700403 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
Tony Barbourfa6cac72015-01-16 14:27:35 -0700411 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800412
Tony Barbourfa6cac72015-01-16 14:27:35 -0700413 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800414 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
Tony Barbourfa6cac72015-01-16 14:27:35 -0700421 if (pipeline->scissor_enable)
Chia-I Wu8016a172014-08-29 18:31:32 +0800422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700425 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
Chia-I Wu8016a172014-08-29 18:31:32 +0800426 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;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700438 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
439 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
440 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800441}
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;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700501 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800502 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800503
504 CMD_ASSERT(cmd, 6, 7.5);
505
506 dw1 = GEN6_CLIP_DW1_STATISTICS;
507 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
508 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
509 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700510 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800511 }
512
513 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
514 GEN6_CLIP_DW2_XY_TEST_ENABLE |
515 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700516 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800517 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
518 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
519 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
520
521 if (pipeline->rasterizerDiscardEnable)
522 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
523 else
524 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
525
526 if (pipeline->depthClipEnable)
527 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
528
529 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
530 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
531 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
532 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
533
534 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
535 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
536 (viewport->viewport_count - 1);
537
Chia-I Wu72292b72014-09-09 10:48:33 +0800538 cmd_batch_pointer(cmd, cmd_len, &dw);
539 dw[0] = dw0;
540 dw[1] = dw1;
541 dw[2] = dw2;
542 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800543}
544
Chia-I Wu784d3042014-12-19 14:30:04 +0800545static void gen6_add_scratch_space(struct intel_cmd *cmd,
546 XGL_UINT batch_pos,
547 const struct intel_pipeline *pipeline,
548 const struct intel_pipeline_shader *sh)
549{
550 int scratch_space;
551
552 CMD_ASSERT(cmd, 6, 7.5);
553
554 assert(sh->per_thread_scratch_size &&
555 sh->per_thread_scratch_size % 1024 == 0 &&
556 u_is_pow2(sh->per_thread_scratch_size) &&
557 sh->scratch_offset % 1024 == 0);
558 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
559
560 cmd_reserve_reloc(cmd, 1);
561 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
562 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
563}
564
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800565static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
566{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800567 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800568 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800569 const uint8_t cmd_len = 9;
Chia-I Wu784d3042014-12-19 14:30:04 +0800570 XGL_UINT pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800571 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572
573 CMD_ASSERT(cmd, 6, 6);
574
575 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
576
577 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
578 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
579
580 dw4 = GEN6_WM_DW4_STATISTICS |
581 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
582 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
583 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
584
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800585 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800586 GEN6_WM_DW5_PS_ENABLE |
587 GEN6_WM_DW5_8_PIXEL_DISPATCH;
588
589 if (fs->uses & INTEL_SHADER_USE_KILL ||
590 pipeline->cb_state.alphaToCoverageEnable)
591 dw5 |= GEN6_WM_DW5_PS_KILL;
592
Cody Northrope238deb2015-01-26 14:41:36 -0700593 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800594 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
595 if (fs->uses & INTEL_SHADER_USE_DEPTH)
596 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
597 if (fs->uses & INTEL_SHADER_USE_W)
598 dw5 |= GEN6_WM_DW5_PS_USE_W;
599
600 if (pipeline->cb_state.dualSourceBlendEnable)
601 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
602
603 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
604 GEN6_WM_DW6_POSOFFSET_NONE |
605 GEN6_WM_DW6_ZW_INTERP_PIXEL |
606 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
607 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
608
Tony Barbourfa6cac72015-01-16 14:27:35 -0700609 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800610 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
611 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
612 } else {
613 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
614 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
615 }
616
Chia-I Wu784d3042014-12-19 14:30:04 +0800617 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800618 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800619 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800620 dw[2] = dw2;
621 dw[3] = 0; /* scratch */
622 dw[4] = dw4;
623 dw[5] = dw5;
624 dw[6] = dw6;
625 dw[7] = 0; /* kernel 1 */
626 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800627
628 if (fs->per_thread_scratch_size)
629 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800630}
631
632static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
633{
634 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800635 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800636 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800637 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638
639 CMD_ASSERT(cmd, 7, 7.5);
640
641 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
642
643 dw1 = GEN7_WM_DW1_STATISTICS |
644 GEN7_WM_DW1_PS_ENABLE |
645 GEN7_WM_DW1_ZW_INTERP_PIXEL |
646 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
647 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
648
649 if (fs->uses & INTEL_SHADER_USE_KILL ||
650 pipeline->cb_state.alphaToCoverageEnable)
651 dw1 |= GEN7_WM_DW1_PS_KILL;
652
Cody Northrope238deb2015-01-26 14:41:36 -0700653 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
654
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800655 if (fs->uses & INTEL_SHADER_USE_DEPTH)
656 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
657 if (fs->uses & INTEL_SHADER_USE_W)
658 dw1 |= GEN7_WM_DW1_PS_USE_W;
659
660 dw2 = 0;
661
Tony Barbourfa6cac72015-01-16 14:27:35 -0700662 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800663 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
664 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
665 } else {
666 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
667 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
668 }
669
Chia-I Wu72292b72014-09-09 10:48:33 +0800670 cmd_batch_pointer(cmd, cmd_len, &dw);
671 dw[0] = dw0;
672 dw[1] = dw1;
673 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800674}
675
676static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
677{
678 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800679 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800680 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800681 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +0800682 XGL_UINT pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800683
684 CMD_ASSERT(cmd, 7, 7.5);
685
686 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
687
688 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
689 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
690
691 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
692 GEN7_PS_DW4_8_PIXEL_DISPATCH;
693
694 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800695 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700696 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800698 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800699 }
700
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800701 if (fs->in_count)
702 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
703
704 if (pipeline->cb_state.dualSourceBlendEnable)
705 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
706
707 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
708 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
709 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
710
Chia-I Wu784d3042014-12-19 14:30:04 +0800711 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800712 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800713 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800714 dw[2] = dw2;
715 dw[3] = 0; /* scratch */
716 dw[4] = dw4;
717 dw[5] = dw5;
718 dw[6] = 0; /* kernel 1 */
719 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800720
721 if (fs->per_thread_scratch_size)
722 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723}
724
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800725static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
726 const struct intel_ds_view *view)
727{
728 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800729 uint32_t dw0, *dw;
730 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800731
732 CMD_ASSERT(cmd, 6, 7.5);
733
734 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800735 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
736 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800737 dw0 |= (cmd_len - 2);
738
Chia-I Wu72292b72014-09-09 10:48:33 +0800739 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
740 dw[0] = dw0;
741 dw[1] = view->cmd[0];
742 dw[2] = 0;
743 dw[3] = view->cmd[2];
744 dw[4] = view->cmd[3];
745 dw[5] = view->cmd[4];
746 dw[6] = view->cmd[5];
747
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600748 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800749 cmd_reserve_reloc(cmd, 1);
750 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
751 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600752 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800753}
754
755static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
756 const struct intel_ds_view *view)
757{
758 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800759 uint32_t dw0, *dw;
760 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800761
762 CMD_ASSERT(cmd, 6, 7.5);
763
764 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800765 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
766 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767 dw0 |= (cmd_len - 2);
768
Chia-I Wu72292b72014-09-09 10:48:33 +0800769 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
770 dw[0] = dw0;
771 dw[1] = view->cmd[6];
772 dw[2] = 0;
773
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600774 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800775 cmd_reserve_reloc(cmd, 1);
776 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
777 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600778 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800779}
780
781static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
782 const struct intel_ds_view *view)
783{
784 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 uint32_t dw0, *dw;
786 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800787
788 CMD_ASSERT(cmd, 6, 7.5);
789
790 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800791 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
792 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793 dw0 |= (cmd_len - 2);
794
Chia-I Wu72292b72014-09-09 10:48:33 +0800795 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
796 dw[0] = dw0;
797 dw[1] = view->cmd[8];
798 dw[2] = 0;
799
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600800 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 cmd_reserve_reloc(cmd, 1);
802 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
803 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600804 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800805}
806
Chia-I Wuf8231032014-08-25 10:44:45 +0800807static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
808 uint32_t clear_val)
809{
810 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800811 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800812 GEN6_CLEAR_PARAMS_DW0_VALID |
813 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800814 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800815
816 CMD_ASSERT(cmd, 6, 6);
817
Chia-I Wu72292b72014-09-09 10:48:33 +0800818 cmd_batch_pointer(cmd, cmd_len, &dw);
819 dw[0] = dw0;
820 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800821}
822
823static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
824 uint32_t clear_val)
825{
826 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800827 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800828 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800829 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800830
831 CMD_ASSERT(cmd, 7, 7.5);
832
Chia-I Wu72292b72014-09-09 10:48:33 +0800833 cmd_batch_pointer(cmd, cmd_len, &dw);
834 dw[0] = dw0;
835 dw[1] = clear_val;
836 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800837}
838
Chia-I Wu302742d2014-08-22 10:28:29 +0800839static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800840 uint32_t blend_offset,
841 uint32_t ds_offset,
842 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800843{
844 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800846
847 CMD_ASSERT(cmd, 6, 6);
848
Chia-I Wu426072d2014-08-26 14:31:55 +0800849 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800850 (cmd_len - 2);
851
Chia-I Wu72292b72014-09-09 10:48:33 +0800852 cmd_batch_pointer(cmd, cmd_len, &dw);
853 dw[0] = dw0;
854 dw[1] = blend_offset | 1;
855 dw[2] = ds_offset | 1;
856 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800857}
858
Chia-I Wu1744cca2014-08-22 11:10:17 +0800859static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800860 uint32_t clip_offset,
861 uint32_t sf_offset,
862 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800863{
864 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800866
867 CMD_ASSERT(cmd, 6, 6);
868
Chia-I Wu426072d2014-08-26 14:31:55 +0800869 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800870 GEN6_PTR_VP_DW0_CLIP_CHANGED |
871 GEN6_PTR_VP_DW0_SF_CHANGED |
872 GEN6_PTR_VP_DW0_CC_CHANGED |
873 (cmd_len - 2);
874
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 cmd_batch_pointer(cmd, cmd_len, &dw);
876 dw[0] = dw0;
877 dw[1] = clip_offset;
878 dw[2] = sf_offset;
879 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800880}
881
882static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800883 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800884{
885 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800886 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800887
888 CMD_ASSERT(cmd, 6, 6);
889
Chia-I Wu426072d2014-08-26 14:31:55 +0800890 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800891 (cmd_len - 2);
892
Chia-I Wu72292b72014-09-09 10:48:33 +0800893 cmd_batch_pointer(cmd, cmd_len, &dw);
894 dw[0] = dw0;
895 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896}
897
Chia-I Wu42a56202014-08-23 16:47:48 +0800898static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800899 uint32_t vs_offset,
900 uint32_t gs_offset,
901 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800902{
903 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800905
906 CMD_ASSERT(cmd, 6, 6);
907
Chia-I Wu426072d2014-08-26 14:31:55 +0800908 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800909 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
910 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
911 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
912 (cmd_len - 2);
913
Chia-I Wu72292b72014-09-09 10:48:33 +0800914 cmd_batch_pointer(cmd, cmd_len, &dw);
915 dw[0] = dw0;
916 dw[1] = vs_offset;
917 dw[2] = gs_offset;
918 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800919}
920
Chia-I Wu257e75e2014-08-29 14:06:35 +0800921static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 uint32_t vs_offset,
923 uint32_t gs_offset,
924 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800925{
926 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800928
929 CMD_ASSERT(cmd, 6, 6);
930
931 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
932 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
933 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
934 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
935 (cmd_len - 2);
936
Chia-I Wu72292b72014-09-09 10:48:33 +0800937 cmd_batch_pointer(cmd, cmd_len, &dw);
938 dw[0] = dw0;
939 dw[1] = vs_offset;
940 dw[2] = gs_offset;
941 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800942}
943
Chia-I Wu302742d2014-08-22 10:28:29 +0800944static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800946{
947 const uint8_t cmd_len = 2;
948 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
949 GEN6_RENDER_SUBTYPE_3D |
950 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800951 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800952
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 cmd_batch_pointer(cmd, cmd_len, &dw);
954 dw[0] = dw0;
955 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800956}
957
Chia-I Wua6c4f152014-12-02 04:19:58 +0800958static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800959{
Chia-I Wue6073342014-11-30 09:43:42 +0800960 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700961 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
962 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800963
964 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700965 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800966
Tony Barbourfa6cac72015-01-16 14:27:35 -0700967 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800968}
969
Chia-I Wu72292b72014-09-09 10:48:33 +0800970static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700971 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800972{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700973 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800974 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800975 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700976 uint32_t dw[3];
977
978 dw[0] = pipeline->cmd_depth_stencil;
979 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
980 (state->ds_info.stencilWriteMask & 0xff) << 16;
981 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800982
983 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700984
985 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
986 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987
Chia-I Wu00b51a82014-09-09 12:07:37 +0800988 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700989 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800990}
991
Chia-I Wu72292b72014-09-09 10:48:33 +0800992static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800993 uint32_t stencil_ref,
994 const uint32_t blend_color[4])
995{
Chia-I Wue6073342014-11-30 09:43:42 +0800996 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800997 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +0800998 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800999
1000 CMD_ASSERT(cmd, 6, 7.5);
1001
Chia-I Wu00b51a82014-09-09 12:07:37 +08001002 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1003 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001004 dw[0] = stencil_ref;
1005 dw[1] = 0;
1006 dw[2] = blend_color[0];
1007 dw[3] = blend_color[1];
1008 dw[4] = blend_color[2];
1009 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001010
Chia-I Wu72292b72014-09-09 10:48:33 +08001011 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001012}
1013
Chia-I Wu8370b402014-08-29 12:28:37 +08001014static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001015{
Chia-I Wu8370b402014-08-29 12:28:37 +08001016 CMD_ASSERT(cmd, 6, 7.5);
1017
Chia-I Wu707a29e2014-08-27 12:51:47 +08001018 if (!cmd->bind.draw_count)
1019 return;
1020
Chia-I Wu8370b402014-08-29 12:28:37 +08001021 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001022 return;
1023
Chia-I Wu8370b402014-08-29 12:28:37 +08001024 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001025
1026 /*
1027 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1028 *
1029 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1030 * pipe-control with a post-sync op and no write-cache flushes."
1031 *
1032 * The workaround below necessitates this workaround.
1033 */
1034 gen6_PIPE_CONTROL(cmd,
1035 GEN6_PIPE_CONTROL_CS_STALL |
1036 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001037 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001038
Chia-I Wud6d079d2014-08-31 13:14:21 +08001039 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1040 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001041}
1042
Chia-I Wu8370b402014-08-29 12:28:37 +08001043static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001044{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001045 CMD_ASSERT(cmd, 6, 7.5);
1046
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001047 if (!cmd->bind.draw_count)
1048 return;
1049
Chia-I Wud6d079d2014-08-31 13:14:21 +08001050 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1051 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001052}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001053
Chia-I Wu8370b402014-08-29 12:28:37 +08001054static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1055{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001056 CMD_ASSERT(cmd, 7, 7.5);
1057
Chia-I Wu8370b402014-08-29 12:28:37 +08001058 if (!cmd->bind.draw_count)
1059 return;
1060
1061 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001062
1063 gen6_PIPE_CONTROL(cmd,
1064 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001065 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001066}
1067
Chia-I Wu8370b402014-08-29 12:28:37 +08001068static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1069{
1070 CMD_ASSERT(cmd, 7, 7.5);
1071
1072 if (!cmd->bind.draw_count)
1073 return;
1074
1075 /*
1076 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1077 *
1078 * "One of the following must also be set (when CS stall is set):
1079 *
1080 * * Render Target Cache Flush Enable ([12] of DW1)
1081 * * Depth Cache Flush Enable ([0] of DW1)
1082 * * Stall at Pixel Scoreboard ([1] of DW1)
1083 * * Depth Stall ([13] of DW1)
1084 * * Post-Sync Operation ([13] of DW1)"
1085 */
1086 gen6_PIPE_CONTROL(cmd,
1087 GEN6_PIPE_CONTROL_CS_STALL |
1088 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001089 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001090}
1091
1092static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1093{
1094 CMD_ASSERT(cmd, 7, 7.5);
1095
1096 if (!cmd->bind.draw_count)
1097 return;
1098
1099 cmd_wa_gen6_pre_depth_stall_write(cmd);
1100
Chia-I Wud6d079d2014-08-31 13:14:21 +08001101 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001102}
1103
1104static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1105{
1106 CMD_ASSERT(cmd, 6, 7.5);
1107
1108 if (!cmd->bind.draw_count)
1109 return;
1110
1111 /*
1112 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1113 *
1114 * "Driver must guarentee that all the caches in the depth pipe are
1115 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1116 * requires driver to send a PIPE_CONTROL with a CS stall along with
1117 * a Depth Flush prior to this command."
1118 *
1119 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1120 *
1121 * "Driver must ierarchi that all the caches in the depth pipe are
1122 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1123 * requires driver to send a PIPE_CONTROL with a CS stall along with
1124 * a Depth Flush prior to this command.
1125 */
1126 gen6_PIPE_CONTROL(cmd,
1127 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1128 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001129 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001130}
1131
1132static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1133{
1134 CMD_ASSERT(cmd, 6, 7.5);
1135
1136 if (!cmd->bind.draw_count)
1137 return;
1138
1139 /*
1140 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1141 *
1142 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1143 * and a post sync operation prior to the group of depth
1144 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1145 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1146 *
1147 * This workaround satifies all the conditions.
1148 */
1149 cmd_wa_gen6_pre_depth_stall_write(cmd);
1150
1151 /*
1152 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1153 *
1154 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1155 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1156 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1157 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1158 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1159 * Depth Flush Bit set, followed by another pipelined depth stall
1160 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1161 * guarantee that the pipeline from WM onwards is already flushed
1162 * (e.g., via a preceding MI_FLUSH)."
1163 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001164 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1165 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1166 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001167}
1168
Chia-I Wu525c6602014-08-27 10:22:34 +08001169void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1170{
1171 if (!cmd->bind.draw_count)
1172 return;
1173
1174 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1175
Chia-I Wu8370b402014-08-29 12:28:37 +08001176 /*
1177 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1178 *
1179 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1180 * PIPE_CONTROL with any non-zero post-sync-op is required."
1181 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001182 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001183 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001184
Chia-I Wu092279a2014-08-30 19:05:30 +08001185 /*
1186 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1187 *
1188 * "One of the following must also be set (when CS stall is set):
1189 *
1190 * * Render Target Cache Flush Enable ([12] of DW1)
1191 * * Depth Cache Flush Enable ([0] of DW1)
1192 * * Stall at Pixel Scoreboard ([1] of DW1)
1193 * * Depth Stall ([13] of DW1)
1194 * * Post-Sync Operation ([13] of DW1)"
1195 */
1196 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1197 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1198 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1199 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1200 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1201 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1202
Chia-I Wud6d079d2014-08-31 13:14:21 +08001203 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001204}
1205
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001206void cmd_batch_flush_all(struct intel_cmd *cmd)
1207{
1208 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1209 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1210 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1211 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1212 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1213 GEN6_PIPE_CONTROL_CS_STALL);
1214}
1215
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001216void cmd_batch_depth_count(struct intel_cmd *cmd,
1217 struct intel_bo *bo,
1218 XGL_GPU_SIZE offset)
1219{
1220 cmd_wa_gen6_pre_depth_stall_write(cmd);
1221
1222 gen6_PIPE_CONTROL(cmd,
1223 GEN6_PIPE_CONTROL_DEPTH_STALL |
1224 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001225 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001226}
1227
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001228void cmd_batch_timestamp(struct intel_cmd *cmd,
1229 struct intel_bo *bo,
1230 XGL_GPU_SIZE offset)
1231{
1232 /* need any WA or stall? */
1233 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1234}
1235
1236void cmd_batch_immediate(struct intel_cmd *cmd,
1237 struct intel_bo *bo,
1238 XGL_GPU_SIZE offset,
1239 uint64_t val)
1240{
1241 /* need any WA or stall? */
1242 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1243}
1244
Chia-I Wu302742d2014-08-22 10:28:29 +08001245static void gen6_cc_states(struct intel_cmd *cmd)
1246{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001247 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1248 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001249 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001250 uint32_t stencil_ref;
1251 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001252
1253 CMD_ASSERT(cmd, 6, 6);
1254
Chia-I Wua6c4f152014-12-02 04:19:58 +08001255 blend_offset = gen6_BLEND_STATE(cmd);
1256
1257 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001258 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001259 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001260 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001261
1262 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001263 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001264 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1265 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001266 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001267 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001268 stencil_ref = 0;
1269 }
1270
Chia-I Wu72292b72014-09-09 10:48:33 +08001271 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001272
Chia-I Wu72292b72014-09-09 10:48:33 +08001273 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001274}
1275
Chia-I Wu1744cca2014-08-22 11:10:17 +08001276static void gen6_viewport_states(struct intel_cmd *cmd)
1277{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001278 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001279 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001280
1281 if (!viewport)
1282 return;
1283
Tony Barbourfa6cac72015-01-16 14:27:35 -07001284 assert(viewport->cmd_len == (8 + 4 + 2) *
1285 viewport->viewport_count + (viewport->has_scissor_rects) ?
1286 (viewport->viewport_count * 2) : 0);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001287
1288 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001289 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001290 viewport->cmd);
1291
1292 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001293 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001294 &viewport->cmd[viewport->cmd_clip_pos]);
1295
1296 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001297 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001298 &viewport->cmd[viewport->cmd_cc_pos]);
1299
Tony Barbourfa6cac72015-01-16 14:27:35 -07001300 if (viewport->has_scissor_rects) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001301 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001302 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001303 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1304 } else {
1305 scissor_offset = 0;
1306 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001307
1308 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001309 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001310
Chia-I Wub1d450a2014-09-09 13:48:03 +08001311 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001312}
1313
Chia-I Wu302742d2014-08-22 10:28:29 +08001314static void gen7_cc_states(struct intel_cmd *cmd)
1315{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001316 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1317 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001318 uint32_t stencil_ref;
1319 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001320 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001321
1322 CMD_ASSERT(cmd, 7, 7.5);
1323
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001324 if (!blend && !ds)
1325 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001326
Chia-I Wua6c4f152014-12-02 04:19:58 +08001327 offset = gen6_BLEND_STATE(cmd);
1328 gen7_3dstate_pointer(cmd,
1329 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001330
Chia-I Wua6c4f152014-12-02 04:19:58 +08001331 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001332 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001333 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001334 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001335
1336 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001337 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001338 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1339 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001340 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001341 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1342 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001343 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1344 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001345 } else {
1346 stencil_ref = 0;
1347 }
1348
Chia-I Wu72292b72014-09-09 10:48:33 +08001349 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001350 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001351 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001352}
1353
Chia-I Wu1744cca2014-08-22 11:10:17 +08001354static void gen7_viewport_states(struct intel_cmd *cmd)
1355{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001356 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
1357 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001358 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001359
1360 if (!viewport)
1361 return;
1362
Tony Barbourfa6cac72015-01-16 14:27:35 -07001363 assert(viewport->cmd_len == (16 + 2 + 2 * pipeline->scissor_enable) *
Chia-I Wub1d450a2014-09-09 13:48:03 +08001364 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001365
Chia-I Wub1d450a2014-09-09 13:48:03 +08001366 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001367 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001368 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001369 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001370 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1371 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001372
1373 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001374 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001375 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001376 gen7_3dstate_pointer(cmd,
1377 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001378 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001379
Tony Barbourfa6cac72015-01-16 14:27:35 -07001380 if (pipeline->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001381 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001382 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001383 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001384 gen7_3dstate_pointer(cmd,
1385 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001386 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001387 }
1388}
1389
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001390static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001391 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001392{
1393 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001394 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001395
Chia-I Wu72292b72014-09-09 10:48:33 +08001396 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001397
1398 dw[0] = GEN6_RENDER_TYPE_RENDER |
1399 GEN6_RENDER_SUBTYPE_3D |
1400 subop | (cmd_len - 2);
1401 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001402 dw[2] = 0;
1403 dw[3] = 0;
1404 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001405}
1406
1407static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001408 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001409{
1410 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001411 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001412
Chia-I Wu72292b72014-09-09 10:48:33 +08001413 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001414
1415 dw[0] = GEN6_RENDER_TYPE_RENDER |
1416 GEN6_RENDER_SUBTYPE_3D |
1417 subop | (cmd_len - 2);
1418 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001419 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001420 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001421 dw[4] = 0;
1422 dw[5] = 0;
1423 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001424}
1425
Chia-I Wu625105f2014-10-13 15:35:29 +08001426static uint32_t emit_samplers(struct intel_cmd *cmd,
1427 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001428{
1429 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1430 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001431 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001432 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001433 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001434 XGL_UINT i;
1435
1436 CMD_ASSERT(cmd, 6, 7.5);
1437
Chia-I Wu625105f2014-10-13 15:35:29 +08001438 if (!rmap || !rmap->sampler_count)
1439 return 0;
1440
Cody Northrop40316a32014-12-09 19:08:33 -07001441 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001442
Chia-I Wudcb509d2014-12-10 08:53:10 +08001443 /*
1444 * note that we cannot call cmd_state_pointer() here as the following
1445 * cmd_state_pointer() would invalidate the pointer
1446 */
1447 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001448 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001449 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001450
1451 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001452 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001453 4 * rmap->sampler_count, &sampler_dw);
1454
Chia-I Wudcb509d2014-12-10 08:53:10 +08001455 cmd_state_update(cmd, border_offset,
1456 border_stride * rmap->sampler_count, &border_dw);
1457
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001458 for (i = 0; i < rmap->sampler_count; i++) {
1459 const struct intel_pipeline_rmap_slot *slot =
1460 &rmap->slots[surface_count + i];
1461 const struct intel_sampler *sampler;
1462
1463 switch (slot->path_len) {
1464 case 0:
1465 sampler = NULL;
1466 break;
1467 case INTEL_PIPELINE_RMAP_SLOT_RT:
1468 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1469 assert(!"unexpected rmap slot type");
1470 sampler = NULL;
1471 break;
1472 case 1:
1473 {
1474 const struct intel_dset *dset = cmd->bind.dset.graphics;
1475 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1476 const struct intel_dset_slot *dset_slot =
1477 &dset->slots[slot_offset + slot->u.index];
1478
1479 switch (dset_slot->type) {
1480 case INTEL_DSET_SLOT_SAMPLER:
1481 sampler = dset_slot->u.sampler;
1482 break;
1483 default:
1484 assert(!"unexpected dset slot type");
1485 sampler = NULL;
1486 break;
1487 }
1488 }
1489 break;
1490 default:
1491 assert(!"nested descriptor set unsupported");
1492 sampler = NULL;
1493 break;
1494 }
1495
1496 if (sampler) {
1497 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1498
1499 sampler_dw[0] = sampler->cmd[0];
1500 sampler_dw[1] = sampler->cmd[1];
1501 sampler_dw[2] = border_offset;
1502 sampler_dw[3] = sampler->cmd[2];
1503 } else {
1504 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1505 sampler_dw[1] = 0;
1506 sampler_dw[2] = 0;
1507 sampler_dw[3] = 0;
1508 }
1509
1510 border_offset += border_stride * 4;
1511 border_dw += border_stride;
1512 sampler_dw += 4;
1513 }
1514
Chia-I Wu625105f2014-10-13 15:35:29 +08001515 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001516}
1517
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001518static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001519 const struct intel_pipeline_rmap *rmap,
1520 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001521{
Chia-I Wu72292b72014-09-09 10:48:33 +08001522 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001523 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001524
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001525 CMD_ASSERT(cmd, 6, 7.5);
1526
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001527 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001528 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001529 if (!surface_count)
1530 return 0;
1531
Chia-I Wu42a56202014-08-23 16:47:48 +08001532 assert(surface_count <= ARRAY_SIZE(binding_table));
1533
1534 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001535 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001536
1537 switch (slot->path_len) {
1538 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001539 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001540 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001541 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001542 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001543 const struct intel_rt_view *view =
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001544 (slot->u.index < cmd->bind.render_pass->fb->rt_count) ?
1545 cmd->bind.render_pass->fb->rt[slot->u.index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001546
Chia-I Wu787a05b2014-12-05 11:02:20 +08001547 if (view) {
1548 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1549 GEN6_ALIGNMENT_SURFACE_STATE,
1550 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001551
Chia-I Wu787a05b2014-12-05 11:02:20 +08001552 cmd_reserve_reloc(cmd, 1);
1553 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1554 view->cmd[1], INTEL_RELOC_WRITE);
1555 } else {
1556 struct intel_null_view null_view;
1557 intel_null_view_init(&null_view, cmd->dev);
1558
1559 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1560 GEN6_ALIGNMENT_SURFACE_STATE,
1561 null_view.cmd_len, null_view.cmd);
1562 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001563 }
1564 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001565 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001566 {
Chia-I Wu714df452015-01-01 07:55:04 +08001567 const struct intel_buf_view *view =
1568 cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001569
Chia-I Wu00b51a82014-09-09 12:07:37 +08001570 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001571 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001572 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001573
Chia-I Wu72292b72014-09-09 10:48:33 +08001574 cmd_reserve_reloc(cmd, 1);
Chia-I Wu714df452015-01-01 07:55:04 +08001575 cmd_surface_reloc(cmd, offset, 1, view->buf->obj.mem->bo,
Chia-I Wu72292b72014-09-09 10:48:33 +08001576 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001577 }
1578 break;
1579 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001580 {
1581 const struct intel_dset *dset = cmd->bind.dset.graphics;
1582 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1583 const struct intel_dset_slot *dset_slot =
1584 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001585 const uint32_t reloc_flags =
1586 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001587
1588 switch (dset_slot->type) {
1589 case INTEL_DSET_SLOT_IMG_VIEW:
1590 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001591 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001592 dset_slot->u.img_view->cmd_len,
1593 dset_slot->u.img_view->cmd);
1594
1595 cmd_reserve_reloc(cmd, 1);
1596 cmd_surface_reloc(cmd, offset, 1,
1597 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001598 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001599 break;
Chia-I Wu714df452015-01-01 07:55:04 +08001600 case INTEL_DSET_SLOT_BUF_VIEW:
Cody Northrop7c76f302014-12-18 11:52:58 -07001601 {
Chia-I Wu714df452015-01-01 07:55:04 +08001602 XGL_BUFFER_VIEW_CREATE_INFO tmp_info =
1603 dset_slot->u.buf_view->info;
1604 struct intel_buf_view *tmp;
1605 XGL_RESULT res;
Cody Northrop7c76f302014-12-18 11:52:58 -07001606
1607 /* The compiler expects uniform buffers to have pitch of
1608 * 4 for fragment shaders, but 16 for other stages.
1609 */
Cody Northropbef0e552015-01-13 12:13:46 -07001610 tmp_info.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
1611 tmp_info.format.numericFormat = XGL_NUM_FMT_FLOAT;
Cody Northrop7c76f302014-12-18 11:52:58 -07001612 if (XGL_SHADER_STAGE_FRAGMENT == stage) {
1613 tmp_info.stride = 4;
1614 } else {
1615 tmp_info.stride = 16;
1616 }
1617
Chia-I Wu714df452015-01-01 07:55:04 +08001618 res = intel_buf_view_create(cmd->dev, &tmp_info, &tmp);
1619 if (res != XGL_SUCCESS) {
1620 cmd->result = res;
1621 break;
1622 }
Cody Northrop7c76f302014-12-18 11:52:58 -07001623
1624 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1625 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu714df452015-01-01 07:55:04 +08001626 tmp->cmd_len,
1627 tmp->cmd);
Cody Northrop7c76f302014-12-18 11:52:58 -07001628
1629 cmd_reserve_reloc(cmd, 1);
1630 cmd_surface_reloc(cmd, offset, 1,
Chia-I Wu714df452015-01-01 07:55:04 +08001631 dset_slot->u.buf_view->buf->obj.mem->bo,
1632 tmp->cmd[1], reloc_flags);
1633
1634 intel_buf_view_destroy(tmp);
Cody Northrop7c76f302014-12-18 11:52:58 -07001635 }
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001636 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001637 case INTEL_DSET_SLOT_SAMPLER:
1638 assert(0 == cmd->bind.dset.graphics_offset);
1639
1640 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001641 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001642 16, dset_slot->u.sampler->cmd);
1643 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001644 default:
1645 assert(!"unexpected dset slot type");
1646 break;
1647 }
1648 }
1649 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001650 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001651 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001652 break;
1653 }
1654
Chia-I Wu72292b72014-09-09 10:48:33 +08001655 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001656 }
1657
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001658 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001659 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001660 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001661}
1662
Chia-I Wu1d125092014-10-08 08:49:38 +08001663static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1664{
1665 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001666 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1667 uint32_t *dw;
1668 XGL_UINT pos, i;
1669
1670 CMD_ASSERT(cmd, 6, 7.5);
1671
1672 if (!pipeline->vb_count)
1673 return;
1674
1675 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1676
1677 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1678 dw++;
1679 pos++;
1680
1681 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001682 assert(pipeline->vb[i].strideInBytes <= 2048);
1683
1684 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1685 pipeline->vb[i].strideInBytes;
1686
1687 if (cmd_gen(cmd) >= INTEL_GEN(7))
1688 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1689
1690 switch (pipeline->vb[i].stepRate) {
1691 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1692 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1693 dw[3] = 0;
1694 break;
1695 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1696 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1697 dw[3] = 1;
1698 break;
1699 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1700 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1701 dw[3] = 0;
1702 break;
1703 default:
1704 assert(!"unknown step rate");
1705 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1706 dw[3] = 0;
1707 break;
1708 }
1709
Chia-I Wu714df452015-01-01 07:55:04 +08001710 if (cmd->bind.vertex.buf[i]) {
1711 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001712 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001713
1714 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001715 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1716 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001717 } else {
1718 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1719 dw[1] = 0;
1720 dw[2] = 0;
1721 }
1722
1723 dw += 4;
1724 pos += 4;
1725 }
1726}
1727
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001728static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1729{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001730 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1731 const struct intel_pipeline_shader *vs = &pipeline->vs;
1732 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001733 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001734 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001735 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001736 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001737
1738 CMD_ASSERT(cmd, 6, 7.5);
1739
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001740 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001741 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1742 *
1743 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1744 * 128-bit vertex elements to be passed into the payload for each
1745 * vertex."
1746 *
1747 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1748 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001749 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001750 vue_read_len = (vs->in_count + 1) / 2;
1751 if (!vue_read_len)
1752 vue_read_len = 1;
1753
1754 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1755 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1756
1757 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1758 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1759 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001760
1761 dw5 = GEN6_VS_DW5_STATISTICS |
1762 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001763
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001764 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001765 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001766 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001767 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001768
Chia-I Wube0a3d92014-09-02 13:20:59 +08001769 if (pipeline->disable_vs_cache)
1770 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1771
Chia-I Wu784d3042014-12-19 14:30:04 +08001772 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001773 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001774 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001775 dw[2] = dw2;
1776 dw[3] = 0; /* scratch */
1777 dw[4] = dw4;
1778 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001779
1780 if (vs->per_thread_scratch_size)
1781 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001782}
1783
Chia-I Wu625105f2014-10-13 15:35:29 +08001784static void emit_shader_resources(struct intel_cmd *cmd)
1785{
1786 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001787 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001788
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001789 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001790 cmd->bind.pipeline.graphics->vs.rmap,
1791 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001792 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001793 cmd->bind.pipeline.graphics->tcs.rmap,
1794 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001795 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001796 cmd->bind.pipeline.graphics->tes.rmap,
1797 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001798 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001799 cmd->bind.pipeline.graphics->gs.rmap,
1800 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001801 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001802 cmd->bind.pipeline.graphics->fs.rmap,
1803 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001804
1805 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1806 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1807 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1808 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1809 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1810
1811 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1812 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001813 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1814 binding_tables[0]);
1815 gen7_3dstate_pointer(cmd,
1816 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1817 binding_tables[1]);
1818 gen7_3dstate_pointer(cmd,
1819 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1820 binding_tables[2]);
1821 gen7_3dstate_pointer(cmd,
1822 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1823 binding_tables[3]);
1824 gen7_3dstate_pointer(cmd,
1825 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1826 binding_tables[4]);
1827
1828 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001829 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1830 samplers[0]);
1831 gen7_3dstate_pointer(cmd,
1832 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1833 samplers[1]);
1834 gen7_3dstate_pointer(cmd,
1835 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1836 samplers[2]);
1837 gen7_3dstate_pointer(cmd,
1838 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1839 samplers[3]);
1840 gen7_3dstate_pointer(cmd,
1841 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1842 samplers[4]);
1843 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001844 assert(!binding_tables[1] && !binding_tables[2]);
1845 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1846 binding_tables[0], binding_tables[3], binding_tables[4]);
1847
Chia-I Wu625105f2014-10-13 15:35:29 +08001848 assert(!samplers[1] && !samplers[2]);
1849 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1850 samplers[0], samplers[3], samplers[4]);
1851 }
1852}
1853
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001854static void emit_rt(struct intel_cmd *cmd)
1855{
1856 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001857 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1858 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001859}
1860
1861static void emit_ds(struct intel_cmd *cmd)
1862{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001863 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001864
1865 if (!ds) {
1866 /* all zeros */
1867 static const struct intel_ds_view null_ds;
1868 ds = &null_ds;
1869 }
1870
1871 cmd_wa_gen6_pre_ds_flush(cmd);
1872 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1873 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1874 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1875
1876 if (cmd_gen(cmd) >= INTEL_GEN(7))
1877 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1878 else
1879 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1880}
1881
Chia-I Wua57761b2014-10-14 14:27:44 +08001882static uint32_t emit_shader(struct intel_cmd *cmd,
1883 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001884{
Chia-I Wua57761b2014-10-14 14:27:44 +08001885 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1886 uint32_t offset;
1887 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001888
Chia-I Wua57761b2014-10-14 14:27:44 +08001889 /* see if the shader is already in the cache */
1890 for (i = 0; i < cache->used; i++) {
1891 if (cache->entries[i].shader == (const void *) shader)
1892 return cache->entries[i].kernel_offset;
1893 }
1894
1895 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1896
1897 /* grow the cache if full */
1898 if (cache->used >= cache->count) {
1899 const XGL_UINT count = cache->count + 16;
1900 void *entries;
1901
1902 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1903 XGL_SYSTEM_ALLOC_INTERNAL);
1904 if (entries) {
1905 if (cache->entries) {
1906 memcpy(entries, cache->entries,
1907 sizeof(cache->entries[0]) * cache->used);
1908 icd_free(cache->entries);
1909 }
1910
1911 cache->entries = entries;
1912 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001913 }
1914 }
1915
Chia-I Wua57761b2014-10-14 14:27:44 +08001916 /* add the shader to the cache */
1917 if (cache->used < cache->count) {
1918 cache->entries[cache->used].shader = (const void *) shader;
1919 cache->entries[cache->used].kernel_offset = offset;
1920 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001921 }
1922
Chia-I Wua57761b2014-10-14 14:27:44 +08001923 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001924}
1925
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001926static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001927{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001928 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001929
Chia-I Wu8370b402014-08-29 12:28:37 +08001930 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1931 cmd_wa_gen6_pre_depth_stall_write(cmd);
1932 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1933 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1934 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1935 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001936
1937 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001938 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001939 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001940
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001941 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001942 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001943 }
1944 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001945 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001946 }
1947 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001948 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1949 }
1950 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1951 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1952 }
1953 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1954 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001955 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001956
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001957 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1958 gen7_3DSTATE_GS(cmd);
1959 } else {
1960 gen6_3DSTATE_GS(cmd);
1961 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001962
Chia-I Wu8370b402014-08-29 12:28:37 +08001963 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1964 cmd_wa_gen7_post_command_cs_stall(cmd);
1965 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1966 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001967}
1968
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001969static void emit_bounded_states(struct intel_cmd *cmd)
1970{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001971
1972 emit_graphics_pipeline(cmd);
1973
1974 emit_rt(cmd);
1975 emit_ds(cmd);
1976
1977 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1978 gen7_cc_states(cmd);
1979 gen7_viewport_states(cmd);
1980
1981 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1982 &cmd->bind.pipeline.graphics->vs);
1983 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1984 &cmd->bind.pipeline.graphics->fs);
1985
1986 gen6_3DSTATE_CLIP(cmd);
1987 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001988 gen7_3DSTATE_WM(cmd);
1989 gen7_3DSTATE_PS(cmd);
1990 } else {
1991 gen6_cc_states(cmd);
1992 gen6_viewport_states(cmd);
1993
1994 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1995 &cmd->bind.pipeline.graphics->vs);
1996 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1997 &cmd->bind.pipeline.graphics->fs);
1998
1999 gen6_3DSTATE_CLIP(cmd);
2000 gen6_3DSTATE_SF(cmd);
2001 gen6_3DSTATE_WM(cmd);
2002 }
2003
2004 emit_shader_resources(cmd);
2005
2006 cmd_wa_gen6_pre_depth_stall_write(cmd);
2007 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2008
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002009 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2010 gen6_3DSTATE_VS(cmd);
2011}
2012
Tony Barbourfa6cac72015-01-16 14:27:35 -07002013static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
2014 const struct intel_cmd_meta *meta)
2015{
2016 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2017 const uint8_t cmd_len = 3;
2018 uint32_t dw[3];
2019 uint32_t cmd_depth_stencil;
2020 uint32_t cmd_depth_test;
2021
2022 CMD_ASSERT(cmd, 6, 7.5);
2023
2024 cmd_depth_stencil = 0;
2025 cmd_depth_test = 0;
2026 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
2027 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
2028 GEN6_COMPAREFUNCTION_ALWAYS << 27;
2029 }
2030 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2031 cmd_depth_stencil = 1 << 31 |
2032 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2033 (GEN6_STENCILOP_KEEP) << 25 |
2034 (GEN6_STENCILOP_KEEP) << 22 |
2035 (GEN6_STENCILOP_REPLACE) << 19 |
2036 1 << 15 |
2037 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2038 (GEN6_STENCILOP_KEEP) << 9 |
2039 (GEN6_STENCILOP_KEEP) << 6 |
2040 (GEN6_STENCILOP_REPLACE) << 3;
2041 }
2042
2043 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2044 dw[0] = cmd_depth_stencil | 1 << 18;
2045 dw[1] = (0xff) << 24 | (0xff) << 16;
2046 dw[2] = cmd_depth_test;
2047
2048 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2049 cmd_align, cmd_len, dw);
2050}
2051
Chia-I Wu6032b892014-10-17 14:47:18 +08002052static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2053{
2054 const struct intel_cmd_meta *meta = cmd->bind.meta;
2055 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2056
2057 CMD_ASSERT(cmd, 6, 7.5);
2058
2059 blend_offset = 0;
2060 ds_offset = 0;
2061 cc_offset = 0;
2062 cc_vp_offset = 0;
2063
Chia-I Wu29e6f502014-11-24 14:27:29 +08002064 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002065 /* BLEND_STATE */
2066 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002067 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002068 dw[0] = 0;
2069 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2070 }
2071
Chia-I Wu29e6f502014-11-24 14:27:29 +08002072 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002073 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002074 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002075 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2076 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002077
Chia-I Wu29e6f502014-11-24 14:27:29 +08002078 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002079 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002080
Chia-I Wu29e6f502014-11-24 14:27:29 +08002081 /* COLOR_CALC_STATE */
2082 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002083 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002084
Chia-I Wu29e6f502014-11-24 14:27:29 +08002085 /* CC_VIEWPORT */
2086 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002087 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002088 dw[0] = u_fui(0.0f);
2089 dw[1] = u_fui(1.0f);
2090 } else {
2091 /* DEPTH_STENCIL_STATE */
2092 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002093 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002094 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2095 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2096 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002097 }
2098
2099 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2100 gen7_3dstate_pointer(cmd,
2101 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2102 blend_offset);
2103 gen7_3dstate_pointer(cmd,
2104 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2105 ds_offset);
2106 gen7_3dstate_pointer(cmd,
2107 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2108
2109 gen7_3dstate_pointer(cmd,
2110 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2111 cc_vp_offset);
2112 } else {
2113 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002114 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002115
2116 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2117 cmd_batch_pointer(cmd, 4, &dw);
2118 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2119 GEN6_PTR_VP_DW0_CC_CHANGED;
2120 dw[1] = 0;
2121 dw[2] = 0;
2122 dw[3] = cc_vp_offset;
2123 }
2124}
2125
2126static void gen6_meta_surface_states(struct intel_cmd *cmd)
2127{
2128 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002129 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002130 uint32_t offset;
2131
2132 CMD_ASSERT(cmd, 6, 7.5);
2133
Chia-I Wu29e6f502014-11-24 14:27:29 +08002134 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2135 return;
2136
Chia-I Wu005c47c2014-10-22 13:49:13 +08002137 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002138 if (meta->src.valid) {
2139 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002140 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002141 meta->src.surface_len, meta->src.surface);
2142
2143 cmd_reserve_reloc(cmd, 1);
2144 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2145 cmd_surface_reloc_writer(cmd, offset, 1,
2146 meta->src.reloc_target, meta->src.reloc_offset);
2147 } else {
2148 cmd_surface_reloc(cmd, offset, 1,
2149 (struct intel_bo *) meta->src.reloc_target,
2150 meta->src.reloc_offset, meta->src.reloc_flags);
2151 }
2152
Chia-I Wu005c47c2014-10-22 13:49:13 +08002153 binding_table[0] = offset;
2154 }
2155 if (meta->dst.valid) {
2156 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002157 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002158 meta->dst.surface_len, meta->dst.surface);
2159
2160 cmd_reserve_reloc(cmd, 1);
2161 cmd_surface_reloc(cmd, offset, 1,
2162 (struct intel_bo *) meta->dst.reloc_target,
2163 meta->dst.reloc_offset, meta->dst.reloc_flags);
2164
2165 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002166 }
2167
2168 /* BINDING_TABLE */
2169 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002170 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002171 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002172
2173 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002174 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2175 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2176 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2177 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002178 } else {
2179 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002180 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2181 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2182 else
2183 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002184 }
2185}
2186
2187static void gen6_meta_urb(struct intel_cmd *cmd)
2188{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002189 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002190 uint32_t *dw;
2191
2192 CMD_ASSERT(cmd, 6, 6);
2193
2194 /* 3DSTATE_URB */
2195 cmd_batch_pointer(cmd, 3, &dw);
2196 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002197 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002198 dw[2] = 0;
2199}
2200
2201static void gen7_meta_urb(struct intel_cmd *cmd)
2202{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002203 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002204 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002205 uint32_t *dw;
2206
2207 CMD_ASSERT(cmd, 7, 7.5);
2208
2209 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2210 cmd_batch_pointer(cmd, 10, &dw);
2211
2212 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002213 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002214 dw += 2;
2215
2216 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2217 dw[1] = 0;
2218 dw += 2;
2219
2220 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2221 dw[1] = 0;
2222 dw += 2;
2223
2224 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2225 dw[1] = 0;
2226 dw += 2;
2227
2228 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002229 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002230
2231 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2232
Chia-I Wu24aa1022014-11-25 11:53:19 +08002233 switch (cmd_gen(cmd)) {
2234 case INTEL_GEN(7.5):
2235 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2236 break;
2237 case INTEL_GEN(7):
2238 default:
2239 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2240 break;
2241 }
2242
Chia-I Wu6032b892014-10-17 14:47:18 +08002243 /* 3DSTATE_URB_x */
2244 cmd_batch_pointer(cmd, 8, &dw);
2245
2246 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2247 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002248 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002249 dw += 2;
2250
2251 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2252 dw[1] = 0;
2253 dw += 2;
2254
2255 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2256 dw[1] = 0;
2257 dw += 2;
2258
2259 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2260 dw[1] = 0;
2261 dw += 2;
2262}
2263
2264static void gen6_meta_vf(struct intel_cmd *cmd)
2265{
2266 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002267 uint32_t vb_start, vb_end, vb_stride;
2268 int ve_format, ve_z_source;
2269 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002270 XGL_UINT pos;
2271
2272 CMD_ASSERT(cmd, 6, 7.5);
2273
Chia-I Wu29e6f502014-11-24 14:27:29 +08002274 switch (meta->mode) {
2275 case INTEL_CMD_META_VS_POINTS:
2276 cmd_batch_pointer(cmd, 3, &dw);
2277 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2278 dw[1] = GEN6_VE_STATE_DW0_VALID;
2279 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2280 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2281 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2282 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2283 return;
2284 break;
2285 case INTEL_CMD_META_FS_RECT:
2286 {
2287 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002288
Chia-I Wu29e6f502014-11-24 14:27:29 +08002289 vertices[0][0] = meta->dst.x + meta->width;
2290 vertices[0][1] = meta->dst.y + meta->height;
2291 vertices[1][0] = meta->dst.x;
2292 vertices[1][1] = meta->dst.y + meta->height;
2293 vertices[2][0] = meta->dst.x;
2294 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002295
Chia-I Wu29e6f502014-11-24 14:27:29 +08002296 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2297 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002298
Chia-I Wu29e6f502014-11-24 14:27:29 +08002299 vb_end = vb_start + sizeof(vertices) - 1;
2300 vb_stride = sizeof(vertices[0]);
2301 ve_z_source = GEN6_VFCOMP_STORE_0;
2302 ve_format = GEN6_FORMAT_R32G32_USCALED;
2303 }
2304 break;
2305 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2306 {
2307 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002308
Chia-I Wu29e6f502014-11-24 14:27:29 +08002309 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2310 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2311 vertices[0][2] = u_uif(meta->clear_val[0]);
2312 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2313 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2314 vertices[1][2] = u_uif(meta->clear_val[0]);
2315 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2316 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2317 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002318
Chia-I Wu29e6f502014-11-24 14:27:29 +08002319 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2320 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002321
Chia-I Wu29e6f502014-11-24 14:27:29 +08002322 vb_end = vb_start + sizeof(vertices) - 1;
2323 vb_stride = sizeof(vertices[0]);
2324 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2325 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2326 }
2327 break;
2328 default:
2329 assert(!"unknown meta mode");
2330 return;
2331 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002332 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002333
2334 /* 3DSTATE_VERTEX_BUFFERS */
2335 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002336
Chia-I Wu6032b892014-10-17 14:47:18 +08002337 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002338 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002339 if (cmd_gen(cmd) >= INTEL_GEN(7))
2340 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2341
2342 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002343 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2344 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002345
2346 dw[4] = 0;
2347
2348 /* 3DSTATE_VERTEX_ELEMENTS */
2349 cmd_batch_pointer(cmd, 5, &dw);
2350 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002351 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002352 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2353 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2354 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2355 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2356 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002357 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002358 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2359 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002360 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002361 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2362}
2363
Chia-I Wu29e6f502014-11-24 14:27:29 +08002364static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002365{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002366 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002367 /* one GPR */
2368 XGL_UINT consts[8];
2369 XGL_UINT const_count;
2370
2371 CMD_ASSERT(cmd, 6, 7.5);
2372
2373 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002374 case INTEL_DEV_META_VS_FILL_MEM:
2375 consts[0] = meta->dst.x;
2376 consts[1] = meta->clear_val[0];
2377 const_count = 2;
2378 break;
2379 case INTEL_DEV_META_VS_COPY_MEM:
2380 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2381 consts[0] = meta->dst.x;
2382 consts[1] = meta->src.x;
2383 const_count = 2;
2384 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002385 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2386 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2387 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2388 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2389 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2390 consts[0] = meta->src.x;
2391 consts[1] = meta->src.y;
2392 consts[2] = meta->width;
2393 consts[3] = meta->dst.x;
2394 const_count = 4;
2395 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002396 default:
2397 assert(!"unknown meta shader id");
2398 const_count = 0;
2399 break;
2400 }
2401
2402 /* this can be skipped but it makes state dumping prettier */
2403 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2404
2405 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2406}
2407
2408static void gen6_meta_vs(struct intel_cmd *cmd)
2409{
2410 const struct intel_cmd_meta *meta = cmd->bind.meta;
2411 const struct intel_pipeline_shader *sh =
2412 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2413 uint32_t offset, *dw;
2414
2415 CMD_ASSERT(cmd, 6, 7.5);
2416
2417 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2418 XGL_UINT cmd_len;
2419
2420 /* 3DSTATE_CONSTANT_VS */
2421 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2422 cmd_batch_pointer(cmd, cmd_len, &dw);
2423 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2424 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2425
2426 /* 3DSTATE_VS */
2427 cmd_batch_pointer(cmd, 6, &dw);
2428 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2429 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2430
2431 return;
2432 }
2433
2434 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2435
2436 /* 3DSTATE_CONSTANT_VS */
2437 offset = gen6_meta_vs_constants(cmd);
2438 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2439 cmd_batch_pointer(cmd, 7, &dw);
2440 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2441 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2442 dw[2] = 0;
2443 dw[3] = offset;
2444 dw[4] = 0;
2445 dw[5] = 0;
2446 dw[6] = 0;
2447 } else {
2448 cmd_batch_pointer(cmd, 5, &dw);
2449 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2450 GEN6_PCB_ANY_DW0_PCB0_VALID;
2451 dw[1] = offset;
2452 dw[2] = 0;
2453 dw[3] = 0;
2454 dw[4] = 0;
2455 }
2456
2457 /* 3DSTATE_VS */
2458 offset = emit_shader(cmd, sh);
2459 cmd_batch_pointer(cmd, 6, &dw);
2460 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2461 dw[1] = offset;
2462 dw[2] = GEN6_THREADDISP_SPF |
2463 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2464 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002465 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002466 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2467 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2468
2469 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2470 GEN6_VS_DW5_VS_ENABLE;
2471 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002472 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002473 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002474 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002475
2476 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002477}
2478
2479static void gen6_meta_disabled(struct intel_cmd *cmd)
2480{
Chia-I Wu6032b892014-10-17 14:47:18 +08002481 uint32_t *dw;
2482
2483 CMD_ASSERT(cmd, 6, 6);
2484
Chia-I Wu6032b892014-10-17 14:47:18 +08002485 /* 3DSTATE_CONSTANT_GS */
2486 cmd_batch_pointer(cmd, 5, &dw);
2487 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2488 dw[1] = 0;
2489 dw[2] = 0;
2490 dw[3] = 0;
2491 dw[4] = 0;
2492
2493 /* 3DSTATE_GS */
2494 cmd_batch_pointer(cmd, 7, &dw);
2495 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2496 dw[1] = 0;
2497 dw[2] = 0;
2498 dw[3] = 0;
2499 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2500 dw[5] = GEN6_GS_DW5_STATISTICS;
2501 dw[6] = 0;
2502
Chia-I Wu6032b892014-10-17 14:47:18 +08002503 /* 3DSTATE_SF */
2504 cmd_batch_pointer(cmd, 20, &dw);
2505 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2506 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2507 memset(&dw[2], 0, 18 * sizeof(*dw));
2508}
2509
2510static void gen7_meta_disabled(struct intel_cmd *cmd)
2511{
2512 uint32_t *dw;
2513
2514 CMD_ASSERT(cmd, 7, 7.5);
2515
Chia-I Wu6032b892014-10-17 14:47:18 +08002516 /* 3DSTATE_CONSTANT_HS */
2517 cmd_batch_pointer(cmd, 7, &dw);
2518 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2519 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2520
2521 /* 3DSTATE_HS */
2522 cmd_batch_pointer(cmd, 7, &dw);
2523 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2524 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2525
2526 /* 3DSTATE_TE */
2527 cmd_batch_pointer(cmd, 4, &dw);
2528 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2529 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2530
2531 /* 3DSTATE_CONSTANT_DS */
2532 cmd_batch_pointer(cmd, 7, &dw);
2533 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2534 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2535
2536 /* 3DSTATE_DS */
2537 cmd_batch_pointer(cmd, 6, &dw);
2538 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2539 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2540
2541 /* 3DSTATE_CONSTANT_GS */
2542 cmd_batch_pointer(cmd, 7, &dw);
2543 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2544 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2545
2546 /* 3DSTATE_GS */
2547 cmd_batch_pointer(cmd, 7, &dw);
2548 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2549 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2550
2551 /* 3DSTATE_STREAMOUT */
2552 cmd_batch_pointer(cmd, 3, &dw);
2553 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2554 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2555
Chia-I Wu6032b892014-10-17 14:47:18 +08002556 /* 3DSTATE_SF */
2557 cmd_batch_pointer(cmd, 7, &dw);
2558 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2559 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2560
2561 /* 3DSTATE_SBE */
2562 cmd_batch_pointer(cmd, 14, &dw);
2563 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2564 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2565 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002566}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002567
Chia-I Wu29e6f502014-11-24 14:27:29 +08002568static void gen6_meta_clip(struct intel_cmd *cmd)
2569{
2570 const struct intel_cmd_meta *meta = cmd->bind.meta;
2571 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002572
Chia-I Wu29e6f502014-11-24 14:27:29 +08002573 /* 3DSTATE_CLIP */
2574 cmd_batch_pointer(cmd, 4, &dw);
2575 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2576 dw[1] = 0;
2577 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2578 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2579 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2580 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002581 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002582 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002583 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002584}
2585
2586static void gen6_meta_wm(struct intel_cmd *cmd)
2587{
2588 const struct intel_cmd_meta *meta = cmd->bind.meta;
2589 uint32_t *dw;
2590
2591 CMD_ASSERT(cmd, 6, 7.5);
2592
2593 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2594
2595 /* 3DSTATE_MULTISAMPLE */
2596 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2597 cmd_batch_pointer(cmd, 4, &dw);
2598 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2599 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2600 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2601 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2602 dw[2] = 0;
2603 dw[3] = 0;
2604 } else {
2605 cmd_batch_pointer(cmd, 3, &dw);
2606 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2607 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2608 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2609 dw[2] = 0;
2610 }
2611
2612 /* 3DSTATE_SAMPLE_MASK */
2613 cmd_batch_pointer(cmd, 2, &dw);
2614 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2615 dw[1] = (1 << meta->samples) - 1;
2616
2617 /* 3DSTATE_DRAWING_RECTANGLE */
2618 cmd_batch_pointer(cmd, 4, &dw);
2619 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2620 dw[1] = meta->dst.y << 16 | meta->dst.x;
2621 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2622 (meta->dst.x + meta->width - 1);
2623 dw[3] = 0;
2624}
2625
2626static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2627{
2628 const struct intel_cmd_meta *meta = cmd->bind.meta;
2629 XGL_UINT offset_x, offset_y;
2630 /* one GPR */
2631 XGL_UINT consts[8];
2632 XGL_UINT const_count;
2633
2634 CMD_ASSERT(cmd, 6, 7.5);
2635
2636 /* underflow is fine here */
2637 offset_x = meta->src.x - meta->dst.x;
2638 offset_y = meta->src.y - meta->dst.y;
2639
2640 switch (meta->shader_id) {
2641 case INTEL_DEV_META_FS_COPY_MEM:
2642 case INTEL_DEV_META_FS_COPY_1D:
2643 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2644 case INTEL_DEV_META_FS_COPY_2D:
2645 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2646 case INTEL_DEV_META_FS_COPY_2D_MS:
2647 consts[0] = offset_x;
2648 consts[1] = offset_y;
2649 consts[2] = meta->src.layer;
2650 consts[3] = meta->src.lod;
2651 const_count = 4;
2652 break;
2653 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2654 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2655 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2656 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2657 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2658 consts[0] = offset_x;
2659 consts[1] = offset_y;
2660 consts[2] = meta->src.layer;
2661 consts[3] = meta->src.lod;
2662 consts[4] = meta->src.x;
2663 consts[5] = meta->width;
2664 const_count = 6;
2665 break;
2666 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2667 consts[0] = offset_x;
2668 consts[1] = offset_y;
2669 consts[2] = meta->width;
2670 const_count = 3;
2671 break;
2672 case INTEL_DEV_META_FS_CLEAR_COLOR:
2673 consts[0] = meta->clear_val[0];
2674 consts[1] = meta->clear_val[1];
2675 consts[2] = meta->clear_val[2];
2676 consts[3] = meta->clear_val[3];
2677 const_count = 4;
2678 break;
2679 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2680 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002681 consts[1] = meta->clear_val[1];
2682 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002683 break;
2684 case INTEL_DEV_META_FS_RESOLVE_2X:
2685 case INTEL_DEV_META_FS_RESOLVE_4X:
2686 case INTEL_DEV_META_FS_RESOLVE_8X:
2687 case INTEL_DEV_META_FS_RESOLVE_16X:
2688 consts[0] = offset_x;
2689 consts[1] = offset_y;
2690 const_count = 2;
2691 break;
2692 default:
2693 assert(!"unknown meta shader id");
2694 const_count = 0;
2695 break;
2696 }
2697
2698 /* this can be skipped but it makes state dumping prettier */
2699 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2700
2701 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2702}
2703
2704static void gen6_meta_ps(struct intel_cmd *cmd)
2705{
2706 const struct intel_cmd_meta *meta = cmd->bind.meta;
2707 const struct intel_pipeline_shader *sh =
2708 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2709 uint32_t offset, *dw;
2710
2711 CMD_ASSERT(cmd, 6, 6);
2712
Chia-I Wu29e6f502014-11-24 14:27:29 +08002713 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2714 /* 3DSTATE_CONSTANT_PS */
2715 cmd_batch_pointer(cmd, 5, &dw);
2716 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2717 dw[1] = 0;
2718 dw[2] = 0;
2719 dw[3] = 0;
2720 dw[4] = 0;
2721
2722 /* 3DSTATE_WM */
2723 cmd_batch_pointer(cmd, 9, &dw);
2724 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2725 dw[1] = 0;
2726 dw[2] = 0;
2727 dw[3] = 0;
2728 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002729 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002730 dw[6] = 0;
2731 dw[7] = 0;
2732 dw[8] = 0;
2733
Chia-I Wu3adf7212014-10-24 15:34:07 +08002734 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002735 }
2736
Chia-I Wu3adf7212014-10-24 15:34:07 +08002737 /* a normal color write */
2738 assert(meta->dst.valid && !sh->uses);
2739
Chia-I Wu6032b892014-10-17 14:47:18 +08002740 /* 3DSTATE_CONSTANT_PS */
2741 offset = gen6_meta_ps_constants(cmd);
2742 cmd_batch_pointer(cmd, 5, &dw);
2743 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2744 GEN6_PCB_ANY_DW0_PCB0_VALID;
2745 dw[1] = offset;
2746 dw[2] = 0;
2747 dw[3] = 0;
2748 dw[4] = 0;
2749
2750 /* 3DSTATE_WM */
2751 offset = emit_shader(cmd, sh);
2752 cmd_batch_pointer(cmd, 9, &dw);
2753 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2754 dw[1] = offset;
2755 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2756 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002757 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002758 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002759 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002760 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002761 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2762
Chia-I Wu6032b892014-10-17 14:47:18 +08002763 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2764 GEN6_WM_DW6_POSOFFSET_NONE |
2765 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2766 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2767 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2768 if (meta->samples > 1) {
2769 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2770 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2771 } else {
2772 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2773 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2774 }
2775 dw[7] = 0;
2776 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002777
2778 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002779}
2780
2781static void gen7_meta_ps(struct intel_cmd *cmd)
2782{
2783 const struct intel_cmd_meta *meta = cmd->bind.meta;
2784 const struct intel_pipeline_shader *sh =
2785 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2786 uint32_t offset, *dw;
2787
2788 CMD_ASSERT(cmd, 7, 7.5);
2789
Chia-I Wu29e6f502014-11-24 14:27:29 +08002790 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2791 /* 3DSTATE_WM */
2792 cmd_batch_pointer(cmd, 3, &dw);
2793 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2794 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2795
2796 /* 3DSTATE_CONSTANT_GS */
2797 cmd_batch_pointer(cmd, 7, &dw);
2798 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2799 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2800
2801 /* 3DSTATE_PS */
2802 cmd_batch_pointer(cmd, 8, &dw);
2803 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2804 dw[1] = 0;
2805 dw[2] = 0;
2806 dw[3] = 0;
2807 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002808 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002809 dw[5] = 0;
2810 dw[6] = 0;
2811 dw[7] = 0;
2812
Chia-I Wu3adf7212014-10-24 15:34:07 +08002813 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002814 }
2815
Chia-I Wu3adf7212014-10-24 15:34:07 +08002816 /* a normal color write */
2817 assert(meta->dst.valid && !sh->uses);
2818
Chia-I Wu6032b892014-10-17 14:47:18 +08002819 /* 3DSTATE_WM */
2820 cmd_batch_pointer(cmd, 3, &dw);
2821 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2822 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2823 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2824 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2825 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2826 dw[2] = 0;
2827
2828 /* 3DSTATE_CONSTANT_PS */
2829 offset = gen6_meta_ps_constants(cmd);
2830 cmd_batch_pointer(cmd, 7, &dw);
2831 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2832 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2833 dw[2] = 0;
2834 dw[3] = offset;
2835 dw[4] = 0;
2836 dw[5] = 0;
2837 dw[6] = 0;
2838
2839 /* 3DSTATE_PS */
2840 offset = emit_shader(cmd, sh);
2841 cmd_batch_pointer(cmd, 8, &dw);
2842 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2843 dw[1] = offset;
2844 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2845 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002846 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002847
2848 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2849 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002850 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2851
2852 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002853 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002854 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002855 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002856 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002857 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002858
2859 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2860 dw[6] = 0;
2861 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002862
2863 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002864}
2865
2866static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2867{
2868 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002869 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002870
2871 CMD_ASSERT(cmd, 6, 7.5);
2872
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002873 if (!ds) {
2874 /* all zeros */
2875 static const struct intel_ds_view null_ds;
2876 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002877 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002878
2879 cmd_wa_gen6_pre_ds_flush(cmd);
2880 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2881 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2882 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2883
2884 if (cmd_gen(cmd) >= INTEL_GEN(7))
2885 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2886 else
2887 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002888}
2889
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002890static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2891 const struct intel_pipeline *pipeline)
2892{
2893 cmd->bind.pipeline.graphics = pipeline;
2894}
2895
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002896static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2897 const struct intel_pipeline *pipeline)
2898{
2899 cmd->bind.pipeline.compute = pipeline;
2900}
2901
2902static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2903 const struct intel_pipeline_delta *delta)
2904{
2905 cmd->bind.pipeline.graphics_delta = delta;
2906}
2907
2908static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2909 const struct intel_pipeline_delta *delta)
2910{
2911 cmd->bind.pipeline.compute_delta = delta;
2912}
2913
2914static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2915 const struct intel_dset *dset,
2916 XGL_UINT slot_offset)
2917{
2918 cmd->bind.dset.graphics = dset;
2919 cmd->bind.dset.graphics_offset = slot_offset;
2920}
2921
2922static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2923 const struct intel_dset *dset,
2924 XGL_UINT slot_offset)
2925{
2926 cmd->bind.dset.compute = dset;
2927 cmd->bind.dset.compute_offset = slot_offset;
2928}
2929
2930static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002931 const XGL_BUFFER_VIEW_ATTACH_INFO *info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002932{
Chia-I Wu714df452015-01-01 07:55:04 +08002933 cmd->bind.dyn_view.graphics = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002934}
2935
2936static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002937 const XGL_BUFFER_VIEW_ATTACH_INFO *info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002938{
Chia-I Wu714df452015-01-01 07:55:04 +08002939 cmd->bind.dyn_view.compute = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002940}
2941
Chia-I Wu3b04af52014-11-08 10:48:20 +08002942static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002943 const struct intel_buf *buf,
Chia-I Wu3b04af52014-11-08 10:48:20 +08002944 XGL_GPU_SIZE offset, XGL_UINT binding)
2945{
Chia-I Wu714df452015-01-01 07:55:04 +08002946 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002947 cmd->result = XGL_ERROR_UNKNOWN;
2948 return;
2949 }
2950
Chia-I Wu714df452015-01-01 07:55:04 +08002951 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002952 cmd->bind.vertex.offset[binding] = offset;
2953}
2954
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002955static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002956 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002957 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2958{
Chia-I Wu714df452015-01-01 07:55:04 +08002959 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002960 cmd->bind.index.offset = offset;
2961 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002962}
2963
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002964static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002965 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002966{
2967 cmd->bind.state.viewport = state;
2968}
2969
2970static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002971 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002972{
2973 cmd->bind.state.raster = state;
2974}
2975
2976static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002977 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002978{
2979 cmd->bind.state.ds = state;
2980}
2981
2982static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002983 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002984{
2985 cmd->bind.state.blend = state;
2986}
2987
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002988static void cmd_draw(struct intel_cmd *cmd,
2989 XGL_UINT vertex_start,
2990 XGL_UINT vertex_count,
2991 XGL_UINT instance_start,
2992 XGL_UINT instance_count,
2993 bool indexed,
2994 XGL_UINT vertex_base)
2995{
2996 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2997
2998 emit_bounded_states(cmd);
2999
3000 if (indexed) {
3001 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3002 cmd->result = XGL_ERROR_UNKNOWN;
3003
3004 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3005 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3006 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003007 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003008 cmd->bind.index.offset, cmd->bind.index.type,
3009 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003010 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003011 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003012 cmd->bind.index.offset, cmd->bind.index.type,
3013 p->primitive_restart);
3014 }
3015 } else {
3016 assert(!vertex_base);
3017 }
3018
3019 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3020 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3021 vertex_start, instance_count, instance_start, vertex_base);
3022 } else {
3023 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3024 vertex_start, instance_count, instance_start, vertex_base);
3025 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003026
Chia-I Wu707a29e2014-08-27 12:51:47 +08003027 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003028 /* need to re-emit all workarounds */
3029 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003030
3031 if (intel_debug & INTEL_DEBUG_NOCACHE)
3032 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003033}
3034
Chia-I Wuc14d1562014-10-17 09:49:22 +08003035void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3036{
Chia-I Wu6032b892014-10-17 14:47:18 +08003037 cmd->bind.meta = meta;
3038
3039 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003040 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003041
3042 gen6_meta_dynamic_states(cmd);
3043 gen6_meta_surface_states(cmd);
3044
3045 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3046 gen7_meta_urb(cmd);
3047 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003048 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003049 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003050 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003051 gen6_meta_wm(cmd);
3052 gen7_meta_ps(cmd);
3053 gen6_meta_depth_buffer(cmd);
3054
3055 cmd_wa_gen7_post_command_cs_stall(cmd);
3056 cmd_wa_gen7_post_command_depth_stall(cmd);
3057
Chia-I Wu29e6f502014-11-24 14:27:29 +08003058 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3059 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003060 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003061 } else {
3062 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3063 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003064 } else {
3065 gen6_meta_urb(cmd);
3066 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003067 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003068 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003069 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003070 gen6_meta_wm(cmd);
3071 gen6_meta_ps(cmd);
3072 gen6_meta_depth_buffer(cmd);
3073
Chia-I Wu29e6f502014-11-24 14:27:29 +08003074 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3075 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003076 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003077 } else {
3078 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3079 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003080 }
3081
3082 cmd->bind.draw_count++;
3083 /* need to re-emit all workarounds */
3084 cmd->bind.wa_flags = 0;
3085
3086 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003087
3088 if (intel_debug & INTEL_DEBUG_NOCACHE)
3089 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003090}
3091
Chia-I Wu96177272015-01-03 15:27:41 +08003092ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003093 XGL_CMD_BUFFER cmdBuffer,
3094 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3095 XGL_PIPELINE pipeline)
3096{
3097 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3098
3099 switch (pipelineBindPoint) {
3100 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003101 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003102 break;
3103 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003104 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003105 break;
3106 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003107 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003108 break;
3109 }
3110}
3111
Chia-I Wu96177272015-01-03 15:27:41 +08003112ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003113 XGL_CMD_BUFFER cmdBuffer,
3114 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3115 XGL_PIPELINE_DELTA delta)
3116{
3117 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3118
3119 switch (pipelineBindPoint) {
3120 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003121 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003122 break;
3123 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003124 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003125 break;
3126 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003127 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003128 break;
3129 }
3130}
3131
Tony Barbourfa6cac72015-01-16 14:27:35 -07003132ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003133 XGL_CMD_BUFFER cmdBuffer,
3134 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003135 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003136{
3137 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3138
3139 switch (stateBindPoint) {
3140 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003141 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003142 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003143 break;
3144 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003145 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003146 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003147 break;
3148 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003149 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003150 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003151 break;
3152 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003153 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003154 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003155 break;
3156 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003157 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003158 break;
3159 }
3160}
3161
Chia-I Wu96177272015-01-03 15:27:41 +08003162ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003163 XGL_CMD_BUFFER cmdBuffer,
3164 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3165 XGL_UINT index,
3166 XGL_DESCRIPTOR_SET descriptorSet,
3167 XGL_UINT slotOffset)
3168{
3169 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3170 struct intel_dset *dset = intel_dset(descriptorSet);
3171
3172 assert(!index);
3173
3174 switch (pipelineBindPoint) {
3175 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003176 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003177 break;
3178 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003179 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003180 break;
3181 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003182 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003183 break;
3184 }
3185}
3186
Chia-I Wu714df452015-01-01 07:55:04 +08003187ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicBufferView(
Chia-I Wub2755562014-08-20 13:38:52 +08003188 XGL_CMD_BUFFER cmdBuffer,
3189 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wu714df452015-01-01 07:55:04 +08003190 const XGL_BUFFER_VIEW_ATTACH_INFO* pBufferView)
Chia-I Wub2755562014-08-20 13:38:52 +08003191{
3192 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3193
3194 switch (pipelineBindPoint) {
3195 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu714df452015-01-01 07:55:04 +08003196 cmd_bind_compute_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003197 break;
3198 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu714df452015-01-01 07:55:04 +08003199 cmd_bind_graphics_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003200 break;
3201 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003202 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003203 break;
3204 }
3205}
3206
Chia-I Wu714df452015-01-01 07:55:04 +08003207ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003208 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003209 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003210 XGL_GPU_SIZE offset,
3211 XGL_UINT binding)
3212{
3213 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003214 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003215
Chia-I Wu714df452015-01-01 07:55:04 +08003216 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003217}
3218
Chia-I Wu714df452015-01-01 07:55:04 +08003219ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003220 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003221 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003222 XGL_GPU_SIZE offset,
3223 XGL_INDEX_TYPE indexType)
3224{
3225 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003226 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003227
Chia-I Wu714df452015-01-01 07:55:04 +08003228 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003229}
3230
Chia-I Wu96177272015-01-03 15:27:41 +08003231ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003232 XGL_CMD_BUFFER cmdBuffer,
3233 XGL_UINT firstVertex,
3234 XGL_UINT vertexCount,
3235 XGL_UINT firstInstance,
3236 XGL_UINT instanceCount)
3237{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003238 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003239
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003240 cmd_draw(cmd, firstVertex, vertexCount,
3241 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003242}
3243
Chia-I Wu96177272015-01-03 15:27:41 +08003244ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003245 XGL_CMD_BUFFER cmdBuffer,
3246 XGL_UINT firstIndex,
3247 XGL_UINT indexCount,
3248 XGL_INT vertexOffset,
3249 XGL_UINT firstInstance,
3250 XGL_UINT instanceCount)
3251{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003252 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003253
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003254 cmd_draw(cmd, firstIndex, indexCount,
3255 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003256}
3257
Chia-I Wu96177272015-01-03 15:27:41 +08003258ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003259 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003260 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003261 XGL_GPU_SIZE offset,
3262 XGL_UINT32 count,
3263 XGL_UINT32 stride)
3264{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003265 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3266
3267 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003268}
3269
Chia-I Wu96177272015-01-03 15:27:41 +08003270ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003271 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003272 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003273 XGL_GPU_SIZE offset,
3274 XGL_UINT32 count,
3275 XGL_UINT32 stride)
3276{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003277 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3278
3279 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003280}
3281
Chia-I Wu96177272015-01-03 15:27:41 +08003282ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003283 XGL_CMD_BUFFER cmdBuffer,
3284 XGL_UINT x,
3285 XGL_UINT y,
3286 XGL_UINT z)
3287{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003288 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3289
3290 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003291}
3292
Chia-I Wu96177272015-01-03 15:27:41 +08003293ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003294 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003295 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003296 XGL_GPU_SIZE offset)
3297{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003298 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3299
3300 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003301}