blob: 6f7ccccd603807f58295e7915420bc24254b8656 [file] [log] [blame]
Brian Salomon99938a82016-11-21 13:41:08 -05001/*
2 * Copyright 2016 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "src/gpu/GrShaderCaps.h"
10#include "src/gpu/GrShaderVar.h"
Brian Salomon99938a82016-11-21 13:41:08 -050011
Brian Salomonf9f45122016-11-29 11:59:17 -050012static const char* type_modifier_string(GrShaderVar::TypeModifier t) {
13 switch (t) {
14 case GrShaderVar::kNone_TypeModifier: return "";
15 case GrShaderVar::kIn_TypeModifier: return "in";
16 case GrShaderVar::kInOut_TypeModifier: return "inout";
17 case GrShaderVar::kOut_TypeModifier: return "out";
18 case GrShaderVar::kUniform_TypeModifier: return "uniform";
19 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040020 SK_ABORT("Unknown shader variable type modifier.");
Brian Salomonf9f45122016-11-29 11:59:17 -050021}
22
Brian Salomonf9f45122016-11-29 11:59:17 -050023void GrShaderVar::setIOType(GrIOType ioType) {
24 switch (ioType) {
25 case kRW_GrIOType:
26 return;
27 case kRead_GrIOType:
28 this->addModifier("readonly");
29 return;
30 case kWrite_GrIOType:
31 this->addModifier("writeonly");
32 return;
33 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040034 SK_ABORT("Unknown io type.");
Brian Salomonf9f45122016-11-29 11:59:17 -050035}
36
Brian Salomon1edc5b92016-11-29 13:43:46 -050037void GrShaderVar::appendDecl(const GrShaderCaps* shaderCaps, SkString* out) const {
Brian Salomonf9f45122016-11-29 11:59:17 -050038 SkString layout = fLayoutQualifier;
Brian Salomon99938a82016-11-21 13:41:08 -050039 if (!fLayoutQualifier.isEmpty()) {
40 out->appendf("layout(%s) ", fLayoutQualifier.c_str());
41 }
42 out->append(fExtraModifiers);
43 if (this->getTypeModifier() != kNone_TypeModifier) {
Brian Salomonf9f45122016-11-29 11:59:17 -050044 out->append(type_modifier_string(this->getTypeModifier()));
Brian Salomon99938a82016-11-21 13:41:08 -050045 out->append(" ");
46 }
47 GrSLType effectiveType = this->getType();
Brian Salomon99938a82016-11-21 13:41:08 -050048 if (this->isArray()) {
49 if (this->isUnsizedArray()) {
Chris Dalton4f5cbcd2019-02-13 14:04:34 -070050 out->appendf("%s %s[]", GrGLSLTypeString(effectiveType), this->getName().c_str());
Brian Salomon99938a82016-11-21 13:41:08 -050051 } else {
52 SkASSERT(this->getArrayCount() > 0);
53 out->appendf("%s %s[%d]",
Chris Dalton4f5cbcd2019-02-13 14:04:34 -070054 GrGLSLTypeString(effectiveType),
Brian Salomon99938a82016-11-21 13:41:08 -050055 this->getName().c_str(),
56 this->getArrayCount());
57 }
58 } else {
Chris Dalton4f5cbcd2019-02-13 14:04:34 -070059 out->appendf("%s %s", GrGLSLTypeString(effectiveType), this->getName().c_str());
Brian Salomon99938a82016-11-21 13:41:08 -050060 }
61}