blob: 9395e537c85ac27b4c7047081d14c78a5f86f71d [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wub2755562014-08-20 13:38:52 +080030#include "dset.h"
Chia-I Wu714df452015-01-01 07:55:04 +080031#include "buf.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
109 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
221 case XGL_INDEX_8:
222 supported = (p->primitive_restart_index != 0xffu);
223 break;
224 case XGL_INDEX_16:
225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
227 case XGL_INDEX_32:
228 supported = (p->primitive_restart_index != 0xffffffffu);
229 break;
230 default:
231 supported = false;
232 break;
233 }
234
235 return supported;
236}
237
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800239 const struct intel_buf *buf,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800240 XGL_GPU_SIZE offset,
241 XGL_INDEX_TYPE type,
242 bool enable_cut_index)
243{
244 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800247 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
260 case XGL_INDEX_8:
261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
264 case XGL_INDEX_16:
265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
268 case XGL_INDEX_32:
269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
273 cmd->result = XGL_ERROR_INVALID_VALUE;
274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
279 cmd->result = XGL_ERROR_INVALID_VALUE;
280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600312
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800313static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
314{
315 const uint8_t cmd_len = 7;
316 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800318
319 CMD_ASSERT(cmd, 6, 6);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 cmd_batch_pointer(cmd, cmd_len, &dw);
340 dw[0] = dw0;
341 dw[1] = 0;
342 dw[2] = 0;
343 dw[3] = 0;
344 dw[4] = 0;
345 dw[5] = GEN6_GS_DW5_STATISTICS;
346 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800347}
348
Chia-I Wud88e02d2014-08-25 10:56:13 +0800349static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
350 XGL_UINT width, XGL_UINT height)
351{
352 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800353 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800355 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800356
357 CMD_ASSERT(cmd, 6, 7.5);
358
Chia-I Wu72292b72014-09-09 10:48:33 +0800359 cmd_batch_pointer(cmd, cmd_len, &dw);
360 dw[0] = dw0;
361
Chia-I Wud88e02d2014-08-25 10:56:13 +0800362 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 dw[1] = 0;
364 dw[2] = (height - 1) << 16 |
365 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800366 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800367 dw[1] = 1;
368 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800369 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800370
371 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800372}
373
Chia-I Wu8016a172014-08-29 18:31:32 +0800374static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
375 uint32_t body[6])
376{
377 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700389 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
394 switch (pipeline->db_format.channelFormat) {
395 case XGL_CH_FMT_R16:
396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
398 case XGL_CH_FMT_R32:
399 case XGL_CH_FMT_R32G8:
400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700403 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
Tony Barbourfa6cac72015-01-16 14:27:35 -0700411 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800412
Tony Barbourfa6cac72015-01-16 14:27:35 -0700413 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
Tony Barbourfa6cac72015-01-16 14:27:35 -0700421 if (pipeline->scissor_enable)
Chia-I Wu8016a172014-08-29 18:31:32 +0800422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700425 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
Chia-I Wu8016a172014-08-29 18:31:32 +0800426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700438 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
439 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
440 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800441}
442
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
GregF8cd81832014-11-18 18:01:01 -0700446 XGL_UINT sbe_offset;
447 XGL_INT i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448
449 CMD_ASSERT(cmd, 6, 7.5);
450
GregF8cd81832014-11-18 18:01:01 -0700451 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452
GregF8cd81832014-11-18 18:01:01 -0700453 for (i = 0; i < 13; i++) {
454 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
455 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800456 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800457}
458
459static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
460{
461 const uint8_t cmd_len = 20;
462 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
463 (cmd_len - 2);
464 uint32_t sf[6];
465 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 6, 6);
469
470 gen7_fill_3DSTATE_SF_body(cmd, sf);
471 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
474 dw[0] = dw0;
475 dw[1] = sbe[0];
476 memcpy(&dw[2], sf, sizeof(sf));
477 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800478}
479
480static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
481{
482 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800483 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800484
485 CMD_ASSERT(cmd, 7, 7.5);
486
Chia-I Wu72292b72014-09-09 10:48:33 +0800487 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
489 (cmd_len - 2);
490 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800491}
492
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800493static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
494{
495 const uint8_t cmd_len = 4;
496 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
497 (cmd_len - 2);
498 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700499 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800500 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700501 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800502 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800503
504 CMD_ASSERT(cmd, 6, 7.5);
505
506 dw1 = GEN6_CLIP_DW1_STATISTICS;
507 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
508 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
509 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700510 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800511 }
512
513 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
514 GEN6_CLIP_DW2_XY_TEST_ENABLE |
515 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700516 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800517 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
518 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
519 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
520
521 if (pipeline->rasterizerDiscardEnable)
522 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
523 else
524 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
525
526 if (pipeline->depthClipEnable)
527 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
528
529 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
530 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
531 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
532 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
533
534 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
535 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
536 (viewport->viewport_count - 1);
537
Chia-I Wu72292b72014-09-09 10:48:33 +0800538 cmd_batch_pointer(cmd, cmd_len, &dw);
539 dw[0] = dw0;
540 dw[1] = dw1;
541 dw[2] = dw2;
542 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800543}
544
Chia-I Wu784d3042014-12-19 14:30:04 +0800545static void gen6_add_scratch_space(struct intel_cmd *cmd,
546 XGL_UINT batch_pos,
547 const struct intel_pipeline *pipeline,
548 const struct intel_pipeline_shader *sh)
549{
550 int scratch_space;
551
552 CMD_ASSERT(cmd, 6, 7.5);
553
554 assert(sh->per_thread_scratch_size &&
555 sh->per_thread_scratch_size % 1024 == 0 &&
556 u_is_pow2(sh->per_thread_scratch_size) &&
557 sh->scratch_offset % 1024 == 0);
558 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
559
560 cmd_reserve_reloc(cmd, 1);
561 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
562 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
563}
564
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800565static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
566{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800567 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800568 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800569 const uint8_t cmd_len = 9;
Chia-I Wu784d3042014-12-19 14:30:04 +0800570 XGL_UINT pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800571 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572
573 CMD_ASSERT(cmd, 6, 6);
574
575 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
576
577 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
578 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
579
580 dw4 = GEN6_WM_DW4_STATISTICS |
581 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
582 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
583 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
584
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800585 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800586 GEN6_WM_DW5_PS_ENABLE |
587 GEN6_WM_DW5_8_PIXEL_DISPATCH;
588
589 if (fs->uses & INTEL_SHADER_USE_KILL ||
590 pipeline->cb_state.alphaToCoverageEnable)
591 dw5 |= GEN6_WM_DW5_PS_KILL;
592
Cody Northrope238deb2015-01-26 14:41:36 -0700593 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800594 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
595 if (fs->uses & INTEL_SHADER_USE_DEPTH)
596 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
597 if (fs->uses & INTEL_SHADER_USE_W)
598 dw5 |= GEN6_WM_DW5_PS_USE_W;
599
600 if (pipeline->cb_state.dualSourceBlendEnable)
601 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
602
603 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
604 GEN6_WM_DW6_POSOFFSET_NONE |
605 GEN6_WM_DW6_ZW_INTERP_PIXEL |
606 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
607 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
608
Tony Barbourfa6cac72015-01-16 14:27:35 -0700609 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800610 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
611 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
612 } else {
613 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
614 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
615 }
616
Chia-I Wu784d3042014-12-19 14:30:04 +0800617 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800618 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800619 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800620 dw[2] = dw2;
621 dw[3] = 0; /* scratch */
622 dw[4] = dw4;
623 dw[5] = dw5;
624 dw[6] = dw6;
625 dw[7] = 0; /* kernel 1 */
626 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800627
628 if (fs->per_thread_scratch_size)
629 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800630}
631
632static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
633{
634 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800635 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800636 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800637 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638
639 CMD_ASSERT(cmd, 7, 7.5);
640
641 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
642
643 dw1 = GEN7_WM_DW1_STATISTICS |
644 GEN7_WM_DW1_PS_ENABLE |
645 GEN7_WM_DW1_ZW_INTERP_PIXEL |
646 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
647 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
648
649 if (fs->uses & INTEL_SHADER_USE_KILL ||
650 pipeline->cb_state.alphaToCoverageEnable)
651 dw1 |= GEN7_WM_DW1_PS_KILL;
652
Cody Northrope238deb2015-01-26 14:41:36 -0700653 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
654
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800655 if (fs->uses & INTEL_SHADER_USE_DEPTH)
656 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
657 if (fs->uses & INTEL_SHADER_USE_W)
658 dw1 |= GEN7_WM_DW1_PS_USE_W;
659
660 dw2 = 0;
661
Tony Barbourfa6cac72015-01-16 14:27:35 -0700662 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800663 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
664 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
665 } else {
666 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
667 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
668 }
669
Chia-I Wu72292b72014-09-09 10:48:33 +0800670 cmd_batch_pointer(cmd, cmd_len, &dw);
671 dw[0] = dw0;
672 dw[1] = dw1;
673 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800674}
675
676static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
677{
678 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800679 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800680 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800681 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +0800682 XGL_UINT pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800683
684 CMD_ASSERT(cmd, 7, 7.5);
685
686 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
687
688 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
689 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
690
691 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
692 GEN7_PS_DW4_8_PIXEL_DISPATCH;
693
694 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800695 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700696 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800698 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800699 }
700
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800701 if (fs->in_count)
702 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
703
704 if (pipeline->cb_state.dualSourceBlendEnable)
705 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
706
707 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
708 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
709 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
710
Chia-I Wu784d3042014-12-19 14:30:04 +0800711 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800712 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800713 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800714 dw[2] = dw2;
715 dw[3] = 0; /* scratch */
716 dw[4] = dw4;
717 dw[5] = dw5;
718 dw[6] = 0; /* kernel 1 */
719 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800720
721 if (fs->per_thread_scratch_size)
722 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723}
724
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800725static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
726 const struct intel_ds_view *view)
727{
728 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800729 uint32_t dw0, *dw;
730 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800731
732 CMD_ASSERT(cmd, 6, 7.5);
733
734 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800735 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
736 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800737 dw0 |= (cmd_len - 2);
738
Chia-I Wu72292b72014-09-09 10:48:33 +0800739 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
740 dw[0] = dw0;
741 dw[1] = view->cmd[0];
742 dw[2] = 0;
743 dw[3] = view->cmd[2];
744 dw[4] = view->cmd[3];
745 dw[5] = view->cmd[4];
746 dw[6] = view->cmd[5];
747
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600748 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800749 cmd_reserve_reloc(cmd, 1);
750 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
751 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600752 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800753}
754
755static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
756 const struct intel_ds_view *view)
757{
758 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800759 uint32_t dw0, *dw;
760 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800761
762 CMD_ASSERT(cmd, 6, 7.5);
763
764 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800765 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
766 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767 dw0 |= (cmd_len - 2);
768
Chia-I Wu72292b72014-09-09 10:48:33 +0800769 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
770 dw[0] = dw0;
771 dw[1] = view->cmd[6];
772 dw[2] = 0;
773
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600774 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800775 cmd_reserve_reloc(cmd, 1);
776 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
777 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600778 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800779}
780
781static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
782 const struct intel_ds_view *view)
783{
784 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 uint32_t dw0, *dw;
786 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800787
788 CMD_ASSERT(cmd, 6, 7.5);
789
790 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800791 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
792 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793 dw0 |= (cmd_len - 2);
794
Chia-I Wu72292b72014-09-09 10:48:33 +0800795 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
796 dw[0] = dw0;
797 dw[1] = view->cmd[8];
798 dw[2] = 0;
799
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600800 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 cmd_reserve_reloc(cmd, 1);
802 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
803 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600804 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800805}
806
Chia-I Wuf8231032014-08-25 10:44:45 +0800807static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
808 uint32_t clear_val)
809{
810 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800811 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800812 GEN6_CLEAR_PARAMS_DW0_VALID |
813 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800814 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800815
816 CMD_ASSERT(cmd, 6, 6);
817
Chia-I Wu72292b72014-09-09 10:48:33 +0800818 cmd_batch_pointer(cmd, cmd_len, &dw);
819 dw[0] = dw0;
820 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800821}
822
823static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
824 uint32_t clear_val)
825{
826 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800827 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800828 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800829 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800830
831 CMD_ASSERT(cmd, 7, 7.5);
832
Chia-I Wu72292b72014-09-09 10:48:33 +0800833 cmd_batch_pointer(cmd, cmd_len, &dw);
834 dw[0] = dw0;
835 dw[1] = clear_val;
836 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800837}
838
Chia-I Wu302742d2014-08-22 10:28:29 +0800839static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800840 uint32_t blend_offset,
841 uint32_t ds_offset,
842 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800843{
844 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800846
847 CMD_ASSERT(cmd, 6, 6);
848
Chia-I Wu426072d2014-08-26 14:31:55 +0800849 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800850 (cmd_len - 2);
851
Chia-I Wu72292b72014-09-09 10:48:33 +0800852 cmd_batch_pointer(cmd, cmd_len, &dw);
853 dw[0] = dw0;
854 dw[1] = blend_offset | 1;
855 dw[2] = ds_offset | 1;
856 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800857}
858
Chia-I Wu1744cca2014-08-22 11:10:17 +0800859static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800860 uint32_t clip_offset,
861 uint32_t sf_offset,
862 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800863{
864 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800866
867 CMD_ASSERT(cmd, 6, 6);
868
Chia-I Wu426072d2014-08-26 14:31:55 +0800869 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800870 GEN6_PTR_VP_DW0_CLIP_CHANGED |
871 GEN6_PTR_VP_DW0_SF_CHANGED |
872 GEN6_PTR_VP_DW0_CC_CHANGED |
873 (cmd_len - 2);
874
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 cmd_batch_pointer(cmd, cmd_len, &dw);
876 dw[0] = dw0;
877 dw[1] = clip_offset;
878 dw[2] = sf_offset;
879 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800880}
881
882static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800883 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800884{
885 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800886 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800887
888 CMD_ASSERT(cmd, 6, 6);
889
Chia-I Wu426072d2014-08-26 14:31:55 +0800890 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800891 (cmd_len - 2);
892
Chia-I Wu72292b72014-09-09 10:48:33 +0800893 cmd_batch_pointer(cmd, cmd_len, &dw);
894 dw[0] = dw0;
895 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896}
897
Chia-I Wu42a56202014-08-23 16:47:48 +0800898static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800899 uint32_t vs_offset,
900 uint32_t gs_offset,
901 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800902{
903 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800905
906 CMD_ASSERT(cmd, 6, 6);
907
Chia-I Wu426072d2014-08-26 14:31:55 +0800908 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800909 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
910 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
911 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
912 (cmd_len - 2);
913
Chia-I Wu72292b72014-09-09 10:48:33 +0800914 cmd_batch_pointer(cmd, cmd_len, &dw);
915 dw[0] = dw0;
916 dw[1] = vs_offset;
917 dw[2] = gs_offset;
918 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800919}
920
Chia-I Wu257e75e2014-08-29 14:06:35 +0800921static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 uint32_t vs_offset,
923 uint32_t gs_offset,
924 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800925{
926 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800928
929 CMD_ASSERT(cmd, 6, 6);
930
931 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
932 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
933 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
934 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
935 (cmd_len - 2);
936
Chia-I Wu72292b72014-09-09 10:48:33 +0800937 cmd_batch_pointer(cmd, cmd_len, &dw);
938 dw[0] = dw0;
939 dw[1] = vs_offset;
940 dw[2] = gs_offset;
941 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800942}
943
Chia-I Wu302742d2014-08-22 10:28:29 +0800944static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800946{
947 const uint8_t cmd_len = 2;
948 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
949 GEN6_RENDER_SUBTYPE_3D |
950 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800951 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800952
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 cmd_batch_pointer(cmd, cmd_len, &dw);
954 dw[0] = dw0;
955 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800956}
957
Chia-I Wua6c4f152014-12-02 04:19:58 +0800958static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800959{
Chia-I Wue6073342014-11-30 09:43:42 +0800960 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700961 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
962 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800963
964 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700965 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800966
Tony Barbourfa6cac72015-01-16 14:27:35 -0700967 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800968}
969
Chia-I Wu72292b72014-09-09 10:48:33 +0800970static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700971 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800972{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700973 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800974 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800975 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700976 uint32_t dw[3];
977
978 dw[0] = pipeline->cmd_depth_stencil;
979 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
980 (state->ds_info.stencilWriteMask & 0xff) << 16;
981 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800982
983 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700984
985 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
986 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987
Chia-I Wu00b51a82014-09-09 12:07:37 +0800988 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700989 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800990}
991
Chia-I Wu72292b72014-09-09 10:48:33 +0800992static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800993 uint32_t stencil_ref,
994 const uint32_t blend_color[4])
995{
Chia-I Wue6073342014-11-30 09:43:42 +0800996 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800997 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +0800998 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800999
1000 CMD_ASSERT(cmd, 6, 7.5);
1001
Chia-I Wu00b51a82014-09-09 12:07:37 +08001002 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1003 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001004 dw[0] = stencil_ref;
1005 dw[1] = 0;
1006 dw[2] = blend_color[0];
1007 dw[3] = blend_color[1];
1008 dw[4] = blend_color[2];
1009 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001010
Chia-I Wu72292b72014-09-09 10:48:33 +08001011 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001012}
1013
Chia-I Wu8370b402014-08-29 12:28:37 +08001014static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001015{
Chia-I Wu8370b402014-08-29 12:28:37 +08001016 CMD_ASSERT(cmd, 6, 7.5);
1017
Chia-I Wu707a29e2014-08-27 12:51:47 +08001018 if (!cmd->bind.draw_count)
1019 return;
1020
Chia-I Wu8370b402014-08-29 12:28:37 +08001021 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001022 return;
1023
Chia-I Wu8370b402014-08-29 12:28:37 +08001024 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001025
1026 /*
1027 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1028 *
1029 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1030 * pipe-control with a post-sync op and no write-cache flushes."
1031 *
1032 * The workaround below necessitates this workaround.
1033 */
1034 gen6_PIPE_CONTROL(cmd,
1035 GEN6_PIPE_CONTROL_CS_STALL |
1036 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001037 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001038
Chia-I Wud6d079d2014-08-31 13:14:21 +08001039 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1040 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001041}
1042
Chia-I Wu8370b402014-08-29 12:28:37 +08001043static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001044{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001045 CMD_ASSERT(cmd, 6, 7.5);
1046
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001047 if (!cmd->bind.draw_count)
1048 return;
1049
Chia-I Wud6d079d2014-08-31 13:14:21 +08001050 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1051 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001052}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001053
Chia-I Wu8370b402014-08-29 12:28:37 +08001054static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1055{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001056 CMD_ASSERT(cmd, 7, 7.5);
1057
Chia-I Wu8370b402014-08-29 12:28:37 +08001058 if (!cmd->bind.draw_count)
1059 return;
1060
1061 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001062
1063 gen6_PIPE_CONTROL(cmd,
1064 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001065 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001066}
1067
Chia-I Wu8370b402014-08-29 12:28:37 +08001068static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1069{
1070 CMD_ASSERT(cmd, 7, 7.5);
1071
1072 if (!cmd->bind.draw_count)
1073 return;
1074
1075 /*
1076 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1077 *
1078 * "One of the following must also be set (when CS stall is set):
1079 *
1080 * * Render Target Cache Flush Enable ([12] of DW1)
1081 * * Depth Cache Flush Enable ([0] of DW1)
1082 * * Stall at Pixel Scoreboard ([1] of DW1)
1083 * * Depth Stall ([13] of DW1)
1084 * * Post-Sync Operation ([13] of DW1)"
1085 */
1086 gen6_PIPE_CONTROL(cmd,
1087 GEN6_PIPE_CONTROL_CS_STALL |
1088 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001089 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001090}
1091
1092static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1093{
1094 CMD_ASSERT(cmd, 7, 7.5);
1095
1096 if (!cmd->bind.draw_count)
1097 return;
1098
1099 cmd_wa_gen6_pre_depth_stall_write(cmd);
1100
Chia-I Wud6d079d2014-08-31 13:14:21 +08001101 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001102}
1103
1104static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1105{
1106 CMD_ASSERT(cmd, 6, 7.5);
1107
1108 if (!cmd->bind.draw_count)
1109 return;
1110
1111 /*
1112 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1113 *
1114 * "Driver must guarentee that all the caches in the depth pipe are
1115 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1116 * requires driver to send a PIPE_CONTROL with a CS stall along with
1117 * a Depth Flush prior to this command."
1118 *
1119 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1120 *
1121 * "Driver must ierarchi that all the caches in the depth pipe are
1122 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1123 * requires driver to send a PIPE_CONTROL with a CS stall along with
1124 * a Depth Flush prior to this command.
1125 */
1126 gen6_PIPE_CONTROL(cmd,
1127 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1128 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001129 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001130}
1131
1132static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1133{
1134 CMD_ASSERT(cmd, 6, 7.5);
1135
1136 if (!cmd->bind.draw_count)
1137 return;
1138
1139 /*
1140 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1141 *
1142 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1143 * and a post sync operation prior to the group of depth
1144 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1145 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1146 *
1147 * This workaround satifies all the conditions.
1148 */
1149 cmd_wa_gen6_pre_depth_stall_write(cmd);
1150
1151 /*
1152 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1153 *
1154 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1155 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1156 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1157 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1158 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1159 * Depth Flush Bit set, followed by another pipelined depth stall
1160 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1161 * guarantee that the pipeline from WM onwards is already flushed
1162 * (e.g., via a preceding MI_FLUSH)."
1163 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001164 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1165 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1166 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001167}
1168
Chia-I Wu525c6602014-08-27 10:22:34 +08001169void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1170{
1171 if (!cmd->bind.draw_count)
1172 return;
1173
1174 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1175
Chia-I Wu8370b402014-08-29 12:28:37 +08001176 /*
1177 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1178 *
1179 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1180 * PIPE_CONTROL with any non-zero post-sync-op is required."
1181 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001182 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001183 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001184
Chia-I Wu092279a2014-08-30 19:05:30 +08001185 /*
1186 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1187 *
1188 * "One of the following must also be set (when CS stall is set):
1189 *
1190 * * Render Target Cache Flush Enable ([12] of DW1)
1191 * * Depth Cache Flush Enable ([0] of DW1)
1192 * * Stall at Pixel Scoreboard ([1] of DW1)
1193 * * Depth Stall ([13] of DW1)
1194 * * Post-Sync Operation ([13] of DW1)"
1195 */
1196 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1197 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1198 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1199 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1200 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1201 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1202
Chia-I Wud6d079d2014-08-31 13:14:21 +08001203 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001204}
1205
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001206void cmd_batch_flush_all(struct intel_cmd *cmd)
1207{
1208 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1209 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1210 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1211 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1212 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1213 GEN6_PIPE_CONTROL_CS_STALL);
1214}
1215
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001216void cmd_batch_depth_count(struct intel_cmd *cmd,
1217 struct intel_bo *bo,
1218 XGL_GPU_SIZE offset)
1219{
1220 cmd_wa_gen6_pre_depth_stall_write(cmd);
1221
1222 gen6_PIPE_CONTROL(cmd,
1223 GEN6_PIPE_CONTROL_DEPTH_STALL |
1224 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001225 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001226}
1227
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001228void cmd_batch_timestamp(struct intel_cmd *cmd,
1229 struct intel_bo *bo,
1230 XGL_GPU_SIZE offset)
1231{
1232 /* need any WA or stall? */
1233 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1234}
1235
1236void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001237 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001238 struct intel_bo *bo,
1239 XGL_GPU_SIZE offset,
1240 uint64_t val)
1241{
1242 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001243 gen6_PIPE_CONTROL(cmd,
1244 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1245 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001246}
1247
Chia-I Wu302742d2014-08-22 10:28:29 +08001248static void gen6_cc_states(struct intel_cmd *cmd)
1249{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001250 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1251 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001252 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001253 uint32_t stencil_ref;
1254 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001255
1256 CMD_ASSERT(cmd, 6, 6);
1257
Chia-I Wua6c4f152014-12-02 04:19:58 +08001258 blend_offset = gen6_BLEND_STATE(cmd);
1259
1260 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001261 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001262 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001263 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001264
1265 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001266 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001267 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1268 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001269 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001270 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001271 stencil_ref = 0;
1272 }
1273
Chia-I Wu72292b72014-09-09 10:48:33 +08001274 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001275
Chia-I Wu72292b72014-09-09 10:48:33 +08001276 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001277}
1278
Chia-I Wu1744cca2014-08-22 11:10:17 +08001279static void gen6_viewport_states(struct intel_cmd *cmd)
1280{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001281 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001282 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001283
1284 if (!viewport)
1285 return;
1286
Tony Barbourfa6cac72015-01-16 14:27:35 -07001287 assert(viewport->cmd_len == (8 + 4 + 2) *
1288 viewport->viewport_count + (viewport->has_scissor_rects) ?
1289 (viewport->viewport_count * 2) : 0);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001290
1291 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001292 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001293 viewport->cmd);
1294
1295 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001296 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001297 &viewport->cmd[viewport->cmd_clip_pos]);
1298
1299 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001300 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001301 &viewport->cmd[viewport->cmd_cc_pos]);
1302
Tony Barbourfa6cac72015-01-16 14:27:35 -07001303 if (viewport->has_scissor_rects) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001304 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001305 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001306 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1307 } else {
1308 scissor_offset = 0;
1309 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001310
1311 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001312 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001313
Chia-I Wub1d450a2014-09-09 13:48:03 +08001314 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001315}
1316
Chia-I Wu302742d2014-08-22 10:28:29 +08001317static void gen7_cc_states(struct intel_cmd *cmd)
1318{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001319 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1320 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001321 uint32_t stencil_ref;
1322 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001323 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001324
1325 CMD_ASSERT(cmd, 7, 7.5);
1326
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001327 if (!blend && !ds)
1328 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001329
Chia-I Wua6c4f152014-12-02 04:19:58 +08001330 offset = gen6_BLEND_STATE(cmd);
1331 gen7_3dstate_pointer(cmd,
1332 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001333
Chia-I Wua6c4f152014-12-02 04:19:58 +08001334 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001335 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001336 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001337 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001338
1339 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001340 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001341 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1342 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001343 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001344 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1345 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001346 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1347 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001348 } else {
1349 stencil_ref = 0;
1350 }
1351
Chia-I Wu72292b72014-09-09 10:48:33 +08001352 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001353 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001354 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001355}
1356
Chia-I Wu1744cca2014-08-22 11:10:17 +08001357static void gen7_viewport_states(struct intel_cmd *cmd)
1358{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001359 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
1360 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001361 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001362
1363 if (!viewport)
1364 return;
1365
Tony Barbourfa6cac72015-01-16 14:27:35 -07001366 assert(viewport->cmd_len == (16 + 2 + 2 * pipeline->scissor_enable) *
Chia-I Wub1d450a2014-09-09 13:48:03 +08001367 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001368
Chia-I Wub1d450a2014-09-09 13:48:03 +08001369 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001370 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001371 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001372 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001373 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1374 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001375
1376 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001377 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001378 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001379 gen7_3dstate_pointer(cmd,
1380 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001381 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001382
Tony Barbourfa6cac72015-01-16 14:27:35 -07001383 if (pipeline->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001384 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001385 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001386 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001387 gen7_3dstate_pointer(cmd,
1388 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001389 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001390 }
1391}
1392
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001393static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001394 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001395{
1396 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001397 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001398
Chia-I Wu72292b72014-09-09 10:48:33 +08001399 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001400
1401 dw[0] = GEN6_RENDER_TYPE_RENDER |
1402 GEN6_RENDER_SUBTYPE_3D |
1403 subop | (cmd_len - 2);
1404 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001405 dw[2] = 0;
1406 dw[3] = 0;
1407 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001408}
1409
1410static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001411 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001412{
1413 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001414 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001415
Chia-I Wu72292b72014-09-09 10:48:33 +08001416 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001417
1418 dw[0] = GEN6_RENDER_TYPE_RENDER |
1419 GEN6_RENDER_SUBTYPE_3D |
1420 subop | (cmd_len - 2);
1421 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001422 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001423 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001424 dw[4] = 0;
1425 dw[5] = 0;
1426 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001427}
1428
Chia-I Wu625105f2014-10-13 15:35:29 +08001429static uint32_t emit_samplers(struct intel_cmd *cmd,
1430 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001431{
1432 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1433 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001434 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001435 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001436 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001437 XGL_UINT i;
1438
1439 CMD_ASSERT(cmd, 6, 7.5);
1440
Chia-I Wu625105f2014-10-13 15:35:29 +08001441 if (!rmap || !rmap->sampler_count)
1442 return 0;
1443
Cody Northrop40316a32014-12-09 19:08:33 -07001444 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001445
Chia-I Wudcb509d2014-12-10 08:53:10 +08001446 /*
1447 * note that we cannot call cmd_state_pointer() here as the following
1448 * cmd_state_pointer() would invalidate the pointer
1449 */
1450 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001451 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001452 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001453
1454 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001455 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001456 4 * rmap->sampler_count, &sampler_dw);
1457
Chia-I Wudcb509d2014-12-10 08:53:10 +08001458 cmd_state_update(cmd, border_offset,
1459 border_stride * rmap->sampler_count, &border_dw);
1460
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001461 for (i = 0; i < rmap->sampler_count; i++) {
1462 const struct intel_pipeline_rmap_slot *slot =
1463 &rmap->slots[surface_count + i];
1464 const struct intel_sampler *sampler;
1465
1466 switch (slot->path_len) {
1467 case 0:
1468 sampler = NULL;
1469 break;
1470 case INTEL_PIPELINE_RMAP_SLOT_RT:
1471 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1472 assert(!"unexpected rmap slot type");
1473 sampler = NULL;
1474 break;
1475 case 1:
1476 {
1477 const struct intel_dset *dset = cmd->bind.dset.graphics;
1478 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1479 const struct intel_dset_slot *dset_slot =
1480 &dset->slots[slot_offset + slot->u.index];
1481
1482 switch (dset_slot->type) {
1483 case INTEL_DSET_SLOT_SAMPLER:
1484 sampler = dset_slot->u.sampler;
1485 break;
1486 default:
1487 assert(!"unexpected dset slot type");
1488 sampler = NULL;
1489 break;
1490 }
1491 }
1492 break;
1493 default:
1494 assert(!"nested descriptor set unsupported");
1495 sampler = NULL;
1496 break;
1497 }
1498
1499 if (sampler) {
1500 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1501
1502 sampler_dw[0] = sampler->cmd[0];
1503 sampler_dw[1] = sampler->cmd[1];
1504 sampler_dw[2] = border_offset;
1505 sampler_dw[3] = sampler->cmd[2];
1506 } else {
1507 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1508 sampler_dw[1] = 0;
1509 sampler_dw[2] = 0;
1510 sampler_dw[3] = 0;
1511 }
1512
1513 border_offset += border_stride * 4;
1514 border_dw += border_stride;
1515 sampler_dw += 4;
1516 }
1517
Chia-I Wu625105f2014-10-13 15:35:29 +08001518 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001519}
1520
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001521static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001522 const struct intel_pipeline_rmap *rmap,
1523 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001524{
Chia-I Wu72292b72014-09-09 10:48:33 +08001525 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001526 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001527
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001528 CMD_ASSERT(cmd, 6, 7.5);
1529
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001530 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001531 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001532 if (!surface_count)
1533 return 0;
1534
Chia-I Wu42a56202014-08-23 16:47:48 +08001535 assert(surface_count <= ARRAY_SIZE(binding_table));
1536
1537 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001538 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001539
1540 switch (slot->path_len) {
1541 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001542 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001543 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001544 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001545 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001546 const struct intel_rt_view *view =
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001547 (slot->u.index < cmd->bind.render_pass->fb->rt_count) ?
1548 cmd->bind.render_pass->fb->rt[slot->u.index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001549
Chia-I Wu787a05b2014-12-05 11:02:20 +08001550 if (view) {
1551 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1552 GEN6_ALIGNMENT_SURFACE_STATE,
1553 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001554
Chia-I Wu787a05b2014-12-05 11:02:20 +08001555 cmd_reserve_reloc(cmd, 1);
1556 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1557 view->cmd[1], INTEL_RELOC_WRITE);
1558 } else {
1559 struct intel_null_view null_view;
1560 intel_null_view_init(&null_view, cmd->dev);
1561
1562 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1563 GEN6_ALIGNMENT_SURFACE_STATE,
1564 null_view.cmd_len, null_view.cmd);
1565 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001566 }
1567 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001568 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001569 {
Chia-I Wu714df452015-01-01 07:55:04 +08001570 const struct intel_buf_view *view =
1571 cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001572
Chia-I Wu00b51a82014-09-09 12:07:37 +08001573 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001574 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001575 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001576
Chia-I Wu72292b72014-09-09 10:48:33 +08001577 cmd_reserve_reloc(cmd, 1);
Chia-I Wu714df452015-01-01 07:55:04 +08001578 cmd_surface_reloc(cmd, offset, 1, view->buf->obj.mem->bo,
Chia-I Wu72292b72014-09-09 10:48:33 +08001579 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001580 }
1581 break;
1582 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001583 {
1584 const struct intel_dset *dset = cmd->bind.dset.graphics;
1585 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1586 const struct intel_dset_slot *dset_slot =
1587 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001588 const uint32_t reloc_flags =
1589 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001590
1591 switch (dset_slot->type) {
1592 case INTEL_DSET_SLOT_IMG_VIEW:
1593 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001594 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001595 dset_slot->u.img_view->cmd_len,
1596 dset_slot->u.img_view->cmd);
1597
1598 cmd_reserve_reloc(cmd, 1);
1599 cmd_surface_reloc(cmd, offset, 1,
1600 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001601 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001602 break;
Chia-I Wu714df452015-01-01 07:55:04 +08001603 case INTEL_DSET_SLOT_BUF_VIEW:
Cody Northrop7c76f302014-12-18 11:52:58 -07001604 {
Chia-I Wu714df452015-01-01 07:55:04 +08001605 XGL_BUFFER_VIEW_CREATE_INFO tmp_info =
1606 dset_slot->u.buf_view->info;
1607 struct intel_buf_view *tmp;
1608 XGL_RESULT res;
Cody Northrop7c76f302014-12-18 11:52:58 -07001609
1610 /* The compiler expects uniform buffers to have pitch of
1611 * 4 for fragment shaders, but 16 for other stages.
1612 */
Cody Northropbef0e552015-01-13 12:13:46 -07001613 tmp_info.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
1614 tmp_info.format.numericFormat = XGL_NUM_FMT_FLOAT;
Cody Northrop7c76f302014-12-18 11:52:58 -07001615 if (XGL_SHADER_STAGE_FRAGMENT == stage) {
1616 tmp_info.stride = 4;
1617 } else {
1618 tmp_info.stride = 16;
1619 }
1620
Chia-I Wu714df452015-01-01 07:55:04 +08001621 res = intel_buf_view_create(cmd->dev, &tmp_info, &tmp);
1622 if (res != XGL_SUCCESS) {
1623 cmd->result = res;
1624 break;
1625 }
Cody Northrop7c76f302014-12-18 11:52:58 -07001626
1627 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1628 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu714df452015-01-01 07:55:04 +08001629 tmp->cmd_len,
1630 tmp->cmd);
Cody Northrop7c76f302014-12-18 11:52:58 -07001631
1632 cmd_reserve_reloc(cmd, 1);
1633 cmd_surface_reloc(cmd, offset, 1,
Chia-I Wu714df452015-01-01 07:55:04 +08001634 dset_slot->u.buf_view->buf->obj.mem->bo,
1635 tmp->cmd[1], reloc_flags);
1636
1637 intel_buf_view_destroy(tmp);
Cody Northrop7c76f302014-12-18 11:52:58 -07001638 }
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001639 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001640 case INTEL_DSET_SLOT_SAMPLER:
1641 assert(0 == cmd->bind.dset.graphics_offset);
1642
1643 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001644 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001645 16, dset_slot->u.sampler->cmd);
1646 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001647 default:
1648 assert(!"unexpected dset slot type");
1649 break;
1650 }
1651 }
1652 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001653 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001654 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001655 break;
1656 }
1657
Chia-I Wu72292b72014-09-09 10:48:33 +08001658 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001659 }
1660
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001661 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001662 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001663 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001664}
1665
Chia-I Wu1d125092014-10-08 08:49:38 +08001666static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1667{
1668 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001669 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1670 uint32_t *dw;
1671 XGL_UINT pos, i;
1672
1673 CMD_ASSERT(cmd, 6, 7.5);
1674
1675 if (!pipeline->vb_count)
1676 return;
1677
1678 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1679
1680 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1681 dw++;
1682 pos++;
1683
1684 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001685 assert(pipeline->vb[i].strideInBytes <= 2048);
1686
1687 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1688 pipeline->vb[i].strideInBytes;
1689
1690 if (cmd_gen(cmd) >= INTEL_GEN(7))
1691 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1692
1693 switch (pipeline->vb[i].stepRate) {
1694 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1695 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1696 dw[3] = 0;
1697 break;
1698 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1699 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1700 dw[3] = 1;
1701 break;
1702 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1703 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1704 dw[3] = 0;
1705 break;
1706 default:
1707 assert(!"unknown step rate");
1708 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1709 dw[3] = 0;
1710 break;
1711 }
1712
Chia-I Wu714df452015-01-01 07:55:04 +08001713 if (cmd->bind.vertex.buf[i]) {
1714 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001715 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001716
1717 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001718 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1719 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001720 } else {
1721 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1722 dw[1] = 0;
1723 dw[2] = 0;
1724 }
1725
1726 dw += 4;
1727 pos += 4;
1728 }
1729}
1730
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001731static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1732{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001733 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1734 const struct intel_pipeline_shader *vs = &pipeline->vs;
1735 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001736 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001737 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001738 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001739 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001740
1741 CMD_ASSERT(cmd, 6, 7.5);
1742
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001743 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001744 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1745 *
1746 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1747 * 128-bit vertex elements to be passed into the payload for each
1748 * vertex."
1749 *
1750 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1751 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001752 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001753 vue_read_len = (vs->in_count + 1) / 2;
1754 if (!vue_read_len)
1755 vue_read_len = 1;
1756
1757 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1758 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1759
1760 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1761 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1762 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001763
1764 dw5 = GEN6_VS_DW5_STATISTICS |
1765 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001766
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001767 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001768 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001769 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001770 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001771
Chia-I Wube0a3d92014-09-02 13:20:59 +08001772 if (pipeline->disable_vs_cache)
1773 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1774
Chia-I Wu784d3042014-12-19 14:30:04 +08001775 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001776 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001777 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001778 dw[2] = dw2;
1779 dw[3] = 0; /* scratch */
1780 dw[4] = dw4;
1781 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001782
1783 if (vs->per_thread_scratch_size)
1784 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001785}
1786
Chia-I Wu625105f2014-10-13 15:35:29 +08001787static void emit_shader_resources(struct intel_cmd *cmd)
1788{
1789 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001790 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001791
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001792 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001793 cmd->bind.pipeline.graphics->vs.rmap,
1794 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001795 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001796 cmd->bind.pipeline.graphics->tcs.rmap,
1797 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001798 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001799 cmd->bind.pipeline.graphics->tes.rmap,
1800 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001801 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001802 cmd->bind.pipeline.graphics->gs.rmap,
1803 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001804 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001805 cmd->bind.pipeline.graphics->fs.rmap,
1806 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001807
1808 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1809 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1810 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1811 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1812 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1813
1814 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1815 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001816 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1817 binding_tables[0]);
1818 gen7_3dstate_pointer(cmd,
1819 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1820 binding_tables[1]);
1821 gen7_3dstate_pointer(cmd,
1822 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1823 binding_tables[2]);
1824 gen7_3dstate_pointer(cmd,
1825 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1826 binding_tables[3]);
1827 gen7_3dstate_pointer(cmd,
1828 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1829 binding_tables[4]);
1830
1831 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001832 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1833 samplers[0]);
1834 gen7_3dstate_pointer(cmd,
1835 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1836 samplers[1]);
1837 gen7_3dstate_pointer(cmd,
1838 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1839 samplers[2]);
1840 gen7_3dstate_pointer(cmd,
1841 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1842 samplers[3]);
1843 gen7_3dstate_pointer(cmd,
1844 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1845 samplers[4]);
1846 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001847 assert(!binding_tables[1] && !binding_tables[2]);
1848 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1849 binding_tables[0], binding_tables[3], binding_tables[4]);
1850
Chia-I Wu625105f2014-10-13 15:35:29 +08001851 assert(!samplers[1] && !samplers[2]);
1852 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1853 samplers[0], samplers[3], samplers[4]);
1854 }
1855}
1856
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001857static void emit_rt(struct intel_cmd *cmd)
1858{
1859 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001860 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1861 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001862}
1863
1864static void emit_ds(struct intel_cmd *cmd)
1865{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001866 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001867
1868 if (!ds) {
1869 /* all zeros */
1870 static const struct intel_ds_view null_ds;
1871 ds = &null_ds;
1872 }
1873
1874 cmd_wa_gen6_pre_ds_flush(cmd);
1875 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1876 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1877 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1878
1879 if (cmd_gen(cmd) >= INTEL_GEN(7))
1880 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1881 else
1882 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1883}
1884
Chia-I Wua57761b2014-10-14 14:27:44 +08001885static uint32_t emit_shader(struct intel_cmd *cmd,
1886 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001887{
Chia-I Wua57761b2014-10-14 14:27:44 +08001888 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1889 uint32_t offset;
1890 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001891
Chia-I Wua57761b2014-10-14 14:27:44 +08001892 /* see if the shader is already in the cache */
1893 for (i = 0; i < cache->used; i++) {
1894 if (cache->entries[i].shader == (const void *) shader)
1895 return cache->entries[i].kernel_offset;
1896 }
1897
1898 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1899
1900 /* grow the cache if full */
1901 if (cache->used >= cache->count) {
1902 const XGL_UINT count = cache->count + 16;
1903 void *entries;
1904
1905 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1906 XGL_SYSTEM_ALLOC_INTERNAL);
1907 if (entries) {
1908 if (cache->entries) {
1909 memcpy(entries, cache->entries,
1910 sizeof(cache->entries[0]) * cache->used);
1911 icd_free(cache->entries);
1912 }
1913
1914 cache->entries = entries;
1915 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001916 }
1917 }
1918
Chia-I Wua57761b2014-10-14 14:27:44 +08001919 /* add the shader to the cache */
1920 if (cache->used < cache->count) {
1921 cache->entries[cache->used].shader = (const void *) shader;
1922 cache->entries[cache->used].kernel_offset = offset;
1923 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001924 }
1925
Chia-I Wua57761b2014-10-14 14:27:44 +08001926 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001927}
1928
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001929static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001930{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001931 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001932
Chia-I Wu8370b402014-08-29 12:28:37 +08001933 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1934 cmd_wa_gen6_pre_depth_stall_write(cmd);
1935 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1936 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1937 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1938 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001939
1940 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001941 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001942 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001943
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001944 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001945 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001946 }
1947 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001948 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001949 }
1950 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001951 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1952 }
1953 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1954 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1955 }
1956 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1957 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001958 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001959
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001960 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1961 gen7_3DSTATE_GS(cmd);
1962 } else {
1963 gen6_3DSTATE_GS(cmd);
1964 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001965
Chia-I Wu8370b402014-08-29 12:28:37 +08001966 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1967 cmd_wa_gen7_post_command_cs_stall(cmd);
1968 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1969 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001970}
1971
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001972static void emit_bounded_states(struct intel_cmd *cmd)
1973{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001974
1975 emit_graphics_pipeline(cmd);
1976
1977 emit_rt(cmd);
1978 emit_ds(cmd);
1979
1980 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1981 gen7_cc_states(cmd);
1982 gen7_viewport_states(cmd);
1983
1984 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1985 &cmd->bind.pipeline.graphics->vs);
1986 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1987 &cmd->bind.pipeline.graphics->fs);
1988
1989 gen6_3DSTATE_CLIP(cmd);
1990 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001991 gen7_3DSTATE_WM(cmd);
1992 gen7_3DSTATE_PS(cmd);
1993 } else {
1994 gen6_cc_states(cmd);
1995 gen6_viewport_states(cmd);
1996
1997 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1998 &cmd->bind.pipeline.graphics->vs);
1999 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2000 &cmd->bind.pipeline.graphics->fs);
2001
2002 gen6_3DSTATE_CLIP(cmd);
2003 gen6_3DSTATE_SF(cmd);
2004 gen6_3DSTATE_WM(cmd);
2005 }
2006
2007 emit_shader_resources(cmd);
2008
2009 cmd_wa_gen6_pre_depth_stall_write(cmd);
2010 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2011
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002012 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2013 gen6_3DSTATE_VS(cmd);
2014}
2015
Tony Barbourfa6cac72015-01-16 14:27:35 -07002016static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
2017 const struct intel_cmd_meta *meta)
2018{
2019 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2020 const uint8_t cmd_len = 3;
2021 uint32_t dw[3];
2022 uint32_t cmd_depth_stencil;
2023 uint32_t cmd_depth_test;
2024
2025 CMD_ASSERT(cmd, 6, 7.5);
2026
2027 cmd_depth_stencil = 0;
2028 cmd_depth_test = 0;
2029 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
2030 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
2031 GEN6_COMPAREFUNCTION_ALWAYS << 27;
2032 }
2033 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2034 cmd_depth_stencil = 1 << 31 |
2035 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2036 (GEN6_STENCILOP_KEEP) << 25 |
2037 (GEN6_STENCILOP_KEEP) << 22 |
2038 (GEN6_STENCILOP_REPLACE) << 19 |
2039 1 << 15 |
2040 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2041 (GEN6_STENCILOP_KEEP) << 9 |
2042 (GEN6_STENCILOP_KEEP) << 6 |
2043 (GEN6_STENCILOP_REPLACE) << 3;
2044 }
2045
2046 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2047 dw[0] = cmd_depth_stencil | 1 << 18;
2048 dw[1] = (0xff) << 24 | (0xff) << 16;
2049 dw[2] = cmd_depth_test;
2050
2051 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2052 cmd_align, cmd_len, dw);
2053}
2054
Chia-I Wu6032b892014-10-17 14:47:18 +08002055static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2056{
2057 const struct intel_cmd_meta *meta = cmd->bind.meta;
2058 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2059
2060 CMD_ASSERT(cmd, 6, 7.5);
2061
2062 blend_offset = 0;
2063 ds_offset = 0;
2064 cc_offset = 0;
2065 cc_vp_offset = 0;
2066
Chia-I Wu29e6f502014-11-24 14:27:29 +08002067 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002068 /* BLEND_STATE */
2069 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002070 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002071 dw[0] = 0;
2072 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2073 }
2074
Chia-I Wu29e6f502014-11-24 14:27:29 +08002075 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002076 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002077 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002078 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2079 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002080
Chia-I Wu29e6f502014-11-24 14:27:29 +08002081 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002082 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002083
Chia-I Wu29e6f502014-11-24 14:27:29 +08002084 /* COLOR_CALC_STATE */
2085 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002086 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002087
Chia-I Wu29e6f502014-11-24 14:27:29 +08002088 /* CC_VIEWPORT */
2089 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002090 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002091 dw[0] = u_fui(0.0f);
2092 dw[1] = u_fui(1.0f);
2093 } else {
2094 /* DEPTH_STENCIL_STATE */
2095 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002096 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002097 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2098 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2099 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002100 }
2101
2102 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2103 gen7_3dstate_pointer(cmd,
2104 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2105 blend_offset);
2106 gen7_3dstate_pointer(cmd,
2107 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2108 ds_offset);
2109 gen7_3dstate_pointer(cmd,
2110 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2111
2112 gen7_3dstate_pointer(cmd,
2113 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2114 cc_vp_offset);
2115 } else {
2116 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002117 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002118
2119 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2120 cmd_batch_pointer(cmd, 4, &dw);
2121 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2122 GEN6_PTR_VP_DW0_CC_CHANGED;
2123 dw[1] = 0;
2124 dw[2] = 0;
2125 dw[3] = cc_vp_offset;
2126 }
2127}
2128
2129static void gen6_meta_surface_states(struct intel_cmd *cmd)
2130{
2131 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002132 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002133 uint32_t offset;
2134
2135 CMD_ASSERT(cmd, 6, 7.5);
2136
Chia-I Wu29e6f502014-11-24 14:27:29 +08002137 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2138 return;
2139
Chia-I Wu005c47c2014-10-22 13:49:13 +08002140 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002141 if (meta->src.valid) {
2142 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002143 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002144 meta->src.surface_len, meta->src.surface);
2145
2146 cmd_reserve_reloc(cmd, 1);
2147 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2148 cmd_surface_reloc_writer(cmd, offset, 1,
2149 meta->src.reloc_target, meta->src.reloc_offset);
2150 } else {
2151 cmd_surface_reloc(cmd, offset, 1,
2152 (struct intel_bo *) meta->src.reloc_target,
2153 meta->src.reloc_offset, meta->src.reloc_flags);
2154 }
2155
Chia-I Wu005c47c2014-10-22 13:49:13 +08002156 binding_table[0] = offset;
2157 }
2158 if (meta->dst.valid) {
2159 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002160 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002161 meta->dst.surface_len, meta->dst.surface);
2162
2163 cmd_reserve_reloc(cmd, 1);
2164 cmd_surface_reloc(cmd, offset, 1,
2165 (struct intel_bo *) meta->dst.reloc_target,
2166 meta->dst.reloc_offset, meta->dst.reloc_flags);
2167
2168 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002169 }
2170
2171 /* BINDING_TABLE */
2172 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002173 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002174 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002175
2176 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002177 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2178 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2179 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2180 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002181 } else {
2182 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002183 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2184 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2185 else
2186 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002187 }
2188}
2189
2190static void gen6_meta_urb(struct intel_cmd *cmd)
2191{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002192 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002193 uint32_t *dw;
2194
2195 CMD_ASSERT(cmd, 6, 6);
2196
2197 /* 3DSTATE_URB */
2198 cmd_batch_pointer(cmd, 3, &dw);
2199 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002200 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002201 dw[2] = 0;
2202}
2203
2204static void gen7_meta_urb(struct intel_cmd *cmd)
2205{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002206 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002207 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002208 uint32_t *dw;
2209
2210 CMD_ASSERT(cmd, 7, 7.5);
2211
2212 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2213 cmd_batch_pointer(cmd, 10, &dw);
2214
2215 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002216 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002217 dw += 2;
2218
2219 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2220 dw[1] = 0;
2221 dw += 2;
2222
2223 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2224 dw[1] = 0;
2225 dw += 2;
2226
2227 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2228 dw[1] = 0;
2229 dw += 2;
2230
2231 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002232 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002233
2234 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2235
Chia-I Wu24aa1022014-11-25 11:53:19 +08002236 switch (cmd_gen(cmd)) {
2237 case INTEL_GEN(7.5):
2238 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2239 break;
2240 case INTEL_GEN(7):
2241 default:
2242 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2243 break;
2244 }
2245
Chia-I Wu6032b892014-10-17 14:47:18 +08002246 /* 3DSTATE_URB_x */
2247 cmd_batch_pointer(cmd, 8, &dw);
2248
2249 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2250 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002251 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002252 dw += 2;
2253
2254 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2255 dw[1] = 0;
2256 dw += 2;
2257
2258 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2259 dw[1] = 0;
2260 dw += 2;
2261
2262 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2263 dw[1] = 0;
2264 dw += 2;
2265}
2266
2267static void gen6_meta_vf(struct intel_cmd *cmd)
2268{
2269 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002270 uint32_t vb_start, vb_end, vb_stride;
2271 int ve_format, ve_z_source;
2272 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002273 XGL_UINT pos;
2274
2275 CMD_ASSERT(cmd, 6, 7.5);
2276
Chia-I Wu29e6f502014-11-24 14:27:29 +08002277 switch (meta->mode) {
2278 case INTEL_CMD_META_VS_POINTS:
2279 cmd_batch_pointer(cmd, 3, &dw);
2280 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2281 dw[1] = GEN6_VE_STATE_DW0_VALID;
2282 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2283 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2284 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2285 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2286 return;
2287 break;
2288 case INTEL_CMD_META_FS_RECT:
2289 {
2290 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002291
Chia-I Wu29e6f502014-11-24 14:27:29 +08002292 vertices[0][0] = meta->dst.x + meta->width;
2293 vertices[0][1] = meta->dst.y + meta->height;
2294 vertices[1][0] = meta->dst.x;
2295 vertices[1][1] = meta->dst.y + meta->height;
2296 vertices[2][0] = meta->dst.x;
2297 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002298
Chia-I Wu29e6f502014-11-24 14:27:29 +08002299 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2300 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002301
Chia-I Wu29e6f502014-11-24 14:27:29 +08002302 vb_end = vb_start + sizeof(vertices) - 1;
2303 vb_stride = sizeof(vertices[0]);
2304 ve_z_source = GEN6_VFCOMP_STORE_0;
2305 ve_format = GEN6_FORMAT_R32G32_USCALED;
2306 }
2307 break;
2308 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2309 {
2310 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002311
Chia-I Wu29e6f502014-11-24 14:27:29 +08002312 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2313 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2314 vertices[0][2] = u_uif(meta->clear_val[0]);
2315 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2316 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2317 vertices[1][2] = u_uif(meta->clear_val[0]);
2318 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2319 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2320 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002321
Chia-I Wu29e6f502014-11-24 14:27:29 +08002322 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2323 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002324
Chia-I Wu29e6f502014-11-24 14:27:29 +08002325 vb_end = vb_start + sizeof(vertices) - 1;
2326 vb_stride = sizeof(vertices[0]);
2327 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2328 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2329 }
2330 break;
2331 default:
2332 assert(!"unknown meta mode");
2333 return;
2334 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002335 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002336
2337 /* 3DSTATE_VERTEX_BUFFERS */
2338 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002339
Chia-I Wu6032b892014-10-17 14:47:18 +08002340 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002341 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002342 if (cmd_gen(cmd) >= INTEL_GEN(7))
2343 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2344
2345 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002346 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2347 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002348
2349 dw[4] = 0;
2350
2351 /* 3DSTATE_VERTEX_ELEMENTS */
2352 cmd_batch_pointer(cmd, 5, &dw);
2353 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002354 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002355 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2356 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2357 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2358 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2359 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002360 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002361 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2362 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002363 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002364 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2365}
2366
Chia-I Wu29e6f502014-11-24 14:27:29 +08002367static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002368{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002369 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002370 /* one GPR */
2371 XGL_UINT consts[8];
2372 XGL_UINT const_count;
2373
2374 CMD_ASSERT(cmd, 6, 7.5);
2375
2376 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002377 case INTEL_DEV_META_VS_FILL_MEM:
2378 consts[0] = meta->dst.x;
2379 consts[1] = meta->clear_val[0];
2380 const_count = 2;
2381 break;
2382 case INTEL_DEV_META_VS_COPY_MEM:
2383 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2384 consts[0] = meta->dst.x;
2385 consts[1] = meta->src.x;
2386 const_count = 2;
2387 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002388 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2389 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2390 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2391 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2392 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2393 consts[0] = meta->src.x;
2394 consts[1] = meta->src.y;
2395 consts[2] = meta->width;
2396 consts[3] = meta->dst.x;
2397 const_count = 4;
2398 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002399 default:
2400 assert(!"unknown meta shader id");
2401 const_count = 0;
2402 break;
2403 }
2404
2405 /* this can be skipped but it makes state dumping prettier */
2406 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2407
2408 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2409}
2410
2411static void gen6_meta_vs(struct intel_cmd *cmd)
2412{
2413 const struct intel_cmd_meta *meta = cmd->bind.meta;
2414 const struct intel_pipeline_shader *sh =
2415 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2416 uint32_t offset, *dw;
2417
2418 CMD_ASSERT(cmd, 6, 7.5);
2419
2420 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2421 XGL_UINT cmd_len;
2422
2423 /* 3DSTATE_CONSTANT_VS */
2424 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2425 cmd_batch_pointer(cmd, cmd_len, &dw);
2426 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2427 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2428
2429 /* 3DSTATE_VS */
2430 cmd_batch_pointer(cmd, 6, &dw);
2431 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2432 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2433
2434 return;
2435 }
2436
2437 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2438
2439 /* 3DSTATE_CONSTANT_VS */
2440 offset = gen6_meta_vs_constants(cmd);
2441 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2442 cmd_batch_pointer(cmd, 7, &dw);
2443 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2444 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2445 dw[2] = 0;
2446 dw[3] = offset;
2447 dw[4] = 0;
2448 dw[5] = 0;
2449 dw[6] = 0;
2450 } else {
2451 cmd_batch_pointer(cmd, 5, &dw);
2452 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2453 GEN6_PCB_ANY_DW0_PCB0_VALID;
2454 dw[1] = offset;
2455 dw[2] = 0;
2456 dw[3] = 0;
2457 dw[4] = 0;
2458 }
2459
2460 /* 3DSTATE_VS */
2461 offset = emit_shader(cmd, sh);
2462 cmd_batch_pointer(cmd, 6, &dw);
2463 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2464 dw[1] = offset;
2465 dw[2] = GEN6_THREADDISP_SPF |
2466 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2467 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002468 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002469 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2470 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2471
2472 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2473 GEN6_VS_DW5_VS_ENABLE;
2474 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002475 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002476 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002477 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002478
2479 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002480}
2481
2482static void gen6_meta_disabled(struct intel_cmd *cmd)
2483{
Chia-I Wu6032b892014-10-17 14:47:18 +08002484 uint32_t *dw;
2485
2486 CMD_ASSERT(cmd, 6, 6);
2487
Chia-I Wu6032b892014-10-17 14:47:18 +08002488 /* 3DSTATE_CONSTANT_GS */
2489 cmd_batch_pointer(cmd, 5, &dw);
2490 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2491 dw[1] = 0;
2492 dw[2] = 0;
2493 dw[3] = 0;
2494 dw[4] = 0;
2495
2496 /* 3DSTATE_GS */
2497 cmd_batch_pointer(cmd, 7, &dw);
2498 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2499 dw[1] = 0;
2500 dw[2] = 0;
2501 dw[3] = 0;
2502 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2503 dw[5] = GEN6_GS_DW5_STATISTICS;
2504 dw[6] = 0;
2505
Chia-I Wu6032b892014-10-17 14:47:18 +08002506 /* 3DSTATE_SF */
2507 cmd_batch_pointer(cmd, 20, &dw);
2508 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2509 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2510 memset(&dw[2], 0, 18 * sizeof(*dw));
2511}
2512
2513static void gen7_meta_disabled(struct intel_cmd *cmd)
2514{
2515 uint32_t *dw;
2516
2517 CMD_ASSERT(cmd, 7, 7.5);
2518
Chia-I Wu6032b892014-10-17 14:47:18 +08002519 /* 3DSTATE_CONSTANT_HS */
2520 cmd_batch_pointer(cmd, 7, &dw);
2521 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2522 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2523
2524 /* 3DSTATE_HS */
2525 cmd_batch_pointer(cmd, 7, &dw);
2526 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2527 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2528
2529 /* 3DSTATE_TE */
2530 cmd_batch_pointer(cmd, 4, &dw);
2531 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2532 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2533
2534 /* 3DSTATE_CONSTANT_DS */
2535 cmd_batch_pointer(cmd, 7, &dw);
2536 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2537 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2538
2539 /* 3DSTATE_DS */
2540 cmd_batch_pointer(cmd, 6, &dw);
2541 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2542 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2543
2544 /* 3DSTATE_CONSTANT_GS */
2545 cmd_batch_pointer(cmd, 7, &dw);
2546 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2547 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2548
2549 /* 3DSTATE_GS */
2550 cmd_batch_pointer(cmd, 7, &dw);
2551 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2552 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2553
2554 /* 3DSTATE_STREAMOUT */
2555 cmd_batch_pointer(cmd, 3, &dw);
2556 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2557 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2558
Chia-I Wu6032b892014-10-17 14:47:18 +08002559 /* 3DSTATE_SF */
2560 cmd_batch_pointer(cmd, 7, &dw);
2561 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2562 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2563
2564 /* 3DSTATE_SBE */
2565 cmd_batch_pointer(cmd, 14, &dw);
2566 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2567 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2568 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002569}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002570
Chia-I Wu29e6f502014-11-24 14:27:29 +08002571static void gen6_meta_clip(struct intel_cmd *cmd)
2572{
2573 const struct intel_cmd_meta *meta = cmd->bind.meta;
2574 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002575
Chia-I Wu29e6f502014-11-24 14:27:29 +08002576 /* 3DSTATE_CLIP */
2577 cmd_batch_pointer(cmd, 4, &dw);
2578 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2579 dw[1] = 0;
2580 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2581 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2582 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2583 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002584 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002585 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002586 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002587}
2588
2589static void gen6_meta_wm(struct intel_cmd *cmd)
2590{
2591 const struct intel_cmd_meta *meta = cmd->bind.meta;
2592 uint32_t *dw;
2593
2594 CMD_ASSERT(cmd, 6, 7.5);
2595
2596 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2597
2598 /* 3DSTATE_MULTISAMPLE */
2599 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2600 cmd_batch_pointer(cmd, 4, &dw);
2601 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2602 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2603 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2604 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2605 dw[2] = 0;
2606 dw[3] = 0;
2607 } else {
2608 cmd_batch_pointer(cmd, 3, &dw);
2609 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2610 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2611 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2612 dw[2] = 0;
2613 }
2614
2615 /* 3DSTATE_SAMPLE_MASK */
2616 cmd_batch_pointer(cmd, 2, &dw);
2617 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2618 dw[1] = (1 << meta->samples) - 1;
2619
2620 /* 3DSTATE_DRAWING_RECTANGLE */
2621 cmd_batch_pointer(cmd, 4, &dw);
2622 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2623 dw[1] = meta->dst.y << 16 | meta->dst.x;
2624 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2625 (meta->dst.x + meta->width - 1);
2626 dw[3] = 0;
2627}
2628
2629static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2630{
2631 const struct intel_cmd_meta *meta = cmd->bind.meta;
2632 XGL_UINT offset_x, offset_y;
2633 /* one GPR */
2634 XGL_UINT consts[8];
2635 XGL_UINT const_count;
2636
2637 CMD_ASSERT(cmd, 6, 7.5);
2638
2639 /* underflow is fine here */
2640 offset_x = meta->src.x - meta->dst.x;
2641 offset_y = meta->src.y - meta->dst.y;
2642
2643 switch (meta->shader_id) {
2644 case INTEL_DEV_META_FS_COPY_MEM:
2645 case INTEL_DEV_META_FS_COPY_1D:
2646 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2647 case INTEL_DEV_META_FS_COPY_2D:
2648 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2649 case INTEL_DEV_META_FS_COPY_2D_MS:
2650 consts[0] = offset_x;
2651 consts[1] = offset_y;
2652 consts[2] = meta->src.layer;
2653 consts[3] = meta->src.lod;
2654 const_count = 4;
2655 break;
2656 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2657 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2658 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2659 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2660 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2661 consts[0] = offset_x;
2662 consts[1] = offset_y;
2663 consts[2] = meta->src.layer;
2664 consts[3] = meta->src.lod;
2665 consts[4] = meta->src.x;
2666 consts[5] = meta->width;
2667 const_count = 6;
2668 break;
2669 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2670 consts[0] = offset_x;
2671 consts[1] = offset_y;
2672 consts[2] = meta->width;
2673 const_count = 3;
2674 break;
2675 case INTEL_DEV_META_FS_CLEAR_COLOR:
2676 consts[0] = meta->clear_val[0];
2677 consts[1] = meta->clear_val[1];
2678 consts[2] = meta->clear_val[2];
2679 consts[3] = meta->clear_val[3];
2680 const_count = 4;
2681 break;
2682 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2683 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002684 consts[1] = meta->clear_val[1];
2685 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002686 break;
2687 case INTEL_DEV_META_FS_RESOLVE_2X:
2688 case INTEL_DEV_META_FS_RESOLVE_4X:
2689 case INTEL_DEV_META_FS_RESOLVE_8X:
2690 case INTEL_DEV_META_FS_RESOLVE_16X:
2691 consts[0] = offset_x;
2692 consts[1] = offset_y;
2693 const_count = 2;
2694 break;
2695 default:
2696 assert(!"unknown meta shader id");
2697 const_count = 0;
2698 break;
2699 }
2700
2701 /* this can be skipped but it makes state dumping prettier */
2702 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2703
2704 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2705}
2706
2707static void gen6_meta_ps(struct intel_cmd *cmd)
2708{
2709 const struct intel_cmd_meta *meta = cmd->bind.meta;
2710 const struct intel_pipeline_shader *sh =
2711 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2712 uint32_t offset, *dw;
2713
2714 CMD_ASSERT(cmd, 6, 6);
2715
Chia-I Wu29e6f502014-11-24 14:27:29 +08002716 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2717 /* 3DSTATE_CONSTANT_PS */
2718 cmd_batch_pointer(cmd, 5, &dw);
2719 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2720 dw[1] = 0;
2721 dw[2] = 0;
2722 dw[3] = 0;
2723 dw[4] = 0;
2724
2725 /* 3DSTATE_WM */
2726 cmd_batch_pointer(cmd, 9, &dw);
2727 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2728 dw[1] = 0;
2729 dw[2] = 0;
2730 dw[3] = 0;
2731 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002732 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002733 dw[6] = 0;
2734 dw[7] = 0;
2735 dw[8] = 0;
2736
Chia-I Wu3adf7212014-10-24 15:34:07 +08002737 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002738 }
2739
Chia-I Wu3adf7212014-10-24 15:34:07 +08002740 /* a normal color write */
2741 assert(meta->dst.valid && !sh->uses);
2742
Chia-I Wu6032b892014-10-17 14:47:18 +08002743 /* 3DSTATE_CONSTANT_PS */
2744 offset = gen6_meta_ps_constants(cmd);
2745 cmd_batch_pointer(cmd, 5, &dw);
2746 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2747 GEN6_PCB_ANY_DW0_PCB0_VALID;
2748 dw[1] = offset;
2749 dw[2] = 0;
2750 dw[3] = 0;
2751 dw[4] = 0;
2752
2753 /* 3DSTATE_WM */
2754 offset = emit_shader(cmd, sh);
2755 cmd_batch_pointer(cmd, 9, &dw);
2756 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2757 dw[1] = offset;
2758 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2759 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002760 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002761 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002762 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002763 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002764 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2765
Chia-I Wu6032b892014-10-17 14:47:18 +08002766 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2767 GEN6_WM_DW6_POSOFFSET_NONE |
2768 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2769 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2770 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2771 if (meta->samples > 1) {
2772 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2773 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2774 } else {
2775 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2776 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2777 }
2778 dw[7] = 0;
2779 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002780
2781 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002782}
2783
2784static void gen7_meta_ps(struct intel_cmd *cmd)
2785{
2786 const struct intel_cmd_meta *meta = cmd->bind.meta;
2787 const struct intel_pipeline_shader *sh =
2788 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2789 uint32_t offset, *dw;
2790
2791 CMD_ASSERT(cmd, 7, 7.5);
2792
Chia-I Wu29e6f502014-11-24 14:27:29 +08002793 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2794 /* 3DSTATE_WM */
2795 cmd_batch_pointer(cmd, 3, &dw);
2796 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2797 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2798
2799 /* 3DSTATE_CONSTANT_GS */
2800 cmd_batch_pointer(cmd, 7, &dw);
2801 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2802 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2803
2804 /* 3DSTATE_PS */
2805 cmd_batch_pointer(cmd, 8, &dw);
2806 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2807 dw[1] = 0;
2808 dw[2] = 0;
2809 dw[3] = 0;
2810 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002811 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002812 dw[5] = 0;
2813 dw[6] = 0;
2814 dw[7] = 0;
2815
Chia-I Wu3adf7212014-10-24 15:34:07 +08002816 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002817 }
2818
Chia-I Wu3adf7212014-10-24 15:34:07 +08002819 /* a normal color write */
2820 assert(meta->dst.valid && !sh->uses);
2821
Chia-I Wu6032b892014-10-17 14:47:18 +08002822 /* 3DSTATE_WM */
2823 cmd_batch_pointer(cmd, 3, &dw);
2824 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2825 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2826 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2827 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2828 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2829 dw[2] = 0;
2830
2831 /* 3DSTATE_CONSTANT_PS */
2832 offset = gen6_meta_ps_constants(cmd);
2833 cmd_batch_pointer(cmd, 7, &dw);
2834 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2835 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2836 dw[2] = 0;
2837 dw[3] = offset;
2838 dw[4] = 0;
2839 dw[5] = 0;
2840 dw[6] = 0;
2841
2842 /* 3DSTATE_PS */
2843 offset = emit_shader(cmd, sh);
2844 cmd_batch_pointer(cmd, 8, &dw);
2845 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2846 dw[1] = offset;
2847 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2848 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002849 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002850
2851 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2852 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002853 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2854
2855 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002856 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002857 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002858 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002859 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002860 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002861
2862 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2863 dw[6] = 0;
2864 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002865
2866 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002867}
2868
2869static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2870{
2871 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002872 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002873
2874 CMD_ASSERT(cmd, 6, 7.5);
2875
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002876 if (!ds) {
2877 /* all zeros */
2878 static const struct intel_ds_view null_ds;
2879 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002880 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002881
2882 cmd_wa_gen6_pre_ds_flush(cmd);
2883 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2884 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2885 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2886
2887 if (cmd_gen(cmd) >= INTEL_GEN(7))
2888 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2889 else
2890 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002891}
2892
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002893static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2894 const struct intel_pipeline *pipeline)
2895{
2896 cmd->bind.pipeline.graphics = pipeline;
2897}
2898
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002899static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2900 const struct intel_pipeline *pipeline)
2901{
2902 cmd->bind.pipeline.compute = pipeline;
2903}
2904
2905static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2906 const struct intel_pipeline_delta *delta)
2907{
2908 cmd->bind.pipeline.graphics_delta = delta;
2909}
2910
2911static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2912 const struct intel_pipeline_delta *delta)
2913{
2914 cmd->bind.pipeline.compute_delta = delta;
2915}
2916
2917static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2918 const struct intel_dset *dset,
2919 XGL_UINT slot_offset)
2920{
2921 cmd->bind.dset.graphics = dset;
2922 cmd->bind.dset.graphics_offset = slot_offset;
2923}
2924
2925static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2926 const struct intel_dset *dset,
2927 XGL_UINT slot_offset)
2928{
2929 cmd->bind.dset.compute = dset;
2930 cmd->bind.dset.compute_offset = slot_offset;
2931}
2932
2933static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002934 const XGL_BUFFER_VIEW_ATTACH_INFO *info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002935{
Chia-I Wu714df452015-01-01 07:55:04 +08002936 cmd->bind.dyn_view.graphics = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002937}
2938
2939static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002940 const XGL_BUFFER_VIEW_ATTACH_INFO *info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002941{
Chia-I Wu714df452015-01-01 07:55:04 +08002942 cmd->bind.dyn_view.compute = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002943}
2944
Chia-I Wu3b04af52014-11-08 10:48:20 +08002945static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002946 const struct intel_buf *buf,
Chia-I Wu3b04af52014-11-08 10:48:20 +08002947 XGL_GPU_SIZE offset, XGL_UINT binding)
2948{
Chia-I Wu714df452015-01-01 07:55:04 +08002949 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002950 cmd->result = XGL_ERROR_UNKNOWN;
2951 return;
2952 }
2953
Chia-I Wu714df452015-01-01 07:55:04 +08002954 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002955 cmd->bind.vertex.offset[binding] = offset;
2956}
2957
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002958static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002959 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002960 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2961{
Chia-I Wu714df452015-01-01 07:55:04 +08002962 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002963 cmd->bind.index.offset = offset;
2964 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002965}
2966
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002967static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002968 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002969{
2970 cmd->bind.state.viewport = state;
2971}
2972
2973static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002974 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002975{
2976 cmd->bind.state.raster = state;
2977}
2978
2979static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002980 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002981{
2982 cmd->bind.state.ds = state;
2983}
2984
2985static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002986 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002987{
2988 cmd->bind.state.blend = state;
2989}
2990
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002991static void cmd_draw(struct intel_cmd *cmd,
2992 XGL_UINT vertex_start,
2993 XGL_UINT vertex_count,
2994 XGL_UINT instance_start,
2995 XGL_UINT instance_count,
2996 bool indexed,
2997 XGL_UINT vertex_base)
2998{
2999 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
3000
3001 emit_bounded_states(cmd);
3002
3003 if (indexed) {
3004 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3005 cmd->result = XGL_ERROR_UNKNOWN;
3006
3007 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3008 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3009 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003010 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003011 cmd->bind.index.offset, cmd->bind.index.type,
3012 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003013 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003014 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003015 cmd->bind.index.offset, cmd->bind.index.type,
3016 p->primitive_restart);
3017 }
3018 } else {
3019 assert(!vertex_base);
3020 }
3021
3022 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3023 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3024 vertex_start, instance_count, instance_start, vertex_base);
3025 } else {
3026 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3027 vertex_start, instance_count, instance_start, vertex_base);
3028 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003029
Chia-I Wu707a29e2014-08-27 12:51:47 +08003030 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003031 /* need to re-emit all workarounds */
3032 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003033
3034 if (intel_debug & INTEL_DEBUG_NOCACHE)
3035 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003036}
3037
Chia-I Wuc14d1562014-10-17 09:49:22 +08003038void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3039{
Chia-I Wu6032b892014-10-17 14:47:18 +08003040 cmd->bind.meta = meta;
3041
3042 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003043 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003044
3045 gen6_meta_dynamic_states(cmd);
3046 gen6_meta_surface_states(cmd);
3047
3048 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3049 gen7_meta_urb(cmd);
3050 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003051 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003052 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003053 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003054 gen6_meta_wm(cmd);
3055 gen7_meta_ps(cmd);
3056 gen6_meta_depth_buffer(cmd);
3057
3058 cmd_wa_gen7_post_command_cs_stall(cmd);
3059 cmd_wa_gen7_post_command_depth_stall(cmd);
3060
Chia-I Wu29e6f502014-11-24 14:27:29 +08003061 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3062 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003063 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003064 } else {
3065 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3066 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003067 } else {
3068 gen6_meta_urb(cmd);
3069 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003070 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003071 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003072 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003073 gen6_meta_wm(cmd);
3074 gen6_meta_ps(cmd);
3075 gen6_meta_depth_buffer(cmd);
3076
Chia-I Wu29e6f502014-11-24 14:27:29 +08003077 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3078 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003079 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003080 } else {
3081 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3082 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003083 }
3084
3085 cmd->bind.draw_count++;
3086 /* need to re-emit all workarounds */
3087 cmd->bind.wa_flags = 0;
3088
3089 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003090
3091 if (intel_debug & INTEL_DEBUG_NOCACHE)
3092 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003093}
3094
Chia-I Wu96177272015-01-03 15:27:41 +08003095ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003096 XGL_CMD_BUFFER cmdBuffer,
3097 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3098 XGL_PIPELINE pipeline)
3099{
3100 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3101
3102 switch (pipelineBindPoint) {
3103 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003104 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003105 break;
3106 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003107 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003108 break;
3109 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003110 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003111 break;
3112 }
3113}
3114
Chia-I Wu96177272015-01-03 15:27:41 +08003115ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003116 XGL_CMD_BUFFER cmdBuffer,
3117 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3118 XGL_PIPELINE_DELTA delta)
3119{
3120 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3121
3122 switch (pipelineBindPoint) {
3123 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003124 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003125 break;
3126 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003127 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003128 break;
3129 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003130 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003131 break;
3132 }
3133}
3134
Tony Barbourfa6cac72015-01-16 14:27:35 -07003135ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003136 XGL_CMD_BUFFER cmdBuffer,
3137 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003138 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003139{
3140 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3141
3142 switch (stateBindPoint) {
3143 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003144 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003145 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003146 break;
3147 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003148 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003149 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003150 break;
3151 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003152 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003153 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003154 break;
3155 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003156 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003157 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003158 break;
3159 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003160 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003161 break;
3162 }
3163}
3164
Chia-I Wu96177272015-01-03 15:27:41 +08003165ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003166 XGL_CMD_BUFFER cmdBuffer,
3167 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3168 XGL_UINT index,
3169 XGL_DESCRIPTOR_SET descriptorSet,
3170 XGL_UINT slotOffset)
3171{
3172 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3173 struct intel_dset *dset = intel_dset(descriptorSet);
3174
3175 assert(!index);
3176
3177 switch (pipelineBindPoint) {
3178 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003179 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003180 break;
3181 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003182 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003183 break;
3184 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003185 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003186 break;
3187 }
3188}
3189
Chia-I Wu714df452015-01-01 07:55:04 +08003190ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicBufferView(
Chia-I Wub2755562014-08-20 13:38:52 +08003191 XGL_CMD_BUFFER cmdBuffer,
3192 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wu714df452015-01-01 07:55:04 +08003193 const XGL_BUFFER_VIEW_ATTACH_INFO* pBufferView)
Chia-I Wub2755562014-08-20 13:38:52 +08003194{
3195 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3196
3197 switch (pipelineBindPoint) {
3198 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu714df452015-01-01 07:55:04 +08003199 cmd_bind_compute_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003200 break;
3201 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu714df452015-01-01 07:55:04 +08003202 cmd_bind_graphics_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003203 break;
3204 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003205 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003206 break;
3207 }
3208}
3209
Chia-I Wu714df452015-01-01 07:55:04 +08003210ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003211 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003212 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003213 XGL_GPU_SIZE offset,
3214 XGL_UINT binding)
3215{
3216 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003217 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003218
Chia-I Wu714df452015-01-01 07:55:04 +08003219 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003220}
3221
Chia-I Wu714df452015-01-01 07:55:04 +08003222ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003223 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003224 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003225 XGL_GPU_SIZE offset,
3226 XGL_INDEX_TYPE indexType)
3227{
3228 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003229 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003230
Chia-I Wu714df452015-01-01 07:55:04 +08003231 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003232}
3233
Chia-I Wu96177272015-01-03 15:27:41 +08003234ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003235 XGL_CMD_BUFFER cmdBuffer,
3236 XGL_UINT firstVertex,
3237 XGL_UINT vertexCount,
3238 XGL_UINT firstInstance,
3239 XGL_UINT instanceCount)
3240{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003241 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003242
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003243 cmd_draw(cmd, firstVertex, vertexCount,
3244 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003245}
3246
Chia-I Wu96177272015-01-03 15:27:41 +08003247ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003248 XGL_CMD_BUFFER cmdBuffer,
3249 XGL_UINT firstIndex,
3250 XGL_UINT indexCount,
3251 XGL_INT vertexOffset,
3252 XGL_UINT firstInstance,
3253 XGL_UINT instanceCount)
3254{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003255 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003256
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003257 cmd_draw(cmd, firstIndex, indexCount,
3258 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003259}
3260
Chia-I Wu96177272015-01-03 15:27:41 +08003261ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003262 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003263 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003264 XGL_GPU_SIZE offset,
3265 XGL_UINT32 count,
3266 XGL_UINT32 stride)
3267{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003268 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3269
3270 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003271}
3272
Chia-I Wu96177272015-01-03 15:27:41 +08003273ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003274 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003275 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003276 XGL_GPU_SIZE offset,
3277 XGL_UINT32 count,
3278 XGL_UINT32 stride)
3279{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003280 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3281
3282 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003283}
3284
Chia-I Wu96177272015-01-03 15:27:41 +08003285ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003286 XGL_CMD_BUFFER cmdBuffer,
3287 XGL_UINT x,
3288 XGL_UINT y,
3289 XGL_UINT z)
3290{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003291 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3292
3293 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003294}
3295
Chia-I Wu96177272015-01-03 15:27:41 +08003296ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003297 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003298 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003299 XGL_GPU_SIZE offset)
3300{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003301 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3302
3303 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003304}