blob: afdd86910383e3ae62904131c484378c5be340b5 [file] [log] [blame]
Chia-I Wu09142132014-08-11 15:42:55 +08001/*
2 * XGL
3 *
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 Wu09142132014-08-11 15:42:55 +080027 */
28
Chia-I Wu730e5362014-08-19 12:15:09 +080029#include "genhw/genhw.h"
30#include "kmd/winsys.h"
31#include "dev.h"
Chia-I Wu343b1372014-08-20 16:39:20 +080032#include "mem.h"
Chia-I Wu730e5362014-08-19 12:15:09 +080033#include "obj.h"
Chia-I Wu00a23b22014-08-20 15:28:08 +080034#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070035#include "fb.h"
Chia-I Wu09142132014-08-11 15:42:55 +080036
Chia-I Wu3c3edc02014-09-09 10:32:59 +080037/**
38 * Free all resources used by a writer. Note that the initial size is not
39 * reset.
40 */
41static void cmd_writer_reset(struct intel_cmd *cmd,
42 enum intel_cmd_writer_type which)
Chia-I Wu730e5362014-08-19 12:15:09 +080043{
Chia-I Wu68f319d2014-09-09 09:43:21 +080044 struct intel_cmd_writer *writer = &cmd->writers[which];
Chia-I Wu730e5362014-08-19 12:15:09 +080045
Chia-I Wu3c3edc02014-09-09 10:32:59 +080046 if (writer->ptr) {
47 intel_bo_unmap(writer->bo);
48 writer->ptr = NULL;
Chia-I Wu730e5362014-08-19 12:15:09 +080049 }
50
Chia-I Wu3c3edc02014-09-09 10:32:59 +080051 if (writer->bo) {
52 intel_bo_unreference(writer->bo);
53 writer->bo = NULL;
54 }
55
Chia-I Wue24c3292014-08-21 14:05:23 +080056 writer->used = 0;
Chia-I Wu00b51a82014-09-09 12:07:37 +080057
Chia-I Wuf98dd882015-02-10 04:17:47 +080058 writer->sba_offset = 0;
59
Chia-I Wu00b51a82014-09-09 12:07:37 +080060 if (writer->items) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +080061 intel_free(cmd, writer->items);
Courtney Goeltzenleuchter2ba70162014-09-25 18:14:53 -060062 writer->items = NULL;
Chia-I Wu00b51a82014-09-09 12:07:37 +080063 writer->item_alloc = 0;
64 writer->item_used = 0;
65 }
Chia-I Wu3c3edc02014-09-09 10:32:59 +080066}
67
68/**
69 * Discard everything written so far.
70 */
71static void cmd_writer_discard(struct intel_cmd *cmd,
72 enum intel_cmd_writer_type which)
73{
74 struct intel_cmd_writer *writer = &cmd->writers[which];
75
76 intel_bo_truncate_relocs(writer->bo, 0);
77 writer->used = 0;
Chia-I Wu00b51a82014-09-09 12:07:37 +080078 writer->item_used = 0;
Chia-I Wu3c3edc02014-09-09 10:32:59 +080079}
80
81static struct intel_bo *alloc_writer_bo(struct intel_winsys *winsys,
82 enum intel_cmd_writer_type which,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060083 size_t size)
Chia-I Wu3c3edc02014-09-09 10:32:59 +080084{
85 static const char *writer_names[INTEL_CMD_WRITER_COUNT] = {
86 [INTEL_CMD_WRITER_BATCH] = "batch",
Chia-I Wu15cccf72015-02-10 04:07:40 +080087 [INTEL_CMD_WRITER_SURFACE] = "surface",
88 [INTEL_CMD_WRITER_STATE] = "state",
Chia-I Wu3c3edc02014-09-09 10:32:59 +080089 [INTEL_CMD_WRITER_INSTRUCTION] = "instruction",
90 };
91
Chia-I Wu72292b72014-09-09 10:48:33 +080092 return intel_winsys_alloc_buffer(winsys, writer_names[which], size, true);
Chia-I Wu3c3edc02014-09-09 10:32:59 +080093}
94
95/**
96 * Allocate and map the buffer for writing.
97 */
98static XGL_RESULT cmd_writer_alloc_and_map(struct intel_cmd *cmd,
99 enum intel_cmd_writer_type which)
100{
101 struct intel_cmd_writer *writer = &cmd->writers[which];
102 struct intel_bo *bo;
103
104 bo = alloc_writer_bo(cmd->dev->winsys, which, writer->size);
105 if (bo) {
106 if (writer->bo)
107 intel_bo_unreference(writer->bo);
108 writer->bo = bo;
109 } else if (writer->bo) {
110 /* reuse the old bo */
111 cmd_writer_discard(cmd, which);
112 } else {
113 return XGL_ERROR_OUT_OF_GPU_MEMORY;
114 }
115
116 writer->used = 0;
Chia-I Wu00b51a82014-09-09 12:07:37 +0800117 writer->item_used = 0;
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800118
119 writer->ptr = intel_bo_map(writer->bo, true);
120 if (!writer->ptr)
121 return XGL_ERROR_UNKNOWN;
Chia-I Wu730e5362014-08-19 12:15:09 +0800122
123 return XGL_SUCCESS;
124}
125
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800126/**
127 * Unmap the buffer for submission.
128 */
129static void cmd_writer_unmap(struct intel_cmd *cmd,
130 enum intel_cmd_writer_type which)
Chia-I Wu5e25c272014-08-21 20:19:12 +0800131{
Chia-I Wu68f319d2014-09-09 09:43:21 +0800132 struct intel_cmd_writer *writer = &cmd->writers[which];
133
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800134 intel_bo_unmap(writer->bo);
135 writer->ptr = NULL;
136}
137
138/**
139 * Grow a mapped writer to at least \p new_size. Failures are handled
140 * silently.
141 */
142void cmd_writer_grow(struct intel_cmd *cmd,
143 enum intel_cmd_writer_type which,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600144 size_t new_size)
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800145{
146 struct intel_cmd_writer *writer = &cmd->writers[which];
147 struct intel_bo *new_bo;
148 void *new_ptr;
149
150 if (new_size < writer->size << 1)
151 new_size = writer->size << 1;
152 /* STATE_BASE_ADDRESS requires page-aligned buffers */
Chia-I Wu72292b72014-09-09 10:48:33 +0800153 new_size = u_align(new_size, 4096);
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800154
155 new_bo = alloc_writer_bo(cmd->dev->winsys, which, new_size);
156 if (!new_bo) {
157 cmd_writer_discard(cmd, which);
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700158 cmd_fail(cmd, XGL_ERROR_OUT_OF_GPU_MEMORY);
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800159 return;
160 }
161
162 /* map and copy the data over */
163 new_ptr = intel_bo_map(new_bo, true);
164 if (!new_ptr) {
165 intel_bo_unreference(new_bo);
166 cmd_writer_discard(cmd, which);
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700167 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800168 return;
169 }
170
Chia-I Wu72292b72014-09-09 10:48:33 +0800171 memcpy(new_ptr, writer->ptr, writer->used);
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800172
173 intel_bo_unmap(writer->bo);
174 intel_bo_unreference(writer->bo);
175
176 writer->size = new_size;
177 writer->bo = new_bo;
178 writer->ptr = new_ptr;
Chia-I Wu5e25c272014-08-21 20:19:12 +0800179}
180
Chia-I Wu00b51a82014-09-09 12:07:37 +0800181/**
182 * Record an item for later decoding.
183 */
184void cmd_writer_record(struct intel_cmd *cmd,
185 enum intel_cmd_writer_type which,
186 enum intel_cmd_item_type type,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600187 size_t offset, size_t size)
Chia-I Wu00b51a82014-09-09 12:07:37 +0800188{
189 struct intel_cmd_writer *writer = &cmd->writers[which];
190 struct intel_cmd_item *item;
191
192 if (writer->item_used == writer->item_alloc) {
193 const unsigned new_alloc = (writer->item_alloc) ?
194 writer->item_alloc << 1 : 256;
195 struct intel_cmd_item *items;
196
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800197 items = intel_alloc(cmd, sizeof(writer->items[0]) * new_alloc,
Chia-I Wu00b51a82014-09-09 12:07:37 +0800198 0, XGL_SYSTEM_ALLOC_DEBUG);
199 if (!items) {
200 writer->item_used = 0;
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700201 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wu00b51a82014-09-09 12:07:37 +0800202 return;
203 }
204
205 memcpy(items, writer->items,
206 sizeof(writer->items[0]) * writer->item_alloc);
207
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800208 intel_free(cmd, writer->items);
Chia-I Wu00b51a82014-09-09 12:07:37 +0800209
210 writer->items = items;
211 writer->item_alloc = new_alloc;
212 }
213
214 item = &writer->items[writer->item_used++];
215 item->type = type;
216 item->offset = offset;
217 item->size = size;
218}
219
Chia-I Wu5e25c272014-08-21 20:19:12 +0800220static void cmd_writer_patch(struct intel_cmd *cmd,
Chia-I Wu68f319d2014-09-09 09:43:21 +0800221 enum intel_cmd_writer_type which,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600222 size_t offset, uint32_t val)
Chia-I Wu5e25c272014-08-21 20:19:12 +0800223{
Chia-I Wu68f319d2014-09-09 09:43:21 +0800224 struct intel_cmd_writer *writer = &cmd->writers[which];
225
Chia-I Wu72292b72014-09-09 10:48:33 +0800226 assert(offset + sizeof(val) <= writer->used);
227 *((uint32_t *) ((char *) writer->ptr + offset)) = val;
Chia-I Wu5e25c272014-08-21 20:19:12 +0800228}
229
Chia-I Wu730e5362014-08-19 12:15:09 +0800230static void cmd_reset(struct intel_cmd *cmd)
231{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600232 uint32_t i;
Chia-I Wu68f319d2014-09-09 09:43:21 +0800233
234 for (i = 0; i < INTEL_CMD_WRITER_COUNT; i++)
235 cmd_writer_reset(cmd, i);
Chia-I Wue97aa0e2014-08-27 12:51:26 +0800236
Chia-I Wua57761b2014-10-14 14:27:44 +0800237 if (cmd->bind.shader_cache.entries)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800238 intel_free(cmd, cmd->bind.shader_cache.entries);
Chia-I Wua57761b2014-10-14 14:27:44 +0800239
Chia-I Wuf8385062015-01-04 16:27:24 +0800240 if (cmd->bind.dset.graphics_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800241 intel_free(cmd, cmd->bind.dset.graphics_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +0800242 if (cmd->bind.dset.compute_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800243 intel_free(cmd, cmd->bind.dset.compute_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +0800244
Chia-I Wue97aa0e2014-08-27 12:51:26 +0800245 memset(&cmd->bind, 0, sizeof(cmd->bind));
246
Chia-I Wu343b1372014-08-20 16:39:20 +0800247 cmd->reloc_used = 0;
Chia-I Wu04966702014-08-20 15:05:03 +0800248 cmd->result = XGL_SUCCESS;
Chia-I Wu730e5362014-08-19 12:15:09 +0800249}
250
251static void cmd_destroy(struct intel_obj *obj)
252{
253 struct intel_cmd *cmd = intel_cmd_from_obj(obj);
254
255 intel_cmd_destroy(cmd);
256}
257
258XGL_RESULT intel_cmd_create(struct intel_dev *dev,
259 const XGL_CMD_BUFFER_CREATE_INFO *info,
260 struct intel_cmd **cmd_ret)
261{
Chia-I Wu63883292014-08-25 13:50:26 +0800262 int pipeline_select;
Chia-I Wu730e5362014-08-19 12:15:09 +0800263 struct intel_cmd *cmd;
264
Chia-I Wu63883292014-08-25 13:50:26 +0800265 switch (info->queueType) {
266 case XGL_QUEUE_TYPE_GRAPHICS:
267 pipeline_select = GEN6_PIPELINE_SELECT_DW0_SELECT_3D;
268 break;
269 case XGL_QUEUE_TYPE_COMPUTE:
270 pipeline_select = GEN6_PIPELINE_SELECT_DW0_SELECT_MEDIA;
271 break;
272 case XGL_QUEUE_TYPE_DMA:
273 pipeline_select = -1;
274 break;
275 default:
276 return XGL_ERROR_INVALID_VALUE;
277 break;
278 }
279
Chia-I Wu545c2e12015-02-22 13:19:54 +0800280 cmd = (struct intel_cmd *) intel_base_create(&dev->base.handle,
281 sizeof(*cmd), dev->base.dbg, XGL_DBG_OBJECT_CMD_BUFFER, info, 0);
Chia-I Wu730e5362014-08-19 12:15:09 +0800282 if (!cmd)
283 return XGL_ERROR_OUT_OF_MEMORY;
284
285 cmd->obj.destroy = cmd_destroy;
286
287 cmd->dev = dev;
Chia-I Wu0b784442014-08-25 22:54:16 +0800288 cmd->scratch_bo = dev->cmd_scratch_bo;
Chia-I Wu63883292014-08-25 13:50:26 +0800289 cmd->pipeline_select = pipeline_select;
Chia-I Wue24c3292014-08-21 14:05:23 +0800290
Chia-I Wue0cdd832014-08-25 12:38:56 +0800291 /*
292 * XXX This is not quite right. intel_gpu sets maxMemRefsPerSubmission to
293 * batch_buffer_reloc_count, but we may emit up to two relocs, for start
294 * and end offsets, for each referenced memories.
295 */
Chia-I Wu343b1372014-08-20 16:39:20 +0800296 cmd->reloc_count = dev->gpu->batch_buffer_reloc_count;
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800297 cmd->relocs = intel_alloc(cmd, sizeof(cmd->relocs[0]) * cmd->reloc_count,
Chia-I Wu343b1372014-08-20 16:39:20 +0800298 4096, XGL_SYSTEM_ALLOC_INTERNAL);
299 if (!cmd->relocs) {
300 intel_cmd_destroy(cmd);
301 return XGL_ERROR_OUT_OF_MEMORY;
302 }
Chia-I Wu730e5362014-08-19 12:15:09 +0800303
304 *cmd_ret = cmd;
305
306 return XGL_SUCCESS;
307}
308
309void intel_cmd_destroy(struct intel_cmd *cmd)
310{
311 cmd_reset(cmd);
Chia-I Wue24c3292014-08-21 14:05:23 +0800312
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800313 intel_free(cmd, cmd->relocs);
Chia-I Wu730e5362014-08-19 12:15:09 +0800314 intel_base_destroy(&cmd->obj.base);
315}
316
Chia-I Wuc6025ac2015-02-18 14:59:11 -0700317XGL_RESULT intel_cmd_begin(struct intel_cmd *cmd, const XGL_CMD_BUFFER_BEGIN_INFO *info)
Chia-I Wu730e5362014-08-19 12:15:09 +0800318{
Chia-I Wuc6025ac2015-02-18 14:59:11 -0700319 const XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *ginfo;
Chia-I Wu24565ee2014-08-21 20:24:31 +0800320 XGL_RESULT ret;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600321 uint32_t i;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700322 XGL_FLAGS flags = 0;
Chia-I Wu730e5362014-08-19 12:15:09 +0800323
324 cmd_reset(cmd);
325
Chia-I Wuc6025ac2015-02-18 14:59:11 -0700326 while (info != NULL) {
327 switch (info->sType) {
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700328 case XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO:
Chia-I Wuc6025ac2015-02-18 14:59:11 -0700329 flags = info->flags;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700330 break;
331 case XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO:
Chia-I Wuc6025ac2015-02-18 14:59:11 -0700332 ginfo = (const XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *) info;
333 cmd_begin_render_pass(cmd, intel_render_pass(ginfo->renderPass));
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700334 break;
335 default:
336 return XGL_ERROR_INVALID_VALUE;
337 break;
338 }
Chia-I Wuc6025ac2015-02-18 14:59:11 -0700339
340 info = (const XGL_CMD_BUFFER_BEGIN_INFO*) info->pNext;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700341 }
342
Chia-I Wu24565ee2014-08-21 20:24:31 +0800343 if (cmd->flags != flags) {
Chia-I Wue24c3292014-08-21 14:05:23 +0800344 cmd->flags = flags;
Chia-I Wu68f319d2014-09-09 09:43:21 +0800345 cmd->writers[INTEL_CMD_WRITER_BATCH].size = 0;
Chia-I Wu730e5362014-08-19 12:15:09 +0800346 }
347
Chia-I Wu68f319d2014-09-09 09:43:21 +0800348 if (!cmd->writers[INTEL_CMD_WRITER_BATCH].size) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600349 const uint32_t size = cmd->dev->gpu->max_batch_buffer_size / 2;
350 uint32_t divider = 1;
Chia-I Wu24565ee2014-08-21 20:24:31 +0800351
352 if (flags & XGL_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT)
353 divider *= 4;
354
Chia-I Wu68f319d2014-09-09 09:43:21 +0800355 cmd->writers[INTEL_CMD_WRITER_BATCH].size = size / divider;
Chia-I Wu15cccf72015-02-10 04:07:40 +0800356 cmd->writers[INTEL_CMD_WRITER_SURFACE].size = size / divider / 2;
357 cmd->writers[INTEL_CMD_WRITER_STATE].size = size / divider / 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800358 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].size = 16384 / divider;
Chia-I Wu24565ee2014-08-21 20:24:31 +0800359 }
360
Chia-I Wu68f319d2014-09-09 09:43:21 +0800361 for (i = 0; i < INTEL_CMD_WRITER_COUNT; i++) {
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800362 ret = cmd_writer_alloc_and_map(cmd, i);
Chia-I Wu68f319d2014-09-09 09:43:21 +0800363 if (ret != XGL_SUCCESS) {
364 cmd_reset(cmd);
365 return ret;
366 }
Chia-I Wu24565ee2014-08-21 20:24:31 +0800367 }
368
Chia-I Wu79dfbb32014-08-25 12:19:02 +0800369 cmd_batch_begin(cmd);
370
Chia-I Wu24565ee2014-08-21 20:24:31 +0800371 return XGL_SUCCESS;
Chia-I Wu730e5362014-08-19 12:15:09 +0800372}
373
374XGL_RESULT intel_cmd_end(struct intel_cmd *cmd)
375{
376 struct intel_winsys *winsys = cmd->dev->winsys;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600377 uint32_t i;
Chia-I Wu730e5362014-08-19 12:15:09 +0800378
Chia-I Wub8762122014-12-01 22:51:03 +0800379 /* no matching intel_cmd_begin() */
380 if (!cmd->writers[INTEL_CMD_WRITER_BATCH].ptr)
381 return XGL_ERROR_INCOMPLETE_COMMAND_BUFFER;
382
Chia-I Wue24c3292014-08-21 14:05:23 +0800383 cmd_batch_end(cmd);
Chia-I Wu730e5362014-08-19 12:15:09 +0800384
Chia-I Wu343b1372014-08-20 16:39:20 +0800385 /* TODO we need a more "explicit" winsys */
Chia-I Wufdfb8ed2014-08-21 15:40:07 +0800386 for (i = 0; i < cmd->reloc_used; i++) {
Chia-I Wu343b1372014-08-20 16:39:20 +0800387 const struct intel_cmd_reloc *reloc = &cmd->relocs[i];
Chia-I Wu68f319d2014-09-09 09:43:21 +0800388 const struct intel_cmd_writer *writer = &cmd->writers[reloc->which];
Chia-I Wu343b1372014-08-20 16:39:20 +0800389 uint64_t presumed_offset;
390 int err;
391
Chia-I Wud7d1e482014-10-18 13:25:10 +0800392 /*
393 * Once a bo is used as a reloc target, libdrm_intel disallows more
394 * relocs to be added to it. That may happen when
395 * INTEL_CMD_RELOC_TARGET_IS_WRITER is set. We have to process them
396 * in another pass.
397 */
398 if (reloc->flags & INTEL_CMD_RELOC_TARGET_IS_WRITER)
399 continue;
400
Chia-I Wu72292b72014-09-09 10:48:33 +0800401 err = intel_bo_add_reloc(writer->bo, reloc->offset,
Chia-I Wud7d1e482014-10-18 13:25:10 +0800402 (struct intel_bo *) reloc->target, reloc->target_offset,
Chia-I Wu32a22462014-08-26 14:13:46 +0800403 reloc->flags, &presumed_offset);
Chia-I Wu343b1372014-08-20 16:39:20 +0800404 if (err) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700405 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu343b1372014-08-20 16:39:20 +0800406 break;
407 }
408
409 assert(presumed_offset == (uint64_t) (uint32_t) presumed_offset);
Chia-I Wu72292b72014-09-09 10:48:33 +0800410 cmd_writer_patch(cmd, reloc->which, reloc->offset,
Chia-I Wue24c3292014-08-21 14:05:23 +0800411 (uint32_t) presumed_offset);
Chia-I Wu343b1372014-08-20 16:39:20 +0800412 }
Chia-I Wud7d1e482014-10-18 13:25:10 +0800413 for (i = 0; i < cmd->reloc_used; i++) {
414 const struct intel_cmd_reloc *reloc = &cmd->relocs[i];
415 const struct intel_cmd_writer *writer = &cmd->writers[reloc->which];
416 uint64_t presumed_offset;
417 int err;
418
419 if (!(reloc->flags & INTEL_CMD_RELOC_TARGET_IS_WRITER))
420 continue;
421
422 err = intel_bo_add_reloc(writer->bo, reloc->offset,
423 cmd->writers[reloc->target].bo, reloc->target_offset,
424 reloc->flags & ~INTEL_CMD_RELOC_TARGET_IS_WRITER,
425 &presumed_offset);
426 if (err) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700427 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wud7d1e482014-10-18 13:25:10 +0800428 break;
429 }
430
431 assert(presumed_offset == (uint64_t) (uint32_t) presumed_offset);
432 cmd_writer_patch(cmd, reloc->which, reloc->offset,
433 (uint32_t) presumed_offset);
434 }
Chia-I Wu343b1372014-08-20 16:39:20 +0800435
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800436 for (i = 0; i < INTEL_CMD_WRITER_COUNT; i++)
437 cmd_writer_unmap(cmd, i);
Chia-I Wu730e5362014-08-19 12:15:09 +0800438
Chia-I Wu04966702014-08-20 15:05:03 +0800439 if (cmd->result != XGL_SUCCESS)
440 return cmd->result;
Chia-I Wue24c3292014-08-21 14:05:23 +0800441
Chia-I Wu68f319d2014-09-09 09:43:21 +0800442 if (intel_winsys_can_submit_bo(winsys,
443 &cmd->writers[INTEL_CMD_WRITER_BATCH].bo, 1))
Chia-I Wu730e5362014-08-19 12:15:09 +0800444 return XGL_SUCCESS;
445 else
446 return XGL_ERROR_TOO_MANY_MEMORY_REFERENCES;
447}
448
Chia-I Wu96177272015-01-03 15:27:41 +0800449ICD_EXPORT XGL_RESULT XGLAPI xglCreateCommandBuffer(
Chia-I Wu09142132014-08-11 15:42:55 +0800450 XGL_DEVICE device,
451 const XGL_CMD_BUFFER_CREATE_INFO* pCreateInfo,
452 XGL_CMD_BUFFER* pCmdBuffer)
453{
Chia-I Wu730e5362014-08-19 12:15:09 +0800454 struct intel_dev *dev = intel_dev(device);
455
456 return intel_cmd_create(dev, pCreateInfo,
457 (struct intel_cmd **) pCmdBuffer);
Chia-I Wu09142132014-08-11 15:42:55 +0800458}
459
Chia-I Wu96177272015-01-03 15:27:41 +0800460ICD_EXPORT XGL_RESULT XGLAPI xglBeginCommandBuffer(
Chia-I Wu09142132014-08-11 15:42:55 +0800461 XGL_CMD_BUFFER cmdBuffer,
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700462 const XGL_CMD_BUFFER_BEGIN_INFO *info)
Chia-I Wu09142132014-08-11 15:42:55 +0800463{
Chia-I Wu730e5362014-08-19 12:15:09 +0800464 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
465
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700466 return intel_cmd_begin(cmd, info);
Chia-I Wu09142132014-08-11 15:42:55 +0800467}
468
Chia-I Wu96177272015-01-03 15:27:41 +0800469ICD_EXPORT XGL_RESULT XGLAPI xglEndCommandBuffer(
Chia-I Wu09142132014-08-11 15:42:55 +0800470 XGL_CMD_BUFFER cmdBuffer)
471{
Chia-I Wu730e5362014-08-19 12:15:09 +0800472 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
473
474 return intel_cmd_end(cmd);
Chia-I Wu09142132014-08-11 15:42:55 +0800475}
476
Chia-I Wu96177272015-01-03 15:27:41 +0800477ICD_EXPORT XGL_RESULT XGLAPI xglResetCommandBuffer(
Chia-I Wu09142132014-08-11 15:42:55 +0800478 XGL_CMD_BUFFER cmdBuffer)
479{
Chia-I Wu730e5362014-08-19 12:15:09 +0800480 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
481
482 cmd_reset(cmd);
483
484 return XGL_SUCCESS;
Chia-I Wu09142132014-08-11 15:42:55 +0800485}
486
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600487ICD_EXPORT void XGLAPI xglCmdInitAtomicCounters(
Chia-I Wu09142132014-08-11 15:42:55 +0800488 XGL_CMD_BUFFER cmdBuffer,
489 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600490 uint32_t startCounter,
491 uint32_t counterCount,
492 const uint32_t* pData)
Chia-I Wu09142132014-08-11 15:42:55 +0800493{
494}
495
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600496ICD_EXPORT void XGLAPI xglCmdLoadAtomicCounters(
Chia-I Wu09142132014-08-11 15:42:55 +0800497 XGL_CMD_BUFFER cmdBuffer,
498 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600499 uint32_t startCounter,
500 uint32_t counterCount,
Chia-I Wu714df452015-01-01 07:55:04 +0800501 XGL_BUFFER srcBuffer,
Chia-I Wu09142132014-08-11 15:42:55 +0800502 XGL_GPU_SIZE srcOffset)
503{
504}
505
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600506ICD_EXPORT void XGLAPI xglCmdSaveAtomicCounters(
Chia-I Wu09142132014-08-11 15:42:55 +0800507 XGL_CMD_BUFFER cmdBuffer,
508 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600509 uint32_t startCounter,
510 uint32_t counterCount,
Chia-I Wu714df452015-01-01 07:55:04 +0800511 XGL_BUFFER destBuffer,
Chia-I Wu09142132014-08-11 15:42:55 +0800512 XGL_GPU_SIZE destOffset)
513{
514}
515
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600516ICD_EXPORT void XGLAPI xglCmdDbgMarkerBegin(
Chia-I Wu09142132014-08-11 15:42:55 +0800517 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600518 const char* pMarker)
Chia-I Wu09142132014-08-11 15:42:55 +0800519{
520}
521
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600522ICD_EXPORT void XGLAPI xglCmdDbgMarkerEnd(
Chia-I Wu09142132014-08-11 15:42:55 +0800523 XGL_CMD_BUFFER cmdBuffer)
524{
525}