blob: c90f9ee7416119576e7a93890950f61e419f82f2 [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 Wu34341ba2015-01-16 17:38:37 +08001608 const uint32_t *cmd_data =
1609 (stage != XGL_SHADER_STAGE_FRAGMENT) ?
1610 dset_slot->u.buf_view->cmd :
1611 dset_slot->u.buf_view->fs_cmd;
Cody Northrop7c76f302014-12-18 11:52:58 -07001612
1613 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1614 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu34341ba2015-01-16 17:38:37 +08001615 dset_slot->u.buf_view->cmd_len,
1616 cmd_data);
Cody Northrop7c76f302014-12-18 11:52:58 -07001617
1618 cmd_reserve_reloc(cmd, 1);
1619 cmd_surface_reloc(cmd, offset, 1,
Chia-I Wu714df452015-01-01 07:55:04 +08001620 dset_slot->u.buf_view->buf->obj.mem->bo,
Chia-I Wu34341ba2015-01-16 17:38:37 +08001621 cmd_data[1], reloc_flags);
Cody Northrop7c76f302014-12-18 11:52:58 -07001622 }
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001623 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001624 case INTEL_DSET_SLOT_SAMPLER:
1625 assert(0 == cmd->bind.dset.graphics_offset);
1626
1627 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001628 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001629 16, dset_slot->u.sampler->cmd);
1630 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001631 default:
1632 assert(!"unexpected dset slot type");
1633 break;
1634 }
1635 }
1636 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001637 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001638 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001639 break;
1640 }
1641
Chia-I Wu72292b72014-09-09 10:48:33 +08001642 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001643 }
1644
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001645 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001646 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001647 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001648}
1649
Chia-I Wu1d125092014-10-08 08:49:38 +08001650static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1651{
1652 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001653 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1654 uint32_t *dw;
1655 XGL_UINT pos, i;
1656
1657 CMD_ASSERT(cmd, 6, 7.5);
1658
1659 if (!pipeline->vb_count)
1660 return;
1661
1662 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1663
1664 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1665 dw++;
1666 pos++;
1667
1668 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001669 assert(pipeline->vb[i].strideInBytes <= 2048);
1670
1671 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1672 pipeline->vb[i].strideInBytes;
1673
1674 if (cmd_gen(cmd) >= INTEL_GEN(7))
1675 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1676
1677 switch (pipeline->vb[i].stepRate) {
1678 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1679 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1680 dw[3] = 0;
1681 break;
1682 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1683 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1684 dw[3] = 1;
1685 break;
1686 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1687 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1688 dw[3] = 0;
1689 break;
1690 default:
1691 assert(!"unknown step rate");
1692 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1693 dw[3] = 0;
1694 break;
1695 }
1696
Chia-I Wu714df452015-01-01 07:55:04 +08001697 if (cmd->bind.vertex.buf[i]) {
1698 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001699 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001700
1701 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001702 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1703 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001704 } else {
1705 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1706 dw[1] = 0;
1707 dw[2] = 0;
1708 }
1709
1710 dw += 4;
1711 pos += 4;
1712 }
1713}
1714
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001715static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1716{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001717 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1718 const struct intel_pipeline_shader *vs = &pipeline->vs;
1719 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001720 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001721 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001722 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001723 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001724
1725 CMD_ASSERT(cmd, 6, 7.5);
1726
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001727 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001728 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1729 *
1730 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1731 * 128-bit vertex elements to be passed into the payload for each
1732 * vertex."
1733 *
1734 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1735 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001736 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001737 vue_read_len = (vs->in_count + 1) / 2;
1738 if (!vue_read_len)
1739 vue_read_len = 1;
1740
1741 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1742 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1743
1744 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1745 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1746 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001747
1748 dw5 = GEN6_VS_DW5_STATISTICS |
1749 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001750
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001751 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001752 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001753 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001754 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001755
Chia-I Wube0a3d92014-09-02 13:20:59 +08001756 if (pipeline->disable_vs_cache)
1757 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1758
Chia-I Wu784d3042014-12-19 14:30:04 +08001759 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001760 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001761 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001762 dw[2] = dw2;
1763 dw[3] = 0; /* scratch */
1764 dw[4] = dw4;
1765 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001766
1767 if (vs->per_thread_scratch_size)
1768 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001769}
1770
Chia-I Wu625105f2014-10-13 15:35:29 +08001771static void emit_shader_resources(struct intel_cmd *cmd)
1772{
1773 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001774 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001775
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001776 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001777 cmd->bind.pipeline.graphics->vs.rmap,
1778 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001779 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001780 cmd->bind.pipeline.graphics->tcs.rmap,
1781 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001782 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001783 cmd->bind.pipeline.graphics->tes.rmap,
1784 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001785 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001786 cmd->bind.pipeline.graphics->gs.rmap,
1787 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001788 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001789 cmd->bind.pipeline.graphics->fs.rmap,
1790 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001791
1792 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1793 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1794 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1795 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1796 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1797
1798 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1799 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001800 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1801 binding_tables[0]);
1802 gen7_3dstate_pointer(cmd,
1803 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1804 binding_tables[1]);
1805 gen7_3dstate_pointer(cmd,
1806 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1807 binding_tables[2]);
1808 gen7_3dstate_pointer(cmd,
1809 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1810 binding_tables[3]);
1811 gen7_3dstate_pointer(cmd,
1812 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1813 binding_tables[4]);
1814
1815 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001816 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1817 samplers[0]);
1818 gen7_3dstate_pointer(cmd,
1819 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1820 samplers[1]);
1821 gen7_3dstate_pointer(cmd,
1822 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1823 samplers[2]);
1824 gen7_3dstate_pointer(cmd,
1825 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1826 samplers[3]);
1827 gen7_3dstate_pointer(cmd,
1828 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1829 samplers[4]);
1830 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001831 assert(!binding_tables[1] && !binding_tables[2]);
1832 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1833 binding_tables[0], binding_tables[3], binding_tables[4]);
1834
Chia-I Wu625105f2014-10-13 15:35:29 +08001835 assert(!samplers[1] && !samplers[2]);
1836 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1837 samplers[0], samplers[3], samplers[4]);
1838 }
1839}
1840
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001841static void emit_rt(struct intel_cmd *cmd)
1842{
1843 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001844 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1845 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001846}
1847
1848static void emit_ds(struct intel_cmd *cmd)
1849{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001850 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001851
1852 if (!ds) {
1853 /* all zeros */
1854 static const struct intel_ds_view null_ds;
1855 ds = &null_ds;
1856 }
1857
1858 cmd_wa_gen6_pre_ds_flush(cmd);
1859 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1860 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1861 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1862
1863 if (cmd_gen(cmd) >= INTEL_GEN(7))
1864 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1865 else
1866 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1867}
1868
Chia-I Wua57761b2014-10-14 14:27:44 +08001869static uint32_t emit_shader(struct intel_cmd *cmd,
1870 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001871{
Chia-I Wua57761b2014-10-14 14:27:44 +08001872 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1873 uint32_t offset;
1874 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001875
Chia-I Wua57761b2014-10-14 14:27:44 +08001876 /* see if the shader is already in the cache */
1877 for (i = 0; i < cache->used; i++) {
1878 if (cache->entries[i].shader == (const void *) shader)
1879 return cache->entries[i].kernel_offset;
1880 }
1881
1882 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1883
1884 /* grow the cache if full */
1885 if (cache->used >= cache->count) {
1886 const XGL_UINT count = cache->count + 16;
1887 void *entries;
1888
1889 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1890 XGL_SYSTEM_ALLOC_INTERNAL);
1891 if (entries) {
1892 if (cache->entries) {
1893 memcpy(entries, cache->entries,
1894 sizeof(cache->entries[0]) * cache->used);
1895 icd_free(cache->entries);
1896 }
1897
1898 cache->entries = entries;
1899 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001900 }
1901 }
1902
Chia-I Wua57761b2014-10-14 14:27:44 +08001903 /* add the shader to the cache */
1904 if (cache->used < cache->count) {
1905 cache->entries[cache->used].shader = (const void *) shader;
1906 cache->entries[cache->used].kernel_offset = offset;
1907 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001908 }
1909
Chia-I Wua57761b2014-10-14 14:27:44 +08001910 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001911}
1912
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001913static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001914{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001915 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001916
Chia-I Wu8370b402014-08-29 12:28:37 +08001917 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1918 cmd_wa_gen6_pre_depth_stall_write(cmd);
1919 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1920 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1921 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1922 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001923
1924 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001925 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001926 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001927
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001928 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001929 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001930 }
1931 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001932 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001933 }
1934 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001935 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1936 }
1937 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1938 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1939 }
1940 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1941 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001942 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001943
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001944 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1945 gen7_3DSTATE_GS(cmd);
1946 } else {
1947 gen6_3DSTATE_GS(cmd);
1948 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001949
Chia-I Wu8370b402014-08-29 12:28:37 +08001950 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1951 cmd_wa_gen7_post_command_cs_stall(cmd);
1952 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1953 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001954}
1955
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001956static void emit_bounded_states(struct intel_cmd *cmd)
1957{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001958
1959 emit_graphics_pipeline(cmd);
1960
1961 emit_rt(cmd);
1962 emit_ds(cmd);
1963
1964 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1965 gen7_cc_states(cmd);
1966 gen7_viewport_states(cmd);
1967
1968 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1969 &cmd->bind.pipeline.graphics->vs);
1970 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1971 &cmd->bind.pipeline.graphics->fs);
1972
1973 gen6_3DSTATE_CLIP(cmd);
1974 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001975 gen7_3DSTATE_WM(cmd);
1976 gen7_3DSTATE_PS(cmd);
1977 } else {
1978 gen6_cc_states(cmd);
1979 gen6_viewport_states(cmd);
1980
1981 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1982 &cmd->bind.pipeline.graphics->vs);
1983 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1984 &cmd->bind.pipeline.graphics->fs);
1985
1986 gen6_3DSTATE_CLIP(cmd);
1987 gen6_3DSTATE_SF(cmd);
1988 gen6_3DSTATE_WM(cmd);
1989 }
1990
1991 emit_shader_resources(cmd);
1992
1993 cmd_wa_gen6_pre_depth_stall_write(cmd);
1994 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1995
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001996 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1997 gen6_3DSTATE_VS(cmd);
1998}
1999
Tony Barbourfa6cac72015-01-16 14:27:35 -07002000static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
2001 const struct intel_cmd_meta *meta)
2002{
2003 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2004 const uint8_t cmd_len = 3;
2005 uint32_t dw[3];
2006 uint32_t cmd_depth_stencil;
2007 uint32_t cmd_depth_test;
2008
2009 CMD_ASSERT(cmd, 6, 7.5);
2010
2011 cmd_depth_stencil = 0;
2012 cmd_depth_test = 0;
2013 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
2014 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
2015 GEN6_COMPAREFUNCTION_ALWAYS << 27;
2016 }
2017 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2018 cmd_depth_stencil = 1 << 31 |
2019 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2020 (GEN6_STENCILOP_KEEP) << 25 |
2021 (GEN6_STENCILOP_KEEP) << 22 |
2022 (GEN6_STENCILOP_REPLACE) << 19 |
2023 1 << 15 |
2024 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2025 (GEN6_STENCILOP_KEEP) << 9 |
2026 (GEN6_STENCILOP_KEEP) << 6 |
2027 (GEN6_STENCILOP_REPLACE) << 3;
2028 }
2029
2030 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2031 dw[0] = cmd_depth_stencil | 1 << 18;
2032 dw[1] = (0xff) << 24 | (0xff) << 16;
2033 dw[2] = cmd_depth_test;
2034
2035 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2036 cmd_align, cmd_len, dw);
2037}
2038
Chia-I Wu6032b892014-10-17 14:47:18 +08002039static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2040{
2041 const struct intel_cmd_meta *meta = cmd->bind.meta;
2042 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2043
2044 CMD_ASSERT(cmd, 6, 7.5);
2045
2046 blend_offset = 0;
2047 ds_offset = 0;
2048 cc_offset = 0;
2049 cc_vp_offset = 0;
2050
Chia-I Wu29e6f502014-11-24 14:27:29 +08002051 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002052 /* BLEND_STATE */
2053 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002054 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002055 dw[0] = 0;
2056 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2057 }
2058
Chia-I Wu29e6f502014-11-24 14:27:29 +08002059 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002060 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002061 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002062 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2063 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002064
Chia-I Wu29e6f502014-11-24 14:27:29 +08002065 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002066 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002067
Chia-I Wu29e6f502014-11-24 14:27:29 +08002068 /* COLOR_CALC_STATE */
2069 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002070 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002071
Chia-I Wu29e6f502014-11-24 14:27:29 +08002072 /* CC_VIEWPORT */
2073 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002074 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002075 dw[0] = u_fui(0.0f);
2076 dw[1] = u_fui(1.0f);
2077 } else {
2078 /* DEPTH_STENCIL_STATE */
2079 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002080 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002081 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2082 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2083 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002084 }
2085
2086 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2087 gen7_3dstate_pointer(cmd,
2088 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2089 blend_offset);
2090 gen7_3dstate_pointer(cmd,
2091 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2092 ds_offset);
2093 gen7_3dstate_pointer(cmd,
2094 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2095
2096 gen7_3dstate_pointer(cmd,
2097 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2098 cc_vp_offset);
2099 } else {
2100 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002101 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002102
2103 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2104 cmd_batch_pointer(cmd, 4, &dw);
2105 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2106 GEN6_PTR_VP_DW0_CC_CHANGED;
2107 dw[1] = 0;
2108 dw[2] = 0;
2109 dw[3] = cc_vp_offset;
2110 }
2111}
2112
2113static void gen6_meta_surface_states(struct intel_cmd *cmd)
2114{
2115 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002116 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002117 uint32_t offset;
2118
2119 CMD_ASSERT(cmd, 6, 7.5);
2120
Chia-I Wu29e6f502014-11-24 14:27:29 +08002121 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2122 return;
2123
Chia-I Wu005c47c2014-10-22 13:49:13 +08002124 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002125 if (meta->src.valid) {
2126 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002127 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002128 meta->src.surface_len, meta->src.surface);
2129
2130 cmd_reserve_reloc(cmd, 1);
2131 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2132 cmd_surface_reloc_writer(cmd, offset, 1,
2133 meta->src.reloc_target, meta->src.reloc_offset);
2134 } else {
2135 cmd_surface_reloc(cmd, offset, 1,
2136 (struct intel_bo *) meta->src.reloc_target,
2137 meta->src.reloc_offset, meta->src.reloc_flags);
2138 }
2139
Chia-I Wu005c47c2014-10-22 13:49:13 +08002140 binding_table[0] = offset;
2141 }
2142 if (meta->dst.valid) {
2143 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002144 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002145 meta->dst.surface_len, meta->dst.surface);
2146
2147 cmd_reserve_reloc(cmd, 1);
2148 cmd_surface_reloc(cmd, offset, 1,
2149 (struct intel_bo *) meta->dst.reloc_target,
2150 meta->dst.reloc_offset, meta->dst.reloc_flags);
2151
2152 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002153 }
2154
2155 /* BINDING_TABLE */
2156 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002157 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002158 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002159
2160 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002161 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2162 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2163 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2164 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002165 } else {
2166 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002167 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2168 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2169 else
2170 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002171 }
2172}
2173
2174static void gen6_meta_urb(struct intel_cmd *cmd)
2175{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002176 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002177 uint32_t *dw;
2178
2179 CMD_ASSERT(cmd, 6, 6);
2180
2181 /* 3DSTATE_URB */
2182 cmd_batch_pointer(cmd, 3, &dw);
2183 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002184 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002185 dw[2] = 0;
2186}
2187
2188static void gen7_meta_urb(struct intel_cmd *cmd)
2189{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002190 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002191 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002192 uint32_t *dw;
2193
2194 CMD_ASSERT(cmd, 7, 7.5);
2195
2196 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2197 cmd_batch_pointer(cmd, 10, &dw);
2198
2199 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002200 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002201 dw += 2;
2202
2203 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2204 dw[1] = 0;
2205 dw += 2;
2206
2207 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2208 dw[1] = 0;
2209 dw += 2;
2210
2211 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2212 dw[1] = 0;
2213 dw += 2;
2214
2215 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002216 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002217
2218 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2219
Chia-I Wu24aa1022014-11-25 11:53:19 +08002220 switch (cmd_gen(cmd)) {
2221 case INTEL_GEN(7.5):
2222 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2223 break;
2224 case INTEL_GEN(7):
2225 default:
2226 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2227 break;
2228 }
2229
Chia-I Wu6032b892014-10-17 14:47:18 +08002230 /* 3DSTATE_URB_x */
2231 cmd_batch_pointer(cmd, 8, &dw);
2232
2233 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2234 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002235 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002236 dw += 2;
2237
2238 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2239 dw[1] = 0;
2240 dw += 2;
2241
2242 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2243 dw[1] = 0;
2244 dw += 2;
2245
2246 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2247 dw[1] = 0;
2248 dw += 2;
2249}
2250
2251static void gen6_meta_vf(struct intel_cmd *cmd)
2252{
2253 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002254 uint32_t vb_start, vb_end, vb_stride;
2255 int ve_format, ve_z_source;
2256 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002257 XGL_UINT pos;
2258
2259 CMD_ASSERT(cmd, 6, 7.5);
2260
Chia-I Wu29e6f502014-11-24 14:27:29 +08002261 switch (meta->mode) {
2262 case INTEL_CMD_META_VS_POINTS:
2263 cmd_batch_pointer(cmd, 3, &dw);
2264 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2265 dw[1] = GEN6_VE_STATE_DW0_VALID;
2266 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2267 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2268 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2269 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2270 return;
2271 break;
2272 case INTEL_CMD_META_FS_RECT:
2273 {
2274 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002275
Chia-I Wu29e6f502014-11-24 14:27:29 +08002276 vertices[0][0] = meta->dst.x + meta->width;
2277 vertices[0][1] = meta->dst.y + meta->height;
2278 vertices[1][0] = meta->dst.x;
2279 vertices[1][1] = meta->dst.y + meta->height;
2280 vertices[2][0] = meta->dst.x;
2281 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002282
Chia-I Wu29e6f502014-11-24 14:27:29 +08002283 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2284 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002285
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 vb_end = vb_start + sizeof(vertices) - 1;
2287 vb_stride = sizeof(vertices[0]);
2288 ve_z_source = GEN6_VFCOMP_STORE_0;
2289 ve_format = GEN6_FORMAT_R32G32_USCALED;
2290 }
2291 break;
2292 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2293 {
2294 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002295
Chia-I Wu29e6f502014-11-24 14:27:29 +08002296 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2297 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2298 vertices[0][2] = u_uif(meta->clear_val[0]);
2299 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2300 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2301 vertices[1][2] = u_uif(meta->clear_val[0]);
2302 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2303 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2304 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002305
Chia-I Wu29e6f502014-11-24 14:27:29 +08002306 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2307 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002308
Chia-I Wu29e6f502014-11-24 14:27:29 +08002309 vb_end = vb_start + sizeof(vertices) - 1;
2310 vb_stride = sizeof(vertices[0]);
2311 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2312 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2313 }
2314 break;
2315 default:
2316 assert(!"unknown meta mode");
2317 return;
2318 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002319 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002320
2321 /* 3DSTATE_VERTEX_BUFFERS */
2322 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002323
Chia-I Wu6032b892014-10-17 14:47:18 +08002324 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002325 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002326 if (cmd_gen(cmd) >= INTEL_GEN(7))
2327 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2328
2329 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002330 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2331 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002332
2333 dw[4] = 0;
2334
2335 /* 3DSTATE_VERTEX_ELEMENTS */
2336 cmd_batch_pointer(cmd, 5, &dw);
2337 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002338 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002339 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2340 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2341 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2342 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2343 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002344 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002345 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2346 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002347 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002348 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2349}
2350
Chia-I Wu29e6f502014-11-24 14:27:29 +08002351static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002352{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002353 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002354 /* one GPR */
2355 XGL_UINT consts[8];
2356 XGL_UINT const_count;
2357
2358 CMD_ASSERT(cmd, 6, 7.5);
2359
2360 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002361 case INTEL_DEV_META_VS_FILL_MEM:
2362 consts[0] = meta->dst.x;
2363 consts[1] = meta->clear_val[0];
2364 const_count = 2;
2365 break;
2366 case INTEL_DEV_META_VS_COPY_MEM:
2367 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2368 consts[0] = meta->dst.x;
2369 consts[1] = meta->src.x;
2370 const_count = 2;
2371 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002372 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2373 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2374 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2375 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2376 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2377 consts[0] = meta->src.x;
2378 consts[1] = meta->src.y;
2379 consts[2] = meta->width;
2380 consts[3] = meta->dst.x;
2381 const_count = 4;
2382 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002383 default:
2384 assert(!"unknown meta shader id");
2385 const_count = 0;
2386 break;
2387 }
2388
2389 /* this can be skipped but it makes state dumping prettier */
2390 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2391
2392 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2393}
2394
2395static void gen6_meta_vs(struct intel_cmd *cmd)
2396{
2397 const struct intel_cmd_meta *meta = cmd->bind.meta;
2398 const struct intel_pipeline_shader *sh =
2399 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2400 uint32_t offset, *dw;
2401
2402 CMD_ASSERT(cmd, 6, 7.5);
2403
2404 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2405 XGL_UINT cmd_len;
2406
2407 /* 3DSTATE_CONSTANT_VS */
2408 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2409 cmd_batch_pointer(cmd, cmd_len, &dw);
2410 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2411 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2412
2413 /* 3DSTATE_VS */
2414 cmd_batch_pointer(cmd, 6, &dw);
2415 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2416 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2417
2418 return;
2419 }
2420
2421 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2422
2423 /* 3DSTATE_CONSTANT_VS */
2424 offset = gen6_meta_vs_constants(cmd);
2425 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2426 cmd_batch_pointer(cmd, 7, &dw);
2427 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2428 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2429 dw[2] = 0;
2430 dw[3] = offset;
2431 dw[4] = 0;
2432 dw[5] = 0;
2433 dw[6] = 0;
2434 } else {
2435 cmd_batch_pointer(cmd, 5, &dw);
2436 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2437 GEN6_PCB_ANY_DW0_PCB0_VALID;
2438 dw[1] = offset;
2439 dw[2] = 0;
2440 dw[3] = 0;
2441 dw[4] = 0;
2442 }
2443
2444 /* 3DSTATE_VS */
2445 offset = emit_shader(cmd, sh);
2446 cmd_batch_pointer(cmd, 6, &dw);
2447 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2448 dw[1] = offset;
2449 dw[2] = GEN6_THREADDISP_SPF |
2450 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2451 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002452 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002453 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2454 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2455
2456 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2457 GEN6_VS_DW5_VS_ENABLE;
2458 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002459 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002460 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002461 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002462
2463 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002464}
2465
2466static void gen6_meta_disabled(struct intel_cmd *cmd)
2467{
Chia-I Wu6032b892014-10-17 14:47:18 +08002468 uint32_t *dw;
2469
2470 CMD_ASSERT(cmd, 6, 6);
2471
Chia-I Wu6032b892014-10-17 14:47:18 +08002472 /* 3DSTATE_CONSTANT_GS */
2473 cmd_batch_pointer(cmd, 5, &dw);
2474 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2475 dw[1] = 0;
2476 dw[2] = 0;
2477 dw[3] = 0;
2478 dw[4] = 0;
2479
2480 /* 3DSTATE_GS */
2481 cmd_batch_pointer(cmd, 7, &dw);
2482 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2483 dw[1] = 0;
2484 dw[2] = 0;
2485 dw[3] = 0;
2486 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2487 dw[5] = GEN6_GS_DW5_STATISTICS;
2488 dw[6] = 0;
2489
Chia-I Wu6032b892014-10-17 14:47:18 +08002490 /* 3DSTATE_SF */
2491 cmd_batch_pointer(cmd, 20, &dw);
2492 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2493 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2494 memset(&dw[2], 0, 18 * sizeof(*dw));
2495}
2496
2497static void gen7_meta_disabled(struct intel_cmd *cmd)
2498{
2499 uint32_t *dw;
2500
2501 CMD_ASSERT(cmd, 7, 7.5);
2502
Chia-I Wu6032b892014-10-17 14:47:18 +08002503 /* 3DSTATE_CONSTANT_HS */
2504 cmd_batch_pointer(cmd, 7, &dw);
2505 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2506 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2507
2508 /* 3DSTATE_HS */
2509 cmd_batch_pointer(cmd, 7, &dw);
2510 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2511 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2512
2513 /* 3DSTATE_TE */
2514 cmd_batch_pointer(cmd, 4, &dw);
2515 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2516 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2517
2518 /* 3DSTATE_CONSTANT_DS */
2519 cmd_batch_pointer(cmd, 7, &dw);
2520 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2521 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2522
2523 /* 3DSTATE_DS */
2524 cmd_batch_pointer(cmd, 6, &dw);
2525 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2526 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2527
2528 /* 3DSTATE_CONSTANT_GS */
2529 cmd_batch_pointer(cmd, 7, &dw);
2530 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2531 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2532
2533 /* 3DSTATE_GS */
2534 cmd_batch_pointer(cmd, 7, &dw);
2535 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2536 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2537
2538 /* 3DSTATE_STREAMOUT */
2539 cmd_batch_pointer(cmd, 3, &dw);
2540 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2541 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2542
Chia-I Wu6032b892014-10-17 14:47:18 +08002543 /* 3DSTATE_SF */
2544 cmd_batch_pointer(cmd, 7, &dw);
2545 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2546 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2547
2548 /* 3DSTATE_SBE */
2549 cmd_batch_pointer(cmd, 14, &dw);
2550 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2551 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2552 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002553}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002554
Chia-I Wu29e6f502014-11-24 14:27:29 +08002555static void gen6_meta_clip(struct intel_cmd *cmd)
2556{
2557 const struct intel_cmd_meta *meta = cmd->bind.meta;
2558 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002559
Chia-I Wu29e6f502014-11-24 14:27:29 +08002560 /* 3DSTATE_CLIP */
2561 cmd_batch_pointer(cmd, 4, &dw);
2562 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2563 dw[1] = 0;
2564 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2565 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2566 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2567 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002568 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002569 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002570 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002571}
2572
2573static void gen6_meta_wm(struct intel_cmd *cmd)
2574{
2575 const struct intel_cmd_meta *meta = cmd->bind.meta;
2576 uint32_t *dw;
2577
2578 CMD_ASSERT(cmd, 6, 7.5);
2579
2580 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2581
2582 /* 3DSTATE_MULTISAMPLE */
2583 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2584 cmd_batch_pointer(cmd, 4, &dw);
2585 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2586 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2587 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2588 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2589 dw[2] = 0;
2590 dw[3] = 0;
2591 } else {
2592 cmd_batch_pointer(cmd, 3, &dw);
2593 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2594 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2595 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2596 dw[2] = 0;
2597 }
2598
2599 /* 3DSTATE_SAMPLE_MASK */
2600 cmd_batch_pointer(cmd, 2, &dw);
2601 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2602 dw[1] = (1 << meta->samples) - 1;
2603
2604 /* 3DSTATE_DRAWING_RECTANGLE */
2605 cmd_batch_pointer(cmd, 4, &dw);
2606 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2607 dw[1] = meta->dst.y << 16 | meta->dst.x;
2608 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2609 (meta->dst.x + meta->width - 1);
2610 dw[3] = 0;
2611}
2612
2613static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2614{
2615 const struct intel_cmd_meta *meta = cmd->bind.meta;
2616 XGL_UINT offset_x, offset_y;
2617 /* one GPR */
2618 XGL_UINT consts[8];
2619 XGL_UINT const_count;
2620
2621 CMD_ASSERT(cmd, 6, 7.5);
2622
2623 /* underflow is fine here */
2624 offset_x = meta->src.x - meta->dst.x;
2625 offset_y = meta->src.y - meta->dst.y;
2626
2627 switch (meta->shader_id) {
2628 case INTEL_DEV_META_FS_COPY_MEM:
2629 case INTEL_DEV_META_FS_COPY_1D:
2630 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2631 case INTEL_DEV_META_FS_COPY_2D:
2632 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2633 case INTEL_DEV_META_FS_COPY_2D_MS:
2634 consts[0] = offset_x;
2635 consts[1] = offset_y;
2636 consts[2] = meta->src.layer;
2637 consts[3] = meta->src.lod;
2638 const_count = 4;
2639 break;
2640 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2641 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2642 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2643 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2644 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2645 consts[0] = offset_x;
2646 consts[1] = offset_y;
2647 consts[2] = meta->src.layer;
2648 consts[3] = meta->src.lod;
2649 consts[4] = meta->src.x;
2650 consts[5] = meta->width;
2651 const_count = 6;
2652 break;
2653 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2654 consts[0] = offset_x;
2655 consts[1] = offset_y;
2656 consts[2] = meta->width;
2657 const_count = 3;
2658 break;
2659 case INTEL_DEV_META_FS_CLEAR_COLOR:
2660 consts[0] = meta->clear_val[0];
2661 consts[1] = meta->clear_val[1];
2662 consts[2] = meta->clear_val[2];
2663 consts[3] = meta->clear_val[3];
2664 const_count = 4;
2665 break;
2666 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2667 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002668 consts[1] = meta->clear_val[1];
2669 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002670 break;
2671 case INTEL_DEV_META_FS_RESOLVE_2X:
2672 case INTEL_DEV_META_FS_RESOLVE_4X:
2673 case INTEL_DEV_META_FS_RESOLVE_8X:
2674 case INTEL_DEV_META_FS_RESOLVE_16X:
2675 consts[0] = offset_x;
2676 consts[1] = offset_y;
2677 const_count = 2;
2678 break;
2679 default:
2680 assert(!"unknown meta shader id");
2681 const_count = 0;
2682 break;
2683 }
2684
2685 /* this can be skipped but it makes state dumping prettier */
2686 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2687
2688 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2689}
2690
2691static void gen6_meta_ps(struct intel_cmd *cmd)
2692{
2693 const struct intel_cmd_meta *meta = cmd->bind.meta;
2694 const struct intel_pipeline_shader *sh =
2695 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2696 uint32_t offset, *dw;
2697
2698 CMD_ASSERT(cmd, 6, 6);
2699
Chia-I Wu29e6f502014-11-24 14:27:29 +08002700 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2701 /* 3DSTATE_CONSTANT_PS */
2702 cmd_batch_pointer(cmd, 5, &dw);
2703 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2704 dw[1] = 0;
2705 dw[2] = 0;
2706 dw[3] = 0;
2707 dw[4] = 0;
2708
2709 /* 3DSTATE_WM */
2710 cmd_batch_pointer(cmd, 9, &dw);
2711 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2712 dw[1] = 0;
2713 dw[2] = 0;
2714 dw[3] = 0;
2715 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002716 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002717 dw[6] = 0;
2718 dw[7] = 0;
2719 dw[8] = 0;
2720
Chia-I Wu3adf7212014-10-24 15:34:07 +08002721 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002722 }
2723
Chia-I Wu3adf7212014-10-24 15:34:07 +08002724 /* a normal color write */
2725 assert(meta->dst.valid && !sh->uses);
2726
Chia-I Wu6032b892014-10-17 14:47:18 +08002727 /* 3DSTATE_CONSTANT_PS */
2728 offset = gen6_meta_ps_constants(cmd);
2729 cmd_batch_pointer(cmd, 5, &dw);
2730 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2731 GEN6_PCB_ANY_DW0_PCB0_VALID;
2732 dw[1] = offset;
2733 dw[2] = 0;
2734 dw[3] = 0;
2735 dw[4] = 0;
2736
2737 /* 3DSTATE_WM */
2738 offset = emit_shader(cmd, sh);
2739 cmd_batch_pointer(cmd, 9, &dw);
2740 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2741 dw[1] = offset;
2742 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2743 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002744 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002745 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002746 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002747 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002748 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2749
Chia-I Wu6032b892014-10-17 14:47:18 +08002750 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2751 GEN6_WM_DW6_POSOFFSET_NONE |
2752 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2753 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2754 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2755 if (meta->samples > 1) {
2756 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2757 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2758 } else {
2759 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2760 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2761 }
2762 dw[7] = 0;
2763 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002764
2765 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002766}
2767
2768static void gen7_meta_ps(struct intel_cmd *cmd)
2769{
2770 const struct intel_cmd_meta *meta = cmd->bind.meta;
2771 const struct intel_pipeline_shader *sh =
2772 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2773 uint32_t offset, *dw;
2774
2775 CMD_ASSERT(cmd, 7, 7.5);
2776
Chia-I Wu29e6f502014-11-24 14:27:29 +08002777 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2778 /* 3DSTATE_WM */
2779 cmd_batch_pointer(cmd, 3, &dw);
2780 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2781 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2782
2783 /* 3DSTATE_CONSTANT_GS */
2784 cmd_batch_pointer(cmd, 7, &dw);
2785 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2786 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2787
2788 /* 3DSTATE_PS */
2789 cmd_batch_pointer(cmd, 8, &dw);
2790 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2791 dw[1] = 0;
2792 dw[2] = 0;
2793 dw[3] = 0;
2794 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002795 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002796 dw[5] = 0;
2797 dw[6] = 0;
2798 dw[7] = 0;
2799
Chia-I Wu3adf7212014-10-24 15:34:07 +08002800 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002801 }
2802
Chia-I Wu3adf7212014-10-24 15:34:07 +08002803 /* a normal color write */
2804 assert(meta->dst.valid && !sh->uses);
2805
Chia-I Wu6032b892014-10-17 14:47:18 +08002806 /* 3DSTATE_WM */
2807 cmd_batch_pointer(cmd, 3, &dw);
2808 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2809 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2810 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2811 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2812 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2813 dw[2] = 0;
2814
2815 /* 3DSTATE_CONSTANT_PS */
2816 offset = gen6_meta_ps_constants(cmd);
2817 cmd_batch_pointer(cmd, 7, &dw);
2818 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2819 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2820 dw[2] = 0;
2821 dw[3] = offset;
2822 dw[4] = 0;
2823 dw[5] = 0;
2824 dw[6] = 0;
2825
2826 /* 3DSTATE_PS */
2827 offset = emit_shader(cmd, sh);
2828 cmd_batch_pointer(cmd, 8, &dw);
2829 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2830 dw[1] = offset;
2831 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2832 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002833 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002834
2835 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2836 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002837 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2838
2839 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002840 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002841 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002842 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002843 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002844 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002845
2846 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2847 dw[6] = 0;
2848 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002849
2850 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002851}
2852
2853static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2854{
2855 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002856 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002857
2858 CMD_ASSERT(cmd, 6, 7.5);
2859
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002860 if (!ds) {
2861 /* all zeros */
2862 static const struct intel_ds_view null_ds;
2863 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002864 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002865
2866 cmd_wa_gen6_pre_ds_flush(cmd);
2867 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2868 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2869 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2870
2871 if (cmd_gen(cmd) >= INTEL_GEN(7))
2872 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2873 else
2874 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002875}
2876
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002877static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2878 const struct intel_pipeline *pipeline)
2879{
2880 cmd->bind.pipeline.graphics = pipeline;
2881}
2882
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002883static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2884 const struct intel_pipeline *pipeline)
2885{
2886 cmd->bind.pipeline.compute = pipeline;
2887}
2888
2889static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2890 const struct intel_pipeline_delta *delta)
2891{
2892 cmd->bind.pipeline.graphics_delta = delta;
2893}
2894
2895static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2896 const struct intel_pipeline_delta *delta)
2897{
2898 cmd->bind.pipeline.compute_delta = delta;
2899}
2900
2901static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2902 const struct intel_dset *dset,
2903 XGL_UINT slot_offset)
2904{
2905 cmd->bind.dset.graphics = dset;
2906 cmd->bind.dset.graphics_offset = slot_offset;
2907}
2908
2909static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2910 const struct intel_dset *dset,
2911 XGL_UINT slot_offset)
2912{
2913 cmd->bind.dset.compute = dset;
2914 cmd->bind.dset.compute_offset = slot_offset;
2915}
2916
2917static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002918 const XGL_BUFFER_VIEW_ATTACH_INFO *info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002919{
Chia-I Wu714df452015-01-01 07:55:04 +08002920 cmd->bind.dyn_view.graphics = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002921}
2922
2923static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002924 const XGL_BUFFER_VIEW_ATTACH_INFO *info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002925{
Chia-I Wu714df452015-01-01 07:55:04 +08002926 cmd->bind.dyn_view.compute = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002927}
2928
Chia-I Wu3b04af52014-11-08 10:48:20 +08002929static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002930 const struct intel_buf *buf,
Chia-I Wu3b04af52014-11-08 10:48:20 +08002931 XGL_GPU_SIZE offset, XGL_UINT binding)
2932{
Chia-I Wu714df452015-01-01 07:55:04 +08002933 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002934 cmd->result = XGL_ERROR_UNKNOWN;
2935 return;
2936 }
2937
Chia-I Wu714df452015-01-01 07:55:04 +08002938 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002939 cmd->bind.vertex.offset[binding] = offset;
2940}
2941
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002942static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002943 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002944 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2945{
Chia-I Wu714df452015-01-01 07:55:04 +08002946 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002947 cmd->bind.index.offset = offset;
2948 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002949}
2950
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002951static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002952 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002953{
2954 cmd->bind.state.viewport = state;
2955}
2956
2957static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002958 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002959{
2960 cmd->bind.state.raster = state;
2961}
2962
2963static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002964 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002965{
2966 cmd->bind.state.ds = state;
2967}
2968
2969static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002970 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002971{
2972 cmd->bind.state.blend = state;
2973}
2974
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002975static void cmd_draw(struct intel_cmd *cmd,
2976 XGL_UINT vertex_start,
2977 XGL_UINT vertex_count,
2978 XGL_UINT instance_start,
2979 XGL_UINT instance_count,
2980 bool indexed,
2981 XGL_UINT vertex_base)
2982{
2983 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2984
2985 emit_bounded_states(cmd);
2986
2987 if (indexed) {
2988 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2989 cmd->result = XGL_ERROR_UNKNOWN;
2990
2991 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2992 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2993 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08002994 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002995 cmd->bind.index.offset, cmd->bind.index.type,
2996 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002997 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08002998 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002999 cmd->bind.index.offset, cmd->bind.index.type,
3000 p->primitive_restart);
3001 }
3002 } else {
3003 assert(!vertex_base);
3004 }
3005
3006 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3007 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3008 vertex_start, instance_count, instance_start, vertex_base);
3009 } else {
3010 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3011 vertex_start, instance_count, instance_start, vertex_base);
3012 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003013
Chia-I Wu707a29e2014-08-27 12:51:47 +08003014 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003015 /* need to re-emit all workarounds */
3016 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003017
3018 if (intel_debug & INTEL_DEBUG_NOCACHE)
3019 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003020}
3021
Chia-I Wuc14d1562014-10-17 09:49:22 +08003022void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3023{
Chia-I Wu6032b892014-10-17 14:47:18 +08003024 cmd->bind.meta = meta;
3025
3026 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003027 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003028
3029 gen6_meta_dynamic_states(cmd);
3030 gen6_meta_surface_states(cmd);
3031
3032 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3033 gen7_meta_urb(cmd);
3034 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003035 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003036 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003037 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003038 gen6_meta_wm(cmd);
3039 gen7_meta_ps(cmd);
3040 gen6_meta_depth_buffer(cmd);
3041
3042 cmd_wa_gen7_post_command_cs_stall(cmd);
3043 cmd_wa_gen7_post_command_depth_stall(cmd);
3044
Chia-I Wu29e6f502014-11-24 14:27:29 +08003045 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3046 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003047 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003048 } else {
3049 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3050 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003051 } else {
3052 gen6_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 gen6_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 gen6_meta_ps(cmd);
3059 gen6_meta_depth_buffer(cmd);
3060
Chia-I Wu29e6f502014-11-24 14:27:29 +08003061 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3062 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003063 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003064 } else {
3065 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3066 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003067 }
3068
3069 cmd->bind.draw_count++;
3070 /* need to re-emit all workarounds */
3071 cmd->bind.wa_flags = 0;
3072
3073 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003074
3075 if (intel_debug & INTEL_DEBUG_NOCACHE)
3076 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003077}
3078
Chia-I Wu96177272015-01-03 15:27:41 +08003079ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003080 XGL_CMD_BUFFER cmdBuffer,
3081 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3082 XGL_PIPELINE pipeline)
3083{
3084 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3085
3086 switch (pipelineBindPoint) {
3087 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003088 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003089 break;
3090 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003091 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003092 break;
3093 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003094 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003095 break;
3096 }
3097}
3098
Chia-I Wu96177272015-01-03 15:27:41 +08003099ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003100 XGL_CMD_BUFFER cmdBuffer,
3101 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3102 XGL_PIPELINE_DELTA delta)
3103{
3104 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3105
3106 switch (pipelineBindPoint) {
3107 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003108 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003109 break;
3110 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003111 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003112 break;
3113 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003114 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003115 break;
3116 }
3117}
3118
Tony Barbourfa6cac72015-01-16 14:27:35 -07003119ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003120 XGL_CMD_BUFFER cmdBuffer,
3121 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003122 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003123{
3124 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3125
3126 switch (stateBindPoint) {
3127 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003128 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003129 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003130 break;
3131 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003132 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003133 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003134 break;
3135 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003136 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003137 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003138 break;
3139 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003140 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003141 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003142 break;
3143 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003144 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003145 break;
3146 }
3147}
3148
Chia-I Wu96177272015-01-03 15:27:41 +08003149ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003150 XGL_CMD_BUFFER cmdBuffer,
3151 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3152 XGL_UINT index,
3153 XGL_DESCRIPTOR_SET descriptorSet,
3154 XGL_UINT slotOffset)
3155{
3156 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3157 struct intel_dset *dset = intel_dset(descriptorSet);
3158
3159 assert(!index);
3160
3161 switch (pipelineBindPoint) {
3162 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003163 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003164 break;
3165 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003166 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003167 break;
3168 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003169 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003170 break;
3171 }
3172}
3173
Chia-I Wu714df452015-01-01 07:55:04 +08003174ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicBufferView(
Chia-I Wub2755562014-08-20 13:38:52 +08003175 XGL_CMD_BUFFER cmdBuffer,
3176 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wu714df452015-01-01 07:55:04 +08003177 const XGL_BUFFER_VIEW_ATTACH_INFO* pBufferView)
Chia-I Wub2755562014-08-20 13:38:52 +08003178{
3179 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3180
3181 switch (pipelineBindPoint) {
3182 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu714df452015-01-01 07:55:04 +08003183 cmd_bind_compute_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003184 break;
3185 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu714df452015-01-01 07:55:04 +08003186 cmd_bind_graphics_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003187 break;
3188 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003189 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003190 break;
3191 }
3192}
3193
Chia-I Wu714df452015-01-01 07:55:04 +08003194ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003195 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003196 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003197 XGL_GPU_SIZE offset,
3198 XGL_UINT binding)
3199{
3200 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003201 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003202
Chia-I Wu714df452015-01-01 07:55:04 +08003203 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003204}
3205
Chia-I Wu714df452015-01-01 07:55:04 +08003206ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003207 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003208 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003209 XGL_GPU_SIZE offset,
3210 XGL_INDEX_TYPE indexType)
3211{
3212 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003213 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003214
Chia-I Wu714df452015-01-01 07:55:04 +08003215 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003216}
3217
Chia-I Wu96177272015-01-03 15:27:41 +08003218ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003219 XGL_CMD_BUFFER cmdBuffer,
3220 XGL_UINT firstVertex,
3221 XGL_UINT vertexCount,
3222 XGL_UINT firstInstance,
3223 XGL_UINT instanceCount)
3224{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003225 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003226
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003227 cmd_draw(cmd, firstVertex, vertexCount,
3228 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003229}
3230
Chia-I Wu96177272015-01-03 15:27:41 +08003231ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003232 XGL_CMD_BUFFER cmdBuffer,
3233 XGL_UINT firstIndex,
3234 XGL_UINT indexCount,
3235 XGL_INT vertexOffset,
3236 XGL_UINT firstInstance,
3237 XGL_UINT instanceCount)
3238{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003239 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003240
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003241 cmd_draw(cmd, firstIndex, indexCount,
3242 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003243}
3244
Chia-I Wu96177272015-01-03 15:27:41 +08003245ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003246 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003247 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003248 XGL_GPU_SIZE offset,
3249 XGL_UINT32 count,
3250 XGL_UINT32 stride)
3251{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003252 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3253
3254 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003255}
3256
Chia-I Wu96177272015-01-03 15:27:41 +08003257ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003258 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003259 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003260 XGL_GPU_SIZE offset,
3261 XGL_UINT32 count,
3262 XGL_UINT32 stride)
3263{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003264 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3265
3266 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003267}
3268
Chia-I Wu96177272015-01-03 15:27:41 +08003269ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003270 XGL_CMD_BUFFER cmdBuffer,
3271 XGL_UINT x,
3272 XGL_UINT y,
3273 XGL_UINT z)
3274{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003275 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3276
3277 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003278}
3279
Chia-I Wu96177272015-01-03 15:27:41 +08003280ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003281 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003282 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003283 XGL_GPU_SIZE offset)
3284{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003285 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3286
3287 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003288}