Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrVkCaps_DEFINED |
| 9 | #define GrVkCaps_DEFINED |
| 10 | |
| 11 | #include "GrCaps.h" |
| 12 | #include "GrVkStencilAttachment.h" |
Greg Daniel | 487132b | 2018-12-20 14:09:36 -0500 | [diff] [blame] | 13 | #include "vk/GrVkTypes.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 14 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 15 | class GrShaderCaps; |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 16 | class GrVkExtensions; |
| 17 | struct GrVkInterface; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 18 | |
| 19 | /** |
| 20 | * Stores some capabilities of a Vk backend. |
| 21 | */ |
| 22 | class GrVkCaps : public GrCaps { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 23 | public: |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 24 | typedef GrVkStencilAttachment::Format StencilFormat; |
| 25 | |
| 26 | /** |
| 27 | * Creates a GrVkCaps that is set such that nothing is supported. The init function should |
| 28 | * be called to fill out the caps. |
| 29 | */ |
| 30 | GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 31 | VkPhysicalDevice device, const VkPhysicalDeviceFeatures2& features, |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 32 | uint32_t instanceVersion, uint32_t physicalDeviceVersion, |
| 33 | const GrVkExtensions& extensions); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 34 | |
| 35 | bool isConfigTexturable(GrPixelConfig config) const override { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 36 | return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fOptimalFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 37 | } |
| 38 | |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 39 | bool isConfigCopyable(GrPixelConfig config) const override { |
| 40 | return true; |
| 41 | } |
| 42 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 43 | int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override; |
| 44 | int maxRenderTargetSampleCount(GrPixelConfig config) const override; |
| 45 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 46 | bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 47 | |
egdaniel | a95d46b | 2016-08-15 08:06:29 -0700 | [diff] [blame] | 48 | bool isConfigTexturableLinearly(GrPixelConfig config) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 49 | return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fLinearFlags); |
| 50 | } |
| 51 | |
| 52 | bool isConfigRenderableLinearly(GrPixelConfig config, bool withMSAA) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 53 | return !withMSAA && SkToBool(ConfigInfo::kRenderable_Flag & |
| 54 | fConfigTable[config].fLinearFlags); |
| 55 | } |
| 56 | |
| 57 | bool configCanBeDstofBlit(GrPixelConfig config, bool linearTiled) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 58 | const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags : |
| 59 | fConfigTable[config].fOptimalFlags; |
| 60 | return SkToBool(ConfigInfo::kBlitDst_Flag & flags); |
| 61 | } |
| 62 | |
| 63 | bool configCanBeSrcofBlit(GrPixelConfig config, bool linearTiled) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 64 | const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags : |
| 65 | fConfigTable[config].fOptimalFlags; |
| 66 | return SkToBool(ConfigInfo::kBlitSrc_Flag & flags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 67 | } |
| 68 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 69 | // On Adreno vulkan, they do not respect the imageOffset parameter at least in |
| 70 | // copyImageToBuffer. This flag says that we must do the copy starting from the origin always. |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 71 | bool mustDoCopiesFromOrigin() const { |
| 72 | return fMustDoCopiesFromOrigin; |
| 73 | } |
| 74 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 75 | // Sometimes calls to QueueWaitIdle return before actually signalling the fences |
| 76 | // on the command buffers even though they have completed. This causes an assert to fire when |
| 77 | // destroying the command buffers. Therefore we add a sleep to make sure the fence signals. |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 78 | bool mustSleepOnTearDown() const { |
| 79 | return fMustSleepOnTearDown; |
| 80 | } |
| 81 | |
Greg Daniel | e3cd691 | 2017-05-17 11:15:55 -0400 | [diff] [blame] | 82 | // Returns true if while adding commands to command buffers, we must make a new command buffer |
| 83 | // everytime we want to bind a new VkPipeline. This is true for both primary and secondary |
| 84 | // command buffers. This is to work around a driver bug specifically on AMD. |
| 85 | bool newCBOnPipelineChange() const { |
| 86 | return fNewCBOnPipelineChange; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Greg Daniel | ddc0c60 | 2018-06-18 11:26:30 -0400 | [diff] [blame] | 89 | // Returns true if we should always make dedicated allocations for VkImages. |
| 90 | bool shouldAlwaysUseDedicatedImageMemory() const { |
| 91 | return fShouldAlwaysUseDedicatedImageMemory; |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 92 | } |
| 93 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 94 | /** |
Ethan Nicholas | f610bae | 2018-09-20 16:55:21 -0400 | [diff] [blame] | 95 | * Returns both a supported and most preferred stencil format to use in draws. |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 96 | */ |
Ethan Nicholas | f610bae | 2018-09-20 16:55:21 -0400 | [diff] [blame] | 97 | const StencilFormat& preferredStencilFormat() const { |
| 98 | return fPreferredStencilFormat; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 99 | } |
| 100 | |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 101 | // Returns whether the device supports the ability to extend VkPhysicalDeviceProperties struct. |
| 102 | bool supportsPhysicalDeviceProperties2() const { return fSupportsPhysicalDeviceProperties2; } |
| 103 | // Returns whether the device supports the ability to extend VkMemoryRequirements struct. |
| 104 | bool supportsMemoryRequirements2() const { return fSupportsMemoryRequirements2; } |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 105 | |
| 106 | // Returns whether the device supports the ability to extend the vkBindMemory call. |
| 107 | bool supportsBindMemory2() const { return fSupportsBindMemory2; } |
| 108 | |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 109 | // Returns whether or not the device suports the various API maintenance fixes to Vulkan 1.0. In |
| 110 | // Vulkan 1.1 all these maintenance are part of the core spec. |
| 111 | bool supportsMaintenance1() const { return fSupportsMaintenance1; } |
| 112 | bool supportsMaintenance2() const { return fSupportsMaintenance2; } |
| 113 | bool supportsMaintenance3() const { return fSupportsMaintenance3; } |
| 114 | |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 115 | // Returns true if the device supports passing in a flag to say we are using dedicated GPU when |
| 116 | // allocating memory. For some devices this allows them to return more optimized memory knowning |
| 117 | // they will never need to suballocate amonst multiple objects. |
| 118 | bool supportsDedicatedAllocation() const { return fSupportsDedicatedAllocation; } |
| 119 | |
| 120 | // Returns true if the device supports importing of external memory into Vulkan memory. |
| 121 | bool supportsExternalMemory() const { return fSupportsExternalMemory; } |
| 122 | // Returns true if the device supports importing Android hardware buffers into Vulkan memory. |
| 123 | bool supportsAndroidHWBExternalMemory() const { return fSupportsAndroidHWBExternalMemory; } |
| 124 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 125 | // Returns true if it supports ycbcr conversion for samplers |
| 126 | bool supportsYcbcrConversion() const { return fSupportsYcbcrConversion; } |
| 127 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 128 | /** |
| 129 | * Helpers used by canCopySurface. In all cases if the SampleCnt parameter is zero that means |
| 130 | * the surface is not a render target, otherwise it is the number of samples in the render |
| 131 | * target. |
| 132 | */ |
| 133 | bool canCopyImage(GrPixelConfig dstConfig, int dstSampleCnt, GrSurfaceOrigin dstOrigin, |
| 134 | GrPixelConfig srcConfig, int srcSamplecnt, GrSurfaceOrigin srcOrigin) const; |
| 135 | |
| 136 | bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt, bool dstIsLinear, |
| 137 | GrPixelConfig srcConfig, int srcSampleCnt, bool srcIsLinear) const; |
| 138 | |
| 139 | bool canCopyAsResolve(GrPixelConfig dstConfig, int dstSampleCnt, GrSurfaceOrigin dstOrigin, |
| 140 | GrPixelConfig srcConfig, int srcSamplecnt, |
| 141 | GrSurfaceOrigin srcOrigin) const; |
| 142 | |
| 143 | bool canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable, |
| 144 | GrPixelConfig srcConfig, bool srcIsTextureable) const; |
| 145 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 146 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 147 | bool* rectsMustMatch, bool* disallowSubrect) const override; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 148 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 149 | GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&, |
| 150 | SkColorType) const override; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 151 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 152 | GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, SkColorType) const override; |
| 153 | GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 154 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 155 | GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct, |
| 156 | GrSRGBEncoded srgbEncoded) const override; |
| 157 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 158 | private: |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 159 | enum VkVendor { |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 160 | kAMD_VkVendor = 4098, |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 161 | kARM_VkVendor = 5045, |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 162 | kImagination_VkVendor = 4112, |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 163 | kIntel_VkVendor = 32902, |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 164 | kNvidia_VkVendor = 4318, |
| 165 | kQualcomm_VkVendor = 20803, |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 168 | void init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
Greg Daniel | 41f0e28 | 2019-01-28 13:15:05 -0500 | [diff] [blame] | 169 | VkPhysicalDevice device, const VkPhysicalDeviceFeatures2&, |
| 170 | uint32_t physicalDeviceVersion, const GrVkExtensions&); |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 171 | void initGrCaps(const GrVkInterface* vkInterface, |
| 172 | VkPhysicalDevice physDev, |
| 173 | const VkPhysicalDeviceProperties&, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 174 | const VkPhysicalDeviceMemoryProperties&, |
Greg Daniel | 313c695 | 2018-08-08 09:24:08 -0400 | [diff] [blame] | 175 | const VkPhysicalDeviceFeatures2&, |
| 176 | const GrVkExtensions&); |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 177 | void initShaderCaps(const VkPhysicalDeviceProperties&, const VkPhysicalDeviceFeatures2&); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 178 | |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 179 | void initConfigTable(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 180 | void initStencilFormat(const GrVkInterface* iface, VkPhysicalDevice physDev); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 181 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 182 | uint8_t getYcbcrKeyFromYcbcrInfo(const GrVkYcbcrConversionInfo& info); |
| 183 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 184 | void applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties&); |
| 185 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 186 | bool onSurfaceSupportsWritePixels(const GrSurface*) const override; |
| 187 | bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 188 | const SkIRect& srcRect, const SkIPoint& dstPoint) const override; |
| 189 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 190 | struct ConfigInfo { |
| 191 | ConfigInfo() : fOptimalFlags(0), fLinearFlags(0) {} |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 192 | |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 193 | void init(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&, |
| 194 | VkFormat); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 195 | static void InitConfigFlags(VkFormatFeatureFlags, uint16_t* flags); |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 196 | void initSampleCounts(const GrVkInterface*, VkPhysicalDevice, |
| 197 | const VkPhysicalDeviceProperties&, VkFormat); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 198 | |
| 199 | enum { |
| 200 | kTextureable_Flag = 0x1, |
| 201 | kRenderable_Flag = 0x2, |
| 202 | kBlitSrc_Flag = 0x4, |
| 203 | kBlitDst_Flag = 0x8, |
| 204 | }; |
| 205 | |
| 206 | uint16_t fOptimalFlags; |
| 207 | uint16_t fLinearFlags; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 208 | |
| 209 | SkTDArray<int> fColorSampleCounts; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 210 | }; |
| 211 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 212 | |
Ethan Nicholas | f610bae | 2018-09-20 16:55:21 -0400 | [diff] [blame] | 213 | StencilFormat fPreferredStencilFormat; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 214 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 215 | SkSTArray<1, GrVkYcbcrConversionInfo> fYcbcrInfos; |
| 216 | |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 217 | bool fMustDoCopiesFromOrigin = false; |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 218 | bool fMustSleepOnTearDown = false; |
| 219 | bool fNewCBOnPipelineChange = false; |
| 220 | bool fShouldAlwaysUseDedicatedImageMemory = false; |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 221 | |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 222 | bool fSupportsPhysicalDeviceProperties2 = false; |
| 223 | bool fSupportsMemoryRequirements2 = false; |
Greg Daniel | 637c06a | 2018-09-12 09:44:25 -0400 | [diff] [blame] | 224 | bool fSupportsBindMemory2 = false; |
Greg Daniel | a9979d1 | 2018-08-27 15:56:46 -0400 | [diff] [blame] | 225 | bool fSupportsMaintenance1 = false; |
| 226 | bool fSupportsMaintenance2 = false; |
| 227 | bool fSupportsMaintenance3 = false; |
| 228 | |
| 229 | bool fSupportsDedicatedAllocation = false; |
| 230 | bool fSupportsExternalMemory = false; |
| 231 | bool fSupportsAndroidHWBExternalMemory = false; |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 232 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 233 | bool fSupportsYcbcrConversion = false; |
| 234 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 235 | typedef GrCaps INHERITED; |
| 236 | }; |
| 237 | |
| 238 | #endif |