blob: 61d78431c59f81eda6d4646390bef86d87eda4a5 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wub2755562014-08-20 13:38:52 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600221 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffffffu);
226 break;
227 default:
228 supported = false;
229 break;
230 }
231
232 return supported;
233}
234
Chia-I Wu59c097e2014-08-21 10:51:07 +0800235static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800236 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600237 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600238 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 bool enable_cut_index)
240{
241 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800242 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800243 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600244 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245
246 CMD_ASSERT(cmd, 6, 7.5);
247
Chia-I Wu426072d2014-08-26 14:31:55 +0800248 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800249
250 /* the bit is moved to 3DSTATE_VF */
251 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
252 assert(!enable_cut_index);
253 if (enable_cut_index)
254 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
255
256 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600257 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800258 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
259 offset_align = 2;
260 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600261 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800262 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
263 offset_align = 4;
264 break;
265 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600266 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800267 return;
268 break;
269 }
270
271 if (offset % offset_align) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800273 return;
274 }
275
276 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800277 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800278
Chia-I Wu72292b72014-09-09 10:48:33 +0800279 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
280 dw[0] = dw0;
281
282 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800283 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
284 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285}
286
Chia-I Wu62a7f252014-08-29 11:31:16 +0800287static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
288 bool enable_cut_index,
289 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800290{
291 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800292 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800293
294 CMD_ASSERT(cmd, 7.5, 7.5);
295
Chia-I Wu426072d2014-08-26 14:31:55 +0800296 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800297 if (enable_cut_index)
298 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
299
Chia-I Wu72292b72014-09-09 10:48:33 +0800300 cmd_batch_pointer(cmd, cmd_len, &dw);
301 dw[0] = dw0;
302 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800303}
304
Cody Northrop293d4502015-05-05 09:38:03 -0600305static void gen6_add_scratch_space(struct intel_cmd *cmd,
306 uint32_t batch_pos,
307 const struct intel_pipeline *pipeline,
308 const struct intel_pipeline_shader *sh)
309{
310 int scratch_space;
311
312 CMD_ASSERT(cmd, 6, 7.5);
313
314 assert(sh->per_thread_scratch_size &&
315 sh->per_thread_scratch_size % 1024 == 0 &&
316 u_is_pow2(sh->per_thread_scratch_size) &&
317 sh->scratch_offset % 1024 == 0);
318 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
319
320 cmd_reserve_reloc(cmd, 1);
321 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
322 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
323}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600324
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800325static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
326{
Cody Northrop293d4502015-05-05 09:38:03 -0600327 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
328 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600330 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800331 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600332 int vue_read_len = 0;
333 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800334
Cody Northrop293d4502015-05-05 09:38:03 -0600335 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
336
337 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
338
339 // based on ilo_gpe_init_gs_cso_gen6
340 vue_read_len = (gs->in_count + 1) / 2;
341 if (!vue_read_len)
342 vue_read_len = 1;
343
344 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
345 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
346 GEN6_THREADDISP_SPF;
347
348 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
349 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
350 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
351
352 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
353 GEN6_GS_DW5_STATISTICS |
354 GEN6_GS_DW5_RENDER_ENABLE;
355
356 dw6 = GEN6_GS_DW6_GS_ENABLE;
357
358 if (gs->discard_adj)
359 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
360
361 } else {
362 dw2 = 0;
363 dw4 = 0;
364 dw5 = GEN6_GS_DW5_STATISTICS;
365 dw6 = 0;
366 }
367
368 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800369 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600370 dw[1] = cmd->bind.pipeline.gs_offset;
371 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800372 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600373 dw[4] = dw4;
374 dw[5] = dw5;
375 dw[6] = dw6;
376
377 if (gs->per_thread_scratch_size)
378 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800379}
380
Chia-I Wu62a7f252014-08-29 11:31:16 +0800381static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
382{
Cody Northrop293d4502015-05-05 09:38:03 -0600383 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
384 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800385 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600386 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800387 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600388 int vue_read_len = 0;
389 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800390
Cody Northrop293d4502015-05-05 09:38:03 -0600391 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
392
393 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
394
395 // based on upload_gs_state
396 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
397 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
398
399 vue_read_len = (gs->in_count + 1) / 2;
400 if (!vue_read_len)
401 vue_read_len = 1;
402
403 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
404 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
405 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
406 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
407 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
408
409
410 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
411 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
412 GEN7_GS_DW5_STATISTICS |
413 GEN7_GS_DW5_GS_ENABLE;
414
415 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
416 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
417
418 if (gs->include_primitive_id)
419 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
420
421 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
422 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
423 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
424 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
425 } else {
426 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
427 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
428 dw6 = 0;
429 }
430 } else {
431 dw2 = 0;
432 dw4 = 0;
433 dw5 = GEN7_GS_DW5_STATISTICS;
434 dw6 = 0;
435 }
436
437 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800438 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600439 dw[1] = cmd->bind.pipeline.gs_offset;
440 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800441 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600442 dw[4] = dw4;
443 dw[5] = dw5;
444 dw[6] = dw6;
445
446 if (gs->per_thread_scratch_size)
447 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800448}
449
Chia-I Wud88e02d2014-08-25 10:56:13 +0800450static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600451 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800452{
453 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800454 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800455 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457
458 CMD_ASSERT(cmd, 6, 7.5);
459
Chia-I Wu72292b72014-09-09 10:48:33 +0800460 cmd_batch_pointer(cmd, cmd_len, &dw);
461 dw[0] = dw0;
462
Chia-I Wud88e02d2014-08-25 10:56:13 +0800463 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800464 dw[1] = 0;
465 dw[2] = (height - 1) << 16 |
466 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800467 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800468 dw[1] = 1;
469 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800470 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800471
472 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800473}
474
Chia-I Wu8016a172014-08-29 18:31:32 +0800475static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
476 uint32_t body[6])
477{
478 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800479 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +0800480 const struct intel_render_pass_subpass *subpass =
481 cmd->bind.render_pass_subpass;
Cody Northrope4bc6942015-08-26 10:01:32 -0600482 const struct intel_dynamic_line_width *line_width = cmd->bind.state.line_width;
483 const struct intel_dynamic_depth_bias *depth_bias = cmd->bind.state.depth_bias;
Cody Northropf5bd2252015-08-17 11:10:49 -0600484 uint32_t dw1, dw2, dw3, dw4, dw5, dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800485
486 CMD_ASSERT(cmd, 6, 7.5);
487
488 dw1 = GEN7_SF_DW1_STATISTICS |
489 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
490 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
491 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
492 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700493 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800494
495 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wubdeed152015-07-09 12:16:29 +0800496 int format = GEN6_ZFORMAT_D32_FLOAT;
Chia-I Wu8016a172014-08-29 18:31:32 +0800497
Chia-I Wubdeed152015-07-09 12:16:29 +0800498 if (subpass->ds_index < rp->attachment_count) {
499 switch (rp->attachments[subpass->ds_index].format) {
500 case VK_FORMAT_D16_UNORM:
501 format = GEN6_ZFORMAT_D16_UNORM;
502 break;
503 case VK_FORMAT_D32_SFLOAT:
504 case VK_FORMAT_D32_SFLOAT_S8_UINT:
505 format = GEN6_ZFORMAT_D32_FLOAT;
506 break;
507 default:
508 assert(!"unsupported depth/stencil format");
509 break;
510 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800511 }
512
513 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
514 }
515
Tony Barbourfa6cac72015-01-16 14:27:35 -0700516 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800517
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700518 /* Scissor is always enabled */
519 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
520
Cody Northropf5bd2252015-08-17 11:10:49 -0600521 // TODO: line width support
Cody Northrope4bc6942015-08-26 10:01:32 -0600522 (void) line_width;
Cody Northropf5bd2252015-08-17 11:10:49 -0600523
Tony Barbourfa6cac72015-01-16 14:27:35 -0700524 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800525 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
526 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
527 } else {
528 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
529 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
530 }
531
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600532 dw3 = 2 << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
533 1 << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
534 2 << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800535 GEN7_SF_DW3_SUBPIXEL_8BITS;
536
Cody Northropf5bd2252015-08-17 11:10:49 -0600537 if (pipeline->depthBiasEnable) {
Cody Northrope4bc6942015-08-26 10:01:32 -0600538 dw4 = u_fui((float) depth_bias->depth_bias_info.depthBias * 2.0f);
539 dw5 = u_fui(depth_bias->depth_bias_info.slopeScaledDepthBias);
540 dw6 = u_fui(depth_bias->depth_bias_info.depthBiasClamp);
Cody Northropf5bd2252015-08-17 11:10:49 -0600541 } else {
542 dw4 = 0;
543 dw5 = 0;
544 dw6 = 0;
545 }
546
Chia-I Wu8016a172014-08-29 18:31:32 +0800547 body[0] = dw1;
548 body[1] = dw2;
549 body[2] = dw3;
Cody Northropf5bd2252015-08-17 11:10:49 -0600550 body[3] = dw4;
551 body[4] = dw5;
552 body[5] = dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800553}
554
Chia-I Wu8016a172014-08-29 18:31:32 +0800555static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
556{
557 const uint8_t cmd_len = 20;
558 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
559 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800560 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800561 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800562 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800563
564 CMD_ASSERT(cmd, 6, 6);
565
566 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800567
Chia-I Wu72292b72014-09-09 10:48:33 +0800568 cmd_batch_pointer(cmd, cmd_len, &dw);
569 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800570 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800571 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800572 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800573}
574
575static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
576{
577 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800578 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800579
580 CMD_ASSERT(cmd, 7, 7.5);
581
Chia-I Wu72292b72014-09-09 10:48:33 +0800582 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800583 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
584 (cmd_len - 2);
585 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800586}
587
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800588static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
589{
590 const uint8_t cmd_len = 4;
591 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
592 (cmd_len - 2);
593 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700594 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800595 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourde4124d2015-07-03 10:33:54 -0600596 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800597 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800598
599 CMD_ASSERT(cmd, 6, 7.5);
600
601 dw1 = GEN6_CLIP_DW1_STATISTICS;
602 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
603 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
604 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700605 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800606 }
607
608 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800609 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800610 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700611 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600612 2 << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
613 1 << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
614 2 << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800615
616 if (pipeline->rasterizerDiscardEnable)
617 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
618 else
619 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
620
621 if (pipeline->depthClipEnable)
622 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
623
624 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
625 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
626 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
627 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
628
629 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
630 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
631 (viewport->viewport_count - 1);
632
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600633 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600634 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600635 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
636 }
637
Chia-I Wu72292b72014-09-09 10:48:33 +0800638 cmd_batch_pointer(cmd, cmd_len, &dw);
639 dw[0] = dw0;
640 dw[1] = dw1;
641 dw[2] = dw2;
642 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800643}
644
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800645static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
646{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800647 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800648 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800649 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600650 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700651 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800652
653 CMD_ASSERT(cmd, 6, 6);
654
655 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
656
657 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
658 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
659
660 dw4 = GEN6_WM_DW4_STATISTICS |
661 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
662 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700663 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800664
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800665 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700666 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
667 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668
Cody Northrope86574e2015-02-24 14:15:29 -0700669 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700670 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700671
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800672 if (fs->uses & INTEL_SHADER_USE_KILL ||
673 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700674 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800675
Cody Northrope238deb2015-01-26 14:41:36 -0700676 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800677 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
678 if (fs->uses & INTEL_SHADER_USE_DEPTH)
679 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
680 if (fs->uses & INTEL_SHADER_USE_W)
681 dw5 |= GEN6_WM_DW5_PS_USE_W;
682
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700683 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700684 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800685
686 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700687 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688 GEN6_WM_DW6_ZW_INTERP_PIXEL |
689 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
690 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
691
Tony Barbourfa6cac72015-01-16 14:27:35 -0700692 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
694 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
695 } else {
696 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
697 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
698 }
699
Cody Northrope86574e2015-02-24 14:15:29 -0700700 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
701
Chia-I Wu784d3042014-12-19 14:30:04 +0800702 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800703 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800704 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800705 dw[2] = dw2;
706 dw[3] = 0; /* scratch */
707 dw[4] = dw4;
708 dw[5] = dw5;
709 dw[6] = dw6;
710 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700711 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800712
713 if (fs->per_thread_scratch_size)
714 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800715}
716
717static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
718{
719 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800720 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800721 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800722 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723
724 CMD_ASSERT(cmd, 7, 7.5);
725
726 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
727
728 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700729 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800730 GEN7_WM_DW1_ZW_INTERP_PIXEL |
731 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
732 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
733
734 if (fs->uses & INTEL_SHADER_USE_KILL ||
735 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700736 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800737
Cody Northrope238deb2015-01-26 14:41:36 -0700738 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
739
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800740 if (fs->uses & INTEL_SHADER_USE_DEPTH)
741 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
742 if (fs->uses & INTEL_SHADER_USE_W)
743 dw1 |= GEN7_WM_DW1_PS_USE_W;
744
745 dw2 = 0;
746
Tony Barbourfa6cac72015-01-16 14:27:35 -0700747 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800748 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
749 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
750 } else {
751 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
752 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
753 }
754
Chia-I Wu72292b72014-09-09 10:48:33 +0800755 cmd_batch_pointer(cmd, cmd_len, &dw);
756 dw[0] = dw0;
757 dw[1] = dw1;
758 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800759}
760
761static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
762{
763 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800764 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800765 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700766 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600767 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800768
769 CMD_ASSERT(cmd, 7, 7.5);
770
771 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
772
773 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
774 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
775
776 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700777 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800778
Cody Northrope86574e2015-02-24 14:15:29 -0700779 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700780 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700781
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800782 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800783 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700784 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800785 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800786 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800787 }
788
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800789 if (fs->in_count)
790 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
791
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700792 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800793 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
794
795 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
796 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700797 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
798
799 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800800
Chia-I Wu784d3042014-12-19 14:30:04 +0800801 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800802 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800803 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800804 dw[2] = dw2;
805 dw[3] = 0; /* scratch */
806 dw[4] = dw4;
807 dw[5] = dw5;
808 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700809 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800810
811 if (fs->per_thread_scratch_size)
812 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800813}
814
Chia-I Wu8ada4242015-03-02 11:19:33 -0700815static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
816 uint32_t sample_count)
817{
818 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
819 uint32_t dw1, dw2, dw3, *dw;
820
821 CMD_ASSERT(cmd, 6, 7.5);
822
823 switch (sample_count) {
824 case 4:
825 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
826 dw2 = cmd->dev->sample_pattern_4x;
827 dw3 = 0;
828 break;
829 case 8:
830 assert(cmd_gen(cmd) >= INTEL_GEN(7));
831 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
832 dw2 = cmd->dev->sample_pattern_8x[0];
833 dw3 = cmd->dev->sample_pattern_8x[1];
834 break;
835 default:
836 assert(sample_count <= 1);
837 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
838 dw2 = 0;
839 dw3 = 0;
840 break;
841 }
842
843 cmd_batch_pointer(cmd, cmd_len, &dw);
844
845 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
846 dw[1] = dw1;
847 dw[2] = dw2;
848 if (cmd_gen(cmd) >= INTEL_GEN(7))
849 dw[3] = dw3;
850}
851
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800852static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800853 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700854 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800855{
856 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600858 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800859
860 CMD_ASSERT(cmd, 6, 7.5);
861
862 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
864 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800865 dw0 |= (cmd_len - 2);
866
Chia-I Wu72292b72014-09-09 10:48:33 +0800867 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
868 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700869
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800870 dw[1] = view->att_cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700871 /* note that we only enable HiZ on Gen7+ */
872 if (!optimal_ds)
873 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
874
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 dw[2] = 0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800876 dw[3] = view->att_cmd[2];
877 dw[4] = view->att_cmd[3];
878 dw[5] = view->att_cmd[4];
879 dw[6] = view->att_cmd[5];
Chia-I Wu72292b72014-09-09 10:48:33 +0800880
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600881 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800882 cmd_reserve_reloc(cmd, 1);
883 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800884 view->att_cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600885 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800886}
887
888static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800889 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700890 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800891{
892 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800893 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600894 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800895
896 CMD_ASSERT(cmd, 6, 7.5);
897
898 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800899 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
900 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800901 dw0 |= (cmd_len - 2);
902
Chia-I Wu72292b72014-09-09 10:48:33 +0800903 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
904 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800905
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700906 if (view->has_stencil) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800907 dw[1] = view->att_cmd[6];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700908
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 cmd_reserve_reloc(cmd, 1);
910 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800911 view->att_cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700912 } else {
913 dw[1] = 0;
914 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600915 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800916}
917
918static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800919 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700920 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800921{
922 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800923 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600924 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800925
926 CMD_ASSERT(cmd, 6, 7.5);
927
928 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800929 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
930 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800931 dw0 |= (cmd_len - 2);
932
Chia-I Wu72292b72014-09-09 10:48:33 +0800933 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
934 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800935
Chia-I Wu73520ac2015-02-19 11:17:45 -0700936 if (view->has_hiz && optimal_ds) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800937 dw[1] = view->att_cmd[8];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700938
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 cmd_reserve_reloc(cmd, 1);
940 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800941 view->att_cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700942 } else {
943 dw[1] = 0;
944 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600945 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800946}
947
Chia-I Wuf8231032014-08-25 10:44:45 +0800948static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
949 uint32_t clear_val)
950{
951 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800952 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800953 GEN6_CLEAR_PARAMS_DW0_VALID |
954 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800956
957 CMD_ASSERT(cmd, 6, 6);
958
Chia-I Wu72292b72014-09-09 10:48:33 +0800959 cmd_batch_pointer(cmd, cmd_len, &dw);
960 dw[0] = dw0;
961 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800962}
963
964static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
965 uint32_t clear_val)
966{
967 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800968 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800969 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800970 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800971
972 CMD_ASSERT(cmd, 7, 7.5);
973
Chia-I Wu72292b72014-09-09 10:48:33 +0800974 cmd_batch_pointer(cmd, cmd_len, &dw);
975 dw[0] = dw0;
976 dw[1] = clear_val;
977 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800978}
979
Chia-I Wu302742d2014-08-22 10:28:29 +0800980static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800981 uint32_t blend_offset,
982 uint32_t ds_offset,
983 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800984{
985 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800986 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987
988 CMD_ASSERT(cmd, 6, 6);
989
Chia-I Wu426072d2014-08-26 14:31:55 +0800990 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800991 (cmd_len - 2);
992
Chia-I Wu72292b72014-09-09 10:48:33 +0800993 cmd_batch_pointer(cmd, cmd_len, &dw);
994 dw[0] = dw0;
995 dw[1] = blend_offset | 1;
996 dw[2] = ds_offset | 1;
997 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800998}
999
Chia-I Wu1744cca2014-08-22 11:10:17 +08001000static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001001 uint32_t clip_offset,
1002 uint32_t sf_offset,
1003 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001004{
1005 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001006 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001007
1008 CMD_ASSERT(cmd, 6, 6);
1009
Chia-I Wu426072d2014-08-26 14:31:55 +08001010 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001011 GEN6_VP_PTR_DW0_CLIP_CHANGED |
1012 GEN6_VP_PTR_DW0_SF_CHANGED |
1013 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001014 (cmd_len - 2);
1015
Chia-I Wu72292b72014-09-09 10:48:33 +08001016 cmd_batch_pointer(cmd, cmd_len, &dw);
1017 dw[0] = dw0;
1018 dw[1] = clip_offset;
1019 dw[2] = sf_offset;
1020 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001021}
1022
1023static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001024 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001025{
1026 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001027 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001028
1029 CMD_ASSERT(cmd, 6, 6);
1030
Chia-I Wu426072d2014-08-26 14:31:55 +08001031 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001032 (cmd_len - 2);
1033
Chia-I Wu72292b72014-09-09 10:48:33 +08001034 cmd_batch_pointer(cmd, cmd_len, &dw);
1035 dw[0] = dw0;
1036 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001037}
1038
Chia-I Wu42a56202014-08-23 16:47:48 +08001039static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001040 uint32_t vs_offset,
1041 uint32_t gs_offset,
1042 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001043{
1044 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001045 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001046
1047 CMD_ASSERT(cmd, 6, 6);
1048
Chia-I Wu426072d2014-08-26 14:31:55 +08001049 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001050 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1051 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1052 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001053 (cmd_len - 2);
1054
Chia-I Wu72292b72014-09-09 10:48:33 +08001055 cmd_batch_pointer(cmd, cmd_len, &dw);
1056 dw[0] = dw0;
1057 dw[1] = vs_offset;
1058 dw[2] = gs_offset;
1059 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001060}
1061
Chia-I Wu257e75e2014-08-29 14:06:35 +08001062static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001063 uint32_t vs_offset,
1064 uint32_t gs_offset,
1065 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001066{
1067 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001068 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001069
1070 CMD_ASSERT(cmd, 6, 6);
1071
1072 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001073 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1074 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1075 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001076 (cmd_len - 2);
1077
Chia-I Wu72292b72014-09-09 10:48:33 +08001078 cmd_batch_pointer(cmd, cmd_len, &dw);
1079 dw[0] = dw0;
1080 dw[1] = vs_offset;
1081 dw[2] = gs_offset;
1082 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001083}
1084
Chia-I Wu302742d2014-08-22 10:28:29 +08001085static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001086 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001087{
1088 const uint8_t cmd_len = 2;
1089 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1090 GEN6_RENDER_SUBTYPE_3D |
1091 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001092 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001093
Chia-I Wu72292b72014-09-09 10:48:33 +08001094 cmd_batch_pointer(cmd, cmd_len, &dw);
1095 dw[0] = dw0;
1096 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001097}
1098
Chia-I Wua6c4f152014-12-02 04:19:58 +08001099static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001100{
Chia-I Wue6073342014-11-30 09:43:42 +08001101 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001102 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1103 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001104
1105 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001106 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001107
Tony Barbourfa6cac72015-01-16 14:27:35 -07001108 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001109}
1110
Chia-I Wu72292b72014-09-09 10:48:33 +08001111static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Cody Northrop2605cb02015-08-18 15:21:16 -06001112 const struct intel_dynamic_stencil *stencil_state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001113{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001114 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001115 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001116 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001117 uint32_t dw[3];
1118
1119 dw[0] = pipeline->cmd_depth_stencil;
Cody Northrop2605cb02015-08-18 15:21:16 -06001120
1121 /* TODO: enable back facing stencil state */
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001122 /* same read and write masks for both front and back faces */
Cody Northrope4bc6942015-08-26 10:01:32 -06001123 dw[1] = (stencil_state->stencil_info_front.stencilCompareMask & 0xff) << 24 |
Cody Northrop2605cb02015-08-18 15:21:16 -06001124 (stencil_state->stencil_info_front.stencilWriteMask & 0xff) << 16 |
Cody Northrope4bc6942015-08-26 10:01:32 -06001125 (stencil_state->stencil_info_front.stencilCompareMask & 0xff) << 8 |
Cody Northrop2605cb02015-08-18 15:21:16 -06001126 (stencil_state->stencil_info_front.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001127 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001128
1129 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001130
Cody Northrop2605cb02015-08-18 15:21:16 -06001131 if (stencil_state->stencil_info_front.stencilWriteMask && pipeline->stencilTestEnable)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001132 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001133
Chia-I Wu00b51a82014-09-09 12:07:37 +08001134 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001135 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001136}
1137
Chia-I Wu72292b72014-09-09 10:48:33 +08001138static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001139 uint32_t stencil_ref,
1140 const uint32_t blend_color[4])
1141{
Chia-I Wue6073342014-11-30 09:43:42 +08001142 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001143 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001144 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001145
1146 CMD_ASSERT(cmd, 6, 7.5);
1147
Chia-I Wu00b51a82014-09-09 12:07:37 +08001148 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1149 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001150 dw[0] = stencil_ref;
1151 dw[1] = 0;
1152 dw[2] = blend_color[0];
1153 dw[3] = blend_color[1];
1154 dw[4] = blend_color[2];
1155 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001156
Chia-I Wu72292b72014-09-09 10:48:33 +08001157 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001158}
1159
Chia-I Wu8370b402014-08-29 12:28:37 +08001160static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001161{
Chia-I Wu8370b402014-08-29 12:28:37 +08001162 CMD_ASSERT(cmd, 6, 7.5);
1163
Chia-I Wu707a29e2014-08-27 12:51:47 +08001164 if (!cmd->bind.draw_count)
1165 return;
1166
Chia-I Wu8370b402014-08-29 12:28:37 +08001167 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001168 return;
1169
Chia-I Wu8370b402014-08-29 12:28:37 +08001170 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001171
1172 /*
1173 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1174 *
1175 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1176 * pipe-control with a post-sync op and no write-cache flushes."
1177 *
1178 * The workaround below necessitates this workaround.
1179 */
1180 gen6_PIPE_CONTROL(cmd,
1181 GEN6_PIPE_CONTROL_CS_STALL |
1182 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001183 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001184
Chia-I Wud6d079d2014-08-31 13:14:21 +08001185 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1186 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001187}
1188
Chia-I Wu8370b402014-08-29 12:28:37 +08001189static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001190{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001191 CMD_ASSERT(cmd, 6, 7.5);
1192
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001193 if (!cmd->bind.draw_count)
1194 return;
1195
Chia-I Wud6d079d2014-08-31 13:14:21 +08001196 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1197 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001198}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001199
Chia-I Wu8370b402014-08-29 12:28:37 +08001200static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1201{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001202 CMD_ASSERT(cmd, 7, 7.5);
1203
Chia-I Wu8370b402014-08-29 12:28:37 +08001204 if (!cmd->bind.draw_count)
1205 return;
1206
1207 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001208
1209 gen6_PIPE_CONTROL(cmd,
1210 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001211 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001212}
1213
Chia-I Wu8370b402014-08-29 12:28:37 +08001214static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1215{
1216 CMD_ASSERT(cmd, 7, 7.5);
1217
Chia-I Wu8370b402014-08-29 12:28:37 +08001218 /*
1219 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1220 *
1221 * "One of the following must also be set (when CS stall is set):
1222 *
1223 * * Render Target Cache Flush Enable ([12] of DW1)
1224 * * Depth Cache Flush Enable ([0] of DW1)
1225 * * Stall at Pixel Scoreboard ([1] of DW1)
1226 * * Depth Stall ([13] of DW1)
1227 * * Post-Sync Operation ([13] of DW1)"
1228 */
1229 gen6_PIPE_CONTROL(cmd,
1230 GEN6_PIPE_CONTROL_CS_STALL |
1231 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001232 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001233}
1234
1235static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1236{
1237 CMD_ASSERT(cmd, 7, 7.5);
1238
Chia-I Wu8370b402014-08-29 12:28:37 +08001239 cmd_wa_gen6_pre_depth_stall_write(cmd);
1240
Chia-I Wud6d079d2014-08-31 13:14:21 +08001241 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001242}
1243
1244static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1245{
1246 CMD_ASSERT(cmd, 6, 7.5);
1247
1248 if (!cmd->bind.draw_count)
1249 return;
1250
1251 /*
1252 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1253 *
1254 * "Driver must guarentee that all the caches in the depth pipe are
1255 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1256 * requires driver to send a PIPE_CONTROL with a CS stall along with
1257 * a Depth Flush prior to this command."
1258 *
1259 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1260 *
1261 * "Driver must ierarchi that all the caches in the depth pipe are
1262 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1263 * requires driver to send a PIPE_CONTROL with a CS stall along with
1264 * a Depth Flush prior to this command.
1265 */
1266 gen6_PIPE_CONTROL(cmd,
1267 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1268 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001269 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001270}
1271
1272static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1273{
1274 CMD_ASSERT(cmd, 6, 7.5);
1275
1276 if (!cmd->bind.draw_count)
1277 return;
1278
1279 /*
1280 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1281 *
1282 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1283 * and a post sync operation prior to the group of depth
1284 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1285 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1286 *
1287 * This workaround satifies all the conditions.
1288 */
1289 cmd_wa_gen6_pre_depth_stall_write(cmd);
1290
1291 /*
1292 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1293 *
1294 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1295 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1296 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1297 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1298 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1299 * Depth Flush Bit set, followed by another pipelined depth stall
1300 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1301 * guarantee that the pipeline from WM onwards is already flushed
1302 * (e.g., via a preceding MI_FLUSH)."
1303 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001304 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1305 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1306 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001307}
1308
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001309void cmd_batch_state_base_address(struct intel_cmd *cmd)
1310{
1311 const uint8_t cmd_len = 10;
1312 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1313 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001314 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001315 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001316 uint32_t pos;
1317 uint32_t *dw;
1318
1319 CMD_ASSERT(cmd, 6, 7.5);
1320
1321 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1322
1323 dw[0] = dw0;
1324 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001325 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001326 dw[2] = 1;
1327 dw[3] = 1;
1328 dw[4] = 1;
1329 dw[5] = 1;
1330 /* end offsets */
1331 dw[6] = 1;
1332 dw[7] = 1 + 0xfffff000;
1333 dw[8] = 1 + 0xfffff000;
1334 dw[9] = 1;
1335
1336 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001337 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1338 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1339 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1340 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1341 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1342 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001343}
1344
Chia-I Wu7c853562015-02-27 14:35:08 -07001345void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1346{
1347 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1348 const uint8_t cmd_len = 2;
1349 uint32_t offset = 0;
1350 uint32_t *dw;
1351
1352 if (cmd_gen(cmd) <= INTEL_GEN(6))
1353 return;
1354
1355 CMD_ASSERT(cmd, 7, 7.5);
1356
1357 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1358 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1359 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1360 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1361 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1362 offset += size;
1363
1364 dw += 2;
1365 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1366 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1367 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1368
1369 dw += 2;
1370 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1371 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1372 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1373
1374 dw += 2;
1375 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1376 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1377 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1378
1379 dw += 2;
1380 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1381 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1382 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1383
1384 /*
1385 *
1386 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1387 *
1388 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1389 * in the ring after this instruction
1390 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1391 */
1392 cmd_wa_gen7_post_command_cs_stall(cmd);
1393}
1394
Chia-I Wu525c6602014-08-27 10:22:34 +08001395void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1396{
Mike Stroyan552fda42015-01-30 17:21:08 -07001397 if (pipe_control_dw0 == 0)
1398 return;
1399
Chia-I Wu525c6602014-08-27 10:22:34 +08001400 if (!cmd->bind.draw_count)
1401 return;
1402
1403 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1404
Chia-I Wu8370b402014-08-29 12:28:37 +08001405 /*
1406 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1407 *
1408 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1409 * PIPE_CONTROL with any non-zero post-sync-op is required."
1410 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001411 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001412 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001413
Chia-I Wu092279a2014-08-30 19:05:30 +08001414 /*
1415 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1416 *
1417 * "One of the following must also be set (when CS stall is set):
1418 *
1419 * * Render Target Cache Flush Enable ([12] of DW1)
1420 * * Depth Cache Flush Enable ([0] of DW1)
1421 * * Stall at Pixel Scoreboard ([1] of DW1)
1422 * * Depth Stall ([13] of DW1)
1423 * * Post-Sync Operation ([13] of DW1)"
1424 */
1425 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1426 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1427 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1428 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1429 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1430 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1431
Chia-I Wud6d079d2014-08-31 13:14:21 +08001432 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001433}
1434
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001435void cmd_batch_flush_all(struct intel_cmd *cmd)
1436{
1437 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1438 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1439 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1440 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1441 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1442 GEN6_PIPE_CONTROL_CS_STALL);
1443}
1444
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001445void cmd_batch_depth_count(struct intel_cmd *cmd,
1446 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001447 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001448{
1449 cmd_wa_gen6_pre_depth_stall_write(cmd);
1450
1451 gen6_PIPE_CONTROL(cmd,
1452 GEN6_PIPE_CONTROL_DEPTH_STALL |
1453 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001454 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001455}
1456
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001457void cmd_batch_timestamp(struct intel_cmd *cmd,
1458 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001459 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001460{
1461 /* need any WA or stall? */
1462 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1463}
1464
1465void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001466 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001467 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001468 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001469 uint64_t val)
1470{
1471 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001472 gen6_PIPE_CONTROL(cmd,
1473 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1474 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001475}
1476
Chia-I Wu302742d2014-08-22 10:28:29 +08001477static void gen6_cc_states(struct intel_cmd *cmd)
1478{
Cody Northrope4bc6942015-08-26 10:01:32 -06001479 const struct intel_dynamic_blend *blend = cmd->bind.state.blend;
Cody Northrop2605cb02015-08-18 15:21:16 -06001480 const struct intel_dynamic_stencil *ss = cmd->bind.state.stencil;
Chia-I Wu72292b72014-09-09 10:48:33 +08001481 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001482 uint32_t stencil_ref;
1483 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001484
1485 CMD_ASSERT(cmd, 6, 6);
1486
Chia-I Wua6c4f152014-12-02 04:19:58 +08001487 blend_offset = gen6_BLEND_STATE(cmd);
1488
1489 if (blend)
Cody Northrope4bc6942015-08-26 10:01:32 -06001490 memcpy(blend_color, blend->blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001491 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001492 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001493
Cody Northrop2605cb02015-08-18 15:21:16 -06001494 if (ss) {
1495 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1496 /* TODO: enable back facing stencil state */
1497 /* same reference for both front and back faces */
1498 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1499 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001500 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001501 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001502 stencil_ref = 0;
1503 }
1504
Chia-I Wu72292b72014-09-09 10:48:33 +08001505 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001506
Chia-I Wu72292b72014-09-09 10:48:33 +08001507 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001508}
1509
Chia-I Wu1744cca2014-08-22 11:10:17 +08001510static void gen6_viewport_states(struct intel_cmd *cmd)
1511{
Tony Barbourde4124d2015-07-03 10:33:54 -06001512 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001513 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001514
1515 if (!viewport)
1516 return;
1517
Tony Barbourfa6cac72015-01-16 14:27:35 -07001518 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001519 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001520
1521 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001522 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001523 viewport->cmd);
1524
1525 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001526 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001527 &viewport->cmd[viewport->cmd_clip_pos]);
1528
1529 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001530 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001531 &viewport->cmd[viewport->cmd_cc_pos]);
1532
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001533 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1534 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1535 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001536
1537 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001538 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001539
Chia-I Wub1d450a2014-09-09 13:48:03 +08001540 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001541}
1542
Chia-I Wu302742d2014-08-22 10:28:29 +08001543static void gen7_cc_states(struct intel_cmd *cmd)
1544{
Cody Northrope4bc6942015-08-26 10:01:32 -06001545 const struct intel_dynamic_blend *blend = cmd->bind.state.blend;
1546 const struct intel_dynamic_depth_bounds *ds = cmd->bind.state.depth_bounds;
Cody Northrop2605cb02015-08-18 15:21:16 -06001547 const struct intel_dynamic_stencil *ss = cmd->bind.state.stencil;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001548 uint32_t stencil_ref;
1549 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001550 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001551
1552 CMD_ASSERT(cmd, 7, 7.5);
1553
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001554 if (!blend && !ds)
1555 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001556
Chia-I Wua6c4f152014-12-02 04:19:58 +08001557 offset = gen6_BLEND_STATE(cmd);
1558 gen7_3dstate_pointer(cmd,
1559 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001560
Chia-I Wua6c4f152014-12-02 04:19:58 +08001561 if (blend)
Cody Northrope4bc6942015-08-26 10:01:32 -06001562 memcpy(blend_color, blend->blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001563 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001564 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001565
Cody Northrop2605cb02015-08-18 15:21:16 -06001566 if (ss) {
1567 offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1568 /* TODO: enable back facing stencil state */
1569 /* same reference for both front and back faces */
1570 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1571 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001572 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001573 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1574 offset);
Cody Northrop2605cb02015-08-18 15:21:16 -06001575 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1576 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001577 } else {
1578 stencil_ref = 0;
1579 }
1580
Chia-I Wu72292b72014-09-09 10:48:33 +08001581 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001582 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001583 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001584}
1585
Chia-I Wu1744cca2014-08-22 11:10:17 +08001586static void gen7_viewport_states(struct intel_cmd *cmd)
1587{
Tony Barbourde4124d2015-07-03 10:33:54 -06001588 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001589 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001590
1591 if (!viewport)
1592 return;
1593
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001594 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001595
Chia-I Wub1d450a2014-09-09 13:48:03 +08001596 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001597 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001598 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001599 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001600 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1601 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001602
1603 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001604 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001605 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001606 gen7_3dstate_pointer(cmd,
1607 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001608 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001609
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001610 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1611 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1612 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1613 gen7_3dstate_pointer(cmd,
1614 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1615 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001616}
1617
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001618static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001619 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001620{
1621 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001622 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001623
Chia-I Wu72292b72014-09-09 10:48:33 +08001624 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001625
1626 dw[0] = GEN6_RENDER_TYPE_RENDER |
1627 GEN6_RENDER_SUBTYPE_3D |
1628 subop | (cmd_len - 2);
1629 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001630 dw[2] = 0;
1631 dw[3] = 0;
1632 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001633}
1634
1635static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001636 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001637{
1638 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001639 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001640
Chia-I Wu72292b72014-09-09 10:48:33 +08001641 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001642
1643 dw[0] = GEN6_RENDER_TYPE_RENDER |
1644 GEN6_RENDER_SUBTYPE_3D |
1645 subop | (cmd_len - 2);
1646 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001647 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001648 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001649 dw[4] = 0;
1650 dw[5] = 0;
1651 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001652}
1653
Chia-I Wu625105f2014-10-13 15:35:29 +08001654static uint32_t emit_samplers(struct intel_cmd *cmd,
1655 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001656{
Chia-I Wu862c5572015-03-28 15:23:55 +08001657 const struct intel_desc_region *region = cmd->dev->desc_region;
1658 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001659 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1660 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001661 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001662 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001663 uint32_t surface_count;
1664 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001665
1666 CMD_ASSERT(cmd, 6, 7.5);
1667
Chia-I Wu625105f2014-10-13 15:35:29 +08001668 if (!rmap || !rmap->sampler_count)
1669 return 0;
1670
Cody Northrop40316a32014-12-09 19:08:33 -07001671 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001672
Chia-I Wudcb509d2014-12-10 08:53:10 +08001673 /*
1674 * note that we cannot call cmd_state_pointer() here as the following
1675 * cmd_state_pointer() would invalidate the pointer
1676 */
1677 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001678 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001679 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001680
1681 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001682 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001683 4 * rmap->sampler_count, &sampler_dw);
1684
Chia-I Wudcb509d2014-12-10 08:53:10 +08001685 cmd_state_update(cmd, border_offset,
1686 border_stride * rmap->sampler_count, &border_dw);
1687
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001688 for (i = 0; i < rmap->sampler_count; i++) {
1689 const struct intel_pipeline_rmap_slot *slot =
1690 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001691 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001692 const struct intel_sampler *sampler;
1693
Chia-I Wuf8385062015-01-04 16:27:24 +08001694 switch (slot->type) {
1695 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001696 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1697 &data->set_offsets[slot->index]);
1698 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001699 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001700 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001701 sampler = NULL;
1702 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001703 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001704 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001705 sampler = NULL;
1706 break;
1707 }
1708
1709 if (sampler) {
1710 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1711
1712 sampler_dw[0] = sampler->cmd[0];
1713 sampler_dw[1] = sampler->cmd[1];
1714 sampler_dw[2] = border_offset;
1715 sampler_dw[3] = sampler->cmd[2];
1716 } else {
1717 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1718 sampler_dw[1] = 0;
1719 sampler_dw[2] = 0;
1720 sampler_dw[3] = 0;
1721 }
1722
1723 border_offset += border_stride * 4;
1724 border_dw += border_stride;
1725 sampler_dw += 4;
1726 }
1727
Chia-I Wu625105f2014-10-13 15:35:29 +08001728 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001729}
1730
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001731static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001732 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001733 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001734{
Chia-I Wu862c5572015-03-28 15:23:55 +08001735 const struct intel_desc_region *region = cmd->dev->desc_region;
1736 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001737 const uint32_t sba_offset =
1738 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001739 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001740 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001741
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001742 CMD_ASSERT(cmd, 6, 7.5);
1743
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001744 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001745 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001746 if (!surface_count)
1747 return 0;
1748
Chia-I Wu42a56202014-08-23 16:47:48 +08001749 assert(surface_count <= ARRAY_SIZE(binding_table));
1750
1751 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001752 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001753 struct intel_null_view null_view;
1754 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001755
Chia-I Wuf8385062015-01-04 16:27:24 +08001756 switch (slot->type) {
1757 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001758 {
Chia-I Wubdeed152015-07-09 12:16:29 +08001759 const struct intel_render_pass_subpass *subpass =
1760 cmd->bind.render_pass_subpass;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001761 const struct intel_fb *fb = cmd->bind.fb;
1762 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08001763 (slot->index < subpass->color_count &&
1764 subpass->color_indices[slot->index] < fb->view_count) ?
1765 fb->views[subpass->color_indices[slot->index]] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001766
Chia-I Wu787a05b2014-12-05 11:02:20 +08001767 if (view) {
1768 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1769 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001770 view->cmd_len, view->att_cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001771
Chia-I Wu787a05b2014-12-05 11:02:20 +08001772 cmd_reserve_reloc(cmd, 1);
1773 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001774 view->att_cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu787a05b2014-12-05 11:02:20 +08001775 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001776 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001777 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001778 }
1779 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001780 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001781 {
Tony Barbour22a30862015-04-22 09:02:32 -06001782 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001783 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001784 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001785 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001786 const struct intel_mem *mem;
1787 bool read_only;
1788 const uint32_t *cmd_data;
1789 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001790
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001791 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001792 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001793
Chia-I Wu862c5572015-03-28 15:23:55 +08001794 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1795 &data->set_offsets[slot->index]);
1796
1797 intel_desc_region_read_surface(region, &desc_offset, stage,
1798 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001799 if (mem) {
1800 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001801 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001802 const uint32_t reloc_flags =
1803 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001804
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001805 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001806 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001807 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001808
1809 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001810 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1811 cmd_data[1] + dynamic_offset, reloc_flags);
1812 } else {
1813 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001814 }
1815 }
1816 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001817 case INTEL_PIPELINE_RMAP_UNUSED:
1818 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001819 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001820 default:
1821 assert(!"unexpected rmap type");
1822 need_null_view = true;
1823 break;
1824 }
1825
1826 if (need_null_view) {
1827 intel_null_view_init(&null_view, cmd->dev);
1828 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1829 GEN6_ALIGNMENT_SURFACE_STATE,
1830 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001831 }
1832
Chia-I Wuf98dd882015-02-10 04:17:47 +08001833 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001834 }
1835
Chia-I Wuf98dd882015-02-10 04:17:47 +08001836 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001837 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001838 surface_count, binding_table) - sba_offset;
1839
1840 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1841 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1842
1843 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001844}
1845
Chia-I Wu1d125092014-10-08 08:49:38 +08001846static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1847{
1848 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001849 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1850 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001851 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001852
1853 CMD_ASSERT(cmd, 6, 7.5);
1854
1855 if (!pipeline->vb_count)
1856 return;
1857
1858 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1859
1860 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1861 dw++;
1862 pos++;
1863
1864 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001865 assert(pipeline->vb[i].strideInBytes <= 2048);
1866
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001867 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001868 pipeline->vb[i].strideInBytes;
1869
Chia-I Wub3686982015-02-27 09:51:16 -07001870 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001871 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1872 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001873 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001874
1875 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001876 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001877 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001878 dw[3] = 0;
1879 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001880 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001881 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001882 dw[3] = 1;
1883 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001884 default:
1885 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001886 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001887 dw[3] = 0;
1888 break;
1889 }
1890
Chia-I Wu714df452015-01-01 07:55:04 +08001891 if (cmd->bind.vertex.buf[i]) {
1892 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001893 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001894
1895 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001896 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1897 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001898 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001899 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001900 dw[1] = 0;
1901 dw[2] = 0;
1902 }
1903
1904 dw += 4;
1905 pos += 4;
1906 }
1907}
1908
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001909static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1910{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001911 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1912 const struct intel_pipeline_shader *vs = &pipeline->vs;
1913 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001914 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001915 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001916 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001917 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001918
1919 CMD_ASSERT(cmd, 6, 7.5);
1920
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001921 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001922 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1923 *
1924 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1925 * 128-bit vertex elements to be passed into the payload for each
1926 * vertex."
1927 *
1928 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1929 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001930 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001931 vue_read_len = (vs->in_count + 1) / 2;
1932 if (!vue_read_len)
1933 vue_read_len = 1;
1934
1935 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1936 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1937
1938 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1939 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1940 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001941
1942 dw5 = GEN6_VS_DW5_STATISTICS |
1943 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001944
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001945 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001946 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001947 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001948 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001949
Chia-I Wube0a3d92014-09-02 13:20:59 +08001950 if (pipeline->disable_vs_cache)
1951 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1952
Chia-I Wu784d3042014-12-19 14:30:04 +08001953 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001954 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001955 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001956 dw[2] = dw2;
1957 dw[3] = 0; /* scratch */
1958 dw[4] = dw4;
1959 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001960
1961 if (vs->per_thread_scratch_size)
1962 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001963}
1964
Chia-I Wu625105f2014-10-13 15:35:29 +08001965static void emit_shader_resources(struct intel_cmd *cmd)
1966{
1967 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001968 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001969
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001970 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001971 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001972 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001973 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001974 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001975 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001976 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001977 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001978 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001979 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001980 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001981 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001982 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001983 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001984 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001985
1986 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1987 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1988 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1989 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1990 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1991
1992 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1993 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001994 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1995 binding_tables[0]);
1996 gen7_3dstate_pointer(cmd,
1997 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1998 binding_tables[1]);
1999 gen7_3dstate_pointer(cmd,
2000 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
2001 binding_tables[2]);
2002 gen7_3dstate_pointer(cmd,
2003 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
2004 binding_tables[3]);
2005 gen7_3dstate_pointer(cmd,
2006 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2007 binding_tables[4]);
2008
2009 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08002010 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
2011 samplers[0]);
2012 gen7_3dstate_pointer(cmd,
2013 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
2014 samplers[1]);
2015 gen7_3dstate_pointer(cmd,
2016 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
2017 samplers[2]);
2018 gen7_3dstate_pointer(cmd,
2019 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
2020 samplers[3]);
2021 gen7_3dstate_pointer(cmd,
2022 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2023 samplers[4]);
2024 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002025 assert(!binding_tables[1] && !binding_tables[2]);
2026 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2027 binding_tables[0], binding_tables[3], binding_tables[4]);
2028
Chia-I Wu625105f2014-10-13 15:35:29 +08002029 assert(!samplers[1] && !samplers[2]);
2030 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2031 samplers[0], samplers[3], samplers[4]);
2032 }
2033}
2034
Chia-I Wu8ada4242015-03-02 11:19:33 -07002035static void emit_msaa(struct intel_cmd *cmd)
2036{
Chia-I Wuc278df82015-07-07 11:50:03 +08002037 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002038
Chia-I Wubbc7d912015-02-27 14:59:50 -07002039 if (!cmd->bind.render_pass_changed)
2040 return;
2041
Chia-I Wu8ada4242015-03-02 11:19:33 -07002042 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wuc278df82015-07-07 11:50:03 +08002043 gen6_3DSTATE_MULTISAMPLE(cmd, pipeline->sample_count);
Chia-I Wu8ada4242015-03-02 11:19:33 -07002044}
2045
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002046static void emit_rt(struct intel_cmd *cmd)
2047{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002048 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002049
2050 if (!cmd->bind.render_pass_changed)
2051 return;
2052
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002053 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002054 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2055 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002056}
2057
2058static void emit_ds(struct intel_cmd *cmd)
2059{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002060 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +08002061 const struct intel_render_pass_subpass *subpass =
2062 cmd->bind.render_pass_subpass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002063 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002064 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08002065 (subpass->ds_index < rp->attachment_count) ?
2066 fb->views[subpass->ds_index] : NULL;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002067
Chia-I Wubbc7d912015-02-27 14:59:50 -07002068 if (!cmd->bind.render_pass_changed)
2069 return;
2070
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002071 if (!view) {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002072 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002073 static const struct intel_att_view null_view;
2074 view = &null_view;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002075 }
2076
2077 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wubdeed152015-07-09 12:16:29 +08002078 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
2079 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, subpass->ds_optimal);
2080 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002081
2082 if (cmd_gen(cmd) >= INTEL_GEN(7))
2083 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2084 else
2085 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2086}
2087
Chia-I Wua57761b2014-10-14 14:27:44 +08002088static uint32_t emit_shader(struct intel_cmd *cmd,
2089 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002090{
Chia-I Wua57761b2014-10-14 14:27:44 +08002091 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2092 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002093 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002094
Chia-I Wua57761b2014-10-14 14:27:44 +08002095 /* see if the shader is already in the cache */
2096 for (i = 0; i < cache->used; i++) {
2097 if (cache->entries[i].shader == (const void *) shader)
2098 return cache->entries[i].kernel_offset;
2099 }
2100
2101 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2102
2103 /* grow the cache if full */
2104 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002105 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002106 void *entries;
2107
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002108 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002109 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002110 if (entries) {
2111 if (cache->entries) {
2112 memcpy(entries, cache->entries,
2113 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002114 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002115 }
2116
2117 cache->entries = entries;
2118 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002119 }
2120 }
2121
Chia-I Wua57761b2014-10-14 14:27:44 +08002122 /* add the shader to the cache */
2123 if (cache->used < cache->count) {
2124 cache->entries[cache->used].shader = (const void *) shader;
2125 cache->entries[cache->used].kernel_offset = offset;
2126 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002127 }
2128
Chia-I Wua57761b2014-10-14 14:27:44 +08002129 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002130}
2131
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002132static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002133{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002134 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002135
Chia-I Wu8370b402014-08-29 12:28:37 +08002136 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2137 cmd_wa_gen6_pre_depth_stall_write(cmd);
2138 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2139 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2140 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2141 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002142
2143 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002144 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002145 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002146
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002147 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002148 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002149 }
2150 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002151 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002152 }
2153 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002154 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2155 }
2156 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2157 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2158 }
2159 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2160 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002161 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002162
Chia-I Wu8370b402014-08-29 12:28:37 +08002163 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2164 cmd_wa_gen7_post_command_cs_stall(cmd);
2165 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2166 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002167}
2168
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002169static void emit_bounded_states(struct intel_cmd *cmd)
2170{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002171 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002172
2173 emit_graphics_pipeline(cmd);
2174
2175 emit_rt(cmd);
2176 emit_ds(cmd);
2177
2178 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2179 gen7_cc_states(cmd);
2180 gen7_viewport_states(cmd);
2181
2182 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2183 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002184 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2185 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002186 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2187 &cmd->bind.pipeline.graphics->fs);
2188
Cody Northrop293d4502015-05-05 09:38:03 -06002189 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002190 gen6_3DSTATE_CLIP(cmd);
2191 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002192 gen7_3DSTATE_WM(cmd);
2193 gen7_3DSTATE_PS(cmd);
2194 } else {
2195 gen6_cc_states(cmd);
2196 gen6_viewport_states(cmd);
2197
2198 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2199 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002200 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2201 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002202 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2203 &cmd->bind.pipeline.graphics->fs);
2204
Cody Northrop293d4502015-05-05 09:38:03 -06002205 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002206 gen6_3DSTATE_CLIP(cmd);
2207 gen6_3DSTATE_SF(cmd);
2208 gen6_3DSTATE_WM(cmd);
2209 }
2210
2211 emit_shader_resources(cmd);
2212
2213 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002214
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002215 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2216 gen6_3DSTATE_VS(cmd);
2217}
2218
Tony Barbourfa6cac72015-01-16 14:27:35 -07002219static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002220 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002221{
2222 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2223 const uint8_t cmd_len = 3;
2224 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002225
2226 CMD_ASSERT(cmd, 6, 7.5);
2227
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002228 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002229 dw[0] = 0;
2230 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002231
2232 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2233 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2234 GEN6_COMPAREFUNCTION_NEVER << 27 |
2235 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2236 } else {
2237 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2238 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2239 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002240 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002241 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002242 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2243 (GEN6_STENCILOP_KEEP) << 25 |
2244 (GEN6_STENCILOP_KEEP) << 22 |
2245 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002246 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2247 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002248 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2249 (GEN6_STENCILOP_KEEP) << 9 |
2250 (GEN6_STENCILOP_KEEP) << 6 |
2251 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002252
Chia-I Wud850a392015-02-19 11:08:25 -07002253 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2254 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2255 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2256 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2257 dw[2] = 0;
2258 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002259
2260 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2261 cmd_align, cmd_len, dw);
2262}
2263
Chia-I Wu6032b892014-10-17 14:47:18 +08002264static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2265{
2266 const struct intel_cmd_meta *meta = cmd->bind.meta;
2267 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2268
2269 CMD_ASSERT(cmd, 6, 7.5);
2270
2271 blend_offset = 0;
2272 ds_offset = 0;
2273 cc_offset = 0;
2274 cc_vp_offset = 0;
2275
Chia-I Wu29e6f502014-11-24 14:27:29 +08002276 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002277 /* BLEND_STATE */
2278 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002279 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002280 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002281 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002282 }
2283
Chia-I Wu29e6f502014-11-24 14:27:29 +08002284 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002285 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002287 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2288 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002289
Chia-I Wu29e6f502014-11-24 14:27:29 +08002290 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002291 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002292
Chia-I Wu29e6f502014-11-24 14:27:29 +08002293 /* COLOR_CALC_STATE */
2294 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002295 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002296
Chia-I Wu29e6f502014-11-24 14:27:29 +08002297 /* CC_VIEWPORT */
2298 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002299 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002300 dw[0] = u_fui(0.0f);
2301 dw[1] = u_fui(1.0f);
2302 } else {
2303 /* DEPTH_STENCIL_STATE */
2304 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002305 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002306 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2307 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2308 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002309 }
2310
2311 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2312 gen7_3dstate_pointer(cmd,
2313 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2314 blend_offset);
2315 gen7_3dstate_pointer(cmd,
2316 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2317 ds_offset);
2318 gen7_3dstate_pointer(cmd,
2319 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2320
2321 gen7_3dstate_pointer(cmd,
2322 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2323 cc_vp_offset);
2324 } else {
2325 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002326 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002327
2328 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2329 cmd_batch_pointer(cmd, 4, &dw);
2330 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002331 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002332 dw[1] = 0;
2333 dw[2] = 0;
2334 dw[3] = cc_vp_offset;
2335 }
2336}
2337
2338static void gen6_meta_surface_states(struct intel_cmd *cmd)
2339{
2340 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002341 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002342 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002343 const uint32_t sba_offset =
2344 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002345
2346 CMD_ASSERT(cmd, 6, 7.5);
2347
Chia-I Wu29e6f502014-11-24 14:27:29 +08002348 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2349 return;
2350
Chia-I Wu005c47c2014-10-22 13:49:13 +08002351 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002352 if (meta->src.valid) {
2353 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002354 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002355 meta->src.surface_len, meta->src.surface);
2356
2357 cmd_reserve_reloc(cmd, 1);
2358 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2359 cmd_surface_reloc_writer(cmd, offset, 1,
2360 meta->src.reloc_target, meta->src.reloc_offset);
2361 } else {
2362 cmd_surface_reloc(cmd, offset, 1,
2363 (struct intel_bo *) meta->src.reloc_target,
2364 meta->src.reloc_offset, meta->src.reloc_flags);
2365 }
2366
Mike Stroyan9bfad482015-02-10 15:09:23 -07002367 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002368 }
2369 if (meta->dst.valid) {
2370 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002371 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002372 meta->dst.surface_len, meta->dst.surface);
2373
2374 cmd_reserve_reloc(cmd, 1);
2375 cmd_surface_reloc(cmd, offset, 1,
2376 (struct intel_bo *) meta->dst.reloc_target,
2377 meta->dst.reloc_offset, meta->dst.reloc_flags);
2378
Mike Stroyan9bfad482015-02-10 15:09:23 -07002379 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002380 }
2381
2382 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002383 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002384 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002385 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002386
2387 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002388 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2389 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2390 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002391 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002392 } else {
2393 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002394 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002395 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002396 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002397 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002398 }
2399}
2400
2401static void gen6_meta_urb(struct intel_cmd *cmd)
2402{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002403 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002404 uint32_t *dw;
2405
2406 CMD_ASSERT(cmd, 6, 6);
2407
2408 /* 3DSTATE_URB */
2409 cmd_batch_pointer(cmd, 3, &dw);
2410 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002411 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002412 dw[2] = 0;
2413}
2414
2415static void gen7_meta_urb(struct intel_cmd *cmd)
2416{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002417 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2418 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002419 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002420 uint32_t *dw;
2421
2422 CMD_ASSERT(cmd, 7, 7.5);
2423
Chia-I Wu6032b892014-10-17 14:47:18 +08002424 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2425
Chia-I Wu24aa1022014-11-25 11:53:19 +08002426 switch (cmd_gen(cmd)) {
2427 case INTEL_GEN(7.5):
2428 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2429 break;
2430 case INTEL_GEN(7):
2431 default:
2432 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2433 break;
2434 }
2435
Chia-I Wu6032b892014-10-17 14:47:18 +08002436 /* 3DSTATE_URB_x */
2437 cmd_batch_pointer(cmd, 8, &dw);
2438
2439 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002440 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002441 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002442 dw += 2;
2443
2444 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002445 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002446 dw += 2;
2447
2448 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002449 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002450 dw += 2;
2451
2452 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002453 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002454 dw += 2;
2455}
2456
2457static void gen6_meta_vf(struct intel_cmd *cmd)
2458{
2459 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002460 uint32_t vb_start, vb_end, vb_stride;
2461 int ve_format, ve_z_source;
2462 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002463 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002464
2465 CMD_ASSERT(cmd, 6, 7.5);
2466
Chia-I Wu29e6f502014-11-24 14:27:29 +08002467 switch (meta->mode) {
2468 case INTEL_CMD_META_VS_POINTS:
2469 cmd_batch_pointer(cmd, 3, &dw);
2470 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002471 dw[1] = GEN6_VE_DW0_VALID;
2472 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2473 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2474 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2475 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002476 return;
2477 break;
2478 case INTEL_CMD_META_FS_RECT:
2479 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002480 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002481
Chia-I Wu29e6f502014-11-24 14:27:29 +08002482 vertices[0][0] = meta->dst.x + meta->width;
2483 vertices[0][1] = meta->dst.y + meta->height;
2484 vertices[1][0] = meta->dst.x;
2485 vertices[1][1] = meta->dst.y + meta->height;
2486 vertices[2][0] = meta->dst.x;
2487 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002488
Chia-I Wu29e6f502014-11-24 14:27:29 +08002489 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2490 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002491
Chia-I Wu29e6f502014-11-24 14:27:29 +08002492 vb_end = vb_start + sizeof(vertices) - 1;
2493 vb_stride = sizeof(vertices[0]);
2494 ve_z_source = GEN6_VFCOMP_STORE_0;
2495 ve_format = GEN6_FORMAT_R32G32_USCALED;
2496 }
2497 break;
2498 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2499 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002500 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002501
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002502 vertices[0][0] = (float) (meta->dst.x + meta->width);
2503 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002504 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002505 vertices[1][0] = (float) meta->dst.x;
2506 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002507 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002508 vertices[2][0] = (float) meta->dst.x;
2509 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002510 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002511
Chia-I Wu29e6f502014-11-24 14:27:29 +08002512 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2513 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002514
Chia-I Wu29e6f502014-11-24 14:27:29 +08002515 vb_end = vb_start + sizeof(vertices) - 1;
2516 vb_stride = sizeof(vertices[0]);
2517 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2518 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2519 }
2520 break;
2521 default:
2522 assert(!"unknown meta mode");
2523 return;
2524 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002525 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002526
2527 /* 3DSTATE_VERTEX_BUFFERS */
2528 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002529
Chia-I Wu6032b892014-10-17 14:47:18 +08002530 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002531 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002532 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002533 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002534
2535 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002536 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2537 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002538
2539 dw[4] = 0;
2540
2541 /* 3DSTATE_VERTEX_ELEMENTS */
2542 cmd_batch_pointer(cmd, 5, &dw);
2543 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002544 dw[1] = GEN6_VE_DW0_VALID;
2545 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2546 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2547 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2548 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2549 dw[3] = GEN6_VE_DW0_VALID |
2550 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2551 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2552 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2553 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2554 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002555}
2556
Chia-I Wu29e6f502014-11-24 14:27:29 +08002557static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002558{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002559 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002560 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002561 uint32_t consts[8];
2562 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002563
2564 CMD_ASSERT(cmd, 6, 7.5);
2565
2566 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002567 case INTEL_DEV_META_VS_FILL_MEM:
2568 consts[0] = meta->dst.x;
2569 consts[1] = meta->clear_val[0];
2570 const_count = 2;
2571 break;
2572 case INTEL_DEV_META_VS_COPY_MEM:
2573 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2574 consts[0] = meta->dst.x;
2575 consts[1] = meta->src.x;
2576 const_count = 2;
2577 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002578 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2579 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2580 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2581 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2582 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2583 consts[0] = meta->src.x;
2584 consts[1] = meta->src.y;
2585 consts[2] = meta->width;
2586 consts[3] = meta->dst.x;
2587 const_count = 4;
2588 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002589 default:
2590 assert(!"unknown meta shader id");
2591 const_count = 0;
2592 break;
2593 }
2594
2595 /* this can be skipped but it makes state dumping prettier */
2596 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2597
2598 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2599}
2600
2601static void gen6_meta_vs(struct intel_cmd *cmd)
2602{
2603 const struct intel_cmd_meta *meta = cmd->bind.meta;
2604 const struct intel_pipeline_shader *sh =
2605 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2606 uint32_t offset, *dw;
2607
2608 CMD_ASSERT(cmd, 6, 7.5);
2609
2610 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002611 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002612
2613 /* 3DSTATE_CONSTANT_VS */
2614 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2615 cmd_batch_pointer(cmd, cmd_len, &dw);
2616 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2617 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2618
2619 /* 3DSTATE_VS */
2620 cmd_batch_pointer(cmd, 6, &dw);
2621 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2622 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2623
2624 return;
2625 }
2626
2627 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2628
2629 /* 3DSTATE_CONSTANT_VS */
2630 offset = gen6_meta_vs_constants(cmd);
2631 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2632 cmd_batch_pointer(cmd, 7, &dw);
2633 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002634 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002635 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002636 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002637 dw[4] = 0;
2638 dw[5] = 0;
2639 dw[6] = 0;
2640 } else {
2641 cmd_batch_pointer(cmd, 5, &dw);
2642 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002643 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002644 dw[1] = offset;
2645 dw[2] = 0;
2646 dw[3] = 0;
2647 dw[4] = 0;
2648 }
2649
2650 /* 3DSTATE_VS */
2651 offset = emit_shader(cmd, sh);
2652 cmd_batch_pointer(cmd, 6, &dw);
2653 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2654 dw[1] = offset;
2655 dw[2] = GEN6_THREADDISP_SPF |
2656 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2657 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002658 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002659 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2660 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2661
2662 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2663 GEN6_VS_DW5_VS_ENABLE;
2664 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002665 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002666 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002667 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002668
2669 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002670}
2671
2672static void gen6_meta_disabled(struct intel_cmd *cmd)
2673{
Chia-I Wu6032b892014-10-17 14:47:18 +08002674 uint32_t *dw;
2675
2676 CMD_ASSERT(cmd, 6, 6);
2677
Chia-I Wu6032b892014-10-17 14:47:18 +08002678 /* 3DSTATE_CONSTANT_GS */
2679 cmd_batch_pointer(cmd, 5, &dw);
2680 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2681 dw[1] = 0;
2682 dw[2] = 0;
2683 dw[3] = 0;
2684 dw[4] = 0;
2685
2686 /* 3DSTATE_GS */
2687 cmd_batch_pointer(cmd, 7, &dw);
2688 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2689 dw[1] = 0;
2690 dw[2] = 0;
2691 dw[3] = 0;
2692 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2693 dw[5] = GEN6_GS_DW5_STATISTICS;
2694 dw[6] = 0;
2695
Chia-I Wu6032b892014-10-17 14:47:18 +08002696 /* 3DSTATE_SF */
2697 cmd_batch_pointer(cmd, 20, &dw);
2698 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2699 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2700 memset(&dw[2], 0, 18 * sizeof(*dw));
2701}
2702
2703static void gen7_meta_disabled(struct intel_cmd *cmd)
2704{
2705 uint32_t *dw;
2706
2707 CMD_ASSERT(cmd, 7, 7.5);
2708
Chia-I Wu6032b892014-10-17 14:47:18 +08002709 /* 3DSTATE_CONSTANT_HS */
2710 cmd_batch_pointer(cmd, 7, &dw);
2711 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2712 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2713
2714 /* 3DSTATE_HS */
2715 cmd_batch_pointer(cmd, 7, &dw);
2716 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2717 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2718
2719 /* 3DSTATE_TE */
2720 cmd_batch_pointer(cmd, 4, &dw);
2721 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2722 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2723
2724 /* 3DSTATE_CONSTANT_DS */
2725 cmd_batch_pointer(cmd, 7, &dw);
2726 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2727 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2728
2729 /* 3DSTATE_DS */
2730 cmd_batch_pointer(cmd, 6, &dw);
2731 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2732 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2733
2734 /* 3DSTATE_CONSTANT_GS */
2735 cmd_batch_pointer(cmd, 7, &dw);
2736 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2737 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2738
2739 /* 3DSTATE_GS */
2740 cmd_batch_pointer(cmd, 7, &dw);
2741 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2742 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2743
2744 /* 3DSTATE_STREAMOUT */
2745 cmd_batch_pointer(cmd, 3, &dw);
2746 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2747 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2748
Chia-I Wu6032b892014-10-17 14:47:18 +08002749 /* 3DSTATE_SF */
2750 cmd_batch_pointer(cmd, 7, &dw);
2751 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2752 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2753
2754 /* 3DSTATE_SBE */
2755 cmd_batch_pointer(cmd, 14, &dw);
2756 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2757 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2758 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002759}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002760
Chia-I Wu29e6f502014-11-24 14:27:29 +08002761static void gen6_meta_clip(struct intel_cmd *cmd)
2762{
2763 const struct intel_cmd_meta *meta = cmd->bind.meta;
2764 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002765
Chia-I Wu29e6f502014-11-24 14:27:29 +08002766 /* 3DSTATE_CLIP */
2767 cmd_batch_pointer(cmd, 4, &dw);
2768 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2769 dw[1] = 0;
2770 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2771 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2772 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2773 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002774 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002775 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002776 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002777}
2778
2779static void gen6_meta_wm(struct intel_cmd *cmd)
2780{
2781 const struct intel_cmd_meta *meta = cmd->bind.meta;
2782 uint32_t *dw;
2783
2784 CMD_ASSERT(cmd, 6, 7.5);
2785
2786 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2787
2788 /* 3DSTATE_MULTISAMPLE */
2789 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2790 cmd_batch_pointer(cmd, 4, &dw);
2791 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2792 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2793 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2794 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2795 dw[2] = 0;
2796 dw[3] = 0;
2797 } else {
2798 cmd_batch_pointer(cmd, 3, &dw);
2799 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2800 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2801 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2802 dw[2] = 0;
2803 }
2804
2805 /* 3DSTATE_SAMPLE_MASK */
2806 cmd_batch_pointer(cmd, 2, &dw);
2807 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2808 dw[1] = (1 << meta->samples) - 1;
2809
2810 /* 3DSTATE_DRAWING_RECTANGLE */
2811 cmd_batch_pointer(cmd, 4, &dw);
2812 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002813 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2814 /* unused */
2815 dw[1] = 0;
2816 dw[2] = 0;
2817 } else {
2818 dw[1] = meta->dst.y << 16 | meta->dst.x;
2819 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2820 (meta->dst.x + meta->width - 1);
2821 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002822 dw[3] = 0;
2823}
2824
2825static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2826{
2827 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002828 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002829 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002830 uint32_t consts[8];
2831 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002832
2833 CMD_ASSERT(cmd, 6, 7.5);
2834
2835 /* underflow is fine here */
2836 offset_x = meta->src.x - meta->dst.x;
2837 offset_y = meta->src.y - meta->dst.y;
2838
2839 switch (meta->shader_id) {
2840 case INTEL_DEV_META_FS_COPY_MEM:
2841 case INTEL_DEV_META_FS_COPY_1D:
2842 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2843 case INTEL_DEV_META_FS_COPY_2D:
2844 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2845 case INTEL_DEV_META_FS_COPY_2D_MS:
2846 consts[0] = offset_x;
2847 consts[1] = offset_y;
2848 consts[2] = meta->src.layer;
2849 consts[3] = meta->src.lod;
2850 const_count = 4;
2851 break;
2852 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2853 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2854 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2855 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2856 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2857 consts[0] = offset_x;
2858 consts[1] = offset_y;
2859 consts[2] = meta->src.layer;
2860 consts[3] = meta->src.lod;
2861 consts[4] = meta->src.x;
2862 consts[5] = meta->width;
2863 const_count = 6;
2864 break;
2865 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2866 consts[0] = offset_x;
2867 consts[1] = offset_y;
2868 consts[2] = meta->width;
2869 const_count = 3;
2870 break;
2871 case INTEL_DEV_META_FS_CLEAR_COLOR:
2872 consts[0] = meta->clear_val[0];
2873 consts[1] = meta->clear_val[1];
2874 consts[2] = meta->clear_val[2];
2875 consts[3] = meta->clear_val[3];
2876 const_count = 4;
2877 break;
2878 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2879 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002880 consts[1] = meta->clear_val[1];
2881 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002882 break;
2883 case INTEL_DEV_META_FS_RESOLVE_2X:
2884 case INTEL_DEV_META_FS_RESOLVE_4X:
2885 case INTEL_DEV_META_FS_RESOLVE_8X:
2886 case INTEL_DEV_META_FS_RESOLVE_16X:
2887 consts[0] = offset_x;
2888 consts[1] = offset_y;
2889 const_count = 2;
2890 break;
2891 default:
2892 assert(!"unknown meta shader id");
2893 const_count = 0;
2894 break;
2895 }
2896
2897 /* this can be skipped but it makes state dumping prettier */
2898 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2899
2900 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2901}
2902
2903static void gen6_meta_ps(struct intel_cmd *cmd)
2904{
2905 const struct intel_cmd_meta *meta = cmd->bind.meta;
2906 const struct intel_pipeline_shader *sh =
2907 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2908 uint32_t offset, *dw;
2909
2910 CMD_ASSERT(cmd, 6, 6);
2911
Chia-I Wu29e6f502014-11-24 14:27:29 +08002912 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2913 /* 3DSTATE_CONSTANT_PS */
2914 cmd_batch_pointer(cmd, 5, &dw);
2915 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2916 dw[1] = 0;
2917 dw[2] = 0;
2918 dw[3] = 0;
2919 dw[4] = 0;
2920
2921 /* 3DSTATE_WM */
2922 cmd_batch_pointer(cmd, 9, &dw);
2923 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2924 dw[1] = 0;
2925 dw[2] = 0;
2926 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002927
2928 switch (meta->ds.op) {
2929 case INTEL_CMD_META_DS_HIZ_CLEAR:
2930 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2931 break;
2932 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2933 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2934 break;
2935 case INTEL_CMD_META_DS_RESOLVE:
2936 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2937 break;
2938 default:
2939 dw[4] = 0;
2940 break;
2941 }
2942
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002943 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002944 dw[6] = 0;
2945 dw[7] = 0;
2946 dw[8] = 0;
2947
Chia-I Wu3adf7212014-10-24 15:34:07 +08002948 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002949 }
2950
Chia-I Wu3adf7212014-10-24 15:34:07 +08002951 /* a normal color write */
2952 assert(meta->dst.valid && !sh->uses);
2953
Chia-I Wu6032b892014-10-17 14:47:18 +08002954 /* 3DSTATE_CONSTANT_PS */
2955 offset = gen6_meta_ps_constants(cmd);
2956 cmd_batch_pointer(cmd, 5, &dw);
2957 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002958 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002959 dw[1] = offset;
2960 dw[2] = 0;
2961 dw[3] = 0;
2962 dw[4] = 0;
2963
2964 /* 3DSTATE_WM */
2965 offset = emit_shader(cmd, sh);
2966 cmd_batch_pointer(cmd, 9, &dw);
2967 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2968 dw[1] = offset;
2969 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2970 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002971 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002972 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002973 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002974 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2975 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002976
Chia-I Wu6032b892014-10-17 14:47:18 +08002977 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002978 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002979 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2980 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2981 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2982 if (meta->samples > 1) {
2983 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2984 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2985 } else {
2986 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2987 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2988 }
2989 dw[7] = 0;
2990 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002991
2992 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002993}
2994
2995static void gen7_meta_ps(struct intel_cmd *cmd)
2996{
2997 const struct intel_cmd_meta *meta = cmd->bind.meta;
2998 const struct intel_pipeline_shader *sh =
2999 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
3000 uint32_t offset, *dw;
3001
3002 CMD_ASSERT(cmd, 7, 7.5);
3003
Chia-I Wu29e6f502014-11-24 14:27:29 +08003004 if (meta->mode != INTEL_CMD_META_FS_RECT) {
3005 /* 3DSTATE_WM */
3006 cmd_batch_pointer(cmd, 3, &dw);
3007 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003008
3009 switch (meta->ds.op) {
3010 case INTEL_CMD_META_DS_HIZ_CLEAR:
3011 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
3012 break;
3013 case INTEL_CMD_META_DS_HIZ_RESOLVE:
3014 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
3015 break;
3016 case INTEL_CMD_META_DS_RESOLVE:
3017 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
3018 break;
3019 default:
3020 dw[1] = 0;
3021 break;
3022 }
3023
3024 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003025
3026 /* 3DSTATE_CONSTANT_GS */
3027 cmd_batch_pointer(cmd, 7, &dw);
3028 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3029 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3030
3031 /* 3DSTATE_PS */
3032 cmd_batch_pointer(cmd, 8, &dw);
3033 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3034 dw[1] = 0;
3035 dw[2] = 0;
3036 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003037 /* required to avoid hangs */
3038 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003039 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003040 dw[5] = 0;
3041 dw[6] = 0;
3042 dw[7] = 0;
3043
Chia-I Wu3adf7212014-10-24 15:34:07 +08003044 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003045 }
3046
Chia-I Wu3adf7212014-10-24 15:34:07 +08003047 /* a normal color write */
3048 assert(meta->dst.valid && !sh->uses);
3049
Chia-I Wu6032b892014-10-17 14:47:18 +08003050 /* 3DSTATE_WM */
3051 cmd_batch_pointer(cmd, 3, &dw);
3052 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003053 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003054 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3055 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3056 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3057 dw[2] = 0;
3058
3059 /* 3DSTATE_CONSTANT_PS */
3060 offset = gen6_meta_ps_constants(cmd);
3061 cmd_batch_pointer(cmd, 7, &dw);
3062 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003063 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003064 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003065 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003066 dw[4] = 0;
3067 dw[5] = 0;
3068 dw[6] = 0;
3069
3070 /* 3DSTATE_PS */
3071 offset = emit_shader(cmd, sh);
3072 cmd_batch_pointer(cmd, 8, &dw);
3073 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3074 dw[1] = offset;
3075 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3076 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003077 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003078
3079 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3080 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003081 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003082
3083 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003084 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003085 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003086 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003087 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003088 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003089
3090 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3091 dw[6] = 0;
3092 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003093
3094 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003095}
3096
3097static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3098{
3099 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003100 const struct intel_att_view *view = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003101
3102 CMD_ASSERT(cmd, 6, 7.5);
3103
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003104 if (!view) {
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003105 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003106 static const struct intel_att_view null_view;
3107 view = &null_view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003108 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003109
3110 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003111 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
3112 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, meta->ds.optimal);
3113 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003114
3115 if (cmd_gen(cmd) >= INTEL_GEN(7))
3116 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3117 else
3118 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003119}
3120
Chia-I Wu862c5572015-03-28 15:23:55 +08003121static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3122 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003123 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003124{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003125 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003126 if (data->set_offsets)
3127 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003128
Chia-I Wu862c5572015-03-28 15:23:55 +08003129 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003130 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003131 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003132 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003133 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003134 data->set_offset_count = 0;
3135 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003136 }
3137
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003138 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003139 }
3140
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003141 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003142 if (data->dynamic_offsets)
3143 intel_free(cmd, data->dynamic_offsets);
3144
3145 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003146 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003147 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003148 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003149 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003150 data->dynamic_offset_count = 0;
3151 return false;
3152 }
3153
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003154 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003155 }
3156
3157 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003158}
3159
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003160static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3161 const struct intel_pipeline *pipeline)
3162{
3163 cmd->bind.pipeline.graphics = pipeline;
3164
3165 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003166 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003167}
3168
3169static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3170 const struct intel_pipeline *pipeline)
3171{
3172 cmd->bind.pipeline.compute = pipeline;
3173
3174 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003175 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003176}
3177
Chia-I Wu862c5572015-03-28 15:23:55 +08003178static void cmd_copy_dset_data(struct intel_cmd *cmd,
3179 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003180 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003181 uint32_t index,
3182 const struct intel_desc_set *set,
3183 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003184{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003185 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003186
Chia-I Wu862c5572015-03-28 15:23:55 +08003187 assert(index < data->set_offset_count);
3188 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003189
Chia-I Wu862c5572015-03-28 15:23:55 +08003190 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003191 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003192 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003193
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003194 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003195 dynamic_offsets,
3196 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003197 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003198}
3199
Chia-I Wu3b04af52014-11-08 10:48:20 +08003200static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003201 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003202 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003203{
Chia-I Wu714df452015-01-01 07:55:04 +08003204 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003205 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003206 return;
3207 }
3208
Chia-I Wu714df452015-01-01 07:55:04 +08003209 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003210 cmd->bind.vertex.offset[binding] = offset;
3211}
3212
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003213static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003214 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003215 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003216{
Chia-I Wu714df452015-01-01 07:55:04 +08003217 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003218 cmd->bind.index.offset = offset;
3219 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003220}
3221
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003222static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003223 const struct intel_dynamic_viewport *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003224{
3225 cmd->bind.state.viewport = state;
3226}
3227
Cody Northrope4bc6942015-08-26 10:01:32 -06003228static void cmd_bind_line_width_state(struct intel_cmd *cmd,
3229 const struct intel_dynamic_line_width *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003230{
Cody Northrope4bc6942015-08-26 10:01:32 -06003231 cmd->bind.state.line_width = state;
Cody Northropf5bd2252015-08-17 11:10:49 -06003232}
3233
Cody Northrope4bc6942015-08-26 10:01:32 -06003234static void cmd_bind_depth_bias_state(struct intel_cmd *cmd,
3235 const struct intel_dynamic_depth_bias *state)
Cody Northropf5bd2252015-08-17 11:10:49 -06003236{
Cody Northrope4bc6942015-08-26 10:01:32 -06003237 cmd->bind.state.depth_bias = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003238}
3239
Cody Northrope4bc6942015-08-26 10:01:32 -06003240static void cmd_bind_depth_bounds_state(struct intel_cmd *cmd,
3241 const struct intel_dynamic_depth_bounds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003242{
Cody Northrope4bc6942015-08-26 10:01:32 -06003243 cmd->bind.state.depth_bounds = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003244}
3245
Cody Northrop2605cb02015-08-18 15:21:16 -06003246static void cmd_bind_stencil_state(struct intel_cmd *cmd,
3247 const struct intel_dynamic_stencil *state)
3248{
3249 cmd->bind.state.stencil = state;
3250}
3251
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003252static void cmd_bind_blend_state(struct intel_cmd *cmd,
Cody Northrope4bc6942015-08-26 10:01:32 -06003253 const struct intel_dynamic_blend *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003254{
3255 cmd->bind.state.blend = state;
3256}
3257
Chia-I Wuf98dd882015-02-10 04:17:47 +08003258static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3259{
3260 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3261 struct intel_pipeline_rmap *rmaps[5] = {
3262 pipeline->vs.rmap,
3263 pipeline->tcs.rmap,
3264 pipeline->tes.rmap,
3265 pipeline->gs.rmap,
3266 pipeline->fs.rmap,
3267 };
3268 uint32_t max_write;
3269 int i;
3270
3271 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3272 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3273 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3274
3275 /* pad first */
3276 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3277
3278 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3279 const struct intel_pipeline_rmap *rmap = rmaps[i];
3280 const uint32_t surface_count = (rmap) ?
3281 rmap->rt_count + rmap->texture_resource_count +
3282 rmap->resource_count + rmap->uav_count : 0;
3283
3284 if (surface_count) {
3285 /* SURFACE_STATEs */
3286 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3287
3288 /* BINDING_TABLE_STATE */
3289 max_write += u_align(sizeof(uint32_t) * surface_count,
3290 GEN6_ALIGNMENT_SURFACE_STATE);
3291 }
3292 }
3293
3294 return max_write;
3295}
3296
3297static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3298{
3299 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3300 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3301 uint32_t max_surface_write;
3302
3303 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3304 if (cmd->bind.meta)
3305 max_surface_write = 64 * sizeof(uint32_t);
3306 else
3307 max_surface_write = cmd_get_max_surface_write(cmd);
3308
3309 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3310 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3311 /* SBA expects page-aligned addresses */
3312 writer->sba_offset = writer->used & ~0xfff;
3313
3314 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3315
3316 cmd_batch_state_base_address(cmd);
3317 }
3318}
3319
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003320static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003321 uint32_t vertex_start,
3322 uint32_t vertex_count,
3323 uint32_t instance_start,
3324 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003325 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003326 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003327{
3328 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003329 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003330 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3331
3332 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003333
3334 emit_bounded_states(cmd);
3335
Chia-I Wuf98dd882015-02-10 04:17:47 +08003336 /* sanity check on cmd_get_max_surface_write() */
3337 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3338 surface_writer_used <= cmd_get_max_surface_write(cmd));
3339
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003340 if (indexed) {
3341 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003342 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003343
3344 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3345 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3346 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003347 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003348 cmd->bind.index.offset, cmd->bind.index.type,
3349 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003350 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003351 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003352 cmd->bind.index.offset, cmd->bind.index.type,
3353 p->primitive_restart);
3354 }
3355 } else {
3356 assert(!vertex_base);
3357 }
3358
3359 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3360 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3361 vertex_start, instance_count, instance_start, vertex_base);
3362 } else {
3363 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3364 vertex_start, instance_count, instance_start, vertex_base);
3365 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003366
Chia-I Wu707a29e2014-08-27 12:51:47 +08003367 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003368 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003369 /* need to re-emit all workarounds */
3370 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003371
3372 if (intel_debug & INTEL_DEBUG_NOCACHE)
3373 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003374}
3375
Chia-I Wuc14d1562014-10-17 09:49:22 +08003376void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3377{
Chia-I Wu6032b892014-10-17 14:47:18 +08003378 cmd->bind.meta = meta;
3379
Chia-I Wuf98dd882015-02-10 04:17:47 +08003380 cmd_adjust_state_base_address(cmd);
3381
Chia-I Wu6032b892014-10-17 14:47:18 +08003382 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003383 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003384
3385 gen6_meta_dynamic_states(cmd);
3386 gen6_meta_surface_states(cmd);
3387
3388 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3389 gen7_meta_urb(cmd);
3390 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003391 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003392 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003393 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003394 gen6_meta_wm(cmd);
3395 gen7_meta_ps(cmd);
3396 gen6_meta_depth_buffer(cmd);
3397
3398 cmd_wa_gen7_post_command_cs_stall(cmd);
3399 cmd_wa_gen7_post_command_depth_stall(cmd);
3400
Chia-I Wu29e6f502014-11-24 14:27:29 +08003401 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3402 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003403 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003404 } else {
3405 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3406 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003407 } else {
3408 gen6_meta_urb(cmd);
3409 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003410 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003411 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003412 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003413 gen6_meta_wm(cmd);
3414 gen6_meta_ps(cmd);
3415 gen6_meta_depth_buffer(cmd);
3416
Chia-I Wu29e6f502014-11-24 14:27:29 +08003417 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3418 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003419 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003420 } else {
3421 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3422 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003423 }
3424
3425 cmd->bind.draw_count++;
3426 /* need to re-emit all workarounds */
3427 cmd->bind.wa_flags = 0;
3428
3429 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003430
Chia-I Wubbc7d912015-02-27 14:59:50 -07003431 /* make the normal path believe the render pass has changed */
3432 cmd->bind.render_pass_changed = true;
3433
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003434 if (intel_debug & INTEL_DEBUG_NOCACHE)
3435 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003436}
3437
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003438static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3439{
3440 const uint8_t cmd_len = 2;
3441 uint32_t *dw;
3442 uint32_t pos;
3443
3444 if (cmd_gen(cmd) < INTEL_GEN(7.5)) {
3445 cmd->result = VK_ERROR_UNKNOWN;
3446 return;
3447 }
3448
3449 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3450 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3451 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3452 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3453 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3454
3455 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3456}
3457
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003458ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003459 VkCmdBuffer cmdBuffer,
3460 VkPipelineBindPoint pipelineBindPoint,
3461 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003462{
3463 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3464
3465 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003466 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003467 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003468 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003469 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003470 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003471 break;
3472 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003473 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003474 break;
3475 }
3476}
3477
Tony Barbourde4124d2015-07-03 10:33:54 -06003478ICD_EXPORT void VKAPI vkCmdBindDynamicViewportState(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003479 VkCmdBuffer cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003480 VkDynamicViewportState state)
Chia-I Wub2755562014-08-20 13:38:52 +08003481{
3482 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3483
Tony Barbourde4124d2015-07-03 10:33:54 -06003484 cmd_bind_viewport_state(cmd,
3485 intel_dynamic_viewport(state));
3486}
3487
Cody Northrope4bc6942015-08-26 10:01:32 -06003488ICD_EXPORT void VKAPI vkCmdBindDynamicLineWidthState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003489 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003490 VkDynamicLineWidthState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003491{
3492 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3493
Cody Northrope4bc6942015-08-26 10:01:32 -06003494 cmd_bind_line_width_state(cmd,
3495 intel_dynamic_line_width(state));
Cody Northropf5bd2252015-08-17 11:10:49 -06003496}
3497
Cody Northrope4bc6942015-08-26 10:01:32 -06003498ICD_EXPORT void VKAPI vkCmdBindDynamicDepthBiasState(
Cody Northropf5bd2252015-08-17 11:10:49 -06003499 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003500 VkDynamicDepthBiasState state)
Cody Northropf5bd2252015-08-17 11:10:49 -06003501{
3502 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3503
Cody Northrope4bc6942015-08-26 10:01:32 -06003504 cmd_bind_depth_bias_state(cmd,
3505 intel_dynamic_depth_bias(state));
Tony Barbourde4124d2015-07-03 10:33:54 -06003506}
3507
Cody Northrope4bc6942015-08-26 10:01:32 -06003508ICD_EXPORT void VKAPI vkCmdBindDynamicBlendState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003509 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003510 VkDynamicBlendState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003511{
3512 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3513
3514 cmd_bind_blend_state(cmd,
Cody Northrope4bc6942015-08-26 10:01:32 -06003515 intel_dynamic_blend(state));
Tony Barbourde4124d2015-07-03 10:33:54 -06003516}
3517
Cody Northrope4bc6942015-08-26 10:01:32 -06003518ICD_EXPORT void VKAPI vkCmdBindDynamicDepthBoundsState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003519 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003520 VkDynamicDepthBoundsState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003521{
3522 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3523
Cody Northrope4bc6942015-08-26 10:01:32 -06003524 cmd_bind_depth_bounds_state(cmd,
3525 intel_dynamic_depth_bounds(state));
Cody Northrop2605cb02015-08-18 15:21:16 -06003526}
3527
3528ICD_EXPORT void VKAPI vkCmdBindDynamicStencilState(
3529 VkCmdBuffer cmdBuffer,
3530 VkDynamicStencilState state)
3531{
3532 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3533
3534 cmd_bind_stencil_state(cmd,
3535 intel_dynamic_stencil(state));
Chia-I Wub2755562014-08-20 13:38:52 +08003536}
3537
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003538ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003539 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003540 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003541 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003542 uint32_t firstSet,
3543 uint32_t setCount,
3544 const VkDescriptorSet* pDescriptorSets,
3545 uint32_t dynamicOffsetCount,
3546 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003547{
3548 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003549 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003550 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003551 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003552 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003553
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003554 pipeline_layout = intel_pipeline_layout(layout);
3555
Chia-I Wub2755562014-08-20 13:38:52 +08003556 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003557 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003558 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003559 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003560 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003561 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003562 break;
3563 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003564 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003565 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003566 break;
3567 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003568
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003569 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003570 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3571
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003572 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003573 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003574 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003575 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003576 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003577 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003578 }
Chia-I Wub2755562014-08-20 13:38:52 +08003579}
3580
Tony Barbour8205d902015-04-16 15:59:00 -06003581
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003582ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3583 VkCmdBuffer cmdBuffer,
3584 uint32_t startBinding,
3585 uint32_t bindingCount,
3586 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003587 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003588{
3589 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003590
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003591 for (uint32_t i = 0; i < bindingCount; i++) {
3592 struct intel_buf *buf = intel_buf(pBuffers[i]);
3593 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3594 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003595}
3596
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003597ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003598 VkCmdBuffer cmdBuffer,
3599 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003600 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003601 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003602{
3603 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003604 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003605
Chia-I Wu714df452015-01-01 07:55:04 +08003606 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003607}
3608
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003609ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003610 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003611 uint32_t firstVertex,
3612 uint32_t vertexCount,
3613 uint32_t firstInstance,
3614 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003615{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003616 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003617
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003618 cmd_draw(cmd, firstVertex, vertexCount,
3619 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003620}
3621
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003622ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003623 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003624 uint32_t firstIndex,
3625 uint32_t indexCount,
3626 int32_t vertexOffset,
3627 uint32_t firstInstance,
3628 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003629{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003630 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003631
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003632 cmd_draw(cmd, firstIndex, indexCount,
3633 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003634}
3635
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003636ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003637 VkCmdBuffer cmdBuffer,
3638 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003639 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003640 uint32_t count,
3641 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003642{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003643 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3644
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003645 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003646}
3647
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003648ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003649 VkCmdBuffer cmdBuffer,
3650 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003651 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003652 uint32_t count,
3653 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003654{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003655 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3656
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003657 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003658}
3659
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003660ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003661 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003662 uint32_t x,
3663 uint32_t y,
3664 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003665{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003666 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3667
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003668 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003669}
3670
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003671ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003672 VkCmdBuffer cmdBuffer,
3673 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003674 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003675{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003676 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3677
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003678 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003679}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003680
Courtney Goeltzenleuchtera375b622015-07-27 14:04:01 -06003681void VKAPI vkCmdPushConstants(
3682 VkCmdBuffer cmdBuffer,
3683 VkPipelineLayout layout,
3684 VkShaderStageFlags stageFlags,
3685 uint32_t start,
3686 uint32_t length,
3687 const void* values)
3688{
3689 /* TODO: Implement */
3690}
Courtney Goeltzenleuchter07fe0662015-07-27 13:47:08 -06003691
3692VkResult VKAPI vkGetRenderAreaGranularity(
3693 VkDevice device,
3694 VkRenderPass renderPass,
3695 VkExtent2D* pGranularity)
3696{
3697 pGranularity->height = 1;
3698 pGranularity->width = 1;
3699
3700 return VK_SUCCESS;
3701}
3702
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003703ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Chia-I Wuc278df82015-07-07 11:50:03 +08003704 VkCmdBuffer cmdBuffer,
3705 const VkRenderPassBeginInfo* pRenderPassBegin,
3706 VkRenderPassContents contents)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003707{
Chia-I Wubdeed152015-07-09 12:16:29 +08003708 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3709 const struct intel_render_pass *rp =
3710 intel_render_pass(pRenderPassBegin->renderPass);
3711 const struct intel_fb *fb = intel_fb(pRenderPassBegin->framebuffer);
3712 const struct intel_att_view *view;
3713 uint32_t i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003714
Chia-I Wubdeed152015-07-09 12:16:29 +08003715 if (!cmd->primary || rp->attachment_count != fb->view_count) {
3716 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3717 return;
3718 }
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003719
Cody Northrop16898b02015-08-11 11:35:58 -06003720 cmd_begin_render_pass(cmd, rp, fb, 0, contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003721
Chia-I Wubdeed152015-07-09 12:16:29 +08003722 for (i = 0; i < rp->attachment_count; i++) {
3723 const struct intel_render_pass_attachment *att = &rp->attachments[i];
Chia-I Wuc278df82015-07-07 11:50:03 +08003724 const VkClearValue *clear_val =
Cody Northropc332eef2015-08-04 11:51:03 -06003725 &pRenderPassBegin->pClearValues[i];
Chia-I Wubdeed152015-07-09 12:16:29 +08003726 VkImageSubresourceRange range;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003727
Chia-I Wubdeed152015-07-09 12:16:29 +08003728 if (!att->clear_on_load)
3729 continue;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003730
Chia-I Wubdeed152015-07-09 12:16:29 +08003731 view = fb->views[i];
3732 range.baseMipLevel = view->mipLevel;
3733 range.mipLevels = 1;
3734 range.baseArraySlice = view->baseArraySlice;
3735 range.arraySize = view->array_size;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003736
Chia-I Wubdeed152015-07-09 12:16:29 +08003737 if (view->is_rt) {
3738 range.aspect = VK_IMAGE_ASPECT_COLOR;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003739
Tony Barbourde4124d2015-07-03 10:33:54 -06003740 cmd_meta_clear_color_image(cmdBuffer, view->img,
Chia-I Wuc278df82015-07-07 11:50:03 +08003741 att->initial_layout, &clear_val->color, 1, &range);
Chia-I Wubdeed152015-07-09 12:16:29 +08003742 } else {
3743 range.aspect = VK_IMAGE_ASPECT_DEPTH;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003744
Chia-I Wubdeed152015-07-09 12:16:29 +08003745 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003746 view->img, att->initial_layout,
Cody Northrop2563a032015-08-25 15:26:38 -06003747 clear_val->depthStencil.depth, clear_val->depthStencil.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003748 1, &range);
Chris Forbes4cf9d102015-06-22 18:46:05 +12003749
Chia-I Wubdeed152015-07-09 12:16:29 +08003750 if (att->stencil_clear_on_load) {
3751 range.aspect = VK_IMAGE_ASPECT_STENCIL;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003752
Chia-I Wubdeed152015-07-09 12:16:29 +08003753 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003754 view->img, att->initial_layout,
Cody Northrop2563a032015-08-25 15:26:38 -06003755 clear_val->depthStencil.depth, clear_val->depthStencil.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003756 1, &range);
3757 }
3758 }
3759 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003760}
3761
Chia-I Wuc278df82015-07-07 11:50:03 +08003762ICD_EXPORT void VKAPI vkCmdNextSubpass(
3763 VkCmdBuffer cmdBuffer,
3764 VkRenderPassContents contents)
3765{
3766 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3767 const struct intel_render_pass *rp = cmd->bind.render_pass;
3768
3769 if (cmd->bind.render_pass_subpass >= rp->subpasses +
3770 rp->subpass_count - 1) {
3771 cmd->result = VK_ERROR_UNKNOWN;
3772 return;
3773 }
3774
3775 cmd->bind.render_pass_changed = true;
3776 cmd->bind.render_pass_subpass++;
3777 cmd->bind.render_pass_contents = contents;
3778}
3779
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003780ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003781 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003782{
3783 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3784
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003785 cmd_end_render_pass(cmd);
3786}
3787
3788ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3789 VkCmdBuffer cmdBuffer,
3790 uint32_t cmdBuffersCount,
3791 const VkCmdBuffer* pCmdBuffers)
3792{
3793 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003794 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003795
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003796 if (!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3797 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) {
3798 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3799 return;
3800 }
3801
3802 for (i = 0; i < cmdBuffersCount; i++) {
3803 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3804
3805 if (secondary->primary) {
3806 cmd->result = VK_ERROR_INVALID_VALUE;
3807 break;
3808 }
3809
3810 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3811 }
3812
3813 if (i)
3814 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003815}