2 * Copyright 2018 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "src/gpu/ganesh/mtl/GrMtlVaryingHandler.h"
10 #include "include/private/gpu/ganesh/GrMtlTypesPriv.h"
12 #if !__has_feature(objc_arc)
13 #error This file must be compiled with Arc. Use -fobjc-arc flag
18 static void finalize_helper(GrMtlVaryingHandler::VarArray& vars) {
19 int locationIndex = 0;
21 SkDEBUGCODE(int componentCount = 0);
22 for (GrShaderVar& var : vars.items()) {
23 // Metal only allows scalars (including bool and char) and vectors as varyings
24 SkASSERT(SkSLTypeVecLength(var.getType()) != -1);
25 SkDEBUGCODE(componentCount += SkSLTypeVecLength(var.getType()));
28 location.appendf("location = %d", locationIndex);
29 var.addLayoutQualifier(location.c_str());
32 // The max number of inputs is 60 for iOS and 32 for macOS. The max number of components is 60
33 // for iOS and 128 for macOS. To be conservative, we are going to assert that we have less than
34 // 32 varyings and less than 60 components across all varyings. If we hit this assert, we can
35 // implement a function in GrMtlCaps to be less conservative.
36 SkASSERT(locationIndex <= 32);
37 SkASSERT(componentCount <= 60);
40 void GrMtlVaryingHandler::onFinalize() {
41 finalize_helper(fVertexInputs);
42 finalize_helper(fVertexOutputs);
43 finalize_helper(fFragInputs);
44 finalize_helper(fFragOutputs);