blob: c6fc12316e67ba3dfc7d4decadf6a692a754a472 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wub2755562014-08-20 13:38:52 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600221 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffffffu);
226 break;
227 default:
228 supported = false;
229 break;
230 }
231
232 return supported;
233}
234
Chia-I Wu59c097e2014-08-21 10:51:07 +0800235static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800236 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600237 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600238 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 bool enable_cut_index)
240{
241 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800242 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800243 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600244 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245
246 CMD_ASSERT(cmd, 6, 7.5);
247
Chia-I Wu426072d2014-08-26 14:31:55 +0800248 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800249
250 /* the bit is moved to 3DSTATE_VF */
251 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
252 assert(!enable_cut_index);
253 if (enable_cut_index)
254 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
255
256 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600257 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800258 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
259 offset_align = 2;
260 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600261 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800262 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
263 offset_align = 4;
264 break;
265 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600266 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800267 return;
268 break;
269 }
270
271 if (offset % offset_align) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800273 return;
274 }
275
276 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800277 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800278
Chia-I Wu72292b72014-09-09 10:48:33 +0800279 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
280 dw[0] = dw0;
281
282 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800283 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
284 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285}
286
Chia-I Wu62a7f252014-08-29 11:31:16 +0800287static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
288 bool enable_cut_index,
289 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800290{
291 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800292 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800293
294 CMD_ASSERT(cmd, 7.5, 7.5);
295
Chia-I Wu426072d2014-08-26 14:31:55 +0800296 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800297 if (enable_cut_index)
298 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
299
Chia-I Wu72292b72014-09-09 10:48:33 +0800300 cmd_batch_pointer(cmd, cmd_len, &dw);
301 dw[0] = dw0;
302 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800303}
304
Cody Northrop293d4502015-05-05 09:38:03 -0600305static void gen6_add_scratch_space(struct intel_cmd *cmd,
306 uint32_t batch_pos,
307 const struct intel_pipeline *pipeline,
308 const struct intel_pipeline_shader *sh)
309{
310 int scratch_space;
311
312 CMD_ASSERT(cmd, 6, 7.5);
313
314 assert(sh->per_thread_scratch_size &&
315 sh->per_thread_scratch_size % 1024 == 0 &&
316 u_is_pow2(sh->per_thread_scratch_size) &&
317 sh->scratch_offset % 1024 == 0);
318 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
319
320 cmd_reserve_reloc(cmd, 1);
321 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
322 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
323}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600324
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800325static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
326{
Cody Northrop293d4502015-05-05 09:38:03 -0600327 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
328 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600330 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800331 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600332 int vue_read_len = 0;
333 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800334
Cody Northrop293d4502015-05-05 09:38:03 -0600335 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
336
337 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
338
339 // based on ilo_gpe_init_gs_cso_gen6
340 vue_read_len = (gs->in_count + 1) / 2;
341 if (!vue_read_len)
342 vue_read_len = 1;
343
344 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
345 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
346 GEN6_THREADDISP_SPF;
347
348 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
349 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
350 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
351
352 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
353 GEN6_GS_DW5_STATISTICS |
354 GEN6_GS_DW5_RENDER_ENABLE;
355
356 dw6 = GEN6_GS_DW6_GS_ENABLE;
357
358 if (gs->discard_adj)
359 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
360
361 } else {
362 dw2 = 0;
363 dw4 = 0;
364 dw5 = GEN6_GS_DW5_STATISTICS;
365 dw6 = 0;
366 }
367
368 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800369 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600370 dw[1] = cmd->bind.pipeline.gs_offset;
371 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800372 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600373 dw[4] = dw4;
374 dw[5] = dw5;
375 dw[6] = dw6;
376
377 if (gs->per_thread_scratch_size)
378 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800379}
380
Chia-I Wu62a7f252014-08-29 11:31:16 +0800381static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
382{
Cody Northrop293d4502015-05-05 09:38:03 -0600383 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
384 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800385 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600386 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800387 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600388 int vue_read_len = 0;
389 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800390
Cody Northrop293d4502015-05-05 09:38:03 -0600391 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
392
393 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
394
395 // based on upload_gs_state
396 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
397 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
398
399 vue_read_len = (gs->in_count + 1) / 2;
400 if (!vue_read_len)
401 vue_read_len = 1;
402
403 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
404 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
405 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
406 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
407 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
408
409
410 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
411 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
412 GEN7_GS_DW5_STATISTICS |
413 GEN7_GS_DW5_GS_ENABLE;
414
415 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
416 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
417
418 if (gs->include_primitive_id)
419 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
420
421 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
422 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
423 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
424 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
425 } else {
426 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
427 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
428 dw6 = 0;
429 }
430 } else {
431 dw2 = 0;
432 dw4 = 0;
433 dw5 = GEN7_GS_DW5_STATISTICS;
434 dw6 = 0;
435 }
436
437 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800438 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600439 dw[1] = cmd->bind.pipeline.gs_offset;
440 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800441 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600442 dw[4] = dw4;
443 dw[5] = dw5;
444 dw[6] = dw6;
445
446 if (gs->per_thread_scratch_size)
447 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800448}
449
Chia-I Wud88e02d2014-08-25 10:56:13 +0800450static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600451 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800452{
453 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800454 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800455 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457
458 CMD_ASSERT(cmd, 6, 7.5);
459
Chia-I Wu72292b72014-09-09 10:48:33 +0800460 cmd_batch_pointer(cmd, cmd_len, &dw);
461 dw[0] = dw0;
462
Chia-I Wud88e02d2014-08-25 10:56:13 +0800463 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800464 dw[1] = 0;
465 dw[2] = (height - 1) << 16 |
466 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800467 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800468 dw[1] = 1;
469 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800470 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800471
472 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800473}
474
Chia-I Wu8016a172014-08-29 18:31:32 +0800475static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
476 uint32_t body[6])
477{
478 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800479 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +0800480 const struct intel_render_pass_subpass *subpass =
481 cmd->bind.render_pass_subpass;
Cody Northropf5bd2252015-08-17 11:10:49 -0600482 const struct intel_dynamic_raster_line *raster_line = cmd->bind.state.raster_line;
483 const struct intel_dynamic_raster_depth_bias *raster_depth_bias = cmd->bind.state.raster_depth_bias;
484 uint32_t dw1, dw2, dw3, dw4, dw5, dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800485
486 CMD_ASSERT(cmd, 6, 7.5);
487
488 dw1 = GEN7_SF_DW1_STATISTICS |
489 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
490 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
491 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
492 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700493 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800494
495 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wubdeed152015-07-09 12:16:29 +0800496 int format = GEN6_ZFORMAT_D32_FLOAT;
Chia-I Wu8016a172014-08-29 18:31:32 +0800497
Chia-I Wubdeed152015-07-09 12:16:29 +0800498 if (subpass->ds_index < rp->attachment_count) {
499 switch (rp->attachments[subpass->ds_index].format) {
500 case VK_FORMAT_D16_UNORM:
501 format = GEN6_ZFORMAT_D16_UNORM;
502 break;
503 case VK_FORMAT_D32_SFLOAT:
504 case VK_FORMAT_D32_SFLOAT_S8_UINT:
505 format = GEN6_ZFORMAT_D32_FLOAT;
506 break;
507 default:
508 assert(!"unsupported depth/stencil format");
509 break;
510 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800511 }
512
513 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
514 }
515
Tony Barbourfa6cac72015-01-16 14:27:35 -0700516 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800517
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700518 /* Scissor is always enabled */
519 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
520
Cody Northropf5bd2252015-08-17 11:10:49 -0600521 // TODO: line width support
522 (void) raster_line;
523
Tony Barbourfa6cac72015-01-16 14:27:35 -0700524 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800525 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
526 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
527 } else {
528 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
529 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
530 }
531
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600532 dw3 = 2 << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
533 1 << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
534 2 << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800535 GEN7_SF_DW3_SUBPIXEL_8BITS;
536
Cody Northropf5bd2252015-08-17 11:10:49 -0600537 if (pipeline->depthBiasEnable) {
538 dw4 = u_fui((float) raster_depth_bias->raster_depth_bias_info.depthBias * 2.0f);
539 dw5 = u_fui(raster_depth_bias->raster_depth_bias_info.slopeScaledDepthBias);
540 dw6 = u_fui(raster_depth_bias->raster_depth_bias_info.depthBiasClamp);
541 } else {
542 dw4 = 0;
543 dw5 = 0;
544 dw6 = 0;
545 }
546
Chia-I Wu8016a172014-08-29 18:31:32 +0800547 body[0] = dw1;
548 body[1] = dw2;
549 body[2] = dw3;
Cody Northropf5bd2252015-08-17 11:10:49 -0600550 body[3] = dw4;
551 body[4] = dw5;
552 body[5] = dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800553}
554
Chia-I Wu8016a172014-08-29 18:31:32 +0800555static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
556{
557 const uint8_t cmd_len = 20;
558 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
559 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800560 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800561 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800562 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800563
564 CMD_ASSERT(cmd, 6, 6);
565
566 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800567
Chia-I Wu72292b72014-09-09 10:48:33 +0800568 cmd_batch_pointer(cmd, cmd_len, &dw);
569 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800570 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800571 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800572 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800573}
574
575static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
576{
577 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800578 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800579
580 CMD_ASSERT(cmd, 7, 7.5);
581
Chia-I Wu72292b72014-09-09 10:48:33 +0800582 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800583 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
584 (cmd_len - 2);
585 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800586}
587
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800588static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
589{
590 const uint8_t cmd_len = 4;
591 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
592 (cmd_len - 2);
593 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700594 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800595 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourde4124d2015-07-03 10:33:54 -0600596 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800597 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800598
599 CMD_ASSERT(cmd, 6, 7.5);
600
601 dw1 = GEN6_CLIP_DW1_STATISTICS;
602 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
603 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
604 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700605 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800606 }
607
608 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800609 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800610 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700611 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600612 2 << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
613 1 << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
614 2 << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800615
616 if (pipeline->rasterizerDiscardEnable)
617 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
618 else
619 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
620
621 if (pipeline->depthClipEnable)
622 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
623
624 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
625 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
626 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
627 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
628
629 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
630 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
631 (viewport->viewport_count - 1);
632
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600633 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600634 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600635 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
636 }
637
Chia-I Wu72292b72014-09-09 10:48:33 +0800638 cmd_batch_pointer(cmd, cmd_len, &dw);
639 dw[0] = dw0;
640 dw[1] = dw1;
641 dw[2] = dw2;
642 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800643}
644
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800645static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
646{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800647 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800648 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800649 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600650 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700651 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800652
653 CMD_ASSERT(cmd, 6, 6);
654
655 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
656
657 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
658 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
659
660 dw4 = GEN6_WM_DW4_STATISTICS |
661 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
662 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700663 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800664
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800665 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700666 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
667 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668
Cody Northrope86574e2015-02-24 14:15:29 -0700669 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700670 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700671
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800672 if (fs->uses & INTEL_SHADER_USE_KILL ||
673 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700674 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800675
Cody Northrope238deb2015-01-26 14:41:36 -0700676 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800677 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
678 if (fs->uses & INTEL_SHADER_USE_DEPTH)
679 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
680 if (fs->uses & INTEL_SHADER_USE_W)
681 dw5 |= GEN6_WM_DW5_PS_USE_W;
682
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700683 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700684 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800685
686 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700687 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688 GEN6_WM_DW6_ZW_INTERP_PIXEL |
689 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
690 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
691
Tony Barbourfa6cac72015-01-16 14:27:35 -0700692 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
694 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
695 } else {
696 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
697 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
698 }
699
Cody Northrope86574e2015-02-24 14:15:29 -0700700 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
701
Chia-I Wu784d3042014-12-19 14:30:04 +0800702 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800703 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800704 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800705 dw[2] = dw2;
706 dw[3] = 0; /* scratch */
707 dw[4] = dw4;
708 dw[5] = dw5;
709 dw[6] = dw6;
710 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700711 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800712
713 if (fs->per_thread_scratch_size)
714 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800715}
716
717static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
718{
719 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800720 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800721 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800722 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723
724 CMD_ASSERT(cmd, 7, 7.5);
725
726 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
727
728 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700729 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800730 GEN7_WM_DW1_ZW_INTERP_PIXEL |
731 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
732 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
733
734 if (fs->uses & INTEL_SHADER_USE_KILL ||
735 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700736 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800737
Cody Northrope238deb2015-01-26 14:41:36 -0700738 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
739
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800740 if (fs->uses & INTEL_SHADER_USE_DEPTH)
741 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
742 if (fs->uses & INTEL_SHADER_USE_W)
743 dw1 |= GEN7_WM_DW1_PS_USE_W;
744
745 dw2 = 0;
746
Tony Barbourfa6cac72015-01-16 14:27:35 -0700747 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800748 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
749 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
750 } else {
751 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
752 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
753 }
754
Chia-I Wu72292b72014-09-09 10:48:33 +0800755 cmd_batch_pointer(cmd, cmd_len, &dw);
756 dw[0] = dw0;
757 dw[1] = dw1;
758 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800759}
760
761static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
762{
763 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800764 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800765 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700766 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600767 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800768
769 CMD_ASSERT(cmd, 7, 7.5);
770
771 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
772
773 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
774 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
775
776 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700777 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800778
Cody Northrope86574e2015-02-24 14:15:29 -0700779 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700780 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700781
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800782 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800783 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700784 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800785 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800786 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800787 }
788
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800789 if (fs->in_count)
790 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
791
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700792 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800793 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
794
795 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
796 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700797 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
798
799 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800800
Chia-I Wu784d3042014-12-19 14:30:04 +0800801 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800802 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800803 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800804 dw[2] = dw2;
805 dw[3] = 0; /* scratch */
806 dw[4] = dw4;
807 dw[5] = dw5;
808 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700809 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800810
811 if (fs->per_thread_scratch_size)
812 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800813}
814
Chia-I Wu8ada4242015-03-02 11:19:33 -0700815static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
816 uint32_t sample_count)
817{
818 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
819 uint32_t dw1, dw2, dw3, *dw;
820
821 CMD_ASSERT(cmd, 6, 7.5);
822
823 switch (sample_count) {
824 case 4:
825 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
826 dw2 = cmd->dev->sample_pattern_4x;
827 dw3 = 0;
828 break;
829 case 8:
830 assert(cmd_gen(cmd) >= INTEL_GEN(7));
831 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
832 dw2 = cmd->dev->sample_pattern_8x[0];
833 dw3 = cmd->dev->sample_pattern_8x[1];
834 break;
835 default:
836 assert(sample_count <= 1);
837 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
838 dw2 = 0;
839 dw3 = 0;
840 break;
841 }
842
843 cmd_batch_pointer(cmd, cmd_len, &dw);
844
845 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
846 dw[1] = dw1;
847 dw[2] = dw2;
848 if (cmd_gen(cmd) >= INTEL_GEN(7))
849 dw[3] = dw3;
850}
851
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800852static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800853 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700854 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800855{
856 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600858 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800859
860 CMD_ASSERT(cmd, 6, 7.5);
861
862 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
864 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800865 dw0 |= (cmd_len - 2);
866
Chia-I Wu72292b72014-09-09 10:48:33 +0800867 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
868 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700869
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800870 dw[1] = view->att_cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700871 /* note that we only enable HiZ on Gen7+ */
872 if (!optimal_ds)
873 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
874
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 dw[2] = 0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800876 dw[3] = view->att_cmd[2];
877 dw[4] = view->att_cmd[3];
878 dw[5] = view->att_cmd[4];
879 dw[6] = view->att_cmd[5];
Chia-I Wu72292b72014-09-09 10:48:33 +0800880
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600881 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800882 cmd_reserve_reloc(cmd, 1);
883 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800884 view->att_cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600885 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800886}
887
888static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800889 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700890 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800891{
892 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800893 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600894 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800895
896 CMD_ASSERT(cmd, 6, 7.5);
897
898 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800899 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
900 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800901 dw0 |= (cmd_len - 2);
902
Chia-I Wu72292b72014-09-09 10:48:33 +0800903 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
904 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800905
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700906 if (view->has_stencil) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800907 dw[1] = view->att_cmd[6];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700908
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 cmd_reserve_reloc(cmd, 1);
910 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800911 view->att_cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700912 } else {
913 dw[1] = 0;
914 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600915 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800916}
917
918static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800919 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700920 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800921{
922 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800923 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600924 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800925
926 CMD_ASSERT(cmd, 6, 7.5);
927
928 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800929 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
930 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800931 dw0 |= (cmd_len - 2);
932
Chia-I Wu72292b72014-09-09 10:48:33 +0800933 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
934 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800935
Chia-I Wu73520ac2015-02-19 11:17:45 -0700936 if (view->has_hiz && optimal_ds) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800937 dw[1] = view->att_cmd[8];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700938
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 cmd_reserve_reloc(cmd, 1);
940 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800941 view->att_cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700942 } else {
943 dw[1] = 0;
944 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600945 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800946}
947
Chia-I Wuf8231032014-08-25 10:44:45 +0800948static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
949 uint32_t clear_val)
950{
951 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800952 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800953 GEN6_CLEAR_PARAMS_DW0_VALID |
954 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800956
957 CMD_ASSERT(cmd, 6, 6);
958
Chia-I Wu72292b72014-09-09 10:48:33 +0800959 cmd_batch_pointer(cmd, cmd_len, &dw);
960 dw[0] = dw0;
961 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800962}
963
964static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
965 uint32_t clear_val)
966{
967 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800968 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800969 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800970 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800971
972 CMD_ASSERT(cmd, 7, 7.5);
973
Chia-I Wu72292b72014-09-09 10:48:33 +0800974 cmd_batch_pointer(cmd, cmd_len, &dw);
975 dw[0] = dw0;
976 dw[1] = clear_val;
977 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800978}
979
Chia-I Wu302742d2014-08-22 10:28:29 +0800980static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800981 uint32_t blend_offset,
982 uint32_t ds_offset,
983 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800984{
985 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800986 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987
988 CMD_ASSERT(cmd, 6, 6);
989
Chia-I Wu426072d2014-08-26 14:31:55 +0800990 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800991 (cmd_len - 2);
992
Chia-I Wu72292b72014-09-09 10:48:33 +0800993 cmd_batch_pointer(cmd, cmd_len, &dw);
994 dw[0] = dw0;
995 dw[1] = blend_offset | 1;
996 dw[2] = ds_offset | 1;
997 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800998}
999
Chia-I Wu1744cca2014-08-22 11:10:17 +08001000static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001001 uint32_t clip_offset,
1002 uint32_t sf_offset,
1003 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001004{
1005 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001006 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001007
1008 CMD_ASSERT(cmd, 6, 6);
1009
Chia-I Wu426072d2014-08-26 14:31:55 +08001010 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001011 GEN6_VP_PTR_DW0_CLIP_CHANGED |
1012 GEN6_VP_PTR_DW0_SF_CHANGED |
1013 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001014 (cmd_len - 2);
1015
Chia-I Wu72292b72014-09-09 10:48:33 +08001016 cmd_batch_pointer(cmd, cmd_len, &dw);
1017 dw[0] = dw0;
1018 dw[1] = clip_offset;
1019 dw[2] = sf_offset;
1020 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001021}
1022
1023static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001024 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001025{
1026 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001027 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001028
1029 CMD_ASSERT(cmd, 6, 6);
1030
Chia-I Wu426072d2014-08-26 14:31:55 +08001031 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001032 (cmd_len - 2);
1033
Chia-I Wu72292b72014-09-09 10:48:33 +08001034 cmd_batch_pointer(cmd, cmd_len, &dw);
1035 dw[0] = dw0;
1036 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001037}
1038
Chia-I Wu42a56202014-08-23 16:47:48 +08001039static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001040 uint32_t vs_offset,
1041 uint32_t gs_offset,
1042 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001043{
1044 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001045 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001046
1047 CMD_ASSERT(cmd, 6, 6);
1048
Chia-I Wu426072d2014-08-26 14:31:55 +08001049 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001050 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1051 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1052 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001053 (cmd_len - 2);
1054
Chia-I Wu72292b72014-09-09 10:48:33 +08001055 cmd_batch_pointer(cmd, cmd_len, &dw);
1056 dw[0] = dw0;
1057 dw[1] = vs_offset;
1058 dw[2] = gs_offset;
1059 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001060}
1061
Chia-I Wu257e75e2014-08-29 14:06:35 +08001062static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001063 uint32_t vs_offset,
1064 uint32_t gs_offset,
1065 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001066{
1067 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001068 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001069
1070 CMD_ASSERT(cmd, 6, 6);
1071
1072 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001073 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1074 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1075 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001076 (cmd_len - 2);
1077
Chia-I Wu72292b72014-09-09 10:48:33 +08001078 cmd_batch_pointer(cmd, cmd_len, &dw);
1079 dw[0] = dw0;
1080 dw[1] = vs_offset;
1081 dw[2] = gs_offset;
1082 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001083}
1084
Chia-I Wu302742d2014-08-22 10:28:29 +08001085static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001086 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001087{
1088 const uint8_t cmd_len = 2;
1089 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1090 GEN6_RENDER_SUBTYPE_3D |
1091 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001092 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001093
Chia-I Wu72292b72014-09-09 10:48:33 +08001094 cmd_batch_pointer(cmd, cmd_len, &dw);
1095 dw[0] = dw0;
1096 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001097}
1098
Chia-I Wua6c4f152014-12-02 04:19:58 +08001099static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001100{
Chia-I Wue6073342014-11-30 09:43:42 +08001101 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001102 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1103 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001104
1105 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001106 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001107
Tony Barbourfa6cac72015-01-16 14:27:35 -07001108 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001109}
1110
Chia-I Wu72292b72014-09-09 10:48:33 +08001111static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Cody Northrop2605cb02015-08-18 15:21:16 -06001112 const struct intel_dynamic_stencil *stencil_state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001113{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001114 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001115 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001116 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001117 uint32_t dw[3];
1118
1119 dw[0] = pipeline->cmd_depth_stencil;
Cody Northrop2605cb02015-08-18 15:21:16 -06001120
1121 /* TODO: enable back facing stencil state */
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001122 /* same read and write masks for both front and back faces */
Cody Northrop2605cb02015-08-18 15:21:16 -06001123 dw[1] = (stencil_state->stencil_info_front.stencilReadMask & 0xff) << 24 |
1124 (stencil_state->stencil_info_front.stencilWriteMask & 0xff) << 16 |
1125 (stencil_state->stencil_info_front.stencilReadMask & 0xff) << 8 |
1126 (stencil_state->stencil_info_front.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001127 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001128
1129 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001130
Cody Northrop2605cb02015-08-18 15:21:16 -06001131 if (stencil_state->stencil_info_front.stencilWriteMask && pipeline->stencilTestEnable)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001132 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001133
Chia-I Wu00b51a82014-09-09 12:07:37 +08001134 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001135 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001136}
1137
Chia-I Wu72292b72014-09-09 10:48:33 +08001138static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001139 uint32_t stencil_ref,
1140 const uint32_t blend_color[4])
1141{
Chia-I Wue6073342014-11-30 09:43:42 +08001142 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001143 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001144 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001145
1146 CMD_ASSERT(cmd, 6, 7.5);
1147
Chia-I Wu00b51a82014-09-09 12:07:37 +08001148 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1149 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001150 dw[0] = stencil_ref;
1151 dw[1] = 0;
1152 dw[2] = blend_color[0];
1153 dw[3] = blend_color[1];
1154 dw[4] = blend_color[2];
1155 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001156
Chia-I Wu72292b72014-09-09 10:48:33 +08001157 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001158}
1159
Chia-I Wu8370b402014-08-29 12:28:37 +08001160static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001161{
Chia-I Wu8370b402014-08-29 12:28:37 +08001162 CMD_ASSERT(cmd, 6, 7.5);
1163
Chia-I Wu707a29e2014-08-27 12:51:47 +08001164 if (!cmd->bind.draw_count)
1165 return;
1166
Chia-I Wu8370b402014-08-29 12:28:37 +08001167 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001168 return;
1169
Chia-I Wu8370b402014-08-29 12:28:37 +08001170 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001171
1172 /*
1173 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1174 *
1175 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1176 * pipe-control with a post-sync op and no write-cache flushes."
1177 *
1178 * The workaround below necessitates this workaround.
1179 */
1180 gen6_PIPE_CONTROL(cmd,
1181 GEN6_PIPE_CONTROL_CS_STALL |
1182 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001183 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001184
Chia-I Wud6d079d2014-08-31 13:14:21 +08001185 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1186 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001187}
1188
Chia-I Wu8370b402014-08-29 12:28:37 +08001189static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001190{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001191 CMD_ASSERT(cmd, 6, 7.5);
1192
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001193 if (!cmd->bind.draw_count)
1194 return;
1195
Chia-I Wud6d079d2014-08-31 13:14:21 +08001196 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1197 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001198}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001199
Chia-I Wu8370b402014-08-29 12:28:37 +08001200static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1201{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001202 CMD_ASSERT(cmd, 7, 7.5);
1203
Chia-I Wu8370b402014-08-29 12:28:37 +08001204 if (!cmd->bind.draw_count)
1205 return;
1206
1207 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001208
1209 gen6_PIPE_CONTROL(cmd,
1210 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001211 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001212}
1213
Chia-I Wu8370b402014-08-29 12:28:37 +08001214static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1215{
1216 CMD_ASSERT(cmd, 7, 7.5);
1217
Chia-I Wu8370b402014-08-29 12:28:37 +08001218 /*
1219 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1220 *
1221 * "One of the following must also be set (when CS stall is set):
1222 *
1223 * * Render Target Cache Flush Enable ([12] of DW1)
1224 * * Depth Cache Flush Enable ([0] of DW1)
1225 * * Stall at Pixel Scoreboard ([1] of DW1)
1226 * * Depth Stall ([13] of DW1)
1227 * * Post-Sync Operation ([13] of DW1)"
1228 */
1229 gen6_PIPE_CONTROL(cmd,
1230 GEN6_PIPE_CONTROL_CS_STALL |
1231 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001232 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001233}
1234
1235static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1236{
1237 CMD_ASSERT(cmd, 7, 7.5);
1238
Chia-I Wu8370b402014-08-29 12:28:37 +08001239 cmd_wa_gen6_pre_depth_stall_write(cmd);
1240
Chia-I Wud6d079d2014-08-31 13:14:21 +08001241 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001242}
1243
1244static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1245{
1246 CMD_ASSERT(cmd, 6, 7.5);
1247
1248 if (!cmd->bind.draw_count)
1249 return;
1250
1251 /*
1252 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1253 *
1254 * "Driver must guarentee that all the caches in the depth pipe are
1255 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1256 * requires driver to send a PIPE_CONTROL with a CS stall along with
1257 * a Depth Flush prior to this command."
1258 *
1259 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1260 *
1261 * "Driver must ierarchi that all the caches in the depth pipe are
1262 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1263 * requires driver to send a PIPE_CONTROL with a CS stall along with
1264 * a Depth Flush prior to this command.
1265 */
1266 gen6_PIPE_CONTROL(cmd,
1267 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1268 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001269 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001270}
1271
1272static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1273{
1274 CMD_ASSERT(cmd, 6, 7.5);
1275
1276 if (!cmd->bind.draw_count)
1277 return;
1278
1279 /*
1280 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1281 *
1282 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1283 * and a post sync operation prior to the group of depth
1284 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1285 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1286 *
1287 * This workaround satifies all the conditions.
1288 */
1289 cmd_wa_gen6_pre_depth_stall_write(cmd);
1290
1291 /*
1292 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1293 *
1294 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1295 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1296 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1297 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1298 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1299 * Depth Flush Bit set, followed by another pipelined depth stall
1300 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1301 * guarantee that the pipeline from WM onwards is already flushed
1302 * (e.g., via a preceding MI_FLUSH)."
1303 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001304 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1305 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1306 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001307}
1308
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001309void cmd_batch_state_base_address(struct intel_cmd *cmd)
1310{
1311 const uint8_t cmd_len = 10;
1312 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1313 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001314 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001315 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001316 uint32_t pos;
1317 uint32_t *dw;
1318
1319 CMD_ASSERT(cmd, 6, 7.5);
1320
1321 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1322
1323 dw[0] = dw0;
1324 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001325 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001326 dw[2] = 1;
1327 dw[3] = 1;
1328 dw[4] = 1;
1329 dw[5] = 1;
1330 /* end offsets */
1331 dw[6] = 1;
1332 dw[7] = 1 + 0xfffff000;
1333 dw[8] = 1 + 0xfffff000;
1334 dw[9] = 1;
1335
1336 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001337 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1338 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1339 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1340 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1341 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1342 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001343}
1344
Chia-I Wu7c853562015-02-27 14:35:08 -07001345void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1346{
1347 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1348 const uint8_t cmd_len = 2;
1349 uint32_t offset = 0;
1350 uint32_t *dw;
1351
1352 if (cmd_gen(cmd) <= INTEL_GEN(6))
1353 return;
1354
1355 CMD_ASSERT(cmd, 7, 7.5);
1356
1357 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1358 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1359 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1360 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1361 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1362 offset += size;
1363
1364 dw += 2;
1365 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1366 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1367 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1368
1369 dw += 2;
1370 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1371 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1372 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1373
1374 dw += 2;
1375 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1376 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1377 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1378
1379 dw += 2;
1380 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1381 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1382 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1383
1384 /*
1385 *
1386 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1387 *
1388 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1389 * in the ring after this instruction
1390 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1391 */
1392 cmd_wa_gen7_post_command_cs_stall(cmd);
1393}
1394
Chia-I Wu525c6602014-08-27 10:22:34 +08001395void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1396{
Mike Stroyan552fda42015-01-30 17:21:08 -07001397 if (pipe_control_dw0 == 0)
1398 return;
1399
Chia-I Wu525c6602014-08-27 10:22:34 +08001400 if (!cmd->bind.draw_count)
1401 return;
1402
1403 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1404
Chia-I Wu8370b402014-08-29 12:28:37 +08001405 /*
1406 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1407 *
1408 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1409 * PIPE_CONTROL with any non-zero post-sync-op is required."
1410 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001411 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001412 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001413
Chia-I Wu092279a2014-08-30 19:05:30 +08001414 /*
1415 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1416 *
1417 * "One of the following must also be set (when CS stall is set):
1418 *
1419 * * Render Target Cache Flush Enable ([12] of DW1)
1420 * * Depth Cache Flush Enable ([0] of DW1)
1421 * * Stall at Pixel Scoreboard ([1] of DW1)
1422 * * Depth Stall ([13] of DW1)
1423 * * Post-Sync Operation ([13] of DW1)"
1424 */
1425 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1426 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1427 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1428 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1429 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1430 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1431
Chia-I Wud6d079d2014-08-31 13:14:21 +08001432 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001433}
1434
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001435void cmd_batch_flush_all(struct intel_cmd *cmd)
1436{
1437 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1438 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1439 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1440 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1441 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1442 GEN6_PIPE_CONTROL_CS_STALL);
1443}
1444
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001445void cmd_batch_depth_count(struct intel_cmd *cmd,
1446 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001447 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001448{
1449 cmd_wa_gen6_pre_depth_stall_write(cmd);
1450
1451 gen6_PIPE_CONTROL(cmd,
1452 GEN6_PIPE_CONTROL_DEPTH_STALL |
1453 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001454 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001455}
1456
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001457void cmd_batch_timestamp(struct intel_cmd *cmd,
1458 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001459 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001460{
1461 /* need any WA or stall? */
1462 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1463}
1464
1465void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001466 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001467 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001468 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001469 uint64_t val)
1470{
1471 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001472 gen6_PIPE_CONTROL(cmd,
1473 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1474 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001475}
1476
Chia-I Wu302742d2014-08-22 10:28:29 +08001477static void gen6_cc_states(struct intel_cmd *cmd)
1478{
Tony Barbourde4124d2015-07-03 10:33:54 -06001479 const struct intel_dynamic_color_blend *blend = cmd->bind.state.blend;
Cody Northrop2605cb02015-08-18 15:21:16 -06001480 const struct intel_dynamic_depth *ds = cmd->bind.state.depth;
1481 const struct intel_dynamic_stencil *ss = cmd->bind.state.stencil;
Chia-I Wu72292b72014-09-09 10:48:33 +08001482 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001483 uint32_t stencil_ref;
1484 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001485
1486 CMD_ASSERT(cmd, 6, 6);
1487
Chia-I Wua6c4f152014-12-02 04:19:58 +08001488 blend_offset = gen6_BLEND_STATE(cmd);
1489
1490 if (blend)
Tony Barbourde4124d2015-07-03 10:33:54 -06001491 memcpy(blend_color, blend->color_blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001492 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001493 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001494
Cody Northrop2605cb02015-08-18 15:21:16 -06001495 if (ss) {
1496 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1497 /* TODO: enable back facing stencil state */
1498 /* same reference for both front and back faces */
1499 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1500 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001501 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001502 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001503 stencil_ref = 0;
1504 }
1505
Chia-I Wu72292b72014-09-09 10:48:33 +08001506 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001507
Chia-I Wu72292b72014-09-09 10:48:33 +08001508 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001509}
1510
Chia-I Wu1744cca2014-08-22 11:10:17 +08001511static void gen6_viewport_states(struct intel_cmd *cmd)
1512{
Tony Barbourde4124d2015-07-03 10:33:54 -06001513 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001514 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001515
1516 if (!viewport)
1517 return;
1518
Tony Barbourfa6cac72015-01-16 14:27:35 -07001519 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001520 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001521
1522 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001523 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001524 viewport->cmd);
1525
1526 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001527 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001528 &viewport->cmd[viewport->cmd_clip_pos]);
1529
1530 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001531 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001532 &viewport->cmd[viewport->cmd_cc_pos]);
1533
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001534 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1535 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1536 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001537
1538 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001539 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001540
Chia-I Wub1d450a2014-09-09 13:48:03 +08001541 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001542}
1543
Chia-I Wu302742d2014-08-22 10:28:29 +08001544static void gen7_cc_states(struct intel_cmd *cmd)
1545{
Tony Barbourde4124d2015-07-03 10:33:54 -06001546 const struct intel_dynamic_color_blend *blend = cmd->bind.state.blend;
Cody Northrop2605cb02015-08-18 15:21:16 -06001547 const struct intel_dynamic_depth *ds = cmd->bind.state.depth;
1548 const struct intel_dynamic_stencil *ss = cmd->bind.state.stencil;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001549 uint32_t stencil_ref;
1550 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001551 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001552
1553 CMD_ASSERT(cmd, 7, 7.5);
1554
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001555 if (!blend && !ds)
1556 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001557
Chia-I Wua6c4f152014-12-02 04:19:58 +08001558 offset = gen6_BLEND_STATE(cmd);
1559 gen7_3dstate_pointer(cmd,
1560 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001561
Chia-I Wua6c4f152014-12-02 04:19:58 +08001562 if (blend)
Tony Barbourde4124d2015-07-03 10:33:54 -06001563 memcpy(blend_color, blend->color_blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001564 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001565 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001566
Cody Northrop2605cb02015-08-18 15:21:16 -06001567 if (ss) {
1568 offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1569 /* TODO: enable back facing stencil state */
1570 /* same reference for both front and back faces */
1571 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1572 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001573 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001574 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1575 offset);
Cody Northrop2605cb02015-08-18 15:21:16 -06001576 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1577 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001578 } else {
1579 stencil_ref = 0;
1580 }
1581
Chia-I Wu72292b72014-09-09 10:48:33 +08001582 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001583 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001584 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001585}
1586
Chia-I Wu1744cca2014-08-22 11:10:17 +08001587static void gen7_viewport_states(struct intel_cmd *cmd)
1588{
Tony Barbourde4124d2015-07-03 10:33:54 -06001589 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001590 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001591
1592 if (!viewport)
1593 return;
1594
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001595 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001596
Chia-I Wub1d450a2014-09-09 13:48:03 +08001597 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001598 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001599 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001600 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001601 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1602 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001603
1604 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001605 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001606 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001607 gen7_3dstate_pointer(cmd,
1608 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001609 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001610
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001611 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1612 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1613 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1614 gen7_3dstate_pointer(cmd,
1615 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1616 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001617}
1618
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001619static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001620 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001621{
1622 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001623 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001624
Chia-I Wu72292b72014-09-09 10:48:33 +08001625 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001626
1627 dw[0] = GEN6_RENDER_TYPE_RENDER |
1628 GEN6_RENDER_SUBTYPE_3D |
1629 subop | (cmd_len - 2);
1630 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001631 dw[2] = 0;
1632 dw[3] = 0;
1633 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001634}
1635
1636static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001637 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001638{
1639 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001640 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001641
Chia-I Wu72292b72014-09-09 10:48:33 +08001642 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001643
1644 dw[0] = GEN6_RENDER_TYPE_RENDER |
1645 GEN6_RENDER_SUBTYPE_3D |
1646 subop | (cmd_len - 2);
1647 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001648 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001649 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001650 dw[4] = 0;
1651 dw[5] = 0;
1652 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001653}
1654
Chia-I Wu625105f2014-10-13 15:35:29 +08001655static uint32_t emit_samplers(struct intel_cmd *cmd,
1656 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001657{
Chia-I Wu862c5572015-03-28 15:23:55 +08001658 const struct intel_desc_region *region = cmd->dev->desc_region;
1659 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001660 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1661 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001662 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001663 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001664 uint32_t surface_count;
1665 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001666
1667 CMD_ASSERT(cmd, 6, 7.5);
1668
Chia-I Wu625105f2014-10-13 15:35:29 +08001669 if (!rmap || !rmap->sampler_count)
1670 return 0;
1671
Cody Northrop40316a32014-12-09 19:08:33 -07001672 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001673
Chia-I Wudcb509d2014-12-10 08:53:10 +08001674 /*
1675 * note that we cannot call cmd_state_pointer() here as the following
1676 * cmd_state_pointer() would invalidate the pointer
1677 */
1678 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001679 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001680 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001681
1682 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001683 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001684 4 * rmap->sampler_count, &sampler_dw);
1685
Chia-I Wudcb509d2014-12-10 08:53:10 +08001686 cmd_state_update(cmd, border_offset,
1687 border_stride * rmap->sampler_count, &border_dw);
1688
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001689 for (i = 0; i < rmap->sampler_count; i++) {
1690 const struct intel_pipeline_rmap_slot *slot =
1691 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001692 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001693 const struct intel_sampler *sampler;
1694
Chia-I Wuf8385062015-01-04 16:27:24 +08001695 switch (slot->type) {
1696 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001697 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1698 &data->set_offsets[slot->index]);
1699 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001700 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001701 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001702 sampler = NULL;
1703 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001704 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001705 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001706 sampler = NULL;
1707 break;
1708 }
1709
1710 if (sampler) {
1711 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1712
1713 sampler_dw[0] = sampler->cmd[0];
1714 sampler_dw[1] = sampler->cmd[1];
1715 sampler_dw[2] = border_offset;
1716 sampler_dw[3] = sampler->cmd[2];
1717 } else {
1718 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1719 sampler_dw[1] = 0;
1720 sampler_dw[2] = 0;
1721 sampler_dw[3] = 0;
1722 }
1723
1724 border_offset += border_stride * 4;
1725 border_dw += border_stride;
1726 sampler_dw += 4;
1727 }
1728
Chia-I Wu625105f2014-10-13 15:35:29 +08001729 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001730}
1731
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001732static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001733 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001734 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001735{
Chia-I Wu862c5572015-03-28 15:23:55 +08001736 const struct intel_desc_region *region = cmd->dev->desc_region;
1737 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001738 const uint32_t sba_offset =
1739 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001740 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001741 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001742
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001743 CMD_ASSERT(cmd, 6, 7.5);
1744
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001745 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001746 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001747 if (!surface_count)
1748 return 0;
1749
Chia-I Wu42a56202014-08-23 16:47:48 +08001750 assert(surface_count <= ARRAY_SIZE(binding_table));
1751
1752 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001753 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001754 struct intel_null_view null_view;
1755 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001756
Chia-I Wuf8385062015-01-04 16:27:24 +08001757 switch (slot->type) {
1758 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001759 {
Chia-I Wubdeed152015-07-09 12:16:29 +08001760 const struct intel_render_pass_subpass *subpass =
1761 cmd->bind.render_pass_subpass;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001762 const struct intel_fb *fb = cmd->bind.fb;
1763 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08001764 (slot->index < subpass->color_count &&
1765 subpass->color_indices[slot->index] < fb->view_count) ?
1766 fb->views[subpass->color_indices[slot->index]] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001767
Chia-I Wu787a05b2014-12-05 11:02:20 +08001768 if (view) {
1769 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1770 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001771 view->cmd_len, view->att_cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001772
Chia-I Wu787a05b2014-12-05 11:02:20 +08001773 cmd_reserve_reloc(cmd, 1);
1774 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001775 view->att_cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu787a05b2014-12-05 11:02:20 +08001776 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001777 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001778 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001779 }
1780 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001781 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001782 {
Tony Barbour22a30862015-04-22 09:02:32 -06001783 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001784 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001785 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001786 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001787 const struct intel_mem *mem;
1788 bool read_only;
1789 const uint32_t *cmd_data;
1790 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001791
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001792 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001793 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001794
Chia-I Wu862c5572015-03-28 15:23:55 +08001795 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1796 &data->set_offsets[slot->index]);
1797
1798 intel_desc_region_read_surface(region, &desc_offset, stage,
1799 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001800 if (mem) {
1801 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001802 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001803 const uint32_t reloc_flags =
1804 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001805
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001806 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001807 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001808 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001809
1810 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001811 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1812 cmd_data[1] + dynamic_offset, reloc_flags);
1813 } else {
1814 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001815 }
1816 }
1817 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001818 case INTEL_PIPELINE_RMAP_UNUSED:
1819 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001820 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001821 default:
1822 assert(!"unexpected rmap type");
1823 need_null_view = true;
1824 break;
1825 }
1826
1827 if (need_null_view) {
1828 intel_null_view_init(&null_view, cmd->dev);
1829 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1830 GEN6_ALIGNMENT_SURFACE_STATE,
1831 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001832 }
1833
Chia-I Wuf98dd882015-02-10 04:17:47 +08001834 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001835 }
1836
Chia-I Wuf98dd882015-02-10 04:17:47 +08001837 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001838 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001839 surface_count, binding_table) - sba_offset;
1840
1841 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1842 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1843
1844 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001845}
1846
Chia-I Wu1d125092014-10-08 08:49:38 +08001847static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1848{
1849 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001850 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1851 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001852 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001853
1854 CMD_ASSERT(cmd, 6, 7.5);
1855
1856 if (!pipeline->vb_count)
1857 return;
1858
1859 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1860
1861 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1862 dw++;
1863 pos++;
1864
1865 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001866 assert(pipeline->vb[i].strideInBytes <= 2048);
1867
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001868 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001869 pipeline->vb[i].strideInBytes;
1870
Chia-I Wub3686982015-02-27 09:51:16 -07001871 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001872 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1873 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001874 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001875
1876 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001877 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001878 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001879 dw[3] = 0;
1880 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001881 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001882 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001883 dw[3] = 1;
1884 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001885 default:
1886 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001887 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001888 dw[3] = 0;
1889 break;
1890 }
1891
Chia-I Wu714df452015-01-01 07:55:04 +08001892 if (cmd->bind.vertex.buf[i]) {
1893 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001894 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001895
1896 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001897 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1898 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001899 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001900 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001901 dw[1] = 0;
1902 dw[2] = 0;
1903 }
1904
1905 dw += 4;
1906 pos += 4;
1907 }
1908}
1909
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001910static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1911{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001912 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1913 const struct intel_pipeline_shader *vs = &pipeline->vs;
1914 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001915 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001916 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001917 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001918 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001919
1920 CMD_ASSERT(cmd, 6, 7.5);
1921
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001922 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001923 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1924 *
1925 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1926 * 128-bit vertex elements to be passed into the payload for each
1927 * vertex."
1928 *
1929 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1930 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001931 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001932 vue_read_len = (vs->in_count + 1) / 2;
1933 if (!vue_read_len)
1934 vue_read_len = 1;
1935
1936 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1937 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1938
1939 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1940 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1941 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001942
1943 dw5 = GEN6_VS_DW5_STATISTICS |
1944 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001945
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001946 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001947 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001948 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001949 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001950
Chia-I Wube0a3d92014-09-02 13:20:59 +08001951 if (pipeline->disable_vs_cache)
1952 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1953
Chia-I Wu784d3042014-12-19 14:30:04 +08001954 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001955 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001956 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001957 dw[2] = dw2;
1958 dw[3] = 0; /* scratch */
1959 dw[4] = dw4;
1960 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001961
1962 if (vs->per_thread_scratch_size)
1963 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001964}
1965
Chia-I Wu625105f2014-10-13 15:35:29 +08001966static void emit_shader_resources(struct intel_cmd *cmd)
1967{
1968 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001969 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001970
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001971 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001972 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001973 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001974 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001975 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001976 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001977 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001978 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001979 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001980 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001981 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001982 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001983 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001984 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001985 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001986
1987 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1988 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1989 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1990 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1991 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1992
1993 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1994 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001995 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1996 binding_tables[0]);
1997 gen7_3dstate_pointer(cmd,
1998 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1999 binding_tables[1]);
2000 gen7_3dstate_pointer(cmd,
2001 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
2002 binding_tables[2]);
2003 gen7_3dstate_pointer(cmd,
2004 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
2005 binding_tables[3]);
2006 gen7_3dstate_pointer(cmd,
2007 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2008 binding_tables[4]);
2009
2010 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08002011 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
2012 samplers[0]);
2013 gen7_3dstate_pointer(cmd,
2014 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
2015 samplers[1]);
2016 gen7_3dstate_pointer(cmd,
2017 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
2018 samplers[2]);
2019 gen7_3dstate_pointer(cmd,
2020 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
2021 samplers[3]);
2022 gen7_3dstate_pointer(cmd,
2023 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2024 samplers[4]);
2025 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002026 assert(!binding_tables[1] && !binding_tables[2]);
2027 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2028 binding_tables[0], binding_tables[3], binding_tables[4]);
2029
Chia-I Wu625105f2014-10-13 15:35:29 +08002030 assert(!samplers[1] && !samplers[2]);
2031 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2032 samplers[0], samplers[3], samplers[4]);
2033 }
2034}
2035
Chia-I Wu8ada4242015-03-02 11:19:33 -07002036static void emit_msaa(struct intel_cmd *cmd)
2037{
Chia-I Wuc278df82015-07-07 11:50:03 +08002038 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002039
Chia-I Wubbc7d912015-02-27 14:59:50 -07002040 if (!cmd->bind.render_pass_changed)
2041 return;
2042
Chia-I Wu8ada4242015-03-02 11:19:33 -07002043 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wuc278df82015-07-07 11:50:03 +08002044 gen6_3DSTATE_MULTISAMPLE(cmd, pipeline->sample_count);
Chia-I Wu8ada4242015-03-02 11:19:33 -07002045}
2046
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002047static void emit_rt(struct intel_cmd *cmd)
2048{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002049 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002050
2051 if (!cmd->bind.render_pass_changed)
2052 return;
2053
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002054 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002055 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2056 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002057}
2058
2059static void emit_ds(struct intel_cmd *cmd)
2060{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002061 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +08002062 const struct intel_render_pass_subpass *subpass =
2063 cmd->bind.render_pass_subpass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002064 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002065 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08002066 (subpass->ds_index < rp->attachment_count) ?
2067 fb->views[subpass->ds_index] : NULL;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002068
Chia-I Wubbc7d912015-02-27 14:59:50 -07002069 if (!cmd->bind.render_pass_changed)
2070 return;
2071
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002072 if (!view) {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002073 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002074 static const struct intel_att_view null_view;
2075 view = &null_view;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002076 }
2077
2078 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wubdeed152015-07-09 12:16:29 +08002079 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
2080 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, subpass->ds_optimal);
2081 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002082
2083 if (cmd_gen(cmd) >= INTEL_GEN(7))
2084 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2085 else
2086 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2087}
2088
Chia-I Wua57761b2014-10-14 14:27:44 +08002089static uint32_t emit_shader(struct intel_cmd *cmd,
2090 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002091{
Chia-I Wua57761b2014-10-14 14:27:44 +08002092 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2093 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002094 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002095
Chia-I Wua57761b2014-10-14 14:27:44 +08002096 /* see if the shader is already in the cache */
2097 for (i = 0; i < cache->used; i++) {
2098 if (cache->entries[i].shader == (const void *) shader)
2099 return cache->entries[i].kernel_offset;
2100 }
2101
2102 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2103
2104 /* grow the cache if full */
2105 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002106 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002107 void *entries;
2108
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002109 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002110 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002111 if (entries) {
2112 if (cache->entries) {
2113 memcpy(entries, cache->entries,
2114 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002115 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002116 }
2117
2118 cache->entries = entries;
2119 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002120 }
2121 }
2122
Chia-I Wua57761b2014-10-14 14:27:44 +08002123 /* add the shader to the cache */
2124 if (cache->used < cache->count) {
2125 cache->entries[cache->used].shader = (const void *) shader;
2126 cache->entries[cache->used].kernel_offset = offset;
2127 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002128 }
2129
Chia-I Wua57761b2014-10-14 14:27:44 +08002130 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002131}
2132
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002133static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002134{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002135 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002136
Chia-I Wu8370b402014-08-29 12:28:37 +08002137 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2138 cmd_wa_gen6_pre_depth_stall_write(cmd);
2139 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2140 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2141 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2142 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002143
2144 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002145 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002146 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002147
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002148 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002149 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002150 }
2151 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002152 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002153 }
2154 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002155 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2156 }
2157 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2158 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2159 }
2160 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2161 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002162 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002163
Chia-I Wu8370b402014-08-29 12:28:37 +08002164 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2165 cmd_wa_gen7_post_command_cs_stall(cmd);
2166 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2167 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002168}
2169
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002170static void emit_bounded_states(struct intel_cmd *cmd)
2171{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002172 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002173
2174 emit_graphics_pipeline(cmd);
2175
2176 emit_rt(cmd);
2177 emit_ds(cmd);
2178
2179 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2180 gen7_cc_states(cmd);
2181 gen7_viewport_states(cmd);
2182
2183 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2184 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002185 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2186 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002187 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2188 &cmd->bind.pipeline.graphics->fs);
2189
Cody Northrop293d4502015-05-05 09:38:03 -06002190 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002191 gen6_3DSTATE_CLIP(cmd);
2192 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002193 gen7_3DSTATE_WM(cmd);
2194 gen7_3DSTATE_PS(cmd);
2195 } else {
2196 gen6_cc_states(cmd);
2197 gen6_viewport_states(cmd);
2198
2199 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2200 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002201 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2202 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002203 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2204 &cmd->bind.pipeline.graphics->fs);
2205
Cody Northrop293d4502015-05-05 09:38:03 -06002206 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002207 gen6_3DSTATE_CLIP(cmd);
2208 gen6_3DSTATE_SF(cmd);
2209 gen6_3DSTATE_WM(cmd);
2210 }
2211
2212 emit_shader_resources(cmd);
2213
2214 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002215
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002216 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2217 gen6_3DSTATE_VS(cmd);
2218}
2219
Tony Barbourfa6cac72015-01-16 14:27:35 -07002220static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002221 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002222{
2223 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2224 const uint8_t cmd_len = 3;
2225 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002226
2227 CMD_ASSERT(cmd, 6, 7.5);
2228
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002229 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002230 dw[0] = 0;
2231 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002232
2233 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2234 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2235 GEN6_COMPAREFUNCTION_NEVER << 27 |
2236 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2237 } else {
2238 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2239 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2240 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002241 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002242 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002243 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2244 (GEN6_STENCILOP_KEEP) << 25 |
2245 (GEN6_STENCILOP_KEEP) << 22 |
2246 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002247 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2248 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002249 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2250 (GEN6_STENCILOP_KEEP) << 9 |
2251 (GEN6_STENCILOP_KEEP) << 6 |
2252 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002253
Chia-I Wud850a392015-02-19 11:08:25 -07002254 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2255 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2256 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2257 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2258 dw[2] = 0;
2259 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002260
2261 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2262 cmd_align, cmd_len, dw);
2263}
2264
Chia-I Wu6032b892014-10-17 14:47:18 +08002265static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2266{
2267 const struct intel_cmd_meta *meta = cmd->bind.meta;
2268 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2269
2270 CMD_ASSERT(cmd, 6, 7.5);
2271
2272 blend_offset = 0;
2273 ds_offset = 0;
2274 cc_offset = 0;
2275 cc_vp_offset = 0;
2276
Chia-I Wu29e6f502014-11-24 14:27:29 +08002277 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002278 /* BLEND_STATE */
2279 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002280 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002281 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002282 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002283 }
2284
Chia-I Wu29e6f502014-11-24 14:27:29 +08002285 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002286 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002287 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002288 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2289 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002290
Chia-I Wu29e6f502014-11-24 14:27:29 +08002291 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002292 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002293
Chia-I Wu29e6f502014-11-24 14:27:29 +08002294 /* COLOR_CALC_STATE */
2295 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002296 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002297
Chia-I Wu29e6f502014-11-24 14:27:29 +08002298 /* CC_VIEWPORT */
2299 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002300 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002301 dw[0] = u_fui(0.0f);
2302 dw[1] = u_fui(1.0f);
2303 } else {
2304 /* DEPTH_STENCIL_STATE */
2305 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002306 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002307 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2308 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2309 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002310 }
2311
2312 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2313 gen7_3dstate_pointer(cmd,
2314 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2315 blend_offset);
2316 gen7_3dstate_pointer(cmd,
2317 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2318 ds_offset);
2319 gen7_3dstate_pointer(cmd,
2320 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2321
2322 gen7_3dstate_pointer(cmd,
2323 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2324 cc_vp_offset);
2325 } else {
2326 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002327 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002328
2329 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2330 cmd_batch_pointer(cmd, 4, &dw);
2331 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002332 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002333 dw[1] = 0;
2334 dw[2] = 0;
2335 dw[3] = cc_vp_offset;
2336 }
2337}
2338
2339static void gen6_meta_surface_states(struct intel_cmd *cmd)
2340{
2341 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002342 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002343 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002344 const uint32_t sba_offset =
2345 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002346
2347 CMD_ASSERT(cmd, 6, 7.5);
2348
Chia-I Wu29e6f502014-11-24 14:27:29 +08002349 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2350 return;
2351
Chia-I Wu005c47c2014-10-22 13:49:13 +08002352 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002353 if (meta->src.valid) {
2354 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002355 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002356 meta->src.surface_len, meta->src.surface);
2357
2358 cmd_reserve_reloc(cmd, 1);
2359 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2360 cmd_surface_reloc_writer(cmd, offset, 1,
2361 meta->src.reloc_target, meta->src.reloc_offset);
2362 } else {
2363 cmd_surface_reloc(cmd, offset, 1,
2364 (struct intel_bo *) meta->src.reloc_target,
2365 meta->src.reloc_offset, meta->src.reloc_flags);
2366 }
2367
Mike Stroyan9bfad482015-02-10 15:09:23 -07002368 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002369 }
2370 if (meta->dst.valid) {
2371 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002372 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002373 meta->dst.surface_len, meta->dst.surface);
2374
2375 cmd_reserve_reloc(cmd, 1);
2376 cmd_surface_reloc(cmd, offset, 1,
2377 (struct intel_bo *) meta->dst.reloc_target,
2378 meta->dst.reloc_offset, meta->dst.reloc_flags);
2379
Mike Stroyan9bfad482015-02-10 15:09:23 -07002380 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002381 }
2382
2383 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002384 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002385 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002386 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002387
2388 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002389 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2390 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2391 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002392 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002393 } else {
2394 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002395 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002396 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002397 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002398 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002399 }
2400}
2401
2402static void gen6_meta_urb(struct intel_cmd *cmd)
2403{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002404 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002405 uint32_t *dw;
2406
2407 CMD_ASSERT(cmd, 6, 6);
2408
2409 /* 3DSTATE_URB */
2410 cmd_batch_pointer(cmd, 3, &dw);
2411 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002412 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002413 dw[2] = 0;
2414}
2415
2416static void gen7_meta_urb(struct intel_cmd *cmd)
2417{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002418 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2419 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002420 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002421 uint32_t *dw;
2422
2423 CMD_ASSERT(cmd, 7, 7.5);
2424
Chia-I Wu6032b892014-10-17 14:47:18 +08002425 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2426
Chia-I Wu24aa1022014-11-25 11:53:19 +08002427 switch (cmd_gen(cmd)) {
2428 case INTEL_GEN(7.5):
2429 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2430 break;
2431 case INTEL_GEN(7):
2432 default:
2433 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2434 break;
2435 }
2436
Chia-I Wu6032b892014-10-17 14:47:18 +08002437 /* 3DSTATE_URB_x */
2438 cmd_batch_pointer(cmd, 8, &dw);
2439
2440 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002441 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002442 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002443 dw += 2;
2444
2445 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002446 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002447 dw += 2;
2448
2449 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002450 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002451 dw += 2;
2452
2453 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002454 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002455 dw += 2;
2456}
2457
2458static void gen6_meta_vf(struct intel_cmd *cmd)
2459{
2460 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002461 uint32_t vb_start, vb_end, vb_stride;
2462 int ve_format, ve_z_source;
2463 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002464 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002465
2466 CMD_ASSERT(cmd, 6, 7.5);
2467
Chia-I Wu29e6f502014-11-24 14:27:29 +08002468 switch (meta->mode) {
2469 case INTEL_CMD_META_VS_POINTS:
2470 cmd_batch_pointer(cmd, 3, &dw);
2471 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002472 dw[1] = GEN6_VE_DW0_VALID;
2473 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2474 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2475 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2476 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002477 return;
2478 break;
2479 case INTEL_CMD_META_FS_RECT:
2480 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002481 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002482
Chia-I Wu29e6f502014-11-24 14:27:29 +08002483 vertices[0][0] = meta->dst.x + meta->width;
2484 vertices[0][1] = meta->dst.y + meta->height;
2485 vertices[1][0] = meta->dst.x;
2486 vertices[1][1] = meta->dst.y + meta->height;
2487 vertices[2][0] = meta->dst.x;
2488 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002489
Chia-I Wu29e6f502014-11-24 14:27:29 +08002490 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2491 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002492
Chia-I Wu29e6f502014-11-24 14:27:29 +08002493 vb_end = vb_start + sizeof(vertices) - 1;
2494 vb_stride = sizeof(vertices[0]);
2495 ve_z_source = GEN6_VFCOMP_STORE_0;
2496 ve_format = GEN6_FORMAT_R32G32_USCALED;
2497 }
2498 break;
2499 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2500 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002501 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002502
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002503 vertices[0][0] = (float) (meta->dst.x + meta->width);
2504 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002505 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002506 vertices[1][0] = (float) meta->dst.x;
2507 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002508 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002509 vertices[2][0] = (float) meta->dst.x;
2510 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002511 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002512
Chia-I Wu29e6f502014-11-24 14:27:29 +08002513 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2514 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002515
Chia-I Wu29e6f502014-11-24 14:27:29 +08002516 vb_end = vb_start + sizeof(vertices) - 1;
2517 vb_stride = sizeof(vertices[0]);
2518 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2519 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2520 }
2521 break;
2522 default:
2523 assert(!"unknown meta mode");
2524 return;
2525 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002526 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002527
2528 /* 3DSTATE_VERTEX_BUFFERS */
2529 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002530
Chia-I Wu6032b892014-10-17 14:47:18 +08002531 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002532 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002533 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002534 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002535
2536 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002537 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2538 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002539
2540 dw[4] = 0;
2541
2542 /* 3DSTATE_VERTEX_ELEMENTS */
2543 cmd_batch_pointer(cmd, 5, &dw);
2544 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002545 dw[1] = GEN6_VE_DW0_VALID;
2546 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2547 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2548 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2549 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2550 dw[3] = GEN6_VE_DW0_VALID |
2551 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2552 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2553 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2554 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2555 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002556}
2557
Chia-I Wu29e6f502014-11-24 14:27:29 +08002558static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002559{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002560 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002561 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002562 uint32_t consts[8];
2563 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002564
2565 CMD_ASSERT(cmd, 6, 7.5);
2566
2567 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002568 case INTEL_DEV_META_VS_FILL_MEM:
2569 consts[0] = meta->dst.x;
2570 consts[1] = meta->clear_val[0];
2571 const_count = 2;
2572 break;
2573 case INTEL_DEV_META_VS_COPY_MEM:
2574 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2575 consts[0] = meta->dst.x;
2576 consts[1] = meta->src.x;
2577 const_count = 2;
2578 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002579 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2580 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2581 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2582 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2583 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2584 consts[0] = meta->src.x;
2585 consts[1] = meta->src.y;
2586 consts[2] = meta->width;
2587 consts[3] = meta->dst.x;
2588 const_count = 4;
2589 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002590 default:
2591 assert(!"unknown meta shader id");
2592 const_count = 0;
2593 break;
2594 }
2595
2596 /* this can be skipped but it makes state dumping prettier */
2597 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2598
2599 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2600}
2601
2602static void gen6_meta_vs(struct intel_cmd *cmd)
2603{
2604 const struct intel_cmd_meta *meta = cmd->bind.meta;
2605 const struct intel_pipeline_shader *sh =
2606 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2607 uint32_t offset, *dw;
2608
2609 CMD_ASSERT(cmd, 6, 7.5);
2610
2611 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002612 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002613
2614 /* 3DSTATE_CONSTANT_VS */
2615 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2616 cmd_batch_pointer(cmd, cmd_len, &dw);
2617 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2618 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2619
2620 /* 3DSTATE_VS */
2621 cmd_batch_pointer(cmd, 6, &dw);
2622 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2623 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2624
2625 return;
2626 }
2627
2628 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2629
2630 /* 3DSTATE_CONSTANT_VS */
2631 offset = gen6_meta_vs_constants(cmd);
2632 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2633 cmd_batch_pointer(cmd, 7, &dw);
2634 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002635 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002636 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002637 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002638 dw[4] = 0;
2639 dw[5] = 0;
2640 dw[6] = 0;
2641 } else {
2642 cmd_batch_pointer(cmd, 5, &dw);
2643 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002644 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002645 dw[1] = offset;
2646 dw[2] = 0;
2647 dw[3] = 0;
2648 dw[4] = 0;
2649 }
2650
2651 /* 3DSTATE_VS */
2652 offset = emit_shader(cmd, sh);
2653 cmd_batch_pointer(cmd, 6, &dw);
2654 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2655 dw[1] = offset;
2656 dw[2] = GEN6_THREADDISP_SPF |
2657 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2658 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002659 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002660 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2661 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2662
2663 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2664 GEN6_VS_DW5_VS_ENABLE;
2665 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002666 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002667 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002668 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002669
2670 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002671}
2672
2673static void gen6_meta_disabled(struct intel_cmd *cmd)
2674{
Chia-I Wu6032b892014-10-17 14:47:18 +08002675 uint32_t *dw;
2676
2677 CMD_ASSERT(cmd, 6, 6);
2678
Chia-I Wu6032b892014-10-17 14:47:18 +08002679 /* 3DSTATE_CONSTANT_GS */
2680 cmd_batch_pointer(cmd, 5, &dw);
2681 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2682 dw[1] = 0;
2683 dw[2] = 0;
2684 dw[3] = 0;
2685 dw[4] = 0;
2686
2687 /* 3DSTATE_GS */
2688 cmd_batch_pointer(cmd, 7, &dw);
2689 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2690 dw[1] = 0;
2691 dw[2] = 0;
2692 dw[3] = 0;
2693 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2694 dw[5] = GEN6_GS_DW5_STATISTICS;
2695 dw[6] = 0;
2696
Chia-I Wu6032b892014-10-17 14:47:18 +08002697 /* 3DSTATE_SF */
2698 cmd_batch_pointer(cmd, 20, &dw);
2699 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2700 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2701 memset(&dw[2], 0, 18 * sizeof(*dw));
2702}
2703
2704static void gen7_meta_disabled(struct intel_cmd *cmd)
2705{
2706 uint32_t *dw;
2707
2708 CMD_ASSERT(cmd, 7, 7.5);
2709
Chia-I Wu6032b892014-10-17 14:47:18 +08002710 /* 3DSTATE_CONSTANT_HS */
2711 cmd_batch_pointer(cmd, 7, &dw);
2712 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2713 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2714
2715 /* 3DSTATE_HS */
2716 cmd_batch_pointer(cmd, 7, &dw);
2717 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2718 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2719
2720 /* 3DSTATE_TE */
2721 cmd_batch_pointer(cmd, 4, &dw);
2722 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2723 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2724
2725 /* 3DSTATE_CONSTANT_DS */
2726 cmd_batch_pointer(cmd, 7, &dw);
2727 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2728 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2729
2730 /* 3DSTATE_DS */
2731 cmd_batch_pointer(cmd, 6, &dw);
2732 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2733 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2734
2735 /* 3DSTATE_CONSTANT_GS */
2736 cmd_batch_pointer(cmd, 7, &dw);
2737 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2738 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2739
2740 /* 3DSTATE_GS */
2741 cmd_batch_pointer(cmd, 7, &dw);
2742 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2743 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2744
2745 /* 3DSTATE_STREAMOUT */
2746 cmd_batch_pointer(cmd, 3, &dw);
2747 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2748 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2749
Chia-I Wu6032b892014-10-17 14:47:18 +08002750 /* 3DSTATE_SF */
2751 cmd_batch_pointer(cmd, 7, &dw);
2752 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2753 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2754
2755 /* 3DSTATE_SBE */
2756 cmd_batch_pointer(cmd, 14, &dw);
2757 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2758 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2759 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002760}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002761
Chia-I Wu29e6f502014-11-24 14:27:29 +08002762static void gen6_meta_clip(struct intel_cmd *cmd)
2763{
2764 const struct intel_cmd_meta *meta = cmd->bind.meta;
2765 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002766
Chia-I Wu29e6f502014-11-24 14:27:29 +08002767 /* 3DSTATE_CLIP */
2768 cmd_batch_pointer(cmd, 4, &dw);
2769 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2770 dw[1] = 0;
2771 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2772 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2773 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2774 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002775 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002776 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002777 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002778}
2779
2780static void gen6_meta_wm(struct intel_cmd *cmd)
2781{
2782 const struct intel_cmd_meta *meta = cmd->bind.meta;
2783 uint32_t *dw;
2784
2785 CMD_ASSERT(cmd, 6, 7.5);
2786
2787 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2788
2789 /* 3DSTATE_MULTISAMPLE */
2790 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2791 cmd_batch_pointer(cmd, 4, &dw);
2792 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2793 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2794 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2795 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2796 dw[2] = 0;
2797 dw[3] = 0;
2798 } else {
2799 cmd_batch_pointer(cmd, 3, &dw);
2800 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2801 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2802 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2803 dw[2] = 0;
2804 }
2805
2806 /* 3DSTATE_SAMPLE_MASK */
2807 cmd_batch_pointer(cmd, 2, &dw);
2808 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2809 dw[1] = (1 << meta->samples) - 1;
2810
2811 /* 3DSTATE_DRAWING_RECTANGLE */
2812 cmd_batch_pointer(cmd, 4, &dw);
2813 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002814 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2815 /* unused */
2816 dw[1] = 0;
2817 dw[2] = 0;
2818 } else {
2819 dw[1] = meta->dst.y << 16 | meta->dst.x;
2820 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2821 (meta->dst.x + meta->width - 1);
2822 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002823 dw[3] = 0;
2824}
2825
2826static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2827{
2828 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002829 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002830 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002831 uint32_t consts[8];
2832 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002833
2834 CMD_ASSERT(cmd, 6, 7.5);
2835
2836 /* underflow is fine here */
2837 offset_x = meta->src.x - meta->dst.x;
2838 offset_y = meta->src.y - meta->dst.y;
2839
2840 switch (meta->shader_id) {
2841 case INTEL_DEV_META_FS_COPY_MEM:
2842 case INTEL_DEV_META_FS_COPY_1D:
2843 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2844 case INTEL_DEV_META_FS_COPY_2D:
2845 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2846 case INTEL_DEV_META_FS_COPY_2D_MS:
2847 consts[0] = offset_x;
2848 consts[1] = offset_y;
2849 consts[2] = meta->src.layer;
2850 consts[3] = meta->src.lod;
2851 const_count = 4;
2852 break;
2853 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2854 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2855 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2856 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2857 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2858 consts[0] = offset_x;
2859 consts[1] = offset_y;
2860 consts[2] = meta->src.layer;
2861 consts[3] = meta->src.lod;
2862 consts[4] = meta->src.x;
2863 consts[5] = meta->width;
2864 const_count = 6;
2865 break;
2866 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2867 consts[0] = offset_x;
2868 consts[1] = offset_y;
2869 consts[2] = meta->width;
2870 const_count = 3;
2871 break;
2872 case INTEL_DEV_META_FS_CLEAR_COLOR:
2873 consts[0] = meta->clear_val[0];
2874 consts[1] = meta->clear_val[1];
2875 consts[2] = meta->clear_val[2];
2876 consts[3] = meta->clear_val[3];
2877 const_count = 4;
2878 break;
2879 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2880 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002881 consts[1] = meta->clear_val[1];
2882 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002883 break;
2884 case INTEL_DEV_META_FS_RESOLVE_2X:
2885 case INTEL_DEV_META_FS_RESOLVE_4X:
2886 case INTEL_DEV_META_FS_RESOLVE_8X:
2887 case INTEL_DEV_META_FS_RESOLVE_16X:
2888 consts[0] = offset_x;
2889 consts[1] = offset_y;
2890 const_count = 2;
2891 break;
2892 default:
2893 assert(!"unknown meta shader id");
2894 const_count = 0;
2895 break;
2896 }
2897
2898 /* this can be skipped but it makes state dumping prettier */
2899 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2900
2901 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2902}
2903
2904static void gen6_meta_ps(struct intel_cmd *cmd)
2905{
2906 const struct intel_cmd_meta *meta = cmd->bind.meta;
2907 const struct intel_pipeline_shader *sh =
2908 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2909 uint32_t offset, *dw;
2910
2911 CMD_ASSERT(cmd, 6, 6);
2912
Chia-I Wu29e6f502014-11-24 14:27:29 +08002913 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2914 /* 3DSTATE_CONSTANT_PS */
2915 cmd_batch_pointer(cmd, 5, &dw);
2916 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2917 dw[1] = 0;
2918 dw[2] = 0;
2919 dw[3] = 0;
2920 dw[4] = 0;
2921
2922 /* 3DSTATE_WM */
2923 cmd_batch_pointer(cmd, 9, &dw);
2924 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2925 dw[1] = 0;
2926 dw[2] = 0;
2927 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002928
2929 switch (meta->ds.op) {
2930 case INTEL_CMD_META_DS_HIZ_CLEAR:
2931 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2932 break;
2933 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2934 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2935 break;
2936 case INTEL_CMD_META_DS_RESOLVE:
2937 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2938 break;
2939 default:
2940 dw[4] = 0;
2941 break;
2942 }
2943
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002944 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002945 dw[6] = 0;
2946 dw[7] = 0;
2947 dw[8] = 0;
2948
Chia-I Wu3adf7212014-10-24 15:34:07 +08002949 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002950 }
2951
Chia-I Wu3adf7212014-10-24 15:34:07 +08002952 /* a normal color write */
2953 assert(meta->dst.valid && !sh->uses);
2954
Chia-I Wu6032b892014-10-17 14:47:18 +08002955 /* 3DSTATE_CONSTANT_PS */
2956 offset = gen6_meta_ps_constants(cmd);
2957 cmd_batch_pointer(cmd, 5, &dw);
2958 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002959 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002960 dw[1] = offset;
2961 dw[2] = 0;
2962 dw[3] = 0;
2963 dw[4] = 0;
2964
2965 /* 3DSTATE_WM */
2966 offset = emit_shader(cmd, sh);
2967 cmd_batch_pointer(cmd, 9, &dw);
2968 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2969 dw[1] = offset;
2970 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2971 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002972 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002973 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002974 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002975 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2976 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002977
Chia-I Wu6032b892014-10-17 14:47:18 +08002978 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002979 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002980 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2981 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2982 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2983 if (meta->samples > 1) {
2984 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2985 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2986 } else {
2987 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2988 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2989 }
2990 dw[7] = 0;
2991 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002992
2993 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002994}
2995
2996static void gen7_meta_ps(struct intel_cmd *cmd)
2997{
2998 const struct intel_cmd_meta *meta = cmd->bind.meta;
2999 const struct intel_pipeline_shader *sh =
3000 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
3001 uint32_t offset, *dw;
3002
3003 CMD_ASSERT(cmd, 7, 7.5);
3004
Chia-I Wu29e6f502014-11-24 14:27:29 +08003005 if (meta->mode != INTEL_CMD_META_FS_RECT) {
3006 /* 3DSTATE_WM */
3007 cmd_batch_pointer(cmd, 3, &dw);
3008 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003009
3010 switch (meta->ds.op) {
3011 case INTEL_CMD_META_DS_HIZ_CLEAR:
3012 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
3013 break;
3014 case INTEL_CMD_META_DS_HIZ_RESOLVE:
3015 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
3016 break;
3017 case INTEL_CMD_META_DS_RESOLVE:
3018 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
3019 break;
3020 default:
3021 dw[1] = 0;
3022 break;
3023 }
3024
3025 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003026
3027 /* 3DSTATE_CONSTANT_GS */
3028 cmd_batch_pointer(cmd, 7, &dw);
3029 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3030 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3031
3032 /* 3DSTATE_PS */
3033 cmd_batch_pointer(cmd, 8, &dw);
3034 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3035 dw[1] = 0;
3036 dw[2] = 0;
3037 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003038 /* required to avoid hangs */
3039 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003040 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003041 dw[5] = 0;
3042 dw[6] = 0;
3043 dw[7] = 0;
3044
Chia-I Wu3adf7212014-10-24 15:34:07 +08003045 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003046 }
3047
Chia-I Wu3adf7212014-10-24 15:34:07 +08003048 /* a normal color write */
3049 assert(meta->dst.valid && !sh->uses);
3050
Chia-I Wu6032b892014-10-17 14:47:18 +08003051 /* 3DSTATE_WM */
3052 cmd_batch_pointer(cmd, 3, &dw);
3053 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003054 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003055 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3056 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3057 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3058 dw[2] = 0;
3059
3060 /* 3DSTATE_CONSTANT_PS */
3061 offset = gen6_meta_ps_constants(cmd);
3062 cmd_batch_pointer(cmd, 7, &dw);
3063 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003064 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003065 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003066 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003067 dw[4] = 0;
3068 dw[5] = 0;
3069 dw[6] = 0;
3070
3071 /* 3DSTATE_PS */
3072 offset = emit_shader(cmd, sh);
3073 cmd_batch_pointer(cmd, 8, &dw);
3074 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3075 dw[1] = offset;
3076 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3077 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003078 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003079
3080 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3081 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003082 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003083
3084 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003085 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003086 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003087 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003088 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003089 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003090
3091 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3092 dw[6] = 0;
3093 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003094
3095 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003096}
3097
3098static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3099{
3100 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003101 const struct intel_att_view *view = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003102
3103 CMD_ASSERT(cmd, 6, 7.5);
3104
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003105 if (!view) {
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003106 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003107 static const struct intel_att_view null_view;
3108 view = &null_view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003109 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003110
3111 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003112 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
3113 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, meta->ds.optimal);
3114 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003115
3116 if (cmd_gen(cmd) >= INTEL_GEN(7))
3117 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3118 else
3119 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003120}
3121
Chia-I Wu862c5572015-03-28 15:23:55 +08003122static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3123 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003124 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003125{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003126 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003127 if (data->set_offsets)
3128 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003129
Chia-I Wu862c5572015-03-28 15:23:55 +08003130 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003131 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003132 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003133 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003134 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003135 data->set_offset_count = 0;
3136 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003137 }
3138
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003139 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003140 }
3141
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003142 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003143 if (data->dynamic_offsets)
3144 intel_free(cmd, data->dynamic_offsets);
3145
3146 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003147 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003148 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003149 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003150 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003151 data->dynamic_offset_count = 0;
3152 return false;
3153 }
3154
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003155 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003156 }
3157
3158 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003159}
3160
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003161static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3162 const struct intel_pipeline *pipeline)
3163{
3164 cmd->bind.pipeline.graphics = pipeline;
3165
3166 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003167 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003168}
3169
3170static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3171 const struct intel_pipeline *pipeline)
3172{
3173 cmd->bind.pipeline.compute = pipeline;
3174
3175 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003176 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003177}
3178
Chia-I Wu862c5572015-03-28 15:23:55 +08003179static void cmd_copy_dset_data(struct intel_cmd *cmd,
3180 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003181 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003182 uint32_t index,
3183 const struct intel_desc_set *set,
3184 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003185{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003186 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003187
Chia-I Wu862c5572015-03-28 15:23:55 +08003188 assert(index < data->set_offset_count);
3189 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003190
Chia-I Wu862c5572015-03-28 15:23:55 +08003191 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003192 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003193 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003194
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003195 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003196 dynamic_offsets,
3197 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003198 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003199}
3200
Chia-I Wu3b04af52014-11-08 10:48:20 +08003201static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003202 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003203 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003204{
Chia-I Wu714df452015-01-01 07:55:04 +08003205 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003206 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003207 return;
3208 }
3209
Chia-I Wu714df452015-01-01 07:55:04 +08003210 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003211 cmd->bind.vertex.offset[binding] = offset;
3212}
3213
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003214static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003215 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003216 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003217{
Chia-I Wu714df452015-01-01 07:55:04 +08003218 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003219 cmd->bind.index.offset = offset;
3220 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003221}
3222
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003223static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003224 const struct intel_dynamic_viewport *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003225{
3226 cmd->bind.state.viewport = state;
3227}
3228
Cody Northropf5bd2252015-08-17 11:10:49 -06003229static void cmd_bind_raster_line_state(struct intel_cmd *cmd,
3230 const struct intel_dynamic_raster_line *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003231{
Cody Northropf5bd2252015-08-17 11:10:49 -06003232 cmd->bind.state.raster_line = state;
3233}
3234
3235static void cmd_bind_raster_depth_bias_state(struct intel_cmd *cmd,
3236 const struct intel_dynamic_raster_depth_bias *state)
3237{
3238 cmd->bind.state.raster_depth_bias = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003239}
3240
Cody Northrop2605cb02015-08-18 15:21:16 -06003241static void cmd_bind_depth_state(struct intel_cmd *cmd,
3242 const struct intel_dynamic_depth*state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003243{
Tony Barbourde4124d2015-07-03 10:33:54 -06003244 cmd->bind.state.depth = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003245}
3246
Cody Northrop2605cb02015-08-18 15:21:16 -06003247static void cmd_bind_stencil_state(struct intel_cmd *cmd,
3248 const struct intel_dynamic_stencil *state)
3249{
3250 cmd->bind.state.stencil = state;
3251}
3252
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003253static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003254 const struct intel_dynamic_color_blend *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003255{
3256 cmd->bind.state.blend = state;
3257}
3258
Chia-I Wuf98dd882015-02-10 04:17:47 +08003259static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3260{
3261 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3262 struct intel_pipeline_rmap *rmaps[5] = {
3263 pipeline->vs.rmap,
3264 pipeline->tcs.rmap,
3265 pipeline->tes.rmap,
3266 pipeline->gs.rmap,
3267 pipeline->fs.rmap,
3268 };
3269 uint32_t max_write;
3270 int i;
3271
3272 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3273 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3274 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3275
3276 /* pad first */
3277 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3278
3279 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3280 const struct intel_pipeline_rmap *rmap = rmaps[i];
3281 const uint32_t surface_count = (rmap) ?
3282 rmap->rt_count + rmap->texture_resource_count +
3283 rmap->resource_count + rmap->uav_count : 0;
3284
3285 if (surface_count) {
3286 /* SURFACE_STATEs */
3287 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3288
3289 /* BINDING_TABLE_STATE */
3290 max_write += u_align(sizeof(uint32_t) * surface_count,
3291 GEN6_ALIGNMENT_SURFACE_STATE);
3292 }
3293 }
3294
3295 return max_write;
3296}
3297
3298static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3299{
3300 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3301 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3302 uint32_t max_surface_write;
3303
3304 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3305 if (cmd->bind.meta)
3306 max_surface_write = 64 * sizeof(uint32_t);
3307 else
3308 max_surface_write = cmd_get_max_surface_write(cmd);
3309
3310 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3311 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3312 /* SBA expects page-aligned addresses */
3313 writer->sba_offset = writer->used & ~0xfff;
3314
3315 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3316
3317 cmd_batch_state_base_address(cmd);
3318 }
3319}
3320
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003321static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003322 uint32_t vertex_start,
3323 uint32_t vertex_count,
3324 uint32_t instance_start,
3325 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003326 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003327 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003328{
3329 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003330 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003331 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3332
3333 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003334
3335 emit_bounded_states(cmd);
3336
Chia-I Wuf98dd882015-02-10 04:17:47 +08003337 /* sanity check on cmd_get_max_surface_write() */
3338 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3339 surface_writer_used <= cmd_get_max_surface_write(cmd));
3340
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003341 if (indexed) {
3342 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003343 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003344
3345 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3346 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3347 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003348 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003349 cmd->bind.index.offset, cmd->bind.index.type,
3350 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003351 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003352 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003353 cmd->bind.index.offset, cmd->bind.index.type,
3354 p->primitive_restart);
3355 }
3356 } else {
3357 assert(!vertex_base);
3358 }
3359
3360 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3361 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3362 vertex_start, instance_count, instance_start, vertex_base);
3363 } else {
3364 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3365 vertex_start, instance_count, instance_start, vertex_base);
3366 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003367
Chia-I Wu707a29e2014-08-27 12:51:47 +08003368 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003369 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003370 /* need to re-emit all workarounds */
3371 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003372
3373 if (intel_debug & INTEL_DEBUG_NOCACHE)
3374 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003375}
3376
Chia-I Wuc14d1562014-10-17 09:49:22 +08003377void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3378{
Chia-I Wu6032b892014-10-17 14:47:18 +08003379 cmd->bind.meta = meta;
3380
Chia-I Wuf98dd882015-02-10 04:17:47 +08003381 cmd_adjust_state_base_address(cmd);
3382
Chia-I Wu6032b892014-10-17 14:47:18 +08003383 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003384 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003385
3386 gen6_meta_dynamic_states(cmd);
3387 gen6_meta_surface_states(cmd);
3388
3389 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3390 gen7_meta_urb(cmd);
3391 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003392 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003393 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003394 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003395 gen6_meta_wm(cmd);
3396 gen7_meta_ps(cmd);
3397 gen6_meta_depth_buffer(cmd);
3398
3399 cmd_wa_gen7_post_command_cs_stall(cmd);
3400 cmd_wa_gen7_post_command_depth_stall(cmd);
3401
Chia-I Wu29e6f502014-11-24 14:27:29 +08003402 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3403 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003404 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003405 } else {
3406 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3407 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003408 } else {
3409 gen6_meta_urb(cmd);
3410 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003411 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003412 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003413 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003414 gen6_meta_wm(cmd);
3415 gen6_meta_ps(cmd);
3416 gen6_meta_depth_buffer(cmd);
3417
Chia-I Wu29e6f502014-11-24 14:27:29 +08003418 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3419 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003420 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003421 } else {
3422 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3423 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003424 }
3425
3426 cmd->bind.draw_count++;
3427 /* need to re-emit all workarounds */
3428 cmd->bind.wa_flags = 0;
3429
3430 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003431
Chia-I Wubbc7d912015-02-27 14:59:50 -07003432 /* make the normal path believe the render pass has changed */
3433 cmd->bind.render_pass_changed = true;
3434
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003435 if (intel_debug & INTEL_DEBUG_NOCACHE)
3436 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003437}
3438
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003439static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3440{
3441 const uint8_t cmd_len = 2;
3442 uint32_t *dw;
3443 uint32_t pos;
3444
3445 if (cmd_gen(cmd) < INTEL_GEN(7.5)) {
3446 cmd->result = VK_ERROR_UNKNOWN;
3447 return;
3448 }
3449
3450 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3451 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3452 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3453 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3454 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3455
3456 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3457}
3458
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003459ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003460 VkCmdBuffer cmdBuffer,
3461 VkPipelineBindPoint pipelineBindPoint,
3462 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003463{
3464 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3465
3466 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003467 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003468 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003469 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003470 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003471 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003472 break;
3473 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003474 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003475 break;
3476 }
3477}
3478
Tony Barbourde4124d2015-07-03 10:33:54 -06003479ICD_EXPORT void VKAPI vkCmdBindDynamicViewportState(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003480 VkCmdBuffer cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003481 VkDynamicViewportState state)
Chia-I Wub2755562014-08-20 13:38:52 +08003482{
3483 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3484
Tony Barbourde4124d2015-07-03 10:33:54 -06003485 cmd_bind_viewport_state(cmd,
3486 intel_dynamic_viewport(state));
3487}
3488
Cody Northropf5bd2252015-08-17 11:10:49 -06003489ICD_EXPORT void VKAPI vkCmdBindDynamicRasterLineState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003490 VkCmdBuffer cmdBuffer,
Cody Northropf5bd2252015-08-17 11:10:49 -06003491 VkDynamicRasterLineState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003492{
3493 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3494
Cody Northropf5bd2252015-08-17 11:10:49 -06003495 cmd_bind_raster_line_state(cmd,
3496 intel_dynamic_raster_line(state));
3497}
3498
3499ICD_EXPORT void VKAPI vkCmdBindDynamicRasterDepthBiasState(
3500 VkCmdBuffer cmdBuffer,
3501 VkDynamicRasterDepthBiasState state)
3502{
3503 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3504
3505 cmd_bind_raster_depth_bias_state(cmd,
3506 intel_dynamic_raster_depth_bias(state));
Tony Barbourde4124d2015-07-03 10:33:54 -06003507}
3508
3509ICD_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(
3510 VkCmdBuffer cmdBuffer,
3511 VkDynamicColorBlendState state)
3512{
3513 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3514
3515 cmd_bind_blend_state(cmd,
3516 intel_dynamic_color_blend(state));
3517}
3518
Cody Northrop2605cb02015-08-18 15:21:16 -06003519ICD_EXPORT void VKAPI vkCmdBindDynamicDepthState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003520 VkCmdBuffer cmdBuffer,
Cody Northrop2605cb02015-08-18 15:21:16 -06003521 VkDynamicDepthState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003522{
3523 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3524
Cody Northrop2605cb02015-08-18 15:21:16 -06003525 cmd_bind_depth_state(cmd,
3526 intel_dynamic_depth(state));
3527}
3528
3529ICD_EXPORT void VKAPI vkCmdBindDynamicStencilState(
3530 VkCmdBuffer cmdBuffer,
3531 VkDynamicStencilState state)
3532{
3533 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3534
3535 cmd_bind_stencil_state(cmd,
3536 intel_dynamic_stencil(state));
Chia-I Wub2755562014-08-20 13:38:52 +08003537}
3538
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003539ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003540 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003541 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003542 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003543 uint32_t firstSet,
3544 uint32_t setCount,
3545 const VkDescriptorSet* pDescriptorSets,
3546 uint32_t dynamicOffsetCount,
3547 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003548{
3549 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003550 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003551 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003552 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003553 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003554
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003555 pipeline_layout = intel_pipeline_layout(layout);
3556
Chia-I Wub2755562014-08-20 13:38:52 +08003557 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003558 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003559 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003560 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003561 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003562 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003563 break;
3564 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003565 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003566 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003567 break;
3568 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003569
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003570 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003571 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3572
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003573 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003574 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003575 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003576 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003577 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003578 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003579 }
Chia-I Wub2755562014-08-20 13:38:52 +08003580}
3581
Tony Barbour8205d902015-04-16 15:59:00 -06003582
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003583ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3584 VkCmdBuffer cmdBuffer,
3585 uint32_t startBinding,
3586 uint32_t bindingCount,
3587 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003588 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003589{
3590 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003591
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003592 for (uint32_t i = 0; i < bindingCount; i++) {
3593 struct intel_buf *buf = intel_buf(pBuffers[i]);
3594 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3595 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003596}
3597
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003598ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003599 VkCmdBuffer cmdBuffer,
3600 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003601 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003602 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003603{
3604 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003605 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003606
Chia-I Wu714df452015-01-01 07:55:04 +08003607 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003608}
3609
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003610ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003611 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003612 uint32_t firstVertex,
3613 uint32_t vertexCount,
3614 uint32_t firstInstance,
3615 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003616{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003617 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003618
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003619 cmd_draw(cmd, firstVertex, vertexCount,
3620 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003621}
3622
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003623ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003624 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003625 uint32_t firstIndex,
3626 uint32_t indexCount,
3627 int32_t vertexOffset,
3628 uint32_t firstInstance,
3629 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003630{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003631 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003632
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003633 cmd_draw(cmd, firstIndex, indexCount,
3634 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003635}
3636
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003637ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003638 VkCmdBuffer cmdBuffer,
3639 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003640 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003641 uint32_t count,
3642 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003643{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003644 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3645
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003646 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003647}
3648
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003649ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003650 VkCmdBuffer cmdBuffer,
3651 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003652 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003653 uint32_t count,
3654 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003655{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003656 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3657
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003658 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003659}
3660
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003661ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003662 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003663 uint32_t x,
3664 uint32_t y,
3665 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003666{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003667 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3668
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003669 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003670}
3671
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003672ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003673 VkCmdBuffer cmdBuffer,
3674 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003675 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003676{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003677 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3678
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003679 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003680}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003681
Courtney Goeltzenleuchtera375b622015-07-27 14:04:01 -06003682void VKAPI vkCmdPushConstants(
3683 VkCmdBuffer cmdBuffer,
3684 VkPipelineLayout layout,
3685 VkShaderStageFlags stageFlags,
3686 uint32_t start,
3687 uint32_t length,
3688 const void* values)
3689{
3690 /* TODO: Implement */
3691}
Courtney Goeltzenleuchter07fe0662015-07-27 13:47:08 -06003692
3693VkResult VKAPI vkGetRenderAreaGranularity(
3694 VkDevice device,
3695 VkRenderPass renderPass,
3696 VkExtent2D* pGranularity)
3697{
3698 pGranularity->height = 1;
3699 pGranularity->width = 1;
3700
3701 return VK_SUCCESS;
3702}
3703
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003704ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Chia-I Wuc278df82015-07-07 11:50:03 +08003705 VkCmdBuffer cmdBuffer,
3706 const VkRenderPassBeginInfo* pRenderPassBegin,
3707 VkRenderPassContents contents)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003708{
Chia-I Wubdeed152015-07-09 12:16:29 +08003709 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3710 const struct intel_render_pass *rp =
3711 intel_render_pass(pRenderPassBegin->renderPass);
3712 const struct intel_fb *fb = intel_fb(pRenderPassBegin->framebuffer);
3713 const struct intel_att_view *view;
3714 uint32_t i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003715
Chia-I Wubdeed152015-07-09 12:16:29 +08003716 if (!cmd->primary || rp->attachment_count != fb->view_count) {
3717 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3718 return;
3719 }
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003720
Cody Northrop16898b02015-08-11 11:35:58 -06003721 cmd_begin_render_pass(cmd, rp, fb, 0, contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003722
Chia-I Wubdeed152015-07-09 12:16:29 +08003723 for (i = 0; i < rp->attachment_count; i++) {
3724 const struct intel_render_pass_attachment *att = &rp->attachments[i];
Chia-I Wuc278df82015-07-07 11:50:03 +08003725 const VkClearValue *clear_val =
Cody Northropc332eef2015-08-04 11:51:03 -06003726 &pRenderPassBegin->pClearValues[i];
Chia-I Wubdeed152015-07-09 12:16:29 +08003727 VkImageSubresourceRange range;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003728
Chia-I Wubdeed152015-07-09 12:16:29 +08003729 if (!att->clear_on_load)
3730 continue;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003731
Chia-I Wubdeed152015-07-09 12:16:29 +08003732 view = fb->views[i];
3733 range.baseMipLevel = view->mipLevel;
3734 range.mipLevels = 1;
3735 range.baseArraySlice = view->baseArraySlice;
3736 range.arraySize = view->array_size;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003737
Chia-I Wubdeed152015-07-09 12:16:29 +08003738 if (view->is_rt) {
3739 range.aspect = VK_IMAGE_ASPECT_COLOR;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003740
Tony Barbourde4124d2015-07-03 10:33:54 -06003741 cmd_meta_clear_color_image(cmdBuffer, view->img,
Chia-I Wuc278df82015-07-07 11:50:03 +08003742 att->initial_layout, &clear_val->color, 1, &range);
Chia-I Wubdeed152015-07-09 12:16:29 +08003743 } else {
3744 range.aspect = VK_IMAGE_ASPECT_DEPTH;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003745
Chia-I Wubdeed152015-07-09 12:16:29 +08003746 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003747 view->img, att->initial_layout,
Chia-I Wuc278df82015-07-07 11:50:03 +08003748 clear_val->ds.depth, clear_val->ds.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003749 1, &range);
Chris Forbes4cf9d102015-06-22 18:46:05 +12003750
Chia-I Wubdeed152015-07-09 12:16:29 +08003751 if (att->stencil_clear_on_load) {
3752 range.aspect = VK_IMAGE_ASPECT_STENCIL;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003753
Chia-I Wubdeed152015-07-09 12:16:29 +08003754 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003755 view->img, att->initial_layout,
Chia-I Wuc278df82015-07-07 11:50:03 +08003756 clear_val->ds.depth, clear_val->ds.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003757 1, &range);
3758 }
3759 }
3760 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003761}
3762
Chia-I Wuc278df82015-07-07 11:50:03 +08003763ICD_EXPORT void VKAPI vkCmdNextSubpass(
3764 VkCmdBuffer cmdBuffer,
3765 VkRenderPassContents contents)
3766{
3767 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3768 const struct intel_render_pass *rp = cmd->bind.render_pass;
3769
3770 if (cmd->bind.render_pass_subpass >= rp->subpasses +
3771 rp->subpass_count - 1) {
3772 cmd->result = VK_ERROR_UNKNOWN;
3773 return;
3774 }
3775
3776 cmd->bind.render_pass_changed = true;
3777 cmd->bind.render_pass_subpass++;
3778 cmd->bind.render_pass_contents = contents;
3779}
3780
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003781ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003782 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003783{
3784 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3785
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003786 cmd_end_render_pass(cmd);
3787}
3788
3789ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3790 VkCmdBuffer cmdBuffer,
3791 uint32_t cmdBuffersCount,
3792 const VkCmdBuffer* pCmdBuffers)
3793{
3794 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003795 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003796
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003797 if (!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3798 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) {
3799 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3800 return;
3801 }
3802
3803 for (i = 0; i < cmdBuffersCount; i++) {
3804 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3805
3806 if (secondary->primary) {
3807 cmd->result = VK_ERROR_INVALID_VALUE;
3808 break;
3809 }
3810
3811 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3812 }
3813
3814 if (i)
3815 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003816}