blob: 4ebefbb70d14cd0f89d511ae678ee2007cfc49e1 [file] [log] [blame]
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wu759fa2e2014-08-30 18:44:47 +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>
Chia-I Wu759fa2e2014-08-30 18:44:47 +080026 */
27
Chia-I Wu714df452015-01-01 07:55:04 +080028#include "kmd/winsys.h"
29#include "buf.h"
Chia-I Wue9115ee2014-08-31 12:58:35 +080030#include "event.h"
Chia-I Wu714df452015-01-01 07:55:04 +080031#include "mem.h"
Chia-I Wu759fa2e2014-08-30 18:44:47 +080032#include "obj.h"
33#include "query.h"
34#include "cmd_priv.h"
35
36static void gen6_MI_STORE_REGISTER_MEM(struct intel_cmd *cmd,
37 struct intel_bo *bo,
38 uint32_t offset,
39 uint32_t reg)
40{
41 const uint8_t cmd_len = 3;
42 uint32_t dw0 = GEN6_MI_CMD(MI_STORE_REGISTER_MEM) |
43 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +080044 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +080045 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060046 uint32_t pos;
Chia-I Wu759fa2e2014-08-30 18:44:47 +080047
Chia-I Wu2caf7492014-08-31 12:28:38 +080048 if (cmd_gen(cmd) == INTEL_GEN(6)) {
Chia-I Wu759fa2e2014-08-30 18:44:47 +080049 dw0 |= GEN6_MI_STORE_REGISTER_MEM_DW0_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +080050 reloc_flags |= INTEL_RELOC_GGTT;
51 }
Chia-I Wu759fa2e2014-08-30 18:44:47 +080052
Chia-I Wu72292b72014-09-09 10:48:33 +080053 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
54 dw[0] = dw0;
55 dw[1] = reg;
56
57 cmd_reserve_reloc(cmd, 1);
58 cmd_batch_reloc(cmd, pos + 2, bo, offset, reloc_flags);
Chia-I Wu759fa2e2014-08-30 18:44:47 +080059}
60
61static void gen6_MI_STORE_DATA_IMM(struct intel_cmd *cmd,
62 struct intel_bo *bo,
63 uint32_t offset,
64 uint64_t val)
65{
66 const uint8_t cmd_len = 5;
67 uint32_t dw0 = GEN6_MI_CMD(MI_STORE_DATA_IMM) |
68 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +080069 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +080070 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060071 uint32_t pos;
Chia-I Wu759fa2e2014-08-30 18:44:47 +080072
Chia-I Wu2caf7492014-08-31 12:28:38 +080073 if (cmd_gen(cmd) == INTEL_GEN(6)) {
Chia-I Wu759fa2e2014-08-30 18:44:47 +080074 dw0 |= GEN6_MI_STORE_DATA_IMM_DW0_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +080075 reloc_flags |= INTEL_RELOC_GGTT;
76 }
Chia-I Wu759fa2e2014-08-30 18:44:47 +080077
Chia-I Wu72292b72014-09-09 10:48:33 +080078 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
79 dw[0] = dw0;
80 dw[1] = 0;
81 dw[3] = (uint32_t) val;
82 dw[4] = (uint32_t) (val >> 32);
83
84 cmd_reserve_reloc(cmd, 1);
85 cmd_batch_reloc(cmd, pos + 2, bo, offset, reloc_flags);
Chia-I Wu759fa2e2014-08-30 18:44:47 +080086}
87
88static void cmd_query_pipeline_statistics(struct intel_cmd *cmd,
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -060089 const struct intel_query *query,
Chia-I Wu759fa2e2014-08-30 18:44:47 +080090 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -060091 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +080092{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060093 uint32_t i;
Chia-I Wu759fa2e2014-08-30 18:44:47 +080094
95 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_CS_STALL);
96
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -060097 for (i = 0; i < query->reg_count; i++) {
98 if (query->regs[i]) {
Chia-I Wu759fa2e2014-08-30 18:44:47 +080099 /* store lower 32 bits */
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600100 gen6_MI_STORE_REGISTER_MEM(cmd, bo, offset, query->regs[i]);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800101 /* store higher 32 bits */
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600102 gen6_MI_STORE_REGISTER_MEM(cmd, bo, offset + 4, query->regs[i] + 4);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800103 } else {
104 gen6_MI_STORE_DATA_IMM(cmd, bo, offset, 0);
105 }
Chia-I Wu8a927bd2014-08-31 00:06:36 +0800106
107 offset += sizeof(uint64_t);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800108 }
109}
110
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600111ICD_EXPORT void VKAPI vkCmdBeginQuery(
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600112 VkCmdBuffer cmdBuffer,
113 VkQueryPool queryPool,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600114 uint32_t slot,
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600115 VkQueryControlFlags flags)
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800116{
117 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
118 struct intel_query *query = intel_query(queryPool);
119 struct intel_bo *bo = query->obj.mem->bo;
Tony Barbour8205d902015-04-16 15:59:00 -0600120 const VkDeviceSize offset = query->slot_stride * slot;
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800121
122 switch (query->type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600123 case VK_QUERY_TYPE_OCCLUSION:
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800124 cmd_batch_depth_count(cmd, bo, offset);
125 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600126 case VK_QUERY_TYPE_PIPELINE_STATISTICS:
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600127 cmd_query_pipeline_statistics(cmd, query, bo, offset);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800128 break;
129 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600130 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800131 break;
132 }
133}
134
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600135ICD_EXPORT void VKAPI vkCmdEndQuery(
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600136 VkCmdBuffer cmdBuffer,
137 VkQueryPool queryPool,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600138 uint32_t slot)
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800139{
140 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
141 struct intel_query *query = intel_query(queryPool);
142 struct intel_bo *bo = query->obj.mem->bo;
Tony Barbour8205d902015-04-16 15:59:00 -0600143 const VkDeviceSize offset = query->slot_stride * slot;
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800144
145 switch (query->type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600146 case VK_QUERY_TYPE_OCCLUSION:
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800147 cmd_batch_depth_count(cmd, bo, offset + sizeof(uint64_t));
148 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600149 case VK_QUERY_TYPE_PIPELINE_STATISTICS:
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600150 cmd_query_pipeline_statistics(cmd, query, bo, offset + query->slot_stride);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800151 break;
152 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600153 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800154 break;
155 }
156}
157
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600158ICD_EXPORT void VKAPI vkCmdResetQueryPool(
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600159 VkCmdBuffer cmdBuffer,
160 VkQueryPool queryPool,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600161 uint32_t startQuery,
162 uint32_t queryCount)
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800163{
Chia-I Wue9115ee2014-08-31 12:58:35 +0800164 /* no-op */
165}
166
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -0600167static void cmd_write_event_value(struct intel_cmd *cmd, struct intel_event *event,
Tony Barbourc2e987e2015-06-29 16:20:35 -0600168 VkPipelineStageFlags stageMask, uint32_t value)
Chia-I Wue9115ee2014-08-31 12:58:35 +0800169{
Tony Barbourc2e987e2015-06-29 16:20:35 -0600170 uint32_t pipe_control_flags = 0;
Chia-I Wue9115ee2014-08-31 12:58:35 +0800171
Mike Stroyan55658c22014-12-04 11:08:39 +0000172 /* Event setting is done with PIPE_CONTROL post-sync write immediate.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600173 * With no other PIPE_CONTROL flags set, it behaves as VK_PIPE_EVENT_TOP_OF_PIPE.
Tony Barbour8205d902015-04-16 15:59:00 -0600174 * All other pipeEvent values will behave as VK_PIPE_EVENT_COMMANDS_COMPLETE.
Mike Stroyan55658c22014-12-04 11:08:39 +0000175 */
Tony Barbourc2e987e2015-06-29 16:20:35 -0600176 if (stageMask & VK_PIPELINE_STAGE_ALL_GRAPHICS) {
Mike Stroyan55658c22014-12-04 11:08:39 +0000177 pipe_control_flags = GEN6_PIPE_CONTROL_CS_STALL;
Mike Stroyan55658c22014-12-04 11:08:39 +0000178 }
Tony Barbourc2e987e2015-06-29 16:20:35 -0600179
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -0600180 cmd_batch_immediate(cmd, pipe_control_flags, event->obj.mem->bo, 0, value);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800181}
182
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600183ICD_EXPORT void VKAPI vkCmdSetEvent(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600184 VkCmdBuffer cmdBuffer,
Tony Barbourc2e987e2015-06-29 16:20:35 -0600185 VkEvent event_,
186 VkPipelineStageFlags stageMask)
Chia-I Wue9115ee2014-08-31 12:58:35 +0800187{
188 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
189 struct intel_event *event = intel_event(event_);
190
Tony Barbourc2e987e2015-06-29 16:20:35 -0600191 cmd_write_event_value(cmd, event, stageMask, 1);
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -0600192}
193
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600194ICD_EXPORT void VKAPI vkCmdResetEvent(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600195 VkCmdBuffer cmdBuffer,
Tony Barbourc2e987e2015-06-29 16:20:35 -0600196 VkEvent event_,
197 VkPipelineStageFlags stageMask)
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -0600198{
199 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
200 struct intel_event *event = intel_event(event_);
201
Tony Barbourc2e987e2015-06-29 16:20:35 -0600202 cmd_write_event_value(cmd, event, stageMask, 0);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800203}
204
Courtney Goeltzenleuchter98049062015-04-15 18:21:13 -0600205ICD_EXPORT void VKAPI vkCmdCopyQueryPoolResults(
206 VkCmdBuffer cmdBuffer,
207 VkQueryPool queryPool,
208 uint32_t startQuery,
209 uint32_t queryCount,
210 VkBuffer destBuffer,
Tony Barbour8205d902015-04-16 15:59:00 -0600211 VkDeviceSize destOffset,
212 VkDeviceSize destStride,
Courtney Goeltzenleuchter98049062015-04-15 18:21:13 -0600213 VkFlags flags)
214{
215 /* TODO: Fill in functionality here */
216}
217
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600218ICD_EXPORT void VKAPI vkCmdWriteTimestamp(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600219 VkCmdBuffer cmdBuffer,
220 VkTimestampType timestampType,
221 VkBuffer destBuffer,
Tony Barbour8205d902015-04-16 15:59:00 -0600222 VkDeviceSize destOffset)
Chia-I Wue9115ee2014-08-31 12:58:35 +0800223{
224 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +0800225 struct intel_buf *buf = intel_buf(destBuffer);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800226
227 switch (timestampType) {
Tony Barbour8205d902015-04-16 15:59:00 -0600228 case VK_TIMESTAMP_TYPE_TOP:
Chia-I Wue9115ee2014-08-31 12:58:35 +0800229 /* XXX we are not supposed to use two commands... */
Chia-I Wu714df452015-01-01 07:55:04 +0800230 gen6_MI_STORE_REGISTER_MEM(cmd, buf->obj.mem->bo,
231 destOffset, GEN6_REG_TIMESTAMP);
232 gen6_MI_STORE_REGISTER_MEM(cmd, buf->obj.mem->bo,
233 destOffset + 4, GEN6_REG_TIMESTAMP + 4);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800234 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600235 case VK_TIMESTAMP_TYPE_BOTTOM:
Chia-I Wu714df452015-01-01 07:55:04 +0800236 cmd_batch_timestamp(cmd, buf->obj.mem->bo, destOffset);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800237 break;
238 default:
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -0600239 /* TODOVV: This should be covered by validation error */
240 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800241 break;
242 }
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800243}