1 2 /* 3 * Copyright 2016 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 #ifndef GrVkTypes_DEFINED 10 #define GrVkTypes_DEFINED 11 12 #include "include/gpu/GpuTypes.h" 13 #include "include/gpu/vk/VulkanTypes.h" 14 15 using GrVkBackendMemory = skgpu::VulkanBackendMemory; 16 using GrVkAlloc = skgpu::VulkanAlloc; 17 using GrVkYcbcrConversionInfo = skgpu::VulkanYcbcrConversionInfo; 18 19 /* 20 * When wrapping a GrBackendTexture or GrBackendRendenderTarget, the fCurrentQueueFamily should 21 * either be VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_EXTERNAL, or VK_QUEUE_FAMILY_FOREIGN_EXT. If 22 * fSharingMode is VK_SHARING_MODE_EXCLUSIVE then fCurrentQueueFamily can also be the graphics 23 * queue index passed into Skia. 24 */ 25 struct GrVkImageInfo { 26 VkImage fImage = VK_NULL_HANDLE; 27 skgpu::VulkanAlloc fAlloc; 28 VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; 29 VkImageLayout fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; 30 VkFormat fFormat = VK_FORMAT_UNDEFINED; 31 VkImageUsageFlags fImageUsageFlags = 0; 32 uint32_t fSampleCount = 1; 33 uint32_t fLevelCount = 0; 34 uint32_t fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; 35 skgpu::Protected fProtected = skgpu::Protected::kNo; 36 GrVkYcbcrConversionInfo fYcbcrConversionInfo; 37 VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; 38 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 39 bool fPartOfSwapchainOrAndroidWindow = false; 40 #endif 41 42 bool operator==(const GrVkImageInfo& that) const { 43 bool equal = fImage == that.fImage && fAlloc == that.fAlloc && 44 fImageTiling == that.fImageTiling && 45 fImageLayout == that.fImageLayout && 46 fFormat == that.fFormat && 47 fImageUsageFlags == that.fImageUsageFlags && 48 fSampleCount == that.fSampleCount && 49 fLevelCount == that.fLevelCount && 50 fCurrentQueueFamily == that.fCurrentQueueFamily && 51 fProtected == that.fProtected && 52 fYcbcrConversionInfo == that.fYcbcrConversionInfo && 53 fSharingMode == that.fSharingMode; 54 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 55 equal = equal && (fPartOfSwapchainOrAndroidWindow == that.fPartOfSwapchainOrAndroidWindow); 56 #endif 57 return equal; 58 } 59 }; 60 61 using GrVkGetProc = skgpu::VulkanGetProc; 62 63 /** 64 * This object is wrapped in a GrBackendDrawableInfo and passed in as an argument to 65 * drawBackendGpu() calls on an SkDrawable. The drawable will use this info to inject direct 66 * Vulkan calls into our stream of GPU draws. 67 * 68 * The SkDrawable is given a secondary VkCommandBuffer in which to record draws. The GPU backend 69 * will then execute that command buffer within a render pass it is using for its own draws. The 70 * drawable is also given the attachment of the color index, a compatible VkRenderPass, and the 71 * VkFormat of the color attachment so that it can make VkPipeline objects for the draws. The 72 * SkDrawable must not alter the state of the VkRenderpass or sub pass. 73 * 74 * Additionally, the SkDrawable may fill in the passed in fDrawBounds with the bounds of the draws 75 * that it submits to the command buffer. This will be used by the GPU backend for setting the 76 * bounds in vkCmdBeginRenderPass. If fDrawBounds is not updated, we will assume that the entire 77 * attachment may have been written to. 78 * 79 * The SkDrawable is always allowed to create its own command buffers and submit them to the queue 80 * to render offscreen textures which will be sampled in draws added to the passed in 81 * VkCommandBuffer. If this is done the SkDrawable is in charge of adding the required memory 82 * barriers to the queue for the sampled images since the Skia backend will not do this. 83 */ 84 struct GrVkDrawableInfo { 85 VkCommandBuffer fSecondaryCommandBuffer; 86 uint32_t fColorAttachmentIndex; 87 VkRenderPass fCompatibleRenderPass; 88 VkFormat fFormat; 89 VkRect2D* fDrawBounds; 90 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 91 bool fFromSwapchainOrAndroidWindow; 92 #endif 93 }; 94 95 struct GrVkSurfaceInfo { 96 uint32_t fSampleCount = 1; 97 uint32_t fLevelCount = 0; 98 skgpu::Protected fProtected = skgpu::Protected::kNo; 99 100 VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; 101 VkFormat fFormat = VK_FORMAT_UNDEFINED; 102 VkImageUsageFlags fImageUsageFlags = 0; 103 GrVkYcbcrConversionInfo fYcbcrConversionInfo; 104 VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; 105 }; 106 107 #endif 108