blob: 79d0d2d330828bc73624c38a614eb4a1ee8c50a6 [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;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700479 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800480 uint32_t dw1, dw2, dw3;
Chia-I Wu8016a172014-08-29 18:31:32 +0800481
482 CMD_ASSERT(cmd, 6, 7.5);
483
484 dw1 = GEN7_SF_DW1_STATISTICS |
485 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
486 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
487 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
488 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700489 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800490
491 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
492 int format;
493
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700494 switch (pipeline->db_format) {
Tony Barbour8205d902015-04-16 15:59:00 -0600495 case VK_FORMAT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800496 format = GEN6_ZFORMAT_D16_UNORM;
497 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600498 case VK_FORMAT_D32_SFLOAT:
499 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800500 format = GEN6_ZFORMAT_D32_FLOAT;
501 break;
502 default:
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600503 assert(!cmd->bind.fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800504 format = 0;
505 break;
506 }
507
508 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
509 }
510
Tony Barbourfa6cac72015-01-16 14:27:35 -0700511 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800512
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700513 /* Scissor is always enabled */
514 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
515
Tony Barbourfa6cac72015-01-16 14:27:35 -0700516 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800517 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
518 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
519 } else {
520 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
521 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
522 }
523
Chia-I Wu8016a172014-08-29 18:31:32 +0800524 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
525 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
526 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800527 GEN7_SF_DW3_SUBPIXEL_8BITS;
528
Chia-I Wu8016a172014-08-29 18:31:32 +0800529 body[0] = dw1;
530 body[1] = dw2;
531 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700532 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
533 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
534 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800535}
536
Chia-I Wu8016a172014-08-29 18:31:32 +0800537static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
538{
539 const uint8_t cmd_len = 20;
540 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
541 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800542 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800543 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800544 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800545
546 CMD_ASSERT(cmd, 6, 6);
547
548 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800549
Chia-I Wu72292b72014-09-09 10:48:33 +0800550 cmd_batch_pointer(cmd, cmd_len, &dw);
551 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800552 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800553 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800554 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800555}
556
557static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
558{
559 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800560 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800561
562 CMD_ASSERT(cmd, 7, 7.5);
563
Chia-I Wu72292b72014-09-09 10:48:33 +0800564 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800565 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
566 (cmd_len - 2);
567 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800568}
569
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800570static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
571{
572 const uint8_t cmd_len = 4;
573 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
574 (cmd_len - 2);
575 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700576 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800577 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700578 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800579 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800580
581 CMD_ASSERT(cmd, 6, 7.5);
582
583 dw1 = GEN6_CLIP_DW1_STATISTICS;
584 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
585 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
586 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700587 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800588 }
589
590 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800591 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800592 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700593 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800594 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
595 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
596 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
597
598 if (pipeline->rasterizerDiscardEnable)
599 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
600 else
601 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
602
603 if (pipeline->depthClipEnable)
604 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
605
606 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
607 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
608 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
609 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
610
611 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
612 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
613 (viewport->viewport_count - 1);
614
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600615 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600616 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600617 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
618 }
619
Chia-I Wu72292b72014-09-09 10:48:33 +0800620 cmd_batch_pointer(cmd, cmd_len, &dw);
621 dw[0] = dw0;
622 dw[1] = dw1;
623 dw[2] = dw2;
624 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800625}
626
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800627static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
628{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800629 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800630 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800631 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600632 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700633 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800634
635 CMD_ASSERT(cmd, 6, 6);
636
637 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
638
639 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
640 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
641
642 dw4 = GEN6_WM_DW4_STATISTICS |
643 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
644 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700645 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800646
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800647 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700648 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
649 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800650
Cody Northrope86574e2015-02-24 14:15:29 -0700651 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700652 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700653
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800654 if (fs->uses & INTEL_SHADER_USE_KILL ||
655 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700656 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800657
Cody Northrope238deb2015-01-26 14:41:36 -0700658 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800659 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
660 if (fs->uses & INTEL_SHADER_USE_DEPTH)
661 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
662 if (fs->uses & INTEL_SHADER_USE_W)
663 dw5 |= GEN6_WM_DW5_PS_USE_W;
664
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700665 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700666 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667
668 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700669 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800670 GEN6_WM_DW6_ZW_INTERP_PIXEL |
671 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
672 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
673
Tony Barbourfa6cac72015-01-16 14:27:35 -0700674 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800675 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
676 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
677 } else {
678 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
679 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
680 }
681
Cody Northrope86574e2015-02-24 14:15:29 -0700682 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
683
Chia-I Wu784d3042014-12-19 14:30:04 +0800684 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800685 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800686 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800687 dw[2] = dw2;
688 dw[3] = 0; /* scratch */
689 dw[4] = dw4;
690 dw[5] = dw5;
691 dw[6] = dw6;
692 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700693 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800694
695 if (fs->per_thread_scratch_size)
696 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697}
698
699static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
700{
701 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800702 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800703 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800704 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800705
706 CMD_ASSERT(cmd, 7, 7.5);
707
708 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
709
710 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700711 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800712 GEN7_WM_DW1_ZW_INTERP_PIXEL |
713 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
714 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
715
716 if (fs->uses & INTEL_SHADER_USE_KILL ||
717 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700718 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800719
Cody Northrope238deb2015-01-26 14:41:36 -0700720 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
721
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800722 if (fs->uses & INTEL_SHADER_USE_DEPTH)
723 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
724 if (fs->uses & INTEL_SHADER_USE_W)
725 dw1 |= GEN7_WM_DW1_PS_USE_W;
726
727 dw2 = 0;
728
Tony Barbourfa6cac72015-01-16 14:27:35 -0700729 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800730 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
731 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
732 } else {
733 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
734 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
735 }
736
Chia-I Wu72292b72014-09-09 10:48:33 +0800737 cmd_batch_pointer(cmd, cmd_len, &dw);
738 dw[0] = dw0;
739 dw[1] = dw1;
740 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800741}
742
743static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
744{
745 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800746 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800747 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700748 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600749 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800750
751 CMD_ASSERT(cmd, 7, 7.5);
752
753 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
754
755 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
756 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
757
758 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700759 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800760
Cody Northrope86574e2015-02-24 14:15:29 -0700761 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700762 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700763
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800764 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800765 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700766 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800767 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800768 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800769 }
770
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800771 if (fs->in_count)
772 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
773
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700774 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800775 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
776
777 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
778 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700779 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
780
781 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800782
Chia-I Wu784d3042014-12-19 14:30:04 +0800783 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800784 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800785 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800786 dw[2] = dw2;
787 dw[3] = 0; /* scratch */
788 dw[4] = dw4;
789 dw[5] = dw5;
790 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700791 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800792
793 if (fs->per_thread_scratch_size)
794 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800795}
796
Chia-I Wu8ada4242015-03-02 11:19:33 -0700797static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
798 uint32_t sample_count)
799{
800 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
801 uint32_t dw1, dw2, dw3, *dw;
802
803 CMD_ASSERT(cmd, 6, 7.5);
804
805 switch (sample_count) {
806 case 4:
807 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
808 dw2 = cmd->dev->sample_pattern_4x;
809 dw3 = 0;
810 break;
811 case 8:
812 assert(cmd_gen(cmd) >= INTEL_GEN(7));
813 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
814 dw2 = cmd->dev->sample_pattern_8x[0];
815 dw3 = cmd->dev->sample_pattern_8x[1];
816 break;
817 default:
818 assert(sample_count <= 1);
819 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
820 dw2 = 0;
821 dw3 = 0;
822 break;
823 }
824
825 cmd_batch_pointer(cmd, cmd_len, &dw);
826
827 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
828 dw[1] = dw1;
829 dw[2] = dw2;
830 if (cmd_gen(cmd) >= INTEL_GEN(7))
831 dw[3] = dw3;
832}
833
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800834static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700835 const struct intel_ds_view *view,
836 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800837{
838 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800839 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600840 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800841
842 CMD_ASSERT(cmd, 6, 7.5);
843
844 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800845 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
846 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800847 dw0 |= (cmd_len - 2);
848
Chia-I Wu72292b72014-09-09 10:48:33 +0800849 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
850 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700851
Chia-I Wu72292b72014-09-09 10:48:33 +0800852 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700853 /* note that we only enable HiZ on Gen7+ */
854 if (!optimal_ds)
855 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
856
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 dw[2] = 0;
858 dw[3] = view->cmd[2];
859 dw[4] = view->cmd[3];
860 dw[5] = view->cmd[4];
861 dw[6] = view->cmd[5];
862
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600863 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800864 cmd_reserve_reloc(cmd, 1);
865 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
866 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600867 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800868}
869
870static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700871 const struct intel_ds_view *view,
872 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800873{
874 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600876 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800877
878 CMD_ASSERT(cmd, 6, 7.5);
879
880 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800881 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
882 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800883 dw0 |= (cmd_len - 2);
884
Chia-I Wu72292b72014-09-09 10:48:33 +0800885 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
886 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800887
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700888 if (view->has_stencil) {
889 dw[1] = view->cmd[6];
890
Chia-I Wu72292b72014-09-09 10:48:33 +0800891 cmd_reserve_reloc(cmd, 1);
892 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
893 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700894 } else {
895 dw[1] = 0;
896 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600897 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800898}
899
900static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700901 const struct intel_ds_view *view,
902 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800903{
904 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800905 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600906 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800907
908 CMD_ASSERT(cmd, 6, 7.5);
909
910 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800911 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
912 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800913 dw0 |= (cmd_len - 2);
914
Chia-I Wu72292b72014-09-09 10:48:33 +0800915 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
916 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800917
Chia-I Wu73520ac2015-02-19 11:17:45 -0700918 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700919 dw[1] = view->cmd[8];
920
Chia-I Wu72292b72014-09-09 10:48:33 +0800921 cmd_reserve_reloc(cmd, 1);
922 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
923 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700924 } else {
925 dw[1] = 0;
926 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600927 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800928}
929
Chia-I Wuf8231032014-08-25 10:44:45 +0800930static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
931 uint32_t clear_val)
932{
933 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800934 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800935 GEN6_CLEAR_PARAMS_DW0_VALID |
936 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800937 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800938
939 CMD_ASSERT(cmd, 6, 6);
940
Chia-I Wu72292b72014-09-09 10:48:33 +0800941 cmd_batch_pointer(cmd, cmd_len, &dw);
942 dw[0] = dw0;
943 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800944}
945
946static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
947 uint32_t clear_val)
948{
949 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800950 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800951 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800952 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800953
954 CMD_ASSERT(cmd, 7, 7.5);
955
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 cmd_batch_pointer(cmd, cmd_len, &dw);
957 dw[0] = dw0;
958 dw[1] = clear_val;
959 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800960}
961
Chia-I Wu302742d2014-08-22 10:28:29 +0800962static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800963 uint32_t blend_offset,
964 uint32_t ds_offset,
965 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800966{
967 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800968 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800969
970 CMD_ASSERT(cmd, 6, 6);
971
Chia-I Wu426072d2014-08-26 14:31:55 +0800972 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800973 (cmd_len - 2);
974
Chia-I Wu72292b72014-09-09 10:48:33 +0800975 cmd_batch_pointer(cmd, cmd_len, &dw);
976 dw[0] = dw0;
977 dw[1] = blend_offset | 1;
978 dw[2] = ds_offset | 1;
979 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800980}
981
Chia-I Wu1744cca2014-08-22 11:10:17 +0800982static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 uint32_t clip_offset,
984 uint32_t sf_offset,
985 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800986{
987 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800988 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800989
990 CMD_ASSERT(cmd, 6, 6);
991
Chia-I Wu426072d2014-08-26 14:31:55 +0800992 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700993 GEN6_VP_PTR_DW0_CLIP_CHANGED |
994 GEN6_VP_PTR_DW0_SF_CHANGED |
995 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800996 (cmd_len - 2);
997
Chia-I Wu72292b72014-09-09 10:48:33 +0800998 cmd_batch_pointer(cmd, cmd_len, &dw);
999 dw[0] = dw0;
1000 dw[1] = clip_offset;
1001 dw[2] = sf_offset;
1002 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001003}
1004
1005static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001006 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001007{
1008 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001009 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001010
1011 CMD_ASSERT(cmd, 6, 6);
1012
Chia-I Wu426072d2014-08-26 14:31:55 +08001013 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001014 (cmd_len - 2);
1015
Chia-I Wu72292b72014-09-09 10:48:33 +08001016 cmd_batch_pointer(cmd, cmd_len, &dw);
1017 dw[0] = dw0;
1018 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001019}
1020
Chia-I Wu42a56202014-08-23 16:47:48 +08001021static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001022 uint32_t vs_offset,
1023 uint32_t gs_offset,
1024 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001025{
1026 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001027 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001028
1029 CMD_ASSERT(cmd, 6, 6);
1030
Chia-I Wu426072d2014-08-26 14:31:55 +08001031 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001032 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1033 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1034 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001035 (cmd_len - 2);
1036
Chia-I Wu72292b72014-09-09 10:48:33 +08001037 cmd_batch_pointer(cmd, cmd_len, &dw);
1038 dw[0] = dw0;
1039 dw[1] = vs_offset;
1040 dw[2] = gs_offset;
1041 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001042}
1043
Chia-I Wu257e75e2014-08-29 14:06:35 +08001044static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001045 uint32_t vs_offset,
1046 uint32_t gs_offset,
1047 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001048{
1049 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001050 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001051
1052 CMD_ASSERT(cmd, 6, 6);
1053
1054 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001055 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1056 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1057 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001058 (cmd_len - 2);
1059
Chia-I Wu72292b72014-09-09 10:48:33 +08001060 cmd_batch_pointer(cmd, cmd_len, &dw);
1061 dw[0] = dw0;
1062 dw[1] = vs_offset;
1063 dw[2] = gs_offset;
1064 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001065}
1066
Chia-I Wu302742d2014-08-22 10:28:29 +08001067static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001068 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001069{
1070 const uint8_t cmd_len = 2;
1071 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1072 GEN6_RENDER_SUBTYPE_3D |
1073 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001074 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001075
Chia-I Wu72292b72014-09-09 10:48:33 +08001076 cmd_batch_pointer(cmd, cmd_len, &dw);
1077 dw[0] = dw0;
1078 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001079}
1080
Chia-I Wua6c4f152014-12-02 04:19:58 +08001081static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001082{
Chia-I Wue6073342014-11-30 09:43:42 +08001083 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001084 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1085 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001086
1087 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001088 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001089
Tony Barbourfa6cac72015-01-16 14:27:35 -07001090 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001091}
1092
Chia-I Wu72292b72014-09-09 10:48:33 +08001093static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001094 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001095{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001096 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001097 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001098 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001099 uint32_t dw[3];
1100
1101 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001102 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001103 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001104 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1105 (state->ds_info.stencilReadMask & 0xff) << 8 |
1106 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001107 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001108
1109 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001110
1111 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1112 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001113
Chia-I Wu00b51a82014-09-09 12:07:37 +08001114 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001115 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001116}
1117
Chia-I Wu72292b72014-09-09 10:48:33 +08001118static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001119 uint32_t stencil_ref,
1120 const uint32_t blend_color[4])
1121{
Chia-I Wue6073342014-11-30 09:43:42 +08001122 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001123 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001124 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001125
1126 CMD_ASSERT(cmd, 6, 7.5);
1127
Chia-I Wu00b51a82014-09-09 12:07:37 +08001128 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1129 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001130 dw[0] = stencil_ref;
1131 dw[1] = 0;
1132 dw[2] = blend_color[0];
1133 dw[3] = blend_color[1];
1134 dw[4] = blend_color[2];
1135 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001136
Chia-I Wu72292b72014-09-09 10:48:33 +08001137 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001138}
1139
Chia-I Wu8370b402014-08-29 12:28:37 +08001140static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001141{
Chia-I Wu8370b402014-08-29 12:28:37 +08001142 CMD_ASSERT(cmd, 6, 7.5);
1143
Chia-I Wu707a29e2014-08-27 12:51:47 +08001144 if (!cmd->bind.draw_count)
1145 return;
1146
Chia-I Wu8370b402014-08-29 12:28:37 +08001147 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001148 return;
1149
Chia-I Wu8370b402014-08-29 12:28:37 +08001150 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001151
1152 /*
1153 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1154 *
1155 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1156 * pipe-control with a post-sync op and no write-cache flushes."
1157 *
1158 * The workaround below necessitates this workaround.
1159 */
1160 gen6_PIPE_CONTROL(cmd,
1161 GEN6_PIPE_CONTROL_CS_STALL |
1162 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001163 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001164
Chia-I Wud6d079d2014-08-31 13:14:21 +08001165 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1166 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001167}
1168
Chia-I Wu8370b402014-08-29 12:28:37 +08001169static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001170{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001171 CMD_ASSERT(cmd, 6, 7.5);
1172
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001173 if (!cmd->bind.draw_count)
1174 return;
1175
Chia-I Wud6d079d2014-08-31 13:14:21 +08001176 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1177 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001178}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001179
Chia-I Wu8370b402014-08-29 12:28:37 +08001180static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1181{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001182 CMD_ASSERT(cmd, 7, 7.5);
1183
Chia-I Wu8370b402014-08-29 12:28:37 +08001184 if (!cmd->bind.draw_count)
1185 return;
1186
1187 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001188
1189 gen6_PIPE_CONTROL(cmd,
1190 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001191 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001192}
1193
Chia-I Wu8370b402014-08-29 12:28:37 +08001194static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1195{
1196 CMD_ASSERT(cmd, 7, 7.5);
1197
Chia-I Wu8370b402014-08-29 12:28:37 +08001198 /*
1199 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1200 *
1201 * "One of the following must also be set (when CS stall is set):
1202 *
1203 * * Render Target Cache Flush Enable ([12] of DW1)
1204 * * Depth Cache Flush Enable ([0] of DW1)
1205 * * Stall at Pixel Scoreboard ([1] of DW1)
1206 * * Depth Stall ([13] of DW1)
1207 * * Post-Sync Operation ([13] of DW1)"
1208 */
1209 gen6_PIPE_CONTROL(cmd,
1210 GEN6_PIPE_CONTROL_CS_STALL |
1211 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001212 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001213}
1214
1215static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1216{
1217 CMD_ASSERT(cmd, 7, 7.5);
1218
Chia-I Wu8370b402014-08-29 12:28:37 +08001219 cmd_wa_gen6_pre_depth_stall_write(cmd);
1220
Chia-I Wud6d079d2014-08-31 13:14:21 +08001221 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001222}
1223
1224static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1225{
1226 CMD_ASSERT(cmd, 6, 7.5);
1227
1228 if (!cmd->bind.draw_count)
1229 return;
1230
1231 /*
1232 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1233 *
1234 * "Driver must guarentee that all the caches in the depth pipe are
1235 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1236 * requires driver to send a PIPE_CONTROL with a CS stall along with
1237 * a Depth Flush prior to this command."
1238 *
1239 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1240 *
1241 * "Driver must ierarchi that all the caches in the depth pipe are
1242 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1243 * requires driver to send a PIPE_CONTROL with a CS stall along with
1244 * a Depth Flush prior to this command.
1245 */
1246 gen6_PIPE_CONTROL(cmd,
1247 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1248 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001249 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001250}
1251
1252static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1253{
1254 CMD_ASSERT(cmd, 6, 7.5);
1255
1256 if (!cmd->bind.draw_count)
1257 return;
1258
1259 /*
1260 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1261 *
1262 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1263 * and a post sync operation prior to the group of depth
1264 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1265 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1266 *
1267 * This workaround satifies all the conditions.
1268 */
1269 cmd_wa_gen6_pre_depth_stall_write(cmd);
1270
1271 /*
1272 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1273 *
1274 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1275 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1276 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1277 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1278 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1279 * Depth Flush Bit set, followed by another pipelined depth stall
1280 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1281 * guarantee that the pipeline from WM onwards is already flushed
1282 * (e.g., via a preceding MI_FLUSH)."
1283 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001284 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1285 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1286 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001287}
1288
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001289void cmd_batch_state_base_address(struct intel_cmd *cmd)
1290{
1291 const uint8_t cmd_len = 10;
1292 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1293 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001294 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001295 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001296 uint32_t pos;
1297 uint32_t *dw;
1298
1299 CMD_ASSERT(cmd, 6, 7.5);
1300
1301 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1302
1303 dw[0] = dw0;
1304 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001305 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001306 dw[2] = 1;
1307 dw[3] = 1;
1308 dw[4] = 1;
1309 dw[5] = 1;
1310 /* end offsets */
1311 dw[6] = 1;
1312 dw[7] = 1 + 0xfffff000;
1313 dw[8] = 1 + 0xfffff000;
1314 dw[9] = 1;
1315
1316 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001317 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1318 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1319 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1320 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1321 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1322 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001323}
1324
Chia-I Wu7c853562015-02-27 14:35:08 -07001325void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1326{
1327 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1328 const uint8_t cmd_len = 2;
1329 uint32_t offset = 0;
1330 uint32_t *dw;
1331
1332 if (cmd_gen(cmd) <= INTEL_GEN(6))
1333 return;
1334
1335 CMD_ASSERT(cmd, 7, 7.5);
1336
1337 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1338 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1339 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1340 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1341 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1342 offset += size;
1343
1344 dw += 2;
1345 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1346 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1347 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1348
1349 dw += 2;
1350 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1351 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1352 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1353
1354 dw += 2;
1355 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1356 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1357 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1358
1359 dw += 2;
1360 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1361 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1362 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1363
1364 /*
1365 *
1366 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1367 *
1368 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1369 * in the ring after this instruction
1370 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1371 */
1372 cmd_wa_gen7_post_command_cs_stall(cmd);
1373}
1374
Chia-I Wu525c6602014-08-27 10:22:34 +08001375void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1376{
Mike Stroyan552fda42015-01-30 17:21:08 -07001377 if (pipe_control_dw0 == 0)
1378 return;
1379
Chia-I Wu525c6602014-08-27 10:22:34 +08001380 if (!cmd->bind.draw_count)
1381 return;
1382
1383 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1384
Chia-I Wu8370b402014-08-29 12:28:37 +08001385 /*
1386 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1387 *
1388 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1389 * PIPE_CONTROL with any non-zero post-sync-op is required."
1390 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001391 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001392 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001393
Chia-I Wu092279a2014-08-30 19:05:30 +08001394 /*
1395 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1396 *
1397 * "One of the following must also be set (when CS stall is set):
1398 *
1399 * * Render Target Cache Flush Enable ([12] of DW1)
1400 * * Depth Cache Flush Enable ([0] of DW1)
1401 * * Stall at Pixel Scoreboard ([1] of DW1)
1402 * * Depth Stall ([13] of DW1)
1403 * * Post-Sync Operation ([13] of DW1)"
1404 */
1405 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1406 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1407 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1408 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1409 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1410 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1411
Chia-I Wud6d079d2014-08-31 13:14:21 +08001412 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001413}
1414
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001415void cmd_batch_flush_all(struct intel_cmd *cmd)
1416{
1417 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1418 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1419 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1420 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1421 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1422 GEN6_PIPE_CONTROL_CS_STALL);
1423}
1424
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001425void cmd_batch_depth_count(struct intel_cmd *cmd,
1426 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001427 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001428{
1429 cmd_wa_gen6_pre_depth_stall_write(cmd);
1430
1431 gen6_PIPE_CONTROL(cmd,
1432 GEN6_PIPE_CONTROL_DEPTH_STALL |
1433 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001434 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001435}
1436
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001437void cmd_batch_timestamp(struct intel_cmd *cmd,
1438 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001439 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001440{
1441 /* need any WA or stall? */
1442 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1443}
1444
1445void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001446 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001447 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001448 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001449 uint64_t val)
1450{
1451 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001452 gen6_PIPE_CONTROL(cmd,
1453 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1454 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001455}
1456
Chia-I Wu302742d2014-08-22 10:28:29 +08001457static void gen6_cc_states(struct intel_cmd *cmd)
1458{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001459 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1460 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001461 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001462 uint32_t stencil_ref;
1463 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001464
1465 CMD_ASSERT(cmd, 6, 6);
1466
Chia-I Wua6c4f152014-12-02 04:19:58 +08001467 blend_offset = gen6_BLEND_STATE(cmd);
1468
1469 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001470 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001471 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001472 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001473
1474 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001475 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001476 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1477 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001478 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001479 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001480 stencil_ref = 0;
1481 }
1482
Chia-I Wu72292b72014-09-09 10:48:33 +08001483 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001484
Chia-I Wu72292b72014-09-09 10:48:33 +08001485 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001486}
1487
Chia-I Wu1744cca2014-08-22 11:10:17 +08001488static void gen6_viewport_states(struct intel_cmd *cmd)
1489{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001490 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001491 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001492
1493 if (!viewport)
1494 return;
1495
Tony Barbourfa6cac72015-01-16 14:27:35 -07001496 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001497 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001498
1499 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001500 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001501 viewport->cmd);
1502
1503 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001504 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001505 &viewport->cmd[viewport->cmd_clip_pos]);
1506
1507 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001508 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001509 &viewport->cmd[viewport->cmd_cc_pos]);
1510
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001511 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1512 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1513 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001514
1515 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001516 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001517
Chia-I Wub1d450a2014-09-09 13:48:03 +08001518 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001519}
1520
Chia-I Wu302742d2014-08-22 10:28:29 +08001521static void gen7_cc_states(struct intel_cmd *cmd)
1522{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001523 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1524 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001525 uint32_t stencil_ref;
1526 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001527 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001528
1529 CMD_ASSERT(cmd, 7, 7.5);
1530
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001531 if (!blend && !ds)
1532 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001533
Chia-I Wua6c4f152014-12-02 04:19:58 +08001534 offset = gen6_BLEND_STATE(cmd);
1535 gen7_3dstate_pointer(cmd,
1536 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001537
Chia-I Wua6c4f152014-12-02 04:19:58 +08001538 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001539 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001540 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001541 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001542
1543 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001544 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001545 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1546 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001547 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001548 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1549 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001550 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1551 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001552 } else {
1553 stencil_ref = 0;
1554 }
1555
Chia-I Wu72292b72014-09-09 10:48:33 +08001556 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001557 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001558 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001559}
1560
Chia-I Wu1744cca2014-08-22 11:10:17 +08001561static void gen7_viewport_states(struct intel_cmd *cmd)
1562{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001563 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001564 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001565
1566 if (!viewport)
1567 return;
1568
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001569 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001570
Chia-I Wub1d450a2014-09-09 13:48:03 +08001571 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001572 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001573 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001574 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001575 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1576 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001577
1578 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001579 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001580 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001581 gen7_3dstate_pointer(cmd,
1582 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001583 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001584
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001585 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1586 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1587 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1588 gen7_3dstate_pointer(cmd,
1589 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1590 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001591}
1592
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001593static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001594 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001595{
1596 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001597 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001598
Chia-I Wu72292b72014-09-09 10:48:33 +08001599 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001600
1601 dw[0] = GEN6_RENDER_TYPE_RENDER |
1602 GEN6_RENDER_SUBTYPE_3D |
1603 subop | (cmd_len - 2);
1604 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001605 dw[2] = 0;
1606 dw[3] = 0;
1607 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001608}
1609
1610static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001611 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001612{
1613 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001614 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001615
Chia-I Wu72292b72014-09-09 10:48:33 +08001616 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001617
1618 dw[0] = GEN6_RENDER_TYPE_RENDER |
1619 GEN6_RENDER_SUBTYPE_3D |
1620 subop | (cmd_len - 2);
1621 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001622 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001623 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001624 dw[4] = 0;
1625 dw[5] = 0;
1626 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001627}
1628
Chia-I Wu625105f2014-10-13 15:35:29 +08001629static uint32_t emit_samplers(struct intel_cmd *cmd,
1630 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001631{
Chia-I Wu862c5572015-03-28 15:23:55 +08001632 const struct intel_desc_region *region = cmd->dev->desc_region;
1633 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001634 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1635 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001636 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001637 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001638 uint32_t surface_count;
1639 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001640
1641 CMD_ASSERT(cmd, 6, 7.5);
1642
Chia-I Wu625105f2014-10-13 15:35:29 +08001643 if (!rmap || !rmap->sampler_count)
1644 return 0;
1645
Cody Northrop40316a32014-12-09 19:08:33 -07001646 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001647
Chia-I Wudcb509d2014-12-10 08:53:10 +08001648 /*
1649 * note that we cannot call cmd_state_pointer() here as the following
1650 * cmd_state_pointer() would invalidate the pointer
1651 */
1652 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001653 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001654 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001655
1656 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001657 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001658 4 * rmap->sampler_count, &sampler_dw);
1659
Chia-I Wudcb509d2014-12-10 08:53:10 +08001660 cmd_state_update(cmd, border_offset,
1661 border_stride * rmap->sampler_count, &border_dw);
1662
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001663 for (i = 0; i < rmap->sampler_count; i++) {
1664 const struct intel_pipeline_rmap_slot *slot =
1665 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001666 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001667 const struct intel_sampler *sampler;
1668
Chia-I Wuf8385062015-01-04 16:27:24 +08001669 switch (slot->type) {
1670 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001671 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1672 &data->set_offsets[slot->index]);
1673 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001674 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001675 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001676 sampler = NULL;
1677 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001678 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001679 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001680 sampler = NULL;
1681 break;
1682 }
1683
1684 if (sampler) {
1685 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1686
1687 sampler_dw[0] = sampler->cmd[0];
1688 sampler_dw[1] = sampler->cmd[1];
1689 sampler_dw[2] = border_offset;
1690 sampler_dw[3] = sampler->cmd[2];
1691 } else {
1692 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1693 sampler_dw[1] = 0;
1694 sampler_dw[2] = 0;
1695 sampler_dw[3] = 0;
1696 }
1697
1698 border_offset += border_stride * 4;
1699 border_dw += border_stride;
1700 sampler_dw += 4;
1701 }
1702
Chia-I Wu625105f2014-10-13 15:35:29 +08001703 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001704}
1705
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001706static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001707 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001708 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001709{
Chia-I Wu862c5572015-03-28 15:23:55 +08001710 const struct intel_desc_region *region = cmd->dev->desc_region;
1711 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001712 const uint32_t sba_offset =
1713 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001714 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001715 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001716
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001717 CMD_ASSERT(cmd, 6, 7.5);
1718
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001719 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001720 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001721 if (!surface_count)
1722 return 0;
1723
Chia-I Wu42a56202014-08-23 16:47:48 +08001724 assert(surface_count <= ARRAY_SIZE(binding_table));
1725
1726 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001727 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001728 struct intel_null_view null_view;
1729 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001730
Chia-I Wuf8385062015-01-04 16:27:24 +08001731 switch (slot->type) {
1732 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001733 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001734 const struct intel_rt_view *view =
Chia-I Wu7732cb22015-03-26 15:27:55 +08001735 (slot->index < cmd->bind.fb->rt_count) ?
1736 cmd->bind.fb->rt[slot->index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001737
Chia-I Wu787a05b2014-12-05 11:02:20 +08001738 if (view) {
1739 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1740 GEN6_ALIGNMENT_SURFACE_STATE,
1741 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001742
Chia-I Wu787a05b2014-12-05 11:02:20 +08001743 cmd_reserve_reloc(cmd, 1);
1744 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1745 view->cmd[1], INTEL_RELOC_WRITE);
1746 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001747 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001748 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001749 }
1750 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001751 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001752 {
Tony Barbour22a30862015-04-22 09:02:32 -06001753 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001754 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001755 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001756 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001757 const struct intel_mem *mem;
1758 bool read_only;
1759 const uint32_t *cmd_data;
1760 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001761
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001762 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001763 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001764
Chia-I Wu862c5572015-03-28 15:23:55 +08001765 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1766 &data->set_offsets[slot->index]);
1767
1768 intel_desc_region_read_surface(region, &desc_offset, stage,
1769 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001770 if (mem) {
1771 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001772 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001773 const uint32_t reloc_flags =
1774 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001775
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001776 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001777 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001778 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001779
1780 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001781 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1782 cmd_data[1] + dynamic_offset, reloc_flags);
1783 } else {
1784 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001785 }
1786 }
1787 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001788 case INTEL_PIPELINE_RMAP_UNUSED:
1789 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001790 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001791 default:
1792 assert(!"unexpected rmap type");
1793 need_null_view = true;
1794 break;
1795 }
1796
1797 if (need_null_view) {
1798 intel_null_view_init(&null_view, cmd->dev);
1799 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1800 GEN6_ALIGNMENT_SURFACE_STATE,
1801 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001802 }
1803
Chia-I Wuf98dd882015-02-10 04:17:47 +08001804 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001805 }
1806
Chia-I Wuf98dd882015-02-10 04:17:47 +08001807 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001808 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001809 surface_count, binding_table) - sba_offset;
1810
1811 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1812 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1813
1814 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001815}
1816
Chia-I Wu1d125092014-10-08 08:49:38 +08001817static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1818{
1819 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001820 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1821 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001822 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001823
1824 CMD_ASSERT(cmd, 6, 7.5);
1825
1826 if (!pipeline->vb_count)
1827 return;
1828
1829 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1830
1831 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1832 dw++;
1833 pos++;
1834
1835 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001836 assert(pipeline->vb[i].strideInBytes <= 2048);
1837
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001838 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001839 pipeline->vb[i].strideInBytes;
1840
Chia-I Wub3686982015-02-27 09:51:16 -07001841 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001842 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1843 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001844 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001845
1846 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001847 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001848 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001849 dw[3] = 0;
1850 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001851 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001852 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001853 dw[3] = 1;
1854 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001855 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001856 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001857 dw[3] = 0;
1858 break;
1859 default:
1860 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001861 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001862 dw[3] = 0;
1863 break;
1864 }
1865
Chia-I Wu714df452015-01-01 07:55:04 +08001866 if (cmd->bind.vertex.buf[i]) {
1867 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001868 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001869
1870 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001871 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1872 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001873 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001874 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001875 dw[1] = 0;
1876 dw[2] = 0;
1877 }
1878
1879 dw += 4;
1880 pos += 4;
1881 }
1882}
1883
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001884static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1885{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001886 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1887 const struct intel_pipeline_shader *vs = &pipeline->vs;
1888 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001889 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001890 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001891 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001892 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001893
1894 CMD_ASSERT(cmd, 6, 7.5);
1895
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001896 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001897 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1898 *
1899 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1900 * 128-bit vertex elements to be passed into the payload for each
1901 * vertex."
1902 *
1903 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1904 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001905 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001906 vue_read_len = (vs->in_count + 1) / 2;
1907 if (!vue_read_len)
1908 vue_read_len = 1;
1909
1910 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1911 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1912
1913 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1914 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1915 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001916
1917 dw5 = GEN6_VS_DW5_STATISTICS |
1918 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001919
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001920 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001921 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001922 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001923 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001924
Chia-I Wube0a3d92014-09-02 13:20:59 +08001925 if (pipeline->disable_vs_cache)
1926 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1927
Chia-I Wu784d3042014-12-19 14:30:04 +08001928 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001929 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001930 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001931 dw[2] = dw2;
1932 dw[3] = 0; /* scratch */
1933 dw[4] = dw4;
1934 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001935
1936 if (vs->per_thread_scratch_size)
1937 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001938}
1939
Chia-I Wu625105f2014-10-13 15:35:29 +08001940static void emit_shader_resources(struct intel_cmd *cmd)
1941{
1942 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001943 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001944
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001945 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001946 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001947 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001948 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001949 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001950 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001951 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001952 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001953 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001954 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001955 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001956 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001957 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001958 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001959 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001960
1961 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1962 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1963 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1964 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1965 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1966
1967 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1968 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001969 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1970 binding_tables[0]);
1971 gen7_3dstate_pointer(cmd,
1972 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1973 binding_tables[1]);
1974 gen7_3dstate_pointer(cmd,
1975 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1976 binding_tables[2]);
1977 gen7_3dstate_pointer(cmd,
1978 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1979 binding_tables[3]);
1980 gen7_3dstate_pointer(cmd,
1981 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1982 binding_tables[4]);
1983
1984 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001985 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1986 samplers[0]);
1987 gen7_3dstate_pointer(cmd,
1988 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1989 samplers[1]);
1990 gen7_3dstate_pointer(cmd,
1991 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1992 samplers[2]);
1993 gen7_3dstate_pointer(cmd,
1994 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1995 samplers[3]);
1996 gen7_3dstate_pointer(cmd,
1997 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1998 samplers[4]);
1999 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002000 assert(!binding_tables[1] && !binding_tables[2]);
2001 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2002 binding_tables[0], binding_tables[3], binding_tables[4]);
2003
Chia-I Wu625105f2014-10-13 15:35:29 +08002004 assert(!samplers[1] && !samplers[2]);
2005 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2006 samplers[0], samplers[3], samplers[4]);
2007 }
2008}
2009
Chia-I Wu8ada4242015-03-02 11:19:33 -07002010static void emit_msaa(struct intel_cmd *cmd)
2011{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002012 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002013
Chia-I Wubbc7d912015-02-27 14:59:50 -07002014 if (!cmd->bind.render_pass_changed)
2015 return;
2016
Chia-I Wu8ada4242015-03-02 11:19:33 -07002017 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002018 cmd->result = VK_ERROR_UNKNOWN;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002019
2020 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2021 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
2022}
2023
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002024static void emit_rt(struct intel_cmd *cmd)
2025{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002026 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002027
2028 if (!cmd->bind.render_pass_changed)
2029 return;
2030
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002031 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002032 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2033 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002034}
2035
2036static void emit_ds(struct intel_cmd *cmd)
2037{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002038 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002039 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002040
Chia-I Wubbc7d912015-02-27 14:59:50 -07002041 if (!cmd->bind.render_pass_changed)
2042 return;
2043
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002044 if (!ds) {
2045 /* all zeros */
2046 static const struct intel_ds_view null_ds;
2047 ds = &null_ds;
2048 }
2049
2050 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07002051 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
2052 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
2053 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002054
2055 if (cmd_gen(cmd) >= INTEL_GEN(7))
2056 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2057 else
2058 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2059}
2060
Chia-I Wua57761b2014-10-14 14:27:44 +08002061static uint32_t emit_shader(struct intel_cmd *cmd,
2062 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002063{
Chia-I Wua57761b2014-10-14 14:27:44 +08002064 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2065 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002066 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002067
Chia-I Wua57761b2014-10-14 14:27:44 +08002068 /* see if the shader is already in the cache */
2069 for (i = 0; i < cache->used; i++) {
2070 if (cache->entries[i].shader == (const void *) shader)
2071 return cache->entries[i].kernel_offset;
2072 }
2073
2074 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2075
2076 /* grow the cache if full */
2077 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002078 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002079 void *entries;
2080
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002081 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002082 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002083 if (entries) {
2084 if (cache->entries) {
2085 memcpy(entries, cache->entries,
2086 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002087 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002088 }
2089
2090 cache->entries = entries;
2091 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002092 }
2093 }
2094
Chia-I Wua57761b2014-10-14 14:27:44 +08002095 /* add the shader to the cache */
2096 if (cache->used < cache->count) {
2097 cache->entries[cache->used].shader = (const void *) shader;
2098 cache->entries[cache->used].kernel_offset = offset;
2099 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002100 }
2101
Chia-I Wua57761b2014-10-14 14:27:44 +08002102 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002103}
2104
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002105static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002106{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002107 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002108
Chia-I Wu8370b402014-08-29 12:28:37 +08002109 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2110 cmd_wa_gen6_pre_depth_stall_write(cmd);
2111 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2112 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2113 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2114 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002115
2116 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002117 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002118 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002119
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002120 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002121 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002122 }
2123 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002124 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002125 }
2126 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002127 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2128 }
2129 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2130 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2131 }
2132 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2133 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002134 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002135
Chia-I Wu8370b402014-08-29 12:28:37 +08002136 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2137 cmd_wa_gen7_post_command_cs_stall(cmd);
2138 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2139 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002140}
2141
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002142static void emit_bounded_states(struct intel_cmd *cmd)
2143{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002144 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002145
2146 emit_graphics_pipeline(cmd);
2147
2148 emit_rt(cmd);
2149 emit_ds(cmd);
2150
2151 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2152 gen7_cc_states(cmd);
2153 gen7_viewport_states(cmd);
2154
2155 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2156 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002157 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2158 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002159 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2160 &cmd->bind.pipeline.graphics->fs);
2161
Cody Northrop293d4502015-05-05 09:38:03 -06002162 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002163 gen6_3DSTATE_CLIP(cmd);
2164 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002165 gen7_3DSTATE_WM(cmd);
2166 gen7_3DSTATE_PS(cmd);
2167 } else {
2168 gen6_cc_states(cmd);
2169 gen6_viewport_states(cmd);
2170
2171 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2172 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002173 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2174 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002175 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2176 &cmd->bind.pipeline.graphics->fs);
2177
Cody Northrop293d4502015-05-05 09:38:03 -06002178 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002179 gen6_3DSTATE_CLIP(cmd);
2180 gen6_3DSTATE_SF(cmd);
2181 gen6_3DSTATE_WM(cmd);
2182 }
2183
2184 emit_shader_resources(cmd);
2185
2186 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002187
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002188 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2189 gen6_3DSTATE_VS(cmd);
2190}
2191
Tony Barbourfa6cac72015-01-16 14:27:35 -07002192static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002193 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002194{
2195 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2196 const uint8_t cmd_len = 3;
2197 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002198
2199 CMD_ASSERT(cmd, 6, 7.5);
2200
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002201 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002202 dw[0] = 0;
2203 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002204
2205 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2206 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2207 GEN6_COMPAREFUNCTION_NEVER << 27 |
2208 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2209 } else {
2210 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2211 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2212 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002213 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002214 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002215 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2216 (GEN6_STENCILOP_KEEP) << 25 |
2217 (GEN6_STENCILOP_KEEP) << 22 |
2218 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002219 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2220 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002221 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2222 (GEN6_STENCILOP_KEEP) << 9 |
2223 (GEN6_STENCILOP_KEEP) << 6 |
2224 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002225
Chia-I Wud850a392015-02-19 11:08:25 -07002226 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2227 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2228 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2229 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2230 dw[2] = 0;
2231 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002232
2233 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2234 cmd_align, cmd_len, dw);
2235}
2236
Chia-I Wu6032b892014-10-17 14:47:18 +08002237static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2238{
2239 const struct intel_cmd_meta *meta = cmd->bind.meta;
2240 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2241
2242 CMD_ASSERT(cmd, 6, 7.5);
2243
2244 blend_offset = 0;
2245 ds_offset = 0;
2246 cc_offset = 0;
2247 cc_vp_offset = 0;
2248
Chia-I Wu29e6f502014-11-24 14:27:29 +08002249 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002250 /* BLEND_STATE */
2251 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002252 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002253 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002254 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002255 }
2256
Chia-I Wu29e6f502014-11-24 14:27:29 +08002257 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002258 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002259 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002260 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2261 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002262
Chia-I Wu29e6f502014-11-24 14:27:29 +08002263 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002264 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002265
Chia-I Wu29e6f502014-11-24 14:27:29 +08002266 /* COLOR_CALC_STATE */
2267 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002268 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002269
Chia-I Wu29e6f502014-11-24 14:27:29 +08002270 /* CC_VIEWPORT */
2271 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002272 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002273 dw[0] = u_fui(0.0f);
2274 dw[1] = u_fui(1.0f);
2275 } else {
2276 /* DEPTH_STENCIL_STATE */
2277 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002278 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002279 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2280 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2281 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002282 }
2283
2284 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2285 gen7_3dstate_pointer(cmd,
2286 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2287 blend_offset);
2288 gen7_3dstate_pointer(cmd,
2289 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2290 ds_offset);
2291 gen7_3dstate_pointer(cmd,
2292 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2293
2294 gen7_3dstate_pointer(cmd,
2295 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2296 cc_vp_offset);
2297 } else {
2298 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002299 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002300
2301 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2302 cmd_batch_pointer(cmd, 4, &dw);
2303 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002304 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002305 dw[1] = 0;
2306 dw[2] = 0;
2307 dw[3] = cc_vp_offset;
2308 }
2309}
2310
2311static void gen6_meta_surface_states(struct intel_cmd *cmd)
2312{
2313 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002314 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002315 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002316 const uint32_t sba_offset =
2317 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002318
2319 CMD_ASSERT(cmd, 6, 7.5);
2320
Chia-I Wu29e6f502014-11-24 14:27:29 +08002321 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2322 return;
2323
Chia-I Wu005c47c2014-10-22 13:49:13 +08002324 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002325 if (meta->src.valid) {
2326 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002327 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002328 meta->src.surface_len, meta->src.surface);
2329
2330 cmd_reserve_reloc(cmd, 1);
2331 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2332 cmd_surface_reloc_writer(cmd, offset, 1,
2333 meta->src.reloc_target, meta->src.reloc_offset);
2334 } else {
2335 cmd_surface_reloc(cmd, offset, 1,
2336 (struct intel_bo *) meta->src.reloc_target,
2337 meta->src.reloc_offset, meta->src.reloc_flags);
2338 }
2339
Mike Stroyan9bfad482015-02-10 15:09:23 -07002340 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002341 }
2342 if (meta->dst.valid) {
2343 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002344 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002345 meta->dst.surface_len, meta->dst.surface);
2346
2347 cmd_reserve_reloc(cmd, 1);
2348 cmd_surface_reloc(cmd, offset, 1,
2349 (struct intel_bo *) meta->dst.reloc_target,
2350 meta->dst.reloc_offset, meta->dst.reloc_flags);
2351
Mike Stroyan9bfad482015-02-10 15:09:23 -07002352 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002353 }
2354
2355 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002356 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002357 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002358 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002359
2360 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002361 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2362 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2363 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002364 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002365 } else {
2366 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002367 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002368 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002369 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002370 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002371 }
2372}
2373
2374static void gen6_meta_urb(struct intel_cmd *cmd)
2375{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002376 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002377 uint32_t *dw;
2378
2379 CMD_ASSERT(cmd, 6, 6);
2380
2381 /* 3DSTATE_URB */
2382 cmd_batch_pointer(cmd, 3, &dw);
2383 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002384 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002385 dw[2] = 0;
2386}
2387
2388static void gen7_meta_urb(struct intel_cmd *cmd)
2389{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002390 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2391 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002392 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002393 uint32_t *dw;
2394
2395 CMD_ASSERT(cmd, 7, 7.5);
2396
Chia-I Wu6032b892014-10-17 14:47:18 +08002397 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2398
Chia-I Wu24aa1022014-11-25 11:53:19 +08002399 switch (cmd_gen(cmd)) {
2400 case INTEL_GEN(7.5):
2401 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2402 break;
2403 case INTEL_GEN(7):
2404 default:
2405 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2406 break;
2407 }
2408
Chia-I Wu6032b892014-10-17 14:47:18 +08002409 /* 3DSTATE_URB_x */
2410 cmd_batch_pointer(cmd, 8, &dw);
2411
2412 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002413 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002414 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002415 dw += 2;
2416
2417 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002418 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002419 dw += 2;
2420
2421 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002422 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002423 dw += 2;
2424
2425 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002426 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002427 dw += 2;
2428}
2429
2430static void gen6_meta_vf(struct intel_cmd *cmd)
2431{
2432 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002433 uint32_t vb_start, vb_end, vb_stride;
2434 int ve_format, ve_z_source;
2435 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002436 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002437
2438 CMD_ASSERT(cmd, 6, 7.5);
2439
Chia-I Wu29e6f502014-11-24 14:27:29 +08002440 switch (meta->mode) {
2441 case INTEL_CMD_META_VS_POINTS:
2442 cmd_batch_pointer(cmd, 3, &dw);
2443 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002444 dw[1] = GEN6_VE_DW0_VALID;
2445 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2446 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2447 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2448 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002449 return;
2450 break;
2451 case INTEL_CMD_META_FS_RECT:
2452 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002453 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002454
Chia-I Wu29e6f502014-11-24 14:27:29 +08002455 vertices[0][0] = meta->dst.x + meta->width;
2456 vertices[0][1] = meta->dst.y + meta->height;
2457 vertices[1][0] = meta->dst.x;
2458 vertices[1][1] = meta->dst.y + meta->height;
2459 vertices[2][0] = meta->dst.x;
2460 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002461
Chia-I Wu29e6f502014-11-24 14:27:29 +08002462 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2463 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002464
Chia-I Wu29e6f502014-11-24 14:27:29 +08002465 vb_end = vb_start + sizeof(vertices) - 1;
2466 vb_stride = sizeof(vertices[0]);
2467 ve_z_source = GEN6_VFCOMP_STORE_0;
2468 ve_format = GEN6_FORMAT_R32G32_USCALED;
2469 }
2470 break;
2471 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2472 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002473 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002474
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002475 vertices[0][0] = (float) (meta->dst.x + meta->width);
2476 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002477 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002478 vertices[1][0] = (float) meta->dst.x;
2479 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002480 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002481 vertices[2][0] = (float) meta->dst.x;
2482 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002483 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002484
Chia-I Wu29e6f502014-11-24 14:27:29 +08002485 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2486 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002487
Chia-I Wu29e6f502014-11-24 14:27:29 +08002488 vb_end = vb_start + sizeof(vertices) - 1;
2489 vb_stride = sizeof(vertices[0]);
2490 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2491 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2492 }
2493 break;
2494 default:
2495 assert(!"unknown meta mode");
2496 return;
2497 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002498 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002499
2500 /* 3DSTATE_VERTEX_BUFFERS */
2501 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002502
Chia-I Wu6032b892014-10-17 14:47:18 +08002503 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002504 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002505 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002506 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002507
2508 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002509 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2510 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002511
2512 dw[4] = 0;
2513
2514 /* 3DSTATE_VERTEX_ELEMENTS */
2515 cmd_batch_pointer(cmd, 5, &dw);
2516 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002517 dw[1] = GEN6_VE_DW0_VALID;
2518 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2519 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2520 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2521 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2522 dw[3] = GEN6_VE_DW0_VALID |
2523 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2524 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2525 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2526 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2527 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002528}
2529
Chia-I Wu29e6f502014-11-24 14:27:29 +08002530static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002531{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002532 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002533 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002534 uint32_t consts[8];
2535 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002536
2537 CMD_ASSERT(cmd, 6, 7.5);
2538
2539 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002540 case INTEL_DEV_META_VS_FILL_MEM:
2541 consts[0] = meta->dst.x;
2542 consts[1] = meta->clear_val[0];
2543 const_count = 2;
2544 break;
2545 case INTEL_DEV_META_VS_COPY_MEM:
2546 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2547 consts[0] = meta->dst.x;
2548 consts[1] = meta->src.x;
2549 const_count = 2;
2550 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002551 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2552 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2553 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2554 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2555 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2556 consts[0] = meta->src.x;
2557 consts[1] = meta->src.y;
2558 consts[2] = meta->width;
2559 consts[3] = meta->dst.x;
2560 const_count = 4;
2561 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002562 default:
2563 assert(!"unknown meta shader id");
2564 const_count = 0;
2565 break;
2566 }
2567
2568 /* this can be skipped but it makes state dumping prettier */
2569 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2570
2571 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2572}
2573
2574static void gen6_meta_vs(struct intel_cmd *cmd)
2575{
2576 const struct intel_cmd_meta *meta = cmd->bind.meta;
2577 const struct intel_pipeline_shader *sh =
2578 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2579 uint32_t offset, *dw;
2580
2581 CMD_ASSERT(cmd, 6, 7.5);
2582
2583 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002584 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002585
2586 /* 3DSTATE_CONSTANT_VS */
2587 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2588 cmd_batch_pointer(cmd, cmd_len, &dw);
2589 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2590 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2591
2592 /* 3DSTATE_VS */
2593 cmd_batch_pointer(cmd, 6, &dw);
2594 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2595 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2596
2597 return;
2598 }
2599
2600 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2601
2602 /* 3DSTATE_CONSTANT_VS */
2603 offset = gen6_meta_vs_constants(cmd);
2604 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2605 cmd_batch_pointer(cmd, 7, &dw);
2606 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002607 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002608 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002609 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002610 dw[4] = 0;
2611 dw[5] = 0;
2612 dw[6] = 0;
2613 } else {
2614 cmd_batch_pointer(cmd, 5, &dw);
2615 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002616 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002617 dw[1] = offset;
2618 dw[2] = 0;
2619 dw[3] = 0;
2620 dw[4] = 0;
2621 }
2622
2623 /* 3DSTATE_VS */
2624 offset = emit_shader(cmd, sh);
2625 cmd_batch_pointer(cmd, 6, &dw);
2626 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2627 dw[1] = offset;
2628 dw[2] = GEN6_THREADDISP_SPF |
2629 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2630 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002631 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002632 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2633 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2634
2635 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2636 GEN6_VS_DW5_VS_ENABLE;
2637 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002638 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002639 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002640 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002641
2642 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002643}
2644
2645static void gen6_meta_disabled(struct intel_cmd *cmd)
2646{
Chia-I Wu6032b892014-10-17 14:47:18 +08002647 uint32_t *dw;
2648
2649 CMD_ASSERT(cmd, 6, 6);
2650
Chia-I Wu6032b892014-10-17 14:47:18 +08002651 /* 3DSTATE_CONSTANT_GS */
2652 cmd_batch_pointer(cmd, 5, &dw);
2653 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2654 dw[1] = 0;
2655 dw[2] = 0;
2656 dw[3] = 0;
2657 dw[4] = 0;
2658
2659 /* 3DSTATE_GS */
2660 cmd_batch_pointer(cmd, 7, &dw);
2661 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2662 dw[1] = 0;
2663 dw[2] = 0;
2664 dw[3] = 0;
2665 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2666 dw[5] = GEN6_GS_DW5_STATISTICS;
2667 dw[6] = 0;
2668
Chia-I Wu6032b892014-10-17 14:47:18 +08002669 /* 3DSTATE_SF */
2670 cmd_batch_pointer(cmd, 20, &dw);
2671 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2672 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2673 memset(&dw[2], 0, 18 * sizeof(*dw));
2674}
2675
2676static void gen7_meta_disabled(struct intel_cmd *cmd)
2677{
2678 uint32_t *dw;
2679
2680 CMD_ASSERT(cmd, 7, 7.5);
2681
Chia-I Wu6032b892014-10-17 14:47:18 +08002682 /* 3DSTATE_CONSTANT_HS */
2683 cmd_batch_pointer(cmd, 7, &dw);
2684 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2685 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2686
2687 /* 3DSTATE_HS */
2688 cmd_batch_pointer(cmd, 7, &dw);
2689 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2690 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2691
2692 /* 3DSTATE_TE */
2693 cmd_batch_pointer(cmd, 4, &dw);
2694 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2695 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2696
2697 /* 3DSTATE_CONSTANT_DS */
2698 cmd_batch_pointer(cmd, 7, &dw);
2699 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2700 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2701
2702 /* 3DSTATE_DS */
2703 cmd_batch_pointer(cmd, 6, &dw);
2704 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2705 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2706
2707 /* 3DSTATE_CONSTANT_GS */
2708 cmd_batch_pointer(cmd, 7, &dw);
2709 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2710 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2711
2712 /* 3DSTATE_GS */
2713 cmd_batch_pointer(cmd, 7, &dw);
2714 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2715 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2716
2717 /* 3DSTATE_STREAMOUT */
2718 cmd_batch_pointer(cmd, 3, &dw);
2719 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2720 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2721
Chia-I Wu6032b892014-10-17 14:47:18 +08002722 /* 3DSTATE_SF */
2723 cmd_batch_pointer(cmd, 7, &dw);
2724 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2725 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2726
2727 /* 3DSTATE_SBE */
2728 cmd_batch_pointer(cmd, 14, &dw);
2729 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2730 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2731 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002732}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002733
Chia-I Wu29e6f502014-11-24 14:27:29 +08002734static void gen6_meta_clip(struct intel_cmd *cmd)
2735{
2736 const struct intel_cmd_meta *meta = cmd->bind.meta;
2737 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002738
Chia-I Wu29e6f502014-11-24 14:27:29 +08002739 /* 3DSTATE_CLIP */
2740 cmd_batch_pointer(cmd, 4, &dw);
2741 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2742 dw[1] = 0;
2743 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2744 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2745 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2746 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002747 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002748 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002749 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002750}
2751
2752static void gen6_meta_wm(struct intel_cmd *cmd)
2753{
2754 const struct intel_cmd_meta *meta = cmd->bind.meta;
2755 uint32_t *dw;
2756
2757 CMD_ASSERT(cmd, 6, 7.5);
2758
2759 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2760
2761 /* 3DSTATE_MULTISAMPLE */
2762 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2763 cmd_batch_pointer(cmd, 4, &dw);
2764 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2765 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2766 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2767 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2768 dw[2] = 0;
2769 dw[3] = 0;
2770 } else {
2771 cmd_batch_pointer(cmd, 3, &dw);
2772 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2773 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2774 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2775 dw[2] = 0;
2776 }
2777
2778 /* 3DSTATE_SAMPLE_MASK */
2779 cmd_batch_pointer(cmd, 2, &dw);
2780 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2781 dw[1] = (1 << meta->samples) - 1;
2782
2783 /* 3DSTATE_DRAWING_RECTANGLE */
2784 cmd_batch_pointer(cmd, 4, &dw);
2785 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002786 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2787 /* unused */
2788 dw[1] = 0;
2789 dw[2] = 0;
2790 } else {
2791 dw[1] = meta->dst.y << 16 | meta->dst.x;
2792 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2793 (meta->dst.x + meta->width - 1);
2794 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002795 dw[3] = 0;
2796}
2797
2798static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2799{
2800 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002801 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002802 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002803 uint32_t consts[8];
2804 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002805
2806 CMD_ASSERT(cmd, 6, 7.5);
2807
2808 /* underflow is fine here */
2809 offset_x = meta->src.x - meta->dst.x;
2810 offset_y = meta->src.y - meta->dst.y;
2811
2812 switch (meta->shader_id) {
2813 case INTEL_DEV_META_FS_COPY_MEM:
2814 case INTEL_DEV_META_FS_COPY_1D:
2815 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2816 case INTEL_DEV_META_FS_COPY_2D:
2817 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2818 case INTEL_DEV_META_FS_COPY_2D_MS:
2819 consts[0] = offset_x;
2820 consts[1] = offset_y;
2821 consts[2] = meta->src.layer;
2822 consts[3] = meta->src.lod;
2823 const_count = 4;
2824 break;
2825 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2826 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2827 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2828 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2829 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2830 consts[0] = offset_x;
2831 consts[1] = offset_y;
2832 consts[2] = meta->src.layer;
2833 consts[3] = meta->src.lod;
2834 consts[4] = meta->src.x;
2835 consts[5] = meta->width;
2836 const_count = 6;
2837 break;
2838 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2839 consts[0] = offset_x;
2840 consts[1] = offset_y;
2841 consts[2] = meta->width;
2842 const_count = 3;
2843 break;
2844 case INTEL_DEV_META_FS_CLEAR_COLOR:
2845 consts[0] = meta->clear_val[0];
2846 consts[1] = meta->clear_val[1];
2847 consts[2] = meta->clear_val[2];
2848 consts[3] = meta->clear_val[3];
2849 const_count = 4;
2850 break;
2851 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2852 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002853 consts[1] = meta->clear_val[1];
2854 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002855 break;
2856 case INTEL_DEV_META_FS_RESOLVE_2X:
2857 case INTEL_DEV_META_FS_RESOLVE_4X:
2858 case INTEL_DEV_META_FS_RESOLVE_8X:
2859 case INTEL_DEV_META_FS_RESOLVE_16X:
2860 consts[0] = offset_x;
2861 consts[1] = offset_y;
2862 const_count = 2;
2863 break;
2864 default:
2865 assert(!"unknown meta shader id");
2866 const_count = 0;
2867 break;
2868 }
2869
2870 /* this can be skipped but it makes state dumping prettier */
2871 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2872
2873 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2874}
2875
2876static void gen6_meta_ps(struct intel_cmd *cmd)
2877{
2878 const struct intel_cmd_meta *meta = cmd->bind.meta;
2879 const struct intel_pipeline_shader *sh =
2880 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2881 uint32_t offset, *dw;
2882
2883 CMD_ASSERT(cmd, 6, 6);
2884
Chia-I Wu29e6f502014-11-24 14:27:29 +08002885 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2886 /* 3DSTATE_CONSTANT_PS */
2887 cmd_batch_pointer(cmd, 5, &dw);
2888 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2889 dw[1] = 0;
2890 dw[2] = 0;
2891 dw[3] = 0;
2892 dw[4] = 0;
2893
2894 /* 3DSTATE_WM */
2895 cmd_batch_pointer(cmd, 9, &dw);
2896 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2897 dw[1] = 0;
2898 dw[2] = 0;
2899 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002900
2901 switch (meta->ds.op) {
2902 case INTEL_CMD_META_DS_HIZ_CLEAR:
2903 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2904 break;
2905 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2906 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2907 break;
2908 case INTEL_CMD_META_DS_RESOLVE:
2909 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2910 break;
2911 default:
2912 dw[4] = 0;
2913 break;
2914 }
2915
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002916 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002917 dw[6] = 0;
2918 dw[7] = 0;
2919 dw[8] = 0;
2920
Chia-I Wu3adf7212014-10-24 15:34:07 +08002921 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002922 }
2923
Chia-I Wu3adf7212014-10-24 15:34:07 +08002924 /* a normal color write */
2925 assert(meta->dst.valid && !sh->uses);
2926
Chia-I Wu6032b892014-10-17 14:47:18 +08002927 /* 3DSTATE_CONSTANT_PS */
2928 offset = gen6_meta_ps_constants(cmd);
2929 cmd_batch_pointer(cmd, 5, &dw);
2930 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002931 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002932 dw[1] = offset;
2933 dw[2] = 0;
2934 dw[3] = 0;
2935 dw[4] = 0;
2936
2937 /* 3DSTATE_WM */
2938 offset = emit_shader(cmd, sh);
2939 cmd_batch_pointer(cmd, 9, &dw);
2940 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2941 dw[1] = offset;
2942 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2943 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002944 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002945 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002946 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002947 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2948 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002949
Chia-I Wu6032b892014-10-17 14:47:18 +08002950 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002951 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002952 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2953 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2954 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2955 if (meta->samples > 1) {
2956 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2957 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2958 } else {
2959 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2960 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2961 }
2962 dw[7] = 0;
2963 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002964
2965 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002966}
2967
2968static void gen7_meta_ps(struct intel_cmd *cmd)
2969{
2970 const struct intel_cmd_meta *meta = cmd->bind.meta;
2971 const struct intel_pipeline_shader *sh =
2972 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2973 uint32_t offset, *dw;
2974
2975 CMD_ASSERT(cmd, 7, 7.5);
2976
Chia-I Wu29e6f502014-11-24 14:27:29 +08002977 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2978 /* 3DSTATE_WM */
2979 cmd_batch_pointer(cmd, 3, &dw);
2980 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002981
2982 switch (meta->ds.op) {
2983 case INTEL_CMD_META_DS_HIZ_CLEAR:
2984 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2985 break;
2986 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2987 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2988 break;
2989 case INTEL_CMD_META_DS_RESOLVE:
2990 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2991 break;
2992 default:
2993 dw[1] = 0;
2994 break;
2995 }
2996
2997 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002998
2999 /* 3DSTATE_CONSTANT_GS */
3000 cmd_batch_pointer(cmd, 7, &dw);
3001 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3002 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3003
3004 /* 3DSTATE_PS */
3005 cmd_batch_pointer(cmd, 8, &dw);
3006 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3007 dw[1] = 0;
3008 dw[2] = 0;
3009 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003010 /* required to avoid hangs */
3011 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003012 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003013 dw[5] = 0;
3014 dw[6] = 0;
3015 dw[7] = 0;
3016
Chia-I Wu3adf7212014-10-24 15:34:07 +08003017 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003018 }
3019
Chia-I Wu3adf7212014-10-24 15:34:07 +08003020 /* a normal color write */
3021 assert(meta->dst.valid && !sh->uses);
3022
Chia-I Wu6032b892014-10-17 14:47:18 +08003023 /* 3DSTATE_WM */
3024 cmd_batch_pointer(cmd, 3, &dw);
3025 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003026 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003027 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3028 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3029 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3030 dw[2] = 0;
3031
3032 /* 3DSTATE_CONSTANT_PS */
3033 offset = gen6_meta_ps_constants(cmd);
3034 cmd_batch_pointer(cmd, 7, &dw);
3035 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003036 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003037 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003038 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003039 dw[4] = 0;
3040 dw[5] = 0;
3041 dw[6] = 0;
3042
3043 /* 3DSTATE_PS */
3044 offset = emit_shader(cmd, sh);
3045 cmd_batch_pointer(cmd, 8, &dw);
3046 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3047 dw[1] = offset;
3048 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3049 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003050 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003051
3052 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3053 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003054 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003055
3056 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003057 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003058 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003059 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003060 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003061 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003062
3063 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3064 dw[6] = 0;
3065 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003066
3067 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003068}
3069
3070static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3071{
3072 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08003073 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003074
3075 CMD_ASSERT(cmd, 6, 7.5);
3076
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003077 if (!ds) {
3078 /* all zeros */
3079 static const struct intel_ds_view null_ds;
3080 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003081 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003082
3083 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003084 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3085 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3086 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003087
3088 if (cmd_gen(cmd) >= INTEL_GEN(7))
3089 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3090 else
3091 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003092}
3093
Chia-I Wu862c5572015-03-28 15:23:55 +08003094static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3095 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003096 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003097{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003098 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003099 if (data->set_offsets)
3100 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003101
Chia-I Wu862c5572015-03-28 15:23:55 +08003102 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003103 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003104 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003105 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003106 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003107 data->set_offset_count = 0;
3108 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003109 }
3110
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003111 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003112 }
3113
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003114 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003115 if (data->dynamic_offsets)
3116 intel_free(cmd, data->dynamic_offsets);
3117
3118 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003119 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003120 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003121 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003122 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003123 data->dynamic_offset_count = 0;
3124 return false;
3125 }
3126
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003127 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003128 }
3129
3130 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003131}
3132
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003133static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3134 const struct intel_pipeline *pipeline)
3135{
3136 cmd->bind.pipeline.graphics = pipeline;
3137
3138 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003139 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003140}
3141
3142static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3143 const struct intel_pipeline *pipeline)
3144{
3145 cmd->bind.pipeline.compute = pipeline;
3146
3147 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003148 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003149}
3150
Chia-I Wu862c5572015-03-28 15:23:55 +08003151static void cmd_copy_dset_data(struct intel_cmd *cmd,
3152 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003153 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003154 uint32_t index,
3155 const struct intel_desc_set *set,
3156 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003157{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003158 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003159
Chia-I Wu862c5572015-03-28 15:23:55 +08003160 assert(index < data->set_offset_count);
3161 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003162
Chia-I Wu862c5572015-03-28 15:23:55 +08003163 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003164 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003165 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003166
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003167 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003168 dynamic_offsets,
3169 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003170 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003171}
3172
Chia-I Wu3b04af52014-11-08 10:48:20 +08003173static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003174 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003175 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003176{
Chia-I Wu714df452015-01-01 07:55:04 +08003177 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003178 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003179 return;
3180 }
3181
Chia-I Wu714df452015-01-01 07:55:04 +08003182 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003183 cmd->bind.vertex.offset[binding] = offset;
3184}
3185
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003186static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003187 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003188 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003189{
Chia-I Wu714df452015-01-01 07:55:04 +08003190 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003191 cmd->bind.index.offset = offset;
3192 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003193}
3194
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003195static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003196 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003197{
3198 cmd->bind.state.viewport = state;
3199}
3200
3201static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003202 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003203{
3204 cmd->bind.state.raster = state;
3205}
3206
3207static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003208 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003209{
3210 cmd->bind.state.ds = state;
3211}
3212
3213static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003214 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003215{
3216 cmd->bind.state.blend = state;
3217}
3218
Chia-I Wuf98dd882015-02-10 04:17:47 +08003219static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3220{
3221 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3222 struct intel_pipeline_rmap *rmaps[5] = {
3223 pipeline->vs.rmap,
3224 pipeline->tcs.rmap,
3225 pipeline->tes.rmap,
3226 pipeline->gs.rmap,
3227 pipeline->fs.rmap,
3228 };
3229 uint32_t max_write;
3230 int i;
3231
3232 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3233 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3234 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3235
3236 /* pad first */
3237 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3238
3239 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3240 const struct intel_pipeline_rmap *rmap = rmaps[i];
3241 const uint32_t surface_count = (rmap) ?
3242 rmap->rt_count + rmap->texture_resource_count +
3243 rmap->resource_count + rmap->uav_count : 0;
3244
3245 if (surface_count) {
3246 /* SURFACE_STATEs */
3247 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3248
3249 /* BINDING_TABLE_STATE */
3250 max_write += u_align(sizeof(uint32_t) * surface_count,
3251 GEN6_ALIGNMENT_SURFACE_STATE);
3252 }
3253 }
3254
3255 return max_write;
3256}
3257
3258static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3259{
3260 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3261 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3262 uint32_t max_surface_write;
3263
3264 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3265 if (cmd->bind.meta)
3266 max_surface_write = 64 * sizeof(uint32_t);
3267 else
3268 max_surface_write = cmd_get_max_surface_write(cmd);
3269
3270 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3271 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3272 /* SBA expects page-aligned addresses */
3273 writer->sba_offset = writer->used & ~0xfff;
3274
3275 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3276
3277 cmd_batch_state_base_address(cmd);
3278 }
3279}
3280
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003281static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003282 uint32_t vertex_start,
3283 uint32_t vertex_count,
3284 uint32_t instance_start,
3285 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003286 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003287 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003288{
3289 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003290 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003291 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3292
3293 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003294
3295 emit_bounded_states(cmd);
3296
Chia-I Wuf98dd882015-02-10 04:17:47 +08003297 /* sanity check on cmd_get_max_surface_write() */
3298 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3299 surface_writer_used <= cmd_get_max_surface_write(cmd));
3300
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003301 if (indexed) {
3302 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003303 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003304
3305 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3306 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3307 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003308 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003309 cmd->bind.index.offset, cmd->bind.index.type,
3310 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003311 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003312 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003313 cmd->bind.index.offset, cmd->bind.index.type,
3314 p->primitive_restart);
3315 }
3316 } else {
3317 assert(!vertex_base);
3318 }
3319
3320 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3321 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3322 vertex_start, instance_count, instance_start, vertex_base);
3323 } else {
3324 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3325 vertex_start, instance_count, instance_start, vertex_base);
3326 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003327
Chia-I Wu707a29e2014-08-27 12:51:47 +08003328 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003329 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003330 /* need to re-emit all workarounds */
3331 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003332
3333 if (intel_debug & INTEL_DEBUG_NOCACHE)
3334 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003335}
3336
Chia-I Wuc14d1562014-10-17 09:49:22 +08003337void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3338{
Chia-I Wu6032b892014-10-17 14:47:18 +08003339 cmd->bind.meta = meta;
3340
Chia-I Wuf98dd882015-02-10 04:17:47 +08003341 cmd_adjust_state_base_address(cmd);
3342
Chia-I Wu6032b892014-10-17 14:47:18 +08003343 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003344 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003345
3346 gen6_meta_dynamic_states(cmd);
3347 gen6_meta_surface_states(cmd);
3348
3349 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3350 gen7_meta_urb(cmd);
3351 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003352 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003353 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003354 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003355 gen6_meta_wm(cmd);
3356 gen7_meta_ps(cmd);
3357 gen6_meta_depth_buffer(cmd);
3358
3359 cmd_wa_gen7_post_command_cs_stall(cmd);
3360 cmd_wa_gen7_post_command_depth_stall(cmd);
3361
Chia-I Wu29e6f502014-11-24 14:27:29 +08003362 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3363 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003364 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003365 } else {
3366 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3367 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003368 } else {
3369 gen6_meta_urb(cmd);
3370 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003371 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003372 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003373 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003374 gen6_meta_wm(cmd);
3375 gen6_meta_ps(cmd);
3376 gen6_meta_depth_buffer(cmd);
3377
Chia-I Wu29e6f502014-11-24 14:27:29 +08003378 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3379 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003380 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003381 } else {
3382 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3383 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003384 }
3385
3386 cmd->bind.draw_count++;
3387 /* need to re-emit all workarounds */
3388 cmd->bind.wa_flags = 0;
3389
3390 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003391
Chia-I Wubbc7d912015-02-27 14:59:50 -07003392 /* make the normal path believe the render pass has changed */
3393 cmd->bind.render_pass_changed = true;
3394
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003395 if (intel_debug & INTEL_DEBUG_NOCACHE)
3396 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003397}
3398
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003399static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3400{
3401 const uint8_t cmd_len = 2;
3402 uint32_t *dw;
3403 uint32_t pos;
3404
3405 if (cmd_gen(cmd) < INTEL_GEN(7.5)) {
3406 cmd->result = VK_ERROR_UNKNOWN;
3407 return;
3408 }
3409
3410 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3411 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3412 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3413 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3414 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3415
3416 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3417}
3418
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003419ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003420 VkCmdBuffer cmdBuffer,
3421 VkPipelineBindPoint pipelineBindPoint,
3422 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003423{
3424 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3425
3426 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003427 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003428 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003429 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003430 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003431 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003432 break;
3433 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003434 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003435 break;
3436 }
3437}
3438
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003439ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003440 VkCmdBuffer cmdBuffer,
3441 VkStateBindPoint stateBindPoint,
3442 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003443{
3444 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3445
3446 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003447 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003448 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003449 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003450 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003451 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003452 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003453 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003454 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003455 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003456 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003457 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003458 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003459 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003460 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003461 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003462 break;
3463 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003464 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003465 break;
3466 }
3467}
3468
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003469ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003470 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003471 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003472 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003473 uint32_t firstSet,
3474 uint32_t setCount,
3475 const VkDescriptorSet* pDescriptorSets,
3476 uint32_t dynamicOffsetCount,
3477 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003478{
3479 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003480 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003481 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003482 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003483 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003484
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003485 pipeline_layout = intel_pipeline_layout(layout);
3486
Chia-I Wub2755562014-08-20 13:38:52 +08003487 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003488 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003489 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003490 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003491 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003492 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003493 break;
3494 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003495 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003496 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003497 break;
3498 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003499
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003500 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003501 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3502
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003503 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003504 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003505 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003506 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003507 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003508 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003509 }
Chia-I Wub2755562014-08-20 13:38:52 +08003510}
3511
Tony Barbour8205d902015-04-16 15:59:00 -06003512
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003513ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3514 VkCmdBuffer cmdBuffer,
3515 uint32_t startBinding,
3516 uint32_t bindingCount,
3517 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003518 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003519{
3520 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003521
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003522 for (uint32_t i = 0; i < bindingCount; i++) {
3523 struct intel_buf *buf = intel_buf(pBuffers[i]);
3524 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3525 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003526}
3527
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003528ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003529 VkCmdBuffer cmdBuffer,
3530 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003531 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003532 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003533{
3534 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003535 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003536
Chia-I Wu714df452015-01-01 07:55:04 +08003537 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003538}
3539
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003540ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003541 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003542 uint32_t firstVertex,
3543 uint32_t vertexCount,
3544 uint32_t firstInstance,
3545 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003546{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003547 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003548
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003549 cmd_draw(cmd, firstVertex, vertexCount,
3550 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003551}
3552
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003553ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003554 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003555 uint32_t firstIndex,
3556 uint32_t indexCount,
3557 int32_t vertexOffset,
3558 uint32_t firstInstance,
3559 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003560{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003561 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003562
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003563 cmd_draw(cmd, firstIndex, indexCount,
3564 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003565}
3566
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003567ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003568 VkCmdBuffer cmdBuffer,
3569 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003570 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003571 uint32_t count,
3572 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003573{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003574 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3575
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003576 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003577}
3578
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003579ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003580 VkCmdBuffer cmdBuffer,
3581 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003582 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003583 uint32_t count,
3584 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003585{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003586 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3587
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003588 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003589}
3590
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003591ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003592 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003593 uint32_t x,
3594 uint32_t y,
3595 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003596{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003597 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3598
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003599 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003600}
3601
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003602ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003603 VkCmdBuffer cmdBuffer,
3604 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003605 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003606{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003607 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3608
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003609 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003610}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003611
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003612ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003613 VkCmdBuffer cmdBuffer,
3614 const VkRenderPassBegin* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003615{
3616 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003617 struct intel_render_pass *rp = (struct intel_render_pass *) pRenderPassBegin->renderPass;
3618 struct intel_fb *fb = (struct intel_fb *) pRenderPassBegin->framebuffer;
3619 unsigned i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003620
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003621 if (!cmd->primary) {
3622 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3623 return;
3624 }
3625
3626 cmd_begin_render_pass(cmd, rp, fb, pRenderPassBegin->contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003627
3628 /* issue load ops */
3629 for (i = 0; i < rp->colorAttachmentCount; i++) {
3630 if (rp->colorLoadOps[i] == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3631 /* issue clear of this attachment */
3632 const struct intel_rt_view *rt = fb->rt[i];
3633
3634 VkImageSubresourceRange ranges[1] = {{
3635 VK_IMAGE_ASPECT_COLOR,
3636 rt->mipLevel,
3637 1,
3638 rt->baseArraySlice,
3639 rt->array_size
3640 }};
3641
3642 cmd_meta_clear_color_image(cmdBuffer, (VkImage) rt->img,
3643 rp->colorLayouts[i],
3644 &rp->colorClearValues[i],
3645 1,
3646 ranges);
3647 }
3648 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003649}
3650
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003651ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003652 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003653{
3654 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3655
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003656 cmd_end_render_pass(cmd);
3657}
3658
3659ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3660 VkCmdBuffer cmdBuffer,
3661 uint32_t cmdBuffersCount,
3662 const VkCmdBuffer* pCmdBuffers)
3663{
3664 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003665 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003666
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003667 if (!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3668 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) {
3669 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3670 return;
3671 }
3672
3673 for (i = 0; i < cmdBuffersCount; i++) {
3674 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3675
3676 if (secondary->primary) {
3677 cmd->result = VK_ERROR_INVALID_VALUE;
3678 break;
3679 }
3680
3681 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3682 }
3683
3684 if (i)
3685 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003686}