• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
13 #include "vk/GrVkDefines.h"
14 
15 struct GrVkInterface;
16 class GrShaderCaps;
17 
18 /**
19  * Stores some capabilities of a Vk backend.
20  */
21 class GrVkCaps : public GrCaps {
22 public:
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,
30              VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags);
31 
32     int getSampleCount(int requestedCount, GrPixelConfig config) const override;
33 
isConfigTexturable(GrPixelConfig config)34     bool isConfigTexturable(GrPixelConfig config) const override {
35         return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fOptimalFlags);
36     }
37 
isConfigRenderable(GrPixelConfig config,bool withMSAA)38     bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override {
39         return SkToBool(ConfigInfo::kRenderable_Flag & fConfigTable[config].fOptimalFlags);
40     }
41 
canConfigBeImageStorage(GrPixelConfig)42     bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
43 
isConfigTexturableLinearly(GrPixelConfig config)44     bool isConfigTexturableLinearly(GrPixelConfig config) const {
45         return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fLinearFlags);
46     }
47 
isConfigRenderableLinearly(GrPixelConfig config,bool withMSAA)48     bool isConfigRenderableLinearly(GrPixelConfig config, bool withMSAA) const {
49         return !withMSAA && SkToBool(ConfigInfo::kRenderable_Flag &
50                                      fConfigTable[config].fLinearFlags);
51     }
52 
configCanBeDstofBlit(GrPixelConfig config,bool linearTiled)53     bool configCanBeDstofBlit(GrPixelConfig config, bool linearTiled) const {
54         const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags :
55                                               fConfigTable[config].fOptimalFlags;
56         return SkToBool(ConfigInfo::kBlitDst_Flag & flags);
57     }
58 
configCanBeSrcofBlit(GrPixelConfig config,bool linearTiled)59     bool configCanBeSrcofBlit(GrPixelConfig config, bool linearTiled) const {
60         const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags :
61                                               fConfigTable[config].fOptimalFlags;
62         return SkToBool(ConfigInfo::kBlitSrc_Flag & flags);
63     }
64 
65     // Tells of if we can pass in straight GLSL string into vkCreateShaderModule
canUseGLSLForShaderModule()66     bool canUseGLSLForShaderModule() const {
67         return fCanUseGLSLForShaderModule;
68     }
69 
70     // On Adreno vulkan, they do not respect the imageOffset parameter at least in
71     // copyImageToBuffer. This flag says that we must do the copy starting from the origin always.
mustDoCopiesFromOrigin()72     bool mustDoCopiesFromOrigin() const {
73         return fMustDoCopiesFromOrigin;
74     }
75 
76     // Check whether we support using draws for copies.
supportsCopiesAsDraws()77     bool supportsCopiesAsDraws() const {
78         return fSupportsCopiesAsDraws;
79     }
80 
81     // On Nvidia there is a current bug where we must the current command buffer before copy
82     // operations or else the copy will not happen. This includes copies, blits, resolves, and copy
83     // as draws.
mustSubmitCommandsBeforeCopyOp()84     bool mustSubmitCommandsBeforeCopyOp() const {
85         return fMustSubmitCommandsBeforeCopyOp;
86     }
87 
88     // Sometimes calls to QueueWaitIdle return before actually signalling the fences
89     // on the command buffers even though they have completed. This causes an assert to fire when
90     // destroying the command buffers. Therefore we add a sleep to make sure the fence signals.
mustSleepOnTearDown()91     bool mustSleepOnTearDown() const {
92         return fMustSleepOnTearDown;
93     }
94 
95     // Returns true if while adding commands to command buffers, we must make a new command buffer
96     // everytime we want to bind a new VkPipeline. This is true for both primary and secondary
97     // command buffers. This is to work around a driver bug specifically on AMD.
newCBOnPipelineChange()98     bool newCBOnPipelineChange() const {
99         return fNewCBOnPipelineChange;
100     }
101 
102     /**
103      * Returns both a supported and most prefered stencil format to use in draws.
104      */
preferedStencilFormat()105     const StencilFormat& preferedStencilFormat() const {
106         return fPreferedStencilFormat;
107     }
108 
109     bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
110                             bool* rectsMustMatch, bool* disallowSubrect) const override;
111 
112 private:
113     enum VkVendor {
114         kAMD_VkVendor = 4098,
115         kImagination_VkVendor = 4112,
116         kNvidia_VkVendor = 4318,
117         kQualcomm_VkVendor = 20803,
118     };
119 
120     void init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
121               VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags);
122     void initGrCaps(const VkPhysicalDeviceProperties&,
123                     const VkPhysicalDeviceMemoryProperties&,
124                     uint32_t featureFlags);
125     void initShaderCaps(const VkPhysicalDeviceProperties&, uint32_t featureFlags);
126     void initSampleCount(const VkPhysicalDeviceProperties& properties);
127 
128 
129     void initConfigTable(const GrVkInterface*, VkPhysicalDevice);
130     void initStencilFormat(const GrVkInterface* iface, VkPhysicalDevice physDev);
131 
132     struct ConfigInfo {
ConfigInfoConfigInfo133         ConfigInfo() : fOptimalFlags(0), fLinearFlags(0) {}
134 
135         void init(const GrVkInterface*, VkPhysicalDevice, VkFormat);
136         static void InitConfigFlags(VkFormatFeatureFlags, uint16_t* flags);
137         void initSampleCounts(const GrVkInterface*, VkPhysicalDevice, VkFormat);
138 
139         enum {
140             kTextureable_Flag = 0x1,
141             kRenderable_Flag  = 0x2,
142             kBlitSrc_Flag     = 0x4,
143             kBlitDst_Flag     = 0x8,
144         };
145 
146         uint16_t fOptimalFlags;
147         uint16_t fLinearFlags;
148 
149         SkTDArray<int> fColorSampleCounts;
150     };
151     ConfigInfo fConfigTable[kGrPixelConfigCnt];
152 
153     StencilFormat fPreferedStencilFormat;
154 
155     bool fCanUseGLSLForShaderModule;
156 
157     bool fMustDoCopiesFromOrigin;
158 
159     bool fSupportsCopiesAsDraws;
160 
161     bool fMustSubmitCommandsBeforeCopyOp;
162 
163     bool fMustSleepOnTearDown;
164 
165     bool fNewCBOnPipelineChange;
166 
167     typedef GrCaps INHERITED;
168 };
169 
170 #endif
171