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