1 // copyright (c) 2022 the android open source project 2 // 3 // licensed under the apache license, version 2.0 (the "license"); 4 // you may not use this file except in compliance with the license. 5 // you may obtain a copy of the license at 6 // 7 // http://www.apache.org/licenses/license-2.0 8 // 9 // unless required by applicable law or agreed to in writing, software 10 // distributed under the license is distributed on an "as is" basis, 11 // without warranties or conditions of any kind, either express or implied. 12 // see the license for the specific language governing permissions and 13 // limitations under the license. 14 15 #pragma once 16 17 #include "goldfish_vk_dispatch.h" 18 #include "vulkan/VkDecoderGlobalState.h" 19 #include "vulkan/vulkan.h" 20 #include "VulkanBoxedHandles.h" 21 22 namespace gfxstream { 23 namespace vk { 24 namespace testing { 25 26 // TODO(gregschlom): This class should be auto-generated 27 class VkDecoderTestDispatch { 28 public: VkDecoderTestDispatch(VulkanDispatch * vk,android::base::BumpPool * bp,VkDecoderContext * decoderContext)29 VkDecoderTestDispatch(VulkanDispatch* vk, android::base::BumpPool* bp, 30 VkDecoderContext* decoderContext) 31 : mVk(vk), mDgs(VkDecoderGlobalState::get()), mBp(bp), mDecoderContext(decoderContext) {} 32 33 // Vulkan API wrappers - please keep sorted alphabetically 34 // 35 // These methods call into VkDecoderGlobalState (or VulkanDispatch if the method isn't 36 // implemented in VkDecoderGlobalState), while taking care of unboxing the parameters as 37 // needed. 38 vkAllocateCommandBuffers(VkDevice device,const VkCommandBufferAllocateInfo * pAllocateInfo,VkCommandBuffer * pCommandBuffers)39 VkResult vkAllocateCommandBuffers(VkDevice device, 40 const VkCommandBufferAllocateInfo* pAllocateInfo, 41 VkCommandBuffer* pCommandBuffers) { 42 return mDgs->on_vkAllocateCommandBuffers(mBp, nullptr, device, pAllocateInfo, 43 pCommandBuffers); 44 } 45 vkAllocateMemory(VkDevice device,const VkMemoryAllocateInfo * pAllocateInfo,const VkAllocationCallbacks * pAllocator,VkDeviceMemory * pMemory)46 VkResult vkAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, 47 const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) { 48 return mDgs->on_vkAllocateMemory(mBp, nullptr, device, pAllocateInfo, pAllocator, pMemory); 49 } 50 vkBeginCommandBuffer(VkCommandBuffer commandBuffer,const VkCommandBufferBeginInfo * pBeginInfo)51 VkResult vkBeginCommandBuffer(VkCommandBuffer commandBuffer, 52 const VkCommandBufferBeginInfo* pBeginInfo) { 53 return mDgs->on_vkBeginCommandBuffer(mBp, nullptr, commandBuffer, pBeginInfo, 54 *mDecoderContext); 55 } 56 vkBindBufferMemory(VkDevice device,VkBuffer buffer,VkDeviceMemory memory,VkDeviceSize memoryOffset)57 VkResult vkBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, 58 VkDeviceSize memoryOffset) { 59 return mDgs->on_vkBindBufferMemory(mBp, nullptr, device, unbox_VkBuffer(buffer), 60 unbox_VkDeviceMemory(memory), memoryOffset); 61 } 62 vkBindImageMemory(VkDevice device,VkImage image,VkDeviceMemory memory,VkDeviceSize memoryOffset)63 VkResult vkBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, 64 VkDeviceSize memoryOffset) { 65 return mDgs->on_vkBindImageMemory(mBp, nullptr, device, unbox_VkImage(image), 66 unbox_VkDeviceMemory(memory), memoryOffset); 67 } 68 vkCmdBlitImage(VkCommandBuffer commandBuffer,VkImage srcImage,VkImageLayout srcImageLayout,VkImage dstImage,VkImageLayout dstImageLayout,uint32_t regionCount,const VkImageBlit * pRegions,VkFilter filter)69 void vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, 70 VkImageLayout srcImageLayout, VkImage dstImage, 71 VkImageLayout dstImageLayout, uint32_t regionCount, 72 const VkImageBlit* pRegions, VkFilter filter) { 73 return mVk->vkCmdBlitImage(unbox_VkCommandBuffer(commandBuffer), unbox_VkImage(srcImage), 74 srcImageLayout, unbox_VkImage(dstImage), dstImageLayout, 75 regionCount, pRegions, filter); 76 } vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,VkBuffer srcBuffer,VkImage dstImage,VkImageLayout dstImageLayout,uint32_t regionCount,const VkBufferImageCopy * pRegions)77 void vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, 78 VkImageLayout dstImageLayout, uint32_t regionCount, 79 const VkBufferImageCopy* pRegions) { 80 mDgs->on_vkCmdCopyBufferToImage(mBp, nullptr, commandBuffer, unbox_VkBuffer(srcBuffer), 81 unbox_VkImage(dstImage), dstImageLayout, regionCount, 82 pRegions, *mDecoderContext); 83 } 84 vkCmdCopyImage(VkCommandBuffer commandBuffer,VkImage srcImage,VkImageLayout srcImageLayout,VkImage dstImage,VkImageLayout dstImageLayout,uint32_t regionCount,const VkImageCopy * pRegions)85 void vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, 86 VkImageLayout srcImageLayout, VkImage dstImage, 87 VkImageLayout dstImageLayout, uint32_t regionCount, 88 const VkImageCopy* pRegions) { 89 mDgs->on_vkCmdCopyImage(mBp, nullptr, commandBuffer, unbox_VkImage(srcImage), 90 srcImageLayout, unbox_VkImage(dstImage), dstImageLayout, 91 regionCount, pRegions); 92 } 93 vkCmdPipelineBarrier(VkCommandBuffer commandBuffer,VkPipelineStageFlags srcStageMask,VkPipelineStageFlags dstStageMask,VkDependencyFlags dependencyFlags,uint32_t memoryBarrierCount,const VkMemoryBarrier * pMemoryBarriers,uint32_t bufferMemoryBarrierCount,const VkBufferMemoryBarrier * pBufferMemoryBarriers,uint32_t imageMemoryBarrierCount,const VkImageMemoryBarrier * pImageMemoryBarriers)94 void vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, 95 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, 96 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, 97 uint32_t bufferMemoryBarrierCount, 98 const VkBufferMemoryBarrier* pBufferMemoryBarriers, 99 uint32_t imageMemoryBarrierCount, 100 const VkImageMemoryBarrier* pImageMemoryBarriers) { 101 mDgs->on_vkCmdPipelineBarrier(mBp, nullptr, commandBuffer, srcStageMask, dstStageMask, 102 dependencyFlags, memoryBarrierCount, pMemoryBarriers, 103 bufferMemoryBarrierCount, pBufferMemoryBarriers, 104 imageMemoryBarrierCount, pImageMemoryBarriers); 105 } 106 vkCmdPipelineBarrier2(VkCommandBuffer commandBuffer,const VkDependencyInfo * pDependencyInfo)107 void vkCmdPipelineBarrier2(VkCommandBuffer commandBuffer, 108 const VkDependencyInfo* pDependencyInfo) { 109 mDgs->on_vkCmdPipelineBarrier2(mBp, nullptr, commandBuffer, pDependencyInfo); 110 } 111 vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,VkImage srcImage,VkImageLayout srcImageLayout,VkBuffer dstBuffer,uint32_t regionCount,const VkBufferImageCopy * pRegions)112 void vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, 113 VkImageLayout srcImageLayout, VkBuffer dstBuffer, 114 uint32_t regionCount, const VkBufferImageCopy* pRegions) { 115 mDgs->on_vkCmdCopyImageToBuffer(mBp, nullptr, commandBuffer, unbox_VkImage(srcImage), 116 srcImageLayout, unbox_VkBuffer(dstBuffer), regionCount, 117 pRegions); 118 } 119 vkCreateBuffer(VkDevice device,const VkBufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkBuffer * pBuffer)120 VkResult vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, 121 const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer) { 122 return mDgs->on_vkCreateBuffer(mBp, nullptr, device, pCreateInfo, pAllocator, pBuffer); 123 } 124 vkCreateCommandPool(VkDevice device,const VkCommandPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkCommandPool * pCommandPool)125 VkResult vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, 126 const VkAllocationCallbacks* pAllocator, 127 VkCommandPool* pCommandPool) { 128 return mDgs->on_vkCreateCommandPool(mBp, nullptr, device, pCreateInfo, pAllocator, 129 pCommandPool); 130 } 131 vkCreateDebugUtilsMessengerEXT(VkInstance instance,const VkDebugUtilsMessengerCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDebugUtilsMessengerEXT * pDebugMessenger)132 VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance, 133 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, 134 const VkAllocationCallbacks* pAllocator, 135 VkDebugUtilsMessengerEXT* pDebugMessenger) { 136 instance = unbox_VkInstance(instance); 137 auto func = (PFN_vkCreateDebugUtilsMessengerEXT)mVk->vkGetInstanceProcAddr( 138 instance, "vkCreateDebugUtilsMessengerEXT"); 139 if (func != nullptr) { 140 return func(instance, pCreateInfo, pAllocator, pDebugMessenger); 141 } else { 142 return VK_ERROR_EXTENSION_NOT_PRESENT; 143 } 144 } 145 vkCreateDevice(VkPhysicalDevice physicalDevice,const VkDeviceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDevice * pDevice)146 VkResult vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, 147 const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) { 148 return mDgs->on_vkCreateDevice(mBp, nullptr, physicalDevice, pCreateInfo, pAllocator, 149 pDevice); 150 } 151 vkCreateImage(VkDevice device,const VkImageCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkImage * pImage)152 VkResult vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, 153 const VkAllocationCallbacks* pAllocator, VkImage* pImage) { 154 mDgs->transformImpl_VkImageCreateInfo_tohost(pCreateInfo, 1); 155 return mDgs->on_vkCreateImage(mBp, nullptr, device, pCreateInfo, pAllocator, pImage); 156 } 157 vkCreateImageView(VkDevice device,const VkImageViewCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkImageView * pView)158 VkResult vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, 159 const VkAllocationCallbacks* pAllocator, VkImageView* pView) { 160 return mDgs->on_vkCreateImageView(mBp, nullptr, device, pCreateInfo, pAllocator, pView); 161 } 162 vkCreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance)163 VkResult vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, 164 const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) { 165 return mDgs->on_vkCreateInstance(mBp, nullptr, pCreateInfo, pAllocator, pInstance); 166 } 167 vkDestroyBuffer(VkDevice device,VkBuffer buffer,const VkAllocationCallbacks * pAllocator)168 void vkDestroyBuffer(VkDevice device, VkBuffer buffer, 169 const VkAllocationCallbacks* pAllocator) { 170 mDgs->on_vkDestroyBuffer(mBp, nullptr, device, unbox_VkBuffer(buffer), pAllocator); 171 delete_VkBuffer(buffer); 172 } 173 vkDestroyCommandPool(VkDevice device,VkCommandPool commandPool,const VkAllocationCallbacks * pAllocator)174 void vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, 175 const VkAllocationCallbacks* pAllocator) { 176 mDgs->on_vkDestroyCommandPool(mBp, nullptr, device, unbox_VkCommandPool(commandPool), 177 pAllocator); 178 delete_VkCommandPool(commandPool); 179 } 180 vkDestroyDebugUtilsMessengerEXT(VkInstance instance,VkDebugUtilsMessengerEXT debugMessenger,const VkAllocationCallbacks * pAllocator)181 void vkDestroyDebugUtilsMessengerEXT(VkInstance instance, 182 VkDebugUtilsMessengerEXT debugMessenger, 183 const VkAllocationCallbacks* pAllocator) { 184 instance = unbox_VkInstance(instance); 185 auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)mVk->vkGetInstanceProcAddr( 186 instance, "vkDestroyDebugUtilsMessengerEXT"); 187 if (func != nullptr) { 188 func(instance, debugMessenger, pAllocator); 189 } 190 } 191 vkDestroyDevice(VkDevice device,const VkAllocationCallbacks * pAllocator)192 void vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) { 193 mDgs->on_vkDestroyDevice(mBp, nullptr, device, pAllocator); 194 } 195 vkDestroyImage(VkDevice device,VkImage image,const VkAllocationCallbacks * pAllocator)196 void vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator) { 197 mDgs->on_vkDestroyImage(mBp, nullptr, device, unbox_VkImage(image), pAllocator); 198 delete_VkImage(image); 199 } 200 vkDestroyImageView(VkDevice device,VkImageView imageView,const VkAllocationCallbacks * pAllocator)201 void vkDestroyImageView(VkDevice device, VkImageView imageView, 202 const VkAllocationCallbacks* pAllocator) { 203 mDgs->on_vkDestroyImageView(mBp, nullptr, device, unbox_VkImageView(imageView), pAllocator); 204 delete_VkImageView(imageView); 205 } 206 vkDestroyInstance(VkInstance instance,const VkAllocationCallbacks * pAllocator)207 void vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) { 208 mDgs->on_vkDestroyInstance(mBp, nullptr, instance, pAllocator); 209 } 210 vkEndCommandBuffer(VkCommandBuffer commandBuffer)211 VkResult vkEndCommandBuffer(VkCommandBuffer commandBuffer) { 212 return mDgs->on_vkEndCommandBuffer(mBp, nullptr, commandBuffer, *mDecoderContext); 213 } 214 vkEnumerateInstanceLayerProperties(uint32_t * pPropertyCount,VkLayerProperties * pProperties)215 VkResult vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount, 216 VkLayerProperties* pProperties) { 217 return mVk->vkEnumerateInstanceLayerProperties(pPropertyCount, pProperties); 218 } 219 vkEnumeratePhysicalDevices(VkInstance instance,uint32_t * physicalDeviceCount,VkPhysicalDevice * physicalDevices)220 VkResult vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* physicalDeviceCount, 221 VkPhysicalDevice* physicalDevices) { 222 return mDgs->on_vkEnumeratePhysicalDevices(mBp, nullptr, instance, physicalDeviceCount, 223 physicalDevices); 224 } 225 vkFreeCommandBuffers(VkDevice device,VkCommandPool commandPool,uint32_t commandBufferCount,const VkCommandBuffer * pCommandBuffers)226 void vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, 227 uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers) { 228 mDgs->on_vkFreeCommandBuffers(mBp, nullptr, device, unbox_VkCommandPool(commandPool), 229 commandBufferCount, pCommandBuffers); 230 // Calling delete_VkCommandBuffer is normally done in the decoder, so we have to do it here. 231 for (int i = 0; i < commandBufferCount; ++i) { 232 delete_VkCommandBuffer(unboxed_to_boxed_VkCommandBuffer(pCommandBuffers[i])); 233 } 234 } 235 vkFreeMemory(VkDevice device,VkDeviceMemory memory,const VkAllocationCallbacks * pAllocator)236 void vkFreeMemory(VkDevice device, VkDeviceMemory memory, 237 const VkAllocationCallbacks* pAllocator) { 238 mDgs->on_vkFreeMemory(mBp, nullptr, device, unbox_VkDeviceMemory(memory), pAllocator); 239 delete_VkDeviceMemory(memory); 240 } 241 vkGetBufferMemoryRequirements(VkDevice device,VkBuffer buffer,VkMemoryRequirements * pMemoryRequirements)242 void vkGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, 243 VkMemoryRequirements* pMemoryRequirements) { 244 mVk->vkGetBufferMemoryRequirements(unbox_VkDevice(device), unbox_VkBuffer(buffer), 245 pMemoryRequirements); 246 } 247 vkGetDeviceQueue(VkDevice device,uint32_t queueFamilyIndex,uint32_t queueIndex,VkQueue * pQueue)248 void vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, 249 VkQueue* pQueue) { 250 mDgs->on_vkGetDeviceQueue(mBp, nullptr, device, queueFamilyIndex, queueIndex, pQueue); 251 } 252 vkGetImageMemoryRequirements(VkDevice device,VkImage image,VkMemoryRequirements * pMemoryRequirements)253 void vkGetImageMemoryRequirements(VkDevice device, VkImage image, 254 VkMemoryRequirements* pMemoryRequirements) { 255 mDgs->on_vkGetImageMemoryRequirements(mBp, nullptr, device, unbox_VkImage(image), 256 pMemoryRequirements); 257 } 258 vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,VkFormat format,VkFormatProperties * pFormatProperties)259 void vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, 260 VkFormatProperties* pFormatProperties) { 261 mDgs->on_vkGetPhysicalDeviceFormatProperties(mBp, nullptr, physicalDevice, format, 262 pFormatProperties); 263 } vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,VkPhysicalDeviceMemoryProperties * pMemoryProperties)264 void vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, 265 VkPhysicalDeviceMemoryProperties* pMemoryProperties) { 266 mDgs->on_vkGetPhysicalDeviceMemoryProperties(mBp, nullptr, physicalDevice, 267 pMemoryProperties); 268 } 269 vkQueueSubmit(VkQueue queue,uint32_t submitCount,const VkSubmitInfo * pSubmits,VkFence fence)270 VkResult vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, 271 VkFence fence) { 272 return mDgs->on_vkQueueSubmit(mBp, nullptr, queue, submitCount, pSubmits, fence); 273 } 274 vkQueueWaitIdle(VkQueue queue)275 VkResult vkQueueWaitIdle(VkQueue queue) { 276 return mDgs->on_vkQueueWaitIdle(mBp, nullptr, queue); 277 } 278 vkDeviceWaitIdle(VkDevice device)279 VkResult vkDeviceWaitIdle(VkDevice device) { 280 return mVk->vkDeviceWaitIdle(unbox_VkDevice(device)); 281 } 282 vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties * pQueueFamilyProperties)283 void vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, 284 uint32_t* pQueueFamilyPropertyCount, 285 VkQueueFamilyProperties* pQueueFamilyProperties) { 286 mVk->vkGetPhysicalDeviceQueueFamilyProperties(unbox_VkPhysicalDevice(physicalDevice), 287 pQueueFamilyPropertyCount, 288 pQueueFamilyProperties); 289 } 290 vkMapMemory(VkDevice device,VkDeviceMemory memory,VkDeviceSize offset,VkDeviceSize size,VkMemoryMapFlags flags,void ** ppData)291 VkResult vkMapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, 292 VkDeviceSize size, VkMemoryMapFlags flags, void** ppData) { 293 return mDgs->on_vkMapMemory(mBp, nullptr, device, unbox_VkDeviceMemory(memory), offset, 294 size, flags, ppData); 295 } 296 vkUnmapMemory(VkDevice device,VkDeviceMemory memory)297 void vkUnmapMemory(VkDevice device, VkDeviceMemory memory) { 298 mDgs->on_vkUnmapMemory(mBp, nullptr, device, unbox_VkDeviceMemory(memory)); 299 } 300 301 private: 302 VulkanDispatch* mVk; 303 VkDecoderGlobalState* mDgs; 304 android::base::BumpPool* mBp; 305 VkDecoderContext* mDecoderContext; 306 }; 307 308 } // namespace testing 309 } // namespace vk 310 } // namespace gfxstream 311