blob: 114a654482c0da45f7f3ed7d91e22cd5d18da2de [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 Goeltzenleuchterac544f32015-09-14 18:01:17 -0600130 /* TODOVV: validate */
131 cmd_fail(cmd, VK_ERROR_VALIDATION_FAILED);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800132 break;
133 }
134}
135
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600136ICD_EXPORT void VKAPI vkCmdEndQuery(
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600137 VkCmdBuffer cmdBuffer,
138 VkQueryPool queryPool,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600139 uint32_t slot)
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800140{
141 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
142 struct intel_query *query = intel_query(queryPool);
143 struct intel_bo *bo = query->obj.mem->bo;
Tony Barbour8205d902015-04-16 15:59:00 -0600144 const VkDeviceSize offset = query->slot_stride * slot;
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800145
146 switch (query->type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600147 case VK_QUERY_TYPE_OCCLUSION:
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800148 cmd_batch_depth_count(cmd, bo, offset + sizeof(uint64_t));
149 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600150 case VK_QUERY_TYPE_PIPELINE_STATISTICS:
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600151 cmd_query_pipeline_statistics(cmd, query, bo, offset + query->slot_stride);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800152 break;
153 default:
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600154 /* TODOVV: validate */
155 cmd_fail(cmd, VK_ERROR_VALIDATION_FAILED);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800156 break;
157 }
158}
159
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600160ICD_EXPORT void VKAPI vkCmdResetQueryPool(
Courtney Goeltzenleuchter29862812015-04-16 09:13:59 -0600161 VkCmdBuffer cmdBuffer,
162 VkQueryPool queryPool,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600163 uint32_t startQuery,
164 uint32_t queryCount)
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800165{
Chia-I Wue9115ee2014-08-31 12:58:35 +0800166 /* no-op */
167}
168
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -0600169static void cmd_write_event_value(struct intel_cmd *cmd, struct intel_event *event,
Tony Barbourc2e987e2015-06-29 16:20:35 -0600170 VkPipelineStageFlags stageMask, uint32_t value)
Chia-I Wue9115ee2014-08-31 12:58:35 +0800171{
Tony Barbourc2e987e2015-06-29 16:20:35 -0600172 uint32_t pipe_control_flags = 0;
Chia-I Wue9115ee2014-08-31 12:58:35 +0800173
Mike Stroyan55658c22014-12-04 11:08:39 +0000174 /* Event setting is done with PIPE_CONTROL post-sync write immediate.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600175 * With no other PIPE_CONTROL flags set, it behaves as VK_PIPE_EVENT_TOP_OF_PIPE.
Tony Barbour8205d902015-04-16 15:59:00 -0600176 * All other pipeEvent values will behave as VK_PIPE_EVENT_COMMANDS_COMPLETE.
Mike Stroyan55658c22014-12-04 11:08:39 +0000177 */
Tony Barbourc2e987e2015-06-29 16:20:35 -0600178 if (stageMask & VK_PIPELINE_STAGE_ALL_GRAPHICS) {
Mike Stroyan55658c22014-12-04 11:08:39 +0000179 pipe_control_flags = GEN6_PIPE_CONTROL_CS_STALL;
Mike Stroyan55658c22014-12-04 11:08:39 +0000180 }
Tony Barbourc2e987e2015-06-29 16:20:35 -0600181
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -0600182 cmd_batch_immediate(cmd, pipe_control_flags, event->obj.mem->bo, 0, value);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800183}
184
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600185ICD_EXPORT void VKAPI vkCmdSetEvent(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600186 VkCmdBuffer cmdBuffer,
Tony Barbourc2e987e2015-06-29 16:20:35 -0600187 VkEvent event_,
188 VkPipelineStageFlags stageMask)
Chia-I Wue9115ee2014-08-31 12:58:35 +0800189{
190 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
191 struct intel_event *event = intel_event(event_);
192
Tony Barbourc2e987e2015-06-29 16:20:35 -0600193 cmd_write_event_value(cmd, event, stageMask, 1);
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -0600194}
195
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600196ICD_EXPORT void VKAPI vkCmdResetEvent(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600197 VkCmdBuffer cmdBuffer,
Tony Barbourc2e987e2015-06-29 16:20:35 -0600198 VkEvent event_,
199 VkPipelineStageFlags stageMask)
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -0600200{
201 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
202 struct intel_event *event = intel_event(event_);
203
Tony Barbourc2e987e2015-06-29 16:20:35 -0600204 cmd_write_event_value(cmd, event, stageMask, 0);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800205}
206
Courtney Goeltzenleuchter98049062015-04-15 18:21:13 -0600207ICD_EXPORT void VKAPI vkCmdCopyQueryPoolResults(
208 VkCmdBuffer cmdBuffer,
209 VkQueryPool queryPool,
210 uint32_t startQuery,
211 uint32_t queryCount,
212 VkBuffer destBuffer,
Tony Barbour8205d902015-04-16 15:59:00 -0600213 VkDeviceSize destOffset,
214 VkDeviceSize destStride,
Courtney Goeltzenleuchter98049062015-04-15 18:21:13 -0600215 VkFlags flags)
216{
217 /* TODO: Fill in functionality here */
218}
219
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600220ICD_EXPORT void VKAPI vkCmdWriteTimestamp(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600221 VkCmdBuffer cmdBuffer,
222 VkTimestampType timestampType,
223 VkBuffer destBuffer,
Tony Barbour8205d902015-04-16 15:59:00 -0600224 VkDeviceSize destOffset)
Chia-I Wue9115ee2014-08-31 12:58:35 +0800225{
226 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +0800227 struct intel_buf *buf = intel_buf(destBuffer);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800228
229 switch (timestampType) {
Tony Barbour8205d902015-04-16 15:59:00 -0600230 case VK_TIMESTAMP_TYPE_TOP:
Chia-I Wue9115ee2014-08-31 12:58:35 +0800231 /* XXX we are not supposed to use two commands... */
Chia-I Wu714df452015-01-01 07:55:04 +0800232 gen6_MI_STORE_REGISTER_MEM(cmd, buf->obj.mem->bo,
233 destOffset, GEN6_REG_TIMESTAMP);
234 gen6_MI_STORE_REGISTER_MEM(cmd, buf->obj.mem->bo,
235 destOffset + 4, GEN6_REG_TIMESTAMP + 4);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800236 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600237 case VK_TIMESTAMP_TYPE_BOTTOM:
Chia-I Wu714df452015-01-01 07:55:04 +0800238 cmd_batch_timestamp(cmd, buf->obj.mem->bo, destOffset);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800239 break;
240 default:
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -0600241 /* TODOVV: This should be covered by validation error */
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600242 cmd_fail(cmd, VK_ERROR_VALIDATION_FAILED);
Chia-I Wue9115ee2014-08-31 12:58:35 +0800243 break;
244 }
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800245}