Coverage Report

Created: 2021-08-22 09:07

/src/skia/include/private/SkSLLayout.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2016 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 SKSL_LAYOUT
9
#define SKSL_LAYOUT
10
11
#include "include/private/SkSLString.h"
12
13
namespace SkSL {
14
15
/**
16
 * Represents a layout block appearing before a variable declaration, as in:
17
 *
18
 * layout (location = 0) int x;
19
 */
20
struct Layout {
21
    enum Flag {
22
        kOriginUpperLeft_Flag            = 1 <<  0,
23
        kPushConstant_Flag               = 1 <<  1,
24
        kBlendSupportAllEquations_Flag   = 1 <<  2,
25
        kSRGBUnpremul_Flag               = 1 <<  3,
26
27
        // These flags indicate if the qualifier appeared, regardless of the accompanying value.
28
        kLocation_Flag                   = 1 <<  4,
29
        kOffset_Flag                     = 1 <<  5,
30
        kBinding_Flag                    = 1 <<  6,
31
        kIndex_Flag                      = 1 <<  7,
32
        kSet_Flag                        = 1 <<  8,
33
        kBuiltin_Flag                    = 1 <<  9,
34
        kInputAttachmentIndex_Flag       = 1 << 10,
35
        kPrimitive_Flag                  = 1 << 11,
36
        kMaxVertices_Flag                = 1 << 12,
37
        kInvocations_Flag                = 1 << 13,
38
    };
39
40
    enum Primitive {
41
        kUnspecified_Primitive = -1,
42
        kPoints_Primitive,
43
        kLines_Primitive,
44
        kLineStrip_Primitive,
45
        kLinesAdjacency_Primitive,
46
        kTriangles_Primitive,
47
        kTriangleStrip_Primitive,
48
        kTrianglesAdjacency_Primitive
49
    };
50
51
    Layout(int flags, int location, int offset, int binding, int index, int set, int builtin,
52
           int inputAttachmentIndex, Primitive primitive, int maxVertices, int invocations)
53
    : fFlags(flags)
54
    , fLocation(location)
55
    , fOffset(offset)
56
    , fBinding(binding)
57
    , fIndex(index)
58
    , fSet(set)
59
    , fBuiltin(builtin)
60
    , fInputAttachmentIndex(inputAttachmentIndex)
61
    , fPrimitive(primitive)
62
    , fMaxVertices(maxVertices)
63
652k
    , fInvocations(invocations) {}
64
65
    Layout()
66
    : fFlags(0)
67
    , fLocation(-1)
68
    , fOffset(-1)
69
    , fBinding(-1)
70
    , fIndex(-1)
71
    , fSet(-1)
72
    , fBuiltin(-1)
73
    , fInputAttachmentIndex(-1)
74
    , fPrimitive(kUnspecified_Primitive)
75
    , fMaxVertices(-1)
76
32.6M
    , fInvocations(-1) {}
77
78
0
    static Layout builtin(int builtin) {
79
0
        Layout result;
80
0
        result.fBuiltin = builtin;
81
0
        return result;
82
0
    }
83
84
26.1k
    String description() const {
85
26.1k
        String result;
86
5.72k
        auto separator = [firstSeparator = true]() mutable -> String {
87
5.72k
            if (firstSeparator) {
88
4.81k
                firstSeparator = false;
89
4.81k
                return "";
90
909
            } else {
91
909
                return ", ";
92
909
            }};
93
26.1k
        if (fLocation >= 0) {
94
0
            result += separator() + "location = " + to_string(fLocation);
95
0
        }
96
26.1k
        if (fOffset >= 0) {
97
2.75k
            result += separator() + "offset = " + to_string(fOffset);
98
2.75k
        }
99
26.1k
        if (fBinding >= 0) {
100
584
            result += separator() + "binding = " + to_string(fBinding);
101
584
        }
102
26.1k
        if (fIndex >= 0) {
103
128
            result += separator() + "index = " + to_string(fIndex);
104
128
        }
105
26.1k
        if (fSet >= 0) {
106
2.10k
            result += separator() + "set = " + to_string(fSet);
107
2.10k
        }
108
26.1k
        if (fBuiltin >= 0) {
109
0
            result += separator() + "builtin = " + to_string(fBuiltin);
110
0
        }
111
26.1k
        if (fInputAttachmentIndex >= 0) {
112
0
            result += separator() + "input_attachment_index = " + to_string(fInputAttachmentIndex);
113
0
        }
114
26.1k
        if (fFlags & kOriginUpperLeft_Flag) {
115
0
            result += separator() + "origin_upper_left";
116
0
        }
117
26.1k
        if (fFlags & kBlendSupportAllEquations_Flag) {
118
156
            result += separator() + "blend_support_all_equations";
119
156
        }
120
26.1k
        if (fFlags & kPushConstant_Flag) {
121
0
            result += separator() + "push_constant";
122
0
        }
123
26.1k
        if (fFlags & kSRGBUnpremul_Flag) {
124
0
            result += separator() + "srgb_unpremul";
125
0
        }
126
26.1k
        switch (fPrimitive) {
127
0
            case kPoints_Primitive:
128
0
                result += separator() + "points";
129
0
                break;
130
0
            case kLines_Primitive:
131
0
                result += separator() + "lines";
132
0
                break;
133
0
            case kLineStrip_Primitive:
134
0
                result += separator() + "line_strip";
135
0
                break;
136
0
            case kLinesAdjacency_Primitive:
137
0
                result += separator() + "lines_adjacency";
138
0
                break;
139
0
            case kTriangles_Primitive:
140
0
                result += separator() + "triangles";
141
0
                break;
142
0
            case kTriangleStrip_Primitive:
143
0
                result += separator() + "triangle_strip";
144
0
                break;
145
0
            case kTrianglesAdjacency_Primitive:
146
0
                result += separator() + "triangles_adjacency";
147
0
                break;
148
26.1k
            case kUnspecified_Primitive:
149
26.1k
                break;
150
26.1k
        }
151
26.1k
        if (fMaxVertices >= 0) {
152
0
            result += separator() + "max_vertices = " + to_string(fMaxVertices);
153
0
        }
154
26.1k
        if (fInvocations >= 0) {
155
0
            result += separator() + "invocations = " + to_string(fInvocations);
156
0
        }
157
26.1k
        if (result.size() > 0) {
158
4.81k
            result = "layout (" + result + ")";
159
4.81k
        }
160
26.1k
        return result;
161
26.1k
    }
162
163
42.0M
    bool operator==(const Layout& other) const {
164
42.0M
        return fFlags                == other.fFlags &&
165
41.9M
               fLocation             == other.fLocation &&
166
41.9M
               fOffset               == other.fOffset &&
167
41.9M
               fBinding              == other.fBinding &&
168
41.9M
               fIndex                == other.fIndex &&
169
41.9M
               fSet                  == other.fSet &&
170
41.9M
               fBuiltin              == other.fBuiltin &&
171
41.8M
               fInputAttachmentIndex == other.fInputAttachmentIndex &&
172
41.8M
               fPrimitive            == other.fPrimitive &&
173
41.8M
               fMaxVertices          == other.fMaxVertices &&
174
41.8M
               fInvocations          == other.fInvocations;
175
42.0M
    }
176
177
0
    bool operator!=(const Layout& other) const {
178
0
        return !(*this == other);
179
0
    }
180
181
    int fFlags;
182
    int fLocation;
183
    int fOffset;
184
    int fBinding;
185
    int fIndex;
186
    int fSet;
187
    // builtin comes from SPIR-V and identifies which particular builtin value this object
188
    // represents.
189
    int fBuiltin;
190
    // input_attachment_index comes from Vulkan/SPIR-V to connect a shader variable to the a
191
    // corresponding attachment on the subpass in which the shader is being used.
192
    int fInputAttachmentIndex;
193
    Primitive fPrimitive;
194
    int fMaxVertices;
195
    int fInvocations;
196
};
197
198
}  // namespace SkSL
199
200
#endif