2016-07-01 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2016-11-28 16:23:23 +00:00
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
#ifndef SKSL_LAYOUT
|
|
|
|
#define SKSL_LAYOUT
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
#include "include/private/SkSLString.h"
|
2016-11-28 16:23:23 +00:00
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a layout block appearing before a variable declaration, as in:
|
|
|
|
*
|
|
|
|
* layout (location = 0) int x;
|
|
|
|
*/
|
|
|
|
struct Layout {
|
2017-11-27 18:12:30 +00:00
|
|
|
enum Flag {
|
|
|
|
kOriginUpperLeft_Flag = 1 << 0,
|
2021-05-18 18:41:35 +00:00
|
|
|
kPushConstant_Flag = 1 << 1,
|
|
|
|
kBlendSupportAllEquations_Flag = 1 << 2,
|
|
|
|
kSRGBUnpremul_Flag = 1 << 3,
|
2021-02-23 17:54:22 +00:00
|
|
|
|
|
|
|
// These flags indicate if the qualifier appeared, regardless of the accompanying value.
|
2021-07-01 20:41:27 +00:00
|
|
|
kLocation_Flag = 1 << 4,
|
|
|
|
kOffset_Flag = 1 << 5,
|
|
|
|
kBinding_Flag = 1 << 6,
|
|
|
|
kIndex_Flag = 1 << 7,
|
|
|
|
kSet_Flag = 1 << 8,
|
|
|
|
kBuiltin_Flag = 1 << 9,
|
|
|
|
kInputAttachmentIndex_Flag = 1 << 10,
|
|
|
|
kPrimitive_Flag = 1 << 11,
|
|
|
|
kMaxVertices_Flag = 1 << 12,
|
|
|
|
kInvocations_Flag = 1 << 13,
|
2017-11-27 18:12:30 +00:00
|
|
|
};
|
|
|
|
|
2017-02-16 21:37:32 +00:00
|
|
|
enum Primitive {
|
|
|
|
kUnspecified_Primitive = -1,
|
|
|
|
kPoints_Primitive,
|
|
|
|
kLines_Primitive,
|
|
|
|
kLineStrip_Primitive,
|
|
|
|
kLinesAdjacency_Primitive,
|
|
|
|
kTriangles_Primitive,
|
|
|
|
kTriangleStrip_Primitive,
|
|
|
|
kTrianglesAdjacency_Primitive
|
|
|
|
};
|
|
|
|
|
2017-11-27 18:12:30 +00:00
|
|
|
Layout(int flags, int location, int offset, int binding, int index, int set, int builtin,
|
2021-07-01 20:41:27 +00:00
|
|
|
int inputAttachmentIndex, Primitive primitive, int maxVertices, int invocations)
|
2017-11-27 18:12:30 +00:00
|
|
|
: fFlags(flags)
|
|
|
|
, fLocation(location)
|
2016-11-28 21:30:17 +00:00
|
|
|
, fOffset(offset)
|
2016-07-01 15:22:01 +00:00
|
|
|
, fBinding(binding)
|
|
|
|
, fIndex(index)
|
|
|
|
, fSet(set)
|
2016-08-03 19:43:36 +00:00
|
|
|
, fBuiltin(builtin)
|
2016-11-22 14:44:03 +00:00
|
|
|
, fInputAttachmentIndex(inputAttachmentIndex)
|
2017-02-16 21:37:32 +00:00
|
|
|
, fPrimitive(primitive)
|
|
|
|
, fMaxVertices(maxVertices)
|
2021-07-01 20:41:27 +00:00
|
|
|
, fInvocations(invocations) {}
|
2016-11-16 17:06:01 +00:00
|
|
|
|
2016-11-22 14:44:03 +00:00
|
|
|
Layout()
|
2017-11-27 18:12:30 +00:00
|
|
|
: fFlags(0)
|
|
|
|
, fLocation(-1)
|
2016-11-28 21:30:17 +00:00
|
|
|
, fOffset(-1)
|
2016-11-16 17:06:01 +00:00
|
|
|
, fBinding(-1)
|
|
|
|
, fIndex(-1)
|
|
|
|
, fSet(-1)
|
|
|
|
, fBuiltin(-1)
|
2016-11-22 14:44:03 +00:00
|
|
|
, fInputAttachmentIndex(-1)
|
2017-02-16 21:37:32 +00:00
|
|
|
, fPrimitive(kUnspecified_Primitive)
|
|
|
|
, fMaxVertices(-1)
|
2021-07-01 20:41:27 +00:00
|
|
|
, fInvocations(-1) {}
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2020-07-28 18:46:53 +00:00
|
|
|
static Layout builtin(int builtin) {
|
|
|
|
Layout result;
|
|
|
|
result.fBuiltin = builtin;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-03-31 17:56:23 +00:00
|
|
|
String description() const {
|
|
|
|
String result;
|
2020-04-30 21:12:03 +00:00
|
|
|
auto separator = [firstSeparator = true]() mutable -> String {
|
|
|
|
if (firstSeparator) {
|
|
|
|
firstSeparator = false;
|
|
|
|
return "";
|
|
|
|
} else {
|
|
|
|
return ", ";
|
|
|
|
}};
|
2016-07-01 15:22:01 +00:00
|
|
|
if (fLocation >= 0) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "location = " + to_string(fLocation);
|
2016-07-01 15:22:01 +00:00
|
|
|
}
|
2016-11-28 21:30:17 +00:00
|
|
|
if (fOffset >= 0) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "offset = " + to_string(fOffset);
|
2016-11-28 21:30:17 +00:00
|
|
|
}
|
2016-07-01 15:22:01 +00:00
|
|
|
if (fBinding >= 0) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "binding = " + to_string(fBinding);
|
2016-07-01 15:22:01 +00:00
|
|
|
}
|
|
|
|
if (fIndex >= 0) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "index = " + to_string(fIndex);
|
2016-07-01 15:22:01 +00:00
|
|
|
}
|
|
|
|
if (fSet >= 0) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "set = " + to_string(fSet);
|
2016-07-01 15:22:01 +00:00
|
|
|
}
|
|
|
|
if (fBuiltin >= 0) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "builtin = " + to_string(fBuiltin);
|
2016-07-01 15:22:01 +00:00
|
|
|
}
|
2016-11-22 14:44:03 +00:00
|
|
|
if (fInputAttachmentIndex >= 0) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "input_attachment_index = " + to_string(fInputAttachmentIndex);
|
2016-11-22 14:44:03 +00:00
|
|
|
}
|
2017-11-27 18:12:30 +00:00
|
|
|
if (fFlags & kOriginUpperLeft_Flag) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "origin_upper_left";
|
2016-08-03 19:43:36 +00:00
|
|
|
}
|
2017-11-27 18:12:30 +00:00
|
|
|
if (fFlags & kBlendSupportAllEquations_Flag) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "blend_support_all_equations";
|
2016-10-12 13:39:56 +00:00
|
|
|
}
|
2017-11-27 18:12:30 +00:00
|
|
|
if (fFlags & kPushConstant_Flag) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "push_constant";
|
2016-11-22 16:39:36 +00:00
|
|
|
}
|
2020-04-30 21:12:03 +00:00
|
|
|
if (fFlags & kSRGBUnpremul_Flag) {
|
|
|
|
result += separator() + "srgb_unpremul";
|
2018-08-31 14:52:47 +00:00
|
|
|
}
|
2017-02-16 21:37:32 +00:00
|
|
|
switch (fPrimitive) {
|
|
|
|
case kPoints_Primitive:
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "points";
|
2017-02-16 21:37:32 +00:00
|
|
|
break;
|
|
|
|
case kLines_Primitive:
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "lines";
|
2017-02-16 21:37:32 +00:00
|
|
|
break;
|
|
|
|
case kLineStrip_Primitive:
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "line_strip";
|
2017-02-16 21:37:32 +00:00
|
|
|
break;
|
|
|
|
case kLinesAdjacency_Primitive:
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "lines_adjacency";
|
2017-02-16 21:37:32 +00:00
|
|
|
break;
|
|
|
|
case kTriangles_Primitive:
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "triangles";
|
2017-02-16 21:37:32 +00:00
|
|
|
break;
|
|
|
|
case kTriangleStrip_Primitive:
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "triangle_strip";
|
2017-02-16 21:37:32 +00:00
|
|
|
break;
|
|
|
|
case kTrianglesAdjacency_Primitive:
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "triangles_adjacency";
|
2017-02-16 21:37:32 +00:00
|
|
|
break;
|
|
|
|
case kUnspecified_Primitive:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fMaxVertices >= 0) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "max_vertices = " + to_string(fMaxVertices);
|
2017-02-16 21:37:32 +00:00
|
|
|
}
|
|
|
|
if (fInvocations >= 0) {
|
2020-04-30 21:12:03 +00:00
|
|
|
result += separator() + "invocations = " + to_string(fInvocations);
|
2017-02-16 21:37:32 +00:00
|
|
|
}
|
2016-11-21 15:39:35 +00:00
|
|
|
if (result.size() > 0) {
|
2016-07-01 15:22:01 +00:00
|
|
|
result = "layout (" + result + ")";
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const Layout& other) const {
|
2017-11-27 18:12:30 +00:00
|
|
|
return fFlags == other.fFlags &&
|
|
|
|
fLocation == other.fLocation &&
|
|
|
|
fOffset == other.fOffset &&
|
|
|
|
fBinding == other.fBinding &&
|
|
|
|
fIndex == other.fIndex &&
|
|
|
|
fSet == other.fSet &&
|
|
|
|
fBuiltin == other.fBuiltin &&
|
|
|
|
fInputAttachmentIndex == other.fInputAttachmentIndex &&
|
|
|
|
fPrimitive == other.fPrimitive &&
|
|
|
|
fMaxVertices == other.fMaxVertices &&
|
2021-07-01 20:41:27 +00:00
|
|
|
fInvocations == other.fInvocations;
|
2016-07-01 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const Layout& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2017-11-27 18:12:30 +00:00
|
|
|
int fFlags;
|
2016-08-03 19:43:36 +00:00
|
|
|
int fLocation;
|
2016-11-28 21:30:17 +00:00
|
|
|
int fOffset;
|
2016-08-03 19:43:36 +00:00
|
|
|
int fBinding;
|
|
|
|
int fIndex;
|
|
|
|
int fSet;
|
2016-11-22 14:44:03 +00:00
|
|
|
// builtin comes from SPIR-V and identifies which particular builtin value this object
|
|
|
|
// represents.
|
2016-08-03 19:43:36 +00:00
|
|
|
int fBuiltin;
|
2016-11-22 14:44:03 +00:00
|
|
|
// input_attachment_index comes from Vulkan/SPIR-V to connect a shader variable to the a
|
|
|
|
// corresponding attachment on the subpass in which the shader is being used.
|
|
|
|
int fInputAttachmentIndex;
|
2017-02-16 21:37:32 +00:00
|
|
|
Primitive fPrimitive;
|
|
|
|
int fMaxVertices;
|
|
|
|
int fInvocations;
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace SkSL
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
#endif
|