Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 1 | /* |
| 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. |
| 23 | */ |
| 24 | |
| 25 | #include "kmd/winsys.h" |
Chia-I Wu | 34f4518 | 2014-08-19 14:02:59 +0800 | [diff] [blame] | 26 | #include "cmd.h" |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 27 | #include "dev.h" |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame^] | 28 | #include "fence.h" |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 29 | #include "queue.h" |
| 30 | |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 31 | XGL_RESULT intel_queue_create(struct intel_dev *dev, |
| 32 | XGL_QUEUE_TYPE type, |
| 33 | struct intel_queue **queue_ret) |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 34 | { |
| 35 | struct intel_queue *queue; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame^] | 36 | enum intel_ring_type ring; |
| 37 | |
| 38 | switch (type) { |
| 39 | case XGL_QUEUE_TYPE_GRAPHICS: |
| 40 | case XGL_QUEUE_TYPE_COMPUTE: |
| 41 | ring = INTEL_RING_RENDER; |
| 42 | break; |
| 43 | case XGL_QUEUE_TYPE_DMA: |
| 44 | ring = INTEL_RING_BLT; |
| 45 | break; |
| 46 | default: |
| 47 | return XGL_ERROR_INVALID_VALUE; |
| 48 | break; |
| 49 | } |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 50 | |
Courtney Goeltzenleuchter | fb4fb53 | 2014-08-14 09:35:21 -0600 | [diff] [blame] | 51 | queue = (struct intel_queue *) intel_base_create(dev, sizeof(*queue), |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 52 | dev->base.dbg, XGL_DBG_OBJECT_QUEUE, NULL, 0); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 53 | if (!queue) |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 54 | return XGL_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 55 | |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 56 | queue->dev = dev; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame^] | 57 | queue->ring = ring; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 58 | |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 59 | *queue_ret = queue; |
| 60 | |
| 61 | return XGL_SUCCESS; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void intel_queue_destroy(struct intel_queue *queue) |
| 65 | { |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 66 | intel_base_destroy(&queue->base); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | XGL_RESULT intel_queue_wait(struct intel_queue *queue, int64_t timeout) |
| 70 | { |
Chia-I Wu | 34f4518 | 2014-08-19 14:02:59 +0800 | [diff] [blame] | 71 | struct intel_cmd *cmd = queue->last_submitted_cmd; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 72 | |
Chia-I Wu | 34f4518 | 2014-08-19 14:02:59 +0800 | [diff] [blame] | 73 | return (!cmd || intel_bo_wait(cmd->bo, timeout) == 0) ? |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 74 | XGL_SUCCESS : XGL_ERROR_UNKNOWN; |
| 75 | } |
| 76 | |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame^] | 77 | XGL_RESULT intel_queue_submit(struct intel_queue *queue, |
| 78 | struct intel_cmd *cmd) |
| 79 | { |
| 80 | struct intel_winsys *winsys = queue->dev->winsys; |
| 81 | int err; |
| 82 | |
| 83 | err = intel_winsys_submit_bo(winsys, queue->ring, |
| 84 | cmd->bo, cmd->used * sizeof(uint32_t), 0); |
| 85 | |
| 86 | queue->last_submitted_cmd = cmd; |
| 87 | |
| 88 | return (err) ? XGL_ERROR_UNKNOWN : XGL_SUCCESS; |
| 89 | } |
| 90 | |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 91 | XGL_RESULT XGLAPI intelQueueSetGlobalMemReferences( |
| 92 | XGL_QUEUE queue, |
| 93 | XGL_UINT memRefCount, |
| 94 | const XGL_MEMORY_REF* pMemRefs) |
| 95 | { |
| 96 | /* |
| 97 | * The winwys maintains the list of memory references. These are ignored |
| 98 | * until we move away from the winsys. |
| 99 | */ |
| 100 | return XGL_SUCCESS; |
| 101 | } |
| 102 | |
| 103 | XGL_RESULT XGLAPI intelQueueWaitIdle( |
| 104 | XGL_QUEUE queue_) |
| 105 | { |
| 106 | struct intel_queue *queue = intel_queue(queue_); |
| 107 | |
| 108 | return intel_queue_wait(queue, -1); |
| 109 | } |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 110 | |
| 111 | XGL_RESULT XGLAPI intelQueueSubmit( |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame^] | 112 | XGL_QUEUE queue_, |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 113 | XGL_UINT cmdBufferCount, |
| 114 | const XGL_CMD_BUFFER* pCmdBuffers, |
| 115 | XGL_UINT memRefCount, |
| 116 | const XGL_MEMORY_REF* pMemRefs, |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame^] | 117 | XGL_FENCE fence_) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 118 | { |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame^] | 119 | struct intel_queue *queue = intel_queue(queue_); |
| 120 | XGL_RESULT ret = XGL_SUCCESS; |
| 121 | XGL_UINT i; |
| 122 | |
| 123 | for (i = 0; i < cmdBufferCount; i++) { |
| 124 | struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]); |
| 125 | |
| 126 | ret = intel_queue_submit(queue, cmd); |
| 127 | if (ret != XGL_SUCCESS) |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | if (ret == XGL_SUCCESS && fence_ != XGL_NULL_HANDLE) { |
| 132 | struct intel_fence *fence = intel_fence(fence_); |
| 133 | intel_fence_set_cmd(fence, queue->last_submitted_cmd); |
| 134 | } |
| 135 | |
| 136 | /* XGL_MEMORY_REFs are ignored as the winsys already knows them */ |
| 137 | |
| 138 | return ret; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | XGL_RESULT XGLAPI intelOpenSharedQueueSemaphore( |
| 142 | XGL_DEVICE device, |
| 143 | const XGL_QUEUE_SEMAPHORE_OPEN_INFO* pOpenInfo, |
| 144 | XGL_QUEUE_SEMAPHORE* pSemaphore) |
| 145 | { |
| 146 | return XGL_ERROR_UNAVAILABLE; |
| 147 | } |
| 148 | |
| 149 | XGL_RESULT XGLAPI intelCreateQueueSemaphore( |
| 150 | XGL_DEVICE device, |
| 151 | const XGL_QUEUE_SEMAPHORE_CREATE_INFO* pCreateInfo, |
| 152 | XGL_QUEUE_SEMAPHORE* pSemaphore) |
| 153 | { |
| 154 | /* |
| 155 | * We want to find an unused semaphore register and initialize it. Signal |
| 156 | * will increment the register. Wait will atomically decrement it and |
| 157 | * block if the value is zero, or a large constant N if we do not want to |
| 158 | * go negative. |
| 159 | * |
| 160 | * XXX However, MI_SEMAPHORE_MBOX does not seem to have the flexibility. |
| 161 | */ |
| 162 | return XGL_ERROR_UNAVAILABLE; |
| 163 | } |
| 164 | |
| 165 | XGL_RESULT XGLAPI intelSignalQueueSemaphore( |
| 166 | XGL_QUEUE queue, |
| 167 | XGL_QUEUE_SEMAPHORE semaphore) |
| 168 | { |
| 169 | return XGL_ERROR_UNAVAILABLE; |
| 170 | } |
| 171 | |
| 172 | XGL_RESULT XGLAPI intelWaitQueueSemaphore( |
| 173 | XGL_QUEUE queue, |
| 174 | XGL_QUEUE_SEMAPHORE semaphore) |
| 175 | { |
| 176 | return XGL_ERROR_UNAVAILABLE; |
| 177 | } |