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 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(GrSLTypeVecLength(var.getType()) != -1); 25 SkDEBUGCODE(componentCount += GrSLTypeVecLength(var.getType())); 26 27 SkString location; 28 location.appendf("location = %d", locationIndex); 29 var.addLayoutQualifier(location.c_str()); 30 ++locationIndex; 31 } 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); 38} 39 40void GrMtlVaryingHandler::onFinalize() { 41 finalize_helper(fVertexInputs); 42 finalize_helper(fVertexOutputs); 43 finalize_helper(fFragInputs); 44 finalize_helper(fFragOutputs); 45} 46 47GR_NORETAIN_END 48