Flutter Engine
The Flutter Engine
Functions
GrSPIRVVaryingHandler.cpp File Reference
#include "src/gpu/ganesh/GrSPIRVVaryingHandler.h"

Go to the source code of this file.

Functions

static int sksltype_to_location_size (SkSLType type)
 
static void finalize_helper (GrSPIRVVaryingHandler::VarArray &vars)
 

Function Documentation

◆ finalize_helper()

static void finalize_helper ( GrSPIRVVaryingHandler::VarArray vars)
static

Definition at line 82 of file GrSPIRVVaryingHandler.cpp.

82 {
83 int locationIndex = 0;
84 for (GrShaderVar& var : vars.items()) {
85 SkString location;
86 location.appendf("location = %d", locationIndex);
87 var.addLayoutQualifier(location.c_str());
88
89 int elementSize = sksltype_to_location_size(var.getType());
90 SkASSERT(elementSize > 0);
91 int numElements = var.isArray() ? var.getArrayCount() : 1;
92 SkASSERT(numElements > 0);
93 locationIndex += elementSize * numElements;
94 }
95 // TODO: determine the layout limits for SPIR-V, and enforce them via asserts here.
96}
static int sksltype_to_location_size(SkSLType type)
#define SkASSERT(cond)
Definition: SkAssert.h:116
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
Definition: __init__.py:1

◆ sksltype_to_location_size()

static int sksltype_to_location_size ( SkSLType  type)
inlinestatic

Returns the number of locations take up by a given SkSLType. We assume that all scalar values are 32 bits.

Definition at line 12 of file GrSPIRVVaryingHandler.cpp.

12 {
13 // If a new GrSL type is added, this function will need to be updated.
14 static_assert(kSkSLTypeCount == 41);
15
16 switch(type) {
17 case SkSLType::kVoid:
18 return 0;
19 case SkSLType::kFloat: // fall through
20 case SkSLType::kHalf:
21 return 1;
22 case SkSLType::kFloat2: // fall through
24 return 1;
27 return 1;
30 return 1;
31 case SkSLType::kInt2:
35 return 1;
36 case SkSLType::kInt3:
40 return 1;
41 case SkSLType::kInt4:
45 return 1;
48 return 2;
51 return 3;
54 return 4;
56 return 0;
58 return 0;
60 return 0;
61 case SkSLType::kBool:
65 return 1;
66 case SkSLType::kInt: // fall through
68 return 1;
69 case SkSLType::kUInt: // fall through
71 return 1;
73 return 0;
75 return 0;
77 return 0;
78 }
79 SK_ABORT("Unexpected type");
80}
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
static const int kSkSLTypeCount
@ kTextureExternalSampler
@ kTexture2DSampler
@ kTexture2DRectSampler
GLenum type