blob: 3135c9e46ea9097dcb123af0cdbda5bb77b81d50 [file] [log] [blame]
Greg Daniel48cf2682016-02-22 09:11:32 -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"
13#include "vulkan/vulkan.h"
14
15struct GrVkInterface;
16class GrGLSLCaps;
17
18/**
19 * Stores some capabilities of a Vk backend.
20 */
21class GrVkCaps : public GrCaps {
22public:
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);
31
32 bool isConfigTexturable(GrPixelConfig config) const override {
33 SkASSERT(kGrPixelConfigCnt > config);
34 return fConfigTextureSupport[config];
35 }
36
37 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override {
38 SkASSERT(kGrPixelConfigCnt > config);
39 return fConfigRenderSupport[config][withMSAA];
40 }
41
42 bool isConfigRenderableLinearly(GrPixelConfig config, bool withMSAA) const {
43 SkASSERT(kGrPixelConfigCnt > config);
44 return fConfigLinearRenderSupport[config][withMSAA];
45 }
46
47 bool isConfigTexurableLinearly(GrPixelConfig config) const {
48 SkASSERT(kGrPixelConfigCnt > config);
49 return fConfigLinearTextureSupport[config];
50 }
51
52 /**
53 * Gets an array of legal stencil formats. These formats are not guaranteed to be supported by
54 * the driver but are legal VK_TEXTURE_FORMATs.
55 */
56 const SkTArray<StencilFormat, true>& stencilFormats() const {
57 return fStencilFormats;
58 }
59
60 /**
61 * Gets an array of legal stencil formats. These formats are not guaranteed to be supported by
62 * the driver but are legal VK_TEXTURE_FORMATs.
63 */
64 const SkTArray<StencilFormat, true>& linearStencilFormats() const {
65 return fLinearStencilFormats;
66 }
67
68 /**
69 * Returns the max number of sampled textures we can use in a program. This number is the max of
70 * max samplers and max sampled images. This number is technically the max sampled textures we
71 * can have per stage, but we'll use it for the whole program since for now we only do texture
72 * lookups in the fragment shader.
73 */
74 int maxSampledTextures() const {
75 return fMaxSampledTextures;
76 }
77
78
79 GrGLSLCaps* glslCaps() const { return reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get()); }
80
81private:
82 void init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
83 VkPhysicalDevice device);
84 void initSampleCount(const VkPhysicalDeviceProperties& properties);
85 void initGLSLCaps(const GrVkInterface* interface, VkPhysicalDevice physDev);
86 void initConfigRenderableTable(const GrVkInterface* interface, VkPhysicalDevice physDev);
87 void initConfigTexturableTable(const GrVkInterface* interface, VkPhysicalDevice physDev);
88 void initStencilFormats(const GrVkInterface* interface, VkPhysicalDevice physDev);
89
90
91 bool fConfigTextureSupport[kGrPixelConfigCnt];
92 // For Vulkan we track whether a config is supported linearly (without need for swizzling)
93 bool fConfigLinearTextureSupport[kGrPixelConfigCnt];
94
95 // The first entry for each config is without msaa and the second is with.
96 bool fConfigRenderSupport[kGrPixelConfigCnt][2];
97 // The first entry for each config is without msaa and the second is with.
98 bool fConfigLinearRenderSupport[kGrPixelConfigCnt][2];
99
100 SkTArray<StencilFormat, true> fLinearStencilFormats;
101 SkTArray<StencilFormat, true> fStencilFormats;
102
103 int fMaxSampledTextures;
104
105 typedef GrCaps INHERITED;
106};
107
108#endif