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 vkCmdPipelineBarrier2(VkCommandBuffer commandBuffer,const VkDependencyInfo * pDependencyInfo)104 void vkCmdPipelineBarrier2(VkCommandBuffer commandBuffer, 105 const VkDependencyInfo* pDependencyInfo) { 106 mDgs->on_vkCmdPipelineBarrier2(mBp, commandBuffer, pDependencyInfo); 107 } 108 vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,VkImage srcImage,VkImageLayout srcImageLayout,VkBuffer dstBuffer,uint32_t regionCount,const VkBufferImageCopy * pRegions)109 void vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, 110 VkImageLayout srcImageLayout, VkBuffer dstBuffer, 111 uint32_t regionCount, const VkBufferImageCopy* pRegions) { 112 mDgs->on_vkCmdCopyImageToBuffer(mBp, commandBuffer, unbox_VkImage(srcImage), srcImageLayout, 113 unbox_VkBuffer(dstBuffer), regionCount, pRegions); 114 } 115 vkCreateBuffer(VkDevice device,const VkBufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkBuffer * pBuffer)116 VkResult vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, 117 const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer) { 118 return mDgs->on_vkCreateBuffer(mBp, device, pCreateInfo, pAllocator, pBuffer); 119 } 120 vkCreateCommandPool(VkDevice device,const VkCommandPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkCommandPool * pCommandPool)121 VkResult vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, 122 const VkAllocationCallbacks* pAllocator, 123 VkCommandPool* pCommandPool) { 124 return mDgs->on_vkCreateCommandPool(mBp, device, pCreateInfo, pAllocator, pCommandPool); 125 } 126 vkCreateDebugUtilsMessengerEXT(VkInstance instance,const VkDebugUtilsMessengerCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDebugUtilsMessengerEXT * pDebugMessenger)127 VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance, 128 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, 129 const VkAllocationCallbacks* pAllocator, 130 VkDebugUtilsMessengerEXT* pDebugMessenger) { 131 instance = unbox_VkInstance(instance); 132 auto func = (PFN_vkCreateDebugUtilsMessengerEXT)mVk->vkGetInstanceProcAddr( 133 instance, "vkCreateDebugUtilsMessengerEXT"); 134 if (func != nullptr) { 135 return func(instance, pCreateInfo, pAllocator, pDebugMessenger); 136 } else { 137 return VK_ERROR_EXTENSION_NOT_PRESENT; 138 } 139 } 140 vkCreateDevice(VkPhysicalDevice physicalDevice,const VkDeviceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDevice * pDevice)141 VkResult vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, 142 const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) { 143 return mDgs->on_vkCreateDevice(mBp, physicalDevice, pCreateInfo, pAllocator, pDevice); 144 } 145 vkCreateImage(VkDevice device,const VkImageCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkImage * pImage)146 VkResult vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, 147 const VkAllocationCallbacks* pAllocator, VkImage* pImage) { 148 mDgs->transformImpl_VkImageCreateInfo_tohost(pCreateInfo, 1); 149 return mDgs->on_vkCreateImage(mBp, device, pCreateInfo, pAllocator, pImage); 150 } 151 vkCreateImageView(VkDevice device,const VkImageViewCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkImageView * pView)152 VkResult vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, 153 const VkAllocationCallbacks* pAllocator, VkImageView* pView) { 154 return mDgs->on_vkCreateImageView(mBp, device, pCreateInfo, pAllocator, pView); 155 } 156 vkCreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance)157 VkResult vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, 158 const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) { 159 return mDgs->on_vkCreateInstance(mBp, pCreateInfo, pAllocator, pInstance); 160 } 161 vkDestroyBuffer(VkDevice device,VkBuffer buffer,const VkAllocationCallbacks * pAllocator)162 void vkDestroyBuffer(VkDevice device, VkBuffer buffer, 163 const VkAllocationCallbacks* pAllocator) { 164 mDgs->on_vkDestroyBuffer(mBp, device, unbox_VkBuffer(buffer), pAllocator); 165 delete_VkBuffer(buffer); 166 } 167 vkDestroyCommandPool(VkDevice device,VkCommandPool commandPool,const VkAllocationCallbacks * pAllocator)168 void vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, 169 const VkAllocationCallbacks* pAllocator) { 170 mDgs->on_vkDestroyCommandPool(mBp, device, unbox_VkCommandPool(commandPool), pAllocator); 171 delete_VkCommandPool(commandPool); 172 } 173 vkDestroyDebugUtilsMessengerEXT(VkInstance instance,VkDebugUtilsMessengerEXT debugMessenger,const VkAllocationCallbacks * pAllocator)174 void vkDestroyDebugUtilsMessengerEXT(VkInstance instance, 175 VkDebugUtilsMessengerEXT debugMessenger, 176 const VkAllocationCallbacks* pAllocator) { 177 instance = unbox_VkInstance(instance); 178 auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)mVk->vkGetInstanceProcAddr( 179 instance, "vkDestroyDebugUtilsMessengerEXT"); 180 if (func != nullptr) { 181 func(instance, debugMessenger, pAllocator); 182 } 183 } 184 vkDestroyDevice(VkDevice device,const VkAllocationCallbacks * pAllocator)185 void vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) { 186 mDgs->on_vkDestroyDevice(mBp, device, pAllocator); 187 } 188 vkDestroyImage(VkDevice device,VkImage image,const VkAllocationCallbacks * pAllocator)189 void vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator) { 190 mDgs->on_vkDestroyImage(mBp, device, unbox_VkImage(image), pAllocator); 191 delete_VkImage(image); 192 } 193 vkDestroyImageView(VkDevice device,VkImageView imageView,const VkAllocationCallbacks * pAllocator)194 void vkDestroyImageView(VkDevice device, VkImageView imageView, 195 const VkAllocationCallbacks* pAllocator) { 196 mDgs->on_vkDestroyImageView(mBp, device, unbox_VkImageView(imageView), pAllocator); 197 delete_VkImageView(imageView); 198 } 199 vkDestroyInstance(VkInstance instance,const VkAllocationCallbacks * pAllocator)200 void vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) { 201 mDgs->on_vkDestroyInstance(mBp, instance, pAllocator); 202 } 203 vkEndCommandBuffer(VkCommandBuffer commandBuffer)204 VkResult vkEndCommandBuffer(VkCommandBuffer commandBuffer) { 205 return mDgs->on_vkEndCommandBuffer(mBp, commandBuffer, *mDecoderContext); 206 } 207 vkEnumerateInstanceLayerProperties(uint32_t * pPropertyCount,VkLayerProperties * pProperties)208 VkResult vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount, 209 VkLayerProperties* pProperties) { 210 return mVk->vkEnumerateInstanceLayerProperties(pPropertyCount, pProperties); 211 } 212 vkEnumeratePhysicalDevices(VkInstance instance,uint32_t * physicalDeviceCount,VkPhysicalDevice * physicalDevices)213 VkResult vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* physicalDeviceCount, 214 VkPhysicalDevice* physicalDevices) { 215 return mDgs->on_vkEnumeratePhysicalDevices(mBp, instance, physicalDeviceCount, 216 physicalDevices); 217 } 218 vkFreeCommandBuffers(VkDevice device,VkCommandPool commandPool,uint32_t commandBufferCount,const VkCommandBuffer * pCommandBuffers)219 void vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, 220 uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers) { 221 mDgs->on_vkFreeCommandBuffers(mBp, device, unbox_VkCommandPool(commandPool), 222 commandBufferCount, pCommandBuffers); 223 // Calling delete_VkCommandBuffer is normally done in the decoder, so we have to do it here. 224 for (int i = 0; i < commandBufferCount; ++i) { 225 delete_VkCommandBuffer(unboxed_to_boxed_VkCommandBuffer(pCommandBuffers[i])); 226 } 227 } 228 vkFreeMemory(VkDevice device,VkDeviceMemory memory,const VkAllocationCallbacks * pAllocator)229 void vkFreeMemory(VkDevice device, VkDeviceMemory memory, 230 const VkAllocationCallbacks* pAllocator) { 231 mDgs->on_vkFreeMemory(mBp, device, unbox_VkDeviceMemory(memory), pAllocator); 232 delete_VkDeviceMemory(memory); 233 } 234 vkGetBufferMemoryRequirements(VkDevice device,VkBuffer buffer,VkMemoryRequirements * pMemoryRequirements)235 void vkGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, 236 VkMemoryRequirements* pMemoryRequirements) { 237 mVk->vkGetBufferMemoryRequirements(unbox_VkDevice(device), unbox_VkBuffer(buffer), 238 pMemoryRequirements); 239 } 240 vkGetDeviceQueue(VkDevice device,uint32_t queueFamilyIndex,uint32_t queueIndex,VkQueue * pQueue)241 void vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, 242 VkQueue* pQueue) { 243 mDgs->on_vkGetDeviceQueue(mBp, device, queueFamilyIndex, queueIndex, pQueue); 244 } 245 vkGetImageMemoryRequirements(VkDevice device,VkImage image,VkMemoryRequirements * pMemoryRequirements)246 void vkGetImageMemoryRequirements(VkDevice device, VkImage image, 247 VkMemoryRequirements* pMemoryRequirements) { 248 mDgs->on_vkGetImageMemoryRequirements(mBp, device, unbox_VkImage(image), 249 pMemoryRequirements); 250 } 251 vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,VkFormat format,VkFormatProperties * pFormatProperties)252 void vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, 253 VkFormatProperties* pFormatProperties) { 254 mDgs->on_vkGetPhysicalDeviceFormatProperties(mBp, physicalDevice, format, 255 pFormatProperties); 256 } vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,VkPhysicalDeviceMemoryProperties * pMemoryProperties)257 void vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, 258 VkPhysicalDeviceMemoryProperties* pMemoryProperties) { 259 mDgs->on_vkGetPhysicalDeviceMemoryProperties(mBp, physicalDevice, pMemoryProperties); 260 } 261 vkQueueSubmit(VkQueue queue,uint32_t submitCount,const VkSubmitInfo * pSubmits,VkFence fence)262 VkResult vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, 263 VkFence fence) { 264 return mDgs->on_vkQueueSubmit(mBp, queue, submitCount, pSubmits, fence); 265 } 266 vkQueueWaitIdle(VkQueue queue)267 VkResult vkQueueWaitIdle(VkQueue queue) { return mDgs->on_vkQueueWaitIdle(mBp, queue); } 268 vkDeviceWaitIdle(VkDevice device)269 VkResult vkDeviceWaitIdle(VkDevice device) { 270 return mVk->vkDeviceWaitIdle(unbox_VkDevice(device)); 271 } 272 vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties * pQueueFamilyProperties)273 void vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, 274 uint32_t* pQueueFamilyPropertyCount, 275 VkQueueFamilyProperties* pQueueFamilyProperties) { 276 mVk->vkGetPhysicalDeviceQueueFamilyProperties(unbox_VkPhysicalDevice(physicalDevice), 277 pQueueFamilyPropertyCount, 278 pQueueFamilyProperties); 279 } 280 vkMapMemory(VkDevice device,VkDeviceMemory memory,VkDeviceSize offset,VkDeviceSize size,VkMemoryMapFlags flags,void ** ppData)281 VkResult vkMapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, 282 VkDeviceSize size, VkMemoryMapFlags flags, void** ppData) { 283 return mDgs->on_vkMapMemory(mBp, device, unbox_VkDeviceMemory(memory), offset, size, flags, 284 ppData); 285 } 286 vkUnmapMemory(VkDevice device,VkDeviceMemory memory)287 void vkUnmapMemory(VkDevice device, VkDeviceMemory memory) { 288 mDgs->on_vkUnmapMemory(mBp, device, unbox_VkDeviceMemory(memory)); 289 } 290 291 private: 292 VulkanDispatch* mVk; 293 VkDecoderGlobalState* mDgs; 294 android::base::BumpPool* mBp; 295 VkDecoderContext* mDecoderContext; 296 }; 297 298 } // namespace testing 299 } // namespace vk 300 } // namespace gfxstream 301