blob: 131a73920ae4a3e10001bc75d97fa43befa395ee [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wub2755562014-08-20 13:38:52 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600221 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffffffu);
226 break;
227 default:
228 supported = false;
229 break;
230 }
231
232 return supported;
233}
234
Chia-I Wu59c097e2014-08-21 10:51:07 +0800235static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800236 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600237 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600238 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 bool enable_cut_index)
240{
241 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800242 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800243 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600244 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245
246 CMD_ASSERT(cmd, 6, 7.5);
247
Chia-I Wu426072d2014-08-26 14:31:55 +0800248 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800249
250 /* the bit is moved to 3DSTATE_VF */
251 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
252 assert(!enable_cut_index);
253 if (enable_cut_index)
254 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
255
256 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600257 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800258 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
259 offset_align = 2;
260 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600261 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800262 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
263 offset_align = 4;
264 break;
265 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600266 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800267 return;
268 break;
269 }
270
271 if (offset % offset_align) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800273 return;
274 }
275
276 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800277 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800278
Chia-I Wu72292b72014-09-09 10:48:33 +0800279 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
280 dw[0] = dw0;
281
282 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800283 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
284 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285}
286
Chia-I Wu62a7f252014-08-29 11:31:16 +0800287static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
288 bool enable_cut_index,
289 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800290{
291 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800292 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800293
294 CMD_ASSERT(cmd, 7.5, 7.5);
295
Chia-I Wu426072d2014-08-26 14:31:55 +0800296 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800297 if (enable_cut_index)
298 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
299
Chia-I Wu72292b72014-09-09 10:48:33 +0800300 cmd_batch_pointer(cmd, cmd_len, &dw);
301 dw[0] = dw0;
302 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800303}
304
Cody Northrop293d4502015-05-05 09:38:03 -0600305static void gen6_add_scratch_space(struct intel_cmd *cmd,
306 uint32_t batch_pos,
307 const struct intel_pipeline *pipeline,
308 const struct intel_pipeline_shader *sh)
309{
310 int scratch_space;
311
312 CMD_ASSERT(cmd, 6, 7.5);
313
314 assert(sh->per_thread_scratch_size &&
315 sh->per_thread_scratch_size % 1024 == 0 &&
316 u_is_pow2(sh->per_thread_scratch_size) &&
317 sh->scratch_offset % 1024 == 0);
318 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
319
320 cmd_reserve_reloc(cmd, 1);
321 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
322 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
323}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600324
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800325static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
326{
Cody Northrop293d4502015-05-05 09:38:03 -0600327 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
328 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600330 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800331 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600332 int vue_read_len = 0;
333 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800334
Cody Northrop293d4502015-05-05 09:38:03 -0600335 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
336
337 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
338
339 // based on ilo_gpe_init_gs_cso_gen6
340 vue_read_len = (gs->in_count + 1) / 2;
341 if (!vue_read_len)
342 vue_read_len = 1;
343
344 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
345 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
346 GEN6_THREADDISP_SPF;
347
348 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
349 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
350 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
351
352 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
353 GEN6_GS_DW5_STATISTICS |
354 GEN6_GS_DW5_RENDER_ENABLE;
355
356 dw6 = GEN6_GS_DW6_GS_ENABLE;
357
358 if (gs->discard_adj)
359 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
360
361 } else {
362 dw2 = 0;
363 dw4 = 0;
364 dw5 = GEN6_GS_DW5_STATISTICS;
365 dw6 = 0;
366 }
367
368 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800369 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600370 dw[1] = cmd->bind.pipeline.gs_offset;
371 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800372 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600373 dw[4] = dw4;
374 dw[5] = dw5;
375 dw[6] = dw6;
376
377 if (gs->per_thread_scratch_size)
378 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800379}
380
Chia-I Wu62a7f252014-08-29 11:31:16 +0800381static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
382{
Cody Northrop293d4502015-05-05 09:38:03 -0600383 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
384 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800385 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600386 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800387 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600388 int vue_read_len = 0;
389 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800390
Cody Northrop293d4502015-05-05 09:38:03 -0600391 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
392
393 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
394
395 // based on upload_gs_state
396 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
397 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
398
399 vue_read_len = (gs->in_count + 1) / 2;
400 if (!vue_read_len)
401 vue_read_len = 1;
402
403 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
404 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
405 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
406 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
407 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
408
409
410 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
411 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
412 GEN7_GS_DW5_STATISTICS |
413 GEN7_GS_DW5_GS_ENABLE;
414
415 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
416 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
417
418 if (gs->include_primitive_id)
419 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
420
421 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
422 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
423 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
424 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
425 } else {
426 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
427 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
428 dw6 = 0;
429 }
430 } else {
431 dw2 = 0;
432 dw4 = 0;
433 dw5 = GEN7_GS_DW5_STATISTICS;
434 dw6 = 0;
435 }
436
437 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800438 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600439 dw[1] = cmd->bind.pipeline.gs_offset;
440 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800441 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600442 dw[4] = dw4;
443 dw[5] = dw5;
444 dw[6] = dw6;
445
446 if (gs->per_thread_scratch_size)
447 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800448}
449
Chia-I Wud88e02d2014-08-25 10:56:13 +0800450static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600451 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800452{
453 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800454 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800455 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457
458 CMD_ASSERT(cmd, 6, 7.5);
459
Chia-I Wu72292b72014-09-09 10:48:33 +0800460 cmd_batch_pointer(cmd, cmd_len, &dw);
461 dw[0] = dw0;
462
Chia-I Wud88e02d2014-08-25 10:56:13 +0800463 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800464 dw[1] = 0;
465 dw[2] = (height - 1) << 16 |
466 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800467 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800468 dw[1] = 1;
469 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800470 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800471
472 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800473}
474
Chia-I Wu8016a172014-08-29 18:31:32 +0800475static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
476 uint32_t body[6])
477{
478 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800479 const struct intel_render_pass *rp = cmd->bind.render_pass;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700480 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800481 uint32_t dw1, dw2, dw3;
Chia-I Wu8016a172014-08-29 18:31:32 +0800482
483 CMD_ASSERT(cmd, 6, 7.5);
484
485 dw1 = GEN7_SF_DW1_STATISTICS |
486 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
487 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
488 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
489 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700490 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800491
492 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
493 int format;
494
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800495 switch (rp->depthStencilFormat) {
Tony Barbour8205d902015-04-16 15:59:00 -0600496 case VK_FORMAT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800497 format = GEN6_ZFORMAT_D16_UNORM;
498 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600499 case VK_FORMAT_D32_SFLOAT:
500 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800501 format = GEN6_ZFORMAT_D32_FLOAT;
502 break;
503 default:
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600504 assert(!cmd->bind.fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800505 format = 0;
506 break;
507 }
508
509 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
510 }
511
Tony Barbourfa6cac72015-01-16 14:27:35 -0700512 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800513
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700514 /* Scissor is always enabled */
515 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
516
Tony Barbourfa6cac72015-01-16 14:27:35 -0700517 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800518 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
519 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
520 } else {
521 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
522 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
523 }
524
Chia-I Wu8016a172014-08-29 18:31:32 +0800525 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
526 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
527 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800528 GEN7_SF_DW3_SUBPIXEL_8BITS;
529
Chia-I Wu8016a172014-08-29 18:31:32 +0800530 body[0] = dw1;
531 body[1] = dw2;
532 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700533 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
534 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
535 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800536}
537
Chia-I Wu8016a172014-08-29 18:31:32 +0800538static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
539{
540 const uint8_t cmd_len = 20;
541 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
542 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800543 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800544 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800545 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800546
547 CMD_ASSERT(cmd, 6, 6);
548
549 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800550
Chia-I Wu72292b72014-09-09 10:48:33 +0800551 cmd_batch_pointer(cmd, cmd_len, &dw);
552 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800553 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800554 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800555 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800556}
557
558static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
559{
560 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800561 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800562
563 CMD_ASSERT(cmd, 7, 7.5);
564
Chia-I Wu72292b72014-09-09 10:48:33 +0800565 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800566 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
567 (cmd_len - 2);
568 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800569}
570
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800571static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
572{
573 const uint8_t cmd_len = 4;
574 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
575 (cmd_len - 2);
576 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700577 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800578 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700579 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800580 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800581
582 CMD_ASSERT(cmd, 6, 7.5);
583
584 dw1 = GEN6_CLIP_DW1_STATISTICS;
585 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
586 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
587 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700588 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800589 }
590
591 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800592 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800593 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700594 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800595 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
596 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
597 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
598
599 if (pipeline->rasterizerDiscardEnable)
600 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
601 else
602 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
603
604 if (pipeline->depthClipEnable)
605 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
606
607 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
608 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
609 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
610 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
611
612 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
613 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
614 (viewport->viewport_count - 1);
615
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600616 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600617 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600618 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
619 }
620
Chia-I Wu72292b72014-09-09 10:48:33 +0800621 cmd_batch_pointer(cmd, cmd_len, &dw);
622 dw[0] = dw0;
623 dw[1] = dw1;
624 dw[2] = dw2;
625 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800626}
627
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800628static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
629{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800630 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800631 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800632 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600633 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700634 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800635
636 CMD_ASSERT(cmd, 6, 6);
637
638 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
639
640 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
641 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
642
643 dw4 = GEN6_WM_DW4_STATISTICS |
644 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
645 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700646 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800647
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800648 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700649 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
650 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800651
Cody Northrope86574e2015-02-24 14:15:29 -0700652 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700653 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700654
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800655 if (fs->uses & INTEL_SHADER_USE_KILL ||
656 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700657 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800658
Cody Northrope238deb2015-01-26 14:41:36 -0700659 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800660 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
661 if (fs->uses & INTEL_SHADER_USE_DEPTH)
662 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
663 if (fs->uses & INTEL_SHADER_USE_W)
664 dw5 |= GEN6_WM_DW5_PS_USE_W;
665
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700666 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700667 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668
669 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700670 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800671 GEN6_WM_DW6_ZW_INTERP_PIXEL |
672 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
673 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
674
Tony Barbourfa6cac72015-01-16 14:27:35 -0700675 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
677 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
678 } else {
679 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
680 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
681 }
682
Cody Northrope86574e2015-02-24 14:15:29 -0700683 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
684
Chia-I Wu784d3042014-12-19 14:30:04 +0800685 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800686 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800687 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800688 dw[2] = dw2;
689 dw[3] = 0; /* scratch */
690 dw[4] = dw4;
691 dw[5] = dw5;
692 dw[6] = dw6;
693 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700694 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800695
696 if (fs->per_thread_scratch_size)
697 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800698}
699
700static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
701{
702 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800703 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800705 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800706
707 CMD_ASSERT(cmd, 7, 7.5);
708
709 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
710
711 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700712 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800713 GEN7_WM_DW1_ZW_INTERP_PIXEL |
714 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
715 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
716
717 if (fs->uses & INTEL_SHADER_USE_KILL ||
718 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700719 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800720
Cody Northrope238deb2015-01-26 14:41:36 -0700721 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
722
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723 if (fs->uses & INTEL_SHADER_USE_DEPTH)
724 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
725 if (fs->uses & INTEL_SHADER_USE_W)
726 dw1 |= GEN7_WM_DW1_PS_USE_W;
727
728 dw2 = 0;
729
Tony Barbourfa6cac72015-01-16 14:27:35 -0700730 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800731 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
732 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
733 } else {
734 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
735 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
736 }
737
Chia-I Wu72292b72014-09-09 10:48:33 +0800738 cmd_batch_pointer(cmd, cmd_len, &dw);
739 dw[0] = dw0;
740 dw[1] = dw1;
741 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800742}
743
744static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
745{
746 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800747 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800748 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700749 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600750 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800751
752 CMD_ASSERT(cmd, 7, 7.5);
753
754 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
755
756 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
757 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
758
759 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700760 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800761
Cody Northrope86574e2015-02-24 14:15:29 -0700762 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700763 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700764
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800765 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800766 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700767 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800768 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800769 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800770 }
771
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800772 if (fs->in_count)
773 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
774
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700775 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800776 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
777
778 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
779 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700780 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
781
782 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800783
Chia-I Wu784d3042014-12-19 14:30:04 +0800784 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800786 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800787 dw[2] = dw2;
788 dw[3] = 0; /* scratch */
789 dw[4] = dw4;
790 dw[5] = dw5;
791 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700792 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800793
794 if (fs->per_thread_scratch_size)
795 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800796}
797
Chia-I Wu8ada4242015-03-02 11:19:33 -0700798static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
799 uint32_t sample_count)
800{
801 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
802 uint32_t dw1, dw2, dw3, *dw;
803
804 CMD_ASSERT(cmd, 6, 7.5);
805
806 switch (sample_count) {
807 case 4:
808 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
809 dw2 = cmd->dev->sample_pattern_4x;
810 dw3 = 0;
811 break;
812 case 8:
813 assert(cmd_gen(cmd) >= INTEL_GEN(7));
814 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
815 dw2 = cmd->dev->sample_pattern_8x[0];
816 dw3 = cmd->dev->sample_pattern_8x[1];
817 break;
818 default:
819 assert(sample_count <= 1);
820 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
821 dw2 = 0;
822 dw3 = 0;
823 break;
824 }
825
826 cmd_batch_pointer(cmd, cmd_len, &dw);
827
828 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
829 dw[1] = dw1;
830 dw[2] = dw2;
831 if (cmd_gen(cmd) >= INTEL_GEN(7))
832 dw[3] = dw3;
833}
834
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800835static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700836 const struct intel_ds_view *view,
837 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800838{
839 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800840 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600841 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800842
843 CMD_ASSERT(cmd, 6, 7.5);
844
845 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800846 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
847 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800848 dw0 |= (cmd_len - 2);
849
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
851 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700852
Chia-I Wu72292b72014-09-09 10:48:33 +0800853 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700854 /* note that we only enable HiZ on Gen7+ */
855 if (!optimal_ds)
856 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
857
Chia-I Wu72292b72014-09-09 10:48:33 +0800858 dw[2] = 0;
859 dw[3] = view->cmd[2];
860 dw[4] = view->cmd[3];
861 dw[5] = view->cmd[4];
862 dw[6] = view->cmd[5];
863
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600864 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 cmd_reserve_reloc(cmd, 1);
866 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
867 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600868 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800869}
870
871static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700872 const struct intel_ds_view *view,
873 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800874{
875 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800876 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600877 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800878
879 CMD_ASSERT(cmd, 6, 7.5);
880
881 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800882 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
883 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800884 dw0 |= (cmd_len - 2);
885
Chia-I Wu72292b72014-09-09 10:48:33 +0800886 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
887 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800888
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700889 if (view->has_stencil) {
890 dw[1] = view->cmd[6];
891
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 cmd_reserve_reloc(cmd, 1);
893 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
894 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700895 } else {
896 dw[1] = 0;
897 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600898 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800899}
900
901static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700902 const struct intel_ds_view *view,
903 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800904{
905 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800906 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600907 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800908
909 CMD_ASSERT(cmd, 6, 7.5);
910
911 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800912 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
913 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800914 dw0 |= (cmd_len - 2);
915
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
917 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800918
Chia-I Wu73520ac2015-02-19 11:17:45 -0700919 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700920 dw[1] = view->cmd[8];
921
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 cmd_reserve_reloc(cmd, 1);
923 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
924 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700925 } else {
926 dw[1] = 0;
927 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600928 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800929}
930
Chia-I Wuf8231032014-08-25 10:44:45 +0800931static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
932 uint32_t clear_val)
933{
934 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800935 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800936 GEN6_CLEAR_PARAMS_DW0_VALID |
937 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800938 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800939
940 CMD_ASSERT(cmd, 6, 6);
941
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 cmd_batch_pointer(cmd, cmd_len, &dw);
943 dw[0] = dw0;
944 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800945}
946
947static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
948 uint32_t clear_val)
949{
950 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800951 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800952 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800954
955 CMD_ASSERT(cmd, 7, 7.5);
956
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 cmd_batch_pointer(cmd, cmd_len, &dw);
958 dw[0] = dw0;
959 dw[1] = clear_val;
960 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800961}
962
Chia-I Wu302742d2014-08-22 10:28:29 +0800963static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800964 uint32_t blend_offset,
965 uint32_t ds_offset,
966 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800967{
968 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800969 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800970
971 CMD_ASSERT(cmd, 6, 6);
972
Chia-I Wu426072d2014-08-26 14:31:55 +0800973 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800974 (cmd_len - 2);
975
Chia-I Wu72292b72014-09-09 10:48:33 +0800976 cmd_batch_pointer(cmd, cmd_len, &dw);
977 dw[0] = dw0;
978 dw[1] = blend_offset | 1;
979 dw[2] = ds_offset | 1;
980 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800981}
982
Chia-I Wu1744cca2014-08-22 11:10:17 +0800983static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800984 uint32_t clip_offset,
985 uint32_t sf_offset,
986 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800987{
988 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800989 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800990
991 CMD_ASSERT(cmd, 6, 6);
992
Chia-I Wu426072d2014-08-26 14:31:55 +0800993 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700994 GEN6_VP_PTR_DW0_CLIP_CHANGED |
995 GEN6_VP_PTR_DW0_SF_CHANGED |
996 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800997 (cmd_len - 2);
998
Chia-I Wu72292b72014-09-09 10:48:33 +0800999 cmd_batch_pointer(cmd, cmd_len, &dw);
1000 dw[0] = dw0;
1001 dw[1] = clip_offset;
1002 dw[2] = sf_offset;
1003 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001004}
1005
1006static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001007 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001008{
1009 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001010 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001011
1012 CMD_ASSERT(cmd, 6, 6);
1013
Chia-I Wu426072d2014-08-26 14:31:55 +08001014 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001015 (cmd_len - 2);
1016
Chia-I Wu72292b72014-09-09 10:48:33 +08001017 cmd_batch_pointer(cmd, cmd_len, &dw);
1018 dw[0] = dw0;
1019 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001020}
1021
Chia-I Wu42a56202014-08-23 16:47:48 +08001022static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001023 uint32_t vs_offset,
1024 uint32_t gs_offset,
1025 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001026{
1027 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001028 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001029
1030 CMD_ASSERT(cmd, 6, 6);
1031
Chia-I Wu426072d2014-08-26 14:31:55 +08001032 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001033 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1034 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1035 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001036 (cmd_len - 2);
1037
Chia-I Wu72292b72014-09-09 10:48:33 +08001038 cmd_batch_pointer(cmd, cmd_len, &dw);
1039 dw[0] = dw0;
1040 dw[1] = vs_offset;
1041 dw[2] = gs_offset;
1042 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001043}
1044
Chia-I Wu257e75e2014-08-29 14:06:35 +08001045static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001046 uint32_t vs_offset,
1047 uint32_t gs_offset,
1048 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001049{
1050 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001051 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001052
1053 CMD_ASSERT(cmd, 6, 6);
1054
1055 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001056 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1057 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1058 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001059 (cmd_len - 2);
1060
Chia-I Wu72292b72014-09-09 10:48:33 +08001061 cmd_batch_pointer(cmd, cmd_len, &dw);
1062 dw[0] = dw0;
1063 dw[1] = vs_offset;
1064 dw[2] = gs_offset;
1065 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001066}
1067
Chia-I Wu302742d2014-08-22 10:28:29 +08001068static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001069 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001070{
1071 const uint8_t cmd_len = 2;
1072 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1073 GEN6_RENDER_SUBTYPE_3D |
1074 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001075 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001076
Chia-I Wu72292b72014-09-09 10:48:33 +08001077 cmd_batch_pointer(cmd, cmd_len, &dw);
1078 dw[0] = dw0;
1079 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001080}
1081
Chia-I Wua6c4f152014-12-02 04:19:58 +08001082static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001083{
Chia-I Wue6073342014-11-30 09:43:42 +08001084 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001085 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1086 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001087
1088 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001089 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001090
Tony Barbourfa6cac72015-01-16 14:27:35 -07001091 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001092}
1093
Chia-I Wu72292b72014-09-09 10:48:33 +08001094static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001095 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001096{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001097 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001098 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001099 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001100 uint32_t dw[3];
1101
1102 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001103 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001104 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001105 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1106 (state->ds_info.stencilReadMask & 0xff) << 8 |
1107 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001108 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001109
1110 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001111
1112 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1113 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001114
Chia-I Wu00b51a82014-09-09 12:07:37 +08001115 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001116 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001117}
1118
Chia-I Wu72292b72014-09-09 10:48:33 +08001119static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001120 uint32_t stencil_ref,
1121 const uint32_t blend_color[4])
1122{
Chia-I Wue6073342014-11-30 09:43:42 +08001123 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001124 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001125 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001126
1127 CMD_ASSERT(cmd, 6, 7.5);
1128
Chia-I Wu00b51a82014-09-09 12:07:37 +08001129 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1130 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001131 dw[0] = stencil_ref;
1132 dw[1] = 0;
1133 dw[2] = blend_color[0];
1134 dw[3] = blend_color[1];
1135 dw[4] = blend_color[2];
1136 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001137
Chia-I Wu72292b72014-09-09 10:48:33 +08001138 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001139}
1140
Chia-I Wu8370b402014-08-29 12:28:37 +08001141static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001142{
Chia-I Wu8370b402014-08-29 12:28:37 +08001143 CMD_ASSERT(cmd, 6, 7.5);
1144
Chia-I Wu707a29e2014-08-27 12:51:47 +08001145 if (!cmd->bind.draw_count)
1146 return;
1147
Chia-I Wu8370b402014-08-29 12:28:37 +08001148 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001149 return;
1150
Chia-I Wu8370b402014-08-29 12:28:37 +08001151 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001152
1153 /*
1154 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1155 *
1156 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1157 * pipe-control with a post-sync op and no write-cache flushes."
1158 *
1159 * The workaround below necessitates this workaround.
1160 */
1161 gen6_PIPE_CONTROL(cmd,
1162 GEN6_PIPE_CONTROL_CS_STALL |
1163 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001164 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001165
Chia-I Wud6d079d2014-08-31 13:14:21 +08001166 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1167 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001168}
1169
Chia-I Wu8370b402014-08-29 12:28:37 +08001170static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001171{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001172 CMD_ASSERT(cmd, 6, 7.5);
1173
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001174 if (!cmd->bind.draw_count)
1175 return;
1176
Chia-I Wud6d079d2014-08-31 13:14:21 +08001177 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1178 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001179}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001180
Chia-I Wu8370b402014-08-29 12:28:37 +08001181static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1182{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001183 CMD_ASSERT(cmd, 7, 7.5);
1184
Chia-I Wu8370b402014-08-29 12:28:37 +08001185 if (!cmd->bind.draw_count)
1186 return;
1187
1188 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001189
1190 gen6_PIPE_CONTROL(cmd,
1191 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001192 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001193}
1194
Chia-I Wu8370b402014-08-29 12:28:37 +08001195static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1196{
1197 CMD_ASSERT(cmd, 7, 7.5);
1198
Chia-I Wu8370b402014-08-29 12:28:37 +08001199 /*
1200 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1201 *
1202 * "One of the following must also be set (when CS stall is set):
1203 *
1204 * * Render Target Cache Flush Enable ([12] of DW1)
1205 * * Depth Cache Flush Enable ([0] of DW1)
1206 * * Stall at Pixel Scoreboard ([1] of DW1)
1207 * * Depth Stall ([13] of DW1)
1208 * * Post-Sync Operation ([13] of DW1)"
1209 */
1210 gen6_PIPE_CONTROL(cmd,
1211 GEN6_PIPE_CONTROL_CS_STALL |
1212 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001213 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001214}
1215
1216static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1217{
1218 CMD_ASSERT(cmd, 7, 7.5);
1219
Chia-I Wu8370b402014-08-29 12:28:37 +08001220 cmd_wa_gen6_pre_depth_stall_write(cmd);
1221
Chia-I Wud6d079d2014-08-31 13:14:21 +08001222 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001223}
1224
1225static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1226{
1227 CMD_ASSERT(cmd, 6, 7.5);
1228
1229 if (!cmd->bind.draw_count)
1230 return;
1231
1232 /*
1233 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1234 *
1235 * "Driver must guarentee that all the caches in the depth pipe are
1236 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1237 * requires driver to send a PIPE_CONTROL with a CS stall along with
1238 * a Depth Flush prior to this command."
1239 *
1240 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1241 *
1242 * "Driver must ierarchi that all the caches in the depth pipe are
1243 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1244 * requires driver to send a PIPE_CONTROL with a CS stall along with
1245 * a Depth Flush prior to this command.
1246 */
1247 gen6_PIPE_CONTROL(cmd,
1248 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1249 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001250 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001251}
1252
1253static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1254{
1255 CMD_ASSERT(cmd, 6, 7.5);
1256
1257 if (!cmd->bind.draw_count)
1258 return;
1259
1260 /*
1261 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1262 *
1263 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1264 * and a post sync operation prior to the group of depth
1265 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1266 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1267 *
1268 * This workaround satifies all the conditions.
1269 */
1270 cmd_wa_gen6_pre_depth_stall_write(cmd);
1271
1272 /*
1273 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1274 *
1275 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1276 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1277 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1278 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1279 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1280 * Depth Flush Bit set, followed by another pipelined depth stall
1281 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1282 * guarantee that the pipeline from WM onwards is already flushed
1283 * (e.g., via a preceding MI_FLUSH)."
1284 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001285 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1286 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1287 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001288}
1289
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001290void cmd_batch_state_base_address(struct intel_cmd *cmd)
1291{
1292 const uint8_t cmd_len = 10;
1293 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1294 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001295 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001296 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001297 uint32_t pos;
1298 uint32_t *dw;
1299
1300 CMD_ASSERT(cmd, 6, 7.5);
1301
1302 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1303
1304 dw[0] = dw0;
1305 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001306 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001307 dw[2] = 1;
1308 dw[3] = 1;
1309 dw[4] = 1;
1310 dw[5] = 1;
1311 /* end offsets */
1312 dw[6] = 1;
1313 dw[7] = 1 + 0xfffff000;
1314 dw[8] = 1 + 0xfffff000;
1315 dw[9] = 1;
1316
1317 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001318 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1319 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1320 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1321 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1322 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1323 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001324}
1325
Chia-I Wu7c853562015-02-27 14:35:08 -07001326void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1327{
1328 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1329 const uint8_t cmd_len = 2;
1330 uint32_t offset = 0;
1331 uint32_t *dw;
1332
1333 if (cmd_gen(cmd) <= INTEL_GEN(6))
1334 return;
1335
1336 CMD_ASSERT(cmd, 7, 7.5);
1337
1338 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1339 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1340 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1341 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1342 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1343 offset += size;
1344
1345 dw += 2;
1346 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1347 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1348 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1349
1350 dw += 2;
1351 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1352 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1353 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1354
1355 dw += 2;
1356 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1357 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1358 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1359
1360 dw += 2;
1361 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1362 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1363 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1364
1365 /*
1366 *
1367 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1368 *
1369 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1370 * in the ring after this instruction
1371 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1372 */
1373 cmd_wa_gen7_post_command_cs_stall(cmd);
1374}
1375
Chia-I Wu525c6602014-08-27 10:22:34 +08001376void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1377{
Mike Stroyan552fda42015-01-30 17:21:08 -07001378 if (pipe_control_dw0 == 0)
1379 return;
1380
Chia-I Wu525c6602014-08-27 10:22:34 +08001381 if (!cmd->bind.draw_count)
1382 return;
1383
1384 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1385
Chia-I Wu8370b402014-08-29 12:28:37 +08001386 /*
1387 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1388 *
1389 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1390 * PIPE_CONTROL with any non-zero post-sync-op is required."
1391 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001392 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001393 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001394
Chia-I Wu092279a2014-08-30 19:05:30 +08001395 /*
1396 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1397 *
1398 * "One of the following must also be set (when CS stall is set):
1399 *
1400 * * Render Target Cache Flush Enable ([12] of DW1)
1401 * * Depth Cache Flush Enable ([0] of DW1)
1402 * * Stall at Pixel Scoreboard ([1] of DW1)
1403 * * Depth Stall ([13] of DW1)
1404 * * Post-Sync Operation ([13] of DW1)"
1405 */
1406 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1407 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1408 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1409 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1410 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1411 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1412
Chia-I Wud6d079d2014-08-31 13:14:21 +08001413 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001414}
1415
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001416void cmd_batch_flush_all(struct intel_cmd *cmd)
1417{
1418 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1419 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1420 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1421 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1422 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1423 GEN6_PIPE_CONTROL_CS_STALL);
1424}
1425
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001426void cmd_batch_depth_count(struct intel_cmd *cmd,
1427 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001428 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001429{
1430 cmd_wa_gen6_pre_depth_stall_write(cmd);
1431
1432 gen6_PIPE_CONTROL(cmd,
1433 GEN6_PIPE_CONTROL_DEPTH_STALL |
1434 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001435 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001436}
1437
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001438void cmd_batch_timestamp(struct intel_cmd *cmd,
1439 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001440 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001441{
1442 /* need any WA or stall? */
1443 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1444}
1445
1446void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001447 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001448 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001449 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001450 uint64_t val)
1451{
1452 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001453 gen6_PIPE_CONTROL(cmd,
1454 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1455 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001456}
1457
Chia-I Wu302742d2014-08-22 10:28:29 +08001458static void gen6_cc_states(struct intel_cmd *cmd)
1459{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001460 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1461 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001462 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001463 uint32_t stencil_ref;
1464 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001465
1466 CMD_ASSERT(cmd, 6, 6);
1467
Chia-I Wua6c4f152014-12-02 04:19:58 +08001468 blend_offset = gen6_BLEND_STATE(cmd);
1469
1470 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001471 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001472 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001473 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001474
1475 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001476 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001477 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1478 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001479 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001480 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001481 stencil_ref = 0;
1482 }
1483
Chia-I Wu72292b72014-09-09 10:48:33 +08001484 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001485
Chia-I Wu72292b72014-09-09 10:48:33 +08001486 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001487}
1488
Chia-I Wu1744cca2014-08-22 11:10:17 +08001489static void gen6_viewport_states(struct intel_cmd *cmd)
1490{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001491 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001492 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001493
1494 if (!viewport)
1495 return;
1496
Tony Barbourfa6cac72015-01-16 14:27:35 -07001497 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001498 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001499
1500 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001501 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001502 viewport->cmd);
1503
1504 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001505 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001506 &viewport->cmd[viewport->cmd_clip_pos]);
1507
1508 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001509 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001510 &viewport->cmd[viewport->cmd_cc_pos]);
1511
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001512 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1513 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1514 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001515
1516 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001517 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001518
Chia-I Wub1d450a2014-09-09 13:48:03 +08001519 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001520}
1521
Chia-I Wu302742d2014-08-22 10:28:29 +08001522static void gen7_cc_states(struct intel_cmd *cmd)
1523{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001524 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1525 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001526 uint32_t stencil_ref;
1527 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001528 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001529
1530 CMD_ASSERT(cmd, 7, 7.5);
1531
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001532 if (!blend && !ds)
1533 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001534
Chia-I Wua6c4f152014-12-02 04:19:58 +08001535 offset = gen6_BLEND_STATE(cmd);
1536 gen7_3dstate_pointer(cmd,
1537 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001538
Chia-I Wua6c4f152014-12-02 04:19:58 +08001539 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001540 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001541 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001542 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001543
1544 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001546 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1547 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001548 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001549 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1550 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001551 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1552 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001553 } else {
1554 stencil_ref = 0;
1555 }
1556
Chia-I Wu72292b72014-09-09 10:48:33 +08001557 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001558 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001559 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001560}
1561
Chia-I Wu1744cca2014-08-22 11:10:17 +08001562static void gen7_viewport_states(struct intel_cmd *cmd)
1563{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001564 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001565 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001566
1567 if (!viewport)
1568 return;
1569
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001570 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001571
Chia-I Wub1d450a2014-09-09 13:48:03 +08001572 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001573 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001574 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001575 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001576 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1577 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001578
1579 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001580 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001581 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001582 gen7_3dstate_pointer(cmd,
1583 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001584 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001585
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001586 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1587 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1588 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1589 gen7_3dstate_pointer(cmd,
1590 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1591 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001592}
1593
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001594static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001595 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001596{
1597 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001598 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001599
Chia-I Wu72292b72014-09-09 10:48:33 +08001600 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001601
1602 dw[0] = GEN6_RENDER_TYPE_RENDER |
1603 GEN6_RENDER_SUBTYPE_3D |
1604 subop | (cmd_len - 2);
1605 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001606 dw[2] = 0;
1607 dw[3] = 0;
1608 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001609}
1610
1611static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001612 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001613{
1614 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001615 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001616
Chia-I Wu72292b72014-09-09 10:48:33 +08001617 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001618
1619 dw[0] = GEN6_RENDER_TYPE_RENDER |
1620 GEN6_RENDER_SUBTYPE_3D |
1621 subop | (cmd_len - 2);
1622 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001623 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001624 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001625 dw[4] = 0;
1626 dw[5] = 0;
1627 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001628}
1629
Chia-I Wu625105f2014-10-13 15:35:29 +08001630static uint32_t emit_samplers(struct intel_cmd *cmd,
1631 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001632{
Chia-I Wu862c5572015-03-28 15:23:55 +08001633 const struct intel_desc_region *region = cmd->dev->desc_region;
1634 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001635 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1636 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001637 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001638 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001639 uint32_t surface_count;
1640 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001641
1642 CMD_ASSERT(cmd, 6, 7.5);
1643
Chia-I Wu625105f2014-10-13 15:35:29 +08001644 if (!rmap || !rmap->sampler_count)
1645 return 0;
1646
Cody Northrop40316a32014-12-09 19:08:33 -07001647 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001648
Chia-I Wudcb509d2014-12-10 08:53:10 +08001649 /*
1650 * note that we cannot call cmd_state_pointer() here as the following
1651 * cmd_state_pointer() would invalidate the pointer
1652 */
1653 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001654 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001655 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001656
1657 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001658 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001659 4 * rmap->sampler_count, &sampler_dw);
1660
Chia-I Wudcb509d2014-12-10 08:53:10 +08001661 cmd_state_update(cmd, border_offset,
1662 border_stride * rmap->sampler_count, &border_dw);
1663
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001664 for (i = 0; i < rmap->sampler_count; i++) {
1665 const struct intel_pipeline_rmap_slot *slot =
1666 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001667 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001668 const struct intel_sampler *sampler;
1669
Chia-I Wuf8385062015-01-04 16:27:24 +08001670 switch (slot->type) {
1671 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001672 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1673 &data->set_offsets[slot->index]);
1674 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001675 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001676 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001677 sampler = NULL;
1678 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001679 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001680 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001681 sampler = NULL;
1682 break;
1683 }
1684
1685 if (sampler) {
1686 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1687
1688 sampler_dw[0] = sampler->cmd[0];
1689 sampler_dw[1] = sampler->cmd[1];
1690 sampler_dw[2] = border_offset;
1691 sampler_dw[3] = sampler->cmd[2];
1692 } else {
1693 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1694 sampler_dw[1] = 0;
1695 sampler_dw[2] = 0;
1696 sampler_dw[3] = 0;
1697 }
1698
1699 border_offset += border_stride * 4;
1700 border_dw += border_stride;
1701 sampler_dw += 4;
1702 }
1703
Chia-I Wu625105f2014-10-13 15:35:29 +08001704 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001705}
1706
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001707static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001708 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001709 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001710{
Chia-I Wu862c5572015-03-28 15:23:55 +08001711 const struct intel_desc_region *region = cmd->dev->desc_region;
1712 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001713 const uint32_t sba_offset =
1714 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001715 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001716 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001717
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001718 CMD_ASSERT(cmd, 6, 7.5);
1719
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001720 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001721 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001722 if (!surface_count)
1723 return 0;
1724
Chia-I Wu42a56202014-08-23 16:47:48 +08001725 assert(surface_count <= ARRAY_SIZE(binding_table));
1726
1727 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001728 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001729 struct intel_null_view null_view;
1730 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001731
Chia-I Wuf8385062015-01-04 16:27:24 +08001732 switch (slot->type) {
1733 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001734 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001735 const struct intel_rt_view *view =
Chia-I Wu7732cb22015-03-26 15:27:55 +08001736 (slot->index < cmd->bind.fb->rt_count) ?
1737 cmd->bind.fb->rt[slot->index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001738
Chia-I Wu787a05b2014-12-05 11:02:20 +08001739 if (view) {
1740 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1741 GEN6_ALIGNMENT_SURFACE_STATE,
1742 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001743
Chia-I Wu787a05b2014-12-05 11:02:20 +08001744 cmd_reserve_reloc(cmd, 1);
1745 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1746 view->cmd[1], INTEL_RELOC_WRITE);
1747 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001748 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001749 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001750 }
1751 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001752 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001753 {
Tony Barbour22a30862015-04-22 09:02:32 -06001754 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001755 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001756 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001757 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001758 const struct intel_mem *mem;
1759 bool read_only;
1760 const uint32_t *cmd_data;
1761 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001762
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001763 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001764 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001765
Chia-I Wu862c5572015-03-28 15:23:55 +08001766 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1767 &data->set_offsets[slot->index]);
1768
1769 intel_desc_region_read_surface(region, &desc_offset, stage,
1770 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001771 if (mem) {
1772 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001773 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001774 const uint32_t reloc_flags =
1775 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001776
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001777 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001778 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001779 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001780
1781 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001782 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1783 cmd_data[1] + dynamic_offset, reloc_flags);
1784 } else {
1785 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001786 }
1787 }
1788 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001789 case INTEL_PIPELINE_RMAP_UNUSED:
1790 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001791 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001792 default:
1793 assert(!"unexpected rmap type");
1794 need_null_view = true;
1795 break;
1796 }
1797
1798 if (need_null_view) {
1799 intel_null_view_init(&null_view, cmd->dev);
1800 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1801 GEN6_ALIGNMENT_SURFACE_STATE,
1802 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001803 }
1804
Chia-I Wuf98dd882015-02-10 04:17:47 +08001805 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001806 }
1807
Chia-I Wuf98dd882015-02-10 04:17:47 +08001808 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001809 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001810 surface_count, binding_table) - sba_offset;
1811
1812 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1813 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1814
1815 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001816}
1817
Chia-I Wu1d125092014-10-08 08:49:38 +08001818static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1819{
1820 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001821 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1822 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001823 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001824
1825 CMD_ASSERT(cmd, 6, 7.5);
1826
1827 if (!pipeline->vb_count)
1828 return;
1829
1830 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1831
1832 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1833 dw++;
1834 pos++;
1835
1836 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001837 assert(pipeline->vb[i].strideInBytes <= 2048);
1838
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001839 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001840 pipeline->vb[i].strideInBytes;
1841
Chia-I Wub3686982015-02-27 09:51:16 -07001842 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001843 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1844 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001845 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001846
1847 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001848 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001849 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001850 dw[3] = 0;
1851 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001852 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001853 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001854 dw[3] = 1;
1855 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001856 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001857 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001858 dw[3] = 0;
1859 break;
1860 default:
1861 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001862 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001863 dw[3] = 0;
1864 break;
1865 }
1866
Chia-I Wu714df452015-01-01 07:55:04 +08001867 if (cmd->bind.vertex.buf[i]) {
1868 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001869 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001870
1871 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001872 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1873 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001874 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001875 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001876 dw[1] = 0;
1877 dw[2] = 0;
1878 }
1879
1880 dw += 4;
1881 pos += 4;
1882 }
1883}
1884
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001885static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1886{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001887 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1888 const struct intel_pipeline_shader *vs = &pipeline->vs;
1889 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001890 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001891 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001892 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001893 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001894
1895 CMD_ASSERT(cmd, 6, 7.5);
1896
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001897 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001898 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1899 *
1900 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1901 * 128-bit vertex elements to be passed into the payload for each
1902 * vertex."
1903 *
1904 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1905 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001906 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001907 vue_read_len = (vs->in_count + 1) / 2;
1908 if (!vue_read_len)
1909 vue_read_len = 1;
1910
1911 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1912 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1913
1914 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1915 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1916 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001917
1918 dw5 = GEN6_VS_DW5_STATISTICS |
1919 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001920
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001921 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001922 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001923 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001924 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001925
Chia-I Wube0a3d92014-09-02 13:20:59 +08001926 if (pipeline->disable_vs_cache)
1927 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1928
Chia-I Wu784d3042014-12-19 14:30:04 +08001929 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001930 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001931 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001932 dw[2] = dw2;
1933 dw[3] = 0; /* scratch */
1934 dw[4] = dw4;
1935 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001936
1937 if (vs->per_thread_scratch_size)
1938 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001939}
1940
Chia-I Wu625105f2014-10-13 15:35:29 +08001941static void emit_shader_resources(struct intel_cmd *cmd)
1942{
1943 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001944 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001945
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001946 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001947 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001948 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001949 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001950 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001951 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001952 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001953 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001954 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001955 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001956 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001957 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001958 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001959 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001960 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001961
1962 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1963 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1964 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1965 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1966 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1967
1968 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1969 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001970 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1971 binding_tables[0]);
1972 gen7_3dstate_pointer(cmd,
1973 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1974 binding_tables[1]);
1975 gen7_3dstate_pointer(cmd,
1976 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1977 binding_tables[2]);
1978 gen7_3dstate_pointer(cmd,
1979 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1980 binding_tables[3]);
1981 gen7_3dstate_pointer(cmd,
1982 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1983 binding_tables[4]);
1984
1985 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001986 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1987 samplers[0]);
1988 gen7_3dstate_pointer(cmd,
1989 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1990 samplers[1]);
1991 gen7_3dstate_pointer(cmd,
1992 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1993 samplers[2]);
1994 gen7_3dstate_pointer(cmd,
1995 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1996 samplers[3]);
1997 gen7_3dstate_pointer(cmd,
1998 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1999 samplers[4]);
2000 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002001 assert(!binding_tables[1] && !binding_tables[2]);
2002 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2003 binding_tables[0], binding_tables[3], binding_tables[4]);
2004
Chia-I Wu625105f2014-10-13 15:35:29 +08002005 assert(!samplers[1] && !samplers[2]);
2006 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2007 samplers[0], samplers[3], samplers[4]);
2008 }
2009}
2010
Chia-I Wu8ada4242015-03-02 11:19:33 -07002011static void emit_msaa(struct intel_cmd *cmd)
2012{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002013 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002014
Chia-I Wubbc7d912015-02-27 14:59:50 -07002015 if (!cmd->bind.render_pass_changed)
2016 return;
2017
Chia-I Wu8ada4242015-03-02 11:19:33 -07002018 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002019 cmd->result = VK_ERROR_UNKNOWN;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002020
2021 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2022 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
2023}
2024
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002025static void emit_rt(struct intel_cmd *cmd)
2026{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002027 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002028
2029 if (!cmd->bind.render_pass_changed)
2030 return;
2031
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002032 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002033 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2034 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002035}
2036
2037static void emit_ds(struct intel_cmd *cmd)
2038{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002039 const struct intel_render_pass *rp = cmd->bind.render_pass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002040 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002041 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002042
Chia-I Wubbc7d912015-02-27 14:59:50 -07002043 if (!cmd->bind.render_pass_changed)
2044 return;
2045
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002046 if (!ds) {
2047 /* all zeros */
2048 static const struct intel_ds_view null_ds;
2049 ds = &null_ds;
2050 }
2051
2052 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu1af1a782015-07-09 10:46:39 +08002053 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, rp->optimal_ds);
2054 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, rp->optimal_ds);
2055 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, rp->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002056
2057 if (cmd_gen(cmd) >= INTEL_GEN(7))
2058 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2059 else
2060 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2061}
2062
Chia-I Wua57761b2014-10-14 14:27:44 +08002063static uint32_t emit_shader(struct intel_cmd *cmd,
2064 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002065{
Chia-I Wua57761b2014-10-14 14:27:44 +08002066 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2067 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002068 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002069
Chia-I Wua57761b2014-10-14 14:27:44 +08002070 /* see if the shader is already in the cache */
2071 for (i = 0; i < cache->used; i++) {
2072 if (cache->entries[i].shader == (const void *) shader)
2073 return cache->entries[i].kernel_offset;
2074 }
2075
2076 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2077
2078 /* grow the cache if full */
2079 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002080 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002081 void *entries;
2082
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002083 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002084 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002085 if (entries) {
2086 if (cache->entries) {
2087 memcpy(entries, cache->entries,
2088 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002089 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002090 }
2091
2092 cache->entries = entries;
2093 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002094 }
2095 }
2096
Chia-I Wua57761b2014-10-14 14:27:44 +08002097 /* add the shader to the cache */
2098 if (cache->used < cache->count) {
2099 cache->entries[cache->used].shader = (const void *) shader;
2100 cache->entries[cache->used].kernel_offset = offset;
2101 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002102 }
2103
Chia-I Wua57761b2014-10-14 14:27:44 +08002104 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002105}
2106
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002107static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002108{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002109 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002110
Chia-I Wu8370b402014-08-29 12:28:37 +08002111 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2112 cmd_wa_gen6_pre_depth_stall_write(cmd);
2113 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2114 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2115 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2116 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002117
2118 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002119 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002120 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002121
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002122 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002123 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002124 }
2125 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002126 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002127 }
2128 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002129 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2130 }
2131 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2132 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2133 }
2134 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2135 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002136 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002137
Chia-I Wu8370b402014-08-29 12:28:37 +08002138 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2139 cmd_wa_gen7_post_command_cs_stall(cmd);
2140 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2141 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002142}
2143
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002144static void emit_bounded_states(struct intel_cmd *cmd)
2145{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002146 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002147
2148 emit_graphics_pipeline(cmd);
2149
2150 emit_rt(cmd);
2151 emit_ds(cmd);
2152
2153 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2154 gen7_cc_states(cmd);
2155 gen7_viewport_states(cmd);
2156
2157 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2158 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002159 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2160 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002161 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2162 &cmd->bind.pipeline.graphics->fs);
2163
Cody Northrop293d4502015-05-05 09:38:03 -06002164 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002165 gen6_3DSTATE_CLIP(cmd);
2166 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002167 gen7_3DSTATE_WM(cmd);
2168 gen7_3DSTATE_PS(cmd);
2169 } else {
2170 gen6_cc_states(cmd);
2171 gen6_viewport_states(cmd);
2172
2173 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2174 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002175 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2176 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002177 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2178 &cmd->bind.pipeline.graphics->fs);
2179
Cody Northrop293d4502015-05-05 09:38:03 -06002180 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002181 gen6_3DSTATE_CLIP(cmd);
2182 gen6_3DSTATE_SF(cmd);
2183 gen6_3DSTATE_WM(cmd);
2184 }
2185
2186 emit_shader_resources(cmd);
2187
2188 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002189
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002190 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2191 gen6_3DSTATE_VS(cmd);
2192}
2193
Tony Barbourfa6cac72015-01-16 14:27:35 -07002194static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002195 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002196{
2197 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2198 const uint8_t cmd_len = 3;
2199 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002200
2201 CMD_ASSERT(cmd, 6, 7.5);
2202
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002203 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002204 dw[0] = 0;
2205 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002206
2207 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2208 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2209 GEN6_COMPAREFUNCTION_NEVER << 27 |
2210 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2211 } else {
2212 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2213 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2214 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002215 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002216 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002217 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2218 (GEN6_STENCILOP_KEEP) << 25 |
2219 (GEN6_STENCILOP_KEEP) << 22 |
2220 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002221 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2222 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002223 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2224 (GEN6_STENCILOP_KEEP) << 9 |
2225 (GEN6_STENCILOP_KEEP) << 6 |
2226 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002227
Chia-I Wud850a392015-02-19 11:08:25 -07002228 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2229 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2230 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2231 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2232 dw[2] = 0;
2233 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002234
2235 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2236 cmd_align, cmd_len, dw);
2237}
2238
Chia-I Wu6032b892014-10-17 14:47:18 +08002239static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2240{
2241 const struct intel_cmd_meta *meta = cmd->bind.meta;
2242 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2243
2244 CMD_ASSERT(cmd, 6, 7.5);
2245
2246 blend_offset = 0;
2247 ds_offset = 0;
2248 cc_offset = 0;
2249 cc_vp_offset = 0;
2250
Chia-I Wu29e6f502014-11-24 14:27:29 +08002251 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002252 /* BLEND_STATE */
2253 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002254 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002255 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002256 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002257 }
2258
Chia-I Wu29e6f502014-11-24 14:27:29 +08002259 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002260 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002261 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002262 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2263 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002264
Chia-I Wu29e6f502014-11-24 14:27:29 +08002265 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002266 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002267
Chia-I Wu29e6f502014-11-24 14:27:29 +08002268 /* COLOR_CALC_STATE */
2269 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002270 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002271
Chia-I Wu29e6f502014-11-24 14:27:29 +08002272 /* CC_VIEWPORT */
2273 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002274 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002275 dw[0] = u_fui(0.0f);
2276 dw[1] = u_fui(1.0f);
2277 } else {
2278 /* DEPTH_STENCIL_STATE */
2279 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002280 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002281 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2282 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2283 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002284 }
2285
2286 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2287 gen7_3dstate_pointer(cmd,
2288 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2289 blend_offset);
2290 gen7_3dstate_pointer(cmd,
2291 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2292 ds_offset);
2293 gen7_3dstate_pointer(cmd,
2294 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2295
2296 gen7_3dstate_pointer(cmd,
2297 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2298 cc_vp_offset);
2299 } else {
2300 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002301 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002302
2303 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2304 cmd_batch_pointer(cmd, 4, &dw);
2305 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002306 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002307 dw[1] = 0;
2308 dw[2] = 0;
2309 dw[3] = cc_vp_offset;
2310 }
2311}
2312
2313static void gen6_meta_surface_states(struct intel_cmd *cmd)
2314{
2315 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002316 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002317 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002318 const uint32_t sba_offset =
2319 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002320
2321 CMD_ASSERT(cmd, 6, 7.5);
2322
Chia-I Wu29e6f502014-11-24 14:27:29 +08002323 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2324 return;
2325
Chia-I Wu005c47c2014-10-22 13:49:13 +08002326 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002327 if (meta->src.valid) {
2328 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002329 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002330 meta->src.surface_len, meta->src.surface);
2331
2332 cmd_reserve_reloc(cmd, 1);
2333 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2334 cmd_surface_reloc_writer(cmd, offset, 1,
2335 meta->src.reloc_target, meta->src.reloc_offset);
2336 } else {
2337 cmd_surface_reloc(cmd, offset, 1,
2338 (struct intel_bo *) meta->src.reloc_target,
2339 meta->src.reloc_offset, meta->src.reloc_flags);
2340 }
2341
Mike Stroyan9bfad482015-02-10 15:09:23 -07002342 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002343 }
2344 if (meta->dst.valid) {
2345 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002346 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002347 meta->dst.surface_len, meta->dst.surface);
2348
2349 cmd_reserve_reloc(cmd, 1);
2350 cmd_surface_reloc(cmd, offset, 1,
2351 (struct intel_bo *) meta->dst.reloc_target,
2352 meta->dst.reloc_offset, meta->dst.reloc_flags);
2353
Mike Stroyan9bfad482015-02-10 15:09:23 -07002354 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002355 }
2356
2357 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002358 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002359 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002360 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002361
2362 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002363 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2364 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2365 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002366 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002367 } else {
2368 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002369 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002370 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002371 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002372 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002373 }
2374}
2375
2376static void gen6_meta_urb(struct intel_cmd *cmd)
2377{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002378 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002379 uint32_t *dw;
2380
2381 CMD_ASSERT(cmd, 6, 6);
2382
2383 /* 3DSTATE_URB */
2384 cmd_batch_pointer(cmd, 3, &dw);
2385 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002386 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002387 dw[2] = 0;
2388}
2389
2390static void gen7_meta_urb(struct intel_cmd *cmd)
2391{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002392 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2393 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002394 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002395 uint32_t *dw;
2396
2397 CMD_ASSERT(cmd, 7, 7.5);
2398
Chia-I Wu6032b892014-10-17 14:47:18 +08002399 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2400
Chia-I Wu24aa1022014-11-25 11:53:19 +08002401 switch (cmd_gen(cmd)) {
2402 case INTEL_GEN(7.5):
2403 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2404 break;
2405 case INTEL_GEN(7):
2406 default:
2407 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2408 break;
2409 }
2410
Chia-I Wu6032b892014-10-17 14:47:18 +08002411 /* 3DSTATE_URB_x */
2412 cmd_batch_pointer(cmd, 8, &dw);
2413
2414 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002415 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002416 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002417 dw += 2;
2418
2419 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002420 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002421 dw += 2;
2422
2423 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002424 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002425 dw += 2;
2426
2427 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002428 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002429 dw += 2;
2430}
2431
2432static void gen6_meta_vf(struct intel_cmd *cmd)
2433{
2434 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002435 uint32_t vb_start, vb_end, vb_stride;
2436 int ve_format, ve_z_source;
2437 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002438 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002439
2440 CMD_ASSERT(cmd, 6, 7.5);
2441
Chia-I Wu29e6f502014-11-24 14:27:29 +08002442 switch (meta->mode) {
2443 case INTEL_CMD_META_VS_POINTS:
2444 cmd_batch_pointer(cmd, 3, &dw);
2445 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002446 dw[1] = GEN6_VE_DW0_VALID;
2447 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2448 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2449 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2450 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002451 return;
2452 break;
2453 case INTEL_CMD_META_FS_RECT:
2454 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002455 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002456
Chia-I Wu29e6f502014-11-24 14:27:29 +08002457 vertices[0][0] = meta->dst.x + meta->width;
2458 vertices[0][1] = meta->dst.y + meta->height;
2459 vertices[1][0] = meta->dst.x;
2460 vertices[1][1] = meta->dst.y + meta->height;
2461 vertices[2][0] = meta->dst.x;
2462 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002463
Chia-I Wu29e6f502014-11-24 14:27:29 +08002464 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2465 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002466
Chia-I Wu29e6f502014-11-24 14:27:29 +08002467 vb_end = vb_start + sizeof(vertices) - 1;
2468 vb_stride = sizeof(vertices[0]);
2469 ve_z_source = GEN6_VFCOMP_STORE_0;
2470 ve_format = GEN6_FORMAT_R32G32_USCALED;
2471 }
2472 break;
2473 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2474 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002475 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002476
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002477 vertices[0][0] = (float) (meta->dst.x + meta->width);
2478 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002479 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002480 vertices[1][0] = (float) meta->dst.x;
2481 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002482 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002483 vertices[2][0] = (float) meta->dst.x;
2484 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002485 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002486
Chia-I Wu29e6f502014-11-24 14:27:29 +08002487 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2488 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002489
Chia-I Wu29e6f502014-11-24 14:27:29 +08002490 vb_end = vb_start + sizeof(vertices) - 1;
2491 vb_stride = sizeof(vertices[0]);
2492 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2493 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2494 }
2495 break;
2496 default:
2497 assert(!"unknown meta mode");
2498 return;
2499 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002500 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002501
2502 /* 3DSTATE_VERTEX_BUFFERS */
2503 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002504
Chia-I Wu6032b892014-10-17 14:47:18 +08002505 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002506 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002507 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002508 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002509
2510 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002511 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2512 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002513
2514 dw[4] = 0;
2515
2516 /* 3DSTATE_VERTEX_ELEMENTS */
2517 cmd_batch_pointer(cmd, 5, &dw);
2518 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002519 dw[1] = GEN6_VE_DW0_VALID;
2520 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2521 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2522 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2523 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2524 dw[3] = GEN6_VE_DW0_VALID |
2525 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2526 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2527 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2528 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2529 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002530}
2531
Chia-I Wu29e6f502014-11-24 14:27:29 +08002532static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002533{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002534 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002535 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002536 uint32_t consts[8];
2537 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002538
2539 CMD_ASSERT(cmd, 6, 7.5);
2540
2541 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002542 case INTEL_DEV_META_VS_FILL_MEM:
2543 consts[0] = meta->dst.x;
2544 consts[1] = meta->clear_val[0];
2545 const_count = 2;
2546 break;
2547 case INTEL_DEV_META_VS_COPY_MEM:
2548 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2549 consts[0] = meta->dst.x;
2550 consts[1] = meta->src.x;
2551 const_count = 2;
2552 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002553 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2554 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2555 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2556 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2557 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2558 consts[0] = meta->src.x;
2559 consts[1] = meta->src.y;
2560 consts[2] = meta->width;
2561 consts[3] = meta->dst.x;
2562 const_count = 4;
2563 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002564 default:
2565 assert(!"unknown meta shader id");
2566 const_count = 0;
2567 break;
2568 }
2569
2570 /* this can be skipped but it makes state dumping prettier */
2571 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2572
2573 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2574}
2575
2576static void gen6_meta_vs(struct intel_cmd *cmd)
2577{
2578 const struct intel_cmd_meta *meta = cmd->bind.meta;
2579 const struct intel_pipeline_shader *sh =
2580 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2581 uint32_t offset, *dw;
2582
2583 CMD_ASSERT(cmd, 6, 7.5);
2584
2585 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002586 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002587
2588 /* 3DSTATE_CONSTANT_VS */
2589 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2590 cmd_batch_pointer(cmd, cmd_len, &dw);
2591 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2592 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2593
2594 /* 3DSTATE_VS */
2595 cmd_batch_pointer(cmd, 6, &dw);
2596 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2597 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2598
2599 return;
2600 }
2601
2602 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2603
2604 /* 3DSTATE_CONSTANT_VS */
2605 offset = gen6_meta_vs_constants(cmd);
2606 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2607 cmd_batch_pointer(cmd, 7, &dw);
2608 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002609 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002610 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002611 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002612 dw[4] = 0;
2613 dw[5] = 0;
2614 dw[6] = 0;
2615 } else {
2616 cmd_batch_pointer(cmd, 5, &dw);
2617 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002618 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002619 dw[1] = offset;
2620 dw[2] = 0;
2621 dw[3] = 0;
2622 dw[4] = 0;
2623 }
2624
2625 /* 3DSTATE_VS */
2626 offset = emit_shader(cmd, sh);
2627 cmd_batch_pointer(cmd, 6, &dw);
2628 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2629 dw[1] = offset;
2630 dw[2] = GEN6_THREADDISP_SPF |
2631 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2632 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002633 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002634 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2635 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2636
2637 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2638 GEN6_VS_DW5_VS_ENABLE;
2639 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002640 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002641 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002642 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002643
2644 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002645}
2646
2647static void gen6_meta_disabled(struct intel_cmd *cmd)
2648{
Chia-I Wu6032b892014-10-17 14:47:18 +08002649 uint32_t *dw;
2650
2651 CMD_ASSERT(cmd, 6, 6);
2652
Chia-I Wu6032b892014-10-17 14:47:18 +08002653 /* 3DSTATE_CONSTANT_GS */
2654 cmd_batch_pointer(cmd, 5, &dw);
2655 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2656 dw[1] = 0;
2657 dw[2] = 0;
2658 dw[3] = 0;
2659 dw[4] = 0;
2660
2661 /* 3DSTATE_GS */
2662 cmd_batch_pointer(cmd, 7, &dw);
2663 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2664 dw[1] = 0;
2665 dw[2] = 0;
2666 dw[3] = 0;
2667 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2668 dw[5] = GEN6_GS_DW5_STATISTICS;
2669 dw[6] = 0;
2670
Chia-I Wu6032b892014-10-17 14:47:18 +08002671 /* 3DSTATE_SF */
2672 cmd_batch_pointer(cmd, 20, &dw);
2673 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2674 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2675 memset(&dw[2], 0, 18 * sizeof(*dw));
2676}
2677
2678static void gen7_meta_disabled(struct intel_cmd *cmd)
2679{
2680 uint32_t *dw;
2681
2682 CMD_ASSERT(cmd, 7, 7.5);
2683
Chia-I Wu6032b892014-10-17 14:47:18 +08002684 /* 3DSTATE_CONSTANT_HS */
2685 cmd_batch_pointer(cmd, 7, &dw);
2686 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2687 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2688
2689 /* 3DSTATE_HS */
2690 cmd_batch_pointer(cmd, 7, &dw);
2691 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2692 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2693
2694 /* 3DSTATE_TE */
2695 cmd_batch_pointer(cmd, 4, &dw);
2696 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2697 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2698
2699 /* 3DSTATE_CONSTANT_DS */
2700 cmd_batch_pointer(cmd, 7, &dw);
2701 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2702 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2703
2704 /* 3DSTATE_DS */
2705 cmd_batch_pointer(cmd, 6, &dw);
2706 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2707 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2708
2709 /* 3DSTATE_CONSTANT_GS */
2710 cmd_batch_pointer(cmd, 7, &dw);
2711 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2712 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2713
2714 /* 3DSTATE_GS */
2715 cmd_batch_pointer(cmd, 7, &dw);
2716 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2717 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2718
2719 /* 3DSTATE_STREAMOUT */
2720 cmd_batch_pointer(cmd, 3, &dw);
2721 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2722 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2723
Chia-I Wu6032b892014-10-17 14:47:18 +08002724 /* 3DSTATE_SF */
2725 cmd_batch_pointer(cmd, 7, &dw);
2726 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2727 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2728
2729 /* 3DSTATE_SBE */
2730 cmd_batch_pointer(cmd, 14, &dw);
2731 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2732 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2733 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002734}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002735
Chia-I Wu29e6f502014-11-24 14:27:29 +08002736static void gen6_meta_clip(struct intel_cmd *cmd)
2737{
2738 const struct intel_cmd_meta *meta = cmd->bind.meta;
2739 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002740
Chia-I Wu29e6f502014-11-24 14:27:29 +08002741 /* 3DSTATE_CLIP */
2742 cmd_batch_pointer(cmd, 4, &dw);
2743 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2744 dw[1] = 0;
2745 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2746 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2747 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2748 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002749 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002750 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002751 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002752}
2753
2754static void gen6_meta_wm(struct intel_cmd *cmd)
2755{
2756 const struct intel_cmd_meta *meta = cmd->bind.meta;
2757 uint32_t *dw;
2758
2759 CMD_ASSERT(cmd, 6, 7.5);
2760
2761 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2762
2763 /* 3DSTATE_MULTISAMPLE */
2764 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2765 cmd_batch_pointer(cmd, 4, &dw);
2766 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2767 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2768 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2769 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2770 dw[2] = 0;
2771 dw[3] = 0;
2772 } else {
2773 cmd_batch_pointer(cmd, 3, &dw);
2774 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2775 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2776 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2777 dw[2] = 0;
2778 }
2779
2780 /* 3DSTATE_SAMPLE_MASK */
2781 cmd_batch_pointer(cmd, 2, &dw);
2782 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2783 dw[1] = (1 << meta->samples) - 1;
2784
2785 /* 3DSTATE_DRAWING_RECTANGLE */
2786 cmd_batch_pointer(cmd, 4, &dw);
2787 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002788 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2789 /* unused */
2790 dw[1] = 0;
2791 dw[2] = 0;
2792 } else {
2793 dw[1] = meta->dst.y << 16 | meta->dst.x;
2794 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2795 (meta->dst.x + meta->width - 1);
2796 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002797 dw[3] = 0;
2798}
2799
2800static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2801{
2802 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002803 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002804 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002805 uint32_t consts[8];
2806 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002807
2808 CMD_ASSERT(cmd, 6, 7.5);
2809
2810 /* underflow is fine here */
2811 offset_x = meta->src.x - meta->dst.x;
2812 offset_y = meta->src.y - meta->dst.y;
2813
2814 switch (meta->shader_id) {
2815 case INTEL_DEV_META_FS_COPY_MEM:
2816 case INTEL_DEV_META_FS_COPY_1D:
2817 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2818 case INTEL_DEV_META_FS_COPY_2D:
2819 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2820 case INTEL_DEV_META_FS_COPY_2D_MS:
2821 consts[0] = offset_x;
2822 consts[1] = offset_y;
2823 consts[2] = meta->src.layer;
2824 consts[3] = meta->src.lod;
2825 const_count = 4;
2826 break;
2827 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2828 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2829 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2830 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2831 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2832 consts[0] = offset_x;
2833 consts[1] = offset_y;
2834 consts[2] = meta->src.layer;
2835 consts[3] = meta->src.lod;
2836 consts[4] = meta->src.x;
2837 consts[5] = meta->width;
2838 const_count = 6;
2839 break;
2840 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2841 consts[0] = offset_x;
2842 consts[1] = offset_y;
2843 consts[2] = meta->width;
2844 const_count = 3;
2845 break;
2846 case INTEL_DEV_META_FS_CLEAR_COLOR:
2847 consts[0] = meta->clear_val[0];
2848 consts[1] = meta->clear_val[1];
2849 consts[2] = meta->clear_val[2];
2850 consts[3] = meta->clear_val[3];
2851 const_count = 4;
2852 break;
2853 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2854 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002855 consts[1] = meta->clear_val[1];
2856 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002857 break;
2858 case INTEL_DEV_META_FS_RESOLVE_2X:
2859 case INTEL_DEV_META_FS_RESOLVE_4X:
2860 case INTEL_DEV_META_FS_RESOLVE_8X:
2861 case INTEL_DEV_META_FS_RESOLVE_16X:
2862 consts[0] = offset_x;
2863 consts[1] = offset_y;
2864 const_count = 2;
2865 break;
2866 default:
2867 assert(!"unknown meta shader id");
2868 const_count = 0;
2869 break;
2870 }
2871
2872 /* this can be skipped but it makes state dumping prettier */
2873 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2874
2875 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2876}
2877
2878static void gen6_meta_ps(struct intel_cmd *cmd)
2879{
2880 const struct intel_cmd_meta *meta = cmd->bind.meta;
2881 const struct intel_pipeline_shader *sh =
2882 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2883 uint32_t offset, *dw;
2884
2885 CMD_ASSERT(cmd, 6, 6);
2886
Chia-I Wu29e6f502014-11-24 14:27:29 +08002887 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2888 /* 3DSTATE_CONSTANT_PS */
2889 cmd_batch_pointer(cmd, 5, &dw);
2890 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2891 dw[1] = 0;
2892 dw[2] = 0;
2893 dw[3] = 0;
2894 dw[4] = 0;
2895
2896 /* 3DSTATE_WM */
2897 cmd_batch_pointer(cmd, 9, &dw);
2898 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2899 dw[1] = 0;
2900 dw[2] = 0;
2901 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002902
2903 switch (meta->ds.op) {
2904 case INTEL_CMD_META_DS_HIZ_CLEAR:
2905 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2906 break;
2907 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2908 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2909 break;
2910 case INTEL_CMD_META_DS_RESOLVE:
2911 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2912 break;
2913 default:
2914 dw[4] = 0;
2915 break;
2916 }
2917
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002918 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002919 dw[6] = 0;
2920 dw[7] = 0;
2921 dw[8] = 0;
2922
Chia-I Wu3adf7212014-10-24 15:34:07 +08002923 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002924 }
2925
Chia-I Wu3adf7212014-10-24 15:34:07 +08002926 /* a normal color write */
2927 assert(meta->dst.valid && !sh->uses);
2928
Chia-I Wu6032b892014-10-17 14:47:18 +08002929 /* 3DSTATE_CONSTANT_PS */
2930 offset = gen6_meta_ps_constants(cmd);
2931 cmd_batch_pointer(cmd, 5, &dw);
2932 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002933 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002934 dw[1] = offset;
2935 dw[2] = 0;
2936 dw[3] = 0;
2937 dw[4] = 0;
2938
2939 /* 3DSTATE_WM */
2940 offset = emit_shader(cmd, sh);
2941 cmd_batch_pointer(cmd, 9, &dw);
2942 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2943 dw[1] = offset;
2944 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2945 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002946 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002947 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002948 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002949 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2950 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002951
Chia-I Wu6032b892014-10-17 14:47:18 +08002952 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002953 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002954 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2955 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2956 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2957 if (meta->samples > 1) {
2958 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2959 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2960 } else {
2961 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2962 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2963 }
2964 dw[7] = 0;
2965 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002966
2967 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002968}
2969
2970static void gen7_meta_ps(struct intel_cmd *cmd)
2971{
2972 const struct intel_cmd_meta *meta = cmd->bind.meta;
2973 const struct intel_pipeline_shader *sh =
2974 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2975 uint32_t offset, *dw;
2976
2977 CMD_ASSERT(cmd, 7, 7.5);
2978
Chia-I Wu29e6f502014-11-24 14:27:29 +08002979 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2980 /* 3DSTATE_WM */
2981 cmd_batch_pointer(cmd, 3, &dw);
2982 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002983
2984 switch (meta->ds.op) {
2985 case INTEL_CMD_META_DS_HIZ_CLEAR:
2986 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2987 break;
2988 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2989 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2990 break;
2991 case INTEL_CMD_META_DS_RESOLVE:
2992 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2993 break;
2994 default:
2995 dw[1] = 0;
2996 break;
2997 }
2998
2999 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003000
3001 /* 3DSTATE_CONSTANT_GS */
3002 cmd_batch_pointer(cmd, 7, &dw);
3003 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3004 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3005
3006 /* 3DSTATE_PS */
3007 cmd_batch_pointer(cmd, 8, &dw);
3008 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3009 dw[1] = 0;
3010 dw[2] = 0;
3011 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003012 /* required to avoid hangs */
3013 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003014 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003015 dw[5] = 0;
3016 dw[6] = 0;
3017 dw[7] = 0;
3018
Chia-I Wu3adf7212014-10-24 15:34:07 +08003019 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003020 }
3021
Chia-I Wu3adf7212014-10-24 15:34:07 +08003022 /* a normal color write */
3023 assert(meta->dst.valid && !sh->uses);
3024
Chia-I Wu6032b892014-10-17 14:47:18 +08003025 /* 3DSTATE_WM */
3026 cmd_batch_pointer(cmd, 3, &dw);
3027 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003028 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003029 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3030 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3031 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3032 dw[2] = 0;
3033
3034 /* 3DSTATE_CONSTANT_PS */
3035 offset = gen6_meta_ps_constants(cmd);
3036 cmd_batch_pointer(cmd, 7, &dw);
3037 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003038 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003039 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003040 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003041 dw[4] = 0;
3042 dw[5] = 0;
3043 dw[6] = 0;
3044
3045 /* 3DSTATE_PS */
3046 offset = emit_shader(cmd, sh);
3047 cmd_batch_pointer(cmd, 8, &dw);
3048 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3049 dw[1] = offset;
3050 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3051 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003052 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003053
3054 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3055 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003056 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003057
3058 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003059 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003060 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003061 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003062 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003063 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003064
3065 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3066 dw[6] = 0;
3067 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003068
3069 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003070}
3071
3072static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3073{
3074 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08003075 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003076
3077 CMD_ASSERT(cmd, 6, 7.5);
3078
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003079 if (!ds) {
3080 /* all zeros */
3081 static const struct intel_ds_view null_ds;
3082 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003083 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003084
3085 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003086 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3087 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3088 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003089
3090 if (cmd_gen(cmd) >= INTEL_GEN(7))
3091 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3092 else
3093 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003094}
3095
Chia-I Wu862c5572015-03-28 15:23:55 +08003096static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3097 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003098 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003099{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003100 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003101 if (data->set_offsets)
3102 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003103
Chia-I Wu862c5572015-03-28 15:23:55 +08003104 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003105 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003106 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003107 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003108 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003109 data->set_offset_count = 0;
3110 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003111 }
3112
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003113 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003114 }
3115
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003116 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003117 if (data->dynamic_offsets)
3118 intel_free(cmd, data->dynamic_offsets);
3119
3120 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003121 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003122 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003123 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003124 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003125 data->dynamic_offset_count = 0;
3126 return false;
3127 }
3128
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003129 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003130 }
3131
3132 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003133}
3134
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003135static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3136 const struct intel_pipeline *pipeline)
3137{
3138 cmd->bind.pipeline.graphics = pipeline;
3139
3140 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003141 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003142}
3143
3144static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3145 const struct intel_pipeline *pipeline)
3146{
3147 cmd->bind.pipeline.compute = pipeline;
3148
3149 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003150 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003151}
3152
Chia-I Wu862c5572015-03-28 15:23:55 +08003153static void cmd_copy_dset_data(struct intel_cmd *cmd,
3154 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003155 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003156 uint32_t index,
3157 const struct intel_desc_set *set,
3158 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003159{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003160 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003161
Chia-I Wu862c5572015-03-28 15:23:55 +08003162 assert(index < data->set_offset_count);
3163 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003164
Chia-I Wu862c5572015-03-28 15:23:55 +08003165 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003166 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003167 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003168
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003169 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003170 dynamic_offsets,
3171 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003172 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003173}
3174
Chia-I Wu3b04af52014-11-08 10:48:20 +08003175static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003176 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003177 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003178{
Chia-I Wu714df452015-01-01 07:55:04 +08003179 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003180 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003181 return;
3182 }
3183
Chia-I Wu714df452015-01-01 07:55:04 +08003184 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003185 cmd->bind.vertex.offset[binding] = offset;
3186}
3187
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003188static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003189 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003190 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003191{
Chia-I Wu714df452015-01-01 07:55:04 +08003192 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003193 cmd->bind.index.offset = offset;
3194 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003195}
3196
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003197static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003198 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003199{
3200 cmd->bind.state.viewport = state;
3201}
3202
3203static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003204 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003205{
3206 cmd->bind.state.raster = state;
3207}
3208
3209static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003210 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003211{
3212 cmd->bind.state.ds = state;
3213}
3214
3215static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003216 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003217{
3218 cmd->bind.state.blend = state;
3219}
3220
Chia-I Wuf98dd882015-02-10 04:17:47 +08003221static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3222{
3223 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3224 struct intel_pipeline_rmap *rmaps[5] = {
3225 pipeline->vs.rmap,
3226 pipeline->tcs.rmap,
3227 pipeline->tes.rmap,
3228 pipeline->gs.rmap,
3229 pipeline->fs.rmap,
3230 };
3231 uint32_t max_write;
3232 int i;
3233
3234 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3235 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3236 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3237
3238 /* pad first */
3239 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3240
3241 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3242 const struct intel_pipeline_rmap *rmap = rmaps[i];
3243 const uint32_t surface_count = (rmap) ?
3244 rmap->rt_count + rmap->texture_resource_count +
3245 rmap->resource_count + rmap->uav_count : 0;
3246
3247 if (surface_count) {
3248 /* SURFACE_STATEs */
3249 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3250
3251 /* BINDING_TABLE_STATE */
3252 max_write += u_align(sizeof(uint32_t) * surface_count,
3253 GEN6_ALIGNMENT_SURFACE_STATE);
3254 }
3255 }
3256
3257 return max_write;
3258}
3259
3260static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3261{
3262 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3263 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3264 uint32_t max_surface_write;
3265
3266 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3267 if (cmd->bind.meta)
3268 max_surface_write = 64 * sizeof(uint32_t);
3269 else
3270 max_surface_write = cmd_get_max_surface_write(cmd);
3271
3272 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3273 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3274 /* SBA expects page-aligned addresses */
3275 writer->sba_offset = writer->used & ~0xfff;
3276
3277 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3278
3279 cmd_batch_state_base_address(cmd);
3280 }
3281}
3282
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003283static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003284 uint32_t vertex_start,
3285 uint32_t vertex_count,
3286 uint32_t instance_start,
3287 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003288 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003289 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003290{
3291 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003292 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003293 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3294
3295 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003296
3297 emit_bounded_states(cmd);
3298
Chia-I Wuf98dd882015-02-10 04:17:47 +08003299 /* sanity check on cmd_get_max_surface_write() */
3300 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3301 surface_writer_used <= cmd_get_max_surface_write(cmd));
3302
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003303 if (indexed) {
3304 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003305 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003306
3307 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3308 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3309 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003310 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003311 cmd->bind.index.offset, cmd->bind.index.type,
3312 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003313 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003314 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003315 cmd->bind.index.offset, cmd->bind.index.type,
3316 p->primitive_restart);
3317 }
3318 } else {
3319 assert(!vertex_base);
3320 }
3321
3322 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3323 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3324 vertex_start, instance_count, instance_start, vertex_base);
3325 } else {
3326 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3327 vertex_start, instance_count, instance_start, vertex_base);
3328 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003329
Chia-I Wu707a29e2014-08-27 12:51:47 +08003330 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003331 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003332 /* need to re-emit all workarounds */
3333 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003334
3335 if (intel_debug & INTEL_DEBUG_NOCACHE)
3336 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003337}
3338
Chia-I Wuc14d1562014-10-17 09:49:22 +08003339void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3340{
Chia-I Wu6032b892014-10-17 14:47:18 +08003341 cmd->bind.meta = meta;
3342
Chia-I Wuf98dd882015-02-10 04:17:47 +08003343 cmd_adjust_state_base_address(cmd);
3344
Chia-I Wu6032b892014-10-17 14:47:18 +08003345 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003346 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003347
3348 gen6_meta_dynamic_states(cmd);
3349 gen6_meta_surface_states(cmd);
3350
3351 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3352 gen7_meta_urb(cmd);
3353 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003354 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003355 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003356 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003357 gen6_meta_wm(cmd);
3358 gen7_meta_ps(cmd);
3359 gen6_meta_depth_buffer(cmd);
3360
3361 cmd_wa_gen7_post_command_cs_stall(cmd);
3362 cmd_wa_gen7_post_command_depth_stall(cmd);
3363
Chia-I Wu29e6f502014-11-24 14:27:29 +08003364 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3365 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003366 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003367 } else {
3368 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3369 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003370 } else {
3371 gen6_meta_urb(cmd);
3372 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003373 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003374 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003375 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003376 gen6_meta_wm(cmd);
3377 gen6_meta_ps(cmd);
3378 gen6_meta_depth_buffer(cmd);
3379
Chia-I Wu29e6f502014-11-24 14:27:29 +08003380 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3381 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003382 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003383 } else {
3384 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3385 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003386 }
3387
3388 cmd->bind.draw_count++;
3389 /* need to re-emit all workarounds */
3390 cmd->bind.wa_flags = 0;
3391
3392 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003393
Chia-I Wubbc7d912015-02-27 14:59:50 -07003394 /* make the normal path believe the render pass has changed */
3395 cmd->bind.render_pass_changed = true;
3396
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003397 if (intel_debug & INTEL_DEBUG_NOCACHE)
3398 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003399}
3400
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003401static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3402{
3403 const uint8_t cmd_len = 2;
3404 uint32_t *dw;
3405 uint32_t pos;
3406
3407 if (cmd_gen(cmd) < INTEL_GEN(7.5)) {
3408 cmd->result = VK_ERROR_UNKNOWN;
3409 return;
3410 }
3411
3412 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3413 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3414 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3415 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3416 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3417
3418 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3419}
3420
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003421ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003422 VkCmdBuffer cmdBuffer,
3423 VkPipelineBindPoint pipelineBindPoint,
3424 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003425{
3426 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3427
3428 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003429 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003430 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003431 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003432 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003433 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003434 break;
3435 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003436 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003437 break;
3438 }
3439}
3440
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003441ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003442 VkCmdBuffer cmdBuffer,
3443 VkStateBindPoint stateBindPoint,
3444 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003445{
3446 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3447
3448 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003449 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003450 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003451 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003452 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003453 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003454 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003455 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003456 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003457 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003458 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003459 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003460 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003461 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003462 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003463 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003464 break;
3465 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003466 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003467 break;
3468 }
3469}
3470
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003471ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003472 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003473 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003474 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003475 uint32_t firstSet,
3476 uint32_t setCount,
3477 const VkDescriptorSet* pDescriptorSets,
3478 uint32_t dynamicOffsetCount,
3479 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003480{
3481 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003482 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003483 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003484 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003485 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003486
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003487 pipeline_layout = intel_pipeline_layout(layout);
3488
Chia-I Wub2755562014-08-20 13:38:52 +08003489 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003490 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003491 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003492 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003493 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003494 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003495 break;
3496 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003497 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003498 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003499 break;
3500 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003501
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003502 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003503 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3504
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003505 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003506 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003507 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003508 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003509 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003510 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003511 }
Chia-I Wub2755562014-08-20 13:38:52 +08003512}
3513
Tony Barbour8205d902015-04-16 15:59:00 -06003514
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003515ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3516 VkCmdBuffer cmdBuffer,
3517 uint32_t startBinding,
3518 uint32_t bindingCount,
3519 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003520 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003521{
3522 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003523
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003524 for (uint32_t i = 0; i < bindingCount; i++) {
3525 struct intel_buf *buf = intel_buf(pBuffers[i]);
3526 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3527 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003528}
3529
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003530ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003531 VkCmdBuffer cmdBuffer,
3532 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003533 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003534 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003535{
3536 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003537 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003538
Chia-I Wu714df452015-01-01 07:55:04 +08003539 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003540}
3541
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003542ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003543 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003544 uint32_t firstVertex,
3545 uint32_t vertexCount,
3546 uint32_t firstInstance,
3547 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003548{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003549 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003550
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003551 cmd_draw(cmd, firstVertex, vertexCount,
3552 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003553}
3554
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003555ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003556 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003557 uint32_t firstIndex,
3558 uint32_t indexCount,
3559 int32_t vertexOffset,
3560 uint32_t firstInstance,
3561 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003562{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003563 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003564
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003565 cmd_draw(cmd, firstIndex, indexCount,
3566 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003567}
3568
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003569ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003570 VkCmdBuffer cmdBuffer,
3571 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003572 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003573 uint32_t count,
3574 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003575{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003576 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3577
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003578 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003579}
3580
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003581ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003582 VkCmdBuffer cmdBuffer,
3583 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003584 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003585 uint32_t count,
3586 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003587{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003588 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3589
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003590 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003591}
3592
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003593ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003594 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003595 uint32_t x,
3596 uint32_t y,
3597 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003598{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003599 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3600
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003601 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003602}
3603
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003604ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003605 VkCmdBuffer cmdBuffer,
3606 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003607 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003608{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003609 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3610
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003611 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003612}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003613
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003614ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003615 VkCmdBuffer cmdBuffer,
3616 const VkRenderPassBegin* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003617{
3618 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003619 struct intel_render_pass *rp = (struct intel_render_pass *) pRenderPassBegin->renderPass;
3620 struct intel_fb *fb = (struct intel_fb *) pRenderPassBegin->framebuffer;
3621 unsigned i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003622
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003623 if (!cmd->primary) {
3624 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3625 return;
3626 }
3627
3628 cmd_begin_render_pass(cmd, rp, fb, pRenderPassBegin->contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003629
3630 /* issue load ops */
3631 for (i = 0; i < rp->colorAttachmentCount; i++) {
3632 if (rp->colorLoadOps[i] == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3633 /* issue clear of this attachment */
3634 const struct intel_rt_view *rt = fb->rt[i];
3635
3636 VkImageSubresourceRange ranges[1] = {{
3637 VK_IMAGE_ASPECT_COLOR,
3638 rt->mipLevel,
3639 1,
3640 rt->baseArraySlice,
3641 rt->array_size
3642 }};
3643
3644 cmd_meta_clear_color_image(cmdBuffer, (VkImage) rt->img,
3645 rp->colorLayouts[i],
3646 &rp->colorClearValues[i],
3647 1,
3648 ranges);
3649 }
3650 }
Chris Forbes4cf9d102015-06-22 18:46:05 +12003651
3652 if (rp->depthLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3653 const struct intel_ds_view *ds = fb->ds;
3654
3655 VkImageSubresourceRange ranges[1] = {{
3656 VK_IMAGE_ASPECT_DEPTH,
3657 0, /* ds->mipLevel, */
3658 1,
3659 0, /* ds->baseArraySlice, */
3660 ds->array_size
3661 }};
3662
3663 cmd_meta_clear_depth_stencil_image(cmdBuffer, (VkImage)ds->img,
3664 rp->depthStencilLayout,
3665 rp->depthLoadClearValue,
3666 0,
3667 1,
3668 ranges);
3669 }
3670
3671 if (rp->stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3672 const struct intel_ds_view *ds = fb->ds;
3673
3674 VkImageSubresourceRange ranges[1] = {{
3675 VK_IMAGE_ASPECT_STENCIL,
3676 0, /* ds->mipLevel, */
3677 1,
3678 0, /* ds->baseArraySlice, */
3679 ds->array_size
3680 }};
3681
3682 cmd_meta_clear_depth_stencil_image(cmdBuffer, (VkImage)ds->img,
3683 rp->depthStencilLayout,
3684 0.0f,
3685 rp->stencilLoadClearValue,
3686 1,
3687 ranges);
3688 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003689}
3690
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003691ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003692 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003693{
3694 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3695
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003696 cmd_end_render_pass(cmd);
3697}
3698
3699ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3700 VkCmdBuffer cmdBuffer,
3701 uint32_t cmdBuffersCount,
3702 const VkCmdBuffer* pCmdBuffers)
3703{
3704 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003705 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003706
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003707 if (!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3708 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) {
3709 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3710 return;
3711 }
3712
3713 for (i = 0; i < cmdBuffersCount; i++) {
3714 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3715
3716 if (secondary->primary) {
3717 cmd->result = VK_ERROR_INVALID_VALUE;
3718 break;
3719 }
3720
3721 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3722 }
3723
3724 if (i)
3725 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003726}