blob: d130aa608781635099fd8d917de069f3ee5f6ea0 [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;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700979 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700980 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700981 (state->ds_info.stencilWriteMask & 0xff) << 16 |
982 (state->ds_info.stencilReadMask & 0xff) << 8 |
983 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700984 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800985
986 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700987
988 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
989 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800990
Chia-I Wu00b51a82014-09-09 12:07:37 +0800991 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700992 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800993}
994
Chia-I Wu72292b72014-09-09 10:48:33 +0800995static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800996 uint32_t stencil_ref,
997 const uint32_t blend_color[4])
998{
Chia-I Wue6073342014-11-30 09:43:42 +0800999 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001000 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001001 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001002
1003 CMD_ASSERT(cmd, 6, 7.5);
1004
Chia-I Wu00b51a82014-09-09 12:07:37 +08001005 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1006 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001007 dw[0] = stencil_ref;
1008 dw[1] = 0;
1009 dw[2] = blend_color[0];
1010 dw[3] = blend_color[1];
1011 dw[4] = blend_color[2];
1012 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001013
Chia-I Wu72292b72014-09-09 10:48:33 +08001014 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001015}
1016
Chia-I Wu8370b402014-08-29 12:28:37 +08001017static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001018{
Chia-I Wu8370b402014-08-29 12:28:37 +08001019 CMD_ASSERT(cmd, 6, 7.5);
1020
Chia-I Wu707a29e2014-08-27 12:51:47 +08001021 if (!cmd->bind.draw_count)
1022 return;
1023
Chia-I Wu8370b402014-08-29 12:28:37 +08001024 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001025 return;
1026
Chia-I Wu8370b402014-08-29 12:28:37 +08001027 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001028
1029 /*
1030 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1031 *
1032 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1033 * pipe-control with a post-sync op and no write-cache flushes."
1034 *
1035 * The workaround below necessitates this workaround.
1036 */
1037 gen6_PIPE_CONTROL(cmd,
1038 GEN6_PIPE_CONTROL_CS_STALL |
1039 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001040 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001041
Chia-I Wud6d079d2014-08-31 13:14:21 +08001042 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1043 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001044}
1045
Chia-I Wu8370b402014-08-29 12:28:37 +08001046static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001047{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001048 CMD_ASSERT(cmd, 6, 7.5);
1049
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001050 if (!cmd->bind.draw_count)
1051 return;
1052
Chia-I Wud6d079d2014-08-31 13:14:21 +08001053 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1054 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001055}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001056
Chia-I Wu8370b402014-08-29 12:28:37 +08001057static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1058{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001059 CMD_ASSERT(cmd, 7, 7.5);
1060
Chia-I Wu8370b402014-08-29 12:28:37 +08001061 if (!cmd->bind.draw_count)
1062 return;
1063
1064 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001065
1066 gen6_PIPE_CONTROL(cmd,
1067 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001068 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001069}
1070
Chia-I Wu8370b402014-08-29 12:28:37 +08001071static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1072{
1073 CMD_ASSERT(cmd, 7, 7.5);
1074
1075 if (!cmd->bind.draw_count)
1076 return;
1077
1078 /*
1079 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1080 *
1081 * "One of the following must also be set (when CS stall is set):
1082 *
1083 * * Render Target Cache Flush Enable ([12] of DW1)
1084 * * Depth Cache Flush Enable ([0] of DW1)
1085 * * Stall at Pixel Scoreboard ([1] of DW1)
1086 * * Depth Stall ([13] of DW1)
1087 * * Post-Sync Operation ([13] of DW1)"
1088 */
1089 gen6_PIPE_CONTROL(cmd,
1090 GEN6_PIPE_CONTROL_CS_STALL |
1091 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001092 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001093}
1094
1095static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1096{
1097 CMD_ASSERT(cmd, 7, 7.5);
1098
1099 if (!cmd->bind.draw_count)
1100 return;
1101
1102 cmd_wa_gen6_pre_depth_stall_write(cmd);
1103
Chia-I Wud6d079d2014-08-31 13:14:21 +08001104 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001105}
1106
1107static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1108{
1109 CMD_ASSERT(cmd, 6, 7.5);
1110
1111 if (!cmd->bind.draw_count)
1112 return;
1113
1114 /*
1115 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1116 *
1117 * "Driver must guarentee that all the caches in the depth pipe are
1118 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1119 * requires driver to send a PIPE_CONTROL with a CS stall along with
1120 * a Depth Flush prior to this command."
1121 *
1122 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1123 *
1124 * "Driver must ierarchi that all the caches in the depth pipe are
1125 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1126 * requires driver to send a PIPE_CONTROL with a CS stall along with
1127 * a Depth Flush prior to this command.
1128 */
1129 gen6_PIPE_CONTROL(cmd,
1130 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1131 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001132 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001133}
1134
1135static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1136{
1137 CMD_ASSERT(cmd, 6, 7.5);
1138
1139 if (!cmd->bind.draw_count)
1140 return;
1141
1142 /*
1143 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1144 *
1145 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1146 * and a post sync operation prior to the group of depth
1147 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1148 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1149 *
1150 * This workaround satifies all the conditions.
1151 */
1152 cmd_wa_gen6_pre_depth_stall_write(cmd);
1153
1154 /*
1155 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1156 *
1157 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1158 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1159 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1160 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1161 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1162 * Depth Flush Bit set, followed by another pipelined depth stall
1163 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1164 * guarantee that the pipeline from WM onwards is already flushed
1165 * (e.g., via a preceding MI_FLUSH)."
1166 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001167 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1168 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1169 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001170}
1171
Chia-I Wu525c6602014-08-27 10:22:34 +08001172void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1173{
1174 if (!cmd->bind.draw_count)
1175 return;
1176
1177 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1178
Chia-I Wu8370b402014-08-29 12:28:37 +08001179 /*
1180 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1181 *
1182 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1183 * PIPE_CONTROL with any non-zero post-sync-op is required."
1184 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001185 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001186 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001187
Chia-I Wu092279a2014-08-30 19:05:30 +08001188 /*
1189 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1190 *
1191 * "One of the following must also be set (when CS stall is set):
1192 *
1193 * * Render Target Cache Flush Enable ([12] of DW1)
1194 * * Depth Cache Flush Enable ([0] of DW1)
1195 * * Stall at Pixel Scoreboard ([1] of DW1)
1196 * * Depth Stall ([13] of DW1)
1197 * * Post-Sync Operation ([13] of DW1)"
1198 */
1199 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1200 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1201 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1202 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1203 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1204 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1205
Chia-I Wud6d079d2014-08-31 13:14:21 +08001206 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001207}
1208
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001209void cmd_batch_flush_all(struct intel_cmd *cmd)
1210{
1211 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1212 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1213 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1214 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1215 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1216 GEN6_PIPE_CONTROL_CS_STALL);
1217}
1218
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001219void cmd_batch_depth_count(struct intel_cmd *cmd,
1220 struct intel_bo *bo,
1221 XGL_GPU_SIZE offset)
1222{
1223 cmd_wa_gen6_pre_depth_stall_write(cmd);
1224
1225 gen6_PIPE_CONTROL(cmd,
1226 GEN6_PIPE_CONTROL_DEPTH_STALL |
1227 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001228 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001229}
1230
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001231void cmd_batch_timestamp(struct intel_cmd *cmd,
1232 struct intel_bo *bo,
1233 XGL_GPU_SIZE offset)
1234{
1235 /* need any WA or stall? */
1236 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1237}
1238
1239void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001240 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001241 struct intel_bo *bo,
1242 XGL_GPU_SIZE offset,
1243 uint64_t val)
1244{
1245 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001246 gen6_PIPE_CONTROL(cmd,
1247 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1248 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001249}
1250
Chia-I Wu302742d2014-08-22 10:28:29 +08001251static void gen6_cc_states(struct intel_cmd *cmd)
1252{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001253 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1254 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001255 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001256 uint32_t stencil_ref;
1257 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001258
1259 CMD_ASSERT(cmd, 6, 6);
1260
Chia-I Wua6c4f152014-12-02 04:19:58 +08001261 blend_offset = gen6_BLEND_STATE(cmd);
1262
1263 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001264 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001265 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001266 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001267
1268 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001269 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001270 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1271 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001272 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001273 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001274 stencil_ref = 0;
1275 }
1276
Chia-I Wu72292b72014-09-09 10:48:33 +08001277 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001278
Chia-I Wu72292b72014-09-09 10:48:33 +08001279 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001280}
1281
Chia-I Wu1744cca2014-08-22 11:10:17 +08001282static void gen6_viewport_states(struct intel_cmd *cmd)
1283{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001284 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001285 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001286
1287 if (!viewport)
1288 return;
1289
Tony Barbourfa6cac72015-01-16 14:27:35 -07001290 assert(viewport->cmd_len == (8 + 4 + 2) *
1291 viewport->viewport_count + (viewport->has_scissor_rects) ?
1292 (viewport->viewport_count * 2) : 0);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001293
1294 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001295 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001296 viewport->cmd);
1297
1298 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001299 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001300 &viewport->cmd[viewport->cmd_clip_pos]);
1301
1302 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001303 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001304 &viewport->cmd[viewport->cmd_cc_pos]);
1305
Tony Barbourfa6cac72015-01-16 14:27:35 -07001306 if (viewport->has_scissor_rects) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001307 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001308 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001309 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1310 } else {
1311 scissor_offset = 0;
1312 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001313
1314 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001315 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001316
Chia-I Wub1d450a2014-09-09 13:48:03 +08001317 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001318}
1319
Chia-I Wu302742d2014-08-22 10:28:29 +08001320static void gen7_cc_states(struct intel_cmd *cmd)
1321{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001322 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1323 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001324 uint32_t stencil_ref;
1325 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001326 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001327
1328 CMD_ASSERT(cmd, 7, 7.5);
1329
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001330 if (!blend && !ds)
1331 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001332
Chia-I Wua6c4f152014-12-02 04:19:58 +08001333 offset = gen6_BLEND_STATE(cmd);
1334 gen7_3dstate_pointer(cmd,
1335 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001336
Chia-I Wua6c4f152014-12-02 04:19:58 +08001337 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001338 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001339 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001340 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001341
1342 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001343 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001344 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1345 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001346 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001347 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1348 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001349 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1350 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001351 } else {
1352 stencil_ref = 0;
1353 }
1354
Chia-I Wu72292b72014-09-09 10:48:33 +08001355 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001356 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001357 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001358}
1359
Chia-I Wu1744cca2014-08-22 11:10:17 +08001360static void gen7_viewport_states(struct intel_cmd *cmd)
1361{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001362 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
1363 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001364 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001365
1366 if (!viewport)
1367 return;
1368
Tony Barbourfa6cac72015-01-16 14:27:35 -07001369 assert(viewport->cmd_len == (16 + 2 + 2 * pipeline->scissor_enable) *
Chia-I Wub1d450a2014-09-09 13:48:03 +08001370 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001371
Chia-I Wub1d450a2014-09-09 13:48:03 +08001372 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001373 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001374 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001375 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001376 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1377 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001378
1379 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001380 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001381 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001382 gen7_3dstate_pointer(cmd,
1383 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001384 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001385
Tony Barbourfa6cac72015-01-16 14:27:35 -07001386 if (pipeline->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001387 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001388 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001389 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001390 gen7_3dstate_pointer(cmd,
1391 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001392 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001393 }
1394}
1395
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001396static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001397 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001398{
1399 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001400 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001401
Chia-I Wu72292b72014-09-09 10:48:33 +08001402 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001403
1404 dw[0] = GEN6_RENDER_TYPE_RENDER |
1405 GEN6_RENDER_SUBTYPE_3D |
1406 subop | (cmd_len - 2);
1407 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001408 dw[2] = 0;
1409 dw[3] = 0;
1410 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001411}
1412
1413static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001414 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001415{
1416 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001417 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001418
Chia-I Wu72292b72014-09-09 10:48:33 +08001419 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001420
1421 dw[0] = GEN6_RENDER_TYPE_RENDER |
1422 GEN6_RENDER_SUBTYPE_3D |
1423 subop | (cmd_len - 2);
1424 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001425 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001426 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001427 dw[4] = 0;
1428 dw[5] = 0;
1429 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001430}
1431
Chia-I Wu625105f2014-10-13 15:35:29 +08001432static uint32_t emit_samplers(struct intel_cmd *cmd,
1433 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001434{
1435 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1436 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001437 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001438 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001439 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001440 XGL_UINT i;
1441
1442 CMD_ASSERT(cmd, 6, 7.5);
1443
Chia-I Wu625105f2014-10-13 15:35:29 +08001444 if (!rmap || !rmap->sampler_count)
1445 return 0;
1446
Cody Northrop40316a32014-12-09 19:08:33 -07001447 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001448
Chia-I Wudcb509d2014-12-10 08:53:10 +08001449 /*
1450 * note that we cannot call cmd_state_pointer() here as the following
1451 * cmd_state_pointer() would invalidate the pointer
1452 */
1453 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001454 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001455 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001456
1457 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001458 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001459 4 * rmap->sampler_count, &sampler_dw);
1460
Chia-I Wudcb509d2014-12-10 08:53:10 +08001461 cmd_state_update(cmd, border_offset,
1462 border_stride * rmap->sampler_count, &border_dw);
1463
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001464 for (i = 0; i < rmap->sampler_count; i++) {
1465 const struct intel_pipeline_rmap_slot *slot =
1466 &rmap->slots[surface_count + i];
1467 const struct intel_sampler *sampler;
1468
1469 switch (slot->path_len) {
1470 case 0:
1471 sampler = NULL;
1472 break;
1473 case INTEL_PIPELINE_RMAP_SLOT_RT:
1474 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1475 assert(!"unexpected rmap slot type");
1476 sampler = NULL;
1477 break;
1478 case 1:
1479 {
1480 const struct intel_dset *dset = cmd->bind.dset.graphics;
1481 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1482 const struct intel_dset_slot *dset_slot =
1483 &dset->slots[slot_offset + slot->u.index];
1484
1485 switch (dset_slot->type) {
1486 case INTEL_DSET_SLOT_SAMPLER:
1487 sampler = dset_slot->u.sampler;
1488 break;
1489 default:
1490 assert(!"unexpected dset slot type");
1491 sampler = NULL;
1492 break;
1493 }
1494 }
1495 break;
1496 default:
1497 assert(!"nested descriptor set unsupported");
1498 sampler = NULL;
1499 break;
1500 }
1501
1502 if (sampler) {
1503 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1504
1505 sampler_dw[0] = sampler->cmd[0];
1506 sampler_dw[1] = sampler->cmd[1];
1507 sampler_dw[2] = border_offset;
1508 sampler_dw[3] = sampler->cmd[2];
1509 } else {
1510 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1511 sampler_dw[1] = 0;
1512 sampler_dw[2] = 0;
1513 sampler_dw[3] = 0;
1514 }
1515
1516 border_offset += border_stride * 4;
1517 border_dw += border_stride;
1518 sampler_dw += 4;
1519 }
1520
Chia-I Wu625105f2014-10-13 15:35:29 +08001521 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001522}
1523
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001524static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001525 const struct intel_pipeline_rmap *rmap,
1526 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001527{
Chia-I Wu72292b72014-09-09 10:48:33 +08001528 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001529 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001530
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001531 CMD_ASSERT(cmd, 6, 7.5);
1532
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001533 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001534 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001535 if (!surface_count)
1536 return 0;
1537
Chia-I Wu42a56202014-08-23 16:47:48 +08001538 assert(surface_count <= ARRAY_SIZE(binding_table));
1539
1540 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001541 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001542
1543 switch (slot->path_len) {
1544 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001546 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001547 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001548 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001549 const struct intel_rt_view *view =
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001550 (slot->u.index < cmd->bind.render_pass->fb->rt_count) ?
1551 cmd->bind.render_pass->fb->rt[slot->u.index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001552
Chia-I Wu787a05b2014-12-05 11:02:20 +08001553 if (view) {
1554 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1555 GEN6_ALIGNMENT_SURFACE_STATE,
1556 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001557
Chia-I Wu787a05b2014-12-05 11:02:20 +08001558 cmd_reserve_reloc(cmd, 1);
1559 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1560 view->cmd[1], INTEL_RELOC_WRITE);
1561 } else {
1562 struct intel_null_view null_view;
1563 intel_null_view_init(&null_view, cmd->dev);
1564
1565 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1566 GEN6_ALIGNMENT_SURFACE_STATE,
1567 null_view.cmd_len, null_view.cmd);
1568 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001569 }
1570 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001571 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001572 {
Chia-I Wu714df452015-01-01 07:55:04 +08001573 const struct intel_buf_view *view =
1574 cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001575
Chia-I Wu00b51a82014-09-09 12:07:37 +08001576 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001577 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001578 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001579
Chia-I Wu72292b72014-09-09 10:48:33 +08001580 cmd_reserve_reloc(cmd, 1);
Chia-I Wu714df452015-01-01 07:55:04 +08001581 cmd_surface_reloc(cmd, offset, 1, view->buf->obj.mem->bo,
Chia-I Wu72292b72014-09-09 10:48:33 +08001582 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001583 }
1584 break;
1585 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001586 {
1587 const struct intel_dset *dset = cmd->bind.dset.graphics;
1588 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1589 const struct intel_dset_slot *dset_slot =
1590 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001591 const uint32_t reloc_flags =
1592 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001593
1594 switch (dset_slot->type) {
1595 case INTEL_DSET_SLOT_IMG_VIEW:
1596 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001597 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001598 dset_slot->u.img_view->cmd_len,
1599 dset_slot->u.img_view->cmd);
1600
1601 cmd_reserve_reloc(cmd, 1);
1602 cmd_surface_reloc(cmd, offset, 1,
1603 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001604 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001605 break;
Chia-I Wu714df452015-01-01 07:55:04 +08001606 case INTEL_DSET_SLOT_BUF_VIEW:
Cody Northrop7c76f302014-12-18 11:52:58 -07001607 {
Chia-I Wu714df452015-01-01 07:55:04 +08001608 XGL_BUFFER_VIEW_CREATE_INFO tmp_info =
1609 dset_slot->u.buf_view->info;
1610 struct intel_buf_view *tmp;
1611 XGL_RESULT res;
Cody Northrop7c76f302014-12-18 11:52:58 -07001612
1613 /* The compiler expects uniform buffers to have pitch of
1614 * 4 for fragment shaders, but 16 for other stages.
1615 */
Cody Northropbef0e552015-01-13 12:13:46 -07001616 tmp_info.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
1617 tmp_info.format.numericFormat = XGL_NUM_FMT_FLOAT;
Cody Northrop7c76f302014-12-18 11:52:58 -07001618 if (XGL_SHADER_STAGE_FRAGMENT == stage) {
1619 tmp_info.stride = 4;
1620 } else {
1621 tmp_info.stride = 16;
1622 }
1623
Chia-I Wu714df452015-01-01 07:55:04 +08001624 res = intel_buf_view_create(cmd->dev, &tmp_info, &tmp);
1625 if (res != XGL_SUCCESS) {
1626 cmd->result = res;
1627 break;
1628 }
Cody Northrop7c76f302014-12-18 11:52:58 -07001629
1630 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1631 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu714df452015-01-01 07:55:04 +08001632 tmp->cmd_len,
1633 tmp->cmd);
Cody Northrop7c76f302014-12-18 11:52:58 -07001634
1635 cmd_reserve_reloc(cmd, 1);
1636 cmd_surface_reloc(cmd, offset, 1,
Chia-I Wu714df452015-01-01 07:55:04 +08001637 dset_slot->u.buf_view->buf->obj.mem->bo,
1638 tmp->cmd[1], reloc_flags);
1639
1640 intel_buf_view_destroy(tmp);
Cody Northrop7c76f302014-12-18 11:52:58 -07001641 }
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001642 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001643 case INTEL_DSET_SLOT_SAMPLER:
1644 assert(0 == cmd->bind.dset.graphics_offset);
1645
1646 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001647 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001648 16, dset_slot->u.sampler->cmd);
1649 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001650 default:
1651 assert(!"unexpected dset slot type");
1652 break;
1653 }
1654 }
1655 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001656 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001657 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001658 break;
1659 }
1660
Chia-I Wu72292b72014-09-09 10:48:33 +08001661 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001662 }
1663
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001664 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001665 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001666 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001667}
1668
Chia-I Wu1d125092014-10-08 08:49:38 +08001669static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1670{
1671 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001672 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1673 uint32_t *dw;
1674 XGL_UINT pos, i;
1675
1676 CMD_ASSERT(cmd, 6, 7.5);
1677
1678 if (!pipeline->vb_count)
1679 return;
1680
1681 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1682
1683 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1684 dw++;
1685 pos++;
1686
1687 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001688 assert(pipeline->vb[i].strideInBytes <= 2048);
1689
1690 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1691 pipeline->vb[i].strideInBytes;
1692
1693 if (cmd_gen(cmd) >= INTEL_GEN(7))
1694 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1695
1696 switch (pipeline->vb[i].stepRate) {
1697 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1698 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1699 dw[3] = 0;
1700 break;
1701 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1702 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1703 dw[3] = 1;
1704 break;
1705 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1706 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1707 dw[3] = 0;
1708 break;
1709 default:
1710 assert(!"unknown step rate");
1711 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1712 dw[3] = 0;
1713 break;
1714 }
1715
Chia-I Wu714df452015-01-01 07:55:04 +08001716 if (cmd->bind.vertex.buf[i]) {
1717 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001718 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001719
1720 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001721 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1722 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001723 } else {
1724 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1725 dw[1] = 0;
1726 dw[2] = 0;
1727 }
1728
1729 dw += 4;
1730 pos += 4;
1731 }
1732}
1733
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001734static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1735{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001736 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1737 const struct intel_pipeline_shader *vs = &pipeline->vs;
1738 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001739 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001740 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001741 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001742 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001743
1744 CMD_ASSERT(cmd, 6, 7.5);
1745
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001746 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001747 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1748 *
1749 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1750 * 128-bit vertex elements to be passed into the payload for each
1751 * vertex."
1752 *
1753 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1754 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001755 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001756 vue_read_len = (vs->in_count + 1) / 2;
1757 if (!vue_read_len)
1758 vue_read_len = 1;
1759
1760 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1761 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1762
1763 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1764 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1765 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001766
1767 dw5 = GEN6_VS_DW5_STATISTICS |
1768 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001769
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001770 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001771 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001772 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001773 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001774
Chia-I Wube0a3d92014-09-02 13:20:59 +08001775 if (pipeline->disable_vs_cache)
1776 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1777
Chia-I Wu784d3042014-12-19 14:30:04 +08001778 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001779 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001780 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001781 dw[2] = dw2;
1782 dw[3] = 0; /* scratch */
1783 dw[4] = dw4;
1784 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001785
1786 if (vs->per_thread_scratch_size)
1787 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001788}
1789
Chia-I Wu625105f2014-10-13 15:35:29 +08001790static void emit_shader_resources(struct intel_cmd *cmd)
1791{
1792 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001793 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001794
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001795 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001796 cmd->bind.pipeline.graphics->vs.rmap,
1797 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001798 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001799 cmd->bind.pipeline.graphics->tcs.rmap,
1800 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001801 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001802 cmd->bind.pipeline.graphics->tes.rmap,
1803 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001804 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001805 cmd->bind.pipeline.graphics->gs.rmap,
1806 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001807 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001808 cmd->bind.pipeline.graphics->fs.rmap,
1809 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001810
1811 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1812 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1813 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1814 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1815 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1816
1817 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1818 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001819 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1820 binding_tables[0]);
1821 gen7_3dstate_pointer(cmd,
1822 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1823 binding_tables[1]);
1824 gen7_3dstate_pointer(cmd,
1825 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1826 binding_tables[2]);
1827 gen7_3dstate_pointer(cmd,
1828 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1829 binding_tables[3]);
1830 gen7_3dstate_pointer(cmd,
1831 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1832 binding_tables[4]);
1833
1834 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001835 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1836 samplers[0]);
1837 gen7_3dstate_pointer(cmd,
1838 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1839 samplers[1]);
1840 gen7_3dstate_pointer(cmd,
1841 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1842 samplers[2]);
1843 gen7_3dstate_pointer(cmd,
1844 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1845 samplers[3]);
1846 gen7_3dstate_pointer(cmd,
1847 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1848 samplers[4]);
1849 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001850 assert(!binding_tables[1] && !binding_tables[2]);
1851 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1852 binding_tables[0], binding_tables[3], binding_tables[4]);
1853
Chia-I Wu625105f2014-10-13 15:35:29 +08001854 assert(!samplers[1] && !samplers[2]);
1855 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1856 samplers[0], samplers[3], samplers[4]);
1857 }
1858}
1859
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001860static void emit_rt(struct intel_cmd *cmd)
1861{
1862 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001863 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1864 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001865}
1866
1867static void emit_ds(struct intel_cmd *cmd)
1868{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001869 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001870
1871 if (!ds) {
1872 /* all zeros */
1873 static const struct intel_ds_view null_ds;
1874 ds = &null_ds;
1875 }
1876
1877 cmd_wa_gen6_pre_ds_flush(cmd);
1878 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1879 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1880 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1881
1882 if (cmd_gen(cmd) >= INTEL_GEN(7))
1883 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1884 else
1885 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1886}
1887
Chia-I Wua57761b2014-10-14 14:27:44 +08001888static uint32_t emit_shader(struct intel_cmd *cmd,
1889 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001890{
Chia-I Wua57761b2014-10-14 14:27:44 +08001891 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1892 uint32_t offset;
1893 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001894
Chia-I Wua57761b2014-10-14 14:27:44 +08001895 /* see if the shader is already in the cache */
1896 for (i = 0; i < cache->used; i++) {
1897 if (cache->entries[i].shader == (const void *) shader)
1898 return cache->entries[i].kernel_offset;
1899 }
1900
1901 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1902
1903 /* grow the cache if full */
1904 if (cache->used >= cache->count) {
1905 const XGL_UINT count = cache->count + 16;
1906 void *entries;
1907
1908 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1909 XGL_SYSTEM_ALLOC_INTERNAL);
1910 if (entries) {
1911 if (cache->entries) {
1912 memcpy(entries, cache->entries,
1913 sizeof(cache->entries[0]) * cache->used);
1914 icd_free(cache->entries);
1915 }
1916
1917 cache->entries = entries;
1918 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001919 }
1920 }
1921
Chia-I Wua57761b2014-10-14 14:27:44 +08001922 /* add the shader to the cache */
1923 if (cache->used < cache->count) {
1924 cache->entries[cache->used].shader = (const void *) shader;
1925 cache->entries[cache->used].kernel_offset = offset;
1926 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001927 }
1928
Chia-I Wua57761b2014-10-14 14:27:44 +08001929 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001930}
1931
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001932static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001933{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001934 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001935
Chia-I Wu8370b402014-08-29 12:28:37 +08001936 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1937 cmd_wa_gen6_pre_depth_stall_write(cmd);
1938 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1939 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1940 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1941 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001942
1943 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001944 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001945 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001946
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001947 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001948 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001949 }
1950 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001951 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001952 }
1953 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001954 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1955 }
1956 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1957 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1958 }
1959 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1960 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001961 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001962
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001963 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1964 gen7_3DSTATE_GS(cmd);
1965 } else {
1966 gen6_3DSTATE_GS(cmd);
1967 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001968
Chia-I Wu8370b402014-08-29 12:28:37 +08001969 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1970 cmd_wa_gen7_post_command_cs_stall(cmd);
1971 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1972 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001973}
1974
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001975static void emit_bounded_states(struct intel_cmd *cmd)
1976{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001977
1978 emit_graphics_pipeline(cmd);
1979
1980 emit_rt(cmd);
1981 emit_ds(cmd);
1982
1983 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1984 gen7_cc_states(cmd);
1985 gen7_viewport_states(cmd);
1986
1987 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1988 &cmd->bind.pipeline.graphics->vs);
1989 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1990 &cmd->bind.pipeline.graphics->fs);
1991
1992 gen6_3DSTATE_CLIP(cmd);
1993 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001994 gen7_3DSTATE_WM(cmd);
1995 gen7_3DSTATE_PS(cmd);
1996 } else {
1997 gen6_cc_states(cmd);
1998 gen6_viewport_states(cmd);
1999
2000 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2001 &cmd->bind.pipeline.graphics->vs);
2002 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2003 &cmd->bind.pipeline.graphics->fs);
2004
2005 gen6_3DSTATE_CLIP(cmd);
2006 gen6_3DSTATE_SF(cmd);
2007 gen6_3DSTATE_WM(cmd);
2008 }
2009
2010 emit_shader_resources(cmd);
2011
2012 cmd_wa_gen6_pre_depth_stall_write(cmd);
2013 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2014
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002015 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2016 gen6_3DSTATE_VS(cmd);
2017}
2018
Tony Barbourfa6cac72015-01-16 14:27:35 -07002019static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
2020 const struct intel_cmd_meta *meta)
2021{
2022 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2023 const uint8_t cmd_len = 3;
2024 uint32_t dw[3];
2025 uint32_t cmd_depth_stencil;
2026 uint32_t cmd_depth_test;
2027
2028 CMD_ASSERT(cmd, 6, 7.5);
2029
2030 cmd_depth_stencil = 0;
2031 cmd_depth_test = 0;
2032 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
2033 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
2034 GEN6_COMPAREFUNCTION_ALWAYS << 27;
2035 }
2036 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2037 cmd_depth_stencil = 1 << 31 |
2038 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2039 (GEN6_STENCILOP_KEEP) << 25 |
2040 (GEN6_STENCILOP_KEEP) << 22 |
2041 (GEN6_STENCILOP_REPLACE) << 19 |
2042 1 << 15 |
2043 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2044 (GEN6_STENCILOP_KEEP) << 9 |
2045 (GEN6_STENCILOP_KEEP) << 6 |
2046 (GEN6_STENCILOP_REPLACE) << 3;
2047 }
2048
2049 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2050 dw[0] = cmd_depth_stencil | 1 << 18;
2051 dw[1] = (0xff) << 24 | (0xff) << 16;
2052 dw[2] = cmd_depth_test;
2053
2054 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2055 cmd_align, cmd_len, dw);
2056}
2057
Chia-I Wu6032b892014-10-17 14:47:18 +08002058static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2059{
2060 const struct intel_cmd_meta *meta = cmd->bind.meta;
2061 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2062
2063 CMD_ASSERT(cmd, 6, 7.5);
2064
2065 blend_offset = 0;
2066 ds_offset = 0;
2067 cc_offset = 0;
2068 cc_vp_offset = 0;
2069
Chia-I Wu29e6f502014-11-24 14:27:29 +08002070 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002071 /* BLEND_STATE */
2072 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002073 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002074 dw[0] = 0;
2075 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2076 }
2077
Chia-I Wu29e6f502014-11-24 14:27:29 +08002078 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002079 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002080 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002081 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2082 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002083
Chia-I Wu29e6f502014-11-24 14:27:29 +08002084 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002085 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002086
Chia-I Wu29e6f502014-11-24 14:27:29 +08002087 /* COLOR_CALC_STATE */
2088 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002089 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002090
Chia-I Wu29e6f502014-11-24 14:27:29 +08002091 /* CC_VIEWPORT */
2092 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002093 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002094 dw[0] = u_fui(0.0f);
2095 dw[1] = u_fui(1.0f);
2096 } else {
2097 /* DEPTH_STENCIL_STATE */
2098 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002099 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002100 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2101 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2102 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002103 }
2104
2105 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2106 gen7_3dstate_pointer(cmd,
2107 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2108 blend_offset);
2109 gen7_3dstate_pointer(cmd,
2110 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2111 ds_offset);
2112 gen7_3dstate_pointer(cmd,
2113 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2114
2115 gen7_3dstate_pointer(cmd,
2116 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2117 cc_vp_offset);
2118 } else {
2119 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002120 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002121
2122 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2123 cmd_batch_pointer(cmd, 4, &dw);
2124 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2125 GEN6_PTR_VP_DW0_CC_CHANGED;
2126 dw[1] = 0;
2127 dw[2] = 0;
2128 dw[3] = cc_vp_offset;
2129 }
2130}
2131
2132static void gen6_meta_surface_states(struct intel_cmd *cmd)
2133{
2134 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002135 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002136 uint32_t offset;
2137
2138 CMD_ASSERT(cmd, 6, 7.5);
2139
Chia-I Wu29e6f502014-11-24 14:27:29 +08002140 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2141 return;
2142
Chia-I Wu005c47c2014-10-22 13:49:13 +08002143 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002144 if (meta->src.valid) {
2145 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002146 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002147 meta->src.surface_len, meta->src.surface);
2148
2149 cmd_reserve_reloc(cmd, 1);
2150 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2151 cmd_surface_reloc_writer(cmd, offset, 1,
2152 meta->src.reloc_target, meta->src.reloc_offset);
2153 } else {
2154 cmd_surface_reloc(cmd, offset, 1,
2155 (struct intel_bo *) meta->src.reloc_target,
2156 meta->src.reloc_offset, meta->src.reloc_flags);
2157 }
2158
Chia-I Wu005c47c2014-10-22 13:49:13 +08002159 binding_table[0] = offset;
2160 }
2161 if (meta->dst.valid) {
2162 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002163 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002164 meta->dst.surface_len, meta->dst.surface);
2165
2166 cmd_reserve_reloc(cmd, 1);
2167 cmd_surface_reloc(cmd, offset, 1,
2168 (struct intel_bo *) meta->dst.reloc_target,
2169 meta->dst.reloc_offset, meta->dst.reloc_flags);
2170
2171 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002172 }
2173
2174 /* BINDING_TABLE */
2175 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002176 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002177 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002178
2179 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002180 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2181 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2182 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2183 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002184 } else {
2185 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002186 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2187 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2188 else
2189 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002190 }
2191}
2192
2193static void gen6_meta_urb(struct intel_cmd *cmd)
2194{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002195 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002196 uint32_t *dw;
2197
2198 CMD_ASSERT(cmd, 6, 6);
2199
2200 /* 3DSTATE_URB */
2201 cmd_batch_pointer(cmd, 3, &dw);
2202 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002203 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002204 dw[2] = 0;
2205}
2206
2207static void gen7_meta_urb(struct intel_cmd *cmd)
2208{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002209 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002210 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002211 uint32_t *dw;
2212
2213 CMD_ASSERT(cmd, 7, 7.5);
2214
2215 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2216 cmd_batch_pointer(cmd, 10, &dw);
2217
2218 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002219 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002220 dw += 2;
2221
2222 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2223 dw[1] = 0;
2224 dw += 2;
2225
2226 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2227 dw[1] = 0;
2228 dw += 2;
2229
2230 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2231 dw[1] = 0;
2232 dw += 2;
2233
2234 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002235 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002236
2237 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2238
Chia-I Wu24aa1022014-11-25 11:53:19 +08002239 switch (cmd_gen(cmd)) {
2240 case INTEL_GEN(7.5):
2241 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2242 break;
2243 case INTEL_GEN(7):
2244 default:
2245 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2246 break;
2247 }
2248
Chia-I Wu6032b892014-10-17 14:47:18 +08002249 /* 3DSTATE_URB_x */
2250 cmd_batch_pointer(cmd, 8, &dw);
2251
2252 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2253 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002254 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002255 dw += 2;
2256
2257 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2258 dw[1] = 0;
2259 dw += 2;
2260
2261 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2262 dw[1] = 0;
2263 dw += 2;
2264
2265 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2266 dw[1] = 0;
2267 dw += 2;
2268}
2269
2270static void gen6_meta_vf(struct intel_cmd *cmd)
2271{
2272 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002273 uint32_t vb_start, vb_end, vb_stride;
2274 int ve_format, ve_z_source;
2275 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002276 XGL_UINT pos;
2277
2278 CMD_ASSERT(cmd, 6, 7.5);
2279
Chia-I Wu29e6f502014-11-24 14:27:29 +08002280 switch (meta->mode) {
2281 case INTEL_CMD_META_VS_POINTS:
2282 cmd_batch_pointer(cmd, 3, &dw);
2283 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2284 dw[1] = GEN6_VE_STATE_DW0_VALID;
2285 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2286 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2287 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2288 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2289 return;
2290 break;
2291 case INTEL_CMD_META_FS_RECT:
2292 {
2293 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002294
Chia-I Wu29e6f502014-11-24 14:27:29 +08002295 vertices[0][0] = meta->dst.x + meta->width;
2296 vertices[0][1] = meta->dst.y + meta->height;
2297 vertices[1][0] = meta->dst.x;
2298 vertices[1][1] = meta->dst.y + meta->height;
2299 vertices[2][0] = meta->dst.x;
2300 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002301
Chia-I Wu29e6f502014-11-24 14:27:29 +08002302 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2303 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002304
Chia-I Wu29e6f502014-11-24 14:27:29 +08002305 vb_end = vb_start + sizeof(vertices) - 1;
2306 vb_stride = sizeof(vertices[0]);
2307 ve_z_source = GEN6_VFCOMP_STORE_0;
2308 ve_format = GEN6_FORMAT_R32G32_USCALED;
2309 }
2310 break;
2311 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2312 {
2313 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002314
Chia-I Wu29e6f502014-11-24 14:27:29 +08002315 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2316 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2317 vertices[0][2] = u_uif(meta->clear_val[0]);
2318 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2319 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2320 vertices[1][2] = u_uif(meta->clear_val[0]);
2321 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2322 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2323 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002324
Chia-I Wu29e6f502014-11-24 14:27:29 +08002325 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2326 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002327
Chia-I Wu29e6f502014-11-24 14:27:29 +08002328 vb_end = vb_start + sizeof(vertices) - 1;
2329 vb_stride = sizeof(vertices[0]);
2330 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2331 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2332 }
2333 break;
2334 default:
2335 assert(!"unknown meta mode");
2336 return;
2337 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002338 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002339
2340 /* 3DSTATE_VERTEX_BUFFERS */
2341 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002342
Chia-I Wu6032b892014-10-17 14:47:18 +08002343 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002344 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002345 if (cmd_gen(cmd) >= INTEL_GEN(7))
2346 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2347
2348 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002349 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2350 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002351
2352 dw[4] = 0;
2353
2354 /* 3DSTATE_VERTEX_ELEMENTS */
2355 cmd_batch_pointer(cmd, 5, &dw);
2356 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002357 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002358 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2359 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2360 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2361 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2362 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002363 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002364 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2365 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002366 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002367 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2368}
2369
Chia-I Wu29e6f502014-11-24 14:27:29 +08002370static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002371{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002372 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002373 /* one GPR */
2374 XGL_UINT consts[8];
2375 XGL_UINT const_count;
2376
2377 CMD_ASSERT(cmd, 6, 7.5);
2378
2379 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002380 case INTEL_DEV_META_VS_FILL_MEM:
2381 consts[0] = meta->dst.x;
2382 consts[1] = meta->clear_val[0];
2383 const_count = 2;
2384 break;
2385 case INTEL_DEV_META_VS_COPY_MEM:
2386 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2387 consts[0] = meta->dst.x;
2388 consts[1] = meta->src.x;
2389 const_count = 2;
2390 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002391 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2392 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2393 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2394 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2395 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2396 consts[0] = meta->src.x;
2397 consts[1] = meta->src.y;
2398 consts[2] = meta->width;
2399 consts[3] = meta->dst.x;
2400 const_count = 4;
2401 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002402 default:
2403 assert(!"unknown meta shader id");
2404 const_count = 0;
2405 break;
2406 }
2407
2408 /* this can be skipped but it makes state dumping prettier */
2409 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2410
2411 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2412}
2413
2414static void gen6_meta_vs(struct intel_cmd *cmd)
2415{
2416 const struct intel_cmd_meta *meta = cmd->bind.meta;
2417 const struct intel_pipeline_shader *sh =
2418 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2419 uint32_t offset, *dw;
2420
2421 CMD_ASSERT(cmd, 6, 7.5);
2422
2423 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2424 XGL_UINT cmd_len;
2425
2426 /* 3DSTATE_CONSTANT_VS */
2427 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2428 cmd_batch_pointer(cmd, cmd_len, &dw);
2429 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2430 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2431
2432 /* 3DSTATE_VS */
2433 cmd_batch_pointer(cmd, 6, &dw);
2434 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2435 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2436
2437 return;
2438 }
2439
2440 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2441
2442 /* 3DSTATE_CONSTANT_VS */
2443 offset = gen6_meta_vs_constants(cmd);
2444 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2445 cmd_batch_pointer(cmd, 7, &dw);
2446 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2447 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2448 dw[2] = 0;
2449 dw[3] = offset;
2450 dw[4] = 0;
2451 dw[5] = 0;
2452 dw[6] = 0;
2453 } else {
2454 cmd_batch_pointer(cmd, 5, &dw);
2455 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2456 GEN6_PCB_ANY_DW0_PCB0_VALID;
2457 dw[1] = offset;
2458 dw[2] = 0;
2459 dw[3] = 0;
2460 dw[4] = 0;
2461 }
2462
2463 /* 3DSTATE_VS */
2464 offset = emit_shader(cmd, sh);
2465 cmd_batch_pointer(cmd, 6, &dw);
2466 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2467 dw[1] = offset;
2468 dw[2] = GEN6_THREADDISP_SPF |
2469 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2470 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002471 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002472 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2473 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2474
2475 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2476 GEN6_VS_DW5_VS_ENABLE;
2477 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002478 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002479 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002480 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002481
2482 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002483}
2484
2485static void gen6_meta_disabled(struct intel_cmd *cmd)
2486{
Chia-I Wu6032b892014-10-17 14:47:18 +08002487 uint32_t *dw;
2488
2489 CMD_ASSERT(cmd, 6, 6);
2490
Chia-I Wu6032b892014-10-17 14:47:18 +08002491 /* 3DSTATE_CONSTANT_GS */
2492 cmd_batch_pointer(cmd, 5, &dw);
2493 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2494 dw[1] = 0;
2495 dw[2] = 0;
2496 dw[3] = 0;
2497 dw[4] = 0;
2498
2499 /* 3DSTATE_GS */
2500 cmd_batch_pointer(cmd, 7, &dw);
2501 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2502 dw[1] = 0;
2503 dw[2] = 0;
2504 dw[3] = 0;
2505 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2506 dw[5] = GEN6_GS_DW5_STATISTICS;
2507 dw[6] = 0;
2508
Chia-I Wu6032b892014-10-17 14:47:18 +08002509 /* 3DSTATE_SF */
2510 cmd_batch_pointer(cmd, 20, &dw);
2511 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2512 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2513 memset(&dw[2], 0, 18 * sizeof(*dw));
2514}
2515
2516static void gen7_meta_disabled(struct intel_cmd *cmd)
2517{
2518 uint32_t *dw;
2519
2520 CMD_ASSERT(cmd, 7, 7.5);
2521
Chia-I Wu6032b892014-10-17 14:47:18 +08002522 /* 3DSTATE_CONSTANT_HS */
2523 cmd_batch_pointer(cmd, 7, &dw);
2524 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2525 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2526
2527 /* 3DSTATE_HS */
2528 cmd_batch_pointer(cmd, 7, &dw);
2529 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2530 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2531
2532 /* 3DSTATE_TE */
2533 cmd_batch_pointer(cmd, 4, &dw);
2534 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2535 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2536
2537 /* 3DSTATE_CONSTANT_DS */
2538 cmd_batch_pointer(cmd, 7, &dw);
2539 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2540 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2541
2542 /* 3DSTATE_DS */
2543 cmd_batch_pointer(cmd, 6, &dw);
2544 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2545 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2546
2547 /* 3DSTATE_CONSTANT_GS */
2548 cmd_batch_pointer(cmd, 7, &dw);
2549 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2550 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2551
2552 /* 3DSTATE_GS */
2553 cmd_batch_pointer(cmd, 7, &dw);
2554 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2555 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2556
2557 /* 3DSTATE_STREAMOUT */
2558 cmd_batch_pointer(cmd, 3, &dw);
2559 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2560 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2561
Chia-I Wu6032b892014-10-17 14:47:18 +08002562 /* 3DSTATE_SF */
2563 cmd_batch_pointer(cmd, 7, &dw);
2564 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2565 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2566
2567 /* 3DSTATE_SBE */
2568 cmd_batch_pointer(cmd, 14, &dw);
2569 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2570 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2571 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002572}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002573
Chia-I Wu29e6f502014-11-24 14:27:29 +08002574static void gen6_meta_clip(struct intel_cmd *cmd)
2575{
2576 const struct intel_cmd_meta *meta = cmd->bind.meta;
2577 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002578
Chia-I Wu29e6f502014-11-24 14:27:29 +08002579 /* 3DSTATE_CLIP */
2580 cmd_batch_pointer(cmd, 4, &dw);
2581 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2582 dw[1] = 0;
2583 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2584 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2585 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2586 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002587 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002588 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002589 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002590}
2591
2592static void gen6_meta_wm(struct intel_cmd *cmd)
2593{
2594 const struct intel_cmd_meta *meta = cmd->bind.meta;
2595 uint32_t *dw;
2596
2597 CMD_ASSERT(cmd, 6, 7.5);
2598
2599 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2600
2601 /* 3DSTATE_MULTISAMPLE */
2602 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2603 cmd_batch_pointer(cmd, 4, &dw);
2604 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2605 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2606 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2607 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2608 dw[2] = 0;
2609 dw[3] = 0;
2610 } else {
2611 cmd_batch_pointer(cmd, 3, &dw);
2612 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2613 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2614 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2615 dw[2] = 0;
2616 }
2617
2618 /* 3DSTATE_SAMPLE_MASK */
2619 cmd_batch_pointer(cmd, 2, &dw);
2620 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2621 dw[1] = (1 << meta->samples) - 1;
2622
2623 /* 3DSTATE_DRAWING_RECTANGLE */
2624 cmd_batch_pointer(cmd, 4, &dw);
2625 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2626 dw[1] = meta->dst.y << 16 | meta->dst.x;
2627 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2628 (meta->dst.x + meta->width - 1);
2629 dw[3] = 0;
2630}
2631
2632static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2633{
2634 const struct intel_cmd_meta *meta = cmd->bind.meta;
2635 XGL_UINT offset_x, offset_y;
2636 /* one GPR */
2637 XGL_UINT consts[8];
2638 XGL_UINT const_count;
2639
2640 CMD_ASSERT(cmd, 6, 7.5);
2641
2642 /* underflow is fine here */
2643 offset_x = meta->src.x - meta->dst.x;
2644 offset_y = meta->src.y - meta->dst.y;
2645
2646 switch (meta->shader_id) {
2647 case INTEL_DEV_META_FS_COPY_MEM:
2648 case INTEL_DEV_META_FS_COPY_1D:
2649 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2650 case INTEL_DEV_META_FS_COPY_2D:
2651 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2652 case INTEL_DEV_META_FS_COPY_2D_MS:
2653 consts[0] = offset_x;
2654 consts[1] = offset_y;
2655 consts[2] = meta->src.layer;
2656 consts[3] = meta->src.lod;
2657 const_count = 4;
2658 break;
2659 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2660 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2661 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2662 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2663 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2664 consts[0] = offset_x;
2665 consts[1] = offset_y;
2666 consts[2] = meta->src.layer;
2667 consts[3] = meta->src.lod;
2668 consts[4] = meta->src.x;
2669 consts[5] = meta->width;
2670 const_count = 6;
2671 break;
2672 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2673 consts[0] = offset_x;
2674 consts[1] = offset_y;
2675 consts[2] = meta->width;
2676 const_count = 3;
2677 break;
2678 case INTEL_DEV_META_FS_CLEAR_COLOR:
2679 consts[0] = meta->clear_val[0];
2680 consts[1] = meta->clear_val[1];
2681 consts[2] = meta->clear_val[2];
2682 consts[3] = meta->clear_val[3];
2683 const_count = 4;
2684 break;
2685 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2686 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002687 consts[1] = meta->clear_val[1];
2688 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002689 break;
2690 case INTEL_DEV_META_FS_RESOLVE_2X:
2691 case INTEL_DEV_META_FS_RESOLVE_4X:
2692 case INTEL_DEV_META_FS_RESOLVE_8X:
2693 case INTEL_DEV_META_FS_RESOLVE_16X:
2694 consts[0] = offset_x;
2695 consts[1] = offset_y;
2696 const_count = 2;
2697 break;
2698 default:
2699 assert(!"unknown meta shader id");
2700 const_count = 0;
2701 break;
2702 }
2703
2704 /* this can be skipped but it makes state dumping prettier */
2705 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2706
2707 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2708}
2709
2710static void gen6_meta_ps(struct intel_cmd *cmd)
2711{
2712 const struct intel_cmd_meta *meta = cmd->bind.meta;
2713 const struct intel_pipeline_shader *sh =
2714 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2715 uint32_t offset, *dw;
2716
2717 CMD_ASSERT(cmd, 6, 6);
2718
Chia-I Wu29e6f502014-11-24 14:27:29 +08002719 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2720 /* 3DSTATE_CONSTANT_PS */
2721 cmd_batch_pointer(cmd, 5, &dw);
2722 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2723 dw[1] = 0;
2724 dw[2] = 0;
2725 dw[3] = 0;
2726 dw[4] = 0;
2727
2728 /* 3DSTATE_WM */
2729 cmd_batch_pointer(cmd, 9, &dw);
2730 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2731 dw[1] = 0;
2732 dw[2] = 0;
2733 dw[3] = 0;
2734 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002735 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002736 dw[6] = 0;
2737 dw[7] = 0;
2738 dw[8] = 0;
2739
Chia-I Wu3adf7212014-10-24 15:34:07 +08002740 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002741 }
2742
Chia-I Wu3adf7212014-10-24 15:34:07 +08002743 /* a normal color write */
2744 assert(meta->dst.valid && !sh->uses);
2745
Chia-I Wu6032b892014-10-17 14:47:18 +08002746 /* 3DSTATE_CONSTANT_PS */
2747 offset = gen6_meta_ps_constants(cmd);
2748 cmd_batch_pointer(cmd, 5, &dw);
2749 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2750 GEN6_PCB_ANY_DW0_PCB0_VALID;
2751 dw[1] = offset;
2752 dw[2] = 0;
2753 dw[3] = 0;
2754 dw[4] = 0;
2755
2756 /* 3DSTATE_WM */
2757 offset = emit_shader(cmd, sh);
2758 cmd_batch_pointer(cmd, 9, &dw);
2759 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2760 dw[1] = offset;
2761 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2762 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002763 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002764 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002765 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002766 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002767 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2768
Chia-I Wu6032b892014-10-17 14:47:18 +08002769 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2770 GEN6_WM_DW6_POSOFFSET_NONE |
2771 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2772 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2773 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2774 if (meta->samples > 1) {
2775 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2776 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2777 } else {
2778 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2779 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2780 }
2781 dw[7] = 0;
2782 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002783
2784 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002785}
2786
2787static void gen7_meta_ps(struct intel_cmd *cmd)
2788{
2789 const struct intel_cmd_meta *meta = cmd->bind.meta;
2790 const struct intel_pipeline_shader *sh =
2791 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2792 uint32_t offset, *dw;
2793
2794 CMD_ASSERT(cmd, 7, 7.5);
2795
Chia-I Wu29e6f502014-11-24 14:27:29 +08002796 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2797 /* 3DSTATE_WM */
2798 cmd_batch_pointer(cmd, 3, &dw);
2799 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2800 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2801
2802 /* 3DSTATE_CONSTANT_GS */
2803 cmd_batch_pointer(cmd, 7, &dw);
2804 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2805 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2806
2807 /* 3DSTATE_PS */
2808 cmd_batch_pointer(cmd, 8, &dw);
2809 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2810 dw[1] = 0;
2811 dw[2] = 0;
2812 dw[3] = 0;
2813 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002814 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002815 dw[5] = 0;
2816 dw[6] = 0;
2817 dw[7] = 0;
2818
Chia-I Wu3adf7212014-10-24 15:34:07 +08002819 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002820 }
2821
Chia-I Wu3adf7212014-10-24 15:34:07 +08002822 /* a normal color write */
2823 assert(meta->dst.valid && !sh->uses);
2824
Chia-I Wu6032b892014-10-17 14:47:18 +08002825 /* 3DSTATE_WM */
2826 cmd_batch_pointer(cmd, 3, &dw);
2827 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2828 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2829 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2830 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2831 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2832 dw[2] = 0;
2833
2834 /* 3DSTATE_CONSTANT_PS */
2835 offset = gen6_meta_ps_constants(cmd);
2836 cmd_batch_pointer(cmd, 7, &dw);
2837 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2838 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2839 dw[2] = 0;
2840 dw[3] = offset;
2841 dw[4] = 0;
2842 dw[5] = 0;
2843 dw[6] = 0;
2844
2845 /* 3DSTATE_PS */
2846 offset = emit_shader(cmd, sh);
2847 cmd_batch_pointer(cmd, 8, &dw);
2848 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2849 dw[1] = offset;
2850 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2851 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002852 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002853
2854 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2855 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002856 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2857
2858 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002859 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002860 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002861 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002862 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002863 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002864
2865 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2866 dw[6] = 0;
2867 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002868
2869 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002870}
2871
2872static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2873{
2874 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002875 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002876
2877 CMD_ASSERT(cmd, 6, 7.5);
2878
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002879 if (!ds) {
2880 /* all zeros */
2881 static const struct intel_ds_view null_ds;
2882 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002883 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002884
2885 cmd_wa_gen6_pre_ds_flush(cmd);
2886 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2887 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2888 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2889
2890 if (cmd_gen(cmd) >= INTEL_GEN(7))
2891 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2892 else
2893 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002894}
2895
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002896static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2897 const struct intel_pipeline *pipeline)
2898{
2899 cmd->bind.pipeline.graphics = pipeline;
2900}
2901
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002902static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2903 const struct intel_pipeline *pipeline)
2904{
2905 cmd->bind.pipeline.compute = pipeline;
2906}
2907
2908static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2909 const struct intel_pipeline_delta *delta)
2910{
2911 cmd->bind.pipeline.graphics_delta = delta;
2912}
2913
2914static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2915 const struct intel_pipeline_delta *delta)
2916{
2917 cmd->bind.pipeline.compute_delta = delta;
2918}
2919
2920static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2921 const struct intel_dset *dset,
2922 XGL_UINT slot_offset)
2923{
2924 cmd->bind.dset.graphics = dset;
2925 cmd->bind.dset.graphics_offset = slot_offset;
2926}
2927
2928static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2929 const struct intel_dset *dset,
2930 XGL_UINT slot_offset)
2931{
2932 cmd->bind.dset.compute = dset;
2933 cmd->bind.dset.compute_offset = slot_offset;
2934}
2935
2936static void cmd_bind_graphics_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.graphics = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002940}
2941
2942static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002943 const XGL_BUFFER_VIEW_ATTACH_INFO *info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002944{
Chia-I Wu714df452015-01-01 07:55:04 +08002945 cmd->bind.dyn_view.compute = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002946}
2947
Chia-I Wu3b04af52014-11-08 10:48:20 +08002948static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002949 const struct intel_buf *buf,
Chia-I Wu3b04af52014-11-08 10:48:20 +08002950 XGL_GPU_SIZE offset, XGL_UINT binding)
2951{
Chia-I Wu714df452015-01-01 07:55:04 +08002952 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002953 cmd->result = XGL_ERROR_UNKNOWN;
2954 return;
2955 }
2956
Chia-I Wu714df452015-01-01 07:55:04 +08002957 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002958 cmd->bind.vertex.offset[binding] = offset;
2959}
2960
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002961static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002962 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002963 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2964{
Chia-I Wu714df452015-01-01 07:55:04 +08002965 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002966 cmd->bind.index.offset = offset;
2967 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002968}
2969
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002970static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002971 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002972{
2973 cmd->bind.state.viewport = state;
2974}
2975
2976static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002977 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002978{
2979 cmd->bind.state.raster = state;
2980}
2981
2982static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002983 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002984{
2985 cmd->bind.state.ds = state;
2986}
2987
2988static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002989 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002990{
2991 cmd->bind.state.blend = state;
2992}
2993
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002994static void cmd_draw(struct intel_cmd *cmd,
2995 XGL_UINT vertex_start,
2996 XGL_UINT vertex_count,
2997 XGL_UINT instance_start,
2998 XGL_UINT instance_count,
2999 bool indexed,
3000 XGL_UINT vertex_base)
3001{
3002 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
3003
3004 emit_bounded_states(cmd);
3005
3006 if (indexed) {
3007 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3008 cmd->result = XGL_ERROR_UNKNOWN;
3009
3010 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3011 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3012 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003013 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003014 cmd->bind.index.offset, cmd->bind.index.type,
3015 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003016 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003017 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003018 cmd->bind.index.offset, cmd->bind.index.type,
3019 p->primitive_restart);
3020 }
3021 } else {
3022 assert(!vertex_base);
3023 }
3024
3025 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3026 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3027 vertex_start, instance_count, instance_start, vertex_base);
3028 } else {
3029 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3030 vertex_start, instance_count, instance_start, vertex_base);
3031 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003032
Chia-I Wu707a29e2014-08-27 12:51:47 +08003033 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003034 /* need to re-emit all workarounds */
3035 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003036
3037 if (intel_debug & INTEL_DEBUG_NOCACHE)
3038 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003039}
3040
Chia-I Wuc14d1562014-10-17 09:49:22 +08003041void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3042{
Chia-I Wu6032b892014-10-17 14:47:18 +08003043 cmd->bind.meta = meta;
3044
3045 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003046 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003047
3048 gen6_meta_dynamic_states(cmd);
3049 gen6_meta_surface_states(cmd);
3050
3051 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3052 gen7_meta_urb(cmd);
3053 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003054 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003055 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003056 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003057 gen6_meta_wm(cmd);
3058 gen7_meta_ps(cmd);
3059 gen6_meta_depth_buffer(cmd);
3060
3061 cmd_wa_gen7_post_command_cs_stall(cmd);
3062 cmd_wa_gen7_post_command_depth_stall(cmd);
3063
Chia-I Wu29e6f502014-11-24 14:27:29 +08003064 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3065 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003066 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003067 } else {
3068 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3069 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003070 } else {
3071 gen6_meta_urb(cmd);
3072 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003073 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003074 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003075 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003076 gen6_meta_wm(cmd);
3077 gen6_meta_ps(cmd);
3078 gen6_meta_depth_buffer(cmd);
3079
Chia-I Wu29e6f502014-11-24 14:27:29 +08003080 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3081 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003082 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003083 } else {
3084 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3085 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003086 }
3087
3088 cmd->bind.draw_count++;
3089 /* need to re-emit all workarounds */
3090 cmd->bind.wa_flags = 0;
3091
3092 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003093
3094 if (intel_debug & INTEL_DEBUG_NOCACHE)
3095 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003096}
3097
Chia-I Wu96177272015-01-03 15:27:41 +08003098ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003099 XGL_CMD_BUFFER cmdBuffer,
3100 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3101 XGL_PIPELINE pipeline)
3102{
3103 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3104
3105 switch (pipelineBindPoint) {
3106 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003107 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003108 break;
3109 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003110 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003111 break;
3112 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003113 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003114 break;
3115 }
3116}
3117
Chia-I Wu96177272015-01-03 15:27:41 +08003118ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003119 XGL_CMD_BUFFER cmdBuffer,
3120 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3121 XGL_PIPELINE_DELTA delta)
3122{
3123 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3124
3125 switch (pipelineBindPoint) {
3126 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003127 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003128 break;
3129 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003130 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003131 break;
3132 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003133 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003134 break;
3135 }
3136}
3137
Tony Barbourfa6cac72015-01-16 14:27:35 -07003138ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003139 XGL_CMD_BUFFER cmdBuffer,
3140 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003141 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003142{
3143 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3144
3145 switch (stateBindPoint) {
3146 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003147 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003148 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003149 break;
3150 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003151 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003152 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003153 break;
3154 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003155 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003156 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003157 break;
3158 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003159 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003160 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003161 break;
3162 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003163 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003164 break;
3165 }
3166}
3167
Chia-I Wu96177272015-01-03 15:27:41 +08003168ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003169 XGL_CMD_BUFFER cmdBuffer,
3170 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3171 XGL_UINT index,
3172 XGL_DESCRIPTOR_SET descriptorSet,
3173 XGL_UINT slotOffset)
3174{
3175 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3176 struct intel_dset *dset = intel_dset(descriptorSet);
3177
3178 assert(!index);
3179
3180 switch (pipelineBindPoint) {
3181 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003182 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003183 break;
3184 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003185 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003186 break;
3187 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003188 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003189 break;
3190 }
3191}
3192
Chia-I Wu714df452015-01-01 07:55:04 +08003193ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicBufferView(
Chia-I Wub2755562014-08-20 13:38:52 +08003194 XGL_CMD_BUFFER cmdBuffer,
3195 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wu714df452015-01-01 07:55:04 +08003196 const XGL_BUFFER_VIEW_ATTACH_INFO* pBufferView)
Chia-I Wub2755562014-08-20 13:38:52 +08003197{
3198 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3199
3200 switch (pipelineBindPoint) {
3201 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu714df452015-01-01 07:55:04 +08003202 cmd_bind_compute_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003203 break;
3204 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu714df452015-01-01 07:55:04 +08003205 cmd_bind_graphics_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003206 break;
3207 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003208 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003209 break;
3210 }
3211}
3212
Chia-I Wu714df452015-01-01 07:55:04 +08003213ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003214 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003215 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003216 XGL_GPU_SIZE offset,
3217 XGL_UINT binding)
3218{
3219 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003220 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003221
Chia-I Wu714df452015-01-01 07:55:04 +08003222 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003223}
3224
Chia-I Wu714df452015-01-01 07:55:04 +08003225ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003226 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003227 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003228 XGL_GPU_SIZE offset,
3229 XGL_INDEX_TYPE indexType)
3230{
3231 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003232 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003233
Chia-I Wu714df452015-01-01 07:55:04 +08003234 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003235}
3236
Chia-I Wu96177272015-01-03 15:27:41 +08003237ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003238 XGL_CMD_BUFFER cmdBuffer,
3239 XGL_UINT firstVertex,
3240 XGL_UINT vertexCount,
3241 XGL_UINT firstInstance,
3242 XGL_UINT instanceCount)
3243{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003244 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003245
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003246 cmd_draw(cmd, firstVertex, vertexCount,
3247 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003248}
3249
Chia-I Wu96177272015-01-03 15:27:41 +08003250ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003251 XGL_CMD_BUFFER cmdBuffer,
3252 XGL_UINT firstIndex,
3253 XGL_UINT indexCount,
3254 XGL_INT vertexOffset,
3255 XGL_UINT firstInstance,
3256 XGL_UINT instanceCount)
3257{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003258 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003259
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003260 cmd_draw(cmd, firstIndex, indexCount,
3261 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003262}
3263
Chia-I Wu96177272015-01-03 15:27:41 +08003264ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003265 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003266 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003267 XGL_GPU_SIZE offset,
3268 XGL_UINT32 count,
3269 XGL_UINT32 stride)
3270{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003271 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3272
3273 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003274}
3275
Chia-I Wu96177272015-01-03 15:27:41 +08003276ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003277 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003278 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003279 XGL_GPU_SIZE offset,
3280 XGL_UINT32 count,
3281 XGL_UINT32 stride)
3282{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003283 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3284
3285 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003286}
3287
Chia-I Wu96177272015-01-03 15:27:41 +08003288ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003289 XGL_CMD_BUFFER cmdBuffer,
3290 XGL_UINT x,
3291 XGL_UINT y,
3292 XGL_UINT z)
3293{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003294 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3295
3296 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003297}
3298
Chia-I Wu96177272015-01-03 15:27:41 +08003299ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003300 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003301 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003302 XGL_GPU_SIZE offset)
3303{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003304 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3305
3306 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003307}