ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/sksl/SkSLUtil.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 9 | |
Brian Osman | 3000d6b | 2020-07-31 15:57:28 -0400 | [diff] [blame] | 10 | #include "src/sksl/SkSLContext.h" |
Mike Klein | 4b432fa | 2019-06-06 11:44:05 -0500 | [diff] [blame] | 11 | #include "src/sksl/SkSLStringStream.h" |
John Stiles | 54e7c05 | 2021-01-11 14:22:36 -0500 | [diff] [blame] | 12 | #include "src/sksl/ir/SkSLType.h" |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 13 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 14 | #ifndef __STDC_FORMAT_MACROS |
| 15 | #define __STDC_FORMAT_MACROS |
| 16 | #endif |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 17 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 18 | namespace SkSL { |
| 19 | |
Brian Osman | fb32ddf | 2019-06-18 10:14:20 -0400 | [diff] [blame] | 20 | #if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 21 | StandaloneShaderCaps standaloneCaps; |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 22 | |
| 23 | ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() { |
| 24 | return std::make_shared<StandaloneShaderCaps>(); |
| 25 | } |
| 26 | #else |
| 27 | ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() { |
| 28 | return sk_make_sp<GrShaderCaps>(GrContextOptions()); |
| 29 | } |
| 30 | #endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 31 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 32 | void write_stringstream(const StringStream& s, OutputStream& out) { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 33 | out.write(s.str().c_str(), s.str().size()); |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Brian Osman | 3000d6b | 2020-07-31 15:57:28 -0400 | [diff] [blame] | 36 | #if !defined(SKSL_STANDALONE) |
| 37 | bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType) { |
John Stiles | abef5ef | 2021-01-19 22:57:39 -0500 | [diff] [blame] | 38 | // If a new GrSL type is added, this function will need to be updated. |
John Stiles | 9fc9b87 | 2021-02-01 15:50:32 -0500 | [diff] [blame] | 39 | static_assert(kGrSLTypeCount == 49); |
John Stiles | abef5ef | 2021-01-19 22:57:39 -0500 | [diff] [blame] | 40 | |
| 41 | if (type == *context.fTypes.fVoid ) { *outType = kVoid_GrSLType; return true; } |
| 42 | if (type == *context.fTypes.fBool ) { *outType = kBool_GrSLType; return true; } |
John Stiles | 9fc9b87 | 2021-02-01 15:50:32 -0500 | [diff] [blame] | 43 | if (type == *context.fTypes.fBool2 ) { *outType = kBool2_GrSLType; return true; } |
| 44 | if (type == *context.fTypes.fBool3 ) { *outType = kBool3_GrSLType; return true; } |
| 45 | if (type == *context.fTypes.fBool4 ) { *outType = kBool4_GrSLType; return true; } |
John Stiles | abef5ef | 2021-01-19 22:57:39 -0500 | [diff] [blame] | 46 | if (type == *context.fTypes.fShort ) { *outType = kShort_GrSLType; return true; } |
| 47 | if (type == *context.fTypes.fShort2 ) { *outType = kShort2_GrSLType; return true; } |
| 48 | if (type == *context.fTypes.fShort3 ) { *outType = kShort3_GrSLType; return true; } |
| 49 | if (type == *context.fTypes.fShort4 ) { *outType = kShort4_GrSLType; return true; } |
| 50 | if (type == *context.fTypes.fUShort ) { *outType = kUShort_GrSLType; return true; } |
| 51 | if (type == *context.fTypes.fUShort2 ) { *outType = kUShort2_GrSLType; return true; } |
| 52 | if (type == *context.fTypes.fUShort3 ) { *outType = kUShort3_GrSLType; return true; } |
| 53 | if (type == *context.fTypes.fUShort4 ) { *outType = kUShort4_GrSLType; return true; } |
| 54 | if (type == *context.fTypes.fFloat ) { *outType = kFloat_GrSLType; return true; } |
| 55 | if (type == *context.fTypes.fFloat2 ) { *outType = kFloat2_GrSLType; return true; } |
| 56 | if (type == *context.fTypes.fFloat3 ) { *outType = kFloat3_GrSLType; return true; } |
| 57 | if (type == *context.fTypes.fFloat4 ) { *outType = kFloat4_GrSLType; return true; } |
John Stiles | 54e7c05 | 2021-01-11 14:22:36 -0500 | [diff] [blame] | 58 | if (type == *context.fTypes.fFloat2x2) { *outType = kFloat2x2_GrSLType; return true; } |
John Stiles | 54e7c05 | 2021-01-11 14:22:36 -0500 | [diff] [blame] | 59 | if (type == *context.fTypes.fFloat3x3) { *outType = kFloat3x3_GrSLType; return true; } |
John Stiles | 54e7c05 | 2021-01-11 14:22:36 -0500 | [diff] [blame] | 60 | if (type == *context.fTypes.fFloat4x4) { *outType = kFloat4x4_GrSLType; return true; } |
John Stiles | abef5ef | 2021-01-19 22:57:39 -0500 | [diff] [blame] | 61 | if (type == *context.fTypes.fHalf ) { *outType = kHalf_GrSLType; return true; } |
| 62 | if (type == *context.fTypes.fHalf2 ) { *outType = kHalf2_GrSLType; return true; } |
| 63 | if (type == *context.fTypes.fHalf3 ) { *outType = kHalf3_GrSLType; return true; } |
| 64 | if (type == *context.fTypes.fHalf4 ) { *outType = kHalf4_GrSLType; return true; } |
| 65 | if (type == *context.fTypes.fHalf2x2 ) { *outType = kHalf2x2_GrSLType; return true; } |
| 66 | if (type == *context.fTypes.fHalf3x3 ) { *outType = kHalf3x3_GrSLType; return true; } |
| 67 | if (type == *context.fTypes.fHalf4x4 ) { *outType = kHalf4x4_GrSLType; return true; } |
| 68 | if (type == *context.fTypes.fInt ) { *outType = kInt_GrSLType; return true; } |
| 69 | if (type == *context.fTypes.fInt2 ) { *outType = kInt2_GrSLType; return true; } |
| 70 | if (type == *context.fTypes.fInt3 ) { *outType = kInt3_GrSLType; return true; } |
| 71 | if (type == *context.fTypes.fInt4 ) { *outType = kInt4_GrSLType; return true; } |
| 72 | if (type == *context.fTypes.fUInt ) { *outType = kUint_GrSLType; return true; } |
| 73 | if (type == *context.fTypes.fUInt2 ) { *outType = kUint2_GrSLType; return true; } |
| 74 | if (type == *context.fTypes.fUInt3 ) { *outType = kUint3_GrSLType; return true; } |
| 75 | if (type == *context.fTypes.fUInt4 ) { *outType = kUint4_GrSLType; return true; } |
Brian Osman | 3000d6b | 2020-07-31 15:57:28 -0400 | [diff] [blame] | 76 | return false; |
| 77 | } |
| 78 | #endif |
| 79 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 80 | } // namespace SkSL |