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 <string> 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 kColor_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 kTexture_Flag = 1 << 7, 32 kSampler_Flag = 1 << 8, 33 kIndex_Flag = 1 << 9, 34 kSet_Flag = 1 << 10, 35 kBuiltin_Flag = 1 << 11, 36 kInputAttachmentIndex_Flag = 1 << 12, 37 38 // These flags indicate the backend type; only one at most can be set. 39 kSPIRV_Flag = 1 << 13, 40 kMetal_Flag = 1 << 14, 41 kGL_Flag = 1 << 15, 42 kWGSL_Flag = 1 << 16, 43 }; 44 45 static constexpr int kAllBackendFlagsMask = 46 Layout::kSPIRV_Flag | Layout::kMetal_Flag | Layout::kGL_Flag | Layout::kWGSL_Flag; 47 LayoutLayout48 Layout(int flags, int location, int offset, int binding, int index, int set, int builtin, 49 int inputAttachmentIndex) 50 : fFlags(flags) 51 , fLocation(location) 52 , fOffset(offset) 53 , fBinding(binding) 54 , fIndex(index) 55 , fSet(set) 56 , fBuiltin(builtin) 57 , fInputAttachmentIndex(inputAttachmentIndex) {} 58 59 Layout() = default; 60 builtinLayout61 static Layout builtin(int builtin) { 62 Layout result; 63 result.fBuiltin = builtin; 64 return result; 65 } 66 67 std::string description() const; 68 69 bool operator==(const Layout& other) const; 70 71 bool operator!=(const Layout& other) const { 72 return !(*this == other); 73 } 74 75 int fFlags = 0; 76 int fLocation = -1; 77 int fOffset = -1; 78 int fBinding = -1; 79 int fTexture = -1; 80 int fSampler = -1; 81 int fIndex = -1; 82 int fSet = -1; 83 // builtin comes from SPIR-V and identifies which particular builtin value this object 84 // represents. 85 int fBuiltin = -1; 86 // input_attachment_index comes from Vulkan/SPIR-V to connect a shader variable to the a 87 // corresponding attachment on the subpass in which the shader is being used. 88 int fInputAttachmentIndex = -1; 89 }; 90 91 } // namespace SkSL 92 93 #endif 94