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 "src/gpu/mtl/GrMtlVaryingHandler.h" 9 10#if !__has_feature(objc_arc) 11#error This file must be compiled with Arc. Use -fobjc-arc flag 12#endif 13 14static void finalize_helper(GrMtlVaryingHandler::VarArray& vars) { 15 int locationIndex; 16 int componentCount = 0; 17 for (locationIndex = 0; locationIndex < vars.count(); locationIndex++) { 18 GrShaderVar& var = vars[locationIndex]; 19 // Metal only allows scalars (including bool and char) and vectors as varyings 20 SkASSERT(GrSLTypeVecLength(var.getType()) != -1); 21 componentCount += GrSLTypeVecLength(var.getType()); 22 23 SkString location; 24 location.appendf("location = %d", locationIndex); 25 var.addLayoutQualifier(location.c_str()); 26 } 27 // The max number of inputs is 60 for iOS and 32 for macOS. The max number of components is 60 28 // for iOS and 128 for macOS. To be conservative, we are going to assert that we have less than 29 // 32 varyings and less than 60 components across all varyings. If we hit this assert, we can 30 // implement a function in GrMtlCaps to be less conservative. 31 SkASSERT(locationIndex <= 32); 32 SkASSERT(componentCount <= 60); 33} 34 35void GrMtlVaryingHandler::onFinalize() { 36 finalize_helper(fVertexInputs); 37 finalize_helper(fVertexOutputs); 38 finalize_helper(fGeomInputs); 39 finalize_helper(fGeomOutputs); 40 finalize_helper(fFragInputs); 41 finalize_helper(fFragOutputs); 42} 43