blob: 08b41fc34118f40a54bebe42a74d90c2dc70d12f [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_UINT8:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600227 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800228 supported = (p->primitive_restart_index != 0xffffffffu);
229 break;
230 default:
231 supported = false;
232 break;
233 }
234
235 return supported;
236}
237
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800239 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600240 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600241 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800242 bool enable_cut_index)
243{
244 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600260 case VK_INDEX_TYPE_UINT8:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600264 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600268 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600273 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600279 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Cody Northrop293d4502015-05-05 09:38:03 -0600312static void gen6_add_scratch_space(struct intel_cmd *cmd,
313 uint32_t batch_pos,
314 const struct intel_pipeline *pipeline,
315 const struct intel_pipeline_shader *sh)
316{
317 int scratch_space;
318
319 CMD_ASSERT(cmd, 6, 7.5);
320
321 assert(sh->per_thread_scratch_size &&
322 sh->per_thread_scratch_size % 1024 == 0 &&
323 u_is_pow2(sh->per_thread_scratch_size) &&
324 sh->scratch_offset % 1024 == 0);
325 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
326
327 cmd_reserve_reloc(cmd, 1);
328 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
329 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
330}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600331
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800332static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
333{
Cody Northrop293d4502015-05-05 09:38:03 -0600334 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
335 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800336 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600337 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800338 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600339 int vue_read_len = 0;
340 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800341
Cody Northrop293d4502015-05-05 09:38:03 -0600342 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
343
344 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
345
346 // based on ilo_gpe_init_gs_cso_gen6
347 vue_read_len = (gs->in_count + 1) / 2;
348 if (!vue_read_len)
349 vue_read_len = 1;
350
351 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
352 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
353 GEN6_THREADDISP_SPF;
354
355 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
356 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
357 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
358
359 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
360 GEN6_GS_DW5_STATISTICS |
361 GEN6_GS_DW5_RENDER_ENABLE;
362
363 dw6 = GEN6_GS_DW6_GS_ENABLE;
364
365 if (gs->discard_adj)
366 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
367
368 } else {
369 dw2 = 0;
370 dw4 = 0;
371 dw5 = GEN6_GS_DW5_STATISTICS;
372 dw6 = 0;
373 }
374
375 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800376 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600377 dw[1] = cmd->bind.pipeline.gs_offset;
378 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800379 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600380 dw[4] = dw4;
381 dw[5] = dw5;
382 dw[6] = dw6;
383
384 if (gs->per_thread_scratch_size)
385 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800386}
387
Chia-I Wu62a7f252014-08-29 11:31:16 +0800388static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
389{
Cody Northrop293d4502015-05-05 09:38:03 -0600390 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
391 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800392 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600393 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800394 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600395 int vue_read_len = 0;
396 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800397
Cody Northrop293d4502015-05-05 09:38:03 -0600398 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
399
400 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
401
402 // based on upload_gs_state
403 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
404 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
405
406 vue_read_len = (gs->in_count + 1) / 2;
407 if (!vue_read_len)
408 vue_read_len = 1;
409
410 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
411 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
412 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
413 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
414 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
415
416
417 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
418 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
419 GEN7_GS_DW5_STATISTICS |
420 GEN7_GS_DW5_GS_ENABLE;
421
422 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
423 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
424
425 if (gs->include_primitive_id)
426 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
427
428 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
429 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
430 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
431 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
432 } else {
433 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
434 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
435 dw6 = 0;
436 }
437 } else {
438 dw2 = 0;
439 dw4 = 0;
440 dw5 = GEN7_GS_DW5_STATISTICS;
441 dw6 = 0;
442 }
443
444 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800445 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600446 dw[1] = cmd->bind.pipeline.gs_offset;
447 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800448 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600449 dw[4] = dw4;
450 dw[5] = dw5;
451 dw[6] = dw6;
452
453 if (gs->per_thread_scratch_size)
454 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800455}
456
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600458 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800459{
460 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800461 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800462 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800463 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800464
465 CMD_ASSERT(cmd, 6, 7.5);
466
Chia-I Wu72292b72014-09-09 10:48:33 +0800467 cmd_batch_pointer(cmd, cmd_len, &dw);
468 dw[0] = dw0;
469
Chia-I Wud88e02d2014-08-25 10:56:13 +0800470 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800471 dw[1] = 0;
472 dw[2] = (height - 1) << 16 |
473 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800474 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800475 dw[1] = 1;
476 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800477 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800478
479 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800480}
481
Chia-I Wu8016a172014-08-29 18:31:32 +0800482static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
483 uint32_t body[6])
484{
485 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700486 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800487 uint32_t dw1, dw2, dw3;
Chia-I Wu8016a172014-08-29 18:31:32 +0800488
489 CMD_ASSERT(cmd, 6, 7.5);
490
491 dw1 = GEN7_SF_DW1_STATISTICS |
492 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
493 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
494 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
495 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700496 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800497
498 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
499 int format;
500
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700501 switch (pipeline->db_format) {
Tony Barbour8205d902015-04-16 15:59:00 -0600502 case VK_FORMAT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800503 format = GEN6_ZFORMAT_D16_UNORM;
504 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600505 case VK_FORMAT_D32_SFLOAT:
506 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800507 format = GEN6_ZFORMAT_D32_FLOAT;
508 break;
509 default:
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600510 assert(!cmd->bind.fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800511 format = 0;
512 break;
513 }
514
515 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
516 }
517
Tony Barbourfa6cac72015-01-16 14:27:35 -0700518 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800519
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700520 /* Scissor is always enabled */
521 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
522
Tony Barbourfa6cac72015-01-16 14:27:35 -0700523 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800524 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
525 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
526 } else {
527 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
528 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
529 }
530
Chia-I Wu8016a172014-08-29 18:31:32 +0800531 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
532 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
533 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800534 GEN7_SF_DW3_SUBPIXEL_8BITS;
535
Chia-I Wu8016a172014-08-29 18:31:32 +0800536 body[0] = dw1;
537 body[1] = dw2;
538 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700539 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
540 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
541 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800542}
543
Chia-I Wu8016a172014-08-29 18:31:32 +0800544static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
545{
546 const uint8_t cmd_len = 20;
547 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
548 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800549 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800550 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800551 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800552
553 CMD_ASSERT(cmd, 6, 6);
554
555 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800556
Chia-I Wu72292b72014-09-09 10:48:33 +0800557 cmd_batch_pointer(cmd, cmd_len, &dw);
558 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800559 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800560 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800561 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800562}
563
564static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
565{
566 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800567 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800568
569 CMD_ASSERT(cmd, 7, 7.5);
570
Chia-I Wu72292b72014-09-09 10:48:33 +0800571 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800572 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
573 (cmd_len - 2);
574 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800575}
576
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800577static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
578{
579 const uint8_t cmd_len = 4;
580 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
581 (cmd_len - 2);
582 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700583 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800584 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700585 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800586 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800587
588 CMD_ASSERT(cmd, 6, 7.5);
589
590 dw1 = GEN6_CLIP_DW1_STATISTICS;
591 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
592 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
593 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700594 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800595 }
596
597 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800598 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800599 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700600 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800601 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
602 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
603 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
604
605 if (pipeline->rasterizerDiscardEnable)
606 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
607 else
608 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
609
610 if (pipeline->depthClipEnable)
611 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
612
613 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
614 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
615 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
616 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
617
618 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
619 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
620 (viewport->viewport_count - 1);
621
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600622 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600623 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600624 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
625 }
626
Chia-I Wu72292b72014-09-09 10:48:33 +0800627 cmd_batch_pointer(cmd, cmd_len, &dw);
628 dw[0] = dw0;
629 dw[1] = dw1;
630 dw[2] = dw2;
631 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800632}
633
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800634static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
635{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800636 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800637 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600639 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700640 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800641
642 CMD_ASSERT(cmd, 6, 6);
643
644 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
645
646 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
647 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
648
649 dw4 = GEN6_WM_DW4_STATISTICS |
650 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
651 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700652 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800653
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800654 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700655 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
656 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800657
Cody Northrope86574e2015-02-24 14:15:29 -0700658 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700659 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700660
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800661 if (fs->uses & INTEL_SHADER_USE_KILL ||
662 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700663 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800664
Cody Northrope238deb2015-01-26 14:41:36 -0700665 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800666 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
667 if (fs->uses & INTEL_SHADER_USE_DEPTH)
668 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
669 if (fs->uses & INTEL_SHADER_USE_W)
670 dw5 |= GEN6_WM_DW5_PS_USE_W;
671
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700672 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700673 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800674
675 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700676 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800677 GEN6_WM_DW6_ZW_INTERP_PIXEL |
678 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
679 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
680
Tony Barbourfa6cac72015-01-16 14:27:35 -0700681 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800682 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
683 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
684 } else {
685 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
686 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
687 }
688
Cody Northrope86574e2015-02-24 14:15:29 -0700689 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
690
Chia-I Wu784d3042014-12-19 14:30:04 +0800691 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800692 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800693 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800694 dw[2] = dw2;
695 dw[3] = 0; /* scratch */
696 dw[4] = dw4;
697 dw[5] = dw5;
698 dw[6] = dw6;
699 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700700 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800701
702 if (fs->per_thread_scratch_size)
703 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704}
705
706static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
707{
708 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800709 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800710 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800711 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800712
713 CMD_ASSERT(cmd, 7, 7.5);
714
715 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
716
717 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700718 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800719 GEN7_WM_DW1_ZW_INTERP_PIXEL |
720 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
721 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
722
723 if (fs->uses & INTEL_SHADER_USE_KILL ||
724 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700725 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800726
Cody Northrope238deb2015-01-26 14:41:36 -0700727 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
728
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800729 if (fs->uses & INTEL_SHADER_USE_DEPTH)
730 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
731 if (fs->uses & INTEL_SHADER_USE_W)
732 dw1 |= GEN7_WM_DW1_PS_USE_W;
733
734 dw2 = 0;
735
Tony Barbourfa6cac72015-01-16 14:27:35 -0700736 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800737 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
738 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
739 } else {
740 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
741 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
742 }
743
Chia-I Wu72292b72014-09-09 10:48:33 +0800744 cmd_batch_pointer(cmd, cmd_len, &dw);
745 dw[0] = dw0;
746 dw[1] = dw1;
747 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800748}
749
750static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
751{
752 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800753 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800754 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700755 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600756 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800757
758 CMD_ASSERT(cmd, 7, 7.5);
759
760 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
761
762 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
763 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
764
765 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700766 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800767
Cody Northrope86574e2015-02-24 14:15:29 -0700768 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700769 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700770
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800771 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800772 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700773 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800774 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800775 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800776 }
777
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800778 if (fs->in_count)
779 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
780
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700781 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800782 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
783
784 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
785 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700786 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
787
788 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800789
Chia-I Wu784d3042014-12-19 14:30:04 +0800790 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800791 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800792 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800793 dw[2] = dw2;
794 dw[3] = 0; /* scratch */
795 dw[4] = dw4;
796 dw[5] = dw5;
797 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700798 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800799
800 if (fs->per_thread_scratch_size)
801 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800802}
803
Chia-I Wu8ada4242015-03-02 11:19:33 -0700804static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
805 uint32_t sample_count)
806{
807 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
808 uint32_t dw1, dw2, dw3, *dw;
809
810 CMD_ASSERT(cmd, 6, 7.5);
811
812 switch (sample_count) {
813 case 4:
814 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
815 dw2 = cmd->dev->sample_pattern_4x;
816 dw3 = 0;
817 break;
818 case 8:
819 assert(cmd_gen(cmd) >= INTEL_GEN(7));
820 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
821 dw2 = cmd->dev->sample_pattern_8x[0];
822 dw3 = cmd->dev->sample_pattern_8x[1];
823 break;
824 default:
825 assert(sample_count <= 1);
826 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
827 dw2 = 0;
828 dw3 = 0;
829 break;
830 }
831
832 cmd_batch_pointer(cmd, cmd_len, &dw);
833
834 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
835 dw[1] = dw1;
836 dw[2] = dw2;
837 if (cmd_gen(cmd) >= INTEL_GEN(7))
838 dw[3] = dw3;
839}
840
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800841static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700842 const struct intel_ds_view *view,
843 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800844{
845 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800846 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600847 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800848
849 CMD_ASSERT(cmd, 6, 7.5);
850
851 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800852 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
853 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800854 dw0 |= (cmd_len - 2);
855
Chia-I Wu72292b72014-09-09 10:48:33 +0800856 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
857 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700858
Chia-I Wu72292b72014-09-09 10:48:33 +0800859 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700860 /* note that we only enable HiZ on Gen7+ */
861 if (!optimal_ds)
862 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
863
Chia-I Wu72292b72014-09-09 10:48:33 +0800864 dw[2] = 0;
865 dw[3] = view->cmd[2];
866 dw[4] = view->cmd[3];
867 dw[5] = view->cmd[4];
868 dw[6] = view->cmd[5];
869
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600870 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800871 cmd_reserve_reloc(cmd, 1);
872 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
873 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600874 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800875}
876
877static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700878 const struct intel_ds_view *view,
879 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800880{
881 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800882 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600883 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800884
885 CMD_ASSERT(cmd, 6, 7.5);
886
887 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800888 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
889 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800890 dw0 |= (cmd_len - 2);
891
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
893 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800894
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700895 if (view->has_stencil) {
896 dw[1] = view->cmd[6];
897
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 cmd_reserve_reloc(cmd, 1);
899 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
900 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700901 } else {
902 dw[1] = 0;
903 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600904 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800905}
906
907static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700908 const struct intel_ds_view *view,
909 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800910{
911 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800912 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600913 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800914
915 CMD_ASSERT(cmd, 6, 7.5);
916
917 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800918 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
919 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800920 dw0 |= (cmd_len - 2);
921
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
923 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800924
Chia-I Wu73520ac2015-02-19 11:17:45 -0700925 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700926 dw[1] = view->cmd[8];
927
Chia-I Wu72292b72014-09-09 10:48:33 +0800928 cmd_reserve_reloc(cmd, 1);
929 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
930 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700931 } else {
932 dw[1] = 0;
933 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600934 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800935}
936
Chia-I Wuf8231032014-08-25 10:44:45 +0800937static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
938 uint32_t clear_val)
939{
940 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800941 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800942 GEN6_CLEAR_PARAMS_DW0_VALID |
943 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800944 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800945
946 CMD_ASSERT(cmd, 6, 6);
947
Chia-I Wu72292b72014-09-09 10:48:33 +0800948 cmd_batch_pointer(cmd, cmd_len, &dw);
949 dw[0] = dw0;
950 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800951}
952
953static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
954 uint32_t clear_val)
955{
956 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800957 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800958 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800959 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800960
961 CMD_ASSERT(cmd, 7, 7.5);
962
Chia-I Wu72292b72014-09-09 10:48:33 +0800963 cmd_batch_pointer(cmd, cmd_len, &dw);
964 dw[0] = dw0;
965 dw[1] = clear_val;
966 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800967}
968
Chia-I Wu302742d2014-08-22 10:28:29 +0800969static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800970 uint32_t blend_offset,
971 uint32_t ds_offset,
972 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800973{
974 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800975 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800976
977 CMD_ASSERT(cmd, 6, 6);
978
Chia-I Wu426072d2014-08-26 14:31:55 +0800979 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800980 (cmd_len - 2);
981
Chia-I Wu72292b72014-09-09 10:48:33 +0800982 cmd_batch_pointer(cmd, cmd_len, &dw);
983 dw[0] = dw0;
984 dw[1] = blend_offset | 1;
985 dw[2] = ds_offset | 1;
986 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987}
988
Chia-I Wu1744cca2014-08-22 11:10:17 +0800989static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800990 uint32_t clip_offset,
991 uint32_t sf_offset,
992 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800993{
994 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800995 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800996
997 CMD_ASSERT(cmd, 6, 6);
998
Chia-I Wu426072d2014-08-26 14:31:55 +0800999 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001000 GEN6_VP_PTR_DW0_CLIP_CHANGED |
1001 GEN6_VP_PTR_DW0_SF_CHANGED |
1002 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001003 (cmd_len - 2);
1004
Chia-I Wu72292b72014-09-09 10:48:33 +08001005 cmd_batch_pointer(cmd, cmd_len, &dw);
1006 dw[0] = dw0;
1007 dw[1] = clip_offset;
1008 dw[2] = sf_offset;
1009 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001010}
1011
1012static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001013 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001014{
1015 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001016 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001017
1018 CMD_ASSERT(cmd, 6, 6);
1019
Chia-I Wu426072d2014-08-26 14:31:55 +08001020 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001021 (cmd_len - 2);
1022
Chia-I Wu72292b72014-09-09 10:48:33 +08001023 cmd_batch_pointer(cmd, cmd_len, &dw);
1024 dw[0] = dw0;
1025 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001026}
1027
Chia-I Wu42a56202014-08-23 16:47:48 +08001028static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001029 uint32_t vs_offset,
1030 uint32_t gs_offset,
1031 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001032{
1033 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001034 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001035
1036 CMD_ASSERT(cmd, 6, 6);
1037
Chia-I Wu426072d2014-08-26 14:31:55 +08001038 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001039 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1040 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1041 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001042 (cmd_len - 2);
1043
Chia-I Wu72292b72014-09-09 10:48:33 +08001044 cmd_batch_pointer(cmd, cmd_len, &dw);
1045 dw[0] = dw0;
1046 dw[1] = vs_offset;
1047 dw[2] = gs_offset;
1048 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001049}
1050
Chia-I Wu257e75e2014-08-29 14:06:35 +08001051static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001052 uint32_t vs_offset,
1053 uint32_t gs_offset,
1054 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001055{
1056 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001057 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001058
1059 CMD_ASSERT(cmd, 6, 6);
1060
1061 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001062 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1063 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1064 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001065 (cmd_len - 2);
1066
Chia-I Wu72292b72014-09-09 10:48:33 +08001067 cmd_batch_pointer(cmd, cmd_len, &dw);
1068 dw[0] = dw0;
1069 dw[1] = vs_offset;
1070 dw[2] = gs_offset;
1071 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001072}
1073
Chia-I Wu302742d2014-08-22 10:28:29 +08001074static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001075 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001076{
1077 const uint8_t cmd_len = 2;
1078 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1079 GEN6_RENDER_SUBTYPE_3D |
1080 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001081 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001082
Chia-I Wu72292b72014-09-09 10:48:33 +08001083 cmd_batch_pointer(cmd, cmd_len, &dw);
1084 dw[0] = dw0;
1085 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001086}
1087
Chia-I Wua6c4f152014-12-02 04:19:58 +08001088static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001089{
Chia-I Wue6073342014-11-30 09:43:42 +08001090 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001091 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1092 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001093
1094 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001095 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001096
Tony Barbourfa6cac72015-01-16 14:27:35 -07001097 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001098}
1099
Chia-I Wu72292b72014-09-09 10:48:33 +08001100static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001101 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001102{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001103 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001104 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001105 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001106 uint32_t dw[3];
1107
1108 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001109 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001110 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001111 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1112 (state->ds_info.stencilReadMask & 0xff) << 8 |
1113 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001114 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001115
1116 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001117
1118 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1119 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001120
Chia-I Wu00b51a82014-09-09 12:07:37 +08001121 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001122 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001123}
1124
Chia-I Wu72292b72014-09-09 10:48:33 +08001125static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001126 uint32_t stencil_ref,
1127 const uint32_t blend_color[4])
1128{
Chia-I Wue6073342014-11-30 09:43:42 +08001129 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001130 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001131 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001132
1133 CMD_ASSERT(cmd, 6, 7.5);
1134
Chia-I Wu00b51a82014-09-09 12:07:37 +08001135 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1136 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001137 dw[0] = stencil_ref;
1138 dw[1] = 0;
1139 dw[2] = blend_color[0];
1140 dw[3] = blend_color[1];
1141 dw[4] = blend_color[2];
1142 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001143
Chia-I Wu72292b72014-09-09 10:48:33 +08001144 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001145}
1146
Chia-I Wu8370b402014-08-29 12:28:37 +08001147static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001148{
Chia-I Wu8370b402014-08-29 12:28:37 +08001149 CMD_ASSERT(cmd, 6, 7.5);
1150
Chia-I Wu707a29e2014-08-27 12:51:47 +08001151 if (!cmd->bind.draw_count)
1152 return;
1153
Chia-I Wu8370b402014-08-29 12:28:37 +08001154 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001155 return;
1156
Chia-I Wu8370b402014-08-29 12:28:37 +08001157 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001158
1159 /*
1160 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1161 *
1162 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1163 * pipe-control with a post-sync op and no write-cache flushes."
1164 *
1165 * The workaround below necessitates this workaround.
1166 */
1167 gen6_PIPE_CONTROL(cmd,
1168 GEN6_PIPE_CONTROL_CS_STALL |
1169 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001170 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001171
Chia-I Wud6d079d2014-08-31 13:14:21 +08001172 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1173 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001174}
1175
Chia-I Wu8370b402014-08-29 12:28:37 +08001176static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001177{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001178 CMD_ASSERT(cmd, 6, 7.5);
1179
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001180 if (!cmd->bind.draw_count)
1181 return;
1182
Chia-I Wud6d079d2014-08-31 13:14:21 +08001183 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1184 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001185}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001186
Chia-I Wu8370b402014-08-29 12:28:37 +08001187static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1188{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001189 CMD_ASSERT(cmd, 7, 7.5);
1190
Chia-I Wu8370b402014-08-29 12:28:37 +08001191 if (!cmd->bind.draw_count)
1192 return;
1193
1194 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001195
1196 gen6_PIPE_CONTROL(cmd,
1197 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001198 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001199}
1200
Chia-I Wu8370b402014-08-29 12:28:37 +08001201static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1202{
1203 CMD_ASSERT(cmd, 7, 7.5);
1204
Chia-I Wu8370b402014-08-29 12:28:37 +08001205 /*
1206 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1207 *
1208 * "One of the following must also be set (when CS stall is set):
1209 *
1210 * * Render Target Cache Flush Enable ([12] of DW1)
1211 * * Depth Cache Flush Enable ([0] of DW1)
1212 * * Stall at Pixel Scoreboard ([1] of DW1)
1213 * * Depth Stall ([13] of DW1)
1214 * * Post-Sync Operation ([13] of DW1)"
1215 */
1216 gen6_PIPE_CONTROL(cmd,
1217 GEN6_PIPE_CONTROL_CS_STALL |
1218 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001219 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001220}
1221
1222static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1223{
1224 CMD_ASSERT(cmd, 7, 7.5);
1225
Chia-I Wu8370b402014-08-29 12:28:37 +08001226 cmd_wa_gen6_pre_depth_stall_write(cmd);
1227
Chia-I Wud6d079d2014-08-31 13:14:21 +08001228 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001229}
1230
1231static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1232{
1233 CMD_ASSERT(cmd, 6, 7.5);
1234
1235 if (!cmd->bind.draw_count)
1236 return;
1237
1238 /*
1239 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1240 *
1241 * "Driver must guarentee that all the caches in the depth pipe are
1242 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1243 * requires driver to send a PIPE_CONTROL with a CS stall along with
1244 * a Depth Flush prior to this command."
1245 *
1246 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1247 *
1248 * "Driver must ierarchi that all the caches in the depth pipe are
1249 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1250 * requires driver to send a PIPE_CONTROL with a CS stall along with
1251 * a Depth Flush prior to this command.
1252 */
1253 gen6_PIPE_CONTROL(cmd,
1254 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1255 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001256 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001257}
1258
1259static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1260{
1261 CMD_ASSERT(cmd, 6, 7.5);
1262
1263 if (!cmd->bind.draw_count)
1264 return;
1265
1266 /*
1267 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1268 *
1269 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1270 * and a post sync operation prior to the group of depth
1271 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1272 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1273 *
1274 * This workaround satifies all the conditions.
1275 */
1276 cmd_wa_gen6_pre_depth_stall_write(cmd);
1277
1278 /*
1279 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1280 *
1281 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1282 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1283 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1284 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1285 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1286 * Depth Flush Bit set, followed by another pipelined depth stall
1287 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1288 * guarantee that the pipeline from WM onwards is already flushed
1289 * (e.g., via a preceding MI_FLUSH)."
1290 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001291 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1292 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1293 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001294}
1295
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001296void cmd_batch_state_base_address(struct intel_cmd *cmd)
1297{
1298 const uint8_t cmd_len = 10;
1299 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1300 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001301 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001302 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001303 uint32_t pos;
1304 uint32_t *dw;
1305
1306 CMD_ASSERT(cmd, 6, 7.5);
1307
1308 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1309
1310 dw[0] = dw0;
1311 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001312 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001313 dw[2] = 1;
1314 dw[3] = 1;
1315 dw[4] = 1;
1316 dw[5] = 1;
1317 /* end offsets */
1318 dw[6] = 1;
1319 dw[7] = 1 + 0xfffff000;
1320 dw[8] = 1 + 0xfffff000;
1321 dw[9] = 1;
1322
1323 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001324 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1325 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1326 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1327 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1328 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1329 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001330}
1331
Chia-I Wu7c853562015-02-27 14:35:08 -07001332void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1333{
1334 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1335 const uint8_t cmd_len = 2;
1336 uint32_t offset = 0;
1337 uint32_t *dw;
1338
1339 if (cmd_gen(cmd) <= INTEL_GEN(6))
1340 return;
1341
1342 CMD_ASSERT(cmd, 7, 7.5);
1343
1344 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1345 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1346 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1347 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1348 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1349 offset += size;
1350
1351 dw += 2;
1352 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1353 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1354 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1355
1356 dw += 2;
1357 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1358 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1359 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1360
1361 dw += 2;
1362 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1363 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1364 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1365
1366 dw += 2;
1367 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1368 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1369 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1370
1371 /*
1372 *
1373 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1374 *
1375 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1376 * in the ring after this instruction
1377 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1378 */
1379 cmd_wa_gen7_post_command_cs_stall(cmd);
1380}
1381
Chia-I Wu525c6602014-08-27 10:22:34 +08001382void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1383{
Mike Stroyan552fda42015-01-30 17:21:08 -07001384 if (pipe_control_dw0 == 0)
1385 return;
1386
Chia-I Wu525c6602014-08-27 10:22:34 +08001387 if (!cmd->bind.draw_count)
1388 return;
1389
1390 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1391
Chia-I Wu8370b402014-08-29 12:28:37 +08001392 /*
1393 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1394 *
1395 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1396 * PIPE_CONTROL with any non-zero post-sync-op is required."
1397 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001398 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001399 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001400
Chia-I Wu092279a2014-08-30 19:05:30 +08001401 /*
1402 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1403 *
1404 * "One of the following must also be set (when CS stall is set):
1405 *
1406 * * Render Target Cache Flush Enable ([12] of DW1)
1407 * * Depth Cache Flush Enable ([0] of DW1)
1408 * * Stall at Pixel Scoreboard ([1] of DW1)
1409 * * Depth Stall ([13] of DW1)
1410 * * Post-Sync Operation ([13] of DW1)"
1411 */
1412 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1413 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1414 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1415 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1416 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1417 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1418
Chia-I Wud6d079d2014-08-31 13:14:21 +08001419 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001420}
1421
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001422void cmd_batch_flush_all(struct intel_cmd *cmd)
1423{
1424 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1425 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1426 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1427 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1428 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1429 GEN6_PIPE_CONTROL_CS_STALL);
1430}
1431
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001432void cmd_batch_depth_count(struct intel_cmd *cmd,
1433 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001434 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001435{
1436 cmd_wa_gen6_pre_depth_stall_write(cmd);
1437
1438 gen6_PIPE_CONTROL(cmd,
1439 GEN6_PIPE_CONTROL_DEPTH_STALL |
1440 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001441 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001442}
1443
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001444void cmd_batch_timestamp(struct intel_cmd *cmd,
1445 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001446 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001447{
1448 /* need any WA or stall? */
1449 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1450}
1451
1452void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001453 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001454 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001455 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001456 uint64_t val)
1457{
1458 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001459 gen6_PIPE_CONTROL(cmd,
1460 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1461 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001462}
1463
Chia-I Wu302742d2014-08-22 10:28:29 +08001464static void gen6_cc_states(struct intel_cmd *cmd)
1465{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001466 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1467 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001468 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001469 uint32_t stencil_ref;
1470 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001471
1472 CMD_ASSERT(cmd, 6, 6);
1473
Chia-I Wua6c4f152014-12-02 04:19:58 +08001474 blend_offset = gen6_BLEND_STATE(cmd);
1475
1476 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001477 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001478 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001479 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001480
1481 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001482 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001483 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1484 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001485 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001486 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001487 stencil_ref = 0;
1488 }
1489
Chia-I Wu72292b72014-09-09 10:48:33 +08001490 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001491
Chia-I Wu72292b72014-09-09 10:48:33 +08001492 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001493}
1494
Chia-I Wu1744cca2014-08-22 11:10:17 +08001495static void gen6_viewport_states(struct intel_cmd *cmd)
1496{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001497 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001498 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001499
1500 if (!viewport)
1501 return;
1502
Tony Barbourfa6cac72015-01-16 14:27:35 -07001503 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001504 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001505
1506 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001507 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001508 viewport->cmd);
1509
1510 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001511 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001512 &viewport->cmd[viewport->cmd_clip_pos]);
1513
1514 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001515 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001516 &viewport->cmd[viewport->cmd_cc_pos]);
1517
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001518 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1519 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1520 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001521
1522 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001523 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001524
Chia-I Wub1d450a2014-09-09 13:48:03 +08001525 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001526}
1527
Chia-I Wu302742d2014-08-22 10:28:29 +08001528static void gen7_cc_states(struct intel_cmd *cmd)
1529{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001530 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1531 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001532 uint32_t stencil_ref;
1533 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001534 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001535
1536 CMD_ASSERT(cmd, 7, 7.5);
1537
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001538 if (!blend && !ds)
1539 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001540
Chia-I Wua6c4f152014-12-02 04:19:58 +08001541 offset = gen6_BLEND_STATE(cmd);
1542 gen7_3dstate_pointer(cmd,
1543 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001544
Chia-I Wua6c4f152014-12-02 04:19:58 +08001545 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001546 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001547 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001548 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001549
1550 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001551 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001552 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1553 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001554 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001555 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1556 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001557 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1558 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001559 } else {
1560 stencil_ref = 0;
1561 }
1562
Chia-I Wu72292b72014-09-09 10:48:33 +08001563 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001564 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001565 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001566}
1567
Chia-I Wu1744cca2014-08-22 11:10:17 +08001568static void gen7_viewport_states(struct intel_cmd *cmd)
1569{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001570 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001571 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001572
1573 if (!viewport)
1574 return;
1575
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001576 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001577
Chia-I Wub1d450a2014-09-09 13:48:03 +08001578 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001579 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001580 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001581 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001582 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1583 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001584
1585 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001586 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001587 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001588 gen7_3dstate_pointer(cmd,
1589 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001590 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001591
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001592 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1593 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1594 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1595 gen7_3dstate_pointer(cmd,
1596 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1597 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001598}
1599
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001600static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001601 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001602{
1603 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001604 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001605
Chia-I Wu72292b72014-09-09 10:48:33 +08001606 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001607
1608 dw[0] = GEN6_RENDER_TYPE_RENDER |
1609 GEN6_RENDER_SUBTYPE_3D |
1610 subop | (cmd_len - 2);
1611 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001612 dw[2] = 0;
1613 dw[3] = 0;
1614 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001615}
1616
1617static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001618 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001619{
1620 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001621 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001622
Chia-I Wu72292b72014-09-09 10:48:33 +08001623 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001624
1625 dw[0] = GEN6_RENDER_TYPE_RENDER |
1626 GEN6_RENDER_SUBTYPE_3D |
1627 subop | (cmd_len - 2);
1628 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001629 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001630 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001631 dw[4] = 0;
1632 dw[5] = 0;
1633 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001634}
1635
Chia-I Wu625105f2014-10-13 15:35:29 +08001636static uint32_t emit_samplers(struct intel_cmd *cmd,
1637 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001638{
Chia-I Wu862c5572015-03-28 15:23:55 +08001639 const struct intel_desc_region *region = cmd->dev->desc_region;
1640 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001641 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1642 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001643 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001644 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001645 uint32_t surface_count;
1646 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001647
1648 CMD_ASSERT(cmd, 6, 7.5);
1649
Chia-I Wu625105f2014-10-13 15:35:29 +08001650 if (!rmap || !rmap->sampler_count)
1651 return 0;
1652
Cody Northrop40316a32014-12-09 19:08:33 -07001653 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001654
Chia-I Wudcb509d2014-12-10 08:53:10 +08001655 /*
1656 * note that we cannot call cmd_state_pointer() here as the following
1657 * cmd_state_pointer() would invalidate the pointer
1658 */
1659 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001660 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001661 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001662
1663 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001664 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001665 4 * rmap->sampler_count, &sampler_dw);
1666
Chia-I Wudcb509d2014-12-10 08:53:10 +08001667 cmd_state_update(cmd, border_offset,
1668 border_stride * rmap->sampler_count, &border_dw);
1669
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001670 for (i = 0; i < rmap->sampler_count; i++) {
1671 const struct intel_pipeline_rmap_slot *slot =
1672 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001673 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001674 const struct intel_sampler *sampler;
1675
Chia-I Wuf8385062015-01-04 16:27:24 +08001676 switch (slot->type) {
1677 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001678 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1679 &data->set_offsets[slot->index]);
1680 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001681 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001682 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001683 sampler = NULL;
1684 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001685 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001686 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001687 sampler = NULL;
1688 break;
1689 }
1690
1691 if (sampler) {
1692 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1693
1694 sampler_dw[0] = sampler->cmd[0];
1695 sampler_dw[1] = sampler->cmd[1];
1696 sampler_dw[2] = border_offset;
1697 sampler_dw[3] = sampler->cmd[2];
1698 } else {
1699 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1700 sampler_dw[1] = 0;
1701 sampler_dw[2] = 0;
1702 sampler_dw[3] = 0;
1703 }
1704
1705 border_offset += border_stride * 4;
1706 border_dw += border_stride;
1707 sampler_dw += 4;
1708 }
1709
Chia-I Wu625105f2014-10-13 15:35:29 +08001710 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001711}
1712
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001713static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001714 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001715 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001716{
Chia-I Wu862c5572015-03-28 15:23:55 +08001717 const struct intel_desc_region *region = cmd->dev->desc_region;
1718 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001719 const uint32_t sba_offset =
1720 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001721 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001722 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001723
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001724 CMD_ASSERT(cmd, 6, 7.5);
1725
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001726 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001727 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001728 if (!surface_count)
1729 return 0;
1730
Chia-I Wu42a56202014-08-23 16:47:48 +08001731 assert(surface_count <= ARRAY_SIZE(binding_table));
1732
1733 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001734 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001735 struct intel_null_view null_view;
1736 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001737
Chia-I Wuf8385062015-01-04 16:27:24 +08001738 switch (slot->type) {
1739 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001740 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001741 const struct intel_rt_view *view =
Chia-I Wu7732cb22015-03-26 15:27:55 +08001742 (slot->index < cmd->bind.fb->rt_count) ?
1743 cmd->bind.fb->rt[slot->index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001744
Chia-I Wu787a05b2014-12-05 11:02:20 +08001745 if (view) {
1746 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1747 GEN6_ALIGNMENT_SURFACE_STATE,
1748 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001749
Chia-I Wu787a05b2014-12-05 11:02:20 +08001750 cmd_reserve_reloc(cmd, 1);
1751 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1752 view->cmd[1], INTEL_RELOC_WRITE);
1753 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001754 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001755 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001756 }
1757 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001758 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001759 {
Tony Barbour22a30862015-04-22 09:02:32 -06001760 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001761 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001762 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001763 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001764 const struct intel_mem *mem;
1765 bool read_only;
1766 const uint32_t *cmd_data;
1767 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001768
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001769 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001770 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001771
Chia-I Wu862c5572015-03-28 15:23:55 +08001772 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1773 &data->set_offsets[slot->index]);
1774
1775 intel_desc_region_read_surface(region, &desc_offset, stage,
1776 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001777 if (mem) {
1778 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001779 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001780 const uint32_t reloc_flags =
1781 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001782
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001783 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001784 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001785 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001786
1787 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001788 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1789 cmd_data[1] + dynamic_offset, reloc_flags);
1790 } else {
1791 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001792 }
1793 }
1794 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001795 case INTEL_PIPELINE_RMAP_UNUSED:
1796 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001797 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001798 default:
1799 assert(!"unexpected rmap type");
1800 need_null_view = true;
1801 break;
1802 }
1803
1804 if (need_null_view) {
1805 intel_null_view_init(&null_view, cmd->dev);
1806 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1807 GEN6_ALIGNMENT_SURFACE_STATE,
1808 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001809 }
1810
Chia-I Wuf98dd882015-02-10 04:17:47 +08001811 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001812 }
1813
Chia-I Wuf98dd882015-02-10 04:17:47 +08001814 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001815 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001816 surface_count, binding_table) - sba_offset;
1817
1818 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1819 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1820
1821 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001822}
1823
Chia-I Wu1d125092014-10-08 08:49:38 +08001824static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1825{
1826 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001827 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1828 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001829 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001830
1831 CMD_ASSERT(cmd, 6, 7.5);
1832
1833 if (!pipeline->vb_count)
1834 return;
1835
1836 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1837
1838 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1839 dw++;
1840 pos++;
1841
1842 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001843 assert(pipeline->vb[i].strideInBytes <= 2048);
1844
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001845 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001846 pipeline->vb[i].strideInBytes;
1847
Chia-I Wub3686982015-02-27 09:51:16 -07001848 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001849 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1850 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001851 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001852
1853 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001854 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001855 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001856 dw[3] = 0;
1857 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001858 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001859 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001860 dw[3] = 1;
1861 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001862 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001863 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001864 dw[3] = 0;
1865 break;
1866 default:
1867 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001868 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001869 dw[3] = 0;
1870 break;
1871 }
1872
Chia-I Wu714df452015-01-01 07:55:04 +08001873 if (cmd->bind.vertex.buf[i]) {
1874 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001875 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001876
1877 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001878 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1879 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001880 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001881 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001882 dw[1] = 0;
1883 dw[2] = 0;
1884 }
1885
1886 dw += 4;
1887 pos += 4;
1888 }
1889}
1890
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001891static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1892{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001893 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1894 const struct intel_pipeline_shader *vs = &pipeline->vs;
1895 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001896 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001897 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001898 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001899 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001900
1901 CMD_ASSERT(cmd, 6, 7.5);
1902
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001903 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001904 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1905 *
1906 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1907 * 128-bit vertex elements to be passed into the payload for each
1908 * vertex."
1909 *
1910 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1911 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001912 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001913 vue_read_len = (vs->in_count + 1) / 2;
1914 if (!vue_read_len)
1915 vue_read_len = 1;
1916
1917 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1918 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1919
1920 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1921 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1922 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001923
1924 dw5 = GEN6_VS_DW5_STATISTICS |
1925 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001926
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001927 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001928 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001929 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001930 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001931
Chia-I Wube0a3d92014-09-02 13:20:59 +08001932 if (pipeline->disable_vs_cache)
1933 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1934
Chia-I Wu784d3042014-12-19 14:30:04 +08001935 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001936 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001937 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001938 dw[2] = dw2;
1939 dw[3] = 0; /* scratch */
1940 dw[4] = dw4;
1941 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001942
1943 if (vs->per_thread_scratch_size)
1944 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001945}
1946
Chia-I Wu625105f2014-10-13 15:35:29 +08001947static void emit_shader_resources(struct intel_cmd *cmd)
1948{
1949 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001950 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001951
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001952 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001953 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001954 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001955 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001956 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001957 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001958 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001959 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001960 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001961 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001962 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001963 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001964 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001965 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001966 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001967
1968 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1969 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1970 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1971 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1972 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1973
1974 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1975 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001976 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1977 binding_tables[0]);
1978 gen7_3dstate_pointer(cmd,
1979 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1980 binding_tables[1]);
1981 gen7_3dstate_pointer(cmd,
1982 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1983 binding_tables[2]);
1984 gen7_3dstate_pointer(cmd,
1985 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1986 binding_tables[3]);
1987 gen7_3dstate_pointer(cmd,
1988 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1989 binding_tables[4]);
1990
1991 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001992 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1993 samplers[0]);
1994 gen7_3dstate_pointer(cmd,
1995 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1996 samplers[1]);
1997 gen7_3dstate_pointer(cmd,
1998 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1999 samplers[2]);
2000 gen7_3dstate_pointer(cmd,
2001 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
2002 samplers[3]);
2003 gen7_3dstate_pointer(cmd,
2004 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2005 samplers[4]);
2006 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002007 assert(!binding_tables[1] && !binding_tables[2]);
2008 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2009 binding_tables[0], binding_tables[3], binding_tables[4]);
2010
Chia-I Wu625105f2014-10-13 15:35:29 +08002011 assert(!samplers[1] && !samplers[2]);
2012 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2013 samplers[0], samplers[3], samplers[4]);
2014 }
2015}
2016
Chia-I Wu8ada4242015-03-02 11:19:33 -07002017static void emit_msaa(struct intel_cmd *cmd)
2018{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002019 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002020
Chia-I Wubbc7d912015-02-27 14:59:50 -07002021 if (!cmd->bind.render_pass_changed)
2022 return;
2023
Chia-I Wu8ada4242015-03-02 11:19:33 -07002024 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002025 cmd->result = VK_ERROR_UNKNOWN;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002026
2027 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2028 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
2029}
2030
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002031static void emit_rt(struct intel_cmd *cmd)
2032{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002033 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002034
2035 if (!cmd->bind.render_pass_changed)
2036 return;
2037
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002038 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002039 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2040 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002041}
2042
2043static void emit_ds(struct intel_cmd *cmd)
2044{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002045 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002046 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002047
Chia-I Wubbc7d912015-02-27 14:59:50 -07002048 if (!cmd->bind.render_pass_changed)
2049 return;
2050
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002051 if (!ds) {
2052 /* all zeros */
2053 static const struct intel_ds_view null_ds;
2054 ds = &null_ds;
2055 }
2056
2057 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07002058 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
2059 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
2060 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002061
2062 if (cmd_gen(cmd) >= INTEL_GEN(7))
2063 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2064 else
2065 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2066}
2067
Chia-I Wua57761b2014-10-14 14:27:44 +08002068static uint32_t emit_shader(struct intel_cmd *cmd,
2069 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002070{
Chia-I Wua57761b2014-10-14 14:27:44 +08002071 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2072 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002073 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002074
Chia-I Wua57761b2014-10-14 14:27:44 +08002075 /* see if the shader is already in the cache */
2076 for (i = 0; i < cache->used; i++) {
2077 if (cache->entries[i].shader == (const void *) shader)
2078 return cache->entries[i].kernel_offset;
2079 }
2080
2081 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2082
2083 /* grow the cache if full */
2084 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002085 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002086 void *entries;
2087
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002088 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002089 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002090 if (entries) {
2091 if (cache->entries) {
2092 memcpy(entries, cache->entries,
2093 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002094 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002095 }
2096
2097 cache->entries = entries;
2098 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002099 }
2100 }
2101
Chia-I Wua57761b2014-10-14 14:27:44 +08002102 /* add the shader to the cache */
2103 if (cache->used < cache->count) {
2104 cache->entries[cache->used].shader = (const void *) shader;
2105 cache->entries[cache->used].kernel_offset = offset;
2106 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002107 }
2108
Chia-I Wua57761b2014-10-14 14:27:44 +08002109 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002110}
2111
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002112static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002113{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002114 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002115
Chia-I Wu8370b402014-08-29 12:28:37 +08002116 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2117 cmd_wa_gen6_pre_depth_stall_write(cmd);
2118 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2119 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2120 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2121 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002122
2123 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002124 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002125 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002126
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002127 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002128 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002129 }
2130 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002131 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002132 }
2133 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002134 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2135 }
2136 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2137 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2138 }
2139 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2140 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002141 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002142
Chia-I Wu8370b402014-08-29 12:28:37 +08002143 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2144 cmd_wa_gen7_post_command_cs_stall(cmd);
2145 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2146 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002147}
2148
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002149static void emit_bounded_states(struct intel_cmd *cmd)
2150{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002151 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002152
2153 emit_graphics_pipeline(cmd);
2154
2155 emit_rt(cmd);
2156 emit_ds(cmd);
2157
2158 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2159 gen7_cc_states(cmd);
2160 gen7_viewport_states(cmd);
2161
2162 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2163 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002164 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2165 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002166 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2167 &cmd->bind.pipeline.graphics->fs);
2168
Cody Northrop293d4502015-05-05 09:38:03 -06002169 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002170 gen6_3DSTATE_CLIP(cmd);
2171 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002172 gen7_3DSTATE_WM(cmd);
2173 gen7_3DSTATE_PS(cmd);
2174 } else {
2175 gen6_cc_states(cmd);
2176 gen6_viewport_states(cmd);
2177
2178 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2179 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002180 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2181 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002182 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2183 &cmd->bind.pipeline.graphics->fs);
2184
Cody Northrop293d4502015-05-05 09:38:03 -06002185 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002186 gen6_3DSTATE_CLIP(cmd);
2187 gen6_3DSTATE_SF(cmd);
2188 gen6_3DSTATE_WM(cmd);
2189 }
2190
2191 emit_shader_resources(cmd);
2192
2193 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002194
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002195 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2196 gen6_3DSTATE_VS(cmd);
2197}
2198
Tony Barbourfa6cac72015-01-16 14:27:35 -07002199static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002200 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002201{
2202 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2203 const uint8_t cmd_len = 3;
2204 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002205
2206 CMD_ASSERT(cmd, 6, 7.5);
2207
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002208 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002209 dw[0] = 0;
2210 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002211
2212 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2213 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2214 GEN6_COMPAREFUNCTION_NEVER << 27 |
2215 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2216 } else {
2217 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2218 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2219 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002220 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002221 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002222 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2223 (GEN6_STENCILOP_KEEP) << 25 |
2224 (GEN6_STENCILOP_KEEP) << 22 |
2225 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002226 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2227 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002228 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2229 (GEN6_STENCILOP_KEEP) << 9 |
2230 (GEN6_STENCILOP_KEEP) << 6 |
2231 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002232
Chia-I Wud850a392015-02-19 11:08:25 -07002233 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2234 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2235 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2236 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2237 dw[2] = 0;
2238 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002239
2240 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2241 cmd_align, cmd_len, dw);
2242}
2243
Chia-I Wu6032b892014-10-17 14:47:18 +08002244static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2245{
2246 const struct intel_cmd_meta *meta = cmd->bind.meta;
2247 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2248
2249 CMD_ASSERT(cmd, 6, 7.5);
2250
2251 blend_offset = 0;
2252 ds_offset = 0;
2253 cc_offset = 0;
2254 cc_vp_offset = 0;
2255
Chia-I Wu29e6f502014-11-24 14:27:29 +08002256 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002257 /* BLEND_STATE */
2258 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002259 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002260 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002261 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002262 }
2263
Chia-I Wu29e6f502014-11-24 14:27:29 +08002264 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002265 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002266 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002267 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2268 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002269
Chia-I Wu29e6f502014-11-24 14:27:29 +08002270 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002271 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002272
Chia-I Wu29e6f502014-11-24 14:27:29 +08002273 /* COLOR_CALC_STATE */
2274 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002275 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002276
Chia-I Wu29e6f502014-11-24 14:27:29 +08002277 /* CC_VIEWPORT */
2278 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002279 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002280 dw[0] = u_fui(0.0f);
2281 dw[1] = u_fui(1.0f);
2282 } else {
2283 /* DEPTH_STENCIL_STATE */
2284 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002285 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2287 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2288 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002289 }
2290
2291 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2292 gen7_3dstate_pointer(cmd,
2293 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2294 blend_offset);
2295 gen7_3dstate_pointer(cmd,
2296 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2297 ds_offset);
2298 gen7_3dstate_pointer(cmd,
2299 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2300
2301 gen7_3dstate_pointer(cmd,
2302 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2303 cc_vp_offset);
2304 } else {
2305 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002306 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002307
2308 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2309 cmd_batch_pointer(cmd, 4, &dw);
2310 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002311 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002312 dw[1] = 0;
2313 dw[2] = 0;
2314 dw[3] = cc_vp_offset;
2315 }
2316}
2317
2318static void gen6_meta_surface_states(struct intel_cmd *cmd)
2319{
2320 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002321 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002322 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002323 const uint32_t sba_offset =
2324 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002325
2326 CMD_ASSERT(cmd, 6, 7.5);
2327
Chia-I Wu29e6f502014-11-24 14:27:29 +08002328 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2329 return;
2330
Chia-I Wu005c47c2014-10-22 13:49:13 +08002331 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002332 if (meta->src.valid) {
2333 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002334 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002335 meta->src.surface_len, meta->src.surface);
2336
2337 cmd_reserve_reloc(cmd, 1);
2338 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2339 cmd_surface_reloc_writer(cmd, offset, 1,
2340 meta->src.reloc_target, meta->src.reloc_offset);
2341 } else {
2342 cmd_surface_reloc(cmd, offset, 1,
2343 (struct intel_bo *) meta->src.reloc_target,
2344 meta->src.reloc_offset, meta->src.reloc_flags);
2345 }
2346
Mike Stroyan9bfad482015-02-10 15:09:23 -07002347 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002348 }
2349 if (meta->dst.valid) {
2350 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002351 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002352 meta->dst.surface_len, meta->dst.surface);
2353
2354 cmd_reserve_reloc(cmd, 1);
2355 cmd_surface_reloc(cmd, offset, 1,
2356 (struct intel_bo *) meta->dst.reloc_target,
2357 meta->dst.reloc_offset, meta->dst.reloc_flags);
2358
Mike Stroyan9bfad482015-02-10 15:09:23 -07002359 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002360 }
2361
2362 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002363 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002364 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002365 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002366
2367 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002368 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2369 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2370 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002371 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002372 } else {
2373 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002374 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002375 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002376 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002377 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002378 }
2379}
2380
2381static void gen6_meta_urb(struct intel_cmd *cmd)
2382{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002383 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002384 uint32_t *dw;
2385
2386 CMD_ASSERT(cmd, 6, 6);
2387
2388 /* 3DSTATE_URB */
2389 cmd_batch_pointer(cmd, 3, &dw);
2390 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002391 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002392 dw[2] = 0;
2393}
2394
2395static void gen7_meta_urb(struct intel_cmd *cmd)
2396{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002397 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2398 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002399 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002400 uint32_t *dw;
2401
2402 CMD_ASSERT(cmd, 7, 7.5);
2403
Chia-I Wu6032b892014-10-17 14:47:18 +08002404 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2405
Chia-I Wu24aa1022014-11-25 11:53:19 +08002406 switch (cmd_gen(cmd)) {
2407 case INTEL_GEN(7.5):
2408 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2409 break;
2410 case INTEL_GEN(7):
2411 default:
2412 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2413 break;
2414 }
2415
Chia-I Wu6032b892014-10-17 14:47:18 +08002416 /* 3DSTATE_URB_x */
2417 cmd_batch_pointer(cmd, 8, &dw);
2418
2419 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002420 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002421 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002422 dw += 2;
2423
2424 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002425 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002426 dw += 2;
2427
2428 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002429 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002430 dw += 2;
2431
2432 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002433 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002434 dw += 2;
2435}
2436
2437static void gen6_meta_vf(struct intel_cmd *cmd)
2438{
2439 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002440 uint32_t vb_start, vb_end, vb_stride;
2441 int ve_format, ve_z_source;
2442 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002443 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002444
2445 CMD_ASSERT(cmd, 6, 7.5);
2446
Chia-I Wu29e6f502014-11-24 14:27:29 +08002447 switch (meta->mode) {
2448 case INTEL_CMD_META_VS_POINTS:
2449 cmd_batch_pointer(cmd, 3, &dw);
2450 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002451 dw[1] = GEN6_VE_DW0_VALID;
2452 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2453 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2454 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2455 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002456 return;
2457 break;
2458 case INTEL_CMD_META_FS_RECT:
2459 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002460 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002461
Chia-I Wu29e6f502014-11-24 14:27:29 +08002462 vertices[0][0] = meta->dst.x + meta->width;
2463 vertices[0][1] = meta->dst.y + meta->height;
2464 vertices[1][0] = meta->dst.x;
2465 vertices[1][1] = meta->dst.y + meta->height;
2466 vertices[2][0] = meta->dst.x;
2467 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002468
Chia-I Wu29e6f502014-11-24 14:27:29 +08002469 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2470 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002471
Chia-I Wu29e6f502014-11-24 14:27:29 +08002472 vb_end = vb_start + sizeof(vertices) - 1;
2473 vb_stride = sizeof(vertices[0]);
2474 ve_z_source = GEN6_VFCOMP_STORE_0;
2475 ve_format = GEN6_FORMAT_R32G32_USCALED;
2476 }
2477 break;
2478 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2479 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002480 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002481
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002482 vertices[0][0] = (float) (meta->dst.x + meta->width);
2483 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002484 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002485 vertices[1][0] = (float) meta->dst.x;
2486 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002487 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002488 vertices[2][0] = (float) meta->dst.x;
2489 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002490 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002491
Chia-I Wu29e6f502014-11-24 14:27:29 +08002492 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2493 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002494
Chia-I Wu29e6f502014-11-24 14:27:29 +08002495 vb_end = vb_start + sizeof(vertices) - 1;
2496 vb_stride = sizeof(vertices[0]);
2497 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2498 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2499 }
2500 break;
2501 default:
2502 assert(!"unknown meta mode");
2503 return;
2504 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002505 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002506
2507 /* 3DSTATE_VERTEX_BUFFERS */
2508 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002509
Chia-I Wu6032b892014-10-17 14:47:18 +08002510 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002511 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002512 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002513 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002514
2515 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002516 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2517 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002518
2519 dw[4] = 0;
2520
2521 /* 3DSTATE_VERTEX_ELEMENTS */
2522 cmd_batch_pointer(cmd, 5, &dw);
2523 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002524 dw[1] = GEN6_VE_DW0_VALID;
2525 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2526 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2527 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2528 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2529 dw[3] = GEN6_VE_DW0_VALID |
2530 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2531 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2532 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2533 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2534 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002535}
2536
Chia-I Wu29e6f502014-11-24 14:27:29 +08002537static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002538{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002539 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002540 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002541 uint32_t consts[8];
2542 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002543
2544 CMD_ASSERT(cmd, 6, 7.5);
2545
2546 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002547 case INTEL_DEV_META_VS_FILL_MEM:
2548 consts[0] = meta->dst.x;
2549 consts[1] = meta->clear_val[0];
2550 const_count = 2;
2551 break;
2552 case INTEL_DEV_META_VS_COPY_MEM:
2553 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2554 consts[0] = meta->dst.x;
2555 consts[1] = meta->src.x;
2556 const_count = 2;
2557 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002558 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2559 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2560 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2561 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2562 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2563 consts[0] = meta->src.x;
2564 consts[1] = meta->src.y;
2565 consts[2] = meta->width;
2566 consts[3] = meta->dst.x;
2567 const_count = 4;
2568 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002569 default:
2570 assert(!"unknown meta shader id");
2571 const_count = 0;
2572 break;
2573 }
2574
2575 /* this can be skipped but it makes state dumping prettier */
2576 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2577
2578 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2579}
2580
2581static void gen6_meta_vs(struct intel_cmd *cmd)
2582{
2583 const struct intel_cmd_meta *meta = cmd->bind.meta;
2584 const struct intel_pipeline_shader *sh =
2585 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2586 uint32_t offset, *dw;
2587
2588 CMD_ASSERT(cmd, 6, 7.5);
2589
2590 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002591 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002592
2593 /* 3DSTATE_CONSTANT_VS */
2594 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2595 cmd_batch_pointer(cmd, cmd_len, &dw);
2596 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2597 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2598
2599 /* 3DSTATE_VS */
2600 cmd_batch_pointer(cmd, 6, &dw);
2601 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2602 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2603
2604 return;
2605 }
2606
2607 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2608
2609 /* 3DSTATE_CONSTANT_VS */
2610 offset = gen6_meta_vs_constants(cmd);
2611 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2612 cmd_batch_pointer(cmd, 7, &dw);
2613 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002614 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002615 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002616 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002617 dw[4] = 0;
2618 dw[5] = 0;
2619 dw[6] = 0;
2620 } else {
2621 cmd_batch_pointer(cmd, 5, &dw);
2622 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002623 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002624 dw[1] = offset;
2625 dw[2] = 0;
2626 dw[3] = 0;
2627 dw[4] = 0;
2628 }
2629
2630 /* 3DSTATE_VS */
2631 offset = emit_shader(cmd, sh);
2632 cmd_batch_pointer(cmd, 6, &dw);
2633 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2634 dw[1] = offset;
2635 dw[2] = GEN6_THREADDISP_SPF |
2636 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2637 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002638 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002639 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2640 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2641
2642 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2643 GEN6_VS_DW5_VS_ENABLE;
2644 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002645 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002646 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002647 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002648
2649 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002650}
2651
2652static void gen6_meta_disabled(struct intel_cmd *cmd)
2653{
Chia-I Wu6032b892014-10-17 14:47:18 +08002654 uint32_t *dw;
2655
2656 CMD_ASSERT(cmd, 6, 6);
2657
Chia-I Wu6032b892014-10-17 14:47:18 +08002658 /* 3DSTATE_CONSTANT_GS */
2659 cmd_batch_pointer(cmd, 5, &dw);
2660 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2661 dw[1] = 0;
2662 dw[2] = 0;
2663 dw[3] = 0;
2664 dw[4] = 0;
2665
2666 /* 3DSTATE_GS */
2667 cmd_batch_pointer(cmd, 7, &dw);
2668 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2669 dw[1] = 0;
2670 dw[2] = 0;
2671 dw[3] = 0;
2672 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2673 dw[5] = GEN6_GS_DW5_STATISTICS;
2674 dw[6] = 0;
2675
Chia-I Wu6032b892014-10-17 14:47:18 +08002676 /* 3DSTATE_SF */
2677 cmd_batch_pointer(cmd, 20, &dw);
2678 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2679 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2680 memset(&dw[2], 0, 18 * sizeof(*dw));
2681}
2682
2683static void gen7_meta_disabled(struct intel_cmd *cmd)
2684{
2685 uint32_t *dw;
2686
2687 CMD_ASSERT(cmd, 7, 7.5);
2688
Chia-I Wu6032b892014-10-17 14:47:18 +08002689 /* 3DSTATE_CONSTANT_HS */
2690 cmd_batch_pointer(cmd, 7, &dw);
2691 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2692 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2693
2694 /* 3DSTATE_HS */
2695 cmd_batch_pointer(cmd, 7, &dw);
2696 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2697 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2698
2699 /* 3DSTATE_TE */
2700 cmd_batch_pointer(cmd, 4, &dw);
2701 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2702 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2703
2704 /* 3DSTATE_CONSTANT_DS */
2705 cmd_batch_pointer(cmd, 7, &dw);
2706 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2707 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2708
2709 /* 3DSTATE_DS */
2710 cmd_batch_pointer(cmd, 6, &dw);
2711 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2712 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2713
2714 /* 3DSTATE_CONSTANT_GS */
2715 cmd_batch_pointer(cmd, 7, &dw);
2716 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2717 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2718
2719 /* 3DSTATE_GS */
2720 cmd_batch_pointer(cmd, 7, &dw);
2721 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2722 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2723
2724 /* 3DSTATE_STREAMOUT */
2725 cmd_batch_pointer(cmd, 3, &dw);
2726 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2727 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2728
Chia-I Wu6032b892014-10-17 14:47:18 +08002729 /* 3DSTATE_SF */
2730 cmd_batch_pointer(cmd, 7, &dw);
2731 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2732 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2733
2734 /* 3DSTATE_SBE */
2735 cmd_batch_pointer(cmd, 14, &dw);
2736 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2737 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2738 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002739}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002740
Chia-I Wu29e6f502014-11-24 14:27:29 +08002741static void gen6_meta_clip(struct intel_cmd *cmd)
2742{
2743 const struct intel_cmd_meta *meta = cmd->bind.meta;
2744 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002745
Chia-I Wu29e6f502014-11-24 14:27:29 +08002746 /* 3DSTATE_CLIP */
2747 cmd_batch_pointer(cmd, 4, &dw);
2748 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2749 dw[1] = 0;
2750 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2751 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2752 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2753 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002754 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002755 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002756 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002757}
2758
2759static void gen6_meta_wm(struct intel_cmd *cmd)
2760{
2761 const struct intel_cmd_meta *meta = cmd->bind.meta;
2762 uint32_t *dw;
2763
2764 CMD_ASSERT(cmd, 6, 7.5);
2765
2766 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2767
2768 /* 3DSTATE_MULTISAMPLE */
2769 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2770 cmd_batch_pointer(cmd, 4, &dw);
2771 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2772 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2773 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2774 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2775 dw[2] = 0;
2776 dw[3] = 0;
2777 } else {
2778 cmd_batch_pointer(cmd, 3, &dw);
2779 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2780 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2781 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2782 dw[2] = 0;
2783 }
2784
2785 /* 3DSTATE_SAMPLE_MASK */
2786 cmd_batch_pointer(cmd, 2, &dw);
2787 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2788 dw[1] = (1 << meta->samples) - 1;
2789
2790 /* 3DSTATE_DRAWING_RECTANGLE */
2791 cmd_batch_pointer(cmd, 4, &dw);
2792 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002793 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2794 /* unused */
2795 dw[1] = 0;
2796 dw[2] = 0;
2797 } else {
2798 dw[1] = meta->dst.y << 16 | meta->dst.x;
2799 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2800 (meta->dst.x + meta->width - 1);
2801 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002802 dw[3] = 0;
2803}
2804
2805static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2806{
2807 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002808 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002809 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002810 uint32_t consts[8];
2811 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002812
2813 CMD_ASSERT(cmd, 6, 7.5);
2814
2815 /* underflow is fine here */
2816 offset_x = meta->src.x - meta->dst.x;
2817 offset_y = meta->src.y - meta->dst.y;
2818
2819 switch (meta->shader_id) {
2820 case INTEL_DEV_META_FS_COPY_MEM:
2821 case INTEL_DEV_META_FS_COPY_1D:
2822 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2823 case INTEL_DEV_META_FS_COPY_2D:
2824 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2825 case INTEL_DEV_META_FS_COPY_2D_MS:
2826 consts[0] = offset_x;
2827 consts[1] = offset_y;
2828 consts[2] = meta->src.layer;
2829 consts[3] = meta->src.lod;
2830 const_count = 4;
2831 break;
2832 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2833 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2834 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2835 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2836 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2837 consts[0] = offset_x;
2838 consts[1] = offset_y;
2839 consts[2] = meta->src.layer;
2840 consts[3] = meta->src.lod;
2841 consts[4] = meta->src.x;
2842 consts[5] = meta->width;
2843 const_count = 6;
2844 break;
2845 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2846 consts[0] = offset_x;
2847 consts[1] = offset_y;
2848 consts[2] = meta->width;
2849 const_count = 3;
2850 break;
2851 case INTEL_DEV_META_FS_CLEAR_COLOR:
2852 consts[0] = meta->clear_val[0];
2853 consts[1] = meta->clear_val[1];
2854 consts[2] = meta->clear_val[2];
2855 consts[3] = meta->clear_val[3];
2856 const_count = 4;
2857 break;
2858 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2859 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002860 consts[1] = meta->clear_val[1];
2861 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002862 break;
2863 case INTEL_DEV_META_FS_RESOLVE_2X:
2864 case INTEL_DEV_META_FS_RESOLVE_4X:
2865 case INTEL_DEV_META_FS_RESOLVE_8X:
2866 case INTEL_DEV_META_FS_RESOLVE_16X:
2867 consts[0] = offset_x;
2868 consts[1] = offset_y;
2869 const_count = 2;
2870 break;
2871 default:
2872 assert(!"unknown meta shader id");
2873 const_count = 0;
2874 break;
2875 }
2876
2877 /* this can be skipped but it makes state dumping prettier */
2878 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2879
2880 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2881}
2882
2883static void gen6_meta_ps(struct intel_cmd *cmd)
2884{
2885 const struct intel_cmd_meta *meta = cmd->bind.meta;
2886 const struct intel_pipeline_shader *sh =
2887 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2888 uint32_t offset, *dw;
2889
2890 CMD_ASSERT(cmd, 6, 6);
2891
Chia-I Wu29e6f502014-11-24 14:27:29 +08002892 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2893 /* 3DSTATE_CONSTANT_PS */
2894 cmd_batch_pointer(cmd, 5, &dw);
2895 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2896 dw[1] = 0;
2897 dw[2] = 0;
2898 dw[3] = 0;
2899 dw[4] = 0;
2900
2901 /* 3DSTATE_WM */
2902 cmd_batch_pointer(cmd, 9, &dw);
2903 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2904 dw[1] = 0;
2905 dw[2] = 0;
2906 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002907
2908 switch (meta->ds.op) {
2909 case INTEL_CMD_META_DS_HIZ_CLEAR:
2910 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2911 break;
2912 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2913 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2914 break;
2915 case INTEL_CMD_META_DS_RESOLVE:
2916 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2917 break;
2918 default:
2919 dw[4] = 0;
2920 break;
2921 }
2922
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002923 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002924 dw[6] = 0;
2925 dw[7] = 0;
2926 dw[8] = 0;
2927
Chia-I Wu3adf7212014-10-24 15:34:07 +08002928 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002929 }
2930
Chia-I Wu3adf7212014-10-24 15:34:07 +08002931 /* a normal color write */
2932 assert(meta->dst.valid && !sh->uses);
2933
Chia-I Wu6032b892014-10-17 14:47:18 +08002934 /* 3DSTATE_CONSTANT_PS */
2935 offset = gen6_meta_ps_constants(cmd);
2936 cmd_batch_pointer(cmd, 5, &dw);
2937 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002938 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002939 dw[1] = offset;
2940 dw[2] = 0;
2941 dw[3] = 0;
2942 dw[4] = 0;
2943
2944 /* 3DSTATE_WM */
2945 offset = emit_shader(cmd, sh);
2946 cmd_batch_pointer(cmd, 9, &dw);
2947 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2948 dw[1] = offset;
2949 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2950 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002951 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002952 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002953 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002954 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2955 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002956
Chia-I Wu6032b892014-10-17 14:47:18 +08002957 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002958 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002959 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2960 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2961 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2962 if (meta->samples > 1) {
2963 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2964 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2965 } else {
2966 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2967 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2968 }
2969 dw[7] = 0;
2970 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002971
2972 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002973}
2974
2975static void gen7_meta_ps(struct intel_cmd *cmd)
2976{
2977 const struct intel_cmd_meta *meta = cmd->bind.meta;
2978 const struct intel_pipeline_shader *sh =
2979 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2980 uint32_t offset, *dw;
2981
2982 CMD_ASSERT(cmd, 7, 7.5);
2983
Chia-I Wu29e6f502014-11-24 14:27:29 +08002984 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2985 /* 3DSTATE_WM */
2986 cmd_batch_pointer(cmd, 3, &dw);
2987 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002988
2989 switch (meta->ds.op) {
2990 case INTEL_CMD_META_DS_HIZ_CLEAR:
2991 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2992 break;
2993 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2994 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2995 break;
2996 case INTEL_CMD_META_DS_RESOLVE:
2997 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2998 break;
2999 default:
3000 dw[1] = 0;
3001 break;
3002 }
3003
3004 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003005
3006 /* 3DSTATE_CONSTANT_GS */
3007 cmd_batch_pointer(cmd, 7, &dw);
3008 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3009 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3010
3011 /* 3DSTATE_PS */
3012 cmd_batch_pointer(cmd, 8, &dw);
3013 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3014 dw[1] = 0;
3015 dw[2] = 0;
3016 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003017 /* required to avoid hangs */
3018 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003019 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003020 dw[5] = 0;
3021 dw[6] = 0;
3022 dw[7] = 0;
3023
Chia-I Wu3adf7212014-10-24 15:34:07 +08003024 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003025 }
3026
Chia-I Wu3adf7212014-10-24 15:34:07 +08003027 /* a normal color write */
3028 assert(meta->dst.valid && !sh->uses);
3029
Chia-I Wu6032b892014-10-17 14:47:18 +08003030 /* 3DSTATE_WM */
3031 cmd_batch_pointer(cmd, 3, &dw);
3032 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003033 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003034 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3035 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3036 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3037 dw[2] = 0;
3038
3039 /* 3DSTATE_CONSTANT_PS */
3040 offset = gen6_meta_ps_constants(cmd);
3041 cmd_batch_pointer(cmd, 7, &dw);
3042 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003043 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003044 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003045 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003046 dw[4] = 0;
3047 dw[5] = 0;
3048 dw[6] = 0;
3049
3050 /* 3DSTATE_PS */
3051 offset = emit_shader(cmd, sh);
3052 cmd_batch_pointer(cmd, 8, &dw);
3053 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3054 dw[1] = offset;
3055 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3056 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003057 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003058
3059 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3060 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003061 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003062
3063 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003064 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003065 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003066 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003067 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003068 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003069
3070 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3071 dw[6] = 0;
3072 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003073
3074 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003075}
3076
3077static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3078{
3079 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08003080 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003081
3082 CMD_ASSERT(cmd, 6, 7.5);
3083
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003084 if (!ds) {
3085 /* all zeros */
3086 static const struct intel_ds_view null_ds;
3087 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003088 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003089
3090 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003091 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3092 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3093 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003094
3095 if (cmd_gen(cmd) >= INTEL_GEN(7))
3096 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3097 else
3098 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003099}
3100
Chia-I Wu862c5572015-03-28 15:23:55 +08003101static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3102 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003103 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003104{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003105 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003106 if (data->set_offsets)
3107 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003108
Chia-I Wu862c5572015-03-28 15:23:55 +08003109 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003110 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003111 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003112 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003113 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003114 data->set_offset_count = 0;
3115 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003116 }
3117
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003118 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003119 }
3120
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003121 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003122 if (data->dynamic_offsets)
3123 intel_free(cmd, data->dynamic_offsets);
3124
3125 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003126 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003127 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003128 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003129 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003130 data->dynamic_offset_count = 0;
3131 return false;
3132 }
3133
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003134 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003135 }
3136
3137 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003138}
3139
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003140static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3141 const struct intel_pipeline *pipeline)
3142{
3143 cmd->bind.pipeline.graphics = pipeline;
3144
3145 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003146 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003147}
3148
3149static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3150 const struct intel_pipeline *pipeline)
3151{
3152 cmd->bind.pipeline.compute = pipeline;
3153
3154 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003155 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003156}
3157
Chia-I Wu862c5572015-03-28 15:23:55 +08003158static void cmd_copy_dset_data(struct intel_cmd *cmd,
3159 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003160 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003161 uint32_t index,
3162 const struct intel_desc_set *set,
3163 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003164{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003165 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003166
Chia-I Wu862c5572015-03-28 15:23:55 +08003167 assert(index < data->set_offset_count);
3168 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003169
Chia-I Wu862c5572015-03-28 15:23:55 +08003170 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003171 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003172 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003173
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003174 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003175 dynamic_offsets,
3176 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003177 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003178}
3179
Chia-I Wu3b04af52014-11-08 10:48:20 +08003180static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003181 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003182 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003183{
Chia-I Wu714df452015-01-01 07:55:04 +08003184 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003185 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003186 return;
3187 }
3188
Chia-I Wu714df452015-01-01 07:55:04 +08003189 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003190 cmd->bind.vertex.offset[binding] = offset;
3191}
3192
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003193static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003194 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003195 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003196{
Chia-I Wu714df452015-01-01 07:55:04 +08003197 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003198 cmd->bind.index.offset = offset;
3199 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003200}
3201
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003202static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003203 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003204{
3205 cmd->bind.state.viewport = state;
3206}
3207
3208static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003209 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003210{
3211 cmd->bind.state.raster = state;
3212}
3213
3214static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003215 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003216{
3217 cmd->bind.state.ds = state;
3218}
3219
3220static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003221 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003222{
3223 cmd->bind.state.blend = state;
3224}
3225
Chia-I Wuf98dd882015-02-10 04:17:47 +08003226static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3227{
3228 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3229 struct intel_pipeline_rmap *rmaps[5] = {
3230 pipeline->vs.rmap,
3231 pipeline->tcs.rmap,
3232 pipeline->tes.rmap,
3233 pipeline->gs.rmap,
3234 pipeline->fs.rmap,
3235 };
3236 uint32_t max_write;
3237 int i;
3238
3239 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3240 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3241 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3242
3243 /* pad first */
3244 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3245
3246 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3247 const struct intel_pipeline_rmap *rmap = rmaps[i];
3248 const uint32_t surface_count = (rmap) ?
3249 rmap->rt_count + rmap->texture_resource_count +
3250 rmap->resource_count + rmap->uav_count : 0;
3251
3252 if (surface_count) {
3253 /* SURFACE_STATEs */
3254 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3255
3256 /* BINDING_TABLE_STATE */
3257 max_write += u_align(sizeof(uint32_t) * surface_count,
3258 GEN6_ALIGNMENT_SURFACE_STATE);
3259 }
3260 }
3261
3262 return max_write;
3263}
3264
3265static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3266{
3267 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3268 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3269 uint32_t max_surface_write;
3270
3271 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3272 if (cmd->bind.meta)
3273 max_surface_write = 64 * sizeof(uint32_t);
3274 else
3275 max_surface_write = cmd_get_max_surface_write(cmd);
3276
3277 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3278 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3279 /* SBA expects page-aligned addresses */
3280 writer->sba_offset = writer->used & ~0xfff;
3281
3282 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3283
3284 cmd_batch_state_base_address(cmd);
3285 }
3286}
3287
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003288static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003289 uint32_t vertex_start,
3290 uint32_t vertex_count,
3291 uint32_t instance_start,
3292 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003293 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003294 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003295{
3296 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003297 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003298 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3299
3300 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003301
3302 emit_bounded_states(cmd);
3303
Chia-I Wuf98dd882015-02-10 04:17:47 +08003304 /* sanity check on cmd_get_max_surface_write() */
3305 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3306 surface_writer_used <= cmd_get_max_surface_write(cmd));
3307
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003308 if (indexed) {
3309 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003310 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003311
3312 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3313 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3314 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003315 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003316 cmd->bind.index.offset, cmd->bind.index.type,
3317 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003318 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003319 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003320 cmd->bind.index.offset, cmd->bind.index.type,
3321 p->primitive_restart);
3322 }
3323 } else {
3324 assert(!vertex_base);
3325 }
3326
3327 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3328 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3329 vertex_start, instance_count, instance_start, vertex_base);
3330 } else {
3331 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3332 vertex_start, instance_count, instance_start, vertex_base);
3333 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003334
Chia-I Wu707a29e2014-08-27 12:51:47 +08003335 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003336 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003337 /* need to re-emit all workarounds */
3338 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003339
3340 if (intel_debug & INTEL_DEBUG_NOCACHE)
3341 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003342}
3343
Chia-I Wuc14d1562014-10-17 09:49:22 +08003344void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3345{
Chia-I Wu6032b892014-10-17 14:47:18 +08003346 cmd->bind.meta = meta;
3347
Chia-I Wuf98dd882015-02-10 04:17:47 +08003348 cmd_adjust_state_base_address(cmd);
3349
Chia-I Wu6032b892014-10-17 14:47:18 +08003350 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003351 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003352
3353 gen6_meta_dynamic_states(cmd);
3354 gen6_meta_surface_states(cmd);
3355
3356 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3357 gen7_meta_urb(cmd);
3358 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003359 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003360 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003361 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003362 gen6_meta_wm(cmd);
3363 gen7_meta_ps(cmd);
3364 gen6_meta_depth_buffer(cmd);
3365
3366 cmd_wa_gen7_post_command_cs_stall(cmd);
3367 cmd_wa_gen7_post_command_depth_stall(cmd);
3368
Chia-I Wu29e6f502014-11-24 14:27:29 +08003369 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3370 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003371 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003372 } else {
3373 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3374 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003375 } else {
3376 gen6_meta_urb(cmd);
3377 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003378 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003379 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003380 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003381 gen6_meta_wm(cmd);
3382 gen6_meta_ps(cmd);
3383 gen6_meta_depth_buffer(cmd);
3384
Chia-I Wu29e6f502014-11-24 14:27:29 +08003385 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3386 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003387 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003388 } else {
3389 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3390 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003391 }
3392
3393 cmd->bind.draw_count++;
3394 /* need to re-emit all workarounds */
3395 cmd->bind.wa_flags = 0;
3396
3397 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003398
Chia-I Wubbc7d912015-02-27 14:59:50 -07003399 /* make the normal path believe the render pass has changed */
3400 cmd->bind.render_pass_changed = true;
3401
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003402 if (intel_debug & INTEL_DEBUG_NOCACHE)
3403 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003404}
3405
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003406ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003407 VkCmdBuffer cmdBuffer,
3408 VkPipelineBindPoint pipelineBindPoint,
3409 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003410{
3411 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3412
3413 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003414 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003415 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003416 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003417 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003418 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003419 break;
3420 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003421 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003422 break;
3423 }
3424}
3425
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003426ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003427 VkCmdBuffer cmdBuffer,
3428 VkStateBindPoint stateBindPoint,
3429 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003430{
3431 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3432
3433 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003434 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003435 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003436 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003437 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003438 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003439 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003440 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003441 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003442 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003443 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003444 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003445 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003446 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003447 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003448 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003449 break;
3450 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003451 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003452 break;
3453 }
3454}
3455
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003456ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003457 VkCmdBuffer cmdBuffer,
3458 VkPipelineBindPoint pipelineBindPoint,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003459 uint32_t firstSet,
3460 uint32_t setCount,
3461 const VkDescriptorSet* pDescriptorSets,
3462 uint32_t dynamicOffsetCount,
3463 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003464{
3465 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003466 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003467 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003468 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003469 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003470
3471 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003472 case VK_PIPELINE_BIND_POINT_COMPUTE:
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003473 pipeline_layout = cmd->bind.pipeline.compute->pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003474 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003475 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003476 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003477 pipeline_layout = cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003478 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003479 break;
3480 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003481 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003482 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003483 break;
3484 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003485
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003486 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003487 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3488
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003489 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003490 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003491 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003492 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003493 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003494 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003495 }
Chia-I Wub2755562014-08-20 13:38:52 +08003496}
3497
Tony Barbour8205d902015-04-16 15:59:00 -06003498
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003499ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3500 VkCmdBuffer cmdBuffer,
3501 uint32_t startBinding,
3502 uint32_t bindingCount,
3503 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003504 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003505{
3506 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003507
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003508 for (uint32_t i = 0; i < bindingCount; i++) {
3509 struct intel_buf *buf = intel_buf(pBuffers[i]);
3510 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3511 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003512}
3513
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003514ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003515 VkCmdBuffer cmdBuffer,
3516 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003517 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003518 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003519{
3520 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003521 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003522
Chia-I Wu714df452015-01-01 07:55:04 +08003523 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003524}
3525
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003526ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003527 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003528 uint32_t firstVertex,
3529 uint32_t vertexCount,
3530 uint32_t firstInstance,
3531 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003532{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003533 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003534
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003535 cmd_draw(cmd, firstVertex, vertexCount,
3536 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003537}
3538
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003539ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003540 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003541 uint32_t firstIndex,
3542 uint32_t indexCount,
3543 int32_t vertexOffset,
3544 uint32_t firstInstance,
3545 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003546{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003547 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003548
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003549 cmd_draw(cmd, firstIndex, indexCount,
3550 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003551}
3552
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003553ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003554 VkCmdBuffer cmdBuffer,
3555 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003556 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003557 uint32_t count,
3558 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003559{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003560 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3561
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003562 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003563}
3564
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003565ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003566 VkCmdBuffer cmdBuffer,
3567 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003568 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003569 uint32_t count,
3570 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003571{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003572 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3573
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003574 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003575}
3576
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003577ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003578 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003579 uint32_t x,
3580 uint32_t y,
3581 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003582{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003583 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3584
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003585 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003586}
3587
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003588ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003589 VkCmdBuffer cmdBuffer,
3590 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003591 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003592{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003593 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3594
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003595 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003596}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003597
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003598ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003599 VkCmdBuffer cmdBuffer,
3600 const VkRenderPassBegin* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003601{
3602 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003603 struct intel_render_pass *rp = (struct intel_render_pass *) pRenderPassBegin->renderPass;
3604 struct intel_fb *fb = (struct intel_fb *) pRenderPassBegin->framebuffer;
3605 unsigned i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003606
Chris Forbesfff9bf42015-06-15 15:26:19 +12003607 cmd_begin_render_pass(cmd, rp, fb);
3608
3609 /* issue load ops */
3610 for (i = 0; i < rp->colorAttachmentCount; i++) {
3611 if (rp->colorLoadOps[i] == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3612 /* issue clear of this attachment */
3613 const struct intel_rt_view *rt = fb->rt[i];
3614
3615 VkImageSubresourceRange ranges[1] = {{
3616 VK_IMAGE_ASPECT_COLOR,
3617 rt->mipLevel,
3618 1,
3619 rt->baseArraySlice,
3620 rt->array_size
3621 }};
3622
3623 cmd_meta_clear_color_image(cmdBuffer, (VkImage) rt->img,
3624 rp->colorLayouts[i],
3625 &rp->colorClearValues[i],
3626 1,
3627 ranges);
3628 }
3629 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003630}
3631
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003632ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003633 VkCmdBuffer cmdBuffer,
3634 VkRenderPass renderPass)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003635{
3636 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3637
3638 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3639}