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 | |
| 36 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 37 | return SkToBool(ConfigInfo::kRenderable_Flag & fConfigTable[config].fOptimalFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 38 | } |
| 39 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 40 | bool canConfigBeImageStorage(GrPixelConfig) const override { return false; } |
| 41 | |
egdaniel | a95d46b | 2016-08-15 08:06:29 -0700 | [diff] [blame] | 42 | bool isConfigTexturableLinearly(GrPixelConfig config) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 43 | return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fLinearFlags); |
| 44 | } |
| 45 | |
| 46 | bool isConfigRenderableLinearly(GrPixelConfig config, bool withMSAA) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 47 | return !withMSAA && SkToBool(ConfigInfo::kRenderable_Flag & |
| 48 | fConfigTable[config].fLinearFlags); |
| 49 | } |
| 50 | |
| 51 | bool configCanBeDstofBlit(GrPixelConfig config, bool linearTiled) const { |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 52 | const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags : |
| 53 | fConfigTable[config].fOptimalFlags; |
| 54 | return SkToBool(ConfigInfo::kBlitDst_Flag & flags); |
| 55 | } |
| 56 | |
| 57 | bool configCanBeSrcofBlit(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::kBlitSrc_Flag & flags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 61 | } |
| 62 | |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 63 | bool canUseGLSLForShaderModule() const { |
| 64 | return fCanUseGLSLForShaderModule; |
| 65 | } |
| 66 | |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 67 | bool mustDoCopiesFromOrigin() const { |
| 68 | return fMustDoCopiesFromOrigin; |
| 69 | } |
| 70 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 71 | bool supportsCopiesAsDraws() const { |
| 72 | return fSupportsCopiesAsDraws; |
| 73 | } |
| 74 | |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 75 | bool mustSubmitCommandsBeforeCopyOp() const { |
| 76 | return fMustSubmitCommandsBeforeCopyOp; |
| 77 | } |
| 78 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame^] | 79 | bool mustSleepOnTearDown() const { |
| 80 | return fMustSleepOnTearDown; |
| 81 | } |
| 82 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 83 | /** |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 84 | * 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] | 85 | */ |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 86 | const StencilFormat& preferedStencilFormat() const { |
| 87 | return fPreferedStencilFormat; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 88 | } |
| 89 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 90 | private: |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 91 | enum VkVendor { |
| 92 | kQualcomm_VkVendor = 20803, |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 93 | kNvidia_VkVendor = 4318, |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame^] | 94 | kImagination_VkVendor = 4112, |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 97 | void init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 98 | VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags); |
egdaniel | d5e3b9e | 2016-03-08 12:19:54 -0800 | [diff] [blame] | 99 | void initGrCaps(const VkPhysicalDeviceProperties&, |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 100 | const VkPhysicalDeviceMemoryProperties&, |
| 101 | uint32_t featureFlags); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 102 | void initShaderCaps(const VkPhysicalDeviceProperties&, uint32_t featureFlags); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 103 | void initSampleCount(const VkPhysicalDeviceProperties& properties); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 104 | |
| 105 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 106 | void initConfigTable(const GrVkInterface*, VkPhysicalDevice); |
| 107 | void initStencilFormat(const GrVkInterface* iface, VkPhysicalDevice physDev); |
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 | struct ConfigInfo { |
| 110 | ConfigInfo() : fOptimalFlags(0), fLinearFlags(0) {} |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 111 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 112 | void init(const GrVkInterface*, VkPhysicalDevice, VkFormat); |
| 113 | static void InitConfigFlags(VkFormatFeatureFlags, uint16_t* flags); |
| 114 | |
| 115 | enum { |
| 116 | kTextureable_Flag = 0x1, |
| 117 | kRenderable_Flag = 0x2, |
| 118 | kBlitSrc_Flag = 0x4, |
| 119 | kBlitDst_Flag = 0x8, |
| 120 | }; |
| 121 | |
| 122 | uint16_t fOptimalFlags; |
| 123 | uint16_t fLinearFlags; |
| 124 | }; |
| 125 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 126 | |
egdaniel | 8f1dcaa | 2016-04-01 10:10:45 -0700 | [diff] [blame] | 127 | StencilFormat fPreferedStencilFormat; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 128 | |
egdaniel | c5ec140 | 2016-03-28 12:14:42 -0700 | [diff] [blame] | 129 | // Tells of if we can pass in straight GLSL string into vkCreateShaderModule |
| 130 | bool fCanUseGLSLForShaderModule; |
| 131 | |
egdaniel | 6fa0a91 | 2016-09-12 11:51:29 -0700 | [diff] [blame] | 132 | // On Adreno vulkan, they do not respect the imageOffset parameter at least in |
| 133 | // copyImageToBuffer. This flag says that we must do the copy starting from the origin always. |
| 134 | bool fMustDoCopiesFromOrigin; |
| 135 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 136 | // Check whether we support using draws for copies. |
| 137 | bool fSupportsCopiesAsDraws; |
| 138 | |
egdaniel | fd016d7 | 2016-09-27 12:13:05 -0700 | [diff] [blame] | 139 | // On Nvidia there is a current bug where we must the current command buffer before copy |
| 140 | // operations or else the copy will not happen. This includes copies, blits, resolves, and copy |
| 141 | // as draws. |
| 142 | bool fMustSubmitCommandsBeforeCopyOp; |
| 143 | |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame^] | 144 | // Sometimes calls to QueueWaitIdle return before actually signalling the fences |
| 145 | // on the command buffers even though they have completed. This causes an assert to fire when |
| 146 | // destroying the command buffers. Therefore we add a sleep to make sure the fence signals. |
| 147 | bool fMustSleepOnTearDown; |
| 148 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 149 | typedef GrCaps INHERITED; |
| 150 | }; |
| 151 | |
| 152 | #endif |