blob: 6a5e6a48fa49b08bda8d2a9c22ba6069bcce22c0 [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;
Cody Northrope86574e2015-02-24 14:15:29 -0700559 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *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 |
Cody Northrope86574e2015-02-24 14:15:29 -0700571 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572
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
Cody Northrope86574e2015-02-24 14:15:29 -0700577 if (fs->offset_16)
578 dw5 |= GEN6_WM_DW5_16_PIXEL_DISPATCH;
579
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800580 if (fs->uses & INTEL_SHADER_USE_KILL ||
581 pipeline->cb_state.alphaToCoverageEnable)
582 dw5 |= GEN6_WM_DW5_PS_KILL;
583
Cody Northrope238deb2015-01-26 14:41:36 -0700584 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800585 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
586 if (fs->uses & INTEL_SHADER_USE_DEPTH)
587 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
588 if (fs->uses & INTEL_SHADER_USE_W)
589 dw5 |= GEN6_WM_DW5_PS_USE_W;
590
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700591 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800592 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
593
594 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
595 GEN6_WM_DW6_POSOFFSET_NONE |
596 GEN6_WM_DW6_ZW_INTERP_PIXEL |
597 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
598 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
599
Tony Barbourfa6cac72015-01-16 14:27:35 -0700600 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800601 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
602 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
603 } else {
604 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
605 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
606 }
607
Cody Northrope86574e2015-02-24 14:15:29 -0700608 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
609
Chia-I Wu784d3042014-12-19 14:30:04 +0800610 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800611 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800612 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800613 dw[2] = dw2;
614 dw[3] = 0; /* scratch */
615 dw[4] = dw4;
616 dw[5] = dw5;
617 dw[6] = dw6;
618 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700619 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800620
621 if (fs->per_thread_scratch_size)
622 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800623}
624
625static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
626{
627 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800628 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800629 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800630 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800631
632 CMD_ASSERT(cmd, 7, 7.5);
633
634 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
635
636 dw1 = GEN7_WM_DW1_STATISTICS |
637 GEN7_WM_DW1_PS_ENABLE |
638 GEN7_WM_DW1_ZW_INTERP_PIXEL |
639 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
640 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
641
642 if (fs->uses & INTEL_SHADER_USE_KILL ||
643 pipeline->cb_state.alphaToCoverageEnable)
644 dw1 |= GEN7_WM_DW1_PS_KILL;
645
Cody Northrope238deb2015-01-26 14:41:36 -0700646 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
647
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800648 if (fs->uses & INTEL_SHADER_USE_DEPTH)
649 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
650 if (fs->uses & INTEL_SHADER_USE_W)
651 dw1 |= GEN7_WM_DW1_PS_USE_W;
652
653 dw2 = 0;
654
Tony Barbourfa6cac72015-01-16 14:27:35 -0700655 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800656 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
657 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
658 } else {
659 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
660 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
661 }
662
Chia-I Wu72292b72014-09-09 10:48:33 +0800663 cmd_batch_pointer(cmd, cmd_len, &dw);
664 dw[0] = dw0;
665 dw[1] = dw1;
666 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667}
668
669static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
670{
671 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800672 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800673 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700674 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600675 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676
677 CMD_ASSERT(cmd, 7, 7.5);
678
679 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
680
681 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
682 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
683
684 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
685 GEN7_PS_DW4_8_PIXEL_DISPATCH;
686
Cody Northrope86574e2015-02-24 14:15:29 -0700687 if (fs->offset_16)
688 dw4 |= GEN7_PS_DW4_16_PIXEL_DISPATCH;
689
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800690 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800691 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700692 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800694 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800695 }
696
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697 if (fs->in_count)
698 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
699
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700700 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800701 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
702
703 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
704 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700705 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
706
707 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800708
Chia-I Wu784d3042014-12-19 14:30:04 +0800709 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800710 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800711 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800712 dw[2] = dw2;
713 dw[3] = 0; /* scratch */
714 dw[4] = dw4;
715 dw[5] = dw5;
716 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700717 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800718
719 if (fs->per_thread_scratch_size)
720 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800721}
722
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800723static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700724 const struct intel_ds_view *view,
725 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800726{
727 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800728 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600729 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800730
731 CMD_ASSERT(cmd, 6, 7.5);
732
733 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800734 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
735 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800736 dw0 |= (cmd_len - 2);
737
Chia-I Wu72292b72014-09-09 10:48:33 +0800738 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
739 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700740
Chia-I Wu72292b72014-09-09 10:48:33 +0800741 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700742 /* note that we only enable HiZ on Gen7+ */
743 if (!optimal_ds)
744 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
745
Chia-I Wu72292b72014-09-09 10:48:33 +0800746 dw[2] = 0;
747 dw[3] = view->cmd[2];
748 dw[4] = view->cmd[3];
749 dw[5] = view->cmd[4];
750 dw[6] = view->cmd[5];
751
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600752 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800753 cmd_reserve_reloc(cmd, 1);
754 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
755 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600756 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800757}
758
759static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700760 const struct intel_ds_view *view,
761 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800762{
763 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800764 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600765 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800766
767 CMD_ASSERT(cmd, 6, 7.5);
768
769 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800770 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
771 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800772 dw0 |= (cmd_len - 2);
773
Chia-I Wu72292b72014-09-09 10:48:33 +0800774 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
775 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800776
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700777 if (view->has_stencil) {
778 dw[1] = view->cmd[6];
779
Chia-I Wu72292b72014-09-09 10:48:33 +0800780 cmd_reserve_reloc(cmd, 1);
781 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
782 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700783 } else {
784 dw[1] = 0;
785 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600786 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800787}
788
789static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700790 const struct intel_ds_view *view,
791 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800792{
793 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800794 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600795 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800796
797 CMD_ASSERT(cmd, 6, 7.5);
798
799 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800800 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
801 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800802 dw0 |= (cmd_len - 2);
803
Chia-I Wu72292b72014-09-09 10:48:33 +0800804 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
805 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800806
Chia-I Wu73520ac2015-02-19 11:17:45 -0700807 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700808 dw[1] = view->cmd[8];
809
Chia-I Wu72292b72014-09-09 10:48:33 +0800810 cmd_reserve_reloc(cmd, 1);
811 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
812 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700813 } else {
814 dw[1] = 0;
815 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600816 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800817}
818
Chia-I Wuf8231032014-08-25 10:44:45 +0800819static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
820 uint32_t clear_val)
821{
822 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800823 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800824 GEN6_CLEAR_PARAMS_DW0_VALID |
825 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800826 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800827
828 CMD_ASSERT(cmd, 6, 6);
829
Chia-I Wu72292b72014-09-09 10:48:33 +0800830 cmd_batch_pointer(cmd, cmd_len, &dw);
831 dw[0] = dw0;
832 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800833}
834
835static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
836 uint32_t clear_val)
837{
838 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800839 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800840 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800841 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800842
843 CMD_ASSERT(cmd, 7, 7.5);
844
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 cmd_batch_pointer(cmd, cmd_len, &dw);
846 dw[0] = dw0;
847 dw[1] = clear_val;
848 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800849}
850
Chia-I Wu302742d2014-08-22 10:28:29 +0800851static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800852 uint32_t blend_offset,
853 uint32_t ds_offset,
854 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800855{
856 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800858
859 CMD_ASSERT(cmd, 6, 6);
860
Chia-I Wu426072d2014-08-26 14:31:55 +0800861 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800862 (cmd_len - 2);
863
Chia-I Wu72292b72014-09-09 10:48:33 +0800864 cmd_batch_pointer(cmd, cmd_len, &dw);
865 dw[0] = dw0;
866 dw[1] = blend_offset | 1;
867 dw[2] = ds_offset | 1;
868 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800869}
870
Chia-I Wu1744cca2014-08-22 11:10:17 +0800871static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800872 uint32_t clip_offset,
873 uint32_t sf_offset,
874 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800875{
876 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800877 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800878
879 CMD_ASSERT(cmd, 6, 6);
880
Chia-I Wu426072d2014-08-26 14:31:55 +0800881 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800882 GEN6_PTR_VP_DW0_CLIP_CHANGED |
883 GEN6_PTR_VP_DW0_SF_CHANGED |
884 GEN6_PTR_VP_DW0_CC_CHANGED |
885 (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] = clip_offset;
890 dw[2] = sf_offset;
891 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800892}
893
894static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800895 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896{
897 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800899
900 CMD_ASSERT(cmd, 6, 6);
901
Chia-I Wu426072d2014-08-26 14:31:55 +0800902 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800903 (cmd_len - 2);
904
Chia-I Wu72292b72014-09-09 10:48:33 +0800905 cmd_batch_pointer(cmd, cmd_len, &dw);
906 dw[0] = dw0;
907 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800908}
909
Chia-I Wu42a56202014-08-23 16:47:48 +0800910static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800911 uint32_t vs_offset,
912 uint32_t gs_offset,
913 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800914{
915 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800917
918 CMD_ASSERT(cmd, 6, 6);
919
Chia-I Wu426072d2014-08-26 14:31:55 +0800920 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800921 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
922 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
923 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
924 (cmd_len - 2);
925
Chia-I Wu72292b72014-09-09 10:48:33 +0800926 cmd_batch_pointer(cmd, cmd_len, &dw);
927 dw[0] = dw0;
928 dw[1] = vs_offset;
929 dw[2] = gs_offset;
930 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800931}
932
Chia-I Wu257e75e2014-08-29 14:06:35 +0800933static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800934 uint32_t vs_offset,
935 uint32_t gs_offset,
936 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800937{
938 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800940
941 CMD_ASSERT(cmd, 6, 6);
942
943 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
944 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
945 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
946 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
947 (cmd_len - 2);
948
Chia-I Wu72292b72014-09-09 10:48:33 +0800949 cmd_batch_pointer(cmd, cmd_len, &dw);
950 dw[0] = dw0;
951 dw[1] = vs_offset;
952 dw[2] = gs_offset;
953 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800954}
955
Chia-I Wu302742d2014-08-22 10:28:29 +0800956static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800958{
959 const uint8_t cmd_len = 2;
960 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
961 GEN6_RENDER_SUBTYPE_3D |
962 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800963 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800964
Chia-I Wu72292b72014-09-09 10:48:33 +0800965 cmd_batch_pointer(cmd, cmd_len, &dw);
966 dw[0] = dw0;
967 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800968}
969
Chia-I Wua6c4f152014-12-02 04:19:58 +0800970static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800971{
Chia-I Wue6073342014-11-30 09:43:42 +0800972 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700973 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
974 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800975
976 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700977 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800978
Tony Barbourfa6cac72015-01-16 14:27:35 -0700979 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800980}
981
Chia-I Wu72292b72014-09-09 10:48:33 +0800982static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700983 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800984{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700985 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800986 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700988 uint32_t dw[3];
989
990 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700991 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700992 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700993 (state->ds_info.stencilWriteMask & 0xff) << 16 |
994 (state->ds_info.stencilReadMask & 0xff) << 8 |
995 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700996 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800997
998 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700999
1000 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1001 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001002
Chia-I Wu00b51a82014-09-09 12:07:37 +08001003 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001004 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001005}
1006
Chia-I Wu72292b72014-09-09 10:48:33 +08001007static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001008 uint32_t stencil_ref,
1009 const uint32_t blend_color[4])
1010{
Chia-I Wue6073342014-11-30 09:43:42 +08001011 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001012 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001013 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001014
1015 CMD_ASSERT(cmd, 6, 7.5);
1016
Chia-I Wu00b51a82014-09-09 12:07:37 +08001017 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1018 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001019 dw[0] = stencil_ref;
1020 dw[1] = 0;
1021 dw[2] = blend_color[0];
1022 dw[3] = blend_color[1];
1023 dw[4] = blend_color[2];
1024 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001025
Chia-I Wu72292b72014-09-09 10:48:33 +08001026 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001027}
1028
Chia-I Wu8370b402014-08-29 12:28:37 +08001029static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001030{
Chia-I Wu8370b402014-08-29 12:28:37 +08001031 CMD_ASSERT(cmd, 6, 7.5);
1032
Chia-I Wu707a29e2014-08-27 12:51:47 +08001033 if (!cmd->bind.draw_count)
1034 return;
1035
Chia-I Wu8370b402014-08-29 12:28:37 +08001036 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001037 return;
1038
Chia-I Wu8370b402014-08-29 12:28:37 +08001039 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001040
1041 /*
1042 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1043 *
1044 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1045 * pipe-control with a post-sync op and no write-cache flushes."
1046 *
1047 * The workaround below necessitates this workaround.
1048 */
1049 gen6_PIPE_CONTROL(cmd,
1050 GEN6_PIPE_CONTROL_CS_STALL |
1051 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001052 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001053
Chia-I Wud6d079d2014-08-31 13:14:21 +08001054 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1055 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001056}
1057
Chia-I Wu8370b402014-08-29 12:28:37 +08001058static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001059{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001060 CMD_ASSERT(cmd, 6, 7.5);
1061
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001062 if (!cmd->bind.draw_count)
1063 return;
1064
Chia-I Wud6d079d2014-08-31 13:14:21 +08001065 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1066 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001067}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001068
Chia-I Wu8370b402014-08-29 12:28:37 +08001069static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1070{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001071 CMD_ASSERT(cmd, 7, 7.5);
1072
Chia-I Wu8370b402014-08-29 12:28:37 +08001073 if (!cmd->bind.draw_count)
1074 return;
1075
1076 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001077
1078 gen6_PIPE_CONTROL(cmd,
1079 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001080 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001081}
1082
Chia-I Wu8370b402014-08-29 12:28:37 +08001083static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1084{
1085 CMD_ASSERT(cmd, 7, 7.5);
1086
Chia-I Wu8370b402014-08-29 12:28:37 +08001087 /*
1088 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1089 *
1090 * "One of the following must also be set (when CS stall is set):
1091 *
1092 * * Render Target Cache Flush Enable ([12] of DW1)
1093 * * Depth Cache Flush Enable ([0] of DW1)
1094 * * Stall at Pixel Scoreboard ([1] of DW1)
1095 * * Depth Stall ([13] of DW1)
1096 * * Post-Sync Operation ([13] of DW1)"
1097 */
1098 gen6_PIPE_CONTROL(cmd,
1099 GEN6_PIPE_CONTROL_CS_STALL |
1100 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001101 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001102}
1103
1104static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1105{
1106 CMD_ASSERT(cmd, 7, 7.5);
1107
Chia-I Wu8370b402014-08-29 12:28:37 +08001108 cmd_wa_gen6_pre_depth_stall_write(cmd);
1109
Chia-I Wud6d079d2014-08-31 13:14:21 +08001110 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001111}
1112
1113static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1114{
1115 CMD_ASSERT(cmd, 6, 7.5);
1116
1117 if (!cmd->bind.draw_count)
1118 return;
1119
1120 /*
1121 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1122 *
1123 * "Driver must guarentee that all the caches in the depth pipe are
1124 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1125 * requires driver to send a PIPE_CONTROL with a CS stall along with
1126 * a Depth Flush prior to this command."
1127 *
1128 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1129 *
1130 * "Driver must ierarchi that all the caches in the depth pipe are
1131 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1132 * requires driver to send a PIPE_CONTROL with a CS stall along with
1133 * a Depth Flush prior to this command.
1134 */
1135 gen6_PIPE_CONTROL(cmd,
1136 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1137 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001138 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001139}
1140
1141static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1142{
1143 CMD_ASSERT(cmd, 6, 7.5);
1144
1145 if (!cmd->bind.draw_count)
1146 return;
1147
1148 /*
1149 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1150 *
1151 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1152 * and a post sync operation prior to the group of depth
1153 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1154 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1155 *
1156 * This workaround satifies all the conditions.
1157 */
1158 cmd_wa_gen6_pre_depth_stall_write(cmd);
1159
1160 /*
1161 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1162 *
1163 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1164 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1165 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1166 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1167 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1168 * Depth Flush Bit set, followed by another pipelined depth stall
1169 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1170 * guarantee that the pipeline from WM onwards is already flushed
1171 * (e.g., via a preceding MI_FLUSH)."
1172 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001173 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1174 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1175 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001176}
1177
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001178void cmd_batch_state_base_address(struct intel_cmd *cmd)
1179{
1180 const uint8_t cmd_len = 10;
1181 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1182 (cmd_len - 2);
1183 uint32_t pos;
1184 uint32_t *dw;
1185
1186 CMD_ASSERT(cmd, 6, 7.5);
1187
1188 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1189
1190 dw[0] = dw0;
1191 /* start offsets */
1192 dw[1] = 1;
1193 dw[2] = 1;
1194 dw[3] = 1;
1195 dw[4] = 1;
1196 dw[5] = 1;
1197 /* end offsets */
1198 dw[6] = 1;
1199 dw[7] = 1 + 0xfffff000;
1200 dw[8] = 1 + 0xfffff000;
1201 dw[9] = 1;
1202
1203 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001204 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1205 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1206 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1207 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1208 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1209 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001210}
1211
Chia-I Wu525c6602014-08-27 10:22:34 +08001212void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1213{
Mike Stroyan552fda42015-01-30 17:21:08 -07001214 if (pipe_control_dw0 == 0)
1215 return;
1216
Chia-I Wu525c6602014-08-27 10:22:34 +08001217 if (!cmd->bind.draw_count)
1218 return;
1219
1220 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1221
Chia-I Wu8370b402014-08-29 12:28:37 +08001222 /*
1223 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1224 *
1225 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1226 * PIPE_CONTROL with any non-zero post-sync-op is required."
1227 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001228 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001229 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001230
Chia-I Wu092279a2014-08-30 19:05:30 +08001231 /*
1232 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1233 *
1234 * "One of the following must also be set (when CS stall is set):
1235 *
1236 * * Render Target Cache Flush Enable ([12] of DW1)
1237 * * Depth Cache Flush Enable ([0] of DW1)
1238 * * Stall at Pixel Scoreboard ([1] of DW1)
1239 * * Depth Stall ([13] of DW1)
1240 * * Post-Sync Operation ([13] of DW1)"
1241 */
1242 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1243 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1244 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1245 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1246 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1247 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1248
Chia-I Wud6d079d2014-08-31 13:14:21 +08001249 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001250}
1251
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001252void cmd_batch_flush_all(struct intel_cmd *cmd)
1253{
1254 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1255 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1256 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1257 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1258 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1259 GEN6_PIPE_CONTROL_CS_STALL);
1260}
1261
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001262void cmd_batch_depth_count(struct intel_cmd *cmd,
1263 struct intel_bo *bo,
1264 XGL_GPU_SIZE offset)
1265{
1266 cmd_wa_gen6_pre_depth_stall_write(cmd);
1267
1268 gen6_PIPE_CONTROL(cmd,
1269 GEN6_PIPE_CONTROL_DEPTH_STALL |
1270 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001271 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001272}
1273
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001274void cmd_batch_timestamp(struct intel_cmd *cmd,
1275 struct intel_bo *bo,
1276 XGL_GPU_SIZE offset)
1277{
1278 /* need any WA or stall? */
1279 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1280}
1281
1282void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001283 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001284 struct intel_bo *bo,
1285 XGL_GPU_SIZE offset,
1286 uint64_t val)
1287{
1288 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001289 gen6_PIPE_CONTROL(cmd,
1290 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1291 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001292}
1293
Chia-I Wu302742d2014-08-22 10:28:29 +08001294static void gen6_cc_states(struct intel_cmd *cmd)
1295{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001296 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1297 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001298 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001299 uint32_t stencil_ref;
1300 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001301
1302 CMD_ASSERT(cmd, 6, 6);
1303
Chia-I Wua6c4f152014-12-02 04:19:58 +08001304 blend_offset = gen6_BLEND_STATE(cmd);
1305
1306 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001307 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001308 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001309 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001310
1311 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001312 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001313 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1314 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001315 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001316 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001317 stencil_ref = 0;
1318 }
1319
Chia-I Wu72292b72014-09-09 10:48:33 +08001320 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001321
Chia-I Wu72292b72014-09-09 10:48:33 +08001322 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001323}
1324
Chia-I Wu1744cca2014-08-22 11:10:17 +08001325static void gen6_viewport_states(struct intel_cmd *cmd)
1326{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001327 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001328 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001329
1330 if (!viewport)
1331 return;
1332
Tony Barbourfa6cac72015-01-16 14:27:35 -07001333 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001334 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001335
1336 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001337 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001338 viewport->cmd);
1339
1340 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001341 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001342 &viewport->cmd[viewport->cmd_clip_pos]);
1343
1344 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001345 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001346 &viewport->cmd[viewport->cmd_cc_pos]);
1347
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001348 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1349 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1350 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001351
1352 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001353 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001354
Chia-I Wub1d450a2014-09-09 13:48:03 +08001355 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001356}
1357
Chia-I Wu302742d2014-08-22 10:28:29 +08001358static void gen7_cc_states(struct intel_cmd *cmd)
1359{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001360 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1361 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001362 uint32_t stencil_ref;
1363 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001364 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001365
1366 CMD_ASSERT(cmd, 7, 7.5);
1367
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001368 if (!blend && !ds)
1369 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001370
Chia-I Wua6c4f152014-12-02 04:19:58 +08001371 offset = gen6_BLEND_STATE(cmd);
1372 gen7_3dstate_pointer(cmd,
1373 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001374
Chia-I Wua6c4f152014-12-02 04:19:58 +08001375 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001376 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001377 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001378 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001379
1380 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001381 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001382 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1383 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001384 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001385 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1386 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001387 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1388 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001389 } else {
1390 stencil_ref = 0;
1391 }
1392
Chia-I Wu72292b72014-09-09 10:48:33 +08001393 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001394 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001395 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001396}
1397
Chia-I Wu1744cca2014-08-22 11:10:17 +08001398static void gen7_viewport_states(struct intel_cmd *cmd)
1399{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001400 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001401 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001402
1403 if (!viewport)
1404 return;
1405
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001406 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001407
Chia-I Wub1d450a2014-09-09 13:48:03 +08001408 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001409 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001410 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001411 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001412 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1413 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001414
1415 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001416 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001417 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001418 gen7_3dstate_pointer(cmd,
1419 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001420 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001421
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001422 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1423 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1424 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1425 gen7_3dstate_pointer(cmd,
1426 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1427 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001428}
1429
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001430static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001431 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001432{
1433 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001434 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001435
Chia-I Wu72292b72014-09-09 10:48:33 +08001436 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001437
1438 dw[0] = GEN6_RENDER_TYPE_RENDER |
1439 GEN6_RENDER_SUBTYPE_3D |
1440 subop | (cmd_len - 2);
1441 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001442 dw[2] = 0;
1443 dw[3] = 0;
1444 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001445}
1446
1447static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001448 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001449{
1450 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001451 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001452
Chia-I Wu72292b72014-09-09 10:48:33 +08001453 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001454
1455 dw[0] = GEN6_RENDER_TYPE_RENDER |
1456 GEN6_RENDER_SUBTYPE_3D |
1457 subop | (cmd_len - 2);
1458 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001459 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001460 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001461 dw[4] = 0;
1462 dw[5] = 0;
1463 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001464}
1465
Chia-I Wu625105f2014-10-13 15:35:29 +08001466static uint32_t emit_samplers(struct intel_cmd *cmd,
1467 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001468{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001469 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1470 const uint32_t border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001471 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001472 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001473 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001474 uint32_t surface_count;
1475 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001476
1477 CMD_ASSERT(cmd, 6, 7.5);
1478
Chia-I Wu625105f2014-10-13 15:35:29 +08001479 if (!rmap || !rmap->sampler_count)
1480 return 0;
1481
Cody Northrop40316a32014-12-09 19:08:33 -07001482 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001483
Chia-I Wudcb509d2014-12-10 08:53:10 +08001484 /*
1485 * note that we cannot call cmd_state_pointer() here as the following
1486 * cmd_state_pointer() would invalidate the pointer
1487 */
1488 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001489 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001490 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001491
1492 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001493 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001494 4 * rmap->sampler_count, &sampler_dw);
1495
Chia-I Wudcb509d2014-12-10 08:53:10 +08001496 cmd_state_update(cmd, border_offset,
1497 border_stride * rmap->sampler_count, &border_dw);
1498
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001499 for (i = 0; i < rmap->sampler_count; i++) {
1500 const struct intel_pipeline_rmap_slot *slot =
1501 &rmap->slots[surface_count + i];
1502 const struct intel_sampler *sampler;
1503
Chia-I Wuf8385062015-01-04 16:27:24 +08001504 switch (slot->type) {
1505 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001506 intel_desc_set_read_sampler(set, &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001507 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001508 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001509 sampler = NULL;
1510 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001511 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001512 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001513 sampler = NULL;
1514 break;
1515 }
1516
1517 if (sampler) {
1518 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1519
1520 sampler_dw[0] = sampler->cmd[0];
1521 sampler_dw[1] = sampler->cmd[1];
1522 sampler_dw[2] = border_offset;
1523 sampler_dw[3] = sampler->cmd[2];
1524 } else {
1525 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1526 sampler_dw[1] = 0;
1527 sampler_dw[2] = 0;
1528 sampler_dw[3] = 0;
1529 }
1530
1531 border_offset += border_stride * 4;
1532 border_dw += border_stride;
1533 sampler_dw += 4;
1534 }
1535
Chia-I Wu625105f2014-10-13 15:35:29 +08001536 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001537}
1538
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001539static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001540 const struct intel_pipeline_rmap *rmap,
1541 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001542{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001543 const uint32_t sba_offset =
1544 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001545 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001546 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001547 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001548
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001549 CMD_ASSERT(cmd, 6, 7.5);
1550
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001551 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001552 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001553 if (!surface_count)
1554 return 0;
1555
Chia-I Wu42a56202014-08-23 16:47:48 +08001556 assert(surface_count <= ARRAY_SIZE(binding_table));
1557
1558 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001559 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001560 struct intel_null_view null_view;
1561 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001562
Chia-I Wuf8385062015-01-04 16:27:24 +08001563 switch (slot->type) {
1564 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001565 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001566 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001567 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1568 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001569
Chia-I Wu787a05b2014-12-05 11:02:20 +08001570 if (view) {
1571 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1572 GEN6_ALIGNMENT_SURFACE_STATE,
1573 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001574
Chia-I Wu787a05b2014-12-05 11:02:20 +08001575 cmd_reserve_reloc(cmd, 1);
1576 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1577 view->cmd[1], INTEL_RELOC_WRITE);
1578 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001579 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001580 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001581 }
1582 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001583 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001584 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001585 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1586 const struct intel_mem *mem;
1587 bool read_only;
1588 const uint32_t *cmd_data;
1589 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001590
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001591 assert(dyn_idx < 0 ||
1592 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001593
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001594 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1595 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001596 if (mem) {
1597 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1598 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1599 const uint32_t reloc_flags =
1600 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001601
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001602 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001603 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001604 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001605
1606 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001607 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1608 cmd_data[1] + dynamic_offset, reloc_flags);
1609 } else {
1610 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001611 }
1612 }
1613 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001614 case INTEL_PIPELINE_RMAP_UNUSED:
1615 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001616 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001617 default:
1618 assert(!"unexpected rmap type");
1619 need_null_view = true;
1620 break;
1621 }
1622
1623 if (need_null_view) {
1624 intel_null_view_init(&null_view, cmd->dev);
1625 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1626 GEN6_ALIGNMENT_SURFACE_STATE,
1627 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001628 }
1629
Chia-I Wuf98dd882015-02-10 04:17:47 +08001630 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001631 }
1632
Chia-I Wuf98dd882015-02-10 04:17:47 +08001633 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001634 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001635 surface_count, binding_table) - sba_offset;
1636
1637 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1638 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1639
1640 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001641}
1642
Chia-I Wu1d125092014-10-08 08:49:38 +08001643static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1644{
1645 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001646 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1647 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001648 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001649
1650 CMD_ASSERT(cmd, 6, 7.5);
1651
1652 if (!pipeline->vb_count)
1653 return;
1654
1655 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1656
1657 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1658 dw++;
1659 pos++;
1660
1661 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001662 assert(pipeline->vb[i].strideInBytes <= 2048);
1663
1664 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1665 pipeline->vb[i].strideInBytes;
1666
1667 if (cmd_gen(cmd) >= INTEL_GEN(7))
1668 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1669
1670 switch (pipeline->vb[i].stepRate) {
1671 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1672 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1673 dw[3] = 0;
1674 break;
1675 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1676 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1677 dw[3] = 1;
1678 break;
1679 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1680 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1681 dw[3] = 0;
1682 break;
1683 default:
1684 assert(!"unknown step rate");
1685 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1686 dw[3] = 0;
1687 break;
1688 }
1689
Chia-I Wu714df452015-01-01 07:55:04 +08001690 if (cmd->bind.vertex.buf[i]) {
1691 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001692 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001693
1694 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001695 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1696 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001697 } else {
1698 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1699 dw[1] = 0;
1700 dw[2] = 0;
1701 }
1702
1703 dw += 4;
1704 pos += 4;
1705 }
1706}
1707
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001708static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1709{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001710 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1711 const struct intel_pipeline_shader *vs = &pipeline->vs;
1712 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001713 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001714 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001715 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001716 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001717
1718 CMD_ASSERT(cmd, 6, 7.5);
1719
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001720 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001721 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1722 *
1723 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1724 * 128-bit vertex elements to be passed into the payload for each
1725 * vertex."
1726 *
1727 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1728 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001729 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001730 vue_read_len = (vs->in_count + 1) / 2;
1731 if (!vue_read_len)
1732 vue_read_len = 1;
1733
1734 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1735 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1736
1737 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1738 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1739 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001740
1741 dw5 = GEN6_VS_DW5_STATISTICS |
1742 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001743
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001744 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001745 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001746 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001747 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001748
Chia-I Wube0a3d92014-09-02 13:20:59 +08001749 if (pipeline->disable_vs_cache)
1750 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1751
Chia-I Wu784d3042014-12-19 14:30:04 +08001752 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001753 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001754 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001755 dw[2] = dw2;
1756 dw[3] = 0; /* scratch */
1757 dw[4] = dw4;
1758 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001759
1760 if (vs->per_thread_scratch_size)
1761 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001762}
1763
Chia-I Wu625105f2014-10-13 15:35:29 +08001764static void emit_shader_resources(struct intel_cmd *cmd)
1765{
1766 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001767 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001768
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001769 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001770 cmd->bind.pipeline.graphics->vs.rmap,
1771 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001772 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001773 cmd->bind.pipeline.graphics->tcs.rmap,
1774 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001775 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001776 cmd->bind.pipeline.graphics->tes.rmap,
1777 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001778 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001779 cmd->bind.pipeline.graphics->gs.rmap,
1780 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001781 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001782 cmd->bind.pipeline.graphics->fs.rmap,
1783 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001784
1785 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1786 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1787 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1788 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1789 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1790
1791 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1792 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001793 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1794 binding_tables[0]);
1795 gen7_3dstate_pointer(cmd,
1796 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1797 binding_tables[1]);
1798 gen7_3dstate_pointer(cmd,
1799 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1800 binding_tables[2]);
1801 gen7_3dstate_pointer(cmd,
1802 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1803 binding_tables[3]);
1804 gen7_3dstate_pointer(cmd,
1805 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1806 binding_tables[4]);
1807
1808 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001809 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1810 samplers[0]);
1811 gen7_3dstate_pointer(cmd,
1812 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1813 samplers[1]);
1814 gen7_3dstate_pointer(cmd,
1815 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1816 samplers[2]);
1817 gen7_3dstate_pointer(cmd,
1818 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1819 samplers[3]);
1820 gen7_3dstate_pointer(cmd,
1821 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1822 samplers[4]);
1823 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001824 assert(!binding_tables[1] && !binding_tables[2]);
1825 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1826 binding_tables[0], binding_tables[3], binding_tables[4]);
1827
Chia-I Wu625105f2014-10-13 15:35:29 +08001828 assert(!samplers[1] && !samplers[2]);
1829 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1830 samplers[0], samplers[3], samplers[4]);
1831 }
1832}
1833
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001834static void emit_rt(struct intel_cmd *cmd)
1835{
1836 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001837 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1838 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001839}
1840
1841static void emit_ds(struct intel_cmd *cmd)
1842{
Chia-I Wu73520ac2015-02-19 11:17:45 -07001843 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1844 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001845
1846 if (!ds) {
1847 /* all zeros */
1848 static const struct intel_ds_view null_ds;
1849 ds = &null_ds;
1850 }
1851
1852 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001853 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1854 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1855 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001856
1857 if (cmd_gen(cmd) >= INTEL_GEN(7))
1858 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1859 else
1860 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1861}
1862
Chia-I Wua57761b2014-10-14 14:27:44 +08001863static uint32_t emit_shader(struct intel_cmd *cmd,
1864 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001865{
Chia-I Wua57761b2014-10-14 14:27:44 +08001866 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1867 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001868 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001869
Chia-I Wua57761b2014-10-14 14:27:44 +08001870 /* see if the shader is already in the cache */
1871 for (i = 0; i < cache->used; i++) {
1872 if (cache->entries[i].shader == (const void *) shader)
1873 return cache->entries[i].kernel_offset;
1874 }
1875
1876 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1877
1878 /* grow the cache if full */
1879 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001880 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001881 void *entries;
1882
1883 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1884 XGL_SYSTEM_ALLOC_INTERNAL);
1885 if (entries) {
1886 if (cache->entries) {
1887 memcpy(entries, cache->entries,
1888 sizeof(cache->entries[0]) * cache->used);
1889 icd_free(cache->entries);
1890 }
1891
1892 cache->entries = entries;
1893 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001894 }
1895 }
1896
Chia-I Wua57761b2014-10-14 14:27:44 +08001897 /* add the shader to the cache */
1898 if (cache->used < cache->count) {
1899 cache->entries[cache->used].shader = (const void *) shader;
1900 cache->entries[cache->used].kernel_offset = offset;
1901 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001902 }
1903
Chia-I Wua57761b2014-10-14 14:27:44 +08001904 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001905}
1906
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001907static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001908{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001909 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001910
Chia-I Wu8370b402014-08-29 12:28:37 +08001911 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1912 cmd_wa_gen6_pre_depth_stall_write(cmd);
1913 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1914 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1915 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1916 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001917
1918 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001919 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001920 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001921
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001922 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001923 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001924 }
1925 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001926 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001927 }
1928 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001929 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1930 }
1931 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1932 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1933 }
1934 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1935 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001936 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001937
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001938 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1939 gen7_3DSTATE_GS(cmd);
1940 } else {
1941 gen6_3DSTATE_GS(cmd);
1942 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001943
Chia-I Wu8370b402014-08-29 12:28:37 +08001944 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1945 cmd_wa_gen7_post_command_cs_stall(cmd);
1946 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1947 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001948}
1949
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001950static void emit_bounded_states(struct intel_cmd *cmd)
1951{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001952
1953 emit_graphics_pipeline(cmd);
1954
1955 emit_rt(cmd);
1956 emit_ds(cmd);
1957
1958 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1959 gen7_cc_states(cmd);
1960 gen7_viewport_states(cmd);
1961
1962 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1963 &cmd->bind.pipeline.graphics->vs);
1964 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1965 &cmd->bind.pipeline.graphics->fs);
1966
1967 gen6_3DSTATE_CLIP(cmd);
1968 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001969 gen7_3DSTATE_WM(cmd);
1970 gen7_3DSTATE_PS(cmd);
1971 } else {
1972 gen6_cc_states(cmd);
1973 gen6_viewport_states(cmd);
1974
1975 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1976 &cmd->bind.pipeline.graphics->vs);
1977 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1978 &cmd->bind.pipeline.graphics->fs);
1979
1980 gen6_3DSTATE_CLIP(cmd);
1981 gen6_3DSTATE_SF(cmd);
1982 gen6_3DSTATE_WM(cmd);
1983 }
1984
1985 emit_shader_resources(cmd);
1986
1987 cmd_wa_gen6_pre_depth_stall_write(cmd);
1988 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1989
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001990 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1991 gen6_3DSTATE_VS(cmd);
1992}
1993
Tony Barbourfa6cac72015-01-16 14:27:35 -07001994static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07001995 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001996{
1997 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
1998 const uint8_t cmd_len = 3;
1999 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002000
2001 CMD_ASSERT(cmd, 6, 7.5);
2002
Tony Barbourfa6cac72015-01-16 14:27:35 -07002003 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002004 dw[0] = 0;
2005 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002006
2007 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2008 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2009 GEN6_COMPAREFUNCTION_NEVER << 27 |
2010 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2011 } else {
2012 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2013 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2014 }
Chia-I Wud850a392015-02-19 11:08:25 -07002015 } else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2016 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002017 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2018 (GEN6_STENCILOP_KEEP) << 25 |
2019 (GEN6_STENCILOP_KEEP) << 22 |
2020 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002021 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2022 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002023 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2024 (GEN6_STENCILOP_KEEP) << 9 |
2025 (GEN6_STENCILOP_KEEP) << 6 |
2026 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002027
Chia-I Wud850a392015-02-19 11:08:25 -07002028 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2029 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2030 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2031 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2032 dw[2] = 0;
2033 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002034
2035 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2036 cmd_align, cmd_len, dw);
2037}
2038
Chia-I Wu6032b892014-10-17 14:47:18 +08002039static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2040{
2041 const struct intel_cmd_meta *meta = cmd->bind.meta;
2042 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2043
2044 CMD_ASSERT(cmd, 6, 7.5);
2045
2046 blend_offset = 0;
2047 ds_offset = 0;
2048 cc_offset = 0;
2049 cc_vp_offset = 0;
2050
Chia-I Wu29e6f502014-11-24 14:27:29 +08002051 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002052 /* BLEND_STATE */
2053 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002054 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002055 dw[0] = 0;
2056 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2057 }
2058
Chia-I Wu29e6f502014-11-24 14:27:29 +08002059 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002060 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002061 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002062 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2063 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002064
Chia-I Wu29e6f502014-11-24 14:27:29 +08002065 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002066 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002067
Chia-I Wu29e6f502014-11-24 14:27:29 +08002068 /* COLOR_CALC_STATE */
2069 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002070 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002071
Chia-I Wu29e6f502014-11-24 14:27:29 +08002072 /* CC_VIEWPORT */
2073 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002074 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002075 dw[0] = u_fui(0.0f);
2076 dw[1] = u_fui(1.0f);
2077 } else {
2078 /* DEPTH_STENCIL_STATE */
2079 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002080 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002081 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2082 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2083 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002084 }
2085
2086 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2087 gen7_3dstate_pointer(cmd,
2088 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2089 blend_offset);
2090 gen7_3dstate_pointer(cmd,
2091 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2092 ds_offset);
2093 gen7_3dstate_pointer(cmd,
2094 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2095
2096 gen7_3dstate_pointer(cmd,
2097 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2098 cc_vp_offset);
2099 } else {
2100 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002101 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002102
2103 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2104 cmd_batch_pointer(cmd, 4, &dw);
2105 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2106 GEN6_PTR_VP_DW0_CC_CHANGED;
2107 dw[1] = 0;
2108 dw[2] = 0;
2109 dw[3] = cc_vp_offset;
2110 }
2111}
2112
2113static void gen6_meta_surface_states(struct intel_cmd *cmd)
2114{
2115 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002116 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002117 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002118 const uint32_t sba_offset =
2119 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002120
2121 CMD_ASSERT(cmd, 6, 7.5);
2122
Chia-I Wu29e6f502014-11-24 14:27:29 +08002123 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2124 return;
2125
Chia-I Wu005c47c2014-10-22 13:49:13 +08002126 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002127 if (meta->src.valid) {
2128 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002129 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002130 meta->src.surface_len, meta->src.surface);
2131
2132 cmd_reserve_reloc(cmd, 1);
2133 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2134 cmd_surface_reloc_writer(cmd, offset, 1,
2135 meta->src.reloc_target, meta->src.reloc_offset);
2136 } else {
2137 cmd_surface_reloc(cmd, offset, 1,
2138 (struct intel_bo *) meta->src.reloc_target,
2139 meta->src.reloc_offset, meta->src.reloc_flags);
2140 }
2141
Mike Stroyan9bfad482015-02-10 15:09:23 -07002142 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002143 }
2144 if (meta->dst.valid) {
2145 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002146 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002147 meta->dst.surface_len, meta->dst.surface);
2148
2149 cmd_reserve_reloc(cmd, 1);
2150 cmd_surface_reloc(cmd, offset, 1,
2151 (struct intel_bo *) meta->dst.reloc_target,
2152 meta->dst.reloc_offset, meta->dst.reloc_flags);
2153
Mike Stroyan9bfad482015-02-10 15:09:23 -07002154 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002155 }
2156
2157 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002158 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002159 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002160 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002161
2162 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002163 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2164 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2165 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002166 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002167 } else {
2168 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002169 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002170 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002171 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002172 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002173 }
2174}
2175
2176static void gen6_meta_urb(struct intel_cmd *cmd)
2177{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002178 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002179 uint32_t *dw;
2180
2181 CMD_ASSERT(cmd, 6, 6);
2182
2183 /* 3DSTATE_URB */
2184 cmd_batch_pointer(cmd, 3, &dw);
2185 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002186 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002187 dw[2] = 0;
2188}
2189
2190static void gen7_meta_urb(struct intel_cmd *cmd)
2191{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002192 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2193 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002194 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002195 uint32_t *dw;
2196
2197 CMD_ASSERT(cmd, 7, 7.5);
2198
2199 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2200 cmd_batch_pointer(cmd, 10, &dw);
2201
2202 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002203 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
2204 dw += 2;
2205
2206 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2207 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
2208 pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002209 dw += 2;
2210
2211 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2212 dw[1] = 0;
2213 dw += 2;
2214
2215 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2216 dw[1] = 0;
2217 dw += 2;
2218
2219 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2220 dw[1] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002221
Chia-I Wu15dacac2015-02-05 11:14:01 -07002222 cmd_wa_gen7_post_command_cs_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002223
2224 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2225
Chia-I Wu24aa1022014-11-25 11:53:19 +08002226 switch (cmd_gen(cmd)) {
2227 case INTEL_GEN(7.5):
2228 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2229 break;
2230 case INTEL_GEN(7):
2231 default:
2232 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2233 break;
2234 }
2235
Chia-I Wu6032b892014-10-17 14:47:18 +08002236 /* 3DSTATE_URB_x */
2237 cmd_batch_pointer(cmd, 8, &dw);
2238
2239 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002240 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002241 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002242 dw += 2;
2243
2244 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002245 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002246 dw += 2;
2247
2248 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002249 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002250 dw += 2;
2251
2252 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002253 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002254 dw += 2;
2255}
2256
2257static void gen6_meta_vf(struct intel_cmd *cmd)
2258{
2259 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002260 uint32_t vb_start, vb_end, vb_stride;
2261 int ve_format, ve_z_source;
2262 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002263 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002264
2265 CMD_ASSERT(cmd, 6, 7.5);
2266
Chia-I Wu29e6f502014-11-24 14:27:29 +08002267 switch (meta->mode) {
2268 case INTEL_CMD_META_VS_POINTS:
2269 cmd_batch_pointer(cmd, 3, &dw);
2270 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2271 dw[1] = GEN6_VE_STATE_DW0_VALID;
2272 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2273 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2274 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2275 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2276 return;
2277 break;
2278 case INTEL_CMD_META_FS_RECT:
2279 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002280 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002281
Chia-I Wu29e6f502014-11-24 14:27:29 +08002282 vertices[0][0] = meta->dst.x + meta->width;
2283 vertices[0][1] = meta->dst.y + meta->height;
2284 vertices[1][0] = meta->dst.x;
2285 vertices[1][1] = meta->dst.y + meta->height;
2286 vertices[2][0] = meta->dst.x;
2287 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002288
Chia-I Wu29e6f502014-11-24 14:27:29 +08002289 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2290 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002291
Chia-I Wu29e6f502014-11-24 14:27:29 +08002292 vb_end = vb_start + sizeof(vertices) - 1;
2293 vb_stride = sizeof(vertices[0]);
2294 ve_z_source = GEN6_VFCOMP_STORE_0;
2295 ve_format = GEN6_FORMAT_R32G32_USCALED;
2296 }
2297 break;
2298 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2299 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002300 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002301
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002302 vertices[0][0] = (float) (meta->dst.x + meta->width);
2303 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002304 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002305 vertices[1][0] = (float) meta->dst.x;
2306 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002307 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002308 vertices[2][0] = (float) meta->dst.x;
2309 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002310 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002311
Chia-I Wu29e6f502014-11-24 14:27:29 +08002312 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2313 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002314
Chia-I Wu29e6f502014-11-24 14:27:29 +08002315 vb_end = vb_start + sizeof(vertices) - 1;
2316 vb_stride = sizeof(vertices[0]);
2317 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2318 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2319 }
2320 break;
2321 default:
2322 assert(!"unknown meta mode");
2323 return;
2324 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002325 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002326
2327 /* 3DSTATE_VERTEX_BUFFERS */
2328 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002329
Chia-I Wu6032b892014-10-17 14:47:18 +08002330 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002331 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002332 if (cmd_gen(cmd) >= INTEL_GEN(7))
2333 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2334
2335 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002336 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2337 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002338
2339 dw[4] = 0;
2340
2341 /* 3DSTATE_VERTEX_ELEMENTS */
2342 cmd_batch_pointer(cmd, 5, &dw);
2343 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002344 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002345 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2346 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2347 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2348 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2349 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002350 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002351 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2352 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002353 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002354 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2355}
2356
Chia-I Wu29e6f502014-11-24 14:27:29 +08002357static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002358{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002359 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002360 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002361 uint32_t consts[8];
2362 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002363
2364 CMD_ASSERT(cmd, 6, 7.5);
2365
2366 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002367 case INTEL_DEV_META_VS_FILL_MEM:
2368 consts[0] = meta->dst.x;
2369 consts[1] = meta->clear_val[0];
2370 const_count = 2;
2371 break;
2372 case INTEL_DEV_META_VS_COPY_MEM:
2373 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2374 consts[0] = meta->dst.x;
2375 consts[1] = meta->src.x;
2376 const_count = 2;
2377 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002378 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2379 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2380 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2381 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2382 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2383 consts[0] = meta->src.x;
2384 consts[1] = meta->src.y;
2385 consts[2] = meta->width;
2386 consts[3] = meta->dst.x;
2387 const_count = 4;
2388 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002389 default:
2390 assert(!"unknown meta shader id");
2391 const_count = 0;
2392 break;
2393 }
2394
2395 /* this can be skipped but it makes state dumping prettier */
2396 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2397
2398 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2399}
2400
2401static void gen6_meta_vs(struct intel_cmd *cmd)
2402{
2403 const struct intel_cmd_meta *meta = cmd->bind.meta;
2404 const struct intel_pipeline_shader *sh =
2405 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2406 uint32_t offset, *dw;
2407
2408 CMD_ASSERT(cmd, 6, 7.5);
2409
2410 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002411 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002412
2413 /* 3DSTATE_CONSTANT_VS */
2414 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2415 cmd_batch_pointer(cmd, cmd_len, &dw);
2416 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2417 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2418
2419 /* 3DSTATE_VS */
2420 cmd_batch_pointer(cmd, 6, &dw);
2421 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2422 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2423
2424 return;
2425 }
2426
2427 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2428
2429 /* 3DSTATE_CONSTANT_VS */
2430 offset = gen6_meta_vs_constants(cmd);
2431 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2432 cmd_batch_pointer(cmd, 7, &dw);
2433 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2434 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2435 dw[2] = 0;
2436 dw[3] = offset;
2437 dw[4] = 0;
2438 dw[5] = 0;
2439 dw[6] = 0;
2440 } else {
2441 cmd_batch_pointer(cmd, 5, &dw);
2442 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2443 GEN6_PCB_ANY_DW0_PCB0_VALID;
2444 dw[1] = offset;
2445 dw[2] = 0;
2446 dw[3] = 0;
2447 dw[4] = 0;
2448 }
2449
2450 /* 3DSTATE_VS */
2451 offset = emit_shader(cmd, sh);
2452 cmd_batch_pointer(cmd, 6, &dw);
2453 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2454 dw[1] = offset;
2455 dw[2] = GEN6_THREADDISP_SPF |
2456 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2457 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002458 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002459 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2460 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2461
2462 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2463 GEN6_VS_DW5_VS_ENABLE;
2464 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002465 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002466 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002467 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002468
2469 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002470}
2471
2472static void gen6_meta_disabled(struct intel_cmd *cmd)
2473{
Chia-I Wu6032b892014-10-17 14:47:18 +08002474 uint32_t *dw;
2475
2476 CMD_ASSERT(cmd, 6, 6);
2477
Chia-I Wu6032b892014-10-17 14:47:18 +08002478 /* 3DSTATE_CONSTANT_GS */
2479 cmd_batch_pointer(cmd, 5, &dw);
2480 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2481 dw[1] = 0;
2482 dw[2] = 0;
2483 dw[3] = 0;
2484 dw[4] = 0;
2485
2486 /* 3DSTATE_GS */
2487 cmd_batch_pointer(cmd, 7, &dw);
2488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2489 dw[1] = 0;
2490 dw[2] = 0;
2491 dw[3] = 0;
2492 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2493 dw[5] = GEN6_GS_DW5_STATISTICS;
2494 dw[6] = 0;
2495
Chia-I Wu6032b892014-10-17 14:47:18 +08002496 /* 3DSTATE_SF */
2497 cmd_batch_pointer(cmd, 20, &dw);
2498 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2499 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2500 memset(&dw[2], 0, 18 * sizeof(*dw));
2501}
2502
2503static void gen7_meta_disabled(struct intel_cmd *cmd)
2504{
2505 uint32_t *dw;
2506
2507 CMD_ASSERT(cmd, 7, 7.5);
2508
Chia-I Wu6032b892014-10-17 14:47:18 +08002509 /* 3DSTATE_CONSTANT_HS */
2510 cmd_batch_pointer(cmd, 7, &dw);
2511 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2512 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2513
2514 /* 3DSTATE_HS */
2515 cmd_batch_pointer(cmd, 7, &dw);
2516 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2517 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2518
2519 /* 3DSTATE_TE */
2520 cmd_batch_pointer(cmd, 4, &dw);
2521 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2522 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2523
2524 /* 3DSTATE_CONSTANT_DS */
2525 cmd_batch_pointer(cmd, 7, &dw);
2526 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2527 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2528
2529 /* 3DSTATE_DS */
2530 cmd_batch_pointer(cmd, 6, &dw);
2531 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2532 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2533
2534 /* 3DSTATE_CONSTANT_GS */
2535 cmd_batch_pointer(cmd, 7, &dw);
2536 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2537 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2538
2539 /* 3DSTATE_GS */
2540 cmd_batch_pointer(cmd, 7, &dw);
2541 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2542 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2543
2544 /* 3DSTATE_STREAMOUT */
2545 cmd_batch_pointer(cmd, 3, &dw);
2546 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2547 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2548
Chia-I Wu6032b892014-10-17 14:47:18 +08002549 /* 3DSTATE_SF */
2550 cmd_batch_pointer(cmd, 7, &dw);
2551 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2552 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2553
2554 /* 3DSTATE_SBE */
2555 cmd_batch_pointer(cmd, 14, &dw);
2556 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2557 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2558 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002559}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002560
Chia-I Wu29e6f502014-11-24 14:27:29 +08002561static void gen6_meta_clip(struct intel_cmd *cmd)
2562{
2563 const struct intel_cmd_meta *meta = cmd->bind.meta;
2564 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002565
Chia-I Wu29e6f502014-11-24 14:27:29 +08002566 /* 3DSTATE_CLIP */
2567 cmd_batch_pointer(cmd, 4, &dw);
2568 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2569 dw[1] = 0;
2570 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2571 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2572 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2573 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002574 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002575 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002576 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002577}
2578
2579static void gen6_meta_wm(struct intel_cmd *cmd)
2580{
2581 const struct intel_cmd_meta *meta = cmd->bind.meta;
2582 uint32_t *dw;
2583
2584 CMD_ASSERT(cmd, 6, 7.5);
2585
2586 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2587
2588 /* 3DSTATE_MULTISAMPLE */
2589 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2590 cmd_batch_pointer(cmd, 4, &dw);
2591 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2592 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2593 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2594 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2595 dw[2] = 0;
2596 dw[3] = 0;
2597 } else {
2598 cmd_batch_pointer(cmd, 3, &dw);
2599 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2600 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2601 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2602 dw[2] = 0;
2603 }
2604
2605 /* 3DSTATE_SAMPLE_MASK */
2606 cmd_batch_pointer(cmd, 2, &dw);
2607 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2608 dw[1] = (1 << meta->samples) - 1;
2609
2610 /* 3DSTATE_DRAWING_RECTANGLE */
2611 cmd_batch_pointer(cmd, 4, &dw);
2612 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002613 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2614 /* unused */
2615 dw[1] = 0;
2616 dw[2] = 0;
2617 } else {
2618 dw[1] = meta->dst.y << 16 | meta->dst.x;
2619 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2620 (meta->dst.x + meta->width - 1);
2621 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002622 dw[3] = 0;
2623}
2624
2625static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2626{
2627 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002628 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002629 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002630 uint32_t consts[8];
2631 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002632
2633 CMD_ASSERT(cmd, 6, 7.5);
2634
2635 /* underflow is fine here */
2636 offset_x = meta->src.x - meta->dst.x;
2637 offset_y = meta->src.y - meta->dst.y;
2638
2639 switch (meta->shader_id) {
2640 case INTEL_DEV_META_FS_COPY_MEM:
2641 case INTEL_DEV_META_FS_COPY_1D:
2642 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2643 case INTEL_DEV_META_FS_COPY_2D:
2644 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2645 case INTEL_DEV_META_FS_COPY_2D_MS:
2646 consts[0] = offset_x;
2647 consts[1] = offset_y;
2648 consts[2] = meta->src.layer;
2649 consts[3] = meta->src.lod;
2650 const_count = 4;
2651 break;
2652 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2653 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2654 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2655 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2656 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2657 consts[0] = offset_x;
2658 consts[1] = offset_y;
2659 consts[2] = meta->src.layer;
2660 consts[3] = meta->src.lod;
2661 consts[4] = meta->src.x;
2662 consts[5] = meta->width;
2663 const_count = 6;
2664 break;
2665 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2666 consts[0] = offset_x;
2667 consts[1] = offset_y;
2668 consts[2] = meta->width;
2669 const_count = 3;
2670 break;
2671 case INTEL_DEV_META_FS_CLEAR_COLOR:
2672 consts[0] = meta->clear_val[0];
2673 consts[1] = meta->clear_val[1];
2674 consts[2] = meta->clear_val[2];
2675 consts[3] = meta->clear_val[3];
2676 const_count = 4;
2677 break;
2678 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2679 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002680 consts[1] = meta->clear_val[1];
2681 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002682 break;
2683 case INTEL_DEV_META_FS_RESOLVE_2X:
2684 case INTEL_DEV_META_FS_RESOLVE_4X:
2685 case INTEL_DEV_META_FS_RESOLVE_8X:
2686 case INTEL_DEV_META_FS_RESOLVE_16X:
2687 consts[0] = offset_x;
2688 consts[1] = offset_y;
2689 const_count = 2;
2690 break;
2691 default:
2692 assert(!"unknown meta shader id");
2693 const_count = 0;
2694 break;
2695 }
2696
2697 /* this can be skipped but it makes state dumping prettier */
2698 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2699
2700 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2701}
2702
2703static void gen6_meta_ps(struct intel_cmd *cmd)
2704{
2705 const struct intel_cmd_meta *meta = cmd->bind.meta;
2706 const struct intel_pipeline_shader *sh =
2707 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2708 uint32_t offset, *dw;
2709
2710 CMD_ASSERT(cmd, 6, 6);
2711
Chia-I Wu29e6f502014-11-24 14:27:29 +08002712 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2713 /* 3DSTATE_CONSTANT_PS */
2714 cmd_batch_pointer(cmd, 5, &dw);
2715 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2716 dw[1] = 0;
2717 dw[2] = 0;
2718 dw[3] = 0;
2719 dw[4] = 0;
2720
2721 /* 3DSTATE_WM */
2722 cmd_batch_pointer(cmd, 9, &dw);
2723 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2724 dw[1] = 0;
2725 dw[2] = 0;
2726 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002727
2728 switch (meta->ds.op) {
2729 case INTEL_CMD_META_DS_HIZ_CLEAR:
2730 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2731 break;
2732 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2733 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2734 break;
2735 case INTEL_CMD_META_DS_RESOLVE:
2736 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2737 break;
2738 default:
2739 dw[4] = 0;
2740 break;
2741 }
2742
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002743 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002744 dw[6] = 0;
2745 dw[7] = 0;
2746 dw[8] = 0;
2747
Chia-I Wu3adf7212014-10-24 15:34:07 +08002748 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002749 }
2750
Chia-I Wu3adf7212014-10-24 15:34:07 +08002751 /* a normal color write */
2752 assert(meta->dst.valid && !sh->uses);
2753
Chia-I Wu6032b892014-10-17 14:47:18 +08002754 /* 3DSTATE_CONSTANT_PS */
2755 offset = gen6_meta_ps_constants(cmd);
2756 cmd_batch_pointer(cmd, 5, &dw);
2757 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2758 GEN6_PCB_ANY_DW0_PCB0_VALID;
2759 dw[1] = offset;
2760 dw[2] = 0;
2761 dw[3] = 0;
2762 dw[4] = 0;
2763
2764 /* 3DSTATE_WM */
2765 offset = emit_shader(cmd, sh);
2766 cmd_batch_pointer(cmd, 9, &dw);
2767 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2768 dw[1] = offset;
2769 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2770 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002771 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002772 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002773 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002774 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002775 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2776
Chia-I Wu6032b892014-10-17 14:47:18 +08002777 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2778 GEN6_WM_DW6_POSOFFSET_NONE |
2779 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2780 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2781 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2782 if (meta->samples > 1) {
2783 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2784 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2785 } else {
2786 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2787 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2788 }
2789 dw[7] = 0;
2790 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002791
2792 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002793}
2794
2795static void gen7_meta_ps(struct intel_cmd *cmd)
2796{
2797 const struct intel_cmd_meta *meta = cmd->bind.meta;
2798 const struct intel_pipeline_shader *sh =
2799 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2800 uint32_t offset, *dw;
2801
2802 CMD_ASSERT(cmd, 7, 7.5);
2803
Chia-I Wu29e6f502014-11-24 14:27:29 +08002804 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2805 /* 3DSTATE_WM */
2806 cmd_batch_pointer(cmd, 3, &dw);
2807 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002808
2809 switch (meta->ds.op) {
2810 case INTEL_CMD_META_DS_HIZ_CLEAR:
2811 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2812 break;
2813 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2814 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2815 break;
2816 case INTEL_CMD_META_DS_RESOLVE:
2817 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2818 break;
2819 default:
2820 dw[1] = 0;
2821 break;
2822 }
2823
2824 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002825
2826 /* 3DSTATE_CONSTANT_GS */
2827 cmd_batch_pointer(cmd, 7, &dw);
2828 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2829 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2830
2831 /* 3DSTATE_PS */
2832 cmd_batch_pointer(cmd, 8, &dw);
2833 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2834 dw[1] = 0;
2835 dw[2] = 0;
2836 dw[3] = 0;
2837 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002838 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002839 dw[5] = 0;
2840 dw[6] = 0;
2841 dw[7] = 0;
2842
Chia-I Wu3adf7212014-10-24 15:34:07 +08002843 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002844 }
2845
Chia-I Wu3adf7212014-10-24 15:34:07 +08002846 /* a normal color write */
2847 assert(meta->dst.valid && !sh->uses);
2848
Chia-I Wu6032b892014-10-17 14:47:18 +08002849 /* 3DSTATE_WM */
2850 cmd_batch_pointer(cmd, 3, &dw);
2851 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2852 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2853 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2854 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2855 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2856 dw[2] = 0;
2857
2858 /* 3DSTATE_CONSTANT_PS */
2859 offset = gen6_meta_ps_constants(cmd);
2860 cmd_batch_pointer(cmd, 7, &dw);
2861 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2862 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2863 dw[2] = 0;
2864 dw[3] = offset;
2865 dw[4] = 0;
2866 dw[5] = 0;
2867 dw[6] = 0;
2868
2869 /* 3DSTATE_PS */
2870 offset = emit_shader(cmd, sh);
2871 cmd_batch_pointer(cmd, 8, &dw);
2872 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2873 dw[1] = offset;
2874 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2875 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002876 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002877
2878 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2879 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002880 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2881
2882 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002883 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002884 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002885 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002886 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002887 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002888
2889 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2890 dw[6] = 0;
2891 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002892
2893 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002894}
2895
2896static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2897{
2898 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002899 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002900
2901 CMD_ASSERT(cmd, 6, 7.5);
2902
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002903 if (!ds) {
2904 /* all zeros */
2905 static const struct intel_ds_view null_ds;
2906 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002907 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002908
2909 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002910 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
2911 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
2912 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002913
2914 if (cmd_gen(cmd) >= INTEL_GEN(7))
2915 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2916 else
2917 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002918}
2919
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002920static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2921 const struct intel_pipeline *pipeline)
2922{
2923 cmd->bind.pipeline.graphics = pipeline;
2924}
2925
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002926static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2927 const struct intel_pipeline *pipeline)
2928{
2929 cmd->bind.pipeline.compute = pipeline;
2930}
2931
2932static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2933 const struct intel_pipeline_delta *delta)
2934{
2935 cmd->bind.pipeline.graphics_delta = delta;
2936}
2937
2938static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2939 const struct intel_pipeline_delta *delta)
2940{
2941 cmd->bind.pipeline.compute_delta = delta;
2942}
2943
2944static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002945 const struct intel_desc_set *dset,
2946 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002947{
Chia-I Wuf8385062015-01-04 16:27:24 +08002948 const uint32_t size = sizeof(*dynamic_offsets) *
2949 dset->layout->dynamic_desc_count;
2950
2951 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2952 if (cmd->bind.dset.graphics_dynamic_offsets)
2953 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2954
2955 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2956 4, XGL_SYSTEM_ALLOC_INTERNAL);
2957 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002958 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002959 return;
2960 }
2961
2962 cmd->bind.dset.graphics_dynamic_offset_size = size;
2963 }
2964
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002965 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002966 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002967}
2968
2969static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002970 const struct intel_desc_set *dset,
2971 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002972{
Chia-I Wuf8385062015-01-04 16:27:24 +08002973 const uint32_t size = sizeof(*dynamic_offsets) *
2974 dset->layout->dynamic_desc_count;
2975
2976 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2977 if (cmd->bind.dset.compute_dynamic_offsets)
2978 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2979
2980 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2981 4, XGL_SYSTEM_ALLOC_INTERNAL);
2982 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002983 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002984 return;
2985 }
2986
2987 cmd->bind.dset.compute_dynamic_offset_size = size;
2988 }
2989
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002990 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002991 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002992}
2993
Chia-I Wu3b04af52014-11-08 10:48:20 +08002994static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002995 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002996 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08002997{
Chia-I Wu714df452015-01-01 07:55:04 +08002998 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002999 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003000 return;
3001 }
3002
Chia-I Wu714df452015-01-01 07:55:04 +08003003 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003004 cmd->bind.vertex.offset[binding] = offset;
3005}
3006
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003007static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003008 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003009 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
3010{
Chia-I Wu714df452015-01-01 07:55:04 +08003011 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003012 cmd->bind.index.offset = offset;
3013 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003014}
3015
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003016static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003017 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003018{
3019 cmd->bind.state.viewport = state;
3020}
3021
3022static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003023 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003024{
3025 cmd->bind.state.raster = state;
3026}
3027
3028static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003029 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003030{
3031 cmd->bind.state.ds = state;
3032}
3033
3034static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003035 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003036{
3037 cmd->bind.state.blend = state;
3038}
3039
Chia-I Wuf98dd882015-02-10 04:17:47 +08003040static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3041{
3042 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3043 struct intel_pipeline_rmap *rmaps[5] = {
3044 pipeline->vs.rmap,
3045 pipeline->tcs.rmap,
3046 pipeline->tes.rmap,
3047 pipeline->gs.rmap,
3048 pipeline->fs.rmap,
3049 };
3050 uint32_t max_write;
3051 int i;
3052
3053 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3054 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3055 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3056
3057 /* pad first */
3058 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3059
3060 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3061 const struct intel_pipeline_rmap *rmap = rmaps[i];
3062 const uint32_t surface_count = (rmap) ?
3063 rmap->rt_count + rmap->texture_resource_count +
3064 rmap->resource_count + rmap->uav_count : 0;
3065
3066 if (surface_count) {
3067 /* SURFACE_STATEs */
3068 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3069
3070 /* BINDING_TABLE_STATE */
3071 max_write += u_align(sizeof(uint32_t) * surface_count,
3072 GEN6_ALIGNMENT_SURFACE_STATE);
3073 }
3074 }
3075
3076 return max_write;
3077}
3078
3079static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3080{
3081 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3082 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3083 uint32_t max_surface_write;
3084
3085 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3086 if (cmd->bind.meta)
3087 max_surface_write = 64 * sizeof(uint32_t);
3088 else
3089 max_surface_write = cmd_get_max_surface_write(cmd);
3090
3091 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3092 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3093 /* SBA expects page-aligned addresses */
3094 writer->sba_offset = writer->used & ~0xfff;
3095
3096 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3097
3098 cmd_batch_state_base_address(cmd);
3099 }
3100}
3101
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003102static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003103 uint32_t vertex_start,
3104 uint32_t vertex_count,
3105 uint32_t instance_start,
3106 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003107 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003108 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003109{
3110 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003111 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003112 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3113
3114 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003115
3116 emit_bounded_states(cmd);
3117
Chia-I Wuf98dd882015-02-10 04:17:47 +08003118 /* sanity check on cmd_get_max_surface_write() */
3119 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3120 surface_writer_used <= cmd_get_max_surface_write(cmd));
3121
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003122 if (indexed) {
3123 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003124 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003125
3126 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3127 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3128 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003129 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003130 cmd->bind.index.offset, cmd->bind.index.type,
3131 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003132 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003133 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003134 cmd->bind.index.offset, cmd->bind.index.type,
3135 p->primitive_restart);
3136 }
3137 } else {
3138 assert(!vertex_base);
3139 }
3140
3141 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3142 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3143 vertex_start, instance_count, instance_start, vertex_base);
3144 } else {
3145 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3146 vertex_start, instance_count, instance_start, vertex_base);
3147 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003148
Chia-I Wu707a29e2014-08-27 12:51:47 +08003149 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003150 /* need to re-emit all workarounds */
3151 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003152
3153 if (intel_debug & INTEL_DEBUG_NOCACHE)
3154 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003155}
3156
Chia-I Wuc14d1562014-10-17 09:49:22 +08003157void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3158{
Chia-I Wu6032b892014-10-17 14:47:18 +08003159 cmd->bind.meta = meta;
3160
Chia-I Wuf98dd882015-02-10 04:17:47 +08003161 cmd_adjust_state_base_address(cmd);
3162
Chia-I Wu6032b892014-10-17 14:47:18 +08003163 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003164 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003165
3166 gen6_meta_dynamic_states(cmd);
3167 gen6_meta_surface_states(cmd);
3168
3169 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3170 gen7_meta_urb(cmd);
3171 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003172 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003173 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003174 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003175 gen6_meta_wm(cmd);
3176 gen7_meta_ps(cmd);
3177 gen6_meta_depth_buffer(cmd);
3178
3179 cmd_wa_gen7_post_command_cs_stall(cmd);
3180 cmd_wa_gen7_post_command_depth_stall(cmd);
3181
Chia-I Wu29e6f502014-11-24 14:27:29 +08003182 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3183 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003184 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003185 } else {
3186 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3187 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003188 } else {
3189 gen6_meta_urb(cmd);
3190 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003191 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003192 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003193 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003194 gen6_meta_wm(cmd);
3195 gen6_meta_ps(cmd);
3196 gen6_meta_depth_buffer(cmd);
3197
Chia-I Wu29e6f502014-11-24 14:27:29 +08003198 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3199 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003200 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003201 } else {
3202 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3203 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003204 }
3205
3206 cmd->bind.draw_count++;
3207 /* need to re-emit all workarounds */
3208 cmd->bind.wa_flags = 0;
3209
3210 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003211
3212 if (intel_debug & INTEL_DEBUG_NOCACHE)
3213 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003214}
3215
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003216ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003217 XGL_CMD_BUFFER cmdBuffer,
3218 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3219 XGL_PIPELINE pipeline)
3220{
3221 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3222
3223 switch (pipelineBindPoint) {
3224 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003225 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003226 break;
3227 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003228 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003229 break;
3230 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003231 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003232 break;
3233 }
3234}
3235
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003236ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003237 XGL_CMD_BUFFER cmdBuffer,
3238 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3239 XGL_PIPELINE_DELTA delta)
3240{
3241 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3242
3243 switch (pipelineBindPoint) {
3244 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003245 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003246 break;
3247 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003248 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003249 break;
3250 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003251 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003252 break;
3253 }
3254}
3255
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003256ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003257 XGL_CMD_BUFFER cmdBuffer,
3258 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003259 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003260{
3261 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3262
3263 switch (stateBindPoint) {
3264 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003265 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003266 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003267 break;
3268 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003269 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003270 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003271 break;
3272 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003273 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003274 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003275 break;
3276 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003277 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003278 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003279 break;
3280 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003281 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003282 break;
3283 }
3284}
3285
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003286ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003287 XGL_CMD_BUFFER cmdBuffer,
3288 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003289 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003290 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003291{
3292 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003293 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003294
3295 switch (pipelineBindPoint) {
3296 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003297 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003298 break;
3299 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003300 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003301 break;
3302 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003303 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003304 break;
3305 }
3306}
3307
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003308ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003309 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003310 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003311 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003312 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003313{
3314 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003315 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003316
Chia-I Wu714df452015-01-01 07:55:04 +08003317 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003318}
3319
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003320ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003321 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003322 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003323 XGL_GPU_SIZE offset,
3324 XGL_INDEX_TYPE indexType)
3325{
3326 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003327 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003328
Chia-I Wu714df452015-01-01 07:55:04 +08003329 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003330}
3331
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003332ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003333 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003334 uint32_t firstVertex,
3335 uint32_t vertexCount,
3336 uint32_t firstInstance,
3337 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003338{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003339 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003340
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003341 cmd_draw(cmd, firstVertex, vertexCount,
3342 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003343}
3344
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003345ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003346 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003347 uint32_t firstIndex,
3348 uint32_t indexCount,
3349 int32_t vertexOffset,
3350 uint32_t firstInstance,
3351 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003352{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003353 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003354
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003355 cmd_draw(cmd, firstIndex, indexCount,
3356 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003357}
3358
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003359ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003360 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003361 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003362 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003363 uint32_t count,
3364 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003365{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003366 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3367
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003368 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003369}
3370
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003371ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003372 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003373 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003374 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003375 uint32_t count,
3376 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003377{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003378 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3379
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003380 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003381}
3382
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003383ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003384 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003385 uint32_t x,
3386 uint32_t y,
3387 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003388{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003389 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3390
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003391 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003392}
3393
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003394ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003395 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003396 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003397 XGL_GPU_SIZE offset)
3398{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003399 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3400
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003401 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003402}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003403
Chia-I Wude26bdf2015-02-18 15:47:12 -07003404ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003405 XGL_CMD_BUFFER cmdBuffer,
3406 XGL_RENDER_PASS renderPass)
3407{
3408 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3409
3410 cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
3411}
3412
Chia-I Wude26bdf2015-02-18 15:47:12 -07003413ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003414 XGL_CMD_BUFFER cmdBuffer,
3415 XGL_RENDER_PASS renderPass)
3416{
3417 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3418
3419 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3420}