| 1 |
/* |
| 2 |
* Copyright © 2022 Imagination Technologies Ltd. |
| 3 |
* |
| 4 |
* based in part on anv driver which is: |
| 5 |
* Copyright © 2015 Intel Corporation |
| 6 |
* |
| 7 |
* based in part on v3dv_cl.c which is: |
| 8 |
* Copyright © 2019 Raspberry Pi |
| 9 |
* |
| 10 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 |
* of this software and associated documentation files (the "Software"), to deal |
| 12 |
* in the Software without restriction, including without limitation the rights |
| 13 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 |
* copies of the Software, and to permit persons to whom the Software is |
| 15 |
* furnished to do so, subject to the following conditions: |
| 16 |
* |
| 17 |
* The above copyright notice and this permission notice (including the next |
| 18 |
* paragraph) shall be included in all copies or substantial portions of the |
| 19 |
* Software. |
| 20 |
* |
| 21 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 27 |
* SOFTWARE. |
| 28 |
*/ |
| 29 |
|
| 30 |
#include "pvr_csb.h" |
| 31 |
|
| 32 |
#include <assert.h> |
| 33 |
#include <stdbool.h> |
| 34 |
#include <stdint.h> |
| 35 |
#include <string.h> |
| 36 |
#include <vulkan/vulkan.h> |
| 37 |
|
| 38 |
#include "hwdef/pvr_hw_utils.h" |
| 39 |
#include "pvr_bo.h" |
| 40 |
#include "pvr_debug.h" |
| 41 |
#include "pvr_device.h" |
| 42 |
#include "pvr_device_info.h" |
| 43 |
#include "pvr_macros.h" |
| 44 |
#include "pvr_physical_device.h" |
| 45 |
#include "pvr_types.h" |
| 46 |
#include "util/list.h" |
| 47 |
#include "util/u_dynarray.h" |
| 48 |
#include "vk_log.h" |
| 49 |
|
| 50 |
/** |
| 51 |
* \file pvr_csb.c |
| 52 |
* |
| 53 |
* \brief Contains functions to manage Control Stream Builder (csb) object. |
| 54 |
* |
| 55 |
* A csb object can be used to create a primary/main control stream, referred |
| 56 |
* as control stream hereafter, or a secondary control stream, also referred as |
| 57 |
* a sub control stream. The main difference between these is that, the control |
| 58 |
* stream is the one directly submitted to the GPU and is terminated using |
| 59 |
* STREAM_TERMINATE. Whereas, the secondary control stream can be thought of as |
| 60 |
* an independent set of commands that can be referenced by a primary control |
| 61 |
* stream to avoid duplication and is instead terminated using STREAM_RETURN, |
| 62 |
* which means the control stream parser should return to the main stream it |
| 63 |
* came from. |
| 64 |
* |
| 65 |
* Note: Sub control stream is only supported for PVR_CMD_STREAM_TYPE_GRAPHICS |
| 66 |
* type control streams. |
| 67 |
*/ |
| 68 |
|
| 69 |
/** |
| 70 |
* \brief Initializes the csb object. |
| 71 |
* |
| 72 |
* \param[in] device Logical device pointer. |
| 73 |
* \param[in] csb Control Stream Builder object to initialize. |
| 74 |
* |
| 75 |
* \sa #pvr_csb_finish() |
| 76 |
*/ |
| 77 |
void pvr_csb_init(struct pvr_device *device, |
| 78 |
enum pvr_cmd_stream_type stream_type, |
| 79 |
struct pvr_csb *csb) |
| 80 |
{ |
| 81 |
csb->start = NULL; |
| 82 |
csb->next = NULL; |
| 83 |
csb->pvr_bo = NULL; |
| 84 |
csb->end = NULL; |
| 85 |
csb->relocation_mark = NULL; |
| 86 |
|
| 87 |
#if MESA_DEBUG |
| 88 |
csb->relocation_mark_status = PVR_CSB_RELOCATION_MARK_UNINITIALIZED; |
| 89 |
#endif |
| 90 |
|
| 91 |
csb->device = device; |
| 92 |
csb->stream_type = stream_type; |
| 93 |
csb->status = VK_SUCCESS; |
| 94 |
|
| 95 |
if (stream_type == PVR_CMD_STREAM_TYPE_GRAPHICS_DEFERRED) |
| 96 |
csb->deferred_cs_mem = UTIL_DYNARRAY_INIT; |
| 97 |
else |
| 98 |
list_inithead(&csb->pvr_bo_list); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* \brief Frees the resources associated with the csb object. |
| 103 |
* |
| 104 |
* \param[in] csb Control Stream Builder object to free. |
| 105 |
* |
| 106 |
* \sa #pvr_csb_init() |
| 107 |
*/ |
| 108 |
void pvr_csb_finish(struct pvr_csb *csb) |
| 109 |
{ |
| 110 |
#if MESA_DEBUG |
| 111 |
assert(csb->relocation_mark_status == |
| 112 |
PVR_CSB_RELOCATION_MARK_UNINITIALIZED || |
| 113 |
csb->relocation_mark_status == PVR_CSB_RELOCATION_MARK_CLEARED); |
| 114 |
#endif |
| 115 |
|
| 116 |
if (csb->stream_type == PVR_CMD_STREAM_TYPE_GRAPHICS_DEFERRED) { |
| 117 |
util_dynarray_fini(&csb->deferred_cs_mem); |
| 118 |
} else { |
| 119 |
list_for_each_entry_safe (struct pvr_bo, pvr_bo, &csb->pvr_bo_list, link) { |
| 120 |
list_del(&pvr_bo->link); |
| 121 |
pvr_bo_free(csb->device, pvr_bo); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
/* Leave the csb in a reset state to catch use after destroy instances */ |
| 126 |
pvr_csb_init(NULL, PVR_CMD_STREAM_TYPE_INVALID, csb); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* \brief Discard information only required while building and return the BOs. |
| 131 |
* |
| 132 |
* \param[in] csb Control Stream Builder object to bake. |
| 133 |
* \param[out] bo_list_out A list of \c pvr_bo containing the control stream. |
| 134 |
* |
| 135 |
* \return The last status value of \c csb. |
| 136 |
* |
| 137 |
* The value of \c bo_list_out is only defined iff this function returns |
| 138 |
* \c VK_SUCCESS. It is not allowed to call this function on a \c pvr_csb for |
| 139 |
* a deferred control stream type. |
| 140 |
* |
| 141 |
* The state of \c csb after calling this function (iff it returns |
| 142 |
* \c VK_SUCCESS) is identical to that after calling #pvr_csb_finish(). |
| 143 |
* Unlike #pvr_csb_finish(), however, the caller must free every entry in |
| 144 |
* \c bo_list_out itself. |
| 145 |
*/ |
| 146 |
VkResult pvr_csb_bake(struct pvr_csb *const csb, |
| 147 |
struct list_head *const bo_list_out) |
| 148 |
{ |
| 149 |
assert(csb->stream_type != PVR_CMD_STREAM_TYPE_GRAPHICS_DEFERRED); |
| 150 |
|
| 151 |
if (csb->status != VK_SUCCESS) |
| 152 |
return csb->status; |
| 153 |
|
| 154 |
list_replace(&csb->pvr_bo_list, bo_list_out); |
| 155 |
|
| 156 |
/* Same as pvr_csb_finish(). */ |
| 157 |
pvr_csb_init(NULL, PVR_CMD_STREAM_TYPE_INVALID, csb); |
| 158 |
|
| 159 |
return VK_SUCCESS; |
| 160 |
} |