blob: 6d1b0f5b3ca3811b2748a8c5c4ee8c3b8077ca33 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wub2755562014-08-20 13:38:52 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600221 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffffffu);
226 break;
227 default:
228 supported = false;
229 break;
230 }
231
232 return supported;
233}
234
Chia-I Wu59c097e2014-08-21 10:51:07 +0800235static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800236 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600237 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600238 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 bool enable_cut_index)
240{
241 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800242 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800243 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600244 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245
246 CMD_ASSERT(cmd, 6, 7.5);
247
Chia-I Wu426072d2014-08-26 14:31:55 +0800248 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800249
250 /* the bit is moved to 3DSTATE_VF */
251 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
252 assert(!enable_cut_index);
253 if (enable_cut_index)
254 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
255
256 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600257 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800258 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
259 offset_align = 2;
260 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600261 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800262 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
263 offset_align = 4;
264 break;
265 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600266 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800267 return;
268 break;
269 }
270
271 if (offset % offset_align) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800273 return;
274 }
275
276 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800277 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800278
Chia-I Wu72292b72014-09-09 10:48:33 +0800279 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
280 dw[0] = dw0;
281
282 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800283 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
284 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285}
286
Chia-I Wu62a7f252014-08-29 11:31:16 +0800287static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
288 bool enable_cut_index,
289 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800290{
291 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800292 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800293
294 CMD_ASSERT(cmd, 7.5, 7.5);
295
Chia-I Wu426072d2014-08-26 14:31:55 +0800296 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800297 if (enable_cut_index)
298 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
299
Chia-I Wu72292b72014-09-09 10:48:33 +0800300 cmd_batch_pointer(cmd, cmd_len, &dw);
301 dw[0] = dw0;
302 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800303}
304
Cody Northrop293d4502015-05-05 09:38:03 -0600305static void gen6_add_scratch_space(struct intel_cmd *cmd,
306 uint32_t batch_pos,
307 const struct intel_pipeline *pipeline,
308 const struct intel_pipeline_shader *sh)
309{
310 int scratch_space;
311
312 CMD_ASSERT(cmd, 6, 7.5);
313
314 assert(sh->per_thread_scratch_size &&
315 sh->per_thread_scratch_size % 1024 == 0 &&
316 u_is_pow2(sh->per_thread_scratch_size) &&
317 sh->scratch_offset % 1024 == 0);
318 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
319
320 cmd_reserve_reloc(cmd, 1);
321 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
322 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
323}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600324
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800325static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
326{
Cody Northrop293d4502015-05-05 09:38:03 -0600327 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
328 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600330 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800331 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600332 int vue_read_len = 0;
333 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800334
Cody Northrop293d4502015-05-05 09:38:03 -0600335 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
336
337 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
338
339 // based on ilo_gpe_init_gs_cso_gen6
340 vue_read_len = (gs->in_count + 1) / 2;
341 if (!vue_read_len)
342 vue_read_len = 1;
343
344 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
345 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
346 GEN6_THREADDISP_SPF;
347
348 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
349 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
350 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
351
352 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
353 GEN6_GS_DW5_STATISTICS |
354 GEN6_GS_DW5_RENDER_ENABLE;
355
356 dw6 = GEN6_GS_DW6_GS_ENABLE;
357
358 if (gs->discard_adj)
359 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
360
361 } else {
362 dw2 = 0;
363 dw4 = 0;
364 dw5 = GEN6_GS_DW5_STATISTICS;
365 dw6 = 0;
366 }
367
368 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800369 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600370 dw[1] = cmd->bind.pipeline.gs_offset;
371 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800372 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600373 dw[4] = dw4;
374 dw[5] = dw5;
375 dw[6] = dw6;
376
377 if (gs->per_thread_scratch_size)
378 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800379}
380
Chia-I Wu62a7f252014-08-29 11:31:16 +0800381static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
382{
Cody Northrop293d4502015-05-05 09:38:03 -0600383 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
384 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800385 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600386 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800387 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600388 int vue_read_len = 0;
389 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800390
Cody Northrop293d4502015-05-05 09:38:03 -0600391 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
392
393 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
394
395 // based on upload_gs_state
396 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
397 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
398
399 vue_read_len = (gs->in_count + 1) / 2;
400 if (!vue_read_len)
401 vue_read_len = 1;
402
403 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
404 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
405 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
406 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
407 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
408
409
410 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
411 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
412 GEN7_GS_DW5_STATISTICS |
413 GEN7_GS_DW5_GS_ENABLE;
414
415 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
416 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
417
418 if (gs->include_primitive_id)
419 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
420
421 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
422 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
423 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
424 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
425 } else {
426 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
427 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
428 dw6 = 0;
429 }
430 } else {
431 dw2 = 0;
432 dw4 = 0;
433 dw5 = GEN7_GS_DW5_STATISTICS;
434 dw6 = 0;
435 }
436
437 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800438 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600439 dw[1] = cmd->bind.pipeline.gs_offset;
440 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800441 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600442 dw[4] = dw4;
443 dw[5] = dw5;
444 dw[6] = dw6;
445
446 if (gs->per_thread_scratch_size)
447 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800448}
449
Chia-I Wud88e02d2014-08-25 10:56:13 +0800450static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600451 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800452{
453 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800454 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800455 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457
458 CMD_ASSERT(cmd, 6, 7.5);
459
Chia-I Wu72292b72014-09-09 10:48:33 +0800460 cmd_batch_pointer(cmd, cmd_len, &dw);
461 dw[0] = dw0;
462
Chia-I Wud88e02d2014-08-25 10:56:13 +0800463 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800464 dw[1] = 0;
465 dw[2] = (height - 1) << 16 |
466 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800467 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800468 dw[1] = 1;
469 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800470 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800471
472 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800473}
474
Chia-I Wu8016a172014-08-29 18:31:32 +0800475static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
476 uint32_t body[6])
477{
478 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800479 const struct intel_render_pass *rp = cmd->bind.render_pass;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700480 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800481 uint32_t dw1, dw2, dw3;
Chia-I Wu8016a172014-08-29 18:31:32 +0800482
483 CMD_ASSERT(cmd, 6, 7.5);
484
485 dw1 = GEN7_SF_DW1_STATISTICS |
486 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
487 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
488 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
489 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700490 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800491
492 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
493 int format;
494
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800495 switch (rp->depthStencilFormat) {
Tony Barbour8205d902015-04-16 15:59:00 -0600496 case VK_FORMAT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800497 format = GEN6_ZFORMAT_D16_UNORM;
498 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600499 case VK_FORMAT_D32_SFLOAT:
500 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800501 format = GEN6_ZFORMAT_D32_FLOAT;
502 break;
503 default:
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600504 assert(!cmd->bind.fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800505 format = 0;
506 break;
507 }
508
509 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
510 }
511
Tony Barbourfa6cac72015-01-16 14:27:35 -0700512 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800513
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700514 /* Scissor is always enabled */
515 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
516
Tony Barbourfa6cac72015-01-16 14:27:35 -0700517 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800518 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
519 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
520 } else {
521 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
522 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
523 }
524
Chia-I Wu8016a172014-08-29 18:31:32 +0800525 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
526 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
527 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800528 GEN7_SF_DW3_SUBPIXEL_8BITS;
529
Chia-I Wu8016a172014-08-29 18:31:32 +0800530 body[0] = dw1;
531 body[1] = dw2;
532 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700533 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
534 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
535 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800536}
537
Chia-I Wu8016a172014-08-29 18:31:32 +0800538static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
539{
540 const uint8_t cmd_len = 20;
541 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
542 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800543 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800544 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800545 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800546
547 CMD_ASSERT(cmd, 6, 6);
548
549 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800550
Chia-I Wu72292b72014-09-09 10:48:33 +0800551 cmd_batch_pointer(cmd, cmd_len, &dw);
552 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800553 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800554 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800555 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800556}
557
558static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
559{
560 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800561 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800562
563 CMD_ASSERT(cmd, 7, 7.5);
564
Chia-I Wu72292b72014-09-09 10:48:33 +0800565 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800566 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
567 (cmd_len - 2);
568 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800569}
570
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800571static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
572{
573 const uint8_t cmd_len = 4;
574 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
575 (cmd_len - 2);
576 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700577 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800578 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700579 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800580 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800581
582 CMD_ASSERT(cmd, 6, 7.5);
583
584 dw1 = GEN6_CLIP_DW1_STATISTICS;
585 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
586 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
587 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700588 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800589 }
590
591 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800592 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800593 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700594 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800595 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
596 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
597 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
598
599 if (pipeline->rasterizerDiscardEnable)
600 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
601 else
602 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
603
604 if (pipeline->depthClipEnable)
605 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
606
607 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
608 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
609 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
610 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
611
612 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
613 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
614 (viewport->viewport_count - 1);
615
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600616 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600617 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600618 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
619 }
620
Chia-I Wu72292b72014-09-09 10:48:33 +0800621 cmd_batch_pointer(cmd, cmd_len, &dw);
622 dw[0] = dw0;
623 dw[1] = dw1;
624 dw[2] = dw2;
625 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800626}
627
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800628static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
629{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800630 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800631 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800632 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600633 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700634 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800635
636 CMD_ASSERT(cmd, 6, 6);
637
638 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
639
640 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
641 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
642
643 dw4 = GEN6_WM_DW4_STATISTICS |
644 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
645 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700646 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800647
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800648 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700649 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
650 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800651
Cody Northrope86574e2015-02-24 14:15:29 -0700652 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700653 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700654
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800655 if (fs->uses & INTEL_SHADER_USE_KILL ||
656 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700657 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800658
Cody Northrope238deb2015-01-26 14:41:36 -0700659 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800660 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
661 if (fs->uses & INTEL_SHADER_USE_DEPTH)
662 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
663 if (fs->uses & INTEL_SHADER_USE_W)
664 dw5 |= GEN6_WM_DW5_PS_USE_W;
665
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700666 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700667 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668
669 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700670 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800671 GEN6_WM_DW6_ZW_INTERP_PIXEL |
672 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
673 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
674
Tony Barbourfa6cac72015-01-16 14:27:35 -0700675 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
677 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
678 } else {
679 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
680 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
681 }
682
Cody Northrope86574e2015-02-24 14:15:29 -0700683 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
684
Chia-I Wu784d3042014-12-19 14:30:04 +0800685 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800686 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800687 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800688 dw[2] = dw2;
689 dw[3] = 0; /* scratch */
690 dw[4] = dw4;
691 dw[5] = dw5;
692 dw[6] = dw6;
693 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700694 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800695
696 if (fs->per_thread_scratch_size)
697 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800698}
699
700static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
701{
702 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800703 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800705 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800706
707 CMD_ASSERT(cmd, 7, 7.5);
708
709 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
710
711 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700712 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800713 GEN7_WM_DW1_ZW_INTERP_PIXEL |
714 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
715 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
716
717 if (fs->uses & INTEL_SHADER_USE_KILL ||
718 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700719 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800720
Cody Northrope238deb2015-01-26 14:41:36 -0700721 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
722
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723 if (fs->uses & INTEL_SHADER_USE_DEPTH)
724 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
725 if (fs->uses & INTEL_SHADER_USE_W)
726 dw1 |= GEN7_WM_DW1_PS_USE_W;
727
728 dw2 = 0;
729
Tony Barbourfa6cac72015-01-16 14:27:35 -0700730 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800731 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
732 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
733 } else {
734 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
735 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
736 }
737
Chia-I Wu72292b72014-09-09 10:48:33 +0800738 cmd_batch_pointer(cmd, cmd_len, &dw);
739 dw[0] = dw0;
740 dw[1] = dw1;
741 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800742}
743
744static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
745{
746 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800747 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800748 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700749 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600750 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800751
752 CMD_ASSERT(cmd, 7, 7.5);
753
754 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
755
756 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
757 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
758
759 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700760 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800761
Cody Northrope86574e2015-02-24 14:15:29 -0700762 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700763 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700764
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800765 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800766 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700767 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800768 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800769 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800770 }
771
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800772 if (fs->in_count)
773 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
774
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700775 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800776 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
777
778 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
779 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700780 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
781
782 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800783
Chia-I Wu784d3042014-12-19 14:30:04 +0800784 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800786 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800787 dw[2] = dw2;
788 dw[3] = 0; /* scratch */
789 dw[4] = dw4;
790 dw[5] = dw5;
791 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700792 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800793
794 if (fs->per_thread_scratch_size)
795 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800796}
797
Chia-I Wu8ada4242015-03-02 11:19:33 -0700798static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
799 uint32_t sample_count)
800{
801 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
802 uint32_t dw1, dw2, dw3, *dw;
803
804 CMD_ASSERT(cmd, 6, 7.5);
805
806 switch (sample_count) {
807 case 4:
808 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
809 dw2 = cmd->dev->sample_pattern_4x;
810 dw3 = 0;
811 break;
812 case 8:
813 assert(cmd_gen(cmd) >= INTEL_GEN(7));
814 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
815 dw2 = cmd->dev->sample_pattern_8x[0];
816 dw3 = cmd->dev->sample_pattern_8x[1];
817 break;
818 default:
819 assert(sample_count <= 1);
820 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
821 dw2 = 0;
822 dw3 = 0;
823 break;
824 }
825
826 cmd_batch_pointer(cmd, cmd_len, &dw);
827
828 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
829 dw[1] = dw1;
830 dw[2] = dw2;
831 if (cmd_gen(cmd) >= INTEL_GEN(7))
832 dw[3] = dw3;
833}
834
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800835static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700836 const struct intel_ds_view *view,
837 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800838{
839 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800840 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600841 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800842
843 CMD_ASSERT(cmd, 6, 7.5);
844
845 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800846 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
847 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800848 dw0 |= (cmd_len - 2);
849
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
851 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700852
Chia-I Wu72292b72014-09-09 10:48:33 +0800853 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700854 /* note that we only enable HiZ on Gen7+ */
855 if (!optimal_ds)
856 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
857
Chia-I Wu72292b72014-09-09 10:48:33 +0800858 dw[2] = 0;
859 dw[3] = view->cmd[2];
860 dw[4] = view->cmd[3];
861 dw[5] = view->cmd[4];
862 dw[6] = view->cmd[5];
863
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600864 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 cmd_reserve_reloc(cmd, 1);
866 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
867 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600868 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800869}
870
871static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700872 const struct intel_ds_view *view,
873 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800874{
875 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800876 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600877 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800878
879 CMD_ASSERT(cmd, 6, 7.5);
880
881 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800882 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
883 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800884 dw0 |= (cmd_len - 2);
885
Chia-I Wu72292b72014-09-09 10:48:33 +0800886 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
887 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800888
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700889 if (view->has_stencil) {
890 dw[1] = view->cmd[6];
891
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 cmd_reserve_reloc(cmd, 1);
893 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
894 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700895 } else {
896 dw[1] = 0;
897 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600898 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800899}
900
901static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700902 const struct intel_ds_view *view,
903 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800904{
905 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800906 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600907 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800908
909 CMD_ASSERT(cmd, 6, 7.5);
910
911 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800912 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
913 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800914 dw0 |= (cmd_len - 2);
915
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
917 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800918
Chia-I Wu73520ac2015-02-19 11:17:45 -0700919 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700920 dw[1] = view->cmd[8];
921
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 cmd_reserve_reloc(cmd, 1);
923 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
924 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700925 } else {
926 dw[1] = 0;
927 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600928 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800929}
930
Chia-I Wuf8231032014-08-25 10:44:45 +0800931static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
932 uint32_t clear_val)
933{
934 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800935 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800936 GEN6_CLEAR_PARAMS_DW0_VALID |
937 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800938 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800939
940 CMD_ASSERT(cmd, 6, 6);
941
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 cmd_batch_pointer(cmd, cmd_len, &dw);
943 dw[0] = dw0;
944 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800945}
946
947static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
948 uint32_t clear_val)
949{
950 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800951 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800952 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800954
955 CMD_ASSERT(cmd, 7, 7.5);
956
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 cmd_batch_pointer(cmd, cmd_len, &dw);
958 dw[0] = dw0;
959 dw[1] = clear_val;
960 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800961}
962
Chia-I Wu302742d2014-08-22 10:28:29 +0800963static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800964 uint32_t blend_offset,
965 uint32_t ds_offset,
966 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800967{
968 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800969 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800970
971 CMD_ASSERT(cmd, 6, 6);
972
Chia-I Wu426072d2014-08-26 14:31:55 +0800973 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800974 (cmd_len - 2);
975
Chia-I Wu72292b72014-09-09 10:48:33 +0800976 cmd_batch_pointer(cmd, cmd_len, &dw);
977 dw[0] = dw0;
978 dw[1] = blend_offset | 1;
979 dw[2] = ds_offset | 1;
980 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800981}
982
Chia-I Wu1744cca2014-08-22 11:10:17 +0800983static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800984 uint32_t clip_offset,
985 uint32_t sf_offset,
986 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800987{
988 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800989 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800990
991 CMD_ASSERT(cmd, 6, 6);
992
Chia-I Wu426072d2014-08-26 14:31:55 +0800993 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700994 GEN6_VP_PTR_DW0_CLIP_CHANGED |
995 GEN6_VP_PTR_DW0_SF_CHANGED |
996 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800997 (cmd_len - 2);
998
Chia-I Wu72292b72014-09-09 10:48:33 +0800999 cmd_batch_pointer(cmd, cmd_len, &dw);
1000 dw[0] = dw0;
1001 dw[1] = clip_offset;
1002 dw[2] = sf_offset;
1003 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001004}
1005
1006static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001007 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001008{
1009 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001010 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001011
1012 CMD_ASSERT(cmd, 6, 6);
1013
Chia-I Wu426072d2014-08-26 14:31:55 +08001014 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001015 (cmd_len - 2);
1016
Chia-I Wu72292b72014-09-09 10:48:33 +08001017 cmd_batch_pointer(cmd, cmd_len, &dw);
1018 dw[0] = dw0;
1019 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001020}
1021
Chia-I Wu42a56202014-08-23 16:47:48 +08001022static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001023 uint32_t vs_offset,
1024 uint32_t gs_offset,
1025 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001026{
1027 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001028 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001029
1030 CMD_ASSERT(cmd, 6, 6);
1031
Chia-I Wu426072d2014-08-26 14:31:55 +08001032 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001033 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1034 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1035 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001036 (cmd_len - 2);
1037
Chia-I Wu72292b72014-09-09 10:48:33 +08001038 cmd_batch_pointer(cmd, cmd_len, &dw);
1039 dw[0] = dw0;
1040 dw[1] = vs_offset;
1041 dw[2] = gs_offset;
1042 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001043}
1044
Chia-I Wu257e75e2014-08-29 14:06:35 +08001045static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001046 uint32_t vs_offset,
1047 uint32_t gs_offset,
1048 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001049{
1050 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001051 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001052
1053 CMD_ASSERT(cmd, 6, 6);
1054
1055 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001056 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1057 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1058 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001059 (cmd_len - 2);
1060
Chia-I Wu72292b72014-09-09 10:48:33 +08001061 cmd_batch_pointer(cmd, cmd_len, &dw);
1062 dw[0] = dw0;
1063 dw[1] = vs_offset;
1064 dw[2] = gs_offset;
1065 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001066}
1067
Chia-I Wu302742d2014-08-22 10:28:29 +08001068static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001069 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001070{
1071 const uint8_t cmd_len = 2;
1072 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1073 GEN6_RENDER_SUBTYPE_3D |
1074 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001075 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001076
Chia-I Wu72292b72014-09-09 10:48:33 +08001077 cmd_batch_pointer(cmd, cmd_len, &dw);
1078 dw[0] = dw0;
1079 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001080}
1081
Chia-I Wua6c4f152014-12-02 04:19:58 +08001082static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001083{
Chia-I Wue6073342014-11-30 09:43:42 +08001084 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001085 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1086 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001087
1088 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001089 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001090
Tony Barbourfa6cac72015-01-16 14:27:35 -07001091 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001092}
1093
Chia-I Wu72292b72014-09-09 10:48:33 +08001094static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001095 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001096{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001097 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001098 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001099 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001100 uint32_t dw[3];
1101
1102 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001103 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001104 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001105 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1106 (state->ds_info.stencilReadMask & 0xff) << 8 |
1107 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001108 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001109
1110 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001111
1112 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1113 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001114
Chia-I Wu00b51a82014-09-09 12:07:37 +08001115 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001116 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001117}
1118
Chia-I Wu72292b72014-09-09 10:48:33 +08001119static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001120 uint32_t stencil_ref,
1121 const uint32_t blend_color[4])
1122{
Chia-I Wue6073342014-11-30 09:43:42 +08001123 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001124 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001125 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001126
1127 CMD_ASSERT(cmd, 6, 7.5);
1128
Chia-I Wu00b51a82014-09-09 12:07:37 +08001129 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1130 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001131 dw[0] = stencil_ref;
1132 dw[1] = 0;
1133 dw[2] = blend_color[0];
1134 dw[3] = blend_color[1];
1135 dw[4] = blend_color[2];
1136 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001137
Chia-I Wu72292b72014-09-09 10:48:33 +08001138 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001139}
1140
Chia-I Wu8370b402014-08-29 12:28:37 +08001141static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001142{
Chia-I Wu8370b402014-08-29 12:28:37 +08001143 CMD_ASSERT(cmd, 6, 7.5);
1144
Chia-I Wu707a29e2014-08-27 12:51:47 +08001145 if (!cmd->bind.draw_count)
1146 return;
1147
Chia-I Wu8370b402014-08-29 12:28:37 +08001148 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001149 return;
1150
Chia-I Wu8370b402014-08-29 12:28:37 +08001151 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001152
1153 /*
1154 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1155 *
1156 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1157 * pipe-control with a post-sync op and no write-cache flushes."
1158 *
1159 * The workaround below necessitates this workaround.
1160 */
1161 gen6_PIPE_CONTROL(cmd,
1162 GEN6_PIPE_CONTROL_CS_STALL |
1163 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001164 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001165
Chia-I Wud6d079d2014-08-31 13:14:21 +08001166 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1167 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001168}
1169
Chia-I Wu8370b402014-08-29 12:28:37 +08001170static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001171{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001172 CMD_ASSERT(cmd, 6, 7.5);
1173
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001174 if (!cmd->bind.draw_count)
1175 return;
1176
Chia-I Wud6d079d2014-08-31 13:14:21 +08001177 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1178 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001179}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001180
Chia-I Wu8370b402014-08-29 12:28:37 +08001181static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1182{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001183 CMD_ASSERT(cmd, 7, 7.5);
1184
Chia-I Wu8370b402014-08-29 12:28:37 +08001185 if (!cmd->bind.draw_count)
1186 return;
1187
1188 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001189
1190 gen6_PIPE_CONTROL(cmd,
1191 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001192 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001193}
1194
Chia-I Wu8370b402014-08-29 12:28:37 +08001195static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1196{
1197 CMD_ASSERT(cmd, 7, 7.5);
1198
Chia-I Wu8370b402014-08-29 12:28:37 +08001199 /*
1200 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1201 *
1202 * "One of the following must also be set (when CS stall is set):
1203 *
1204 * * Render Target Cache Flush Enable ([12] of DW1)
1205 * * Depth Cache Flush Enable ([0] of DW1)
1206 * * Stall at Pixel Scoreboard ([1] of DW1)
1207 * * Depth Stall ([13] of DW1)
1208 * * Post-Sync Operation ([13] of DW1)"
1209 */
1210 gen6_PIPE_CONTROL(cmd,
1211 GEN6_PIPE_CONTROL_CS_STALL |
1212 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001213 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001214}
1215
1216static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1217{
1218 CMD_ASSERT(cmd, 7, 7.5);
1219
Chia-I Wu8370b402014-08-29 12:28:37 +08001220 cmd_wa_gen6_pre_depth_stall_write(cmd);
1221
Chia-I Wud6d079d2014-08-31 13:14:21 +08001222 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001223}
1224
1225static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1226{
1227 CMD_ASSERT(cmd, 6, 7.5);
1228
1229 if (!cmd->bind.draw_count)
1230 return;
1231
1232 /*
1233 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1234 *
1235 * "Driver must guarentee that all the caches in the depth pipe are
1236 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1237 * requires driver to send a PIPE_CONTROL with a CS stall along with
1238 * a Depth Flush prior to this command."
1239 *
1240 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1241 *
1242 * "Driver must ierarchi that all the caches in the depth pipe are
1243 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1244 * requires driver to send a PIPE_CONTROL with a CS stall along with
1245 * a Depth Flush prior to this command.
1246 */
1247 gen6_PIPE_CONTROL(cmd,
1248 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1249 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001250 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001251}
1252
1253static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1254{
1255 CMD_ASSERT(cmd, 6, 7.5);
1256
1257 if (!cmd->bind.draw_count)
1258 return;
1259
1260 /*
1261 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1262 *
1263 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1264 * and a post sync operation prior to the group of depth
1265 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1266 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1267 *
1268 * This workaround satifies all the conditions.
1269 */
1270 cmd_wa_gen6_pre_depth_stall_write(cmd);
1271
1272 /*
1273 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1274 *
1275 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1276 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1277 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1278 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1279 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1280 * Depth Flush Bit set, followed by another pipelined depth stall
1281 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1282 * guarantee that the pipeline from WM onwards is already flushed
1283 * (e.g., via a preceding MI_FLUSH)."
1284 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001285 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1286 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1287 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001288}
1289
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001290void cmd_batch_state_base_address(struct intel_cmd *cmd)
1291{
1292 const uint8_t cmd_len = 10;
1293 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1294 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001295 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001296 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001297 uint32_t pos;
1298 uint32_t *dw;
1299
1300 CMD_ASSERT(cmd, 6, 7.5);
1301
1302 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1303
1304 dw[0] = dw0;
1305 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001306 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001307 dw[2] = 1;
1308 dw[3] = 1;
1309 dw[4] = 1;
1310 dw[5] = 1;
1311 /* end offsets */
1312 dw[6] = 1;
1313 dw[7] = 1 + 0xfffff000;
1314 dw[8] = 1 + 0xfffff000;
1315 dw[9] = 1;
1316
1317 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001318 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1319 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1320 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1321 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1322 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1323 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001324}
1325
Chia-I Wu7c853562015-02-27 14:35:08 -07001326void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1327{
1328 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1329 const uint8_t cmd_len = 2;
1330 uint32_t offset = 0;
1331 uint32_t *dw;
1332
1333 if (cmd_gen(cmd) <= INTEL_GEN(6))
1334 return;
1335
1336 CMD_ASSERT(cmd, 7, 7.5);
1337
1338 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1339 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1340 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1341 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1342 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1343 offset += size;
1344
1345 dw += 2;
1346 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1347 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1348 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1349
1350 dw += 2;
1351 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1352 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1353 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1354
1355 dw += 2;
1356 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1357 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1358 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1359
1360 dw += 2;
1361 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1362 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1363 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1364
1365 /*
1366 *
1367 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1368 *
1369 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1370 * in the ring after this instruction
1371 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1372 */
1373 cmd_wa_gen7_post_command_cs_stall(cmd);
1374}
1375
Chia-I Wu525c6602014-08-27 10:22:34 +08001376void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1377{
Mike Stroyan552fda42015-01-30 17:21:08 -07001378 if (pipe_control_dw0 == 0)
1379 return;
1380
Chia-I Wu525c6602014-08-27 10:22:34 +08001381 if (!cmd->bind.draw_count)
1382 return;
1383
1384 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1385
Chia-I Wu8370b402014-08-29 12:28:37 +08001386 /*
1387 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1388 *
1389 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1390 * PIPE_CONTROL with any non-zero post-sync-op is required."
1391 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001392 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001393 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001394
Chia-I Wu092279a2014-08-30 19:05:30 +08001395 /*
1396 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1397 *
1398 * "One of the following must also be set (when CS stall is set):
1399 *
1400 * * Render Target Cache Flush Enable ([12] of DW1)
1401 * * Depth Cache Flush Enable ([0] of DW1)
1402 * * Stall at Pixel Scoreboard ([1] of DW1)
1403 * * Depth Stall ([13] of DW1)
1404 * * Post-Sync Operation ([13] of DW1)"
1405 */
1406 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1407 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1408 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1409 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1410 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1411 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1412
Chia-I Wud6d079d2014-08-31 13:14:21 +08001413 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001414}
1415
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001416void cmd_batch_flush_all(struct intel_cmd *cmd)
1417{
1418 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1419 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1420 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1421 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1422 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1423 GEN6_PIPE_CONTROL_CS_STALL);
1424}
1425
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001426void cmd_batch_depth_count(struct intel_cmd *cmd,
1427 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001428 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001429{
1430 cmd_wa_gen6_pre_depth_stall_write(cmd);
1431
1432 gen6_PIPE_CONTROL(cmd,
1433 GEN6_PIPE_CONTROL_DEPTH_STALL |
1434 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001435 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001436}
1437
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001438void cmd_batch_timestamp(struct intel_cmd *cmd,
1439 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001440 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001441{
1442 /* need any WA or stall? */
1443 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1444}
1445
1446void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001447 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001448 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001449 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001450 uint64_t val)
1451{
1452 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001453 gen6_PIPE_CONTROL(cmd,
1454 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1455 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001456}
1457
Chia-I Wu302742d2014-08-22 10:28:29 +08001458static void gen6_cc_states(struct intel_cmd *cmd)
1459{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001460 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1461 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001462 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001463 uint32_t stencil_ref;
1464 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001465
1466 CMD_ASSERT(cmd, 6, 6);
1467
Chia-I Wua6c4f152014-12-02 04:19:58 +08001468 blend_offset = gen6_BLEND_STATE(cmd);
1469
1470 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001471 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001472 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001473 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001474
1475 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001476 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001477 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1478 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001479 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001480 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001481 stencil_ref = 0;
1482 }
1483
Chia-I Wu72292b72014-09-09 10:48:33 +08001484 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001485
Chia-I Wu72292b72014-09-09 10:48:33 +08001486 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001487}
1488
Chia-I Wu1744cca2014-08-22 11:10:17 +08001489static void gen6_viewport_states(struct intel_cmd *cmd)
1490{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001491 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001492 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001493
1494 if (!viewport)
1495 return;
1496
Tony Barbourfa6cac72015-01-16 14:27:35 -07001497 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001498 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001499
1500 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001501 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001502 viewport->cmd);
1503
1504 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001505 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001506 &viewport->cmd[viewport->cmd_clip_pos]);
1507
1508 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001509 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001510 &viewport->cmd[viewport->cmd_cc_pos]);
1511
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001512 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1513 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1514 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001515
1516 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001517 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001518
Chia-I Wub1d450a2014-09-09 13:48:03 +08001519 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001520}
1521
Chia-I Wu302742d2014-08-22 10:28:29 +08001522static void gen7_cc_states(struct intel_cmd *cmd)
1523{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001524 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1525 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001526 uint32_t stencil_ref;
1527 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001528 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001529
1530 CMD_ASSERT(cmd, 7, 7.5);
1531
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001532 if (!blend && !ds)
1533 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001534
Chia-I Wua6c4f152014-12-02 04:19:58 +08001535 offset = gen6_BLEND_STATE(cmd);
1536 gen7_3dstate_pointer(cmd,
1537 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001538
Chia-I Wua6c4f152014-12-02 04:19:58 +08001539 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001540 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001541 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001542 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001543
1544 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001546 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1547 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001548 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001549 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1550 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001551 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1552 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001553 } else {
1554 stencil_ref = 0;
1555 }
1556
Chia-I Wu72292b72014-09-09 10:48:33 +08001557 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001558 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001559 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001560}
1561
Chia-I Wu1744cca2014-08-22 11:10:17 +08001562static void gen7_viewport_states(struct intel_cmd *cmd)
1563{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001564 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001565 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001566
1567 if (!viewport)
1568 return;
1569
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001570 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001571
Chia-I Wub1d450a2014-09-09 13:48:03 +08001572 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001573 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001574 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001575 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001576 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1577 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001578
1579 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001580 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001581 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001582 gen7_3dstate_pointer(cmd,
1583 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001584 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001585
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001586 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1587 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1588 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1589 gen7_3dstate_pointer(cmd,
1590 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1591 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001592}
1593
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001594static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001595 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001596{
1597 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001598 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001599
Chia-I Wu72292b72014-09-09 10:48:33 +08001600 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001601
1602 dw[0] = GEN6_RENDER_TYPE_RENDER |
1603 GEN6_RENDER_SUBTYPE_3D |
1604 subop | (cmd_len - 2);
1605 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001606 dw[2] = 0;
1607 dw[3] = 0;
1608 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001609}
1610
1611static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001612 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001613{
1614 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001615 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001616
Chia-I Wu72292b72014-09-09 10:48:33 +08001617 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001618
1619 dw[0] = GEN6_RENDER_TYPE_RENDER |
1620 GEN6_RENDER_SUBTYPE_3D |
1621 subop | (cmd_len - 2);
1622 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001623 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001624 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001625 dw[4] = 0;
1626 dw[5] = 0;
1627 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001628}
1629
Chia-I Wu625105f2014-10-13 15:35:29 +08001630static uint32_t emit_samplers(struct intel_cmd *cmd,
1631 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001632{
Chia-I Wu862c5572015-03-28 15:23:55 +08001633 const struct intel_desc_region *region = cmd->dev->desc_region;
1634 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001635 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1636 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001637 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001638 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001639 uint32_t surface_count;
1640 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001641
1642 CMD_ASSERT(cmd, 6, 7.5);
1643
Chia-I Wu625105f2014-10-13 15:35:29 +08001644 if (!rmap || !rmap->sampler_count)
1645 return 0;
1646
Cody Northrop40316a32014-12-09 19:08:33 -07001647 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001648
Chia-I Wudcb509d2014-12-10 08:53:10 +08001649 /*
1650 * note that we cannot call cmd_state_pointer() here as the following
1651 * cmd_state_pointer() would invalidate the pointer
1652 */
1653 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001654 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001655 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001656
1657 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001658 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001659 4 * rmap->sampler_count, &sampler_dw);
1660
Chia-I Wudcb509d2014-12-10 08:53:10 +08001661 cmd_state_update(cmd, border_offset,
1662 border_stride * rmap->sampler_count, &border_dw);
1663
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001664 for (i = 0; i < rmap->sampler_count; i++) {
1665 const struct intel_pipeline_rmap_slot *slot =
1666 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001667 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001668 const struct intel_sampler *sampler;
1669
Chia-I Wuf8385062015-01-04 16:27:24 +08001670 switch (slot->type) {
1671 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001672 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1673 &data->set_offsets[slot->index]);
1674 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001675 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001676 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001677 sampler = NULL;
1678 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001679 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001680 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001681 sampler = NULL;
1682 break;
1683 }
1684
1685 if (sampler) {
1686 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1687
1688 sampler_dw[0] = sampler->cmd[0];
1689 sampler_dw[1] = sampler->cmd[1];
1690 sampler_dw[2] = border_offset;
1691 sampler_dw[3] = sampler->cmd[2];
1692 } else {
1693 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1694 sampler_dw[1] = 0;
1695 sampler_dw[2] = 0;
1696 sampler_dw[3] = 0;
1697 }
1698
1699 border_offset += border_stride * 4;
1700 border_dw += border_stride;
1701 sampler_dw += 4;
1702 }
1703
Chia-I Wu625105f2014-10-13 15:35:29 +08001704 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001705}
1706
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001707static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001708 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001709 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001710{
Chia-I Wu862c5572015-03-28 15:23:55 +08001711 const struct intel_desc_region *region = cmd->dev->desc_region;
1712 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001713 const uint32_t sba_offset =
1714 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001715 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001716 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001717
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001718 CMD_ASSERT(cmd, 6, 7.5);
1719
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001720 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001721 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001722 if (!surface_count)
1723 return 0;
1724
Chia-I Wu42a56202014-08-23 16:47:48 +08001725 assert(surface_count <= ARRAY_SIZE(binding_table));
1726
1727 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001728 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001729 struct intel_null_view null_view;
1730 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001731
Chia-I Wuf8385062015-01-04 16:27:24 +08001732 switch (slot->type) {
1733 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001734 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001735 const struct intel_rt_view *view =
Chia-I Wu7732cb22015-03-26 15:27:55 +08001736 (slot->index < cmd->bind.fb->rt_count) ?
1737 cmd->bind.fb->rt[slot->index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001738
Chia-I Wu787a05b2014-12-05 11:02:20 +08001739 if (view) {
1740 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1741 GEN6_ALIGNMENT_SURFACE_STATE,
1742 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001743
Chia-I Wu787a05b2014-12-05 11:02:20 +08001744 cmd_reserve_reloc(cmd, 1);
1745 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1746 view->cmd[1], INTEL_RELOC_WRITE);
1747 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001748 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001749 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001750 }
1751 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001752 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001753 {
Tony Barbour22a30862015-04-22 09:02:32 -06001754 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001755 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001756 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001757 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001758 const struct intel_mem *mem;
1759 bool read_only;
1760 const uint32_t *cmd_data;
1761 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001762
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001763 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001764 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001765
Chia-I Wu862c5572015-03-28 15:23:55 +08001766 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1767 &data->set_offsets[slot->index]);
1768
1769 intel_desc_region_read_surface(region, &desc_offset, stage,
1770 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001771 if (mem) {
1772 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001773 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001774 const uint32_t reloc_flags =
1775 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001776
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001777 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001778 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001779 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001780
1781 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001782 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1783 cmd_data[1] + dynamic_offset, reloc_flags);
1784 } else {
1785 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001786 }
1787 }
1788 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001789 case INTEL_PIPELINE_RMAP_UNUSED:
1790 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001791 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001792 default:
1793 assert(!"unexpected rmap type");
1794 need_null_view = true;
1795 break;
1796 }
1797
1798 if (need_null_view) {
1799 intel_null_view_init(&null_view, cmd->dev);
1800 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1801 GEN6_ALIGNMENT_SURFACE_STATE,
1802 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001803 }
1804
Chia-I Wuf98dd882015-02-10 04:17:47 +08001805 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001806 }
1807
Chia-I Wuf98dd882015-02-10 04:17:47 +08001808 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001809 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001810 surface_count, binding_table) - sba_offset;
1811
1812 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1813 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1814
1815 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001816}
1817
Chia-I Wu1d125092014-10-08 08:49:38 +08001818static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1819{
1820 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001821 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1822 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001823 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001824
1825 CMD_ASSERT(cmd, 6, 7.5);
1826
1827 if (!pipeline->vb_count)
1828 return;
1829
1830 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1831
1832 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1833 dw++;
1834 pos++;
1835
1836 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001837 assert(pipeline->vb[i].strideInBytes <= 2048);
1838
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001839 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001840 pipeline->vb[i].strideInBytes;
1841
Chia-I Wub3686982015-02-27 09:51:16 -07001842 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001843 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1844 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001845 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001846
1847 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001848 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001849 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001850 dw[3] = 0;
1851 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001852 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001853 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001854 dw[3] = 1;
1855 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001856 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001857 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001858 dw[3] = 0;
1859 break;
1860 default:
1861 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001862 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001863 dw[3] = 0;
1864 break;
1865 }
1866
Chia-I Wu714df452015-01-01 07:55:04 +08001867 if (cmd->bind.vertex.buf[i]) {
1868 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001869 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001870
1871 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001872 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1873 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001874 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001875 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001876 dw[1] = 0;
1877 dw[2] = 0;
1878 }
1879
1880 dw += 4;
1881 pos += 4;
1882 }
1883}
1884
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001885static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1886{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001887 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1888 const struct intel_pipeline_shader *vs = &pipeline->vs;
1889 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001890 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001891 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001892 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001893 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001894
1895 CMD_ASSERT(cmd, 6, 7.5);
1896
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001897 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001898 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1899 *
1900 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1901 * 128-bit vertex elements to be passed into the payload for each
1902 * vertex."
1903 *
1904 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1905 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001906 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001907 vue_read_len = (vs->in_count + 1) / 2;
1908 if (!vue_read_len)
1909 vue_read_len = 1;
1910
1911 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1912 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1913
1914 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1915 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1916 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001917
1918 dw5 = GEN6_VS_DW5_STATISTICS |
1919 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001920
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001921 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001922 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001923 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001924 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001925
Chia-I Wube0a3d92014-09-02 13:20:59 +08001926 if (pipeline->disable_vs_cache)
1927 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1928
Chia-I Wu784d3042014-12-19 14:30:04 +08001929 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001930 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001931 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001932 dw[2] = dw2;
1933 dw[3] = 0; /* scratch */
1934 dw[4] = dw4;
1935 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001936
1937 if (vs->per_thread_scratch_size)
1938 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001939}
1940
Chia-I Wu625105f2014-10-13 15:35:29 +08001941static void emit_shader_resources(struct intel_cmd *cmd)
1942{
1943 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001944 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001945
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001946 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001947 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001948 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001949 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001950 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001951 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001952 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001953 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001954 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001955 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001956 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001957 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001958 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001959 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001960 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001961
1962 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1963 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1964 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1965 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1966 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1967
1968 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1969 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001970 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1971 binding_tables[0]);
1972 gen7_3dstate_pointer(cmd,
1973 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1974 binding_tables[1]);
1975 gen7_3dstate_pointer(cmd,
1976 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1977 binding_tables[2]);
1978 gen7_3dstate_pointer(cmd,
1979 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1980 binding_tables[3]);
1981 gen7_3dstate_pointer(cmd,
1982 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1983 binding_tables[4]);
1984
1985 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001986 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1987 samplers[0]);
1988 gen7_3dstate_pointer(cmd,
1989 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1990 samplers[1]);
1991 gen7_3dstate_pointer(cmd,
1992 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1993 samplers[2]);
1994 gen7_3dstate_pointer(cmd,
1995 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1996 samplers[3]);
1997 gen7_3dstate_pointer(cmd,
1998 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1999 samplers[4]);
2000 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002001 assert(!binding_tables[1] && !binding_tables[2]);
2002 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2003 binding_tables[0], binding_tables[3], binding_tables[4]);
2004
Chia-I Wu625105f2014-10-13 15:35:29 +08002005 assert(!samplers[1] && !samplers[2]);
2006 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2007 samplers[0], samplers[3], samplers[4]);
2008 }
2009}
2010
Chia-I Wu8ada4242015-03-02 11:19:33 -07002011static void emit_msaa(struct intel_cmd *cmd)
2012{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002013 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002014
Chia-I Wubbc7d912015-02-27 14:59:50 -07002015 if (!cmd->bind.render_pass_changed)
2016 return;
2017
Chia-I Wu8ada4242015-03-02 11:19:33 -07002018 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002019 cmd->result = VK_ERROR_UNKNOWN;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002020
2021 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2022 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
2023}
2024
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002025static void emit_rt(struct intel_cmd *cmd)
2026{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002027 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002028
2029 if (!cmd->bind.render_pass_changed)
2030 return;
2031
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002032 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002033 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2034 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002035}
2036
2037static void emit_ds(struct intel_cmd *cmd)
2038{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002039 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002040 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002041
Chia-I Wubbc7d912015-02-27 14:59:50 -07002042 if (!cmd->bind.render_pass_changed)
2043 return;
2044
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002045 if (!ds) {
2046 /* all zeros */
2047 static const struct intel_ds_view null_ds;
2048 ds = &null_ds;
2049 }
2050
2051 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07002052 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
2053 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
2054 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002055
2056 if (cmd_gen(cmd) >= INTEL_GEN(7))
2057 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2058 else
2059 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2060}
2061
Chia-I Wua57761b2014-10-14 14:27:44 +08002062static uint32_t emit_shader(struct intel_cmd *cmd,
2063 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002064{
Chia-I Wua57761b2014-10-14 14:27:44 +08002065 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2066 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002067 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002068
Chia-I Wua57761b2014-10-14 14:27:44 +08002069 /* see if the shader is already in the cache */
2070 for (i = 0; i < cache->used; i++) {
2071 if (cache->entries[i].shader == (const void *) shader)
2072 return cache->entries[i].kernel_offset;
2073 }
2074
2075 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2076
2077 /* grow the cache if full */
2078 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002079 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002080 void *entries;
2081
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002082 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002083 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002084 if (entries) {
2085 if (cache->entries) {
2086 memcpy(entries, cache->entries,
2087 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002088 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002089 }
2090
2091 cache->entries = entries;
2092 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002093 }
2094 }
2095
Chia-I Wua57761b2014-10-14 14:27:44 +08002096 /* add the shader to the cache */
2097 if (cache->used < cache->count) {
2098 cache->entries[cache->used].shader = (const void *) shader;
2099 cache->entries[cache->used].kernel_offset = offset;
2100 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002101 }
2102
Chia-I Wua57761b2014-10-14 14:27:44 +08002103 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002104}
2105
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002106static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002107{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002108 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002109
Chia-I Wu8370b402014-08-29 12:28:37 +08002110 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2111 cmd_wa_gen6_pre_depth_stall_write(cmd);
2112 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2113 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2114 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2115 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002116
2117 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002118 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002119 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002120
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002121 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002122 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002123 }
2124 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002125 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002126 }
2127 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002128 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2129 }
2130 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2131 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2132 }
2133 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2134 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002135 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002136
Chia-I Wu8370b402014-08-29 12:28:37 +08002137 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2138 cmd_wa_gen7_post_command_cs_stall(cmd);
2139 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2140 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002141}
2142
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002143static void emit_bounded_states(struct intel_cmd *cmd)
2144{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002145 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002146
2147 emit_graphics_pipeline(cmd);
2148
2149 emit_rt(cmd);
2150 emit_ds(cmd);
2151
2152 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2153 gen7_cc_states(cmd);
2154 gen7_viewport_states(cmd);
2155
2156 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2157 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002158 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2159 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002160 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2161 &cmd->bind.pipeline.graphics->fs);
2162
Cody Northrop293d4502015-05-05 09:38:03 -06002163 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002164 gen6_3DSTATE_CLIP(cmd);
2165 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002166 gen7_3DSTATE_WM(cmd);
2167 gen7_3DSTATE_PS(cmd);
2168 } else {
2169 gen6_cc_states(cmd);
2170 gen6_viewport_states(cmd);
2171
2172 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2173 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002174 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2175 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002176 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2177 &cmd->bind.pipeline.graphics->fs);
2178
Cody Northrop293d4502015-05-05 09:38:03 -06002179 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002180 gen6_3DSTATE_CLIP(cmd);
2181 gen6_3DSTATE_SF(cmd);
2182 gen6_3DSTATE_WM(cmd);
2183 }
2184
2185 emit_shader_resources(cmd);
2186
2187 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002188
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002189 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2190 gen6_3DSTATE_VS(cmd);
2191}
2192
Tony Barbourfa6cac72015-01-16 14:27:35 -07002193static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002194 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002195{
2196 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2197 const uint8_t cmd_len = 3;
2198 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002199
2200 CMD_ASSERT(cmd, 6, 7.5);
2201
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002202 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002203 dw[0] = 0;
2204 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002205
2206 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2207 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2208 GEN6_COMPAREFUNCTION_NEVER << 27 |
2209 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2210 } else {
2211 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2212 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2213 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002214 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002215 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002216 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2217 (GEN6_STENCILOP_KEEP) << 25 |
2218 (GEN6_STENCILOP_KEEP) << 22 |
2219 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002220 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2221 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002222 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2223 (GEN6_STENCILOP_KEEP) << 9 |
2224 (GEN6_STENCILOP_KEEP) << 6 |
2225 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002226
Chia-I Wud850a392015-02-19 11:08:25 -07002227 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2228 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2229 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2230 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2231 dw[2] = 0;
2232 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002233
2234 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2235 cmd_align, cmd_len, dw);
2236}
2237
Chia-I Wu6032b892014-10-17 14:47:18 +08002238static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2239{
2240 const struct intel_cmd_meta *meta = cmd->bind.meta;
2241 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2242
2243 CMD_ASSERT(cmd, 6, 7.5);
2244
2245 blend_offset = 0;
2246 ds_offset = 0;
2247 cc_offset = 0;
2248 cc_vp_offset = 0;
2249
Chia-I Wu29e6f502014-11-24 14:27:29 +08002250 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002251 /* BLEND_STATE */
2252 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002253 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002254 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002255 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002256 }
2257
Chia-I Wu29e6f502014-11-24 14:27:29 +08002258 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002259 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002260 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002261 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2262 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002263
Chia-I Wu29e6f502014-11-24 14:27:29 +08002264 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002265 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002266
Chia-I Wu29e6f502014-11-24 14:27:29 +08002267 /* COLOR_CALC_STATE */
2268 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002269 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002270
Chia-I Wu29e6f502014-11-24 14:27:29 +08002271 /* CC_VIEWPORT */
2272 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002273 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002274 dw[0] = u_fui(0.0f);
2275 dw[1] = u_fui(1.0f);
2276 } else {
2277 /* DEPTH_STENCIL_STATE */
2278 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002279 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002280 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2281 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2282 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002283 }
2284
2285 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2286 gen7_3dstate_pointer(cmd,
2287 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2288 blend_offset);
2289 gen7_3dstate_pointer(cmd,
2290 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2291 ds_offset);
2292 gen7_3dstate_pointer(cmd,
2293 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2294
2295 gen7_3dstate_pointer(cmd,
2296 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2297 cc_vp_offset);
2298 } else {
2299 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002300 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002301
2302 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2303 cmd_batch_pointer(cmd, 4, &dw);
2304 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002305 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002306 dw[1] = 0;
2307 dw[2] = 0;
2308 dw[3] = cc_vp_offset;
2309 }
2310}
2311
2312static void gen6_meta_surface_states(struct intel_cmd *cmd)
2313{
2314 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002315 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002316 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002317 const uint32_t sba_offset =
2318 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002319
2320 CMD_ASSERT(cmd, 6, 7.5);
2321
Chia-I Wu29e6f502014-11-24 14:27:29 +08002322 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2323 return;
2324
Chia-I Wu005c47c2014-10-22 13:49:13 +08002325 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002326 if (meta->src.valid) {
2327 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002328 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002329 meta->src.surface_len, meta->src.surface);
2330
2331 cmd_reserve_reloc(cmd, 1);
2332 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2333 cmd_surface_reloc_writer(cmd, offset, 1,
2334 meta->src.reloc_target, meta->src.reloc_offset);
2335 } else {
2336 cmd_surface_reloc(cmd, offset, 1,
2337 (struct intel_bo *) meta->src.reloc_target,
2338 meta->src.reloc_offset, meta->src.reloc_flags);
2339 }
2340
Mike Stroyan9bfad482015-02-10 15:09:23 -07002341 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002342 }
2343 if (meta->dst.valid) {
2344 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002345 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002346 meta->dst.surface_len, meta->dst.surface);
2347
2348 cmd_reserve_reloc(cmd, 1);
2349 cmd_surface_reloc(cmd, offset, 1,
2350 (struct intel_bo *) meta->dst.reloc_target,
2351 meta->dst.reloc_offset, meta->dst.reloc_flags);
2352
Mike Stroyan9bfad482015-02-10 15:09:23 -07002353 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002354 }
2355
2356 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002357 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002358 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002359 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002360
2361 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002362 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2363 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2364 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002365 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002366 } else {
2367 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002368 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002369 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002370 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002371 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002372 }
2373}
2374
2375static void gen6_meta_urb(struct intel_cmd *cmd)
2376{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002377 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002378 uint32_t *dw;
2379
2380 CMD_ASSERT(cmd, 6, 6);
2381
2382 /* 3DSTATE_URB */
2383 cmd_batch_pointer(cmd, 3, &dw);
2384 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002385 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002386 dw[2] = 0;
2387}
2388
2389static void gen7_meta_urb(struct intel_cmd *cmd)
2390{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002391 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2392 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002393 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002394 uint32_t *dw;
2395
2396 CMD_ASSERT(cmd, 7, 7.5);
2397
Chia-I Wu6032b892014-10-17 14:47:18 +08002398 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2399
Chia-I Wu24aa1022014-11-25 11:53:19 +08002400 switch (cmd_gen(cmd)) {
2401 case INTEL_GEN(7.5):
2402 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2403 break;
2404 case INTEL_GEN(7):
2405 default:
2406 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2407 break;
2408 }
2409
Chia-I Wu6032b892014-10-17 14:47:18 +08002410 /* 3DSTATE_URB_x */
2411 cmd_batch_pointer(cmd, 8, &dw);
2412
2413 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002414 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002415 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002416 dw += 2;
2417
2418 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002419 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002420 dw += 2;
2421
2422 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002423 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002424 dw += 2;
2425
2426 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002427 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002428 dw += 2;
2429}
2430
2431static void gen6_meta_vf(struct intel_cmd *cmd)
2432{
2433 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002434 uint32_t vb_start, vb_end, vb_stride;
2435 int ve_format, ve_z_source;
2436 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002437 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002438
2439 CMD_ASSERT(cmd, 6, 7.5);
2440
Chia-I Wu29e6f502014-11-24 14:27:29 +08002441 switch (meta->mode) {
2442 case INTEL_CMD_META_VS_POINTS:
2443 cmd_batch_pointer(cmd, 3, &dw);
2444 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002445 dw[1] = GEN6_VE_DW0_VALID;
2446 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2447 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2448 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2449 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002450 return;
2451 break;
2452 case INTEL_CMD_META_FS_RECT:
2453 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002454 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002455
Chia-I Wu29e6f502014-11-24 14:27:29 +08002456 vertices[0][0] = meta->dst.x + meta->width;
2457 vertices[0][1] = meta->dst.y + meta->height;
2458 vertices[1][0] = meta->dst.x;
2459 vertices[1][1] = meta->dst.y + meta->height;
2460 vertices[2][0] = meta->dst.x;
2461 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002462
Chia-I Wu29e6f502014-11-24 14:27:29 +08002463 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2464 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002465
Chia-I Wu29e6f502014-11-24 14:27:29 +08002466 vb_end = vb_start + sizeof(vertices) - 1;
2467 vb_stride = sizeof(vertices[0]);
2468 ve_z_source = GEN6_VFCOMP_STORE_0;
2469 ve_format = GEN6_FORMAT_R32G32_USCALED;
2470 }
2471 break;
2472 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2473 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002474 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002475
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002476 vertices[0][0] = (float) (meta->dst.x + meta->width);
2477 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002478 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002479 vertices[1][0] = (float) meta->dst.x;
2480 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002481 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002482 vertices[2][0] = (float) meta->dst.x;
2483 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002484 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002485
Chia-I Wu29e6f502014-11-24 14:27:29 +08002486 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2487 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002488
Chia-I Wu29e6f502014-11-24 14:27:29 +08002489 vb_end = vb_start + sizeof(vertices) - 1;
2490 vb_stride = sizeof(vertices[0]);
2491 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2492 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2493 }
2494 break;
2495 default:
2496 assert(!"unknown meta mode");
2497 return;
2498 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002499 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002500
2501 /* 3DSTATE_VERTEX_BUFFERS */
2502 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002503
Chia-I Wu6032b892014-10-17 14:47:18 +08002504 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002505 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002506 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002507 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002508
2509 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002510 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2511 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002512
2513 dw[4] = 0;
2514
2515 /* 3DSTATE_VERTEX_ELEMENTS */
2516 cmd_batch_pointer(cmd, 5, &dw);
2517 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002518 dw[1] = GEN6_VE_DW0_VALID;
2519 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2520 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2521 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2522 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2523 dw[3] = GEN6_VE_DW0_VALID |
2524 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2525 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2526 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2527 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2528 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002529}
2530
Chia-I Wu29e6f502014-11-24 14:27:29 +08002531static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002532{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002533 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002534 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002535 uint32_t consts[8];
2536 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002537
2538 CMD_ASSERT(cmd, 6, 7.5);
2539
2540 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002541 case INTEL_DEV_META_VS_FILL_MEM:
2542 consts[0] = meta->dst.x;
2543 consts[1] = meta->clear_val[0];
2544 const_count = 2;
2545 break;
2546 case INTEL_DEV_META_VS_COPY_MEM:
2547 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2548 consts[0] = meta->dst.x;
2549 consts[1] = meta->src.x;
2550 const_count = 2;
2551 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002552 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2553 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2554 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2555 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2556 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2557 consts[0] = meta->src.x;
2558 consts[1] = meta->src.y;
2559 consts[2] = meta->width;
2560 consts[3] = meta->dst.x;
2561 const_count = 4;
2562 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002563 default:
2564 assert(!"unknown meta shader id");
2565 const_count = 0;
2566 break;
2567 }
2568
2569 /* this can be skipped but it makes state dumping prettier */
2570 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2571
2572 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2573}
2574
2575static void gen6_meta_vs(struct intel_cmd *cmd)
2576{
2577 const struct intel_cmd_meta *meta = cmd->bind.meta;
2578 const struct intel_pipeline_shader *sh =
2579 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2580 uint32_t offset, *dw;
2581
2582 CMD_ASSERT(cmd, 6, 7.5);
2583
2584 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002585 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002586
2587 /* 3DSTATE_CONSTANT_VS */
2588 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2589 cmd_batch_pointer(cmd, cmd_len, &dw);
2590 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2591 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2592
2593 /* 3DSTATE_VS */
2594 cmd_batch_pointer(cmd, 6, &dw);
2595 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2596 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2597
2598 return;
2599 }
2600
2601 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2602
2603 /* 3DSTATE_CONSTANT_VS */
2604 offset = gen6_meta_vs_constants(cmd);
2605 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2606 cmd_batch_pointer(cmd, 7, &dw);
2607 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002608 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002609 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002610 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002611 dw[4] = 0;
2612 dw[5] = 0;
2613 dw[6] = 0;
2614 } else {
2615 cmd_batch_pointer(cmd, 5, &dw);
2616 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002617 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002618 dw[1] = offset;
2619 dw[2] = 0;
2620 dw[3] = 0;
2621 dw[4] = 0;
2622 }
2623
2624 /* 3DSTATE_VS */
2625 offset = emit_shader(cmd, sh);
2626 cmd_batch_pointer(cmd, 6, &dw);
2627 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2628 dw[1] = offset;
2629 dw[2] = GEN6_THREADDISP_SPF |
2630 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2631 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002632 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002633 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2634 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2635
2636 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2637 GEN6_VS_DW5_VS_ENABLE;
2638 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002639 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002640 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002641 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002642
2643 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002644}
2645
2646static void gen6_meta_disabled(struct intel_cmd *cmd)
2647{
Chia-I Wu6032b892014-10-17 14:47:18 +08002648 uint32_t *dw;
2649
2650 CMD_ASSERT(cmd, 6, 6);
2651
Chia-I Wu6032b892014-10-17 14:47:18 +08002652 /* 3DSTATE_CONSTANT_GS */
2653 cmd_batch_pointer(cmd, 5, &dw);
2654 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2655 dw[1] = 0;
2656 dw[2] = 0;
2657 dw[3] = 0;
2658 dw[4] = 0;
2659
2660 /* 3DSTATE_GS */
2661 cmd_batch_pointer(cmd, 7, &dw);
2662 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2663 dw[1] = 0;
2664 dw[2] = 0;
2665 dw[3] = 0;
2666 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2667 dw[5] = GEN6_GS_DW5_STATISTICS;
2668 dw[6] = 0;
2669
Chia-I Wu6032b892014-10-17 14:47:18 +08002670 /* 3DSTATE_SF */
2671 cmd_batch_pointer(cmd, 20, &dw);
2672 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2673 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2674 memset(&dw[2], 0, 18 * sizeof(*dw));
2675}
2676
2677static void gen7_meta_disabled(struct intel_cmd *cmd)
2678{
2679 uint32_t *dw;
2680
2681 CMD_ASSERT(cmd, 7, 7.5);
2682
Chia-I Wu6032b892014-10-17 14:47:18 +08002683 /* 3DSTATE_CONSTANT_HS */
2684 cmd_batch_pointer(cmd, 7, &dw);
2685 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2686 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2687
2688 /* 3DSTATE_HS */
2689 cmd_batch_pointer(cmd, 7, &dw);
2690 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2691 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2692
2693 /* 3DSTATE_TE */
2694 cmd_batch_pointer(cmd, 4, &dw);
2695 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2696 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2697
2698 /* 3DSTATE_CONSTANT_DS */
2699 cmd_batch_pointer(cmd, 7, &dw);
2700 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2701 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2702
2703 /* 3DSTATE_DS */
2704 cmd_batch_pointer(cmd, 6, &dw);
2705 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2706 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2707
2708 /* 3DSTATE_CONSTANT_GS */
2709 cmd_batch_pointer(cmd, 7, &dw);
2710 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2711 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2712
2713 /* 3DSTATE_GS */
2714 cmd_batch_pointer(cmd, 7, &dw);
2715 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2716 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2717
2718 /* 3DSTATE_STREAMOUT */
2719 cmd_batch_pointer(cmd, 3, &dw);
2720 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2721 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2722
Chia-I Wu6032b892014-10-17 14:47:18 +08002723 /* 3DSTATE_SF */
2724 cmd_batch_pointer(cmd, 7, &dw);
2725 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2726 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2727
2728 /* 3DSTATE_SBE */
2729 cmd_batch_pointer(cmd, 14, &dw);
2730 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2731 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2732 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002733}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002734
Chia-I Wu29e6f502014-11-24 14:27:29 +08002735static void gen6_meta_clip(struct intel_cmd *cmd)
2736{
2737 const struct intel_cmd_meta *meta = cmd->bind.meta;
2738 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002739
Chia-I Wu29e6f502014-11-24 14:27:29 +08002740 /* 3DSTATE_CLIP */
2741 cmd_batch_pointer(cmd, 4, &dw);
2742 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2743 dw[1] = 0;
2744 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2745 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2746 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2747 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002748 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002749 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002750 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002751}
2752
2753static void gen6_meta_wm(struct intel_cmd *cmd)
2754{
2755 const struct intel_cmd_meta *meta = cmd->bind.meta;
2756 uint32_t *dw;
2757
2758 CMD_ASSERT(cmd, 6, 7.5);
2759
2760 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2761
2762 /* 3DSTATE_MULTISAMPLE */
2763 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2764 cmd_batch_pointer(cmd, 4, &dw);
2765 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2766 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2767 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2768 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2769 dw[2] = 0;
2770 dw[3] = 0;
2771 } else {
2772 cmd_batch_pointer(cmd, 3, &dw);
2773 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2774 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2775 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2776 dw[2] = 0;
2777 }
2778
2779 /* 3DSTATE_SAMPLE_MASK */
2780 cmd_batch_pointer(cmd, 2, &dw);
2781 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2782 dw[1] = (1 << meta->samples) - 1;
2783
2784 /* 3DSTATE_DRAWING_RECTANGLE */
2785 cmd_batch_pointer(cmd, 4, &dw);
2786 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002787 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2788 /* unused */
2789 dw[1] = 0;
2790 dw[2] = 0;
2791 } else {
2792 dw[1] = meta->dst.y << 16 | meta->dst.x;
2793 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2794 (meta->dst.x + meta->width - 1);
2795 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002796 dw[3] = 0;
2797}
2798
2799static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2800{
2801 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002802 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002803 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002804 uint32_t consts[8];
2805 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002806
2807 CMD_ASSERT(cmd, 6, 7.5);
2808
2809 /* underflow is fine here */
2810 offset_x = meta->src.x - meta->dst.x;
2811 offset_y = meta->src.y - meta->dst.y;
2812
2813 switch (meta->shader_id) {
2814 case INTEL_DEV_META_FS_COPY_MEM:
2815 case INTEL_DEV_META_FS_COPY_1D:
2816 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2817 case INTEL_DEV_META_FS_COPY_2D:
2818 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2819 case INTEL_DEV_META_FS_COPY_2D_MS:
2820 consts[0] = offset_x;
2821 consts[1] = offset_y;
2822 consts[2] = meta->src.layer;
2823 consts[3] = meta->src.lod;
2824 const_count = 4;
2825 break;
2826 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2827 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2828 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2829 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2830 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2831 consts[0] = offset_x;
2832 consts[1] = offset_y;
2833 consts[2] = meta->src.layer;
2834 consts[3] = meta->src.lod;
2835 consts[4] = meta->src.x;
2836 consts[5] = meta->width;
2837 const_count = 6;
2838 break;
2839 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2840 consts[0] = offset_x;
2841 consts[1] = offset_y;
2842 consts[2] = meta->width;
2843 const_count = 3;
2844 break;
2845 case INTEL_DEV_META_FS_CLEAR_COLOR:
2846 consts[0] = meta->clear_val[0];
2847 consts[1] = meta->clear_val[1];
2848 consts[2] = meta->clear_val[2];
2849 consts[3] = meta->clear_val[3];
2850 const_count = 4;
2851 break;
2852 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2853 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002854 consts[1] = meta->clear_val[1];
2855 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002856 break;
2857 case INTEL_DEV_META_FS_RESOLVE_2X:
2858 case INTEL_DEV_META_FS_RESOLVE_4X:
2859 case INTEL_DEV_META_FS_RESOLVE_8X:
2860 case INTEL_DEV_META_FS_RESOLVE_16X:
2861 consts[0] = offset_x;
2862 consts[1] = offset_y;
2863 const_count = 2;
2864 break;
2865 default:
2866 assert(!"unknown meta shader id");
2867 const_count = 0;
2868 break;
2869 }
2870
2871 /* this can be skipped but it makes state dumping prettier */
2872 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2873
2874 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2875}
2876
2877static void gen6_meta_ps(struct intel_cmd *cmd)
2878{
2879 const struct intel_cmd_meta *meta = cmd->bind.meta;
2880 const struct intel_pipeline_shader *sh =
2881 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2882 uint32_t offset, *dw;
2883
2884 CMD_ASSERT(cmd, 6, 6);
2885
Chia-I Wu29e6f502014-11-24 14:27:29 +08002886 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2887 /* 3DSTATE_CONSTANT_PS */
2888 cmd_batch_pointer(cmd, 5, &dw);
2889 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2890 dw[1] = 0;
2891 dw[2] = 0;
2892 dw[3] = 0;
2893 dw[4] = 0;
2894
2895 /* 3DSTATE_WM */
2896 cmd_batch_pointer(cmd, 9, &dw);
2897 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2898 dw[1] = 0;
2899 dw[2] = 0;
2900 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002901
2902 switch (meta->ds.op) {
2903 case INTEL_CMD_META_DS_HIZ_CLEAR:
2904 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2905 break;
2906 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2907 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2908 break;
2909 case INTEL_CMD_META_DS_RESOLVE:
2910 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2911 break;
2912 default:
2913 dw[4] = 0;
2914 break;
2915 }
2916
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002917 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002918 dw[6] = 0;
2919 dw[7] = 0;
2920 dw[8] = 0;
2921
Chia-I Wu3adf7212014-10-24 15:34:07 +08002922 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002923 }
2924
Chia-I Wu3adf7212014-10-24 15:34:07 +08002925 /* a normal color write */
2926 assert(meta->dst.valid && !sh->uses);
2927
Chia-I Wu6032b892014-10-17 14:47:18 +08002928 /* 3DSTATE_CONSTANT_PS */
2929 offset = gen6_meta_ps_constants(cmd);
2930 cmd_batch_pointer(cmd, 5, &dw);
2931 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002932 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002933 dw[1] = offset;
2934 dw[2] = 0;
2935 dw[3] = 0;
2936 dw[4] = 0;
2937
2938 /* 3DSTATE_WM */
2939 offset = emit_shader(cmd, sh);
2940 cmd_batch_pointer(cmd, 9, &dw);
2941 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2942 dw[1] = offset;
2943 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2944 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002945 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002946 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002947 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002948 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2949 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002950
Chia-I Wu6032b892014-10-17 14:47:18 +08002951 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002952 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002953 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2954 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2955 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2956 if (meta->samples > 1) {
2957 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2958 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2959 } else {
2960 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2961 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2962 }
2963 dw[7] = 0;
2964 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002965
2966 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002967}
2968
2969static void gen7_meta_ps(struct intel_cmd *cmd)
2970{
2971 const struct intel_cmd_meta *meta = cmd->bind.meta;
2972 const struct intel_pipeline_shader *sh =
2973 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2974 uint32_t offset, *dw;
2975
2976 CMD_ASSERT(cmd, 7, 7.5);
2977
Chia-I Wu29e6f502014-11-24 14:27:29 +08002978 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2979 /* 3DSTATE_WM */
2980 cmd_batch_pointer(cmd, 3, &dw);
2981 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002982
2983 switch (meta->ds.op) {
2984 case INTEL_CMD_META_DS_HIZ_CLEAR:
2985 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2986 break;
2987 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2988 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2989 break;
2990 case INTEL_CMD_META_DS_RESOLVE:
2991 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2992 break;
2993 default:
2994 dw[1] = 0;
2995 break;
2996 }
2997
2998 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002999
3000 /* 3DSTATE_CONSTANT_GS */
3001 cmd_batch_pointer(cmd, 7, &dw);
3002 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3003 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3004
3005 /* 3DSTATE_PS */
3006 cmd_batch_pointer(cmd, 8, &dw);
3007 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3008 dw[1] = 0;
3009 dw[2] = 0;
3010 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003011 /* required to avoid hangs */
3012 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003013 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003014 dw[5] = 0;
3015 dw[6] = 0;
3016 dw[7] = 0;
3017
Chia-I Wu3adf7212014-10-24 15:34:07 +08003018 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003019 }
3020
Chia-I Wu3adf7212014-10-24 15:34:07 +08003021 /* a normal color write */
3022 assert(meta->dst.valid && !sh->uses);
3023
Chia-I Wu6032b892014-10-17 14:47:18 +08003024 /* 3DSTATE_WM */
3025 cmd_batch_pointer(cmd, 3, &dw);
3026 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003027 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003028 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3029 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3030 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3031 dw[2] = 0;
3032
3033 /* 3DSTATE_CONSTANT_PS */
3034 offset = gen6_meta_ps_constants(cmd);
3035 cmd_batch_pointer(cmd, 7, &dw);
3036 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003037 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003038 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003039 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003040 dw[4] = 0;
3041 dw[5] = 0;
3042 dw[6] = 0;
3043
3044 /* 3DSTATE_PS */
3045 offset = emit_shader(cmd, sh);
3046 cmd_batch_pointer(cmd, 8, &dw);
3047 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3048 dw[1] = offset;
3049 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3050 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003051 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003052
3053 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3054 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003055 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003056
3057 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003058 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003059 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003060 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003061 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003062 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003063
3064 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3065 dw[6] = 0;
3066 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003067
3068 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003069}
3070
3071static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3072{
3073 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08003074 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003075
3076 CMD_ASSERT(cmd, 6, 7.5);
3077
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003078 if (!ds) {
3079 /* all zeros */
3080 static const struct intel_ds_view null_ds;
3081 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003082 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003083
3084 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003085 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3086 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3087 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003088
3089 if (cmd_gen(cmd) >= INTEL_GEN(7))
3090 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3091 else
3092 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003093}
3094
Chia-I Wu862c5572015-03-28 15:23:55 +08003095static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3096 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003097 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003098{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003099 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003100 if (data->set_offsets)
3101 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003102
Chia-I Wu862c5572015-03-28 15:23:55 +08003103 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003104 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003105 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003106 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003107 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003108 data->set_offset_count = 0;
3109 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003110 }
3111
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003112 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003113 }
3114
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003115 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003116 if (data->dynamic_offsets)
3117 intel_free(cmd, data->dynamic_offsets);
3118
3119 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003120 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003121 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003122 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003123 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003124 data->dynamic_offset_count = 0;
3125 return false;
3126 }
3127
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003128 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003129 }
3130
3131 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003132}
3133
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003134static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3135 const struct intel_pipeline *pipeline)
3136{
3137 cmd->bind.pipeline.graphics = pipeline;
3138
3139 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003140 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003141}
3142
3143static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3144 const struct intel_pipeline *pipeline)
3145{
3146 cmd->bind.pipeline.compute = pipeline;
3147
3148 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003149 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003150}
3151
Chia-I Wu862c5572015-03-28 15:23:55 +08003152static void cmd_copy_dset_data(struct intel_cmd *cmd,
3153 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003154 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003155 uint32_t index,
3156 const struct intel_desc_set *set,
3157 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003158{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003159 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003160
Chia-I Wu862c5572015-03-28 15:23:55 +08003161 assert(index < data->set_offset_count);
3162 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003163
Chia-I Wu862c5572015-03-28 15:23:55 +08003164 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003165 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003166 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003167
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003168 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003169 dynamic_offsets,
3170 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003171 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003172}
3173
Chia-I Wu3b04af52014-11-08 10:48:20 +08003174static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003175 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003176 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003177{
Chia-I Wu714df452015-01-01 07:55:04 +08003178 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003179 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003180 return;
3181 }
3182
Chia-I Wu714df452015-01-01 07:55:04 +08003183 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003184 cmd->bind.vertex.offset[binding] = offset;
3185}
3186
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003187static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003188 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003189 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003190{
Chia-I Wu714df452015-01-01 07:55:04 +08003191 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003192 cmd->bind.index.offset = offset;
3193 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003194}
3195
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003196static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003197 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003198{
3199 cmd->bind.state.viewport = state;
3200}
3201
3202static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003203 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003204{
3205 cmd->bind.state.raster = state;
3206}
3207
3208static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003209 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003210{
3211 cmd->bind.state.ds = state;
3212}
3213
3214static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003215 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003216{
3217 cmd->bind.state.blend = state;
3218}
3219
Chia-I Wuf98dd882015-02-10 04:17:47 +08003220static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3221{
3222 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3223 struct intel_pipeline_rmap *rmaps[5] = {
3224 pipeline->vs.rmap,
3225 pipeline->tcs.rmap,
3226 pipeline->tes.rmap,
3227 pipeline->gs.rmap,
3228 pipeline->fs.rmap,
3229 };
3230 uint32_t max_write;
3231 int i;
3232
3233 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3234 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3235 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3236
3237 /* pad first */
3238 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3239
3240 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3241 const struct intel_pipeline_rmap *rmap = rmaps[i];
3242 const uint32_t surface_count = (rmap) ?
3243 rmap->rt_count + rmap->texture_resource_count +
3244 rmap->resource_count + rmap->uav_count : 0;
3245
3246 if (surface_count) {
3247 /* SURFACE_STATEs */
3248 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3249
3250 /* BINDING_TABLE_STATE */
3251 max_write += u_align(sizeof(uint32_t) * surface_count,
3252 GEN6_ALIGNMENT_SURFACE_STATE);
3253 }
3254 }
3255
3256 return max_write;
3257}
3258
3259static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3260{
3261 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3262 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3263 uint32_t max_surface_write;
3264
3265 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3266 if (cmd->bind.meta)
3267 max_surface_write = 64 * sizeof(uint32_t);
3268 else
3269 max_surface_write = cmd_get_max_surface_write(cmd);
3270
3271 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3272 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3273 /* SBA expects page-aligned addresses */
3274 writer->sba_offset = writer->used & ~0xfff;
3275
3276 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3277
3278 cmd_batch_state_base_address(cmd);
3279 }
3280}
3281
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003282static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003283 uint32_t vertex_start,
3284 uint32_t vertex_count,
3285 uint32_t instance_start,
3286 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003287 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003288 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003289{
3290 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003291 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003292 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3293
3294 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003295
3296 emit_bounded_states(cmd);
3297
Chia-I Wuf98dd882015-02-10 04:17:47 +08003298 /* sanity check on cmd_get_max_surface_write() */
3299 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3300 surface_writer_used <= cmd_get_max_surface_write(cmd));
3301
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003302 if (indexed) {
3303 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003304 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003305
3306 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3307 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3308 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003309 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003310 cmd->bind.index.offset, cmd->bind.index.type,
3311 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003312 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003313 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003314 cmd->bind.index.offset, cmd->bind.index.type,
3315 p->primitive_restart);
3316 }
3317 } else {
3318 assert(!vertex_base);
3319 }
3320
3321 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3322 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3323 vertex_start, instance_count, instance_start, vertex_base);
3324 } else {
3325 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3326 vertex_start, instance_count, instance_start, vertex_base);
3327 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003328
Chia-I Wu707a29e2014-08-27 12:51:47 +08003329 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003330 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003331 /* need to re-emit all workarounds */
3332 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003333
3334 if (intel_debug & INTEL_DEBUG_NOCACHE)
3335 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003336}
3337
Chia-I Wuc14d1562014-10-17 09:49:22 +08003338void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3339{
Chia-I Wu6032b892014-10-17 14:47:18 +08003340 cmd->bind.meta = meta;
3341
Chia-I Wuf98dd882015-02-10 04:17:47 +08003342 cmd_adjust_state_base_address(cmd);
3343
Chia-I Wu6032b892014-10-17 14:47:18 +08003344 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003345 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003346
3347 gen6_meta_dynamic_states(cmd);
3348 gen6_meta_surface_states(cmd);
3349
3350 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3351 gen7_meta_urb(cmd);
3352 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003353 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003354 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003355 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003356 gen6_meta_wm(cmd);
3357 gen7_meta_ps(cmd);
3358 gen6_meta_depth_buffer(cmd);
3359
3360 cmd_wa_gen7_post_command_cs_stall(cmd);
3361 cmd_wa_gen7_post_command_depth_stall(cmd);
3362
Chia-I Wu29e6f502014-11-24 14:27:29 +08003363 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3364 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003365 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003366 } else {
3367 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3368 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003369 } else {
3370 gen6_meta_urb(cmd);
3371 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003372 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003373 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003374 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003375 gen6_meta_wm(cmd);
3376 gen6_meta_ps(cmd);
3377 gen6_meta_depth_buffer(cmd);
3378
Chia-I Wu29e6f502014-11-24 14:27:29 +08003379 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3380 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003381 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003382 } else {
3383 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3384 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003385 }
3386
3387 cmd->bind.draw_count++;
3388 /* need to re-emit all workarounds */
3389 cmd->bind.wa_flags = 0;
3390
3391 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003392
Chia-I Wubbc7d912015-02-27 14:59:50 -07003393 /* make the normal path believe the render pass has changed */
3394 cmd->bind.render_pass_changed = true;
3395
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003396 if (intel_debug & INTEL_DEBUG_NOCACHE)
3397 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003398}
3399
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003400static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3401{
3402 const uint8_t cmd_len = 2;
3403 uint32_t *dw;
3404 uint32_t pos;
3405
3406 if (cmd_gen(cmd) < INTEL_GEN(7.5)) {
3407 cmd->result = VK_ERROR_UNKNOWN;
3408 return;
3409 }
3410
3411 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3412 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3413 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3414 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3415 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3416
3417 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3418}
3419
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003420ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003421 VkCmdBuffer cmdBuffer,
3422 VkPipelineBindPoint pipelineBindPoint,
3423 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003424{
3425 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3426
3427 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003428 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003429 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003430 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003431 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003432 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003433 break;
3434 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003435 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003436 break;
3437 }
3438}
3439
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003440ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003441 VkCmdBuffer cmdBuffer,
3442 VkStateBindPoint stateBindPoint,
3443 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003444{
3445 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3446
3447 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003448 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003449 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003450 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003451 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003452 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003453 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003454 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003455 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003456 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003457 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003458 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003459 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003460 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003461 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003462 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003463 break;
3464 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003465 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003466 break;
3467 }
3468}
3469
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003470ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003471 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003472 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003473 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003474 uint32_t firstSet,
3475 uint32_t setCount,
3476 const VkDescriptorSet* pDescriptorSets,
3477 uint32_t dynamicOffsetCount,
3478 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003479{
3480 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003481 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003482 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003483 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003484 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003485
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003486 pipeline_layout = intel_pipeline_layout(layout);
3487
Chia-I Wub2755562014-08-20 13:38:52 +08003488 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003489 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003490 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003491 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003492 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003493 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003494 break;
3495 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003496 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003497 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003498 break;
3499 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003500
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003501 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003502 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3503
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003504 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003505 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003506 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003507 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003508 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003509 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003510 }
Chia-I Wub2755562014-08-20 13:38:52 +08003511}
3512
Tony Barbour8205d902015-04-16 15:59:00 -06003513
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003514ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3515 VkCmdBuffer cmdBuffer,
3516 uint32_t startBinding,
3517 uint32_t bindingCount,
3518 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003519 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003520{
3521 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003522
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003523 for (uint32_t i = 0; i < bindingCount; i++) {
3524 struct intel_buf *buf = intel_buf(pBuffers[i]);
3525 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3526 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003527}
3528
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003529ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003530 VkCmdBuffer cmdBuffer,
3531 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003532 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003533 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003534{
3535 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003536 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003537
Chia-I Wu714df452015-01-01 07:55:04 +08003538 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003539}
3540
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003541ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003542 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003543 uint32_t firstVertex,
3544 uint32_t vertexCount,
3545 uint32_t firstInstance,
3546 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003547{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003548 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003549
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003550 cmd_draw(cmd, firstVertex, vertexCount,
3551 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003552}
3553
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003554ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003555 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003556 uint32_t firstIndex,
3557 uint32_t indexCount,
3558 int32_t vertexOffset,
3559 uint32_t firstInstance,
3560 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003561{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003562 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003563
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003564 cmd_draw(cmd, firstIndex, indexCount,
3565 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003566}
3567
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003568ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003569 VkCmdBuffer cmdBuffer,
3570 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003571 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003572 uint32_t count,
3573 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003574{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003575 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3576
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003577 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003578}
3579
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003580ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003581 VkCmdBuffer cmdBuffer,
3582 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003583 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003584 uint32_t count,
3585 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003586{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003587 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3588
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003589 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003590}
3591
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003592ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003593 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003594 uint32_t x,
3595 uint32_t y,
3596 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003597{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003598 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3599
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003600 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003601}
3602
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003603ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003604 VkCmdBuffer cmdBuffer,
3605 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003606 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003607{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003608 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3609
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003610 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003611}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003612
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003613ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003614 VkCmdBuffer cmdBuffer,
3615 const VkRenderPassBegin* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003616{
3617 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003618 struct intel_render_pass *rp = (struct intel_render_pass *) pRenderPassBegin->renderPass;
3619 struct intel_fb *fb = (struct intel_fb *) pRenderPassBegin->framebuffer;
3620 unsigned i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003621
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003622 if (!cmd->primary) {
3623 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3624 return;
3625 }
3626
3627 cmd_begin_render_pass(cmd, rp, fb, pRenderPassBegin->contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003628
3629 /* issue load ops */
3630 for (i = 0; i < rp->colorAttachmentCount; i++) {
3631 if (rp->colorLoadOps[i] == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3632 /* issue clear of this attachment */
3633 const struct intel_rt_view *rt = fb->rt[i];
3634
3635 VkImageSubresourceRange ranges[1] = {{
3636 VK_IMAGE_ASPECT_COLOR,
3637 rt->mipLevel,
3638 1,
3639 rt->baseArraySlice,
3640 rt->array_size
3641 }};
3642
3643 cmd_meta_clear_color_image(cmdBuffer, (VkImage) rt->img,
3644 rp->colorLayouts[i],
3645 &rp->colorClearValues[i],
3646 1,
3647 ranges);
3648 }
3649 }
Chris Forbes4cf9d102015-06-22 18:46:05 +12003650
3651 if (rp->depthLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3652 const struct intel_ds_view *ds = fb->ds;
3653
3654 VkImageSubresourceRange ranges[1] = {{
3655 VK_IMAGE_ASPECT_DEPTH,
3656 0, /* ds->mipLevel, */
3657 1,
3658 0, /* ds->baseArraySlice, */
3659 ds->array_size
3660 }};
3661
3662 cmd_meta_clear_depth_stencil_image(cmdBuffer, (VkImage)ds->img,
3663 rp->depthStencilLayout,
3664 rp->depthLoadClearValue,
3665 0,
3666 1,
3667 ranges);
3668 }
3669
3670 if (rp->stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3671 const struct intel_ds_view *ds = fb->ds;
3672
3673 VkImageSubresourceRange ranges[1] = {{
3674 VK_IMAGE_ASPECT_STENCIL,
3675 0, /* ds->mipLevel, */
3676 1,
3677 0, /* ds->baseArraySlice, */
3678 ds->array_size
3679 }};
3680
3681 cmd_meta_clear_depth_stencil_image(cmdBuffer, (VkImage)ds->img,
3682 rp->depthStencilLayout,
3683 0.0f,
3684 rp->stencilLoadClearValue,
3685 1,
3686 ranges);
3687 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003688}
3689
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003690ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003691 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003692{
3693 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3694
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003695 cmd_end_render_pass(cmd);
3696}
3697
3698ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3699 VkCmdBuffer cmdBuffer,
3700 uint32_t cmdBuffersCount,
3701 const VkCmdBuffer* pCmdBuffers)
3702{
3703 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003704 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003705
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003706 if (!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3707 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) {
3708 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3709 return;
3710 }
3711
3712 for (i = 0; i < cmdBuffersCount; i++) {
3713 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3714
3715 if (secondary->primary) {
3716 cmd->result = VK_ERROR_INVALID_VALUE;
3717 break;
3718 }
3719
3720 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3721 }
3722
3723 if (i)
3724 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003725}