1/* 2 * Copyright 2018 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#include "GrMtlVaryingHandler.h" 9 10static void finalize_helper(GrMtlVaryingHandler::VarArray& vars) { 11 int locationIndex; 12 for (locationIndex = 0; locationIndex < vars.count(); locationIndex++) { 13 GrShaderVar& var = vars[locationIndex]; 14 // Metal only allows scalars (including bool and char) and vectors as varyings 15 SkASSERT(GrSLTypeVecLength(var.getType()) != -1); 16 17 SkString location; 18 location.appendf("location = %d", locationIndex); 19 var.addLayoutQualifier(location.c_str()); 20 } 21 // The max number of inputs is 60 for iOS and 32 for macOS. The max number of components is 60 22 // for iOS and 128 for macOS. To be conservative, we are going to assert that we have less than 23 // 15 varyings because in the worst case scenario, they are all vec4s (15 * 4 = 60). If we hit 24 // this assert, we can implement a function in GrMtlCaps to be less conservative. 25 SkASSERT(locationIndex <= 15); 26} 27 28void GrMtlVaryingHandler::onFinalize() { 29 finalize_helper(fVertexInputs); 30 finalize_helper(fVertexOutputs); 31 finalize_helper(fGeomInputs); 32 finalize_helper(fGeomOutputs); 33 finalize_helper(fFragInputs); 34 finalize_helper(fFragOutputs); 35} 36