blob: 69298d7f5e3e1a9de66ddaca4eb6a92aef35acdf [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
15struct GrVkInterface;
Brian Salomon94efbf52016-11-29 13:43:05 -050016class GrShaderCaps;
Greg Daniel164a9f02016-02-22 09:56:40 -050017
18/**
19 * Stores some capabilities of a Vk backend.
20 */
21class GrVkCaps : public GrCaps {
halcanary9d524f22016-03-29 09:03:52 -070022public:
Greg Daniel164a9f02016-02-22 09:56:40 -050023 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,
egdanielc5ec1402016-03-28 12:14:42 -070030 VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags);
Greg Daniel164a9f02016-02-22 09:56:40 -050031
32 bool isConfigTexturable(GrPixelConfig config) const override {
egdaniel8f1dcaa2016-04-01 10:10:45 -070033 return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fOptimalFlags);
Greg Daniel164a9f02016-02-22 09:56:40 -050034 }
35
Greg Danielbb76ace2017-09-29 15:58:22 -040036 bool isConfigCopyable(GrPixelConfig config) const override {
37 return true;
38 }
39
Brian Salomonbdecacf2018-02-02 20:32:49 -050040 int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override;
41 int maxRenderTargetSampleCount(GrPixelConfig config) const override;
42
Brian Salomon19eaf2d2018-03-19 16:06:44 -040043 bool surfaceSupportsWritePixels(const GrSurface*) const override;
44 bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; }
Brian Salomon5f33a8c2018-02-26 14:32:39 -050045
egdaniela95d46b2016-08-15 08:06:29 -070046 bool isConfigTexturableLinearly(GrPixelConfig config) const {
egdaniel8f1dcaa2016-04-01 10:10:45 -070047 return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fLinearFlags);
48 }
49
50 bool isConfigRenderableLinearly(GrPixelConfig config, bool withMSAA) const {
egdaniel8f1dcaa2016-04-01 10:10:45 -070051 return !withMSAA && SkToBool(ConfigInfo::kRenderable_Flag &
52 fConfigTable[config].fLinearFlags);
53 }
54
55 bool configCanBeDstofBlit(GrPixelConfig config, bool linearTiled) const {
egdaniel8f1dcaa2016-04-01 10:10:45 -070056 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 {
egdaniel8f1dcaa2016-04-01 10:10:45 -070062 const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags :
63 fConfigTable[config].fOptimalFlags;
64 return SkToBool(ConfigInfo::kBlitSrc_Flag & flags);
Greg Daniel164a9f02016-02-22 09:56:40 -050065 }
66
Greg Daniel22bc8652017-03-22 15:45:43 -040067 // Tells of if we can pass in straight GLSL string into vkCreateShaderModule
egdanielc5ec1402016-03-28 12:14:42 -070068 bool canUseGLSLForShaderModule() const {
69 return fCanUseGLSLForShaderModule;
70 }
71
Greg Daniel22bc8652017-03-22 15:45:43 -040072 // 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.
egdaniel6fa0a912016-09-12 11:51:29 -070074 bool mustDoCopiesFromOrigin() const {
75 return fMustDoCopiesFromOrigin;
76 }
77
Greg Daniel22bc8652017-03-22 15:45:43 -040078 // 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.
egdanielfd016d72016-09-27 12:13:05 -070081 bool mustSubmitCommandsBeforeCopyOp() const {
82 return fMustSubmitCommandsBeforeCopyOp;
83 }
84
Greg Daniel22bc8652017-03-22 15:45:43 -040085 // 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 Daniel80a08dd2017-01-20 10:45:49 -050088 bool mustSleepOnTearDown() const {
89 return fMustSleepOnTearDown;
90 }
91
Greg Daniele3cd6912017-05-17 11:15:55 -040092 // 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 Daniel22bc8652017-03-22 15:45:43 -040097 }
98
Greg Daniel8385a8a2018-02-26 13:29:37 -050099 // 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 Daniel164a9f02016-02-22 09:56:40 -0500106 /**
egdaniel8f1dcaa2016-04-01 10:10:45 -0700107 * Returns both a supported and most prefered stencil format to use in draws.
Greg Daniel164a9f02016-02-22 09:56:40 -0500108 */
egdaniel8f1dcaa2016-04-01 10:10:45 -0700109 const StencilFormat& preferedStencilFormat() const {
110 return fPreferedStencilFormat;
Greg Daniel164a9f02016-02-22 09:56:40 -0500111 }
112
Greg Daniel25af6712018-04-25 10:44:38 -0400113 /**
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 Salomon2a4f9832018-03-03 22:43:43 -0500135 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400136 bool* rectsMustMatch, bool* disallowSubrect) const override;
Brian Salomon467921e2017-03-06 16:17:12 -0500137
Greg Danielfaa095e2017-12-19 13:15:02 -0500138 bool validateBackendTexture(const GrBackendTexture&, SkColorType,
139 GrPixelConfig*) const override;
140 bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
141 GrPixelConfig*) const override;
Greg Danielf5d87582017-12-18 14:48:15 -0500142
Robert Phillipsfc711a22018-02-13 17:03:00 -0500143 bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
144 GrPixelConfig*) const override;
145
Greg Danielfaa095e2017-12-19 13:15:02 -0500146private:
egdaniel6fa0a912016-09-12 11:51:29 -0700147 enum VkVendor {
Greg Danielc5cc2de2017-03-20 11:40:58 -0400148 kAMD_VkVendor = 4098,
Greg Daniel8385a8a2018-02-26 13:29:37 -0500149 kARM_VkVendor = 5045,
Greg Daniel80a08dd2017-01-20 10:45:49 -0500150 kImagination_VkVendor = 4112,
Greg Daniel8385a8a2018-02-26 13:29:37 -0500151 kIntel_VkVendor = 32902,
Greg Danielc5cc2de2017-03-20 11:40:58 -0400152 kNvidia_VkVendor = 4318,
153 kQualcomm_VkVendor = 20803,
egdaniel6fa0a912016-09-12 11:51:29 -0700154 };
155
Greg Daniel164a9f02016-02-22 09:56:40 -0500156 void init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
egdanielc5ec1402016-03-28 12:14:42 -0700157 VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags);
egdanield5e3b9e2016-03-08 12:19:54 -0800158 void initGrCaps(const VkPhysicalDeviceProperties&,
jvanverthfd7bd452016-03-25 06:29:52 -0700159 const VkPhysicalDeviceMemoryProperties&,
160 uint32_t featureFlags);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500161 void initShaderCaps(const VkPhysicalDeviceProperties&, uint32_t featureFlags);
Greg Daniel164a9f02016-02-22 09:56:40 -0500162
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000163 void initConfigTable(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&);
egdaniel8f1dcaa2016-04-01 10:10:45 -0700164 void initStencilFormat(const GrVkInterface* iface, VkPhysicalDevice physDev);
Greg Daniel164a9f02016-02-22 09:56:40 -0500165
Greg Daniel691f5e72018-02-28 14:21:34 -0500166 void applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties&);
167
egdaniel8f1dcaa2016-04-01 10:10:45 -0700168 struct ConfigInfo {
169 ConfigInfo() : fOptimalFlags(0), fLinearFlags(0) {}
Greg Daniel164a9f02016-02-22 09:56:40 -0500170
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000171 void init(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&,
172 VkFormat);
egdaniel8f1dcaa2016-04-01 10:10:45 -0700173 static void InitConfigFlags(VkFormatFeatureFlags, uint16_t* flags);
Greg Daniel2bb6ecc2017-07-20 13:11:14 +0000174 void initSampleCounts(const GrVkInterface*, VkPhysicalDevice,
175 const VkPhysicalDeviceProperties&, VkFormat);
egdaniel8f1dcaa2016-04-01 10:10:45 -0700176
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 Daniel81e7bf82017-07-19 14:47:42 -0400186
187 SkTDArray<int> fColorSampleCounts;
egdaniel8f1dcaa2016-04-01 10:10:45 -0700188 };
189 ConfigInfo fConfigTable[kGrPixelConfigCnt];
egdaniel3fe03272016-08-15 10:59:17 -0700190
egdaniel8f1dcaa2016-04-01 10:10:45 -0700191 StencilFormat fPreferedStencilFormat;
Greg Daniel164a9f02016-02-22 09:56:40 -0500192
egdanielc5ec1402016-03-28 12:14:42 -0700193 bool fCanUseGLSLForShaderModule;
194
egdaniel6fa0a912016-09-12 11:51:29 -0700195 bool fMustDoCopiesFromOrigin;
196
egdanielfd016d72016-09-27 12:13:05 -0700197 bool fMustSubmitCommandsBeforeCopyOp;
198
Greg Daniel80a08dd2017-01-20 10:45:49 -0500199 bool fMustSleepOnTearDown;
200
Greg Daniele3cd6912017-05-17 11:15:55 -0400201 bool fNewCBOnPipelineChange;
Greg Daniel22bc8652017-03-22 15:45:43 -0400202
Greg Daniel8385a8a2018-02-26 13:29:37 -0500203 bool fCanUseWholeSizeOnFlushMappedMemory;
204
Greg Daniel164a9f02016-02-22 09:56:40 -0500205 typedef GrCaps INHERITED;
206};
207
208#endif