blob: aed6f7b7dcb0d1190d38f27f6b92e35fa115eb0a [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
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"
jvanverthe50f3e72016-03-28 07:03:06 -070013#include "vk/GrVkDefines.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050014
Brian Salomon94efbf52016-11-29 13:43:05 -050015class GrShaderCaps;
Greg Danielc0b03d82018-08-03 14:41:15 -040016class GrVkExtensions;
17struct GrVkInterface;
Greg Daniel164a9f02016-02-22 09:56:40 -050018
19/**
20 * Stores some capabilities of a Vk backend.
21 */
22class GrVkCaps : public GrCaps {
halcanary9d524f22016-03-29 09:03:52 -070023public:
Greg Daniel164a9f02016-02-22 09:56:40 -050024 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 Daniela0651ac2018-08-08 09:23:18 -040031 VkPhysicalDevice device, const VkPhysicalDeviceFeatures2& features,
Greg Danielc0b03d82018-08-03 14:41:15 -040032 uint32_t instanceVersion, const GrVkExtensions& extensions);
Greg Daniel164a9f02016-02-22 09:56:40 -050033
34 bool isConfigTexturable(GrPixelConfig config) const override {
egdaniel8f1dcaa2016-04-01 10:10:45 -070035 return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fOptimalFlags);
Greg Daniel164a9f02016-02-22 09:56:40 -050036 }
37
Greg Danielbb76ace2017-09-29 15:58:22 -040038 bool isConfigCopyable(GrPixelConfig config) const override {
39 return true;
40 }
41
Brian Salomonbdecacf2018-02-02 20:32:49 -050042 int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override;
43 int maxRenderTargetSampleCount(GrPixelConfig config) const override;
44
Brian Salomon19eaf2d2018-03-19 16:06:44 -040045 bool surfaceSupportsWritePixels(const GrSurface*) const override;
46 bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; }
Brian Salomon5f33a8c2018-02-26 14:32:39 -050047
egdaniela95d46b2016-08-15 08:06:29 -070048 bool isConfigTexturableLinearly(GrPixelConfig config) const {
egdaniel8f1dcaa2016-04-01 10:10:45 -070049 return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fLinearFlags);
50 }
51
52 bool isConfigRenderableLinearly(GrPixelConfig config, bool withMSAA) const {
egdaniel8f1dcaa2016-04-01 10:10:45 -070053 return !withMSAA && SkToBool(ConfigInfo::kRenderable_Flag &
54 fConfigTable[config].fLinearFlags);
55 }
56
57 bool configCanBeDstofBlit(GrPixelConfig config, bool linearTiled) const {
egdaniel8f1dcaa2016-04-01 10:10:45 -070058 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 {
egdaniel8f1dcaa2016-04-01 10:10:45 -070064 const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags :
65 fConfigTable[config].fOptimalFlags;
66 return SkToBool(ConfigInfo::kBlitSrc_Flag & flags);
Greg Daniel164a9f02016-02-22 09:56:40 -050067 }
68
Greg Daniel22bc8652017-03-22 15:45:43 -040069 // 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.
egdaniel6fa0a912016-09-12 11:51:29 -070071 bool mustDoCopiesFromOrigin() const {
72 return fMustDoCopiesFromOrigin;
73 }
74
Greg Daniel22bc8652017-03-22 15:45:43 -040075 // On Nvidia there is a current bug where we must the current command buffer before copy
76 // operations or else the copy will not happen. This includes copies, blits, resolves, and copy
77 // as draws.
egdanielfd016d72016-09-27 12:13:05 -070078 bool mustSubmitCommandsBeforeCopyOp() const {
79 return fMustSubmitCommandsBeforeCopyOp;
80 }
81
Greg Daniel22bc8652017-03-22 15:45:43 -040082 // Sometimes calls to QueueWaitIdle return before actually signalling the fences
83 // on the command buffers even though they have completed. This causes an assert to fire when
84 // destroying the command buffers. Therefore we add a sleep to make sure the fence signals.
Greg Daniel80a08dd2017-01-20 10:45:49 -050085 bool mustSleepOnTearDown() const {
86 return fMustSleepOnTearDown;
87 }
88
Greg Daniele3cd6912017-05-17 11:15:55 -040089 // Returns true if while adding commands to command buffers, we must make a new command buffer
90 // everytime we want to bind a new VkPipeline. This is true for both primary and secondary
91 // command buffers. This is to work around a driver bug specifically on AMD.
92 bool newCBOnPipelineChange() const {
93 return fNewCBOnPipelineChange;
Greg Daniel22bc8652017-03-22 15:45:43 -040094 }
95
Greg Danielddc0c602018-06-18 11:26:30 -040096 // Returns true if we should always make dedicated allocations for VkImages.
97 bool shouldAlwaysUseDedicatedImageMemory() const {
98 return fShouldAlwaysUseDedicatedImageMemory;
Greg Daniel8385a8a2018-02-26 13:29:37 -050099 }
100
Greg Daniel164a9f02016-02-22 09:56:40 -0500101 /**
egdaniel8f1dcaa2016-04-01 10:10:45 -0700102 * Returns both a supported and most prefered stencil format to use in draws.
Greg Daniel164a9f02016-02-22 09:56:40 -0500103 */
egdaniel8f1dcaa2016-04-01 10:10:45 -0700104 const StencilFormat& preferedStencilFormat() const {
105 return fPreferedStencilFormat;
Greg Daniel164a9f02016-02-22 09:56:40 -0500106 }
107
Greg Danielc0b03d82018-08-03 14:41:15 -0400108 // Returns whether the device supports the ability to extend VkPhysicalDeviceProperties struct.
109 bool supportsPhysicalDeviceProperties2() const { return fSupportsPhysicalDeviceProperties2; }
110 // Returns whether the device supports the ability to extend VkMemoryRequirements struct.
111 bool supportsMemoryRequirements2() const { return fSupportsMemoryRequirements2; }
Greg Daniel637c06a2018-09-12 09:44:25 -0400112
113 // Returns whether the device supports the ability to extend the vkBindMemory call.
114 bool supportsBindMemory2() const { return fSupportsBindMemory2; }
115
Greg Danielc0b03d82018-08-03 14:41:15 -0400116 // Returns whether or not the device suports the various API maintenance fixes to Vulkan 1.0. In
117 // Vulkan 1.1 all these maintenance are part of the core spec.
118 bool supportsMaintenance1() const { return fSupportsMaintenance1; }
119 bool supportsMaintenance2() const { return fSupportsMaintenance2; }
120 bool supportsMaintenance3() const { return fSupportsMaintenance3; }
121
Greg Daniela9979d12018-08-27 15:56:46 -0400122 // Returns true if the device supports passing in a flag to say we are using dedicated GPU when
123 // allocating memory. For some devices this allows them to return more optimized memory knowning
124 // they will never need to suballocate amonst multiple objects.
125 bool supportsDedicatedAllocation() const { return fSupportsDedicatedAllocation; }
126
127 // Returns true if the device supports importing of external memory into Vulkan memory.
128 bool supportsExternalMemory() const { return fSupportsExternalMemory; }
129 // Returns true if the device supports importing Android hardware buffers into Vulkan memory.
130 bool supportsAndroidHWBExternalMemory() const { return fSupportsAndroidHWBExternalMemory; }
131
Greg Daniel25af6712018-04-25 10:44:38 -0400132 /**
133 * Helpers used by canCopySurface. In all cases if the SampleCnt parameter is zero that means
134 * the surface is not a render target, otherwise it is the number of samples in the render
135 * target.
136 */
137 bool canCopyImage(GrPixelConfig dstConfig, int dstSampleCnt, GrSurfaceOrigin dstOrigin,
138 GrPixelConfig srcConfig, int srcSamplecnt, GrSurfaceOrigin srcOrigin) const;
139
140 bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt, bool dstIsLinear,
141 GrPixelConfig srcConfig, int srcSampleCnt, bool srcIsLinear) const;
142
143 bool canCopyAsResolve(GrPixelConfig dstConfig, int dstSampleCnt, GrSurfaceOrigin dstOrigin,
144 GrPixelConfig srcConfig, int srcSamplecnt,
145 GrSurfaceOrigin srcOrigin) const;
146
147 bool canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable,
148 GrPixelConfig srcConfig, bool srcIsTextureable) const;
149
150 bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
151 const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
152
Brian Salomon2a4f9832018-03-03 22:43:43 -0500153 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400154 bool* rectsMustMatch, bool* disallowSubrect) const override;
Brian Salomon467921e2017-03-06 16:17:12 -0500155
Greg Danielfaa095e2017-12-19 13:15:02 -0500156 bool validateBackendTexture(const GrBackendTexture&, SkColorType,
157 GrPixelConfig*) const override;
158 bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
159 GrPixelConfig*) const override;
Greg Danielf5d87582017-12-18 14:48:15 -0500160
Robert Phillipsfc711a22018-02-13 17:03:00 -0500161 bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
162 GrPixelConfig*) const override;
163
Greg Danielfaa095e2017-12-19 13:15:02 -0500164private:
egdaniel6fa0a912016-09-12 11:51:29 -0700165 enum VkVendor {
Greg Danielc5cc2de2017-03-20 11:40:58 -0400166 kAMD_VkVendor = 4098,
Greg Daniel8385a8a2018-02-26 13:29:37 -0500167 kARM_VkVendor = 5045,
Greg Daniel80a08dd2017-01-20 10:45:49 -0500168 kImagination_VkVendor = 4112,
Greg Daniel8385a8a2018-02-26 13:29:37 -0500169 kIntel_VkVendor = 32902,
Greg Danielc5cc2de2017-03-20 11:40:58 -0400170 kNvidia_VkVendor = 4318,
171 kQualcomm_VkVendor = 20803,
egdaniel6fa0a912016-09-12 11:51:29 -0700172 };
173
Greg Daniel164a9f02016-02-22 09:56:40 -0500174 void init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
Greg Daniela0651ac2018-08-08 09:23:18 -0400175 VkPhysicalDevice device, const VkPhysicalDeviceFeatures2&, const GrVkExtensions&);
Greg Daniel313c6952018-08-08 09:24:08 -0400176 void initGrCaps(const GrVkInterface* vkInterface,
177 VkPhysicalDevice physDev,
178 const VkPhysicalDeviceProperties&,
jvanverthfd7bd452016-03-25 06:29:52 -0700179 const VkPhysicalDeviceMemoryProperties&,
Greg Daniel313c6952018-08-08 09:24:08 -0400180 const VkPhysicalDeviceFeatures2&,
181 const GrVkExtensions&);
Greg Daniela0651ac2018-08-08 09:23:18 -0400182 void initShaderCaps(const VkPhysicalDeviceProperties&, const VkPhysicalDeviceFeatures2&);
Greg Daniel164a9f02016-02-22 09:56:40 -0500183
Timothy Liang036fdfe2018-06-28 15:50:36 -0400184#ifdef GR_TEST_UTILS
185 GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override;
186#endif
187
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000188 void initConfigTable(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&);
egdaniel8f1dcaa2016-04-01 10:10:45 -0700189 void initStencilFormat(const GrVkInterface* iface, VkPhysicalDevice physDev);
Greg Daniel164a9f02016-02-22 09:56:40 -0500190
Greg Daniel691f5e72018-02-28 14:21:34 -0500191 void applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties&);
192
egdaniel8f1dcaa2016-04-01 10:10:45 -0700193 struct ConfigInfo {
194 ConfigInfo() : fOptimalFlags(0), fLinearFlags(0) {}
Greg Daniel164a9f02016-02-22 09:56:40 -0500195
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000196 void init(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&,
197 VkFormat);
egdaniel8f1dcaa2016-04-01 10:10:45 -0700198 static void InitConfigFlags(VkFormatFeatureFlags, uint16_t* flags);
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000199 void initSampleCounts(const GrVkInterface*, VkPhysicalDevice,
200 const VkPhysicalDeviceProperties&, VkFormat);
egdaniel8f1dcaa2016-04-01 10:10:45 -0700201
202 enum {
203 kTextureable_Flag = 0x1,
204 kRenderable_Flag = 0x2,
205 kBlitSrc_Flag = 0x4,
206 kBlitDst_Flag = 0x8,
207 };
208
209 uint16_t fOptimalFlags;
210 uint16_t fLinearFlags;
Greg Daniel81e7bf82017-07-19 14:47:42 -0400211
212 SkTDArray<int> fColorSampleCounts;
egdaniel8f1dcaa2016-04-01 10:10:45 -0700213 };
214 ConfigInfo fConfigTable[kGrPixelConfigCnt];
egdaniel3fe03272016-08-15 10:59:17 -0700215
egdaniel8f1dcaa2016-04-01 10:10:45 -0700216 StencilFormat fPreferedStencilFormat;
Greg Daniel164a9f02016-02-22 09:56:40 -0500217
Greg Daniela9979d12018-08-27 15:56:46 -0400218 bool fMustDoCopiesFromOrigin = false;
219 bool fMustSubmitCommandsBeforeCopyOp = false;
220 bool fMustSleepOnTearDown = false;
221 bool fNewCBOnPipelineChange = false;
222 bool fShouldAlwaysUseDedicatedImageMemory = false;
Greg Daniel8385a8a2018-02-26 13:29:37 -0500223
Greg Daniela9979d12018-08-27 15:56:46 -0400224 bool fSupportsPhysicalDeviceProperties2 = false;
225 bool fSupportsMemoryRequirements2 = false;
Greg Daniel637c06a2018-09-12 09:44:25 -0400226 bool fSupportsBindMemory2 = false;
Greg Daniela9979d12018-08-27 15:56:46 -0400227 bool fSupportsMaintenance1 = false;
228 bool fSupportsMaintenance2 = false;
229 bool fSupportsMaintenance3 = false;
230
231 bool fSupportsDedicatedAllocation = false;
232 bool fSupportsExternalMemory = false;
233 bool fSupportsAndroidHWBExternalMemory = false;
Greg Danielc0b03d82018-08-03 14:41:15 -0400234
Greg Daniel164a9f02016-02-22 09:56:40 -0500235 typedef GrCaps INHERITED;
236};
237
238#endif