aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk/GrVkCaps.h
blob: 5834b151fdef20d93da394d6991eb98dce0c2193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrVkCaps_DEFINED
#define GrVkCaps_DEFINED

#include "GrCaps.h"
#include "GrVkStencilAttachment.h"
#include "vk/GrVkDefines.h"

struct GrVkInterface;
class GrGLSLCaps;

/**
 * Stores some capabilities of a Vk backend.
 */
class GrVkCaps : public GrCaps {
public:
    typedef GrVkStencilAttachment::Format StencilFormat;

    /**
     * Creates a GrVkCaps that is set such that nothing is supported. The init function should
     * be called to fill out the caps.
     */
    GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
             VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags);

    bool isConfigTexturable(GrPixelConfig config) const override {
        SkASSERT(kGrPixelConfigCnt > config);
        return fConfigTextureSupport[config];
    }

    bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override {
        SkASSERT(kGrPixelConfigCnt > config);
        return fConfigRenderSupport[config][withMSAA];
    }

    bool isConfigRenderableLinearly(GrPixelConfig config, bool withMSAA) const {
        SkASSERT(kGrPixelConfigCnt > config);
        return fConfigLinearRenderSupport[config][withMSAA];
    }

    bool isConfigTexurableLinearly(GrPixelConfig config) const {
        SkASSERT(kGrPixelConfigCnt > config);
        return fConfigLinearTextureSupport[config];
    }

    bool canUseGLSLForShaderModule() const {
        return fCanUseGLSLForShaderModule;
    }

    /**
     * Gets an array of legal stencil formats. These formats are not guaranteed to be supported by
     * the driver but are legal VK_TEXTURE_FORMATs.
     */
    const SkTArray<StencilFormat, true>& stencilFormats() const {
        return fStencilFormats;
    }

    /**
     * Gets an array of legal stencil formats. These formats are not guaranteed to be supported by
     * the driver but are legal VK_TEXTURE_FORMATs.
     */
    const SkTArray<StencilFormat, true>& linearStencilFormats() const {
        return fLinearStencilFormats;
    }

    GrGLSLCaps* glslCaps() const { return reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get()); }

private:
    void init(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
              VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags);
    void initGrCaps(const VkPhysicalDeviceProperties&,
                    const VkPhysicalDeviceMemoryProperties&,
                    uint32_t featureFlags);
    void initGLSLCaps(const VkPhysicalDeviceProperties&, uint32_t featureFlags);
    void initSampleCount(const VkPhysicalDeviceProperties& properties);
    void initConfigRenderableTable(const GrVkInterface* iface, VkPhysicalDevice physDev);
    void initConfigTexturableTable(const GrVkInterface* iface, VkPhysicalDevice physDev);
    void initStencilFormats(const GrVkInterface* iface, VkPhysicalDevice physDev);


    bool fConfigTextureSupport[kGrPixelConfigCnt];
    // For Vulkan we track whether a config is supported linearly (without need for swizzling)
    bool fConfigLinearTextureSupport[kGrPixelConfigCnt];

    // The first entry for each config is without msaa and the second is with.
    bool fConfigRenderSupport[kGrPixelConfigCnt][2];
    // The first entry for each config is without msaa and the second is with.
    bool fConfigLinearRenderSupport[kGrPixelConfigCnt][2];

    SkTArray<StencilFormat, true> fLinearStencilFormats;
    SkTArray<StencilFormat, true> fStencilFormats;

    // Tells of if we can pass in straight GLSL string into vkCreateShaderModule
    bool fCanUseGLSLForShaderModule;

    typedef GrCaps INHERITED;
};

#endif