blob: 81226fa206b7ca31a47e4ba08d181acea51c523e [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 */
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700522 if (cmd->bind.render_pass->fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600523 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;
Chia-I Wu72292b72014-09-09 10:48:33 +0800759
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700760 if (view->has_stencil) {
761 dw[1] = view->cmd[6];
762
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);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700766 } else {
767 dw[1] = 0;
768 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600769 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800770}
771
772static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
773 const struct intel_ds_view *view)
774{
775 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800776 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600777 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800778
779 CMD_ASSERT(cmd, 6, 7.5);
780
781 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800782 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
783 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800784 dw0 |= (cmd_len - 2);
785
Chia-I Wu72292b72014-09-09 10:48:33 +0800786 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
787 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800788
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700789 if (view->has_hiz) {
790 dw[1] = view->cmd[8];
791
Chia-I Wu72292b72014-09-09 10:48:33 +0800792 cmd_reserve_reloc(cmd, 1);
793 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
794 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700795 } else {
796 dw[1] = 0;
797 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600798 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800799}
800
Chia-I Wuf8231032014-08-25 10:44:45 +0800801static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
802 uint32_t clear_val)
803{
804 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800805 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800806 GEN6_CLEAR_PARAMS_DW0_VALID |
807 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800808 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800809
810 CMD_ASSERT(cmd, 6, 6);
811
Chia-I Wu72292b72014-09-09 10:48:33 +0800812 cmd_batch_pointer(cmd, cmd_len, &dw);
813 dw[0] = dw0;
814 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800815}
816
817static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
818 uint32_t clear_val)
819{
820 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800821 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800822 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800823 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800824
825 CMD_ASSERT(cmd, 7, 7.5);
826
Chia-I Wu72292b72014-09-09 10:48:33 +0800827 cmd_batch_pointer(cmd, cmd_len, &dw);
828 dw[0] = dw0;
829 dw[1] = clear_val;
830 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800831}
832
Chia-I Wu302742d2014-08-22 10:28:29 +0800833static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800834 uint32_t blend_offset,
835 uint32_t ds_offset,
836 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800837{
838 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800839 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800840
841 CMD_ASSERT(cmd, 6, 6);
842
Chia-I Wu426072d2014-08-26 14:31:55 +0800843 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800844 (cmd_len - 2);
845
Chia-I Wu72292b72014-09-09 10:48:33 +0800846 cmd_batch_pointer(cmd, cmd_len, &dw);
847 dw[0] = dw0;
848 dw[1] = blend_offset | 1;
849 dw[2] = ds_offset | 1;
850 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800851}
852
Chia-I Wu1744cca2014-08-22 11:10:17 +0800853static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800854 uint32_t clip_offset,
855 uint32_t sf_offset,
856 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800857{
858 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800859 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800860
861 CMD_ASSERT(cmd, 6, 6);
862
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800864 GEN6_PTR_VP_DW0_CLIP_CHANGED |
865 GEN6_PTR_VP_DW0_SF_CHANGED |
866 GEN6_PTR_VP_DW0_CC_CHANGED |
867 (cmd_len - 2);
868
Chia-I Wu72292b72014-09-09 10:48:33 +0800869 cmd_batch_pointer(cmd, cmd_len, &dw);
870 dw[0] = dw0;
871 dw[1] = clip_offset;
872 dw[2] = sf_offset;
873 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800874}
875
876static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800877 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800878{
879 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800880 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800881
882 CMD_ASSERT(cmd, 6, 6);
883
Chia-I Wu426072d2014-08-26 14:31:55 +0800884 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800885 (cmd_len - 2);
886
Chia-I Wu72292b72014-09-09 10:48:33 +0800887 cmd_batch_pointer(cmd, cmd_len, &dw);
888 dw[0] = dw0;
889 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800890}
891
Chia-I Wu42a56202014-08-23 16:47:48 +0800892static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800893 uint32_t vs_offset,
894 uint32_t gs_offset,
895 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800896{
897 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800899
900 CMD_ASSERT(cmd, 6, 6);
901
Chia-I Wu426072d2014-08-26 14:31:55 +0800902 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800903 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
904 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
905 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
906 (cmd_len - 2);
907
Chia-I Wu72292b72014-09-09 10:48:33 +0800908 cmd_batch_pointer(cmd, cmd_len, &dw);
909 dw[0] = dw0;
910 dw[1] = vs_offset;
911 dw[2] = gs_offset;
912 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800913}
914
Chia-I Wu257e75e2014-08-29 14:06:35 +0800915static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t vs_offset,
917 uint32_t gs_offset,
918 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800919{
920 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800921 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800922
923 CMD_ASSERT(cmd, 6, 6);
924
925 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
926 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
927 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
928 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
929 (cmd_len - 2);
930
Chia-I Wu72292b72014-09-09 10:48:33 +0800931 cmd_batch_pointer(cmd, cmd_len, &dw);
932 dw[0] = dw0;
933 dw[1] = vs_offset;
934 dw[2] = gs_offset;
935 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800936}
937
Chia-I Wu302742d2014-08-22 10:28:29 +0800938static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800940{
941 const uint8_t cmd_len = 2;
942 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
943 GEN6_RENDER_SUBTYPE_3D |
944 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800946
Chia-I Wu72292b72014-09-09 10:48:33 +0800947 cmd_batch_pointer(cmd, cmd_len, &dw);
948 dw[0] = dw0;
949 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800950}
951
Chia-I Wua6c4f152014-12-02 04:19:58 +0800952static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800953{
Chia-I Wue6073342014-11-30 09:43:42 +0800954 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700955 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
956 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800957
958 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700959 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800960
Tony Barbourfa6cac72015-01-16 14:27:35 -0700961 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800962}
963
Chia-I Wu72292b72014-09-09 10:48:33 +0800964static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700965 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800966{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700967 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800968 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800969 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700970 uint32_t dw[3];
971
972 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700973 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700974 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700975 (state->ds_info.stencilWriteMask & 0xff) << 16 |
976 (state->ds_info.stencilReadMask & 0xff) << 8 |
977 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700978 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800979
980 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700981
982 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
983 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800984
Chia-I Wu00b51a82014-09-09 12:07:37 +0800985 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700986 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800987}
988
Chia-I Wu72292b72014-09-09 10:48:33 +0800989static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800990 uint32_t stencil_ref,
991 const uint32_t blend_color[4])
992{
Chia-I Wue6073342014-11-30 09:43:42 +0800993 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800994 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +0800995 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800996
997 CMD_ASSERT(cmd, 6, 7.5);
998
Chia-I Wu00b51a82014-09-09 12:07:37 +0800999 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1000 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001001 dw[0] = stencil_ref;
1002 dw[1] = 0;
1003 dw[2] = blend_color[0];
1004 dw[3] = blend_color[1];
1005 dw[4] = blend_color[2];
1006 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001007
Chia-I Wu72292b72014-09-09 10:48:33 +08001008 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001009}
1010
Chia-I Wu8370b402014-08-29 12:28:37 +08001011static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001012{
Chia-I Wu8370b402014-08-29 12:28:37 +08001013 CMD_ASSERT(cmd, 6, 7.5);
1014
Chia-I Wu707a29e2014-08-27 12:51:47 +08001015 if (!cmd->bind.draw_count)
1016 return;
1017
Chia-I Wu8370b402014-08-29 12:28:37 +08001018 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001019 return;
1020
Chia-I Wu8370b402014-08-29 12:28:37 +08001021 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001022
1023 /*
1024 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1025 *
1026 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1027 * pipe-control with a post-sync op and no write-cache flushes."
1028 *
1029 * The workaround below necessitates this workaround.
1030 */
1031 gen6_PIPE_CONTROL(cmd,
1032 GEN6_PIPE_CONTROL_CS_STALL |
1033 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001034 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001035
Chia-I Wud6d079d2014-08-31 13:14:21 +08001036 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1037 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001038}
1039
Chia-I Wu8370b402014-08-29 12:28:37 +08001040static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001041{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001042 CMD_ASSERT(cmd, 6, 7.5);
1043
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001044 if (!cmd->bind.draw_count)
1045 return;
1046
Chia-I Wud6d079d2014-08-31 13:14:21 +08001047 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1048 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001049}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001050
Chia-I Wu8370b402014-08-29 12:28:37 +08001051static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1052{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001053 CMD_ASSERT(cmd, 7, 7.5);
1054
Chia-I Wu8370b402014-08-29 12:28:37 +08001055 if (!cmd->bind.draw_count)
1056 return;
1057
1058 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001059
1060 gen6_PIPE_CONTROL(cmd,
1061 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001062 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001063}
1064
Chia-I Wu8370b402014-08-29 12:28:37 +08001065static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1066{
1067 CMD_ASSERT(cmd, 7, 7.5);
1068
Chia-I Wu8370b402014-08-29 12:28:37 +08001069 /*
1070 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1071 *
1072 * "One of the following must also be set (when CS stall is set):
1073 *
1074 * * Render Target Cache Flush Enable ([12] of DW1)
1075 * * Depth Cache Flush Enable ([0] of DW1)
1076 * * Stall at Pixel Scoreboard ([1] of DW1)
1077 * * Depth Stall ([13] of DW1)
1078 * * Post-Sync Operation ([13] of DW1)"
1079 */
1080 gen6_PIPE_CONTROL(cmd,
1081 GEN6_PIPE_CONTROL_CS_STALL |
1082 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001083 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001084}
1085
1086static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1087{
1088 CMD_ASSERT(cmd, 7, 7.5);
1089
Chia-I Wu8370b402014-08-29 12:28:37 +08001090 cmd_wa_gen6_pre_depth_stall_write(cmd);
1091
Chia-I Wud6d079d2014-08-31 13:14:21 +08001092 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001093}
1094
1095static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1096{
1097 CMD_ASSERT(cmd, 6, 7.5);
1098
1099 if (!cmd->bind.draw_count)
1100 return;
1101
1102 /*
1103 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1104 *
1105 * "Driver must guarentee that all the caches in the depth pipe are
1106 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1107 * requires driver to send a PIPE_CONTROL with a CS stall along with
1108 * a Depth Flush prior to this command."
1109 *
1110 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1111 *
1112 * "Driver must ierarchi that all the caches in the depth pipe are
1113 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1114 * requires driver to send a PIPE_CONTROL with a CS stall along with
1115 * a Depth Flush prior to this command.
1116 */
1117 gen6_PIPE_CONTROL(cmd,
1118 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1119 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001120 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001121}
1122
1123static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1124{
1125 CMD_ASSERT(cmd, 6, 7.5);
1126
1127 if (!cmd->bind.draw_count)
1128 return;
1129
1130 /*
1131 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1132 *
1133 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1134 * and a post sync operation prior to the group of depth
1135 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1136 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1137 *
1138 * This workaround satifies all the conditions.
1139 */
1140 cmd_wa_gen6_pre_depth_stall_write(cmd);
1141
1142 /*
1143 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1144 *
1145 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1146 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1147 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1148 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1149 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1150 * Depth Flush Bit set, followed by another pipelined depth stall
1151 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1152 * guarantee that the pipeline from WM onwards is already flushed
1153 * (e.g., via a preceding MI_FLUSH)."
1154 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001155 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1156 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1157 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001158}
1159
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001160void cmd_batch_state_base_address(struct intel_cmd *cmd)
1161{
1162 const uint8_t cmd_len = 10;
1163 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1164 (cmd_len - 2);
1165 uint32_t pos;
1166 uint32_t *dw;
1167
1168 CMD_ASSERT(cmd, 6, 7.5);
1169
1170 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1171
1172 dw[0] = dw0;
1173 /* start offsets */
1174 dw[1] = 1;
1175 dw[2] = 1;
1176 dw[3] = 1;
1177 dw[4] = 1;
1178 dw[5] = 1;
1179 /* end offsets */
1180 dw[6] = 1;
1181 dw[7] = 1 + 0xfffff000;
1182 dw[8] = 1 + 0xfffff000;
1183 dw[9] = 1;
1184
1185 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001186 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1187 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1188 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1189 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1190 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1191 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001192}
1193
Chia-I Wu525c6602014-08-27 10:22:34 +08001194void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1195{
Mike Stroyan552fda42015-01-30 17:21:08 -07001196 if (pipe_control_dw0 == 0)
1197 return;
1198
Chia-I Wu525c6602014-08-27 10:22:34 +08001199 if (!cmd->bind.draw_count)
1200 return;
1201
1202 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1203
Chia-I Wu8370b402014-08-29 12:28:37 +08001204 /*
1205 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1206 *
1207 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1208 * PIPE_CONTROL with any non-zero post-sync-op is required."
1209 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001210 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001211 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001212
Chia-I Wu092279a2014-08-30 19:05:30 +08001213 /*
1214 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1215 *
1216 * "One of the following must also be set (when CS stall is set):
1217 *
1218 * * Render Target Cache Flush Enable ([12] of DW1)
1219 * * Depth Cache Flush Enable ([0] of DW1)
1220 * * Stall at Pixel Scoreboard ([1] of DW1)
1221 * * Depth Stall ([13] of DW1)
1222 * * Post-Sync Operation ([13] of DW1)"
1223 */
1224 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1225 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1226 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1227 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1228 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1229 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1230
Chia-I Wud6d079d2014-08-31 13:14:21 +08001231 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001232}
1233
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001234void cmd_batch_flush_all(struct intel_cmd *cmd)
1235{
1236 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1237 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1238 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1239 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1240 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1241 GEN6_PIPE_CONTROL_CS_STALL);
1242}
1243
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001244void cmd_batch_depth_count(struct intel_cmd *cmd,
1245 struct intel_bo *bo,
1246 XGL_GPU_SIZE offset)
1247{
1248 cmd_wa_gen6_pre_depth_stall_write(cmd);
1249
1250 gen6_PIPE_CONTROL(cmd,
1251 GEN6_PIPE_CONTROL_DEPTH_STALL |
1252 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001253 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001254}
1255
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001256void cmd_batch_timestamp(struct intel_cmd *cmd,
1257 struct intel_bo *bo,
1258 XGL_GPU_SIZE offset)
1259{
1260 /* need any WA or stall? */
1261 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1262}
1263
1264void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001265 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001266 struct intel_bo *bo,
1267 XGL_GPU_SIZE offset,
1268 uint64_t val)
1269{
1270 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001271 gen6_PIPE_CONTROL(cmd,
1272 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1273 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001274}
1275
Chia-I Wu302742d2014-08-22 10:28:29 +08001276static void gen6_cc_states(struct intel_cmd *cmd)
1277{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001278 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1279 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001280 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001281 uint32_t stencil_ref;
1282 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001283
1284 CMD_ASSERT(cmd, 6, 6);
1285
Chia-I Wua6c4f152014-12-02 04:19:58 +08001286 blend_offset = gen6_BLEND_STATE(cmd);
1287
1288 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001289 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001290 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001291 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001292
1293 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001294 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001295 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1296 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001297 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001298 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001299 stencil_ref = 0;
1300 }
1301
Chia-I Wu72292b72014-09-09 10:48:33 +08001302 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001303
Chia-I Wu72292b72014-09-09 10:48:33 +08001304 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001305}
1306
Chia-I Wu1744cca2014-08-22 11:10:17 +08001307static void gen6_viewport_states(struct intel_cmd *cmd)
1308{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001309 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001310 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001311
1312 if (!viewport)
1313 return;
1314
Tony Barbourfa6cac72015-01-16 14:27:35 -07001315 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001316 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001317
1318 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001319 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001320 viewport->cmd);
1321
1322 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001323 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001324 &viewport->cmd[viewport->cmd_clip_pos]);
1325
1326 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001327 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001328 &viewport->cmd[viewport->cmd_cc_pos]);
1329
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001330 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1331 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1332 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001333
1334 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001335 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001336
Chia-I Wub1d450a2014-09-09 13:48:03 +08001337 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001338}
1339
Chia-I Wu302742d2014-08-22 10:28:29 +08001340static void gen7_cc_states(struct intel_cmd *cmd)
1341{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001342 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1343 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001344 uint32_t stencil_ref;
1345 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001346 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001347
1348 CMD_ASSERT(cmd, 7, 7.5);
1349
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001350 if (!blend && !ds)
1351 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001352
Chia-I Wua6c4f152014-12-02 04:19:58 +08001353 offset = gen6_BLEND_STATE(cmd);
1354 gen7_3dstate_pointer(cmd,
1355 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001356
Chia-I Wua6c4f152014-12-02 04:19:58 +08001357 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001358 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001359 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001360 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001361
1362 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001363 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001364 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1365 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001366 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001367 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1368 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001369 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1370 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001371 } else {
1372 stencil_ref = 0;
1373 }
1374
Chia-I Wu72292b72014-09-09 10:48:33 +08001375 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001376 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001377 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001378}
1379
Chia-I Wu1744cca2014-08-22 11:10:17 +08001380static void gen7_viewport_states(struct intel_cmd *cmd)
1381{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001382 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001383 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001384
1385 if (!viewport)
1386 return;
1387
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001388 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001389
Chia-I Wub1d450a2014-09-09 13:48:03 +08001390 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001391 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001392 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001393 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001394 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1395 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001396
1397 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001398 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001399 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001400 gen7_3dstate_pointer(cmd,
1401 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001402 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001403
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001404 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1405 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1406 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1407 gen7_3dstate_pointer(cmd,
1408 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1409 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001410}
1411
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001412static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001413 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001414{
1415 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001416 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001417
Chia-I Wu72292b72014-09-09 10:48:33 +08001418 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001419
1420 dw[0] = GEN6_RENDER_TYPE_RENDER |
1421 GEN6_RENDER_SUBTYPE_3D |
1422 subop | (cmd_len - 2);
1423 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001424 dw[2] = 0;
1425 dw[3] = 0;
1426 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001427}
1428
1429static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001430 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001431{
1432 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001433 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001434
Chia-I Wu72292b72014-09-09 10:48:33 +08001435 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001436
1437 dw[0] = GEN6_RENDER_TYPE_RENDER |
1438 GEN6_RENDER_SUBTYPE_3D |
1439 subop | (cmd_len - 2);
1440 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001441 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001442 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001443 dw[4] = 0;
1444 dw[5] = 0;
1445 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001446}
1447
Chia-I Wu625105f2014-10-13 15:35:29 +08001448static uint32_t emit_samplers(struct intel_cmd *cmd,
1449 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001450{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001451 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1452 const uint32_t border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001453 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001454 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001455 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001456 uint32_t surface_count;
1457 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001458
1459 CMD_ASSERT(cmd, 6, 7.5);
1460
Chia-I Wu625105f2014-10-13 15:35:29 +08001461 if (!rmap || !rmap->sampler_count)
1462 return 0;
1463
Cody Northrop40316a32014-12-09 19:08:33 -07001464 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001465
Chia-I Wudcb509d2014-12-10 08:53:10 +08001466 /*
1467 * note that we cannot call cmd_state_pointer() here as the following
1468 * cmd_state_pointer() would invalidate the pointer
1469 */
1470 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001471 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001472 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001473
1474 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001475 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001476 4 * rmap->sampler_count, &sampler_dw);
1477
Chia-I Wudcb509d2014-12-10 08:53:10 +08001478 cmd_state_update(cmd, border_offset,
1479 border_stride * rmap->sampler_count, &border_dw);
1480
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001481 for (i = 0; i < rmap->sampler_count; i++) {
1482 const struct intel_pipeline_rmap_slot *slot =
1483 &rmap->slots[surface_count + i];
1484 const struct intel_sampler *sampler;
1485
Chia-I Wuf8385062015-01-04 16:27:24 +08001486 switch (slot->type) {
1487 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001488 intel_desc_set_read_sampler(set, &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001489 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001490 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001491 sampler = NULL;
1492 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001493 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001494 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001495 sampler = NULL;
1496 break;
1497 }
1498
1499 if (sampler) {
1500 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1501
1502 sampler_dw[0] = sampler->cmd[0];
1503 sampler_dw[1] = sampler->cmd[1];
1504 sampler_dw[2] = border_offset;
1505 sampler_dw[3] = sampler->cmd[2];
1506 } else {
1507 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1508 sampler_dw[1] = 0;
1509 sampler_dw[2] = 0;
1510 sampler_dw[3] = 0;
1511 }
1512
1513 border_offset += border_stride * 4;
1514 border_dw += border_stride;
1515 sampler_dw += 4;
1516 }
1517
Chia-I Wu625105f2014-10-13 15:35:29 +08001518 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001519}
1520
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001521static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001522 const struct intel_pipeline_rmap *rmap,
1523 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001524{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001525 const uint32_t sba_offset =
1526 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001527 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001528 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001529 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001530
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001531 CMD_ASSERT(cmd, 6, 7.5);
1532
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001533 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001534 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001535 if (!surface_count)
1536 return 0;
1537
Chia-I Wu42a56202014-08-23 16:47:48 +08001538 assert(surface_count <= ARRAY_SIZE(binding_table));
1539
1540 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001541 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001542 struct intel_null_view null_view;
1543 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001544
Chia-I Wuf8385062015-01-04 16:27:24 +08001545 switch (slot->type) {
1546 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001547 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001548 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001549 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1550 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001551
Chia-I Wu787a05b2014-12-05 11:02:20 +08001552 if (view) {
1553 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1554 GEN6_ALIGNMENT_SURFACE_STATE,
1555 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001556
Chia-I Wu787a05b2014-12-05 11:02:20 +08001557 cmd_reserve_reloc(cmd, 1);
1558 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1559 view->cmd[1], INTEL_RELOC_WRITE);
1560 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001561 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001562 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001563 }
1564 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001565 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001566 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001567 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1568 const struct intel_mem *mem;
1569 bool read_only;
1570 const uint32_t *cmd_data;
1571 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001572
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001573 assert(dyn_idx < 0 ||
1574 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001575
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001576 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1577 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001578 if (mem) {
1579 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1580 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1581 const uint32_t reloc_flags =
1582 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001583
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001584 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001585 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001586 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001587
1588 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001589 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1590 cmd_data[1] + dynamic_offset, reloc_flags);
1591 } else {
1592 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001593 }
1594 }
1595 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001596 case INTEL_PIPELINE_RMAP_UNUSED:
1597 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001598 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001599 default:
1600 assert(!"unexpected rmap type");
1601 need_null_view = true;
1602 break;
1603 }
1604
1605 if (need_null_view) {
1606 intel_null_view_init(&null_view, cmd->dev);
1607 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1608 GEN6_ALIGNMENT_SURFACE_STATE,
1609 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001610 }
1611
Chia-I Wuf98dd882015-02-10 04:17:47 +08001612 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001613 }
1614
Chia-I Wuf98dd882015-02-10 04:17:47 +08001615 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001616 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001617 surface_count, binding_table) - sba_offset;
1618
1619 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1620 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1621
1622 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001623}
1624
Chia-I Wu1d125092014-10-08 08:49:38 +08001625static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1626{
1627 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001628 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1629 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001630 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001631
1632 CMD_ASSERT(cmd, 6, 7.5);
1633
1634 if (!pipeline->vb_count)
1635 return;
1636
1637 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1638
1639 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1640 dw++;
1641 pos++;
1642
1643 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001644 assert(pipeline->vb[i].strideInBytes <= 2048);
1645
1646 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1647 pipeline->vb[i].strideInBytes;
1648
1649 if (cmd_gen(cmd) >= INTEL_GEN(7))
1650 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1651
1652 switch (pipeline->vb[i].stepRate) {
1653 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1654 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1655 dw[3] = 0;
1656 break;
1657 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1658 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1659 dw[3] = 1;
1660 break;
1661 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1662 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1663 dw[3] = 0;
1664 break;
1665 default:
1666 assert(!"unknown step rate");
1667 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1668 dw[3] = 0;
1669 break;
1670 }
1671
Chia-I Wu714df452015-01-01 07:55:04 +08001672 if (cmd->bind.vertex.buf[i]) {
1673 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001674 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001675
1676 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001677 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1678 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001679 } else {
1680 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1681 dw[1] = 0;
1682 dw[2] = 0;
1683 }
1684
1685 dw += 4;
1686 pos += 4;
1687 }
1688}
1689
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001690static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1691{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001692 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1693 const struct intel_pipeline_shader *vs = &pipeline->vs;
1694 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001695 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001696 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001697 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001698 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001699
1700 CMD_ASSERT(cmd, 6, 7.5);
1701
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001702 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001703 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1704 *
1705 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1706 * 128-bit vertex elements to be passed into the payload for each
1707 * vertex."
1708 *
1709 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1710 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001711 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001712 vue_read_len = (vs->in_count + 1) / 2;
1713 if (!vue_read_len)
1714 vue_read_len = 1;
1715
1716 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1717 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1718
1719 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1720 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1721 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001722
1723 dw5 = GEN6_VS_DW5_STATISTICS |
1724 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001725
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001726 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001727 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001728 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001729 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001730
Chia-I Wube0a3d92014-09-02 13:20:59 +08001731 if (pipeline->disable_vs_cache)
1732 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1733
Chia-I Wu784d3042014-12-19 14:30:04 +08001734 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001735 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001736 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001737 dw[2] = dw2;
1738 dw[3] = 0; /* scratch */
1739 dw[4] = dw4;
1740 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001741
1742 if (vs->per_thread_scratch_size)
1743 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001744}
1745
Chia-I Wu625105f2014-10-13 15:35:29 +08001746static void emit_shader_resources(struct intel_cmd *cmd)
1747{
1748 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001749 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001750
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001751 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001752 cmd->bind.pipeline.graphics->vs.rmap,
1753 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001754 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001755 cmd->bind.pipeline.graphics->tcs.rmap,
1756 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001757 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001758 cmd->bind.pipeline.graphics->tes.rmap,
1759 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001760 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001761 cmd->bind.pipeline.graphics->gs.rmap,
1762 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001763 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001764 cmd->bind.pipeline.graphics->fs.rmap,
1765 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001766
1767 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1768 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1769 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1770 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1771 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1772
1773 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1774 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001775 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1776 binding_tables[0]);
1777 gen7_3dstate_pointer(cmd,
1778 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1779 binding_tables[1]);
1780 gen7_3dstate_pointer(cmd,
1781 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1782 binding_tables[2]);
1783 gen7_3dstate_pointer(cmd,
1784 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1785 binding_tables[3]);
1786 gen7_3dstate_pointer(cmd,
1787 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1788 binding_tables[4]);
1789
1790 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001791 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1792 samplers[0]);
1793 gen7_3dstate_pointer(cmd,
1794 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1795 samplers[1]);
1796 gen7_3dstate_pointer(cmd,
1797 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1798 samplers[2]);
1799 gen7_3dstate_pointer(cmd,
1800 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1801 samplers[3]);
1802 gen7_3dstate_pointer(cmd,
1803 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1804 samplers[4]);
1805 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001806 assert(!binding_tables[1] && !binding_tables[2]);
1807 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1808 binding_tables[0], binding_tables[3], binding_tables[4]);
1809
Chia-I Wu625105f2014-10-13 15:35:29 +08001810 assert(!samplers[1] && !samplers[2]);
1811 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1812 samplers[0], samplers[3], samplers[4]);
1813 }
1814}
1815
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001816static void emit_rt(struct intel_cmd *cmd)
1817{
1818 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001819 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1820 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001821}
1822
1823static void emit_ds(struct intel_cmd *cmd)
1824{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001825 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001826
1827 if (!ds) {
1828 /* all zeros */
1829 static const struct intel_ds_view null_ds;
1830 ds = &null_ds;
1831 }
1832
1833 cmd_wa_gen6_pre_ds_flush(cmd);
1834 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1835 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1836 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1837
1838 if (cmd_gen(cmd) >= INTEL_GEN(7))
1839 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1840 else
1841 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1842}
1843
Chia-I Wua57761b2014-10-14 14:27:44 +08001844static uint32_t emit_shader(struct intel_cmd *cmd,
1845 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001846{
Chia-I Wua57761b2014-10-14 14:27:44 +08001847 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1848 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001849 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001850
Chia-I Wua57761b2014-10-14 14:27:44 +08001851 /* see if the shader is already in the cache */
1852 for (i = 0; i < cache->used; i++) {
1853 if (cache->entries[i].shader == (const void *) shader)
1854 return cache->entries[i].kernel_offset;
1855 }
1856
1857 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1858
1859 /* grow the cache if full */
1860 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001861 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001862 void *entries;
1863
1864 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1865 XGL_SYSTEM_ALLOC_INTERNAL);
1866 if (entries) {
1867 if (cache->entries) {
1868 memcpy(entries, cache->entries,
1869 sizeof(cache->entries[0]) * cache->used);
1870 icd_free(cache->entries);
1871 }
1872
1873 cache->entries = entries;
1874 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001875 }
1876 }
1877
Chia-I Wua57761b2014-10-14 14:27:44 +08001878 /* add the shader to the cache */
1879 if (cache->used < cache->count) {
1880 cache->entries[cache->used].shader = (const void *) shader;
1881 cache->entries[cache->used].kernel_offset = offset;
1882 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001883 }
1884
Chia-I Wua57761b2014-10-14 14:27:44 +08001885 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001886}
1887
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001888static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001889{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001890 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001891
Chia-I Wu8370b402014-08-29 12:28:37 +08001892 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1893 cmd_wa_gen6_pre_depth_stall_write(cmd);
1894 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1895 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1896 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1897 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001898
1899 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001900 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001901 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001902
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001903 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001904 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001905 }
1906 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001907 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001908 }
1909 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001910 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1911 }
1912 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1913 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1914 }
1915 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1916 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001917 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001918
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001919 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1920 gen7_3DSTATE_GS(cmd);
1921 } else {
1922 gen6_3DSTATE_GS(cmd);
1923 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001924
Chia-I Wu8370b402014-08-29 12:28:37 +08001925 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1926 cmd_wa_gen7_post_command_cs_stall(cmd);
1927 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1928 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001929}
1930
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001931static void emit_bounded_states(struct intel_cmd *cmd)
1932{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001933
1934 emit_graphics_pipeline(cmd);
1935
1936 emit_rt(cmd);
1937 emit_ds(cmd);
1938
1939 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1940 gen7_cc_states(cmd);
1941 gen7_viewport_states(cmd);
1942
1943 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1944 &cmd->bind.pipeline.graphics->vs);
1945 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1946 &cmd->bind.pipeline.graphics->fs);
1947
1948 gen6_3DSTATE_CLIP(cmd);
1949 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001950 gen7_3DSTATE_WM(cmd);
1951 gen7_3DSTATE_PS(cmd);
1952 } else {
1953 gen6_cc_states(cmd);
1954 gen6_viewport_states(cmd);
1955
1956 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1957 &cmd->bind.pipeline.graphics->vs);
1958 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1959 &cmd->bind.pipeline.graphics->fs);
1960
1961 gen6_3DSTATE_CLIP(cmd);
1962 gen6_3DSTATE_SF(cmd);
1963 gen6_3DSTATE_WM(cmd);
1964 }
1965
1966 emit_shader_resources(cmd);
1967
1968 cmd_wa_gen6_pre_depth_stall_write(cmd);
1969 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1970
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001971 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1972 gen6_3DSTATE_VS(cmd);
1973}
1974
Tony Barbourfa6cac72015-01-16 14:27:35 -07001975static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
1976 const struct intel_cmd_meta *meta)
1977{
1978 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
1979 const uint8_t cmd_len = 3;
1980 uint32_t dw[3];
1981 uint32_t cmd_depth_stencil;
1982 uint32_t cmd_depth_test;
1983
1984 CMD_ASSERT(cmd, 6, 7.5);
1985
1986 cmd_depth_stencil = 0;
1987 cmd_depth_test = 0;
1988 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
1989 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
1990 GEN6_COMPAREFUNCTION_ALWAYS << 27;
1991 }
1992 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
1993 cmd_depth_stencil = 1 << 31 |
1994 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
1995 (GEN6_STENCILOP_KEEP) << 25 |
1996 (GEN6_STENCILOP_KEEP) << 22 |
1997 (GEN6_STENCILOP_REPLACE) << 19 |
1998 1 << 15 |
1999 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2000 (GEN6_STENCILOP_KEEP) << 9 |
2001 (GEN6_STENCILOP_KEEP) << 6 |
2002 (GEN6_STENCILOP_REPLACE) << 3;
2003 }
2004
2005 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2006 dw[0] = cmd_depth_stencil | 1 << 18;
2007 dw[1] = (0xff) << 24 | (0xff) << 16;
2008 dw[2] = cmd_depth_test;
2009
2010 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2011 cmd_align, cmd_len, dw);
2012}
2013
Chia-I Wu6032b892014-10-17 14:47:18 +08002014static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2015{
2016 const struct intel_cmd_meta *meta = cmd->bind.meta;
2017 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2018
2019 CMD_ASSERT(cmd, 6, 7.5);
2020
2021 blend_offset = 0;
2022 ds_offset = 0;
2023 cc_offset = 0;
2024 cc_vp_offset = 0;
2025
Chia-I Wu29e6f502014-11-24 14:27:29 +08002026 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002027 /* BLEND_STATE */
2028 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002029 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002030 dw[0] = 0;
2031 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2032 }
2033
Chia-I Wu29e6f502014-11-24 14:27:29 +08002034 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002035 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002036 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002037 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2038 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002039
Chia-I Wu29e6f502014-11-24 14:27:29 +08002040 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002041 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002042
Chia-I Wu29e6f502014-11-24 14:27:29 +08002043 /* COLOR_CALC_STATE */
2044 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002045 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002046
Chia-I Wu29e6f502014-11-24 14:27:29 +08002047 /* CC_VIEWPORT */
2048 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002049 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002050 dw[0] = u_fui(0.0f);
2051 dw[1] = u_fui(1.0f);
2052 } else {
2053 /* DEPTH_STENCIL_STATE */
2054 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002055 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002056 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2057 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2058 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002059 }
2060
2061 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2062 gen7_3dstate_pointer(cmd,
2063 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2064 blend_offset);
2065 gen7_3dstate_pointer(cmd,
2066 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2067 ds_offset);
2068 gen7_3dstate_pointer(cmd,
2069 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2070
2071 gen7_3dstate_pointer(cmd,
2072 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2073 cc_vp_offset);
2074 } else {
2075 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002076 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002077
2078 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2079 cmd_batch_pointer(cmd, 4, &dw);
2080 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2081 GEN6_PTR_VP_DW0_CC_CHANGED;
2082 dw[1] = 0;
2083 dw[2] = 0;
2084 dw[3] = cc_vp_offset;
2085 }
2086}
2087
2088static void gen6_meta_surface_states(struct intel_cmd *cmd)
2089{
2090 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002091 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002092 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002093 const uint32_t sba_offset =
2094 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002095
2096 CMD_ASSERT(cmd, 6, 7.5);
2097
Chia-I Wu29e6f502014-11-24 14:27:29 +08002098 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2099 return;
2100
Chia-I Wu005c47c2014-10-22 13:49:13 +08002101 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002102 if (meta->src.valid) {
2103 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002104 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002105 meta->src.surface_len, meta->src.surface);
2106
2107 cmd_reserve_reloc(cmd, 1);
2108 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2109 cmd_surface_reloc_writer(cmd, offset, 1,
2110 meta->src.reloc_target, meta->src.reloc_offset);
2111 } else {
2112 cmd_surface_reloc(cmd, offset, 1,
2113 (struct intel_bo *) meta->src.reloc_target,
2114 meta->src.reloc_offset, meta->src.reloc_flags);
2115 }
2116
Mike Stroyan9bfad482015-02-10 15:09:23 -07002117 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002118 }
2119 if (meta->dst.valid) {
2120 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002121 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002122 meta->dst.surface_len, meta->dst.surface);
2123
2124 cmd_reserve_reloc(cmd, 1);
2125 cmd_surface_reloc(cmd, offset, 1,
2126 (struct intel_bo *) meta->dst.reloc_target,
2127 meta->dst.reloc_offset, meta->dst.reloc_flags);
2128
Mike Stroyan9bfad482015-02-10 15:09:23 -07002129 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002130 }
2131
2132 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002133 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002134 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002135 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002136
2137 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002138 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2139 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2140 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002141 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002142 } else {
2143 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002144 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002145 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002146 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002147 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002148 }
2149}
2150
2151static void gen6_meta_urb(struct intel_cmd *cmd)
2152{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002153 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002154 uint32_t *dw;
2155
2156 CMD_ASSERT(cmd, 6, 6);
2157
2158 /* 3DSTATE_URB */
2159 cmd_batch_pointer(cmd, 3, &dw);
2160 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002161 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002162 dw[2] = 0;
2163}
2164
2165static void gen7_meta_urb(struct intel_cmd *cmd)
2166{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002167 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2168 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002169 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002170 uint32_t *dw;
2171
2172 CMD_ASSERT(cmd, 7, 7.5);
2173
2174 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2175 cmd_batch_pointer(cmd, 10, &dw);
2176
2177 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002178 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
2179 dw += 2;
2180
2181 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2182 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
2183 pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002184 dw += 2;
2185
2186 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2187 dw[1] = 0;
2188 dw += 2;
2189
2190 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2191 dw[1] = 0;
2192 dw += 2;
2193
2194 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2195 dw[1] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002196
Chia-I Wu15dacac2015-02-05 11:14:01 -07002197 cmd_wa_gen7_post_command_cs_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002198
2199 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2200
Chia-I Wu24aa1022014-11-25 11:53:19 +08002201 switch (cmd_gen(cmd)) {
2202 case INTEL_GEN(7.5):
2203 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2204 break;
2205 case INTEL_GEN(7):
2206 default:
2207 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2208 break;
2209 }
2210
Chia-I Wu6032b892014-10-17 14:47:18 +08002211 /* 3DSTATE_URB_x */
2212 cmd_batch_pointer(cmd, 8, &dw);
2213
2214 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002215 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002216 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002217 dw += 2;
2218
2219 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002220 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002221 dw += 2;
2222
2223 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002224 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002225 dw += 2;
2226
2227 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002228 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002229 dw += 2;
2230}
2231
2232static void gen6_meta_vf(struct intel_cmd *cmd)
2233{
2234 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002235 uint32_t vb_start, vb_end, vb_stride;
2236 int ve_format, ve_z_source;
2237 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002238 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002239
2240 CMD_ASSERT(cmd, 6, 7.5);
2241
Chia-I Wu29e6f502014-11-24 14:27:29 +08002242 switch (meta->mode) {
2243 case INTEL_CMD_META_VS_POINTS:
2244 cmd_batch_pointer(cmd, 3, &dw);
2245 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2246 dw[1] = GEN6_VE_STATE_DW0_VALID;
2247 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2248 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2249 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2250 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2251 return;
2252 break;
2253 case INTEL_CMD_META_FS_RECT:
2254 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002255 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002256
Chia-I Wu29e6f502014-11-24 14:27:29 +08002257 vertices[0][0] = meta->dst.x + meta->width;
2258 vertices[0][1] = meta->dst.y + meta->height;
2259 vertices[1][0] = meta->dst.x;
2260 vertices[1][1] = meta->dst.y + meta->height;
2261 vertices[2][0] = meta->dst.x;
2262 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002263
Chia-I Wu29e6f502014-11-24 14:27:29 +08002264 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2265 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002266
Chia-I Wu29e6f502014-11-24 14:27:29 +08002267 vb_end = vb_start + sizeof(vertices) - 1;
2268 vb_stride = sizeof(vertices[0]);
2269 ve_z_source = GEN6_VFCOMP_STORE_0;
2270 ve_format = GEN6_FORMAT_R32G32_USCALED;
2271 }
2272 break;
2273 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2274 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002275 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002276
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002277 vertices[0][0] = (float) (meta->dst.x + meta->width);
2278 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002279 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002280 vertices[1][0] = (float) meta->dst.x;
2281 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002282 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002283 vertices[2][0] = (float) meta->dst.x;
2284 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002285 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002286
Chia-I Wu29e6f502014-11-24 14:27:29 +08002287 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2288 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002289
Chia-I Wu29e6f502014-11-24 14:27:29 +08002290 vb_end = vb_start + sizeof(vertices) - 1;
2291 vb_stride = sizeof(vertices[0]);
2292 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2293 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2294 }
2295 break;
2296 default:
2297 assert(!"unknown meta mode");
2298 return;
2299 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002300 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002301
2302 /* 3DSTATE_VERTEX_BUFFERS */
2303 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002304
Chia-I Wu6032b892014-10-17 14:47:18 +08002305 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002306 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002307 if (cmd_gen(cmd) >= INTEL_GEN(7))
2308 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2309
2310 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002311 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2312 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002313
2314 dw[4] = 0;
2315
2316 /* 3DSTATE_VERTEX_ELEMENTS */
2317 cmd_batch_pointer(cmd, 5, &dw);
2318 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002319 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002320 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2321 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2322 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2323 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2324 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002325 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002326 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2327 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002328 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002329 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2330}
2331
Chia-I Wu29e6f502014-11-24 14:27:29 +08002332static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002333{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002334 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002335 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002336 uint32_t consts[8];
2337 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002338
2339 CMD_ASSERT(cmd, 6, 7.5);
2340
2341 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002342 case INTEL_DEV_META_VS_FILL_MEM:
2343 consts[0] = meta->dst.x;
2344 consts[1] = meta->clear_val[0];
2345 const_count = 2;
2346 break;
2347 case INTEL_DEV_META_VS_COPY_MEM:
2348 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2349 consts[0] = meta->dst.x;
2350 consts[1] = meta->src.x;
2351 const_count = 2;
2352 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002353 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2354 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2355 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2356 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2357 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2358 consts[0] = meta->src.x;
2359 consts[1] = meta->src.y;
2360 consts[2] = meta->width;
2361 consts[3] = meta->dst.x;
2362 const_count = 4;
2363 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002364 default:
2365 assert(!"unknown meta shader id");
2366 const_count = 0;
2367 break;
2368 }
2369
2370 /* this can be skipped but it makes state dumping prettier */
2371 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2372
2373 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2374}
2375
2376static void gen6_meta_vs(struct intel_cmd *cmd)
2377{
2378 const struct intel_cmd_meta *meta = cmd->bind.meta;
2379 const struct intel_pipeline_shader *sh =
2380 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2381 uint32_t offset, *dw;
2382
2383 CMD_ASSERT(cmd, 6, 7.5);
2384
2385 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002386 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002387
2388 /* 3DSTATE_CONSTANT_VS */
2389 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2390 cmd_batch_pointer(cmd, cmd_len, &dw);
2391 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2392 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2393
2394 /* 3DSTATE_VS */
2395 cmd_batch_pointer(cmd, 6, &dw);
2396 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2397 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2398
2399 return;
2400 }
2401
2402 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2403
2404 /* 3DSTATE_CONSTANT_VS */
2405 offset = gen6_meta_vs_constants(cmd);
2406 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2407 cmd_batch_pointer(cmd, 7, &dw);
2408 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2409 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2410 dw[2] = 0;
2411 dw[3] = offset;
2412 dw[4] = 0;
2413 dw[5] = 0;
2414 dw[6] = 0;
2415 } else {
2416 cmd_batch_pointer(cmd, 5, &dw);
2417 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2418 GEN6_PCB_ANY_DW0_PCB0_VALID;
2419 dw[1] = offset;
2420 dw[2] = 0;
2421 dw[3] = 0;
2422 dw[4] = 0;
2423 }
2424
2425 /* 3DSTATE_VS */
2426 offset = emit_shader(cmd, sh);
2427 cmd_batch_pointer(cmd, 6, &dw);
2428 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2429 dw[1] = offset;
2430 dw[2] = GEN6_THREADDISP_SPF |
2431 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2432 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002433 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002434 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2435 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2436
2437 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2438 GEN6_VS_DW5_VS_ENABLE;
2439 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002440 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002441 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002442 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002443
2444 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002445}
2446
2447static void gen6_meta_disabled(struct intel_cmd *cmd)
2448{
Chia-I Wu6032b892014-10-17 14:47:18 +08002449 uint32_t *dw;
2450
2451 CMD_ASSERT(cmd, 6, 6);
2452
Chia-I Wu6032b892014-10-17 14:47:18 +08002453 /* 3DSTATE_CONSTANT_GS */
2454 cmd_batch_pointer(cmd, 5, &dw);
2455 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2456 dw[1] = 0;
2457 dw[2] = 0;
2458 dw[3] = 0;
2459 dw[4] = 0;
2460
2461 /* 3DSTATE_GS */
2462 cmd_batch_pointer(cmd, 7, &dw);
2463 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2464 dw[1] = 0;
2465 dw[2] = 0;
2466 dw[3] = 0;
2467 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2468 dw[5] = GEN6_GS_DW5_STATISTICS;
2469 dw[6] = 0;
2470
Chia-I Wu6032b892014-10-17 14:47:18 +08002471 /* 3DSTATE_SF */
2472 cmd_batch_pointer(cmd, 20, &dw);
2473 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2474 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2475 memset(&dw[2], 0, 18 * sizeof(*dw));
2476}
2477
2478static void gen7_meta_disabled(struct intel_cmd *cmd)
2479{
2480 uint32_t *dw;
2481
2482 CMD_ASSERT(cmd, 7, 7.5);
2483
Chia-I Wu6032b892014-10-17 14:47:18 +08002484 /* 3DSTATE_CONSTANT_HS */
2485 cmd_batch_pointer(cmd, 7, &dw);
2486 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2487 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2488
2489 /* 3DSTATE_HS */
2490 cmd_batch_pointer(cmd, 7, &dw);
2491 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2492 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2493
2494 /* 3DSTATE_TE */
2495 cmd_batch_pointer(cmd, 4, &dw);
2496 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2497 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2498
2499 /* 3DSTATE_CONSTANT_DS */
2500 cmd_batch_pointer(cmd, 7, &dw);
2501 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2502 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2503
2504 /* 3DSTATE_DS */
2505 cmd_batch_pointer(cmd, 6, &dw);
2506 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2507 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2508
2509 /* 3DSTATE_CONSTANT_GS */
2510 cmd_batch_pointer(cmd, 7, &dw);
2511 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2512 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2513
2514 /* 3DSTATE_GS */
2515 cmd_batch_pointer(cmd, 7, &dw);
2516 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2517 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2518
2519 /* 3DSTATE_STREAMOUT */
2520 cmd_batch_pointer(cmd, 3, &dw);
2521 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2522 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2523
Chia-I Wu6032b892014-10-17 14:47:18 +08002524 /* 3DSTATE_SF */
2525 cmd_batch_pointer(cmd, 7, &dw);
2526 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2527 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2528
2529 /* 3DSTATE_SBE */
2530 cmd_batch_pointer(cmd, 14, &dw);
2531 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2532 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2533 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002534}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002535
Chia-I Wu29e6f502014-11-24 14:27:29 +08002536static void gen6_meta_clip(struct intel_cmd *cmd)
2537{
2538 const struct intel_cmd_meta *meta = cmd->bind.meta;
2539 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002540
Chia-I Wu29e6f502014-11-24 14:27:29 +08002541 /* 3DSTATE_CLIP */
2542 cmd_batch_pointer(cmd, 4, &dw);
2543 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2544 dw[1] = 0;
2545 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2546 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2547 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2548 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002549 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002550 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002551 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002552}
2553
2554static void gen6_meta_wm(struct intel_cmd *cmd)
2555{
2556 const struct intel_cmd_meta *meta = cmd->bind.meta;
2557 uint32_t *dw;
2558
2559 CMD_ASSERT(cmd, 6, 7.5);
2560
2561 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2562
2563 /* 3DSTATE_MULTISAMPLE */
2564 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2565 cmd_batch_pointer(cmd, 4, &dw);
2566 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2567 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2568 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2569 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2570 dw[2] = 0;
2571 dw[3] = 0;
2572 } else {
2573 cmd_batch_pointer(cmd, 3, &dw);
2574 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2575 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2576 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2577 dw[2] = 0;
2578 }
2579
2580 /* 3DSTATE_SAMPLE_MASK */
2581 cmd_batch_pointer(cmd, 2, &dw);
2582 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2583 dw[1] = (1 << meta->samples) - 1;
2584
2585 /* 3DSTATE_DRAWING_RECTANGLE */
2586 cmd_batch_pointer(cmd, 4, &dw);
2587 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002588 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2589 /* unused */
2590 dw[1] = 0;
2591 dw[2] = 0;
2592 } else {
2593 dw[1] = meta->dst.y << 16 | meta->dst.x;
2594 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2595 (meta->dst.x + meta->width - 1);
2596 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002597 dw[3] = 0;
2598}
2599
2600static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2601{
2602 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002603 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002604 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002605 uint32_t consts[8];
2606 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002607
2608 CMD_ASSERT(cmd, 6, 7.5);
2609
2610 /* underflow is fine here */
2611 offset_x = meta->src.x - meta->dst.x;
2612 offset_y = meta->src.y - meta->dst.y;
2613
2614 switch (meta->shader_id) {
2615 case INTEL_DEV_META_FS_COPY_MEM:
2616 case INTEL_DEV_META_FS_COPY_1D:
2617 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2618 case INTEL_DEV_META_FS_COPY_2D:
2619 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2620 case INTEL_DEV_META_FS_COPY_2D_MS:
2621 consts[0] = offset_x;
2622 consts[1] = offset_y;
2623 consts[2] = meta->src.layer;
2624 consts[3] = meta->src.lod;
2625 const_count = 4;
2626 break;
2627 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2628 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2629 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2630 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2631 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2632 consts[0] = offset_x;
2633 consts[1] = offset_y;
2634 consts[2] = meta->src.layer;
2635 consts[3] = meta->src.lod;
2636 consts[4] = meta->src.x;
2637 consts[5] = meta->width;
2638 const_count = 6;
2639 break;
2640 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2641 consts[0] = offset_x;
2642 consts[1] = offset_y;
2643 consts[2] = meta->width;
2644 const_count = 3;
2645 break;
2646 case INTEL_DEV_META_FS_CLEAR_COLOR:
2647 consts[0] = meta->clear_val[0];
2648 consts[1] = meta->clear_val[1];
2649 consts[2] = meta->clear_val[2];
2650 consts[3] = meta->clear_val[3];
2651 const_count = 4;
2652 break;
2653 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2654 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002655 consts[1] = meta->clear_val[1];
2656 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002657 break;
2658 case INTEL_DEV_META_FS_RESOLVE_2X:
2659 case INTEL_DEV_META_FS_RESOLVE_4X:
2660 case INTEL_DEV_META_FS_RESOLVE_8X:
2661 case INTEL_DEV_META_FS_RESOLVE_16X:
2662 consts[0] = offset_x;
2663 consts[1] = offset_y;
2664 const_count = 2;
2665 break;
2666 default:
2667 assert(!"unknown meta shader id");
2668 const_count = 0;
2669 break;
2670 }
2671
2672 /* this can be skipped but it makes state dumping prettier */
2673 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2674
2675 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2676}
2677
2678static void gen6_meta_ps(struct intel_cmd *cmd)
2679{
2680 const struct intel_cmd_meta *meta = cmd->bind.meta;
2681 const struct intel_pipeline_shader *sh =
2682 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2683 uint32_t offset, *dw;
2684
2685 CMD_ASSERT(cmd, 6, 6);
2686
Chia-I Wu29e6f502014-11-24 14:27:29 +08002687 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2688 /* 3DSTATE_CONSTANT_PS */
2689 cmd_batch_pointer(cmd, 5, &dw);
2690 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2691 dw[1] = 0;
2692 dw[2] = 0;
2693 dw[3] = 0;
2694 dw[4] = 0;
2695
2696 /* 3DSTATE_WM */
2697 cmd_batch_pointer(cmd, 9, &dw);
2698 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2699 dw[1] = 0;
2700 dw[2] = 0;
2701 dw[3] = 0;
2702 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002703 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002704 dw[6] = 0;
2705 dw[7] = 0;
2706 dw[8] = 0;
2707
Chia-I Wu3adf7212014-10-24 15:34:07 +08002708 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002709 }
2710
Chia-I Wu3adf7212014-10-24 15:34:07 +08002711 /* a normal color write */
2712 assert(meta->dst.valid && !sh->uses);
2713
Chia-I Wu6032b892014-10-17 14:47:18 +08002714 /* 3DSTATE_CONSTANT_PS */
2715 offset = gen6_meta_ps_constants(cmd);
2716 cmd_batch_pointer(cmd, 5, &dw);
2717 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2718 GEN6_PCB_ANY_DW0_PCB0_VALID;
2719 dw[1] = offset;
2720 dw[2] = 0;
2721 dw[3] = 0;
2722 dw[4] = 0;
2723
2724 /* 3DSTATE_WM */
2725 offset = emit_shader(cmd, sh);
2726 cmd_batch_pointer(cmd, 9, &dw);
2727 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2728 dw[1] = offset;
2729 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2730 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002731 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002732 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002733 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002734 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002735 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2736
Chia-I Wu6032b892014-10-17 14:47:18 +08002737 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2738 GEN6_WM_DW6_POSOFFSET_NONE |
2739 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2740 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2741 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2742 if (meta->samples > 1) {
2743 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2744 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2745 } else {
2746 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2747 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2748 }
2749 dw[7] = 0;
2750 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002751
2752 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002753}
2754
2755static void gen7_meta_ps(struct intel_cmd *cmd)
2756{
2757 const struct intel_cmd_meta *meta = cmd->bind.meta;
2758 const struct intel_pipeline_shader *sh =
2759 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2760 uint32_t offset, *dw;
2761
2762 CMD_ASSERT(cmd, 7, 7.5);
2763
Chia-I Wu29e6f502014-11-24 14:27:29 +08002764 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2765 /* 3DSTATE_WM */
2766 cmd_batch_pointer(cmd, 3, &dw);
2767 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2768 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2769
2770 /* 3DSTATE_CONSTANT_GS */
2771 cmd_batch_pointer(cmd, 7, &dw);
2772 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2773 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2774
2775 /* 3DSTATE_PS */
2776 cmd_batch_pointer(cmd, 8, &dw);
2777 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2778 dw[1] = 0;
2779 dw[2] = 0;
2780 dw[3] = 0;
2781 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002782 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002783 dw[5] = 0;
2784 dw[6] = 0;
2785 dw[7] = 0;
2786
Chia-I Wu3adf7212014-10-24 15:34:07 +08002787 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002788 }
2789
Chia-I Wu3adf7212014-10-24 15:34:07 +08002790 /* a normal color write */
2791 assert(meta->dst.valid && !sh->uses);
2792
Chia-I Wu6032b892014-10-17 14:47:18 +08002793 /* 3DSTATE_WM */
2794 cmd_batch_pointer(cmd, 3, &dw);
2795 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2796 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2797 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2798 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2799 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2800 dw[2] = 0;
2801
2802 /* 3DSTATE_CONSTANT_PS */
2803 offset = gen6_meta_ps_constants(cmd);
2804 cmd_batch_pointer(cmd, 7, &dw);
2805 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2806 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2807 dw[2] = 0;
2808 dw[3] = offset;
2809 dw[4] = 0;
2810 dw[5] = 0;
2811 dw[6] = 0;
2812
2813 /* 3DSTATE_PS */
2814 offset = emit_shader(cmd, sh);
2815 cmd_batch_pointer(cmd, 8, &dw);
2816 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2817 dw[1] = offset;
2818 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2819 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002820 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002821
2822 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2823 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002824 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2825
2826 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002827 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002828 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002829 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002830 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002831 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002832
2833 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2834 dw[6] = 0;
2835 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002836
2837 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002838}
2839
2840static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2841{
2842 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002843 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002844
2845 CMD_ASSERT(cmd, 6, 7.5);
2846
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002847 if (!ds) {
2848 /* all zeros */
2849 static const struct intel_ds_view null_ds;
2850 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002851 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002852
2853 cmd_wa_gen6_pre_ds_flush(cmd);
2854 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2855 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2856 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2857
2858 if (cmd_gen(cmd) >= INTEL_GEN(7))
2859 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2860 else
2861 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002862}
2863
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002864static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2865 const struct intel_pipeline *pipeline)
2866{
2867 cmd->bind.pipeline.graphics = pipeline;
2868}
2869
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002870static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2871 const struct intel_pipeline *pipeline)
2872{
2873 cmd->bind.pipeline.compute = pipeline;
2874}
2875
2876static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2877 const struct intel_pipeline_delta *delta)
2878{
2879 cmd->bind.pipeline.graphics_delta = delta;
2880}
2881
2882static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2883 const struct intel_pipeline_delta *delta)
2884{
2885 cmd->bind.pipeline.compute_delta = delta;
2886}
2887
2888static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002889 const struct intel_desc_set *dset,
2890 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002891{
Chia-I Wuf8385062015-01-04 16:27:24 +08002892 const uint32_t size = sizeof(*dynamic_offsets) *
2893 dset->layout->dynamic_desc_count;
2894
2895 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2896 if (cmd->bind.dset.graphics_dynamic_offsets)
2897 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2898
2899 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2900 4, XGL_SYSTEM_ALLOC_INTERNAL);
2901 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002902 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002903 return;
2904 }
2905
2906 cmd->bind.dset.graphics_dynamic_offset_size = size;
2907 }
2908
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002909 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002910 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002911}
2912
2913static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002914 const struct intel_desc_set *dset,
2915 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002916{
Chia-I Wuf8385062015-01-04 16:27:24 +08002917 const uint32_t size = sizeof(*dynamic_offsets) *
2918 dset->layout->dynamic_desc_count;
2919
2920 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2921 if (cmd->bind.dset.compute_dynamic_offsets)
2922 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2923
2924 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2925 4, XGL_SYSTEM_ALLOC_INTERNAL);
2926 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002927 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002928 return;
2929 }
2930
2931 cmd->bind.dset.compute_dynamic_offset_size = size;
2932 }
2933
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002934 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002935 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002936}
2937
Chia-I Wu3b04af52014-11-08 10:48:20 +08002938static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002939 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002940 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08002941{
Chia-I Wu714df452015-01-01 07:55:04 +08002942 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002943 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08002944 return;
2945 }
2946
Chia-I Wu714df452015-01-01 07:55:04 +08002947 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002948 cmd->bind.vertex.offset[binding] = offset;
2949}
2950
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002951static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002952 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002953 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2954{
Chia-I Wu714df452015-01-01 07:55:04 +08002955 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002956 cmd->bind.index.offset = offset;
2957 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002958}
2959
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002960static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002961 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002962{
2963 cmd->bind.state.viewport = state;
2964}
2965
2966static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002967 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002968{
2969 cmd->bind.state.raster = state;
2970}
2971
2972static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002973 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002974{
2975 cmd->bind.state.ds = state;
2976}
2977
2978static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002979 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002980{
2981 cmd->bind.state.blend = state;
2982}
2983
Chia-I Wuf98dd882015-02-10 04:17:47 +08002984static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
2985{
2986 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
2987 struct intel_pipeline_rmap *rmaps[5] = {
2988 pipeline->vs.rmap,
2989 pipeline->tcs.rmap,
2990 pipeline->tes.rmap,
2991 pipeline->gs.rmap,
2992 pipeline->fs.rmap,
2993 };
2994 uint32_t max_write;
2995 int i;
2996
2997 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
2998 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
2999 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3000
3001 /* pad first */
3002 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3003
3004 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3005 const struct intel_pipeline_rmap *rmap = rmaps[i];
3006 const uint32_t surface_count = (rmap) ?
3007 rmap->rt_count + rmap->texture_resource_count +
3008 rmap->resource_count + rmap->uav_count : 0;
3009
3010 if (surface_count) {
3011 /* SURFACE_STATEs */
3012 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3013
3014 /* BINDING_TABLE_STATE */
3015 max_write += u_align(sizeof(uint32_t) * surface_count,
3016 GEN6_ALIGNMENT_SURFACE_STATE);
3017 }
3018 }
3019
3020 return max_write;
3021}
3022
3023static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3024{
3025 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3026 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3027 uint32_t max_surface_write;
3028
3029 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3030 if (cmd->bind.meta)
3031 max_surface_write = 64 * sizeof(uint32_t);
3032 else
3033 max_surface_write = cmd_get_max_surface_write(cmd);
3034
3035 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3036 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3037 /* SBA expects page-aligned addresses */
3038 writer->sba_offset = writer->used & ~0xfff;
3039
3040 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3041
3042 cmd_batch_state_base_address(cmd);
3043 }
3044}
3045
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003046static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003047 uint32_t vertex_start,
3048 uint32_t vertex_count,
3049 uint32_t instance_start,
3050 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003051 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003052 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003053{
3054 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003055 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003056 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3057
3058 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003059
3060 emit_bounded_states(cmd);
3061
Chia-I Wuf98dd882015-02-10 04:17:47 +08003062 /* sanity check on cmd_get_max_surface_write() */
3063 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3064 surface_writer_used <= cmd_get_max_surface_write(cmd));
3065
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003066 if (indexed) {
3067 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003068 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003069
3070 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3071 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3072 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003073 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003074 cmd->bind.index.offset, cmd->bind.index.type,
3075 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003076 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003077 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003078 cmd->bind.index.offset, cmd->bind.index.type,
3079 p->primitive_restart);
3080 }
3081 } else {
3082 assert(!vertex_base);
3083 }
3084
3085 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3086 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3087 vertex_start, instance_count, instance_start, vertex_base);
3088 } else {
3089 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3090 vertex_start, instance_count, instance_start, vertex_base);
3091 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003092
Chia-I Wu707a29e2014-08-27 12:51:47 +08003093 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003094 /* need to re-emit all workarounds */
3095 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003096
3097 if (intel_debug & INTEL_DEBUG_NOCACHE)
3098 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003099}
3100
Chia-I Wuc14d1562014-10-17 09:49:22 +08003101void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3102{
Chia-I Wu6032b892014-10-17 14:47:18 +08003103 cmd->bind.meta = meta;
3104
Chia-I Wuf98dd882015-02-10 04:17:47 +08003105 cmd_adjust_state_base_address(cmd);
3106
Chia-I Wu6032b892014-10-17 14:47:18 +08003107 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003108 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003109
3110 gen6_meta_dynamic_states(cmd);
3111 gen6_meta_surface_states(cmd);
3112
3113 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3114 gen7_meta_urb(cmd);
3115 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003116 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003117 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003118 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003119 gen6_meta_wm(cmd);
3120 gen7_meta_ps(cmd);
3121 gen6_meta_depth_buffer(cmd);
3122
3123 cmd_wa_gen7_post_command_cs_stall(cmd);
3124 cmd_wa_gen7_post_command_depth_stall(cmd);
3125
Chia-I Wu29e6f502014-11-24 14:27:29 +08003126 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3127 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003128 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003129 } else {
3130 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3131 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003132 } else {
3133 gen6_meta_urb(cmd);
3134 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003135 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003136 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003137 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003138 gen6_meta_wm(cmd);
3139 gen6_meta_ps(cmd);
3140 gen6_meta_depth_buffer(cmd);
3141
Chia-I Wu29e6f502014-11-24 14:27:29 +08003142 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3143 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003144 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003145 } else {
3146 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3147 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003148 }
3149
3150 cmd->bind.draw_count++;
3151 /* need to re-emit all workarounds */
3152 cmd->bind.wa_flags = 0;
3153
3154 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003155
3156 if (intel_debug & INTEL_DEBUG_NOCACHE)
3157 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003158}
3159
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003160ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003161 XGL_CMD_BUFFER cmdBuffer,
3162 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3163 XGL_PIPELINE pipeline)
3164{
3165 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3166
3167 switch (pipelineBindPoint) {
3168 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003169 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003170 break;
3171 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003172 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003173 break;
3174 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003175 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003176 break;
3177 }
3178}
3179
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003180ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003181 XGL_CMD_BUFFER cmdBuffer,
3182 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3183 XGL_PIPELINE_DELTA delta)
3184{
3185 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3186
3187 switch (pipelineBindPoint) {
3188 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003189 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003190 break;
3191 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003192 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003193 break;
3194 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003195 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003196 break;
3197 }
3198}
3199
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003200ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003201 XGL_CMD_BUFFER cmdBuffer,
3202 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003203 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003204{
3205 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3206
3207 switch (stateBindPoint) {
3208 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003209 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003210 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003211 break;
3212 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003213 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003214 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003215 break;
3216 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003217 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003218 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003219 break;
3220 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003221 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003222 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003223 break;
3224 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003225 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003226 break;
3227 }
3228}
3229
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003230ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003231 XGL_CMD_BUFFER cmdBuffer,
3232 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003233 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003234 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003235{
3236 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003237 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003238
3239 switch (pipelineBindPoint) {
3240 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003241 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003242 break;
3243 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003244 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003245 break;
3246 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003247 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003248 break;
3249 }
3250}
3251
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003252ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003253 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003254 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003255 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003256 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003257{
3258 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003259 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003260
Chia-I Wu714df452015-01-01 07:55:04 +08003261 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003262}
3263
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003264ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003265 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003266 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003267 XGL_GPU_SIZE offset,
3268 XGL_INDEX_TYPE indexType)
3269{
3270 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003271 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003272
Chia-I Wu714df452015-01-01 07:55:04 +08003273 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003274}
3275
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003276ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003277 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003278 uint32_t firstVertex,
3279 uint32_t vertexCount,
3280 uint32_t firstInstance,
3281 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003282{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003283 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003284
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003285 cmd_draw(cmd, firstVertex, vertexCount,
3286 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003287}
3288
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003289ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003290 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003291 uint32_t firstIndex,
3292 uint32_t indexCount,
3293 int32_t vertexOffset,
3294 uint32_t firstInstance,
3295 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003296{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003297 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003298
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003299 cmd_draw(cmd, firstIndex, indexCount,
3300 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003301}
3302
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003303ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003304 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003305 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003306 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003307 uint32_t count,
3308 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003309{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003310 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3311
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003312 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003313}
3314
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003315ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003316 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003317 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003318 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003319 uint32_t count,
3320 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003321{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003322 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3323
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003324 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003325}
3326
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003327ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003328 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003329 uint32_t x,
3330 uint32_t y,
3331 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003332{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003333 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3334
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003335 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003336}
3337
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003338ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003339 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003340 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003341 XGL_GPU_SIZE offset)
3342{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003343 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3344
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003345 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003346}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003347
Chia-I Wude26bdf2015-02-18 15:47:12 -07003348ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003349 XGL_CMD_BUFFER cmdBuffer,
3350 XGL_RENDER_PASS renderPass)
3351{
3352 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3353
3354 cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
3355}
3356
Chia-I Wude26bdf2015-02-18 15:47:12 -07003357ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003358 XGL_CMD_BUFFER cmdBuffer,
3359 XGL_RENDER_PASS renderPass)
3360{
3361 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3362
3363 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3364}