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