blob: 96645887b265bff9a9d73add5f1286fcb5fa0218 [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 Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.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;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t 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;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 uint32_t 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:
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700273 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700279 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280 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,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600350 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800351{
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
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700394 switch (pipeline->db_format) {
395 case XGL_FMT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700398 case XGL_FMT_D32_SFLOAT:
399 case XGL_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800400 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
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700413 /* Scissor is always enabled */
414 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
415
Tony Barbourfa6cac72015-01-16 14:27:35 -0700416 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800417 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
419 } else {
420 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
421 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
422 }
423
Chia-I Wu8016a172014-08-29 18:31:32 +0800424 /* 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
Chia-I Wu8016a172014-08-29 18:31:32 +0800443static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
444{
445 const uint8_t cmd_len = 20;
446 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
447 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800448 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800450 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800451
452 CMD_ASSERT(cmd, 6, 6);
453
454 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800455
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 cmd_batch_pointer(cmd, cmd_len, &dw);
457 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800458 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800459 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800460 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800461}
462
463static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
464{
465 const uint8_t cmd_len = 7;
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, 7, 7.5);
469
Chia-I Wu72292b72014-09-09 10:48:33 +0800470 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800471 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
472 (cmd_len - 2);
473 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800474}
475
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800476static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
477{
478 const uint8_t cmd_len = 4;
479 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
480 (cmd_len - 2);
481 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700482 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800483 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700484 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800485 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800486
487 CMD_ASSERT(cmd, 6, 7.5);
488
489 dw1 = GEN6_CLIP_DW1_STATISTICS;
490 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
491 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
492 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700493 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800494 }
495
496 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
497 GEN6_CLIP_DW2_XY_TEST_ENABLE |
498 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700499 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800500 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
501 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
502 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
503
504 if (pipeline->rasterizerDiscardEnable)
505 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
506 else
507 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
508
509 if (pipeline->depthClipEnable)
510 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
511
512 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
513 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
514 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
515 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
516
517 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
518 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
519 (viewport->viewport_count - 1);
520
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600521 /* TODO: framebuffer requests layer_count > 1 */
522 if (cmd->bind.render_pass->fb->layer_count == 1) {
523 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
524 }
525
Chia-I Wu72292b72014-09-09 10:48:33 +0800526 cmd_batch_pointer(cmd, cmd_len, &dw);
527 dw[0] = dw0;
528 dw[1] = dw1;
529 dw[2] = dw2;
530 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800531}
532
Chia-I Wu784d3042014-12-19 14:30:04 +0800533static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600534 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800535 const struct intel_pipeline *pipeline,
536 const struct intel_pipeline_shader *sh)
537{
538 int scratch_space;
539
540 CMD_ASSERT(cmd, 6, 7.5);
541
542 assert(sh->per_thread_scratch_size &&
543 sh->per_thread_scratch_size % 1024 == 0 &&
544 u_is_pow2(sh->per_thread_scratch_size) &&
545 sh->scratch_offset % 1024 == 0);
546 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
547
548 cmd_reserve_reloc(cmd, 1);
549 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
550 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
551}
552
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800553static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
554{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800555 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800556 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800557 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600558 uint32_t pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800559 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800560
561 CMD_ASSERT(cmd, 6, 6);
562
563 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
564
565 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
566 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
567
568 dw4 = GEN6_WM_DW4_STATISTICS |
569 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
570 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
571 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
572
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800573 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800574 GEN6_WM_DW5_PS_ENABLE |
575 GEN6_WM_DW5_8_PIXEL_DISPATCH;
576
577 if (fs->uses & INTEL_SHADER_USE_KILL ||
578 pipeline->cb_state.alphaToCoverageEnable)
579 dw5 |= GEN6_WM_DW5_PS_KILL;
580
Cody Northrope238deb2015-01-26 14:41:36 -0700581 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800582 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
583 if (fs->uses & INTEL_SHADER_USE_DEPTH)
584 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
585 if (fs->uses & INTEL_SHADER_USE_W)
586 dw5 |= GEN6_WM_DW5_PS_USE_W;
587
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700588 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800589 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
590
591 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
592 GEN6_WM_DW6_POSOFFSET_NONE |
593 GEN6_WM_DW6_ZW_INTERP_PIXEL |
594 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
595 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
596
Tony Barbourfa6cac72015-01-16 14:27:35 -0700597 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800598 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
599 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
600 } else {
601 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
602 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
603 }
604
Chia-I Wu784d3042014-12-19 14:30:04 +0800605 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800606 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800607 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800608 dw[2] = dw2;
609 dw[3] = 0; /* scratch */
610 dw[4] = dw4;
611 dw[5] = dw5;
612 dw[6] = dw6;
613 dw[7] = 0; /* kernel 1 */
614 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800615
616 if (fs->per_thread_scratch_size)
617 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800618}
619
620static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
621{
622 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800623 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800624 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800625 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800626
627 CMD_ASSERT(cmd, 7, 7.5);
628
629 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
630
631 dw1 = GEN7_WM_DW1_STATISTICS |
632 GEN7_WM_DW1_PS_ENABLE |
633 GEN7_WM_DW1_ZW_INTERP_PIXEL |
634 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
635 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
636
637 if (fs->uses & INTEL_SHADER_USE_KILL ||
638 pipeline->cb_state.alphaToCoverageEnable)
639 dw1 |= GEN7_WM_DW1_PS_KILL;
640
Cody Northrope238deb2015-01-26 14:41:36 -0700641 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
642
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800643 if (fs->uses & INTEL_SHADER_USE_DEPTH)
644 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
645 if (fs->uses & INTEL_SHADER_USE_W)
646 dw1 |= GEN7_WM_DW1_PS_USE_W;
647
648 dw2 = 0;
649
Tony Barbourfa6cac72015-01-16 14:27:35 -0700650 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800651 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
652 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
653 } else {
654 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
655 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
656 }
657
Chia-I Wu72292b72014-09-09 10:48:33 +0800658 cmd_batch_pointer(cmd, cmd_len, &dw);
659 dw[0] = dw0;
660 dw[1] = dw1;
661 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800662}
663
664static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
665{
666 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800667 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800669 uint32_t dw0, dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600670 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800671
672 CMD_ASSERT(cmd, 7, 7.5);
673
674 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
675
676 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
677 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
678
679 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
680 GEN7_PS_DW4_8_PIXEL_DISPATCH;
681
682 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800683 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700684 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800685 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800686 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800687 }
688
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800689 if (fs->in_count)
690 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
691
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700692 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
694
695 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
696 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
697 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
698
Chia-I Wu784d3042014-12-19 14:30:04 +0800699 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800700 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800701 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800702 dw[2] = dw2;
703 dw[3] = 0; /* scratch */
704 dw[4] = dw4;
705 dw[5] = dw5;
706 dw[6] = 0; /* kernel 1 */
707 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800708
709 if (fs->per_thread_scratch_size)
710 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800711}
712
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800713static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
714 const struct intel_ds_view *view)
715{
716 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600718 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800719
720 CMD_ASSERT(cmd, 6, 7.5);
721
722 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800723 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
724 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800725 dw0 |= (cmd_len - 2);
726
Chia-I Wu72292b72014-09-09 10:48:33 +0800727 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
728 dw[0] = dw0;
729 dw[1] = view->cmd[0];
730 dw[2] = 0;
731 dw[3] = view->cmd[2];
732 dw[4] = view->cmd[3];
733 dw[5] = view->cmd[4];
734 dw[6] = view->cmd[5];
735
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600736 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800737 cmd_reserve_reloc(cmd, 1);
738 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
739 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600740 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800741}
742
743static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
744 const struct intel_ds_view *view)
745{
746 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800747 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600748 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800749
750 CMD_ASSERT(cmd, 6, 7.5);
751
752 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800753 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
754 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800755 dw0 |= (cmd_len - 2);
756
Chia-I Wu72292b72014-09-09 10:48:33 +0800757 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
758 dw[0] = dw0;
759 dw[1] = view->cmd[6];
760 dw[2] = 0;
761
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600762 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800763 cmd_reserve_reloc(cmd, 1);
764 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
765 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600766 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767}
768
769static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
770 const struct intel_ds_view *view)
771{
772 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800773 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600774 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800775
776 CMD_ASSERT(cmd, 6, 7.5);
777
778 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800779 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
780 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800781 dw0 |= (cmd_len - 2);
782
Chia-I Wu72292b72014-09-09 10:48:33 +0800783 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
784 dw[0] = dw0;
785 dw[1] = view->cmd[8];
786 dw[2] = 0;
787
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600788 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800789 cmd_reserve_reloc(cmd, 1);
790 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
791 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600792 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793}
794
Chia-I Wuf8231032014-08-25 10:44:45 +0800795static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
796 uint32_t clear_val)
797{
798 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800799 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800800 GEN6_CLEAR_PARAMS_DW0_VALID |
801 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800802 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800803
804 CMD_ASSERT(cmd, 6, 6);
805
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 cmd_batch_pointer(cmd, cmd_len, &dw);
807 dw[0] = dw0;
808 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800809}
810
811static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
812 uint32_t clear_val)
813{
814 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800815 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800816 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800817 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800818
819 CMD_ASSERT(cmd, 7, 7.5);
820
Chia-I Wu72292b72014-09-09 10:48:33 +0800821 cmd_batch_pointer(cmd, cmd_len, &dw);
822 dw[0] = dw0;
823 dw[1] = clear_val;
824 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800825}
826
Chia-I Wu302742d2014-08-22 10:28:29 +0800827static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800828 uint32_t blend_offset,
829 uint32_t ds_offset,
830 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800831{
832 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800833 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800834
835 CMD_ASSERT(cmd, 6, 6);
836
Chia-I Wu426072d2014-08-26 14:31:55 +0800837 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800838 (cmd_len - 2);
839
Chia-I Wu72292b72014-09-09 10:48:33 +0800840 cmd_batch_pointer(cmd, cmd_len, &dw);
841 dw[0] = dw0;
842 dw[1] = blend_offset | 1;
843 dw[2] = ds_offset | 1;
844 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800845}
846
Chia-I Wu1744cca2014-08-22 11:10:17 +0800847static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800848 uint32_t clip_offset,
849 uint32_t sf_offset,
850 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800851{
852 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800853 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800854
855 CMD_ASSERT(cmd, 6, 6);
856
Chia-I Wu426072d2014-08-26 14:31:55 +0800857 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800858 GEN6_PTR_VP_DW0_CLIP_CHANGED |
859 GEN6_PTR_VP_DW0_SF_CHANGED |
860 GEN6_PTR_VP_DW0_CC_CHANGED |
861 (cmd_len - 2);
862
Chia-I Wu72292b72014-09-09 10:48:33 +0800863 cmd_batch_pointer(cmd, cmd_len, &dw);
864 dw[0] = dw0;
865 dw[1] = clip_offset;
866 dw[2] = sf_offset;
867 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800868}
869
870static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800871 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800872{
873 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800874 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800875
876 CMD_ASSERT(cmd, 6, 6);
877
Chia-I Wu426072d2014-08-26 14:31:55 +0800878 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800879 (cmd_len - 2);
880
Chia-I Wu72292b72014-09-09 10:48:33 +0800881 cmd_batch_pointer(cmd, cmd_len, &dw);
882 dw[0] = dw0;
883 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800884}
885
Chia-I Wu42a56202014-08-23 16:47:48 +0800886static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800887 uint32_t vs_offset,
888 uint32_t gs_offset,
889 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800890{
891 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800893
894 CMD_ASSERT(cmd, 6, 6);
895
Chia-I Wu426072d2014-08-26 14:31:55 +0800896 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800897 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
898 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
899 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
900 (cmd_len - 2);
901
Chia-I Wu72292b72014-09-09 10:48:33 +0800902 cmd_batch_pointer(cmd, cmd_len, &dw);
903 dw[0] = dw0;
904 dw[1] = vs_offset;
905 dw[2] = gs_offset;
906 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800907}
908
Chia-I Wu257e75e2014-08-29 14:06:35 +0800909static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800910 uint32_t vs_offset,
911 uint32_t gs_offset,
912 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800913{
914 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800915 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800916
917 CMD_ASSERT(cmd, 6, 6);
918
919 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
920 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
921 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
922 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
923 (cmd_len - 2);
924
Chia-I Wu72292b72014-09-09 10:48:33 +0800925 cmd_batch_pointer(cmd, cmd_len, &dw);
926 dw[0] = dw0;
927 dw[1] = vs_offset;
928 dw[2] = gs_offset;
929 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800930}
931
Chia-I Wu302742d2014-08-22 10:28:29 +0800932static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800933 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800934{
935 const uint8_t cmd_len = 2;
936 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
937 GEN6_RENDER_SUBTYPE_3D |
938 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800940
Chia-I Wu72292b72014-09-09 10:48:33 +0800941 cmd_batch_pointer(cmd, cmd_len, &dw);
942 dw[0] = dw0;
943 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800944}
945
Chia-I Wua6c4f152014-12-02 04:19:58 +0800946static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800947{
Chia-I Wue6073342014-11-30 09:43:42 +0800948 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700949 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
950 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800951
952 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700953 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800954
Tony Barbourfa6cac72015-01-16 14:27:35 -0700955 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800956}
957
Chia-I Wu72292b72014-09-09 10:48:33 +0800958static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700959 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800960{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700961 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800962 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800963 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700964 uint32_t dw[3];
965
966 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700967 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700968 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700969 (state->ds_info.stencilWriteMask & 0xff) << 16 |
970 (state->ds_info.stencilReadMask & 0xff) << 8 |
971 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700972 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800973
974 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700975
976 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
977 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800978
Chia-I Wu00b51a82014-09-09 12:07:37 +0800979 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700980 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800981}
982
Chia-I Wu72292b72014-09-09 10:48:33 +0800983static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800984 uint32_t stencil_ref,
985 const uint32_t blend_color[4])
986{
Chia-I Wue6073342014-11-30 09:43:42 +0800987 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800988 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +0800989 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800990
991 CMD_ASSERT(cmd, 6, 7.5);
992
Chia-I Wu00b51a82014-09-09 12:07:37 +0800993 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
994 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800995 dw[0] = stencil_ref;
996 dw[1] = 0;
997 dw[2] = blend_color[0];
998 dw[3] = blend_color[1];
999 dw[4] = blend_color[2];
1000 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001001
Chia-I Wu72292b72014-09-09 10:48:33 +08001002 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001003}
1004
Chia-I Wu8370b402014-08-29 12:28:37 +08001005static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001006{
Chia-I Wu8370b402014-08-29 12:28:37 +08001007 CMD_ASSERT(cmd, 6, 7.5);
1008
Chia-I Wu707a29e2014-08-27 12:51:47 +08001009 if (!cmd->bind.draw_count)
1010 return;
1011
Chia-I Wu8370b402014-08-29 12:28:37 +08001012 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001013 return;
1014
Chia-I Wu8370b402014-08-29 12:28:37 +08001015 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001016
1017 /*
1018 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1019 *
1020 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1021 * pipe-control with a post-sync op and no write-cache flushes."
1022 *
1023 * The workaround below necessitates this workaround.
1024 */
1025 gen6_PIPE_CONTROL(cmd,
1026 GEN6_PIPE_CONTROL_CS_STALL |
1027 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001028 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001029
Chia-I Wud6d079d2014-08-31 13:14:21 +08001030 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1031 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001032}
1033
Chia-I Wu8370b402014-08-29 12:28:37 +08001034static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001035{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001036 CMD_ASSERT(cmd, 6, 7.5);
1037
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001038 if (!cmd->bind.draw_count)
1039 return;
1040
Chia-I Wud6d079d2014-08-31 13:14:21 +08001041 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1042 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001043}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001044
Chia-I Wu8370b402014-08-29 12:28:37 +08001045static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1046{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001047 CMD_ASSERT(cmd, 7, 7.5);
1048
Chia-I Wu8370b402014-08-29 12:28:37 +08001049 if (!cmd->bind.draw_count)
1050 return;
1051
1052 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001053
1054 gen6_PIPE_CONTROL(cmd,
1055 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001056 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001057}
1058
Chia-I Wu8370b402014-08-29 12:28:37 +08001059static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1060{
1061 CMD_ASSERT(cmd, 7, 7.5);
1062
Chia-I Wu8370b402014-08-29 12:28:37 +08001063 /*
1064 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1065 *
1066 * "One of the following must also be set (when CS stall is set):
1067 *
1068 * * Render Target Cache Flush Enable ([12] of DW1)
1069 * * Depth Cache Flush Enable ([0] of DW1)
1070 * * Stall at Pixel Scoreboard ([1] of DW1)
1071 * * Depth Stall ([13] of DW1)
1072 * * Post-Sync Operation ([13] of DW1)"
1073 */
1074 gen6_PIPE_CONTROL(cmd,
1075 GEN6_PIPE_CONTROL_CS_STALL |
1076 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001077 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001078}
1079
1080static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1081{
1082 CMD_ASSERT(cmd, 7, 7.5);
1083
Chia-I Wu8370b402014-08-29 12:28:37 +08001084 cmd_wa_gen6_pre_depth_stall_write(cmd);
1085
Chia-I Wud6d079d2014-08-31 13:14:21 +08001086 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001087}
1088
1089static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1090{
1091 CMD_ASSERT(cmd, 6, 7.5);
1092
1093 if (!cmd->bind.draw_count)
1094 return;
1095
1096 /*
1097 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1098 *
1099 * "Driver must guarentee that all the caches in the depth pipe are
1100 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1101 * requires driver to send a PIPE_CONTROL with a CS stall along with
1102 * a Depth Flush prior to this command."
1103 *
1104 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1105 *
1106 * "Driver must ierarchi that all the caches in the depth pipe are
1107 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1108 * requires driver to send a PIPE_CONTROL with a CS stall along with
1109 * a Depth Flush prior to this command.
1110 */
1111 gen6_PIPE_CONTROL(cmd,
1112 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1113 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001114 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001115}
1116
1117static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1118{
1119 CMD_ASSERT(cmd, 6, 7.5);
1120
1121 if (!cmd->bind.draw_count)
1122 return;
1123
1124 /*
1125 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1126 *
1127 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1128 * and a post sync operation prior to the group of depth
1129 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1130 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1131 *
1132 * This workaround satifies all the conditions.
1133 */
1134 cmd_wa_gen6_pre_depth_stall_write(cmd);
1135
1136 /*
1137 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1138 *
1139 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1140 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1141 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1142 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1143 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1144 * Depth Flush Bit set, followed by another pipelined depth stall
1145 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1146 * guarantee that the pipeline from WM onwards is already flushed
1147 * (e.g., via a preceding MI_FLUSH)."
1148 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001149 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1150 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1151 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001152}
1153
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001154void cmd_batch_state_base_address(struct intel_cmd *cmd)
1155{
1156 const uint8_t cmd_len = 10;
1157 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1158 (cmd_len - 2);
1159 uint32_t pos;
1160 uint32_t *dw;
1161
1162 CMD_ASSERT(cmd, 6, 7.5);
1163
1164 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1165
1166 dw[0] = dw0;
1167 /* start offsets */
1168 dw[1] = 1;
1169 dw[2] = 1;
1170 dw[3] = 1;
1171 dw[4] = 1;
1172 dw[5] = 1;
1173 /* end offsets */
1174 dw[6] = 1;
1175 dw[7] = 1 + 0xfffff000;
1176 dw[8] = 1 + 0xfffff000;
1177 dw[9] = 1;
1178
1179 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001180 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1181 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1182 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1183 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1184 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1185 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001186}
1187
Chia-I Wu525c6602014-08-27 10:22:34 +08001188void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1189{
Mike Stroyan552fda42015-01-30 17:21:08 -07001190 if (pipe_control_dw0 == 0)
1191 return;
1192
Chia-I Wu525c6602014-08-27 10:22:34 +08001193 if (!cmd->bind.draw_count)
1194 return;
1195
1196 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1197
Chia-I Wu8370b402014-08-29 12:28:37 +08001198 /*
1199 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1200 *
1201 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1202 * PIPE_CONTROL with any non-zero post-sync-op is required."
1203 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001204 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001205 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001206
Chia-I Wu092279a2014-08-30 19:05:30 +08001207 /*
1208 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1209 *
1210 * "One of the following must also be set (when CS stall is set):
1211 *
1212 * * Render Target Cache Flush Enable ([12] of DW1)
1213 * * Depth Cache Flush Enable ([0] of DW1)
1214 * * Stall at Pixel Scoreboard ([1] of DW1)
1215 * * Depth Stall ([13] of DW1)
1216 * * Post-Sync Operation ([13] of DW1)"
1217 */
1218 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1219 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1220 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1221 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1222 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1223 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1224
Chia-I Wud6d079d2014-08-31 13:14:21 +08001225 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001226}
1227
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001228void cmd_batch_flush_all(struct intel_cmd *cmd)
1229{
1230 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1231 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1232 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1233 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1234 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1235 GEN6_PIPE_CONTROL_CS_STALL);
1236}
1237
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001238void cmd_batch_depth_count(struct intel_cmd *cmd,
1239 struct intel_bo *bo,
1240 XGL_GPU_SIZE offset)
1241{
1242 cmd_wa_gen6_pre_depth_stall_write(cmd);
1243
1244 gen6_PIPE_CONTROL(cmd,
1245 GEN6_PIPE_CONTROL_DEPTH_STALL |
1246 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001247 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001248}
1249
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001250void cmd_batch_timestamp(struct intel_cmd *cmd,
1251 struct intel_bo *bo,
1252 XGL_GPU_SIZE offset)
1253{
1254 /* need any WA or stall? */
1255 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1256}
1257
1258void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001259 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001260 struct intel_bo *bo,
1261 XGL_GPU_SIZE offset,
1262 uint64_t val)
1263{
1264 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001265 gen6_PIPE_CONTROL(cmd,
1266 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1267 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001268}
1269
Chia-I Wu302742d2014-08-22 10:28:29 +08001270static void gen6_cc_states(struct intel_cmd *cmd)
1271{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001272 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1273 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001274 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001275 uint32_t stencil_ref;
1276 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001277
1278 CMD_ASSERT(cmd, 6, 6);
1279
Chia-I Wua6c4f152014-12-02 04:19:58 +08001280 blend_offset = gen6_BLEND_STATE(cmd);
1281
1282 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001283 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001284 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001285 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001286
1287 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001288 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001289 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1290 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001291 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001292 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001293 stencil_ref = 0;
1294 }
1295
Chia-I Wu72292b72014-09-09 10:48:33 +08001296 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001297
Chia-I Wu72292b72014-09-09 10:48:33 +08001298 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001299}
1300
Chia-I Wu1744cca2014-08-22 11:10:17 +08001301static void gen6_viewport_states(struct intel_cmd *cmd)
1302{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001303 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001304 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001305
1306 if (!viewport)
1307 return;
1308
Tony Barbourfa6cac72015-01-16 14:27:35 -07001309 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001310 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001311
1312 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001313 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001314 viewport->cmd);
1315
1316 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001317 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001318 &viewport->cmd[viewport->cmd_clip_pos]);
1319
1320 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001321 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001322 &viewport->cmd[viewport->cmd_cc_pos]);
1323
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001324 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1325 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1326 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001327
1328 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001329 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001330
Chia-I Wub1d450a2014-09-09 13:48:03 +08001331 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001332}
1333
Chia-I Wu302742d2014-08-22 10:28:29 +08001334static void gen7_cc_states(struct intel_cmd *cmd)
1335{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001336 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1337 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001338 uint32_t stencil_ref;
1339 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001340 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001341
1342 CMD_ASSERT(cmd, 7, 7.5);
1343
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001344 if (!blend && !ds)
1345 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001346
Chia-I Wua6c4f152014-12-02 04:19:58 +08001347 offset = gen6_BLEND_STATE(cmd);
1348 gen7_3dstate_pointer(cmd,
1349 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001350
Chia-I Wua6c4f152014-12-02 04:19:58 +08001351 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001352 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001353 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001354 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001355
1356 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001357 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001358 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1359 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001360 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001361 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1362 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001363 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1364 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001365 } else {
1366 stencil_ref = 0;
1367 }
1368
Chia-I Wu72292b72014-09-09 10:48:33 +08001369 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001370 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001371 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001372}
1373
Chia-I Wu1744cca2014-08-22 11:10:17 +08001374static void gen7_viewport_states(struct intel_cmd *cmd)
1375{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001376 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001377 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001378
1379 if (!viewport)
1380 return;
1381
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001382 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001383
Chia-I Wub1d450a2014-09-09 13:48:03 +08001384 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001385 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001386 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001387 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001388 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1389 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001390
1391 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001392 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001393 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001394 gen7_3dstate_pointer(cmd,
1395 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001396 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001397
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001398 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1399 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1400 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1401 gen7_3dstate_pointer(cmd,
1402 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1403 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001404}
1405
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001406static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001407 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001408{
1409 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001410 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001411
Chia-I Wu72292b72014-09-09 10:48:33 +08001412 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001413
1414 dw[0] = GEN6_RENDER_TYPE_RENDER |
1415 GEN6_RENDER_SUBTYPE_3D |
1416 subop | (cmd_len - 2);
1417 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001418 dw[2] = 0;
1419 dw[3] = 0;
1420 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001421}
1422
1423static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001424 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001425{
1426 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001427 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001428
Chia-I Wu72292b72014-09-09 10:48:33 +08001429 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001430
1431 dw[0] = GEN6_RENDER_TYPE_RENDER |
1432 GEN6_RENDER_SUBTYPE_3D |
1433 subop | (cmd_len - 2);
1434 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001435 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001436 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001437 dw[4] = 0;
1438 dw[5] = 0;
1439 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001440}
1441
Chia-I Wu625105f2014-10-13 15:35:29 +08001442static uint32_t emit_samplers(struct intel_cmd *cmd,
1443 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001444{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001445 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1446 const uint32_t border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001447 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001448 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001449 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001450 uint32_t surface_count;
1451 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001452
1453 CMD_ASSERT(cmd, 6, 7.5);
1454
Chia-I Wu625105f2014-10-13 15:35:29 +08001455 if (!rmap || !rmap->sampler_count)
1456 return 0;
1457
Cody Northrop40316a32014-12-09 19:08:33 -07001458 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001459
Chia-I Wudcb509d2014-12-10 08:53:10 +08001460 /*
1461 * note that we cannot call cmd_state_pointer() here as the following
1462 * cmd_state_pointer() would invalidate the pointer
1463 */
1464 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001465 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001466 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001467
1468 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001469 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001470 4 * rmap->sampler_count, &sampler_dw);
1471
Chia-I Wudcb509d2014-12-10 08:53:10 +08001472 cmd_state_update(cmd, border_offset,
1473 border_stride * rmap->sampler_count, &border_dw);
1474
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001475 for (i = 0; i < rmap->sampler_count; i++) {
1476 const struct intel_pipeline_rmap_slot *slot =
1477 &rmap->slots[surface_count + i];
1478 const struct intel_sampler *sampler;
1479
Chia-I Wuf8385062015-01-04 16:27:24 +08001480 switch (slot->type) {
1481 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001482 intel_desc_set_read_sampler(set, &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001483 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001484 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001485 sampler = NULL;
1486 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001487 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001488 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001489 sampler = NULL;
1490 break;
1491 }
1492
1493 if (sampler) {
1494 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1495
1496 sampler_dw[0] = sampler->cmd[0];
1497 sampler_dw[1] = sampler->cmd[1];
1498 sampler_dw[2] = border_offset;
1499 sampler_dw[3] = sampler->cmd[2];
1500 } else {
1501 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1502 sampler_dw[1] = 0;
1503 sampler_dw[2] = 0;
1504 sampler_dw[3] = 0;
1505 }
1506
1507 border_offset += border_stride * 4;
1508 border_dw += border_stride;
1509 sampler_dw += 4;
1510 }
1511
Chia-I Wu625105f2014-10-13 15:35:29 +08001512 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001513}
1514
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001515static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001516 const struct intel_pipeline_rmap *rmap,
1517 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001518{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001519 const uint32_t sba_offset =
1520 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001521 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001522 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001523 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001524
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001525 CMD_ASSERT(cmd, 6, 7.5);
1526
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001527 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001528 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001529 if (!surface_count)
1530 return 0;
1531
Chia-I Wu42a56202014-08-23 16:47:48 +08001532 assert(surface_count <= ARRAY_SIZE(binding_table));
1533
1534 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001535 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001536 struct intel_null_view null_view;
1537 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001538
Chia-I Wuf8385062015-01-04 16:27:24 +08001539 switch (slot->type) {
1540 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001541 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001542 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001543 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1544 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001545
Chia-I Wu787a05b2014-12-05 11:02:20 +08001546 if (view) {
1547 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1548 GEN6_ALIGNMENT_SURFACE_STATE,
1549 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001550
Chia-I Wu787a05b2014-12-05 11:02:20 +08001551 cmd_reserve_reloc(cmd, 1);
1552 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1553 view->cmd[1], INTEL_RELOC_WRITE);
1554 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001555 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001556 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001557 }
1558 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001559 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001560 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001561 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1562 const struct intel_mem *mem;
1563 bool read_only;
1564 const uint32_t *cmd_data;
1565 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001566
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001567 assert(dyn_idx < 0 ||
1568 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001569
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001570 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1571 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001572 if (mem) {
1573 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1574 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1575 const uint32_t reloc_flags =
1576 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001577
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001578 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001579 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001580 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001581
1582 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001583 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1584 cmd_data[1] + dynamic_offset, reloc_flags);
1585 } else {
1586 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001587 }
1588 }
1589 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001590 case INTEL_PIPELINE_RMAP_UNUSED:
1591 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001592 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001593 default:
1594 assert(!"unexpected rmap type");
1595 need_null_view = true;
1596 break;
1597 }
1598
1599 if (need_null_view) {
1600 intel_null_view_init(&null_view, cmd->dev);
1601 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1602 GEN6_ALIGNMENT_SURFACE_STATE,
1603 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001604 }
1605
Chia-I Wuf98dd882015-02-10 04:17:47 +08001606 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001607 }
1608
Chia-I Wuf98dd882015-02-10 04:17:47 +08001609 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001610 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001611 surface_count, binding_table) - sba_offset;
1612
1613 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1614 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1615
1616 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001617}
1618
Chia-I Wu1d125092014-10-08 08:49:38 +08001619static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1620{
1621 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001622 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1623 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001624 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001625
1626 CMD_ASSERT(cmd, 6, 7.5);
1627
1628 if (!pipeline->vb_count)
1629 return;
1630
1631 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1632
1633 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1634 dw++;
1635 pos++;
1636
1637 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001638 assert(pipeline->vb[i].strideInBytes <= 2048);
1639
1640 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1641 pipeline->vb[i].strideInBytes;
1642
1643 if (cmd_gen(cmd) >= INTEL_GEN(7))
1644 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1645
1646 switch (pipeline->vb[i].stepRate) {
1647 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1648 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1649 dw[3] = 0;
1650 break;
1651 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1652 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1653 dw[3] = 1;
1654 break;
1655 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1656 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1657 dw[3] = 0;
1658 break;
1659 default:
1660 assert(!"unknown step rate");
1661 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1662 dw[3] = 0;
1663 break;
1664 }
1665
Chia-I Wu714df452015-01-01 07:55:04 +08001666 if (cmd->bind.vertex.buf[i]) {
1667 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001668 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001669
1670 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001671 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1672 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001673 } else {
1674 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1675 dw[1] = 0;
1676 dw[2] = 0;
1677 }
1678
1679 dw += 4;
1680 pos += 4;
1681 }
1682}
1683
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001684static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1685{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001686 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1687 const struct intel_pipeline_shader *vs = &pipeline->vs;
1688 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001689 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001690 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001691 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001692 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001693
1694 CMD_ASSERT(cmd, 6, 7.5);
1695
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001696 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001697 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1698 *
1699 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1700 * 128-bit vertex elements to be passed into the payload for each
1701 * vertex."
1702 *
1703 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1704 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001705 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001706 vue_read_len = (vs->in_count + 1) / 2;
1707 if (!vue_read_len)
1708 vue_read_len = 1;
1709
1710 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1711 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1712
1713 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1714 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1715 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001716
1717 dw5 = GEN6_VS_DW5_STATISTICS |
1718 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001719
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001720 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001721 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001722 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001723 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001724
Chia-I Wube0a3d92014-09-02 13:20:59 +08001725 if (pipeline->disable_vs_cache)
1726 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1727
Chia-I Wu784d3042014-12-19 14:30:04 +08001728 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001729 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001730 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001731 dw[2] = dw2;
1732 dw[3] = 0; /* scratch */
1733 dw[4] = dw4;
1734 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001735
1736 if (vs->per_thread_scratch_size)
1737 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001738}
1739
Chia-I Wu625105f2014-10-13 15:35:29 +08001740static void emit_shader_resources(struct intel_cmd *cmd)
1741{
1742 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001743 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001744
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001745 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001746 cmd->bind.pipeline.graphics->vs.rmap,
1747 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001748 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001749 cmd->bind.pipeline.graphics->tcs.rmap,
1750 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001751 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001752 cmd->bind.pipeline.graphics->tes.rmap,
1753 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001754 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001755 cmd->bind.pipeline.graphics->gs.rmap,
1756 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001757 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001758 cmd->bind.pipeline.graphics->fs.rmap,
1759 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001760
1761 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1762 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1763 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1764 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1765 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1766
1767 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1768 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001769 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1770 binding_tables[0]);
1771 gen7_3dstate_pointer(cmd,
1772 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1773 binding_tables[1]);
1774 gen7_3dstate_pointer(cmd,
1775 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1776 binding_tables[2]);
1777 gen7_3dstate_pointer(cmd,
1778 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1779 binding_tables[3]);
1780 gen7_3dstate_pointer(cmd,
1781 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1782 binding_tables[4]);
1783
1784 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001785 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1786 samplers[0]);
1787 gen7_3dstate_pointer(cmd,
1788 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1789 samplers[1]);
1790 gen7_3dstate_pointer(cmd,
1791 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1792 samplers[2]);
1793 gen7_3dstate_pointer(cmd,
1794 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1795 samplers[3]);
1796 gen7_3dstate_pointer(cmd,
1797 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1798 samplers[4]);
1799 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001800 assert(!binding_tables[1] && !binding_tables[2]);
1801 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1802 binding_tables[0], binding_tables[3], binding_tables[4]);
1803
Chia-I Wu625105f2014-10-13 15:35:29 +08001804 assert(!samplers[1] && !samplers[2]);
1805 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1806 samplers[0], samplers[3], samplers[4]);
1807 }
1808}
1809
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001810static void emit_rt(struct intel_cmd *cmd)
1811{
1812 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001813 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1814 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001815}
1816
1817static void emit_ds(struct intel_cmd *cmd)
1818{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001819 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001820
1821 if (!ds) {
1822 /* all zeros */
1823 static const struct intel_ds_view null_ds;
1824 ds = &null_ds;
1825 }
1826
1827 cmd_wa_gen6_pre_ds_flush(cmd);
1828 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1829 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1830 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1831
1832 if (cmd_gen(cmd) >= INTEL_GEN(7))
1833 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1834 else
1835 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1836}
1837
Chia-I Wua57761b2014-10-14 14:27:44 +08001838static uint32_t emit_shader(struct intel_cmd *cmd,
1839 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001840{
Chia-I Wua57761b2014-10-14 14:27:44 +08001841 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1842 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001843 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001844
Chia-I Wua57761b2014-10-14 14:27:44 +08001845 /* see if the shader is already in the cache */
1846 for (i = 0; i < cache->used; i++) {
1847 if (cache->entries[i].shader == (const void *) shader)
1848 return cache->entries[i].kernel_offset;
1849 }
1850
1851 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1852
1853 /* grow the cache if full */
1854 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001855 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001856 void *entries;
1857
1858 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1859 XGL_SYSTEM_ALLOC_INTERNAL);
1860 if (entries) {
1861 if (cache->entries) {
1862 memcpy(entries, cache->entries,
1863 sizeof(cache->entries[0]) * cache->used);
1864 icd_free(cache->entries);
1865 }
1866
1867 cache->entries = entries;
1868 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001869 }
1870 }
1871
Chia-I Wua57761b2014-10-14 14:27:44 +08001872 /* add the shader to the cache */
1873 if (cache->used < cache->count) {
1874 cache->entries[cache->used].shader = (const void *) shader;
1875 cache->entries[cache->used].kernel_offset = offset;
1876 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001877 }
1878
Chia-I Wua57761b2014-10-14 14:27:44 +08001879 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001880}
1881
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001882static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001883{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001884 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001885
Chia-I Wu8370b402014-08-29 12:28:37 +08001886 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1887 cmd_wa_gen6_pre_depth_stall_write(cmd);
1888 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1889 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1890 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1891 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001892
1893 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001894 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001895 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001896
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001897 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001898 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001899 }
1900 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001901 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001902 }
1903 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001904 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1905 }
1906 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1907 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1908 }
1909 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1910 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001911 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001912
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001913 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1914 gen7_3DSTATE_GS(cmd);
1915 } else {
1916 gen6_3DSTATE_GS(cmd);
1917 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001918
Chia-I Wu8370b402014-08-29 12:28:37 +08001919 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1920 cmd_wa_gen7_post_command_cs_stall(cmd);
1921 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1922 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001923}
1924
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001925static void emit_bounded_states(struct intel_cmd *cmd)
1926{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001927
1928 emit_graphics_pipeline(cmd);
1929
1930 emit_rt(cmd);
1931 emit_ds(cmd);
1932
1933 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1934 gen7_cc_states(cmd);
1935 gen7_viewport_states(cmd);
1936
1937 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1938 &cmd->bind.pipeline.graphics->vs);
1939 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1940 &cmd->bind.pipeline.graphics->fs);
1941
1942 gen6_3DSTATE_CLIP(cmd);
1943 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001944 gen7_3DSTATE_WM(cmd);
1945 gen7_3DSTATE_PS(cmd);
1946 } else {
1947 gen6_cc_states(cmd);
1948 gen6_viewport_states(cmd);
1949
1950 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1951 &cmd->bind.pipeline.graphics->vs);
1952 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1953 &cmd->bind.pipeline.graphics->fs);
1954
1955 gen6_3DSTATE_CLIP(cmd);
1956 gen6_3DSTATE_SF(cmd);
1957 gen6_3DSTATE_WM(cmd);
1958 }
1959
1960 emit_shader_resources(cmd);
1961
1962 cmd_wa_gen6_pre_depth_stall_write(cmd);
1963 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1964
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001965 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1966 gen6_3DSTATE_VS(cmd);
1967}
1968
Tony Barbourfa6cac72015-01-16 14:27:35 -07001969static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
1970 const struct intel_cmd_meta *meta)
1971{
1972 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
1973 const uint8_t cmd_len = 3;
1974 uint32_t dw[3];
1975 uint32_t cmd_depth_stencil;
1976 uint32_t cmd_depth_test;
1977
1978 CMD_ASSERT(cmd, 6, 7.5);
1979
1980 cmd_depth_stencil = 0;
1981 cmd_depth_test = 0;
1982 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
1983 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
1984 GEN6_COMPAREFUNCTION_ALWAYS << 27;
1985 }
1986 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
1987 cmd_depth_stencil = 1 << 31 |
1988 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
1989 (GEN6_STENCILOP_KEEP) << 25 |
1990 (GEN6_STENCILOP_KEEP) << 22 |
1991 (GEN6_STENCILOP_REPLACE) << 19 |
1992 1 << 15 |
1993 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
1994 (GEN6_STENCILOP_KEEP) << 9 |
1995 (GEN6_STENCILOP_KEEP) << 6 |
1996 (GEN6_STENCILOP_REPLACE) << 3;
1997 }
1998
1999 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2000 dw[0] = cmd_depth_stencil | 1 << 18;
2001 dw[1] = (0xff) << 24 | (0xff) << 16;
2002 dw[2] = cmd_depth_test;
2003
2004 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2005 cmd_align, cmd_len, dw);
2006}
2007
Chia-I Wu6032b892014-10-17 14:47:18 +08002008static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2009{
2010 const struct intel_cmd_meta *meta = cmd->bind.meta;
2011 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2012
2013 CMD_ASSERT(cmd, 6, 7.5);
2014
2015 blend_offset = 0;
2016 ds_offset = 0;
2017 cc_offset = 0;
2018 cc_vp_offset = 0;
2019
Chia-I Wu29e6f502014-11-24 14:27:29 +08002020 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002021 /* BLEND_STATE */
2022 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002023 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002024 dw[0] = 0;
2025 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2026 }
2027
Chia-I Wu29e6f502014-11-24 14:27:29 +08002028 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002029 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002030 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002031 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2032 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002033
Chia-I Wu29e6f502014-11-24 14:27:29 +08002034 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002035 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002036
Chia-I Wu29e6f502014-11-24 14:27:29 +08002037 /* COLOR_CALC_STATE */
2038 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002039 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002040
Chia-I Wu29e6f502014-11-24 14:27:29 +08002041 /* CC_VIEWPORT */
2042 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002043 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002044 dw[0] = u_fui(0.0f);
2045 dw[1] = u_fui(1.0f);
2046 } else {
2047 /* DEPTH_STENCIL_STATE */
2048 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002049 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002050 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2051 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2052 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002053 }
2054
2055 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2056 gen7_3dstate_pointer(cmd,
2057 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2058 blend_offset);
2059 gen7_3dstate_pointer(cmd,
2060 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2061 ds_offset);
2062 gen7_3dstate_pointer(cmd,
2063 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2064
2065 gen7_3dstate_pointer(cmd,
2066 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2067 cc_vp_offset);
2068 } else {
2069 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002070 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002071
2072 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2073 cmd_batch_pointer(cmd, 4, &dw);
2074 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2075 GEN6_PTR_VP_DW0_CC_CHANGED;
2076 dw[1] = 0;
2077 dw[2] = 0;
2078 dw[3] = cc_vp_offset;
2079 }
2080}
2081
2082static void gen6_meta_surface_states(struct intel_cmd *cmd)
2083{
2084 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002085 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002086 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002087 const uint32_t sba_offset =
2088 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002089
2090 CMD_ASSERT(cmd, 6, 7.5);
2091
Chia-I Wu29e6f502014-11-24 14:27:29 +08002092 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2093 return;
2094
Chia-I Wu005c47c2014-10-22 13:49:13 +08002095 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002096 if (meta->src.valid) {
2097 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002098 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002099 meta->src.surface_len, meta->src.surface);
2100
2101 cmd_reserve_reloc(cmd, 1);
2102 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2103 cmd_surface_reloc_writer(cmd, offset, 1,
2104 meta->src.reloc_target, meta->src.reloc_offset);
2105 } else {
2106 cmd_surface_reloc(cmd, offset, 1,
2107 (struct intel_bo *) meta->src.reloc_target,
2108 meta->src.reloc_offset, meta->src.reloc_flags);
2109 }
2110
Mike Stroyan9bfad482015-02-10 15:09:23 -07002111 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002112 }
2113 if (meta->dst.valid) {
2114 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002115 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002116 meta->dst.surface_len, meta->dst.surface);
2117
2118 cmd_reserve_reloc(cmd, 1);
2119 cmd_surface_reloc(cmd, offset, 1,
2120 (struct intel_bo *) meta->dst.reloc_target,
2121 meta->dst.reloc_offset, meta->dst.reloc_flags);
2122
Mike Stroyan9bfad482015-02-10 15:09:23 -07002123 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002124 }
2125
2126 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002127 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002128 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002129 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002130
2131 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002132 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2133 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2134 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002135 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002136 } else {
2137 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002138 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002139 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002140 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002141 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002142 }
2143}
2144
2145static void gen6_meta_urb(struct intel_cmd *cmd)
2146{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002147 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002148 uint32_t *dw;
2149
2150 CMD_ASSERT(cmd, 6, 6);
2151
2152 /* 3DSTATE_URB */
2153 cmd_batch_pointer(cmd, 3, &dw);
2154 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002155 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002156 dw[2] = 0;
2157}
2158
2159static void gen7_meta_urb(struct intel_cmd *cmd)
2160{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002161 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2162 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002163 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002164 uint32_t *dw;
2165
2166 CMD_ASSERT(cmd, 7, 7.5);
2167
2168 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2169 cmd_batch_pointer(cmd, 10, &dw);
2170
2171 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002172 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
2173 dw += 2;
2174
2175 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2176 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
2177 pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002178 dw += 2;
2179
2180 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2181 dw[1] = 0;
2182 dw += 2;
2183
2184 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2185 dw[1] = 0;
2186 dw += 2;
2187
2188 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2189 dw[1] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002190
Chia-I Wu15dacac2015-02-05 11:14:01 -07002191 cmd_wa_gen7_post_command_cs_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002192
2193 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2194
Chia-I Wu24aa1022014-11-25 11:53:19 +08002195 switch (cmd_gen(cmd)) {
2196 case INTEL_GEN(7.5):
2197 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2198 break;
2199 case INTEL_GEN(7):
2200 default:
2201 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2202 break;
2203 }
2204
Chia-I Wu6032b892014-10-17 14:47:18 +08002205 /* 3DSTATE_URB_x */
2206 cmd_batch_pointer(cmd, 8, &dw);
2207
2208 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002209 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002210 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002211 dw += 2;
2212
2213 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002214 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002215 dw += 2;
2216
2217 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002218 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002219 dw += 2;
2220
2221 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002222 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002223 dw += 2;
2224}
2225
2226static void gen6_meta_vf(struct intel_cmd *cmd)
2227{
2228 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002229 uint32_t vb_start, vb_end, vb_stride;
2230 int ve_format, ve_z_source;
2231 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002232 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002233
2234 CMD_ASSERT(cmd, 6, 7.5);
2235
Chia-I Wu29e6f502014-11-24 14:27:29 +08002236 switch (meta->mode) {
2237 case INTEL_CMD_META_VS_POINTS:
2238 cmd_batch_pointer(cmd, 3, &dw);
2239 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2240 dw[1] = GEN6_VE_STATE_DW0_VALID;
2241 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2242 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2243 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2244 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2245 return;
2246 break;
2247 case INTEL_CMD_META_FS_RECT:
2248 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002249 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002250
Chia-I Wu29e6f502014-11-24 14:27:29 +08002251 vertices[0][0] = meta->dst.x + meta->width;
2252 vertices[0][1] = meta->dst.y + meta->height;
2253 vertices[1][0] = meta->dst.x;
2254 vertices[1][1] = meta->dst.y + meta->height;
2255 vertices[2][0] = meta->dst.x;
2256 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002257
Chia-I Wu29e6f502014-11-24 14:27:29 +08002258 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2259 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002260
Chia-I Wu29e6f502014-11-24 14:27:29 +08002261 vb_end = vb_start + sizeof(vertices) - 1;
2262 vb_stride = sizeof(vertices[0]);
2263 ve_z_source = GEN6_VFCOMP_STORE_0;
2264 ve_format = GEN6_FORMAT_R32G32_USCALED;
2265 }
2266 break;
2267 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2268 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002269 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002270
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002271 vertices[0][0] = (float) (meta->dst.x + meta->width);
2272 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002273 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002274 vertices[1][0] = (float) meta->dst.x;
2275 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002276 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002277 vertices[2][0] = (float) meta->dst.x;
2278 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002279 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002280
Chia-I Wu29e6f502014-11-24 14:27:29 +08002281 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2282 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002283
Chia-I Wu29e6f502014-11-24 14:27:29 +08002284 vb_end = vb_start + sizeof(vertices) - 1;
2285 vb_stride = sizeof(vertices[0]);
2286 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2287 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2288 }
2289 break;
2290 default:
2291 assert(!"unknown meta mode");
2292 return;
2293 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002294 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002295
2296 /* 3DSTATE_VERTEX_BUFFERS */
2297 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002298
Chia-I Wu6032b892014-10-17 14:47:18 +08002299 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002300 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002301 if (cmd_gen(cmd) >= INTEL_GEN(7))
2302 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2303
2304 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002305 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2306 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002307
2308 dw[4] = 0;
2309
2310 /* 3DSTATE_VERTEX_ELEMENTS */
2311 cmd_batch_pointer(cmd, 5, &dw);
2312 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002313 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002314 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2315 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2316 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2317 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2318 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002319 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002320 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2321 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002322 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002323 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2324}
2325
Chia-I Wu29e6f502014-11-24 14:27:29 +08002326static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002327{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002328 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002329 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002330 uint32_t consts[8];
2331 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002332
2333 CMD_ASSERT(cmd, 6, 7.5);
2334
2335 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002336 case INTEL_DEV_META_VS_FILL_MEM:
2337 consts[0] = meta->dst.x;
2338 consts[1] = meta->clear_val[0];
2339 const_count = 2;
2340 break;
2341 case INTEL_DEV_META_VS_COPY_MEM:
2342 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2343 consts[0] = meta->dst.x;
2344 consts[1] = meta->src.x;
2345 const_count = 2;
2346 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002347 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2348 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2349 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2350 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2351 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2352 consts[0] = meta->src.x;
2353 consts[1] = meta->src.y;
2354 consts[2] = meta->width;
2355 consts[3] = meta->dst.x;
2356 const_count = 4;
2357 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002358 default:
2359 assert(!"unknown meta shader id");
2360 const_count = 0;
2361 break;
2362 }
2363
2364 /* this can be skipped but it makes state dumping prettier */
2365 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2366
2367 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2368}
2369
2370static void gen6_meta_vs(struct intel_cmd *cmd)
2371{
2372 const struct intel_cmd_meta *meta = cmd->bind.meta;
2373 const struct intel_pipeline_shader *sh =
2374 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2375 uint32_t offset, *dw;
2376
2377 CMD_ASSERT(cmd, 6, 7.5);
2378
2379 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002380 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002381
2382 /* 3DSTATE_CONSTANT_VS */
2383 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2384 cmd_batch_pointer(cmd, cmd_len, &dw);
2385 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2386 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2387
2388 /* 3DSTATE_VS */
2389 cmd_batch_pointer(cmd, 6, &dw);
2390 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2391 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2392
2393 return;
2394 }
2395
2396 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2397
2398 /* 3DSTATE_CONSTANT_VS */
2399 offset = gen6_meta_vs_constants(cmd);
2400 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2401 cmd_batch_pointer(cmd, 7, &dw);
2402 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2403 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2404 dw[2] = 0;
2405 dw[3] = offset;
2406 dw[4] = 0;
2407 dw[5] = 0;
2408 dw[6] = 0;
2409 } else {
2410 cmd_batch_pointer(cmd, 5, &dw);
2411 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2412 GEN6_PCB_ANY_DW0_PCB0_VALID;
2413 dw[1] = offset;
2414 dw[2] = 0;
2415 dw[3] = 0;
2416 dw[4] = 0;
2417 }
2418
2419 /* 3DSTATE_VS */
2420 offset = emit_shader(cmd, sh);
2421 cmd_batch_pointer(cmd, 6, &dw);
2422 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2423 dw[1] = offset;
2424 dw[2] = GEN6_THREADDISP_SPF |
2425 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2426 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002427 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002428 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2429 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2430
2431 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2432 GEN6_VS_DW5_VS_ENABLE;
2433 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002434 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002435 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002436 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002437
2438 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002439}
2440
2441static void gen6_meta_disabled(struct intel_cmd *cmd)
2442{
Chia-I Wu6032b892014-10-17 14:47:18 +08002443 uint32_t *dw;
2444
2445 CMD_ASSERT(cmd, 6, 6);
2446
Chia-I Wu6032b892014-10-17 14:47:18 +08002447 /* 3DSTATE_CONSTANT_GS */
2448 cmd_batch_pointer(cmd, 5, &dw);
2449 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2450 dw[1] = 0;
2451 dw[2] = 0;
2452 dw[3] = 0;
2453 dw[4] = 0;
2454
2455 /* 3DSTATE_GS */
2456 cmd_batch_pointer(cmd, 7, &dw);
2457 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2458 dw[1] = 0;
2459 dw[2] = 0;
2460 dw[3] = 0;
2461 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2462 dw[5] = GEN6_GS_DW5_STATISTICS;
2463 dw[6] = 0;
2464
Chia-I Wu6032b892014-10-17 14:47:18 +08002465 /* 3DSTATE_SF */
2466 cmd_batch_pointer(cmd, 20, &dw);
2467 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2468 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2469 memset(&dw[2], 0, 18 * sizeof(*dw));
2470}
2471
2472static void gen7_meta_disabled(struct intel_cmd *cmd)
2473{
2474 uint32_t *dw;
2475
2476 CMD_ASSERT(cmd, 7, 7.5);
2477
Chia-I Wu6032b892014-10-17 14:47:18 +08002478 /* 3DSTATE_CONSTANT_HS */
2479 cmd_batch_pointer(cmd, 7, &dw);
2480 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2481 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2482
2483 /* 3DSTATE_HS */
2484 cmd_batch_pointer(cmd, 7, &dw);
2485 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2486 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2487
2488 /* 3DSTATE_TE */
2489 cmd_batch_pointer(cmd, 4, &dw);
2490 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2491 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2492
2493 /* 3DSTATE_CONSTANT_DS */
2494 cmd_batch_pointer(cmd, 7, &dw);
2495 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2496 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2497
2498 /* 3DSTATE_DS */
2499 cmd_batch_pointer(cmd, 6, &dw);
2500 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2501 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2502
2503 /* 3DSTATE_CONSTANT_GS */
2504 cmd_batch_pointer(cmd, 7, &dw);
2505 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2506 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2507
2508 /* 3DSTATE_GS */
2509 cmd_batch_pointer(cmd, 7, &dw);
2510 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2511 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2512
2513 /* 3DSTATE_STREAMOUT */
2514 cmd_batch_pointer(cmd, 3, &dw);
2515 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2516 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2517
Chia-I Wu6032b892014-10-17 14:47:18 +08002518 /* 3DSTATE_SF */
2519 cmd_batch_pointer(cmd, 7, &dw);
2520 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2521 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2522
2523 /* 3DSTATE_SBE */
2524 cmd_batch_pointer(cmd, 14, &dw);
2525 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2526 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2527 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002528}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002529
Chia-I Wu29e6f502014-11-24 14:27:29 +08002530static void gen6_meta_clip(struct intel_cmd *cmd)
2531{
2532 const struct intel_cmd_meta *meta = cmd->bind.meta;
2533 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002534
Chia-I Wu29e6f502014-11-24 14:27:29 +08002535 /* 3DSTATE_CLIP */
2536 cmd_batch_pointer(cmd, 4, &dw);
2537 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2538 dw[1] = 0;
2539 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2540 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2541 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2542 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002543 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002544 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002545 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002546}
2547
2548static void gen6_meta_wm(struct intel_cmd *cmd)
2549{
2550 const struct intel_cmd_meta *meta = cmd->bind.meta;
2551 uint32_t *dw;
2552
2553 CMD_ASSERT(cmd, 6, 7.5);
2554
2555 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2556
2557 /* 3DSTATE_MULTISAMPLE */
2558 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2559 cmd_batch_pointer(cmd, 4, &dw);
2560 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2561 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2562 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2563 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2564 dw[2] = 0;
2565 dw[3] = 0;
2566 } else {
2567 cmd_batch_pointer(cmd, 3, &dw);
2568 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2569 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2570 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2571 dw[2] = 0;
2572 }
2573
2574 /* 3DSTATE_SAMPLE_MASK */
2575 cmd_batch_pointer(cmd, 2, &dw);
2576 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2577 dw[1] = (1 << meta->samples) - 1;
2578
2579 /* 3DSTATE_DRAWING_RECTANGLE */
2580 cmd_batch_pointer(cmd, 4, &dw);
2581 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002582 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2583 /* unused */
2584 dw[1] = 0;
2585 dw[2] = 0;
2586 } else {
2587 dw[1] = meta->dst.y << 16 | meta->dst.x;
2588 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2589 (meta->dst.x + meta->width - 1);
2590 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002591 dw[3] = 0;
2592}
2593
2594static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2595{
2596 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002597 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002598 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002599 uint32_t consts[8];
2600 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002601
2602 CMD_ASSERT(cmd, 6, 7.5);
2603
2604 /* underflow is fine here */
2605 offset_x = meta->src.x - meta->dst.x;
2606 offset_y = meta->src.y - meta->dst.y;
2607
2608 switch (meta->shader_id) {
2609 case INTEL_DEV_META_FS_COPY_MEM:
2610 case INTEL_DEV_META_FS_COPY_1D:
2611 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2612 case INTEL_DEV_META_FS_COPY_2D:
2613 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2614 case INTEL_DEV_META_FS_COPY_2D_MS:
2615 consts[0] = offset_x;
2616 consts[1] = offset_y;
2617 consts[2] = meta->src.layer;
2618 consts[3] = meta->src.lod;
2619 const_count = 4;
2620 break;
2621 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2622 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2623 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2624 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2625 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2626 consts[0] = offset_x;
2627 consts[1] = offset_y;
2628 consts[2] = meta->src.layer;
2629 consts[3] = meta->src.lod;
2630 consts[4] = meta->src.x;
2631 consts[5] = meta->width;
2632 const_count = 6;
2633 break;
2634 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2635 consts[0] = offset_x;
2636 consts[1] = offset_y;
2637 consts[2] = meta->width;
2638 const_count = 3;
2639 break;
2640 case INTEL_DEV_META_FS_CLEAR_COLOR:
2641 consts[0] = meta->clear_val[0];
2642 consts[1] = meta->clear_val[1];
2643 consts[2] = meta->clear_val[2];
2644 consts[3] = meta->clear_val[3];
2645 const_count = 4;
2646 break;
2647 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2648 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002649 consts[1] = meta->clear_val[1];
2650 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002651 break;
2652 case INTEL_DEV_META_FS_RESOLVE_2X:
2653 case INTEL_DEV_META_FS_RESOLVE_4X:
2654 case INTEL_DEV_META_FS_RESOLVE_8X:
2655 case INTEL_DEV_META_FS_RESOLVE_16X:
2656 consts[0] = offset_x;
2657 consts[1] = offset_y;
2658 const_count = 2;
2659 break;
2660 default:
2661 assert(!"unknown meta shader id");
2662 const_count = 0;
2663 break;
2664 }
2665
2666 /* this can be skipped but it makes state dumping prettier */
2667 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2668
2669 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2670}
2671
2672static void gen6_meta_ps(struct intel_cmd *cmd)
2673{
2674 const struct intel_cmd_meta *meta = cmd->bind.meta;
2675 const struct intel_pipeline_shader *sh =
2676 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2677 uint32_t offset, *dw;
2678
2679 CMD_ASSERT(cmd, 6, 6);
2680
Chia-I Wu29e6f502014-11-24 14:27:29 +08002681 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2682 /* 3DSTATE_CONSTANT_PS */
2683 cmd_batch_pointer(cmd, 5, &dw);
2684 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2685 dw[1] = 0;
2686 dw[2] = 0;
2687 dw[3] = 0;
2688 dw[4] = 0;
2689
2690 /* 3DSTATE_WM */
2691 cmd_batch_pointer(cmd, 9, &dw);
2692 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2693 dw[1] = 0;
2694 dw[2] = 0;
2695 dw[3] = 0;
2696 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002697 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002698 dw[6] = 0;
2699 dw[7] = 0;
2700 dw[8] = 0;
2701
Chia-I Wu3adf7212014-10-24 15:34:07 +08002702 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002703 }
2704
Chia-I Wu3adf7212014-10-24 15:34:07 +08002705 /* a normal color write */
2706 assert(meta->dst.valid && !sh->uses);
2707
Chia-I Wu6032b892014-10-17 14:47:18 +08002708 /* 3DSTATE_CONSTANT_PS */
2709 offset = gen6_meta_ps_constants(cmd);
2710 cmd_batch_pointer(cmd, 5, &dw);
2711 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2712 GEN6_PCB_ANY_DW0_PCB0_VALID;
2713 dw[1] = offset;
2714 dw[2] = 0;
2715 dw[3] = 0;
2716 dw[4] = 0;
2717
2718 /* 3DSTATE_WM */
2719 offset = emit_shader(cmd, sh);
2720 cmd_batch_pointer(cmd, 9, &dw);
2721 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2722 dw[1] = offset;
2723 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2724 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002725 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002726 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002727 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002728 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002729 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2730
Chia-I Wu6032b892014-10-17 14:47:18 +08002731 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2732 GEN6_WM_DW6_POSOFFSET_NONE |
2733 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2734 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2735 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2736 if (meta->samples > 1) {
2737 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2738 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2739 } else {
2740 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2741 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2742 }
2743 dw[7] = 0;
2744 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002745
2746 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002747}
2748
2749static void gen7_meta_ps(struct intel_cmd *cmd)
2750{
2751 const struct intel_cmd_meta *meta = cmd->bind.meta;
2752 const struct intel_pipeline_shader *sh =
2753 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2754 uint32_t offset, *dw;
2755
2756 CMD_ASSERT(cmd, 7, 7.5);
2757
Chia-I Wu29e6f502014-11-24 14:27:29 +08002758 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2759 /* 3DSTATE_WM */
2760 cmd_batch_pointer(cmd, 3, &dw);
2761 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2762 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2763
2764 /* 3DSTATE_CONSTANT_GS */
2765 cmd_batch_pointer(cmd, 7, &dw);
2766 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2767 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2768
2769 /* 3DSTATE_PS */
2770 cmd_batch_pointer(cmd, 8, &dw);
2771 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2772 dw[1] = 0;
2773 dw[2] = 0;
2774 dw[3] = 0;
2775 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002776 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002777 dw[5] = 0;
2778 dw[6] = 0;
2779 dw[7] = 0;
2780
Chia-I Wu3adf7212014-10-24 15:34:07 +08002781 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002782 }
2783
Chia-I Wu3adf7212014-10-24 15:34:07 +08002784 /* a normal color write */
2785 assert(meta->dst.valid && !sh->uses);
2786
Chia-I Wu6032b892014-10-17 14:47:18 +08002787 /* 3DSTATE_WM */
2788 cmd_batch_pointer(cmd, 3, &dw);
2789 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2790 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2791 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2792 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2793 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2794 dw[2] = 0;
2795
2796 /* 3DSTATE_CONSTANT_PS */
2797 offset = gen6_meta_ps_constants(cmd);
2798 cmd_batch_pointer(cmd, 7, &dw);
2799 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2800 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2801 dw[2] = 0;
2802 dw[3] = offset;
2803 dw[4] = 0;
2804 dw[5] = 0;
2805 dw[6] = 0;
2806
2807 /* 3DSTATE_PS */
2808 offset = emit_shader(cmd, sh);
2809 cmd_batch_pointer(cmd, 8, &dw);
2810 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2811 dw[1] = offset;
2812 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2813 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002814 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002815
2816 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2817 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002818 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2819
2820 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002821 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002822 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002823 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002824 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002825 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002826
2827 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2828 dw[6] = 0;
2829 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002830
2831 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002832}
2833
2834static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2835{
2836 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002837 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002838
2839 CMD_ASSERT(cmd, 6, 7.5);
2840
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002841 if (!ds) {
2842 /* all zeros */
2843 static const struct intel_ds_view null_ds;
2844 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002845 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002846
2847 cmd_wa_gen6_pre_ds_flush(cmd);
2848 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2849 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2850 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2851
2852 if (cmd_gen(cmd) >= INTEL_GEN(7))
2853 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2854 else
2855 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002856}
2857
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002858static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2859 const struct intel_pipeline *pipeline)
2860{
2861 cmd->bind.pipeline.graphics = pipeline;
2862}
2863
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002864static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2865 const struct intel_pipeline *pipeline)
2866{
2867 cmd->bind.pipeline.compute = pipeline;
2868}
2869
2870static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2871 const struct intel_pipeline_delta *delta)
2872{
2873 cmd->bind.pipeline.graphics_delta = delta;
2874}
2875
2876static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2877 const struct intel_pipeline_delta *delta)
2878{
2879 cmd->bind.pipeline.compute_delta = delta;
2880}
2881
2882static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002883 const struct intel_desc_set *dset,
2884 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002885{
Chia-I Wuf8385062015-01-04 16:27:24 +08002886 const uint32_t size = sizeof(*dynamic_offsets) *
2887 dset->layout->dynamic_desc_count;
2888
2889 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2890 if (cmd->bind.dset.graphics_dynamic_offsets)
2891 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2892
2893 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2894 4, XGL_SYSTEM_ALLOC_INTERNAL);
2895 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002896 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002897 return;
2898 }
2899
2900 cmd->bind.dset.graphics_dynamic_offset_size = size;
2901 }
2902
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002903 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002904 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002905}
2906
2907static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002908 const struct intel_desc_set *dset,
2909 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002910{
Chia-I Wuf8385062015-01-04 16:27:24 +08002911 const uint32_t size = sizeof(*dynamic_offsets) *
2912 dset->layout->dynamic_desc_count;
2913
2914 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2915 if (cmd->bind.dset.compute_dynamic_offsets)
2916 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2917
2918 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2919 4, XGL_SYSTEM_ALLOC_INTERNAL);
2920 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002921 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002922 return;
2923 }
2924
2925 cmd->bind.dset.compute_dynamic_offset_size = size;
2926 }
2927
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002928 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002929 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002930}
2931
Chia-I Wu3b04af52014-11-08 10:48:20 +08002932static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002933 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002934 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08002935{
Chia-I Wu714df452015-01-01 07:55:04 +08002936 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002937 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08002938 return;
2939 }
2940
Chia-I Wu714df452015-01-01 07:55:04 +08002941 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002942 cmd->bind.vertex.offset[binding] = offset;
2943}
2944
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002945static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002946 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002947 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2948{
Chia-I Wu714df452015-01-01 07:55:04 +08002949 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002950 cmd->bind.index.offset = offset;
2951 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002952}
2953
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002954static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002955 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002956{
2957 cmd->bind.state.viewport = state;
2958}
2959
2960static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002961 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002962{
2963 cmd->bind.state.raster = state;
2964}
2965
2966static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002967 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002968{
2969 cmd->bind.state.ds = state;
2970}
2971
2972static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002973 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002974{
2975 cmd->bind.state.blend = state;
2976}
2977
Chia-I Wuf98dd882015-02-10 04:17:47 +08002978static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
2979{
2980 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
2981 struct intel_pipeline_rmap *rmaps[5] = {
2982 pipeline->vs.rmap,
2983 pipeline->tcs.rmap,
2984 pipeline->tes.rmap,
2985 pipeline->gs.rmap,
2986 pipeline->fs.rmap,
2987 };
2988 uint32_t max_write;
2989 int i;
2990
2991 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
2992 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
2993 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
2994
2995 /* pad first */
2996 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
2997
2998 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
2999 const struct intel_pipeline_rmap *rmap = rmaps[i];
3000 const uint32_t surface_count = (rmap) ?
3001 rmap->rt_count + rmap->texture_resource_count +
3002 rmap->resource_count + rmap->uav_count : 0;
3003
3004 if (surface_count) {
3005 /* SURFACE_STATEs */
3006 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3007
3008 /* BINDING_TABLE_STATE */
3009 max_write += u_align(sizeof(uint32_t) * surface_count,
3010 GEN6_ALIGNMENT_SURFACE_STATE);
3011 }
3012 }
3013
3014 return max_write;
3015}
3016
3017static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3018{
3019 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3020 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3021 uint32_t max_surface_write;
3022
3023 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3024 if (cmd->bind.meta)
3025 max_surface_write = 64 * sizeof(uint32_t);
3026 else
3027 max_surface_write = cmd_get_max_surface_write(cmd);
3028
3029 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3030 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3031 /* SBA expects page-aligned addresses */
3032 writer->sba_offset = writer->used & ~0xfff;
3033
3034 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3035
3036 cmd_batch_state_base_address(cmd);
3037 }
3038}
3039
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003040static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003041 uint32_t vertex_start,
3042 uint32_t vertex_count,
3043 uint32_t instance_start,
3044 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003045 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003046 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003047{
3048 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003049 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003050 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3051
3052 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003053
3054 emit_bounded_states(cmd);
3055
Chia-I Wuf98dd882015-02-10 04:17:47 +08003056 /* sanity check on cmd_get_max_surface_write() */
3057 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3058 surface_writer_used <= cmd_get_max_surface_write(cmd));
3059
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003060 if (indexed) {
3061 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003062 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003063
3064 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3065 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3066 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003067 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003068 cmd->bind.index.offset, cmd->bind.index.type,
3069 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003070 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003071 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003072 cmd->bind.index.offset, cmd->bind.index.type,
3073 p->primitive_restart);
3074 }
3075 } else {
3076 assert(!vertex_base);
3077 }
3078
3079 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3080 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3081 vertex_start, instance_count, instance_start, vertex_base);
3082 } else {
3083 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3084 vertex_start, instance_count, instance_start, vertex_base);
3085 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003086
Chia-I Wu707a29e2014-08-27 12:51:47 +08003087 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003088 /* need to re-emit all workarounds */
3089 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003090
3091 if (intel_debug & INTEL_DEBUG_NOCACHE)
3092 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003093}
3094
Chia-I Wuc14d1562014-10-17 09:49:22 +08003095void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3096{
Chia-I Wu6032b892014-10-17 14:47:18 +08003097 cmd->bind.meta = meta;
3098
Chia-I Wuf98dd882015-02-10 04:17:47 +08003099 cmd_adjust_state_base_address(cmd);
3100
Chia-I Wu6032b892014-10-17 14:47:18 +08003101 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003102 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003103
3104 gen6_meta_dynamic_states(cmd);
3105 gen6_meta_surface_states(cmd);
3106
3107 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3108 gen7_meta_urb(cmd);
3109 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003110 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003111 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003112 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003113 gen6_meta_wm(cmd);
3114 gen7_meta_ps(cmd);
3115 gen6_meta_depth_buffer(cmd);
3116
3117 cmd_wa_gen7_post_command_cs_stall(cmd);
3118 cmd_wa_gen7_post_command_depth_stall(cmd);
3119
Chia-I Wu29e6f502014-11-24 14:27:29 +08003120 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3121 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003122 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003123 } else {
3124 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3125 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003126 } else {
3127 gen6_meta_urb(cmd);
3128 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003129 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003130 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003131 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003132 gen6_meta_wm(cmd);
3133 gen6_meta_ps(cmd);
3134 gen6_meta_depth_buffer(cmd);
3135
Chia-I Wu29e6f502014-11-24 14:27:29 +08003136 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3137 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003138 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003139 } else {
3140 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3141 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003142 }
3143
3144 cmd->bind.draw_count++;
3145 /* need to re-emit all workarounds */
3146 cmd->bind.wa_flags = 0;
3147
3148 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003149
3150 if (intel_debug & INTEL_DEBUG_NOCACHE)
3151 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003152}
3153
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003154ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003155 XGL_CMD_BUFFER cmdBuffer,
3156 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3157 XGL_PIPELINE pipeline)
3158{
3159 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3160
3161 switch (pipelineBindPoint) {
3162 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003163 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
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_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003167 break;
3168 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003169 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003170 break;
3171 }
3172}
3173
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003174ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003175 XGL_CMD_BUFFER cmdBuffer,
3176 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3177 XGL_PIPELINE_DELTA delta)
3178{
3179 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3180
3181 switch (pipelineBindPoint) {
3182 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003183 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003184 break;
3185 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003186 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003187 break;
3188 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003189 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003190 break;
3191 }
3192}
3193
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003194ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003195 XGL_CMD_BUFFER cmdBuffer,
3196 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003197 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003198{
3199 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3200
3201 switch (stateBindPoint) {
3202 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003203 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003204 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003205 break;
3206 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003207 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003208 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003209 break;
3210 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003211 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003212 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003213 break;
3214 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003215 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003216 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003217 break;
3218 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003219 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003220 break;
3221 }
3222}
3223
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003224ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003225 XGL_CMD_BUFFER cmdBuffer,
3226 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003227 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003228 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003229{
3230 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003231 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003232
3233 switch (pipelineBindPoint) {
3234 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003235 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003236 break;
3237 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003238 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003239 break;
3240 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003241 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003242 break;
3243 }
3244}
3245
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003246ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003247 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003248 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003249 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003250 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003251{
3252 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003253 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003254
Chia-I Wu714df452015-01-01 07:55:04 +08003255 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003256}
3257
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003258ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003259 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003260 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003261 XGL_GPU_SIZE offset,
3262 XGL_INDEX_TYPE indexType)
3263{
3264 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003265 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003266
Chia-I Wu714df452015-01-01 07:55:04 +08003267 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003268}
3269
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003270ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003271 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003272 uint32_t firstVertex,
3273 uint32_t vertexCount,
3274 uint32_t firstInstance,
3275 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003276{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003277 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003278
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003279 cmd_draw(cmd, firstVertex, vertexCount,
3280 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003281}
3282
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003283ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003284 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003285 uint32_t firstIndex,
3286 uint32_t indexCount,
3287 int32_t vertexOffset,
3288 uint32_t firstInstance,
3289 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003290{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003291 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003292
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003293 cmd_draw(cmd, firstIndex, indexCount,
3294 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003295}
3296
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003297ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003298 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003299 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003300 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003301 uint32_t count,
3302 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003303{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003304 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3305
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003306 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003307}
3308
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003309ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003310 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003311 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003312 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003313 uint32_t count,
3314 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003315{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003316 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3317
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003318 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003319}
3320
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003321ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003322 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003323 uint32_t x,
3324 uint32_t y,
3325 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003326{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003327 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3328
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003329 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003330}
3331
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003332ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003333 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003334 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003335 XGL_GPU_SIZE offset)
3336{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003337 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3338
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003339 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003340}