1 /*
2 * Copyright © 2021 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "vk_common_entrypoints.h"
25 #include "vk_device.h"
26 #include "vk_util.h"
27
28 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdCopyBuffer(VkCommandBuffer commandBuffer,VkBuffer srcBuffer,VkBuffer dstBuffer,uint32_t regionCount,const VkBufferCopy * pRegions)29 vk_common_CmdCopyBuffer(VkCommandBuffer commandBuffer,
30 VkBuffer srcBuffer,
31 VkBuffer dstBuffer,
32 uint32_t regionCount,
33 const VkBufferCopy *pRegions)
34 {
35 /* We don't have a vk_command_buffer object but we can assume, since we're
36 * using common dispatch, that it's a vk_object of some sort.
37 */
38 struct vk_object_base *disp = (struct vk_object_base *)commandBuffer;
39
40 STACK_ARRAY(VkBufferCopy2, region2s, regionCount);
41
42 for (uint32_t r = 0; r < regionCount; r++) {
43 region2s[r] = (VkBufferCopy2) {
44 .sType = VK_STRUCTURE_TYPE_BUFFER_COPY_2,
45 .srcOffset = pRegions[r].srcOffset,
46 .dstOffset = pRegions[r].dstOffset,
47 .size = pRegions[r].size,
48 };
49 }
50
51 VkCopyBufferInfo2 info = {
52 .sType = VK_STRUCTURE_TYPE_COPY_BUFFER_INFO_2,
53 .srcBuffer = srcBuffer,
54 .dstBuffer = dstBuffer,
55 .regionCount = regionCount,
56 .pRegions = region2s,
57 };
58
59 disp->device->dispatch_table.CmdCopyBuffer2KHR(commandBuffer, &info);
60
61 STACK_ARRAY_FINISH(region2s);
62 }
63
64 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdCopyImage(VkCommandBuffer commandBuffer,VkImage srcImage,VkImageLayout srcImageLayout,VkImage dstImage,VkImageLayout dstImageLayout,uint32_t regionCount,const VkImageCopy * pRegions)65 vk_common_CmdCopyImage(VkCommandBuffer commandBuffer,
66 VkImage srcImage,
67 VkImageLayout srcImageLayout,
68 VkImage dstImage,
69 VkImageLayout dstImageLayout,
70 uint32_t regionCount,
71 const VkImageCopy *pRegions)
72 {
73 /* We don't have a vk_command_buffer object but we can assume, since we're
74 * using common dispatch, that it's a vk_object of some sort.
75 */
76 struct vk_object_base *disp = (struct vk_object_base *)commandBuffer;
77
78 STACK_ARRAY(VkImageCopy2, region2s, regionCount);
79
80 for (uint32_t r = 0; r < regionCount; r++) {
81 region2s[r] = (VkImageCopy2) {
82 .sType = VK_STRUCTURE_TYPE_IMAGE_COPY_2,
83 .srcSubresource = pRegions[r].srcSubresource,
84 .srcOffset = pRegions[r].srcOffset,
85 .dstSubresource = pRegions[r].dstSubresource,
86 .dstOffset = pRegions[r].dstOffset,
87 .extent = pRegions[r].extent,
88 };
89 }
90
91 VkCopyImageInfo2 info = {
92 .sType = VK_STRUCTURE_TYPE_COPY_IMAGE_INFO_2,
93 .srcImage = srcImage,
94 .srcImageLayout = srcImageLayout,
95 .dstImage = dstImage,
96 .dstImageLayout = dstImageLayout,
97 .regionCount = regionCount,
98 .pRegions = region2s,
99 };
100
101 disp->device->dispatch_table.CmdCopyImage2KHR(commandBuffer, &info);
102
103 STACK_ARRAY_FINISH(region2s);
104 }
105
106 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdCopyBufferToImage(VkCommandBuffer commandBuffer,VkBuffer srcBuffer,VkImage dstImage,VkImageLayout dstImageLayout,uint32_t regionCount,const VkBufferImageCopy * pRegions)107 vk_common_CmdCopyBufferToImage(VkCommandBuffer commandBuffer,
108 VkBuffer srcBuffer,
109 VkImage dstImage,
110 VkImageLayout dstImageLayout,
111 uint32_t regionCount,
112 const VkBufferImageCopy *pRegions)
113 {
114 /* We don't have a vk_command_buffer object but we can assume, since we're
115 * using common dispatch, that it's a vk_object of some sort.
116 */
117 struct vk_object_base *disp = (struct vk_object_base *)commandBuffer;
118
119 STACK_ARRAY(VkBufferImageCopy2, region2s, regionCount);
120
121 for (uint32_t r = 0; r < regionCount; r++) {
122 region2s[r] = (VkBufferImageCopy2) {
123 .sType = VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2,
124 .bufferOffset = pRegions[r].bufferOffset,
125 .bufferRowLength = pRegions[r].bufferRowLength,
126 .bufferImageHeight = pRegions[r].bufferImageHeight,
127 .imageSubresource = pRegions[r].imageSubresource,
128 .imageOffset = pRegions[r].imageOffset,
129 .imageExtent = pRegions[r].imageExtent,
130 };
131 }
132
133 VkCopyBufferToImageInfo2 info = {
134 .sType = VK_STRUCTURE_TYPE_COPY_BUFFER_TO_IMAGE_INFO_2,
135 .srcBuffer = srcBuffer,
136 .dstImage = dstImage,
137 .dstImageLayout = dstImageLayout,
138 .regionCount = regionCount,
139 .pRegions = region2s,
140 };
141
142 disp->device->dispatch_table.CmdCopyBufferToImage2KHR(commandBuffer, &info);
143
144 STACK_ARRAY_FINISH(region2s);
145 }
146
147 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdCopyImageToBuffer(VkCommandBuffer commandBuffer,VkImage srcImage,VkImageLayout srcImageLayout,VkBuffer dstBuffer,uint32_t regionCount,const VkBufferImageCopy * pRegions)148 vk_common_CmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
149 VkImage srcImage,
150 VkImageLayout srcImageLayout,
151 VkBuffer dstBuffer,
152 uint32_t regionCount,
153 const VkBufferImageCopy *pRegions)
154 {
155 /* We don't have a vk_command_buffer object but we can assume, since we're
156 * using common dispatch, that it's a vk_object of some sort.
157 */
158 struct vk_object_base *disp = (struct vk_object_base *)commandBuffer;
159
160 STACK_ARRAY(VkBufferImageCopy2, region2s, regionCount);
161
162 for (uint32_t r = 0; r < regionCount; r++) {
163 region2s[r] = (VkBufferImageCopy2) {
164 .sType = VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2,
165 .bufferOffset = pRegions[r].bufferOffset,
166 .bufferRowLength = pRegions[r].bufferRowLength,
167 .bufferImageHeight = pRegions[r].bufferImageHeight,
168 .imageSubresource = pRegions[r].imageSubresource,
169 .imageOffset = pRegions[r].imageOffset,
170 .imageExtent = pRegions[r].imageExtent,
171 };
172 }
173
174 VkCopyImageToBufferInfo2 info = {
175 .sType = VK_STRUCTURE_TYPE_COPY_IMAGE_TO_BUFFER_INFO_2,
176 .srcImage = srcImage,
177 .srcImageLayout = srcImageLayout,
178 .dstBuffer = dstBuffer,
179 .regionCount = regionCount,
180 .pRegions = region2s,
181 };
182
183 disp->device->dispatch_table.CmdCopyImageToBuffer2KHR(commandBuffer, &info);
184
185 STACK_ARRAY_FINISH(region2s);
186 }
187
188 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdBlitImage(VkCommandBuffer commandBuffer,VkImage srcImage,VkImageLayout srcImageLayout,VkImage dstImage,VkImageLayout dstImageLayout,uint32_t regionCount,const VkImageBlit * pRegions,VkFilter filter)189 vk_common_CmdBlitImage(VkCommandBuffer commandBuffer,
190 VkImage srcImage,
191 VkImageLayout srcImageLayout,
192 VkImage dstImage,
193 VkImageLayout dstImageLayout,
194 uint32_t regionCount,
195 const VkImageBlit *pRegions,
196 VkFilter filter)
197 {
198 /* We don't have a vk_command_buffer object but we can assume, since we're
199 * using common dispatch, that it's a vk_object of some sort.
200 */
201 struct vk_object_base *disp = (struct vk_object_base *)commandBuffer;
202
203 STACK_ARRAY(VkImageBlit2, region2s, regionCount);
204
205 for (uint32_t r = 0; r < regionCount; r++) {
206 region2s[r] = (VkImageBlit2) {
207 .sType = VK_STRUCTURE_TYPE_IMAGE_BLIT_2,
208 .srcSubresource = pRegions[r].srcSubresource,
209 .srcOffsets = {
210 pRegions[r].srcOffsets[0],
211 pRegions[r].srcOffsets[1],
212 },
213 .dstSubresource = pRegions[r].dstSubresource,
214 .dstOffsets = {
215 pRegions[r].dstOffsets[0],
216 pRegions[r].dstOffsets[1],
217 },
218 };
219 }
220
221 VkBlitImageInfo2 info = {
222 .sType = VK_STRUCTURE_TYPE_BLIT_IMAGE_INFO_2,
223 .srcImage = srcImage,
224 .srcImageLayout = srcImageLayout,
225 .dstImage = dstImage,
226 .dstImageLayout = dstImageLayout,
227 .regionCount = regionCount,
228 .pRegions = region2s,
229 .filter = filter,
230 };
231
232 disp->device->dispatch_table.CmdBlitImage2KHR(commandBuffer, &info);
233
234 STACK_ARRAY_FINISH(region2s);
235 }
236
237 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdResolveImage(VkCommandBuffer commandBuffer,VkImage srcImage,VkImageLayout srcImageLayout,VkImage dstImage,VkImageLayout dstImageLayout,uint32_t regionCount,const VkImageResolve * pRegions)238 vk_common_CmdResolveImage(VkCommandBuffer commandBuffer,
239 VkImage srcImage,
240 VkImageLayout srcImageLayout,
241 VkImage dstImage,
242 VkImageLayout dstImageLayout,
243 uint32_t regionCount,
244 const VkImageResolve *pRegions)
245 {
246 /* We don't have a vk_command_buffer object but we can assume, since we're
247 * using common dispatch, that it's a vk_object of some sort.
248 */
249 struct vk_object_base *disp = (struct vk_object_base *)commandBuffer;
250
251 STACK_ARRAY(VkImageResolve2, region2s, regionCount);
252
253 for (uint32_t r = 0; r < regionCount; r++) {
254 region2s[r] = (VkImageResolve2) {
255 .sType = VK_STRUCTURE_TYPE_IMAGE_RESOLVE_2,
256 .srcSubresource = pRegions[r].srcSubresource,
257 .srcOffset = pRegions[r].srcOffset,
258 .dstSubresource = pRegions[r].dstSubresource,
259 .dstOffset = pRegions[r].dstOffset,
260 .extent = pRegions[r].extent,
261 };
262 }
263
264 VkResolveImageInfo2 info = {
265 .sType = VK_STRUCTURE_TYPE_RESOLVE_IMAGE_INFO_2,
266 .srcImage = srcImage,
267 .srcImageLayout = srcImageLayout,
268 .dstImage = dstImage,
269 .dstImageLayout = dstImageLayout,
270 .regionCount = regionCount,
271 .pRegions = region2s,
272 };
273
274 disp->device->dispatch_table.CmdResolveImage2KHR(commandBuffer, &info);
275
276 STACK_ARRAY_FINISH(region2s);
277 }
278