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