blob: 6d030f69a1b05de7444eddb80ea8a1d3477c5889 [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
36 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override {
egdaniel8f1dcaa2016-04-01 10:10:45 -070037 return SkToBool(ConfigInfo::kRenderable_Flag & fConfigTable[config].fOptimalFlags);
Greg Daniel164a9f02016-02-22 09:56:40 -050038 }
39
Brian Salomonf9f45122016-11-29 11:59:17 -050040 bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
41
egdaniela95d46b2016-08-15 08:06:29 -070042 bool isConfigTexturableLinearly(GrPixelConfig config) const {
egdaniel8f1dcaa2016-04-01 10:10:45 -070043 return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fLinearFlags);
44 }
45
46 bool isConfigRenderableLinearly(GrPixelConfig config, bool withMSAA) const {
egdaniel8f1dcaa2016-04-01 10:10:45 -070047 return !withMSAA && SkToBool(ConfigInfo::kRenderable_Flag &
48 fConfigTable[config].fLinearFlags);
49 }
50
51 bool configCanBeDstofBlit(GrPixelConfig config, bool linearTiled) const {
egdaniel8f1dcaa2016-04-01 10:10:45 -070052 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 {
egdaniel8f1dcaa2016-04-01 10:10:45 -070058 const uint16_t& flags = linearTiled ? fConfigTable[config].fLinearFlags :
59 fConfigTable[config].fOptimalFlags;
60 return SkToBool(ConfigInfo::kBlitSrc_Flag & flags);
Greg Daniel164a9f02016-02-22 09:56:40 -050061 }
62
egdanielc5ec1402016-03-28 12:14:42 -070063 bool canUseGLSLForShaderModule() const {
64 return fCanUseGLSLForShaderModule;
65 }
66
egdaniel6fa0a912016-09-12 11:51:29 -070067 bool mustDoCopiesFromOrigin() const {
68 return fMustDoCopiesFromOrigin;
69 }
70
egdanielbc9b2962016-09-27 08:00:53 -070071 bool supportsCopiesAsDraws() const {
72 return fSupportsCopiesAsDraws;
73 }
74
egdanielfd016d72016-09-27 12:13:05 -070075 bool mustSubmitCommandsBeforeCopyOp() const {
76 return fMustSubmitCommandsBeforeCopyOp;
77 }
78
Greg Daniel80a08dd2017-01-20 10:45:49 -050079 bool mustSleepOnTearDown() const {
80 return fMustSleepOnTearDown;
81 }
82
Greg Daniel164a9f02016-02-22 09:56:40 -050083 /**
egdaniel8f1dcaa2016-04-01 10:10:45 -070084 * Returns both a supported and most prefered stencil format to use in draws.
Greg Daniel164a9f02016-02-22 09:56:40 -050085 */
egdaniel8f1dcaa2016-04-01 10:10:45 -070086 const StencilFormat& preferedStencilFormat() const {
87 return fPreferedStencilFormat;
Greg Daniel164a9f02016-02-22 09:56:40 -050088 }
89
Greg Daniel164a9f02016-02-22 09:56:40 -050090private:
egdaniel6fa0a912016-09-12 11:51:29 -070091 enum VkVendor {
92 kQualcomm_VkVendor = 20803,
egdanielfd016d72016-09-27 12:13:05 -070093 kNvidia_VkVendor = 4318,
Greg Daniel80a08dd2017-01-20 10:45:49 -050094 kImagination_VkVendor = 4112,
egdaniel6fa0a912016-09-12 11:51:29 -070095 };
96
Greg Daniel164a9f02016-02-22 09:56:40 -050097 void init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
egdanielc5ec1402016-03-28 12:14:42 -070098 VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags);
egdanield5e3b9e2016-03-08 12:19:54 -080099 void initGrCaps(const VkPhysicalDeviceProperties&,
jvanverthfd7bd452016-03-25 06:29:52 -0700100 const VkPhysicalDeviceMemoryProperties&,
101 uint32_t featureFlags);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500102 void initShaderCaps(const VkPhysicalDeviceProperties&, uint32_t featureFlags);
Greg Daniel164a9f02016-02-22 09:56:40 -0500103 void initSampleCount(const VkPhysicalDeviceProperties& properties);
Greg Daniel164a9f02016-02-22 09:56:40 -0500104
105
egdaniel8f1dcaa2016-04-01 10:10:45 -0700106 void initConfigTable(const GrVkInterface*, VkPhysicalDevice);
107 void initStencilFormat(const GrVkInterface* iface, VkPhysicalDevice physDev);
Greg Daniel164a9f02016-02-22 09:56:40 -0500108
egdaniel8f1dcaa2016-04-01 10:10:45 -0700109 struct ConfigInfo {
110 ConfigInfo() : fOptimalFlags(0), fLinearFlags(0) {}
Greg Daniel164a9f02016-02-22 09:56:40 -0500111
egdaniel8f1dcaa2016-04-01 10:10:45 -0700112 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];
egdaniel3fe03272016-08-15 10:59:17 -0700126
egdaniel8f1dcaa2016-04-01 10:10:45 -0700127 StencilFormat fPreferedStencilFormat;
Greg Daniel164a9f02016-02-22 09:56:40 -0500128
egdanielc5ec1402016-03-28 12:14:42 -0700129 // Tells of if we can pass in straight GLSL string into vkCreateShaderModule
130 bool fCanUseGLSLForShaderModule;
131
egdaniel6fa0a912016-09-12 11:51:29 -0700132 // 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
egdanielbc9b2962016-09-27 08:00:53 -0700136 // Check whether we support using draws for copies.
137 bool fSupportsCopiesAsDraws;
138
egdanielfd016d72016-09-27 12:13:05 -0700139 // 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 Daniel80a08dd2017-01-20 10:45:49 -0500144 // 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 Daniel164a9f02016-02-22 09:56:40 -0500149 typedef GrCaps INHERITED;
150};
151
152#endif