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" |
jvanverth | e50f3e7 | 2016-03-28 07:03:06 -0700 | [diff] [blame] | 13 | #include "vk/GrVkDefines.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 14 | |
| 15 | struct GrVkInterface; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 16 | class GrShaderCaps; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Stores some capabilities of a Vk backend. |
| 20 | */ |
| 21 | class GrVkCaps : public GrCaps { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 22 | public: |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 23 | typedef GrVkStencilAttachment::Format StencilFormat; |
| 24 | |
| 25 | /** |
| 26 | * Creates a GrVkCaps that is set such that nothing is supported. The init function should |
| 27 | * be called to fill out the caps. |
| 28 | */ |
| 29 | GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 30 | VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 31 | |
| 32 | bool isConfigTexturable(GrPixelConfig config) const override { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 33 | return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fOptimalFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 36 | bool isConfigCopyable(GrPixelConfig config) const override { |
| 37 | return true; |
| 38 | } |
| 39 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 40 | int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override; |
| 41 | int maxRenderTargetSampleCount(GrPixelConfig config) const override; |
| 42 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 43 | bool surfaceSupportsWritePixels(const GrSurface*) const override; |
| 44 | bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 45 | |
egdaniel | a95d46b | 2016-08-15 08:06:29 -0700 | [diff] [blame] | 46 | bool isConfigTexturableLinearly(GrPixelConfig config) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 47 | return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fLinearFlags); |
| 48 | } |
| 49 | |
| 50 | bool isConfigRenderableLinearly(GrPixelConfig config, bool withMSAA) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 51 | return !withMSAA && SkToBool(ConfigInfo::kRenderable_Flag & |
| 52 | fConfigTable[config].fLinearFlags); |
| 53 | } |
| 54 | |
| 55 | bool configCanBeDstofBlit(GrPixelConfig config, bool linearTiled) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 56 | const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags : |
| 57 | fConfigTable[config].fOptimalFlags; |
| 58 | return SkToBool(ConfigInfo::kBlitDst_Flag & flags); |
| 59 | } |
| 60 | |
| 61 | bool configCanBeSrcofBlit(GrPixelConfig config, bool linearTiled) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 62 | const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags : |
| 63 | fConfigTable[config].fOptimalFlags; |
| 64 | return SkToBool(ConfigInfo::kBlitSrc_Flag & flags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 67 | // Tells of if we can pass in straight GLSL string into vkCreateShaderModule |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 68 | bool canUseGLSLForShaderModule() const { |
| 69 | return fCanUseGLSLForShaderModule; |
| 70 | } |
| 71 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 72 | // On Adreno vulkan, they do not respect the imageOffset parameter at least in |
| 73 | // 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] | 74 | bool mustDoCopiesFromOrigin() const { |
| 75 | return fMustDoCopiesFromOrigin; |
| 76 | } |
| 77 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 78 | // On Nvidia there is a current bug where we must the current command buffer before copy |
| 79 | // operations or else the copy will not happen. This includes copies, blits, resolves, and copy |
| 80 | // as draws. |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 81 | bool mustSubmitCommandsBeforeCopyOp() const { |
| 82 | return fMustSubmitCommandsBeforeCopyOp; |
| 83 | } |
| 84 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 85 | // Sometimes calls to QueueWaitIdle return before actually signalling the fences |
| 86 | // on the command buffers even though they have completed. This causes an assert to fire when |
| 87 | // 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] | 88 | bool mustSleepOnTearDown() const { |
| 89 | return fMustSleepOnTearDown; |
| 90 | } |
| 91 | |
Greg Daniel | e3cd691 | 2017-05-17 11:15:55 -0400 | [diff] [blame] | 92 | // Returns true if while adding commands to command buffers, we must make a new command buffer |
| 93 | // everytime we want to bind a new VkPipeline. This is true for both primary and secondary |
| 94 | // command buffers. This is to work around a driver bug specifically on AMD. |
| 95 | bool newCBOnPipelineChange() const { |
| 96 | return fNewCBOnPipelineChange; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 97 | } |
| 98 | |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 99 | // On certain Intel devices/drivers (IntelHD405) there is a bug if we try to flush non-coherent |
| 100 | // memory and pass in VK_WHOLE_SIZE. This returns whether or not it is safe to use VK_WHOLE_SIZE |
| 101 | // or not. |
| 102 | bool canUseWholeSizeOnFlushMappedMemory() const { |
| 103 | return fCanUseWholeSizeOnFlushMappedMemory; |
| 104 | } |
| 105 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 106 | /** |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 107 | * Returns both a supported and most prefered stencil format to use in draws. |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 108 | */ |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 109 | const StencilFormat& preferedStencilFormat() const { |
| 110 | return fPreferedStencilFormat; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 111 | } |
| 112 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame^] | 113 | /** |
| 114 | * Helpers used by canCopySurface. In all cases if the SampleCnt parameter is zero that means |
| 115 | * the surface is not a render target, otherwise it is the number of samples in the render |
| 116 | * target. |
| 117 | */ |
| 118 | bool canCopyImage(GrPixelConfig dstConfig, int dstSampleCnt, GrSurfaceOrigin dstOrigin, |
| 119 | GrPixelConfig srcConfig, int srcSamplecnt, GrSurfaceOrigin srcOrigin) const; |
| 120 | |
| 121 | bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt, bool dstIsLinear, |
| 122 | GrPixelConfig srcConfig, int srcSampleCnt, bool srcIsLinear) const; |
| 123 | |
| 124 | bool canCopyAsResolve(GrPixelConfig dstConfig, int dstSampleCnt, GrSurfaceOrigin dstOrigin, |
| 125 | GrPixelConfig srcConfig, int srcSamplecnt, |
| 126 | GrSurfaceOrigin srcOrigin) const; |
| 127 | |
| 128 | bool canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable, |
| 129 | GrPixelConfig srcConfig, bool srcIsTextureable) const; |
| 130 | |
| 131 | bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 132 | const SkIRect& srcRect, const SkIPoint& dstPoint) const override; |
| 133 | |
| 134 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 135 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 136 | bool* rectsMustMatch, bool* disallowSubrect) const override; |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 137 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 138 | bool validateBackendTexture(const GrBackendTexture&, SkColorType, |
| 139 | GrPixelConfig*) const override; |
| 140 | bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType, |
| 141 | GrPixelConfig*) const override; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 142 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 143 | bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType, |
| 144 | GrPixelConfig*) const override; |
| 145 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 146 | private: |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 147 | enum VkVendor { |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 148 | kAMD_VkVendor = 4098, |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 149 | kARM_VkVendor = 5045, |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 150 | kImagination_VkVendor = 4112, |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 151 | kIntel_VkVendor = 32902, |
Greg Daniel | c5cc2de | 2017-03-20 11:40:58 -0400 | [diff] [blame] | 152 | kNvidia_VkVendor = 4318, |
| 153 | kQualcomm_VkVendor = 20803, |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 156 | void init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 157 | VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 158 | void initGrCaps(const VkPhysicalDeviceProperties&, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 159 | const VkPhysicalDeviceMemoryProperties&, |
| 160 | uint32_t featureFlags); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 161 | void initShaderCaps(const VkPhysicalDeviceProperties&, uint32_t featureFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 162 | |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 163 | void initConfigTable(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 164 | void initStencilFormat(const GrVkInterface* iface, VkPhysicalDevice physDev); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 165 | |
Greg Daniel | 691f5e7 | 2018-02-28 14:21:34 -0500 | [diff] [blame] | 166 | void applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties&); |
| 167 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 168 | struct ConfigInfo { |
| 169 | ConfigInfo() : fOptimalFlags(0), fLinearFlags(0) {} |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 170 | |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 171 | void init(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&, |
| 172 | VkFormat); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 173 | static void InitConfigFlags(VkFormatFeatureFlags, uint16_t* flags); |
Greg Daniel | 2bb6ecc | 2017-07-20 13:11:14 +0000 | [diff] [blame] | 174 | void initSampleCounts(const GrVkInterface*, VkPhysicalDevice, |
| 175 | const VkPhysicalDeviceProperties&, VkFormat); |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 176 | |
| 177 | enum { |
| 178 | kTextureable_Flag = 0x1, |
| 179 | kRenderable_Flag = 0x2, |
| 180 | kBlitSrc_Flag = 0x4, |
| 181 | kBlitDst_Flag = 0x8, |
| 182 | }; |
| 183 | |
| 184 | uint16_t fOptimalFlags; |
| 185 | uint16_t fLinearFlags; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 186 | |
| 187 | SkTDArray<int> fColorSampleCounts; |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 188 | }; |
| 189 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 190 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 191 | StencilFormat fPreferedStencilFormat; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 192 | |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 193 | bool fCanUseGLSLForShaderModule; |
| 194 | |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 195 | bool fMustDoCopiesFromOrigin; |
| 196 | |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 197 | bool fMustSubmitCommandsBeforeCopyOp; |
| 198 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 199 | bool fMustSleepOnTearDown; |
| 200 | |
Greg Daniel | e3cd691 | 2017-05-17 11:15:55 -0400 | [diff] [blame] | 201 | bool fNewCBOnPipelineChange; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 202 | |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 203 | bool fCanUseWholeSizeOnFlushMappedMemory; |
| 204 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 205 | typedef GrCaps INHERITED; |
| 206 | }; |
| 207 | |
| 208 | #endif |