Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 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 | |
Ethan Nicholas | 24c1772 | 2021-03-09 13:10:59 -0500 | [diff] [blame] | 8 | #include "include/private/SkSLIRNode.h" |
Ethan Nicholas | daed259 | 2021-03-04 14:30:25 -0500 | [diff] [blame] | 9 | #include "include/sksl/DSL.h" |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrDirectContextPriv.h" |
| 11 | #include "src/gpu/GrGpu.h" |
| 12 | #include "src/sksl/SkSLIRGenerator.h" |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 13 | #include "src/sksl/dsl/priv/DSLWriter.h" |
| 14 | |
| 15 | #include "tests/Test.h" |
| 16 | |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 17 | #include <limits> |
| 18 | |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 19 | using namespace SkSL::dsl; |
| 20 | |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 21 | SkSL::ProgramSettings default_settings() { |
| 22 | SkSL::ProgramSettings result; |
| 23 | result.fDSLMarkVarsDeclared = true; |
| 24 | result.fDSLMangling = false; |
| 25 | return result; |
| 26 | } |
| 27 | |
| 28 | SkSL::ProgramSettings no_mark_vars_declared() { |
| 29 | SkSL::ProgramSettings result = default_settings(); |
| 30 | result.fDSLMarkVarsDeclared = false; |
| 31 | return result; |
| 32 | } |
Ethan Nicholas | 22dcb73 | 2021-05-12 11:26:58 -0400 | [diff] [blame] | 33 | |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 34 | /** |
| 35 | * In addition to issuing an automatic Start() and End(), disables mangling and optionally |
| 36 | * auto-declares variables during its lifetime. Variable auto-declaration simplifies testing so we |
| 37 | * don't have to sprinkle all the tests with a bunch of Declare(foo).release() calls just to avoid |
| 38 | * errors, especially given that some of the variables have options that make them an error to |
| 39 | * actually declare. |
| 40 | */ |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 41 | class AutoDSLContext { |
| 42 | public: |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 43 | AutoDSLContext(GrGpu* gpu, SkSL::ProgramSettings settings = default_settings(), |
Ethan Nicholas | ee49efc | 2021-04-09 15:33:53 -0400 | [diff] [blame] | 44 | SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 45 | Start(gpu->shaderCompiler(), kind, settings); |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | ~AutoDSLContext() { |
| 49 | End(); |
| 50 | } |
| 51 | }; |
| 52 | |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 53 | class ExpectError : public SkSL::ErrorReporter { |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 54 | public: |
| 55 | ExpectError(skiatest::Reporter* reporter, const char* msg) |
| 56 | : fMsg(msg) |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 57 | , fReporter(reporter) |
| 58 | , fOldReporter(&GetErrorReporter()) { |
| 59 | SetErrorReporter(this); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | ~ExpectError() override { |
John Stiles | 642cde2 | 2021-02-23 14:57:01 -0500 | [diff] [blame] | 63 | REPORTER_ASSERT(fReporter, !fMsg, |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 64 | "Error mismatch: expected:\n%s\nbut no error occurred\n", fMsg); |
| 65 | SetErrorReporter(fOldReporter); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 66 | } |
| 67 | |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 68 | void handleError(const char* msg, SkSL::PositionInfo pos) override { |
| 69 | REPORTER_ASSERT(fReporter, fMsg, "Received unexpected extra error: %s\n", msg); |
| 70 | REPORTER_ASSERT(fReporter, !fMsg || !strcmp(msg, fMsg), |
| 71 | "Error mismatch: expected:\n%s\nbut received:\n%s", fMsg, msg); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 72 | fMsg = nullptr; |
| 73 | } |
| 74 | |
| 75 | private: |
| 76 | const char* fMsg; |
| 77 | skiatest::Reporter* fReporter; |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 78 | ErrorReporter* fOldReporter; |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 79 | }; |
| 80 | |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 81 | static bool whitespace_insensitive_compare(const char* a, const char* b) { |
| 82 | for (;;) { |
| 83 | while (isspace(*a)) { |
| 84 | ++a; |
| 85 | } |
| 86 | while (isspace(*b)) { |
| 87 | ++b; |
| 88 | } |
| 89 | if (*a != *b) { |
| 90 | return false; |
| 91 | } |
| 92 | if (*a == 0) { |
| 93 | return true; |
| 94 | } |
| 95 | ++a; |
| 96 | ++b; |
| 97 | } |
| 98 | } |
| 99 | |
Ethan Nicholas | 24c1772 | 2021-03-09 13:10:59 -0500 | [diff] [blame] | 100 | // for use from SkSLDSLOnlyTest.cpp |
| 101 | void StartDSL(const sk_gpu_test::ContextInfo ctxInfo) { |
| 102 | Start(ctxInfo.directContext()->priv().getGpu()->shaderCompiler()); |
| 103 | } |
| 104 | |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 105 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLStartup, r, ctxInfo) { |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 106 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 107 | Expression e1 = 1; |
| 108 | REPORTER_ASSERT(r, e1.release()->description() == "1"); |
| 109 | Expression e2 = 1.0; |
| 110 | REPORTER_ASSERT(r, e2.release()->description() == "1.0"); |
| 111 | Expression e3 = true; |
| 112 | REPORTER_ASSERT(r, e3.release()->description() == "true"); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 113 | Var a(kInt_Type, "a"); |
Ethan Nicholas | bffe80a | 2021-01-11 15:42:44 -0500 | [diff] [blame] | 114 | Expression e4 = a; |
| 115 | REPORTER_ASSERT(r, e4.release()->description() == "a"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 116 | |
| 117 | REPORTER_ASSERT(r, whitespace_insensitive_compare("", "")); |
| 118 | REPORTER_ASSERT(r, !whitespace_insensitive_compare("", "a")); |
| 119 | REPORTER_ASSERT(r, !whitespace_insensitive_compare("a", "")); |
| 120 | REPORTER_ASSERT(r, whitespace_insensitive_compare("a", "a")); |
| 121 | REPORTER_ASSERT(r, whitespace_insensitive_compare("abc", "abc")); |
| 122 | REPORTER_ASSERT(r, whitespace_insensitive_compare("abc", " abc ")); |
| 123 | REPORTER_ASSERT(r, whitespace_insensitive_compare("a b c ", "\n\n\nabc")); |
| 124 | REPORTER_ASSERT(r, !whitespace_insensitive_compare("a b c d", "\n\n\nabc")); |
Ethan Nicholas | 9504614 | 2021-01-07 10:57:27 -0500 | [diff] [blame] | 125 | } |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 126 | |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 127 | static SkSL::String stringize(DSLStatement& stmt) { return stmt.release()->description(); } |
| 128 | static SkSL::String stringize(DSLPossibleStatement& stmt) { return stmt.release()->description(); } |
| 129 | static SkSL::String stringize(DSLExpression& expr) { return expr.release()->description(); } |
| 130 | static SkSL::String stringize(DSLPossibleExpression& expr) { return expr.release()->description(); } |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 131 | static SkSL::String stringize(DSLBlock& blck) { return blck.release()->description(); } |
Ethan Nicholas | 292a09d | 2021-07-14 09:52:16 -0400 | [diff] [blame] | 132 | static SkSL::String stringize(SkSL::IRNode& node) { return node.description(); } |
| 133 | static SkSL::String stringize(SkSL::Program& program) { return program.description(); } |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 134 | |
| 135 | template <typename T> |
| 136 | static void expect_equal(skiatest::Reporter* r, int lineNumber, T& input, const char* expected) { |
| 137 | SkSL::String actual = stringize(input); |
| 138 | if (!whitespace_insensitive_compare(expected, actual.c_str())) { |
| 139 | ERRORF(r, "(Failed on line %d)\nExpected: %s\n Actual: %s\n", |
| 140 | lineNumber, expected, actual.c_str()); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | template <typename T> |
| 145 | static void expect_equal(skiatest::Reporter* r, int lineNumber, T&& dsl, const char* expected) { |
| 146 | // This overload allows temporary values to be passed to expect_equal. |
| 147 | return expect_equal(r, lineNumber, dsl, expected); |
| 148 | } |
| 149 | |
| 150 | #define EXPECT_EQUAL(a, b) expect_equal(r, __LINE__, (a), (b)) |
| 151 | |
Ethan Nicholas | 22dcb73 | 2021-05-12 11:26:58 -0400 | [diff] [blame] | 152 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLFlags, r, ctxInfo) { |
| 153 | { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 154 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | 22dcb73 | 2021-05-12 11:26:58 -0400 | [diff] [blame] | 155 | EXPECT_EQUAL(All(GreaterThan(Float4(1), Float4(0))), "true"); |
| 156 | |
| 157 | Var x(kInt_Type, "x"); |
| 158 | EXPECT_EQUAL(Declare(x), "int x;"); |
| 159 | } |
| 160 | |
| 161 | { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 162 | SkSL::ProgramSettings settings; |
| 163 | settings.fOptimize = false; |
| 164 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), settings, |
Brian Osman | 8c26479 | 2021-07-01 16:41:27 -0400 | [diff] [blame] | 165 | SkSL::ProgramKind::kFragment); |
Ethan Nicholas | 22dcb73 | 2021-05-12 11:26:58 -0400 | [diff] [blame] | 166 | EXPECT_EQUAL(All(GreaterThan(Float4(1), Float4(0))), |
| 167 | "all(greaterThan(float4(1.0), float4(0.0)))"); |
| 168 | } |
| 169 | |
| 170 | { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 171 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), SkSL::ProgramSettings()); |
Ethan Nicholas | 22dcb73 | 2021-05-12 11:26:58 -0400 | [diff] [blame] | 172 | Var x(kInt_Type, "x"); |
| 173 | EXPECT_EQUAL(Declare(x), "int _0_x;"); |
| 174 | } |
| 175 | } |
| 176 | |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 177 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLFloat, r, ctxInfo) { |
| 178 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 179 | Expression e1 = Float(std::numeric_limits<float>::max()); |
| 180 | REPORTER_ASSERT(r, atof(e1.release()->description().c_str()) == |
| 181 | std::numeric_limits<float>::max()); |
| 182 | |
| 183 | Expression e2 = Float(std::numeric_limits<float>::min()); |
| 184 | REPORTER_ASSERT(r, atof(e2.release()->description().c_str()) == |
| 185 | std::numeric_limits<float>::min()); |
| 186 | |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 187 | EXPECT_EQUAL(Float2(0), |
| 188 | "float2(0.0)"); |
| 189 | EXPECT_EQUAL(Float2(-0.5, 1), |
| 190 | "float2(-0.5, 1.0)"); |
| 191 | EXPECT_EQUAL(Float3(0.75), |
| 192 | "float3(0.75)"); |
| 193 | EXPECT_EQUAL(Float3(Float2(0, 1), -2), |
John Stiles | b9e4f64 | 2021-03-05 09:11:38 -0500 | [diff] [blame] | 194 | "float3(0.0, 1.0, -2.0)"); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 195 | EXPECT_EQUAL(Float3(0, 1, 2), |
| 196 | "float3(0.0, 1.0, 2.0)"); |
| 197 | EXPECT_EQUAL(Float4(0), |
| 198 | "float4(0.0)"); |
| 199 | EXPECT_EQUAL(Float4(Float2(0, 1), Float2(2, 3)), |
John Stiles | b9e4f64 | 2021-03-05 09:11:38 -0500 | [diff] [blame] | 200 | "float4(0.0, 1.0, 2.0, 3.0)"); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 201 | EXPECT_EQUAL(Float4(0, 1, Float2(2, 3)), |
John Stiles | b9e4f64 | 2021-03-05 09:11:38 -0500 | [diff] [blame] | 202 | "float4(0.0, 1.0, 2.0, 3.0)"); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 203 | EXPECT_EQUAL(Float4(0, 1, 2, 3), |
| 204 | "float4(0.0, 1.0, 2.0, 3.0)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 205 | |
Ethan Nicholas | a60cc3e | 2021-04-23 16:15:11 -0400 | [diff] [blame] | 206 | DSLVar x(kFloat_Type, "x"); |
| 207 | EXPECT_EQUAL(x = 1.0, "(x = 1.0)"); |
| 208 | EXPECT_EQUAL(x = 1.0f, "(x = 1.0)"); |
| 209 | |
| 210 | DSLVar y(kFloat2_Type, "y"); |
| 211 | EXPECT_EQUAL(y.x() = 1.0, "(y.x = 1.0)"); |
| 212 | EXPECT_EQUAL(y.x() = 1.0f, "(y.x = 1.0)"); |
| 213 | |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 214 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 215 | ExpectError error(r, "floating point value is infinite"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 216 | Float(std::numeric_limits<float>::infinity()).release(); |
| 217 | } |
| 218 | |
| 219 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 220 | ExpectError error(r, "floating point value is NaN"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 221 | Float(std::numeric_limits<float>::quiet_NaN()).release(); |
| 222 | } |
| 223 | |
| 224 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 225 | ExpectError error(r, "'float4' is not a valid parameter to 'float2' constructor; use '.xy' " |
| 226 | "instead"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 227 | Float2(Float4(1)).release(); |
| 228 | } |
| 229 | |
| 230 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 231 | ExpectError error(r, "invalid arguments to 'float4' constructor (expected 4 scalars, but " |
| 232 | "found 3)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 233 | Float4(Float3(1)).release(); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLHalf, r, ctxInfo) { |
| 238 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 239 | Expression e1 = Half(std::numeric_limits<float>::max()); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 240 | REPORTER_ASSERT(r, |
| 241 | atof(e1.release()->description().c_str()) == std::numeric_limits<float>::max()); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 242 | |
| 243 | Expression e2 = Half(std::numeric_limits<float>::min()); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 244 | REPORTER_ASSERT(r, |
| 245 | atof(e2.release()->description().c_str()) == std::numeric_limits<float>::min()); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 246 | |
John Stiles | b9e4f64 | 2021-03-05 09:11:38 -0500 | [diff] [blame] | 247 | EXPECT_EQUAL(Half2(0), |
| 248 | "half2(0.0)"); |
| 249 | EXPECT_EQUAL(Half2(-0.5, 1), |
| 250 | "half2(-0.5, 1.0)"); |
| 251 | EXPECT_EQUAL(Half3(0.75), |
| 252 | "half3(0.75)"); |
| 253 | EXPECT_EQUAL(Half3(Half2(0, 1), -2), |
| 254 | "half3(0.0, 1.0, -2.0)"); |
| 255 | EXPECT_EQUAL(Half3(0, 1, 2), |
| 256 | "half3(0.0, 1.0, 2.0)"); |
| 257 | EXPECT_EQUAL(Half4(0), |
| 258 | "half4(0.0)"); |
| 259 | EXPECT_EQUAL(Half4(Half2(0, 1), Half2(2, 3)), |
| 260 | "half4(0.0, 1.0, 2.0, 3.0)"); |
| 261 | EXPECT_EQUAL(Half4(0, 1, Half2(2, 3)), |
| 262 | "half4(0.0, 1.0, 2.0, 3.0)"); |
| 263 | EXPECT_EQUAL(Half4(0, 1, 2, 3), |
| 264 | "half4(0.0, 1.0, 2.0, 3.0)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 265 | |
| 266 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 267 | ExpectError error(r, "floating point value is infinite"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 268 | Half(std::numeric_limits<float>::infinity()).release(); |
| 269 | } |
| 270 | |
| 271 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 272 | ExpectError error(r, "floating point value is NaN"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 273 | Half(std::numeric_limits<float>::quiet_NaN()).release(); |
| 274 | } |
| 275 | |
| 276 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 277 | ExpectError error(r, "'half4' is not a valid parameter to 'half2' constructor; use '.xy' " |
| 278 | "instead"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 279 | Half2(Half4(1)).release(); |
| 280 | } |
| 281 | |
| 282 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 283 | ExpectError error(r, "invalid arguments to 'half4' constructor (expected 4 scalars, but " |
| 284 | "found 3)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 285 | Half4(Half3(1)).release(); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLInt, r, ctxInfo) { |
| 290 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 291 | |
John Stiles | b9e4f64 | 2021-03-05 09:11:38 -0500 | [diff] [blame] | 292 | EXPECT_EQUAL(Int(std::numeric_limits<int32_t>::max()), |
| 293 | "2147483647"); |
| 294 | EXPECT_EQUAL(Int2(std::numeric_limits<int32_t>::min()), |
| 295 | "int2(-2147483648)"); |
| 296 | EXPECT_EQUAL(Int2(0, 1), |
| 297 | "int2(0, 1)"); |
| 298 | EXPECT_EQUAL(Int3(0), |
| 299 | "int3(0)"); |
| 300 | EXPECT_EQUAL(Int3(Int2(0, 1), -2), |
| 301 | "int3(0, 1, -2)"); |
| 302 | EXPECT_EQUAL(Int3(0, 1, 2), |
| 303 | "int3(0, 1, 2)"); |
| 304 | EXPECT_EQUAL(Int4(0), |
| 305 | "int4(0)"); |
| 306 | EXPECT_EQUAL(Int4(Int2(0, 1), Int2(2, 3)), |
| 307 | "int4(0, 1, 2, 3)"); |
| 308 | EXPECT_EQUAL(Int4(0, 1, Int2(2, 3)), |
| 309 | "int4(0, 1, 2, 3)"); |
| 310 | EXPECT_EQUAL(Int4(0, 1, 2, 3), |
| 311 | "int4(0, 1, 2, 3)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 312 | |
| 313 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 314 | ExpectError error(r, "'int4' is not a valid parameter to 'int2' constructor; use '.xy' " |
| 315 | "instead"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 316 | Int2(Int4(1)).release(); |
| 317 | } |
| 318 | |
| 319 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 320 | ExpectError error(r, "invalid arguments to 'int4' constructor (expected 4 scalars, but " |
| 321 | "found 3)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 322 | Int4(Int3(1)).release(); |
| 323 | } |
| 324 | } |
| 325 | |
Ethan Nicholas | b83199e | 2021-05-03 14:25:35 -0400 | [diff] [blame] | 326 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLUInt, r, ctxInfo) { |
| 327 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 328 | |
| 329 | EXPECT_EQUAL(UInt(std::numeric_limits<uint32_t>::max()), |
| 330 | "4294967295"); |
| 331 | EXPECT_EQUAL(UInt2(std::numeric_limits<uint32_t>::min()), |
| 332 | "uint2(0)"); |
| 333 | EXPECT_EQUAL(UInt2(0, 1), |
| 334 | "uint2(0, 1)"); |
| 335 | EXPECT_EQUAL(UInt3(0), |
| 336 | "uint3(0)"); |
| 337 | EXPECT_EQUAL(UInt3(UInt2(0, 1), -2), |
| 338 | "uint3(0, 1, -2)"); |
| 339 | EXPECT_EQUAL(UInt3(0, 1, 2), |
| 340 | "uint3(0, 1, 2)"); |
| 341 | EXPECT_EQUAL(UInt4(0), |
| 342 | "uint4(0)"); |
| 343 | EXPECT_EQUAL(UInt4(UInt2(0, 1), UInt2(2, 3)), |
| 344 | "uint4(0, 1, 2, 3)"); |
| 345 | EXPECT_EQUAL(UInt4(0, 1, UInt2(2, 3)), |
| 346 | "uint4(0, 1, 2, 3)"); |
| 347 | EXPECT_EQUAL(UInt4(0, 1, 2, 3), |
| 348 | "uint4(0, 1, 2, 3)"); |
| 349 | |
| 350 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 351 | ExpectError error(r, "'uint4' is not a valid parameter to 'uint2' constructor; use '.xy' " |
| 352 | "instead"); |
Ethan Nicholas | b83199e | 2021-05-03 14:25:35 -0400 | [diff] [blame] | 353 | UInt2(UInt4(1)).release(); |
| 354 | } |
| 355 | |
| 356 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 357 | ExpectError error(r, "invalid arguments to 'uint4' constructor (expected 4 scalars, but " |
| 358 | "found 3)"); |
Ethan Nicholas | b83199e | 2021-05-03 14:25:35 -0400 | [diff] [blame] | 359 | UInt4(UInt3(1)).release(); |
| 360 | } |
| 361 | } |
| 362 | |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 363 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLShort, r, ctxInfo) { |
| 364 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 365 | |
John Stiles | b9e4f64 | 2021-03-05 09:11:38 -0500 | [diff] [blame] | 366 | EXPECT_EQUAL(Short(std::numeric_limits<int16_t>::max()), |
| 367 | "32767"); |
| 368 | EXPECT_EQUAL(Short2(std::numeric_limits<int16_t>::min()), |
| 369 | "short2(-32768)"); |
| 370 | EXPECT_EQUAL(Short2(0, 1), |
| 371 | "short2(0, 1)"); |
| 372 | EXPECT_EQUAL(Short3(0), |
| 373 | "short3(0)"); |
| 374 | EXPECT_EQUAL(Short3(Short2(0, 1), -2), |
| 375 | "short3(0, 1, -2)"); |
| 376 | EXPECT_EQUAL(Short3(0, 1, 2), |
| 377 | "short3(0, 1, 2)"); |
| 378 | EXPECT_EQUAL(Short4(0), |
| 379 | "short4(0)"); |
| 380 | EXPECT_EQUAL(Short4(Short2(0, 1), Short2(2, 3)), |
| 381 | "short4(0, 1, 2, 3)"); |
| 382 | EXPECT_EQUAL(Short4(0, 1, Short2(2, 3)), |
| 383 | "short4(0, 1, 2, 3)"); |
| 384 | EXPECT_EQUAL(Short4(0, 1, 2, 3), |
| 385 | "short4(0, 1, 2, 3)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 386 | |
| 387 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 388 | ExpectError error(r, "'short4' is not a valid parameter to 'short2' constructor; use '.xy' " |
| 389 | "instead"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 390 | Short2(Short4(1)).release(); |
| 391 | } |
| 392 | |
| 393 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 394 | ExpectError error(r, "invalid arguments to 'short4' constructor (expected 4 scalars, but " |
| 395 | "found 3)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 396 | Short4(Short3(1)).release(); |
| 397 | } |
| 398 | } |
| 399 | |
Ethan Nicholas | b83199e | 2021-05-03 14:25:35 -0400 | [diff] [blame] | 400 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLUShort, r, ctxInfo) { |
| 401 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 402 | |
| 403 | EXPECT_EQUAL(UShort(std::numeric_limits<uint16_t>::max()), |
| 404 | "65535"); |
| 405 | EXPECT_EQUAL(UShort2(std::numeric_limits<uint16_t>::min()), |
| 406 | "ushort2(0)"); |
| 407 | EXPECT_EQUAL(UShort2(0, 1), |
| 408 | "ushort2(0, 1)"); |
| 409 | EXPECT_EQUAL(UShort3(0), |
| 410 | "ushort3(0)"); |
| 411 | EXPECT_EQUAL(UShort3(UShort2(0, 1), -2), |
| 412 | "ushort3(0, 1, -2)"); |
| 413 | EXPECT_EQUAL(UShort3(0, 1, 2), |
| 414 | "ushort3(0, 1, 2)"); |
| 415 | EXPECT_EQUAL(UShort4(0), |
| 416 | "ushort4(0)"); |
| 417 | EXPECT_EQUAL(UShort4(UShort2(0, 1), UShort2(2, 3)), |
| 418 | "ushort4(0, 1, 2, 3)"); |
| 419 | EXPECT_EQUAL(UShort4(0, 1, UShort2(2, 3)), |
| 420 | "ushort4(0, 1, 2, 3)"); |
| 421 | EXPECT_EQUAL(UShort4(0, 1, 2, 3), |
| 422 | "ushort4(0, 1, 2, 3)"); |
| 423 | |
| 424 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 425 | ExpectError error(r, "'ushort4' is not a valid parameter to 'ushort2' constructor; use " |
| 426 | "'.xy' instead"); |
Ethan Nicholas | b83199e | 2021-05-03 14:25:35 -0400 | [diff] [blame] | 427 | UShort2(UShort4(1)).release(); |
| 428 | } |
| 429 | |
| 430 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 431 | ExpectError error(r, "invalid arguments to 'ushort4' constructor (expected 4 scalars, but " |
| 432 | "found 3)"); |
Ethan Nicholas | b83199e | 2021-05-03 14:25:35 -0400 | [diff] [blame] | 433 | UShort4(UShort3(1)).release(); |
| 434 | } |
| 435 | } |
| 436 | |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 437 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBool, r, ctxInfo) { |
| 438 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 439 | |
John Stiles | b9e4f64 | 2021-03-05 09:11:38 -0500 | [diff] [blame] | 440 | EXPECT_EQUAL(Bool2(false), |
| 441 | "bool2(false)"); |
| 442 | EXPECT_EQUAL(Bool2(false, true), |
| 443 | "bool2(false, true)"); |
| 444 | EXPECT_EQUAL(Bool3(false), |
| 445 | "bool3(false)"); |
| 446 | EXPECT_EQUAL(Bool3(Bool2(false, true), false), |
| 447 | "bool3(false, true, false)"); |
| 448 | EXPECT_EQUAL(Bool3(false, true, false), |
| 449 | "bool3(false, true, false)"); |
| 450 | EXPECT_EQUAL(Bool4(false), |
| 451 | "bool4(false)"); |
| 452 | EXPECT_EQUAL(Bool4(Bool2(false, true), Bool2(false, true)), |
| 453 | "bool4(false, true, false, true)"); |
| 454 | EXPECT_EQUAL(Bool4(false, true, Bool2(false, true)), |
| 455 | "bool4(false, true, false, true)"); |
| 456 | EXPECT_EQUAL(Bool4(false, true, false, true), |
| 457 | "bool4(false, true, false, true)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 458 | |
| 459 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 460 | ExpectError error(r, "'bool4' is not a valid parameter to 'bool2' constructor; use '.xy' " |
| 461 | "instead"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 462 | Bool2(Bool4(true)).release(); |
| 463 | } |
| 464 | |
| 465 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 466 | ExpectError error(r, "invalid arguments to 'bool4' constructor (expected 4 scalars, but " |
| 467 | "found 3)"); |
Ethan Nicholas | b3d4e74 | 2021-01-08 11:42:25 -0500 | [diff] [blame] | 468 | Bool4(Bool3(true)).release(); |
| 469 | } |
| 470 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 471 | |
Ethan Nicholas | b83199e | 2021-05-03 14:25:35 -0400 | [diff] [blame] | 472 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLType, r, ctxInfo) { |
| 473 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 474 | REPORTER_ASSERT(r, DSLType(kBool_Type).isBoolean()); |
| 475 | REPORTER_ASSERT(r, !DSLType(kBool_Type).isNumber()); |
| 476 | REPORTER_ASSERT(r, !DSLType(kBool_Type).isFloat()); |
| 477 | REPORTER_ASSERT(r, !DSLType(kBool_Type).isSigned()); |
| 478 | REPORTER_ASSERT(r, !DSLType(kBool_Type).isUnsigned()); |
| 479 | REPORTER_ASSERT(r, !DSLType(kBool_Type).isInteger()); |
| 480 | REPORTER_ASSERT(r, DSLType(kBool_Type).isScalar()); |
| 481 | REPORTER_ASSERT(r, !DSLType(kBool_Type).isVector()); |
| 482 | REPORTER_ASSERT(r, !DSLType(kBool_Type).isMatrix()); |
| 483 | REPORTER_ASSERT(r, !DSLType(kBool_Type).isArray()); |
| 484 | REPORTER_ASSERT(r, !DSLType(kBool_Type).isStruct()); |
| 485 | |
| 486 | REPORTER_ASSERT(r, !DSLType(kInt_Type).isBoolean()); |
| 487 | REPORTER_ASSERT(r, DSLType(kInt_Type).isNumber()); |
| 488 | REPORTER_ASSERT(r, !DSLType(kInt_Type).isFloat()); |
| 489 | REPORTER_ASSERT(r, DSLType(kInt_Type).isSigned()); |
| 490 | REPORTER_ASSERT(r, !DSLType(kInt_Type).isUnsigned()); |
| 491 | REPORTER_ASSERT(r, DSLType(kInt_Type).isInteger()); |
| 492 | REPORTER_ASSERT(r, DSLType(kInt_Type).isScalar()); |
| 493 | REPORTER_ASSERT(r, !DSLType(kInt_Type).isVector()); |
| 494 | REPORTER_ASSERT(r, !DSLType(kInt_Type).isMatrix()); |
| 495 | REPORTER_ASSERT(r, !DSLType(kInt_Type).isArray()); |
| 496 | REPORTER_ASSERT(r, !DSLType(kInt_Type).isStruct()); |
| 497 | |
| 498 | REPORTER_ASSERT(r, !DSLType(kUInt_Type).isBoolean()); |
| 499 | REPORTER_ASSERT(r, DSLType(kUInt_Type).isNumber()); |
| 500 | REPORTER_ASSERT(r, !DSLType(kUInt_Type).isFloat()); |
| 501 | REPORTER_ASSERT(r, !DSLType(kUInt_Type).isSigned()); |
| 502 | REPORTER_ASSERT(r, DSLType(kUInt_Type).isUnsigned()); |
| 503 | REPORTER_ASSERT(r, DSLType(kUInt_Type).isInteger()); |
| 504 | REPORTER_ASSERT(r, DSLType(kUInt_Type).isScalar()); |
| 505 | REPORTER_ASSERT(r, !DSLType(kUInt_Type).isVector()); |
| 506 | REPORTER_ASSERT(r, !DSLType(kUInt_Type).isMatrix()); |
| 507 | REPORTER_ASSERT(r, !DSLType(kUInt_Type).isArray()); |
| 508 | REPORTER_ASSERT(r, !DSLType(kUInt_Type).isStruct()); |
| 509 | |
| 510 | REPORTER_ASSERT(r, !DSLType(kFloat_Type).isBoolean()); |
| 511 | REPORTER_ASSERT(r, DSLType(kFloat_Type).isNumber()); |
| 512 | REPORTER_ASSERT(r, DSLType(kFloat_Type).isFloat()); |
| 513 | REPORTER_ASSERT(r, !DSLType(kFloat_Type).isSigned()); |
| 514 | REPORTER_ASSERT(r, !DSLType(kFloat_Type).isUnsigned()); |
| 515 | REPORTER_ASSERT(r, !DSLType(kFloat_Type).isInteger()); |
| 516 | REPORTER_ASSERT(r, DSLType(kFloat_Type).isScalar()); |
| 517 | REPORTER_ASSERT(r, !DSLType(kFloat_Type).isVector()); |
| 518 | REPORTER_ASSERT(r, !DSLType(kFloat_Type).isMatrix()); |
| 519 | REPORTER_ASSERT(r, !DSLType(kFloat_Type).isArray()); |
| 520 | REPORTER_ASSERT(r, !DSLType(kFloat_Type).isStruct()); |
| 521 | |
| 522 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isBoolean()); |
| 523 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isNumber()); |
| 524 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isFloat()); |
| 525 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isSigned()); |
| 526 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isUnsigned()); |
| 527 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isInteger()); |
| 528 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isScalar()); |
| 529 | REPORTER_ASSERT(r, DSLType(kFloat2_Type).isVector()); |
| 530 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isMatrix()); |
| 531 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isArray()); |
| 532 | REPORTER_ASSERT(r, !DSLType(kFloat2_Type).isStruct()); |
| 533 | |
| 534 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isBoolean()); |
| 535 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isNumber()); |
| 536 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isFloat()); |
| 537 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isSigned()); |
| 538 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isUnsigned()); |
| 539 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isInteger()); |
| 540 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isScalar()); |
| 541 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isVector()); |
| 542 | REPORTER_ASSERT(r, DSLType(kHalf2x2_Type).isMatrix()); |
| 543 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isArray()); |
| 544 | REPORTER_ASSERT(r, !DSLType(kHalf2x2_Type).isStruct()); |
| 545 | |
| 546 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isBoolean()); |
| 547 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isNumber()); |
| 548 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isFloat()); |
| 549 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isSigned()); |
| 550 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isUnsigned()); |
| 551 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isInteger()); |
| 552 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isScalar()); |
| 553 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isVector()); |
| 554 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isMatrix()); |
| 555 | REPORTER_ASSERT(r, DSLType(Array(kFloat_Type, 2)).isArray()); |
| 556 | REPORTER_ASSERT(r, !DSLType(Array(kFloat_Type, 2)).isStruct()); |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 557 | |
| 558 | Var x(kFloat_Type); |
| 559 | DSLExpression e = x + 1; |
| 560 | REPORTER_ASSERT(r, e.type().isFloat()); |
| 561 | e.release(); |
Ethan Nicholas | ed6e54f | 2021-07-19 13:33:47 -0400 | [diff] [blame] | 562 | |
| 563 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 564 | ExpectError error(r, "array size must be positive"); |
Ethan Nicholas | ed6e54f | 2021-07-19 13:33:47 -0400 | [diff] [blame] | 565 | Array(kFloat_Type, -1); |
| 566 | } |
| 567 | |
| 568 | { |
Ethan Nicholas | 6f20b8d | 2021-08-31 07:40:24 -0400 | [diff] [blame] | 569 | ExpectError error(r, "multi-dimensional arrays are not supported"); |
Ethan Nicholas | ed6e54f | 2021-07-19 13:33:47 -0400 | [diff] [blame] | 570 | Array(Array(kFloat_Type, 2), 2); |
| 571 | } |
Ethan Nicholas | b83199e | 2021-05-03 14:25:35 -0400 | [diff] [blame] | 572 | } |
| 573 | |
Ethan Nicholas | 8455893 | 2021-04-12 16:56:37 -0400 | [diff] [blame] | 574 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLMatrices, r, ctxInfo) { |
| 575 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 576 | Var f22(kFloat2x2_Type, "f22"); |
| 577 | EXPECT_EQUAL(f22 = Float2x2(1), "(f22 = float2x2(1.0))"); |
| 578 | Var f32(kFloat3x2_Type, "f32"); |
| 579 | EXPECT_EQUAL(f32 = Float3x2(1, 2, 3, 4, 5, 6), |
| 580 | "(f32 = float3x2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0))"); |
| 581 | Var f42(kFloat4x2_Type, "f42"); |
| 582 | EXPECT_EQUAL(f42 = Float4x2(Float4(1, 2, 3, 4), 5, 6, 7, 8), |
| 583 | "(f42 = float4x2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0))"); |
| 584 | Var f23(kFloat2x3_Type, "f23"); |
| 585 | EXPECT_EQUAL(f23 = Float2x3(1, Float2(2, 3), 4, Float2(5, 6)), |
| 586 | "(f23 = float2x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0))"); |
| 587 | Var f33(kFloat3x3_Type, "f33"); |
| 588 | EXPECT_EQUAL(f33 = Float3x3(Float3(1, 2, 3), 4, Float2(5, 6), 7, 8, 9), |
| 589 | "(f33 = float3x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))"); |
| 590 | Var f43(kFloat4x3_Type, "f43"); |
| 591 | EXPECT_EQUAL(f43 = Float4x3(Float4(1, 2, 3, 4), Float4(5, 6, 7, 8), Float4(9, 10, 11, 12)), |
| 592 | "(f43 = float4x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0))"); |
| 593 | Var f24(kFloat2x4_Type, "f24"); |
| 594 | EXPECT_EQUAL(f24 = Float2x4(1, 2, 3, 4, 5, 6, 7, 8), |
| 595 | "(f24 = float2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0))"); |
| 596 | Var f34(kFloat3x4_Type, "f34"); |
| 597 | EXPECT_EQUAL(f34 = Float3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, Float3(10, 11, 12)), |
| 598 | "(f34 = float3x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0))"); |
| 599 | Var f44(kFloat4x4_Type, "f44"); |
| 600 | EXPECT_EQUAL(f44 = Float4x4(1), "(f44 = float4x4(1.0))"); |
| 601 | |
| 602 | Var h22(kHalf2x2_Type, "h22"); |
| 603 | EXPECT_EQUAL(h22 = Half2x2(1), "(h22 = half2x2(1.0))"); |
| 604 | Var h32(kHalf3x2_Type, "h32"); |
| 605 | EXPECT_EQUAL(h32 = Half3x2(1, 2, 3, 4, 5, 6), |
| 606 | "(h32 = half3x2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0))"); |
| 607 | Var h42(kHalf4x2_Type, "h42"); |
| 608 | EXPECT_EQUAL(h42 = Half4x2(Half4(1, 2, 3, 4), 5, 6, 7, 8), |
| 609 | "(h42 = half4x2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0))"); |
| 610 | Var h23(kHalf2x3_Type, "h23"); |
| 611 | EXPECT_EQUAL(h23 = Half2x3(1, Half2(2, 3), 4, Half2(5, 6)), |
| 612 | "(h23 = half2x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0))"); |
| 613 | Var h33(kHalf3x3_Type, "h33"); |
| 614 | EXPECT_EQUAL(h33 = Half3x3(Half3(1, 2, 3), 4, Half2(5, 6), 7, 8, 9), |
| 615 | "(h33 = half3x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))"); |
| 616 | Var h43(kHalf4x3_Type, "h43"); |
| 617 | EXPECT_EQUAL(h43 = Half4x3(Half4(1, 2, 3, 4), Half4(5, 6, 7, 8), Half4(9, 10, 11, 12)), |
| 618 | "(h43 = half4x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0))"); |
| 619 | Var h24(kHalf2x4_Type, "h24"); |
| 620 | EXPECT_EQUAL(h24 = Half2x4(1, 2, 3, 4, 5, 6, 7, 8), |
| 621 | "(h24 = half2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0))"); |
| 622 | Var h34(kHalf3x4_Type, "h34"); |
| 623 | EXPECT_EQUAL(h34 = Half3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, Half3(10, 11, 12)), |
| 624 | "(h34 = half3x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0))"); |
| 625 | Var h44(kHalf4x4_Type, "h44"); |
| 626 | EXPECT_EQUAL(h44 = Half4x4(1), "(h44 = half4x4(1.0))"); |
| 627 | |
| 628 | EXPECT_EQUAL(f22 * 2, "(f22 * 2.0)"); |
| 629 | EXPECT_EQUAL(f22 == Float2x2(1), "(f22 == float2x2(1.0))"); |
| 630 | EXPECT_EQUAL(h42[0][1], "h42[0].y"); |
| 631 | EXPECT_EQUAL(f43 * Float4(0), "(f43 * float4(0.0))"); |
| 632 | EXPECT_EQUAL(h23 * 2, "(h23 * 2.0)"); |
| 633 | EXPECT_EQUAL(Inverse(f44), "inverse(f44)"); |
| 634 | |
| 635 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 636 | ExpectError error(r, "invalid arguments to 'float3x3' constructor (expected 9 scalars, but " |
| 637 | "found 2)"); |
Ethan Nicholas | 8455893 | 2021-04-12 16:56:37 -0400 | [diff] [blame] | 638 | DSLExpression(Float3x3(Float2(1))).release(); |
| 639 | } |
| 640 | |
| 641 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 642 | ExpectError error(r, "invalid arguments to 'half2x2' constructor (expected 4 scalars, but " |
| 643 | "found 5)"); |
Ethan Nicholas | 8455893 | 2021-04-12 16:56:37 -0400 | [diff] [blame] | 644 | DSLExpression(Half2x2(1, 2, 3, 4, 5)).release(); |
| 645 | } |
| 646 | |
| 647 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 648 | ExpectError error(r, "type mismatch: '*' cannot operate on 'float4x3', 'float3'"); |
Ethan Nicholas | 8455893 | 2021-04-12 16:56:37 -0400 | [diff] [blame] | 649 | DSLExpression(f43 * Float3(1)).release(); |
| 650 | } |
| 651 | |
| 652 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 653 | ExpectError error(r, "type mismatch: '=' cannot operate on 'float4x3', 'float3x3'"); |
Ethan Nicholas | 8455893 | 2021-04-12 16:56:37 -0400 | [diff] [blame] | 654 | DSLExpression(f43 = f33).release(); |
| 655 | } |
| 656 | |
| 657 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 658 | ExpectError error(r, "type mismatch: '=' cannot operate on 'half2x2', 'float2x2'"); |
Ethan Nicholas | 8455893 | 2021-04-12 16:56:37 -0400 | [diff] [blame] | 659 | DSLExpression(h22 = f22).release(); |
| 660 | } |
| 661 | |
| 662 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 663 | ExpectError error(r, "no match for inverse(float4x3)"); |
Ethan Nicholas | 8455893 | 2021-04-12 16:56:37 -0400 | [diff] [blame] | 664 | DSLExpression(Inverse(f43)).release(); |
| 665 | } |
| 666 | } |
| 667 | |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 668 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLPlus, r, ctxInfo) { |
| 669 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 670 | Var a(kFloat_Type, "a"), b(kFloat_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 671 | |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 672 | EXPECT_EQUAL(a + b, |
| 673 | "(a + b)"); |
| 674 | EXPECT_EQUAL(a + 1, |
| 675 | "(a + 1.0)"); |
| 676 | EXPECT_EQUAL(0.5 + a + -99, |
| 677 | "((0.5 + a) + -99.0)"); |
| 678 | EXPECT_EQUAL(a += b + 1, |
| 679 | "(a += (b + 1.0))"); |
Ethan Nicholas | b14b636 | 2021-03-08 17:07:58 -0500 | [diff] [blame] | 680 | EXPECT_EQUAL(+a, |
| 681 | "a"); |
| 682 | EXPECT_EQUAL(+(a + b), |
| 683 | "(a + b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 684 | |
| 685 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 686 | ExpectError error(r, "type mismatch: '+' cannot operate on 'bool2', 'float'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 687 | DSLExpression((Bool2(true) + a)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 691 | ExpectError error(r, "type mismatch: '+=' cannot operate on 'float', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 692 | DSLExpression((a += Bool2(true))).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 696 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 697 | DSLExpression((1.0 += a)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 698 | } |
Ethan Nicholas | b14b636 | 2021-03-08 17:07:58 -0500 | [diff] [blame] | 699 | |
| 700 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 701 | ExpectError error(r, "'+' cannot operate on 'bool'"); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 702 | Var c(kBool_Type); |
Ethan Nicholas | 549c6b8 | 2021-06-25 12:31:44 -0400 | [diff] [blame] | 703 | DSLExpression(+c).release(); |
Ethan Nicholas | b14b636 | 2021-03-08 17:07:58 -0500 | [diff] [blame] | 704 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLMinus, r, ctxInfo) { |
| 708 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 709 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 710 | |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 711 | EXPECT_EQUAL(a - b, |
| 712 | "(a - b)"); |
| 713 | EXPECT_EQUAL(a - 1, |
| 714 | "(a - 1)"); |
| 715 | EXPECT_EQUAL(2 - a - b, |
| 716 | "((2 - a) - b)"); |
| 717 | EXPECT_EQUAL(a -= b + 1, |
| 718 | "(a -= (b + 1))"); |
Ethan Nicholas | b14b636 | 2021-03-08 17:07:58 -0500 | [diff] [blame] | 719 | EXPECT_EQUAL(-a, |
| 720 | "-a"); |
| 721 | EXPECT_EQUAL(-(a - b), |
| 722 | "-(a - b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 723 | |
| 724 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 725 | ExpectError error(r, "type mismatch: '-' cannot operate on 'bool2', 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 726 | DSLExpression(Bool2(true) - a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 730 | ExpectError error(r, "type mismatch: '-=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 731 | DSLExpression(a -= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 732 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 733 | |
| 734 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 735 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 736 | DSLExpression(1.0 -= a).release(); |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 737 | } |
Ethan Nicholas | b14b636 | 2021-03-08 17:07:58 -0500 | [diff] [blame] | 738 | |
| 739 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 740 | ExpectError error(r, "'-' cannot operate on 'bool'"); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 741 | Var c(kBool_Type); |
Ethan Nicholas | 549c6b8 | 2021-06-25 12:31:44 -0400 | [diff] [blame] | 742 | DSLExpression(-c).release(); |
Ethan Nicholas | b14b636 | 2021-03-08 17:07:58 -0500 | [diff] [blame] | 743 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLMultiply, r, ctxInfo) { |
| 747 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 748 | Var a(kFloat_Type, "a"), b(kFloat_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 749 | |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 750 | EXPECT_EQUAL(a * b, |
| 751 | "(a * b)"); |
| 752 | EXPECT_EQUAL(a * 2, |
| 753 | "(a * 2.0)"); |
| 754 | EXPECT_EQUAL(0.5 * a * -99, |
| 755 | "((0.5 * a) * -99.0)"); |
| 756 | EXPECT_EQUAL(a *= b + 1, |
| 757 | "(a *= (b + 1.0))"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 758 | |
| 759 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 760 | ExpectError error(r, "type mismatch: '*' cannot operate on 'bool2', 'float'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 761 | DSLExpression(Bool2(true) * a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 765 | ExpectError error(r, "type mismatch: '*=' cannot operate on 'float', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 766 | DSLExpression(a *= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 767 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 768 | |
| 769 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 770 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 771 | DSLExpression(1.0 *= a).release(); |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 772 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLDivide, r, ctxInfo) { |
| 776 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 777 | Var a(kFloat_Type, "a"), b(kFloat_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 778 | |
John Stiles | 8f440b4 | 2021-03-05 16:48:56 -0500 | [diff] [blame] | 779 | EXPECT_EQUAL(a / b, |
| 780 | "(a / b)"); |
| 781 | EXPECT_EQUAL(a / 2, |
| 782 | "(a / 2.0)"); |
| 783 | EXPECT_EQUAL(0.5 / a / -99, |
| 784 | "((0.5 / a) / -99.0)"); |
| 785 | EXPECT_EQUAL(b / (a - 1), |
| 786 | "(b / (a - 1.0))"); |
| 787 | EXPECT_EQUAL(a /= b + 1, |
| 788 | "(a /= (b + 1.0))"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 789 | |
| 790 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 791 | ExpectError error(r, "type mismatch: '/' cannot operate on 'bool2', 'float'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 792 | DSLExpression(Bool2(true) / a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 796 | ExpectError error(r, "type mismatch: '/=' cannot operate on 'float', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 797 | DSLExpression(a /= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 798 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 799 | |
| 800 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 801 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 802 | DSLExpression(1.0 /= a).release(); |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 803 | } |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 804 | |
| 805 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 806 | ExpectError error(r, "division by zero"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 807 | DSLExpression(a /= 0).release(); |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | { |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 811 | Var c(kFloat2_Type, "c"); |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 812 | ExpectError error(r, "division by zero"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 813 | DSLExpression(c /= Float2(Float(0), 1)).release(); |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 814 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLMod, r, ctxInfo) { |
| 818 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 819 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 820 | Expression e1 = a % b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 821 | EXPECT_EQUAL(e1, "(a % b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 822 | |
| 823 | Expression e2 = a % 2; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 824 | EXPECT_EQUAL(e2, "(a % 2)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 825 | |
| 826 | Expression e3 = 10 % a % -99; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 827 | EXPECT_EQUAL(e3, "((10 % a) % -99)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 828 | |
| 829 | Expression e4 = a %= b + 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 830 | EXPECT_EQUAL(e4, "(a %= (b + 1))"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 831 | |
| 832 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 833 | ExpectError error(r, "type mismatch: '%' cannot operate on 'bool2', 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 834 | DSLExpression(Bool2(true) % a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 838 | ExpectError error(r, "type mismatch: '%=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 839 | DSLExpression(a %= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 840 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 841 | |
| 842 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 843 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 844 | DSLExpression(1 %= a).release(); |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 845 | } |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 846 | |
| 847 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 848 | ExpectError error(r, "division by zero"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 849 | DSLExpression(a %= 0).release(); |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | { |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 853 | Var c(kInt2_Type, "c"); |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 854 | ExpectError error(r, "division by zero"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 855 | DSLExpression(c %= Int2(Int(0), 1)).release(); |
Ethan Nicholas | c0f9815 | 2021-02-05 16:21:10 -0500 | [diff] [blame] | 856 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLShl, r, ctxInfo) { |
| 860 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 861 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 862 | Expression e1 = a << b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 863 | EXPECT_EQUAL(e1, "(a << b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 864 | |
| 865 | Expression e2 = a << 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 866 | EXPECT_EQUAL(e2, "(a << 1)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 867 | |
| 868 | Expression e3 = 1 << a << 2; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 869 | EXPECT_EQUAL(e3, "((1 << a) << 2)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 870 | |
| 871 | Expression e4 = a <<= b + 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 872 | EXPECT_EQUAL(e4, "(a <<= (b + 1))"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 873 | |
| 874 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 875 | ExpectError error(r, "type mismatch: '<<' cannot operate on 'bool2', 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 876 | DSLExpression(Bool2(true) << a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 880 | ExpectError error(r, "type mismatch: '<<=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 881 | DSLExpression(a <<= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 882 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 883 | |
| 884 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 885 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 886 | DSLExpression(1 <<= a).release(); |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 887 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLShr, r, ctxInfo) { |
| 891 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 892 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 893 | Expression e1 = a >> b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 894 | EXPECT_EQUAL(e1, "(a >> b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 895 | |
| 896 | Expression e2 = a >> 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 897 | EXPECT_EQUAL(e2, "(a >> 1)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 898 | |
| 899 | Expression e3 = 1 >> a >> 2; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 900 | EXPECT_EQUAL(e3, "((1 >> a) >> 2)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 901 | |
| 902 | Expression e4 = a >>= b + 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 903 | EXPECT_EQUAL(e4, "(a >>= (b + 1))"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 904 | |
| 905 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 906 | ExpectError error(r, "type mismatch: '>>' cannot operate on 'bool2', 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 907 | DSLExpression(Bool2(true) >> a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 911 | ExpectError error(r, "type mismatch: '>>=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 912 | DSLExpression(a >>= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 913 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 914 | |
| 915 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 916 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 917 | DSLExpression(1 >>= a).release(); |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 918 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBitwiseAnd, r, ctxInfo) { |
| 922 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 923 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 924 | Expression e1 = a & b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 925 | EXPECT_EQUAL(e1, "(a & b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 926 | |
| 927 | Expression e2 = a & 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 928 | EXPECT_EQUAL(e2, "(a & 1)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 929 | |
| 930 | Expression e3 = 1 & a & 2; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 931 | EXPECT_EQUAL(e3, "((1 & a) & 2)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 932 | |
| 933 | Expression e4 = a &= b + 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 934 | EXPECT_EQUAL(e4, "(a &= (b + 1))"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 935 | |
| 936 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 937 | ExpectError error(r, "type mismatch: '&' cannot operate on 'bool2', 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 938 | DSLExpression(Bool2(true) & a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 942 | ExpectError error(r, "type mismatch: '&=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 943 | DSLExpression(a &= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 944 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 945 | |
| 946 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 947 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 948 | DSLExpression(1 &= a).release(); |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 949 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBitwiseOr, r, ctxInfo) { |
| 953 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 954 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 955 | Expression e1 = a | b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 956 | EXPECT_EQUAL(e1, "(a | b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 957 | |
| 958 | Expression e2 = a | 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 959 | EXPECT_EQUAL(e2, "(a | 1)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 960 | |
| 961 | Expression e3 = 1 | a | 2; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 962 | EXPECT_EQUAL(e3, "((1 | a) | 2)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 963 | |
| 964 | Expression e4 = a |= b + 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 965 | EXPECT_EQUAL(e4, "(a |= (b + 1))"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 966 | |
| 967 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 968 | ExpectError error(r, "type mismatch: '|' cannot operate on 'bool2', 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 969 | DSLExpression(Bool2(true) | a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 973 | ExpectError error(r, "type mismatch: '|=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 974 | DSLExpression(a |= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 975 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 976 | |
| 977 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 978 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 979 | DSLExpression(1 |= a).release(); |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 980 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBitwiseXor, r, ctxInfo) { |
| 984 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 985 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 986 | Expression e1 = a ^ b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 987 | EXPECT_EQUAL(e1, "(a ^ b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 988 | |
| 989 | Expression e2 = a ^ 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 990 | EXPECT_EQUAL(e2, "(a ^ 1)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 991 | |
| 992 | Expression e3 = 1 ^ a ^ 2; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 993 | EXPECT_EQUAL(e3, "((1 ^ a) ^ 2)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 994 | |
| 995 | Expression e4 = a ^= b + 1; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 996 | EXPECT_EQUAL(e4, "(a ^= (b + 1))"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 997 | |
| 998 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 999 | ExpectError error(r, "type mismatch: '^' cannot operate on 'bool2', 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1000 | DSLExpression(Bool2(true) ^ a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1004 | ExpectError error(r, "type mismatch: '^=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1005 | DSLExpression(a ^= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1006 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 1007 | |
| 1008 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1009 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1010 | DSLExpression(1 ^= a).release(); |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 1011 | } |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLLogicalAnd, r, ctxInfo) { |
| 1015 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1016 | Var a(kBool_Type, "a"), b(kBool_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1017 | Expression e1 = a && b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1018 | EXPECT_EQUAL(e1, "(a && b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1019 | |
| 1020 | Expression e2 = a && true && b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1021 | EXPECT_EQUAL(e2, "(a && b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1022 | |
| 1023 | Expression e3 = a && false && b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1024 | EXPECT_EQUAL(e3, "false"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1025 | |
| 1026 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1027 | ExpectError error(r, "type mismatch: '&&' cannot operate on 'bool', 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1028 | DSLExpression(a && 5).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLLogicalOr, r, ctxInfo) { |
| 1033 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1034 | Var a(kBool_Type, "a"), b(kBool_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1035 | Expression e1 = a || b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1036 | EXPECT_EQUAL(e1, "(a || b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1037 | |
| 1038 | Expression e2 = a || true || b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1039 | EXPECT_EQUAL(e2, "true"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1040 | |
| 1041 | Expression e3 = a || false || b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1042 | EXPECT_EQUAL(e3, "(a || b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1043 | |
| 1044 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1045 | ExpectError error(r, "type mismatch: '||' cannot operate on 'bool', 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1046 | DSLExpression(a || 5).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
Ethan Nicholas | 2ab47c9 | 2021-07-19 12:30:37 -0400 | [diff] [blame] | 1050 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLLogicalXor, r, ctxInfo) { |
| 1051 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 1052 | Var a(kBool_Type, "a"), b(kBool_Type, "b"); |
| 1053 | Expression e1 = LogicalXor(a, b); |
| 1054 | EXPECT_EQUAL(e1, "(a ^^ b)"); |
| 1055 | |
| 1056 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1057 | ExpectError error(r, "type mismatch: '^^' cannot operate on 'bool', 'int'"); |
Ethan Nicholas | 2ab47c9 | 2021-07-19 12:30:37 -0400 | [diff] [blame] | 1058 | DSLExpression(LogicalXor(a, 5)).release(); |
| 1059 | } |
| 1060 | } |
| 1061 | |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1062 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLComma, r, ctxInfo) { |
| 1063 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1064 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1065 | Expression e1 = (a += b, b); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1066 | EXPECT_EQUAL(e1, "((a += b) , b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1067 | |
| 1068 | Expression e2 = (a += b, b += b, Int2(a)); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1069 | EXPECT_EQUAL(e2, "(((a += b) , (b += b)) , int2(a))"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLEqual, r, ctxInfo) { |
| 1073 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1074 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1075 | Expression e1 = a == b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1076 | EXPECT_EQUAL(e1, "(a == b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1077 | |
| 1078 | Expression e2 = a == 5; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1079 | EXPECT_EQUAL(e2, "(a == 5)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1080 | |
| 1081 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1082 | ExpectError error(r, "type mismatch: '==' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1083 | DSLExpression(a == Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLNotEqual, r, ctxInfo) { |
| 1088 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1089 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1090 | Expression e1 = a != b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1091 | EXPECT_EQUAL(e1, "(a != b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1092 | |
| 1093 | Expression e2 = a != 5; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1094 | EXPECT_EQUAL(e2, "(a != 5)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1095 | |
| 1096 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1097 | ExpectError error(r, "type mismatch: '!=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1098 | DSLExpression(a != Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLGreaterThan, r, ctxInfo) { |
| 1103 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1104 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1105 | Expression e1 = a > b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1106 | EXPECT_EQUAL(e1, "(a > b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1107 | |
| 1108 | Expression e2 = a > 5; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1109 | EXPECT_EQUAL(e2, "(a > 5)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1110 | |
| 1111 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1112 | ExpectError error(r, "type mismatch: '>' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1113 | DSLExpression(a > Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLGreaterThanOrEqual, r, ctxInfo) { |
| 1118 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1119 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1120 | Expression e1 = a >= b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1121 | EXPECT_EQUAL(e1, "(a >= b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1122 | |
| 1123 | Expression e2 = a >= 5; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1124 | EXPECT_EQUAL(e2, "(a >= 5)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1125 | |
| 1126 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1127 | ExpectError error(r, "type mismatch: '>=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1128 | DSLExpression(a >= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLLessThan, r, ctxInfo) { |
| 1133 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1134 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1135 | Expression e1 = a < b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1136 | EXPECT_EQUAL(e1, "(a < b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1137 | |
| 1138 | Expression e2 = a < 5; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1139 | EXPECT_EQUAL(e2, "(a < 5)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1140 | |
| 1141 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1142 | ExpectError error(r, "type mismatch: '<' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1143 | DSLExpression(a < Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLLessThanOrEqual, r, ctxInfo) { |
| 1148 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1149 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1150 | Expression e1 = a <= b; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1151 | EXPECT_EQUAL(e1, "(a <= b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1152 | |
| 1153 | Expression e2 = a <= 5; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1154 | EXPECT_EQUAL(e2, "(a <= 5)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1155 | |
| 1156 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1157 | ExpectError error(r, "type mismatch: '<=' cannot operate on 'int', 'bool2'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1158 | DSLExpression(a <= Bool2(true)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLLogicalNot, r, ctxInfo) { |
| 1163 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1164 | Var a(kInt_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1165 | Expression e1 = !(a <= b); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1166 | EXPECT_EQUAL(e1, "!(a <= b)"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1167 | |
| 1168 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1169 | ExpectError error(r, "'!' cannot operate on 'int'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1170 | DSLExpression(!a).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBitwiseNot, r, ctxInfo) { |
| 1175 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1176 | Var a(kInt_Type, "a"), b(kBool_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1177 | Expression e1 = ~a; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1178 | EXPECT_EQUAL(e1, "~a"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1179 | |
| 1180 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1181 | ExpectError error(r, "'~' cannot operate on 'bool'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1182 | DSLExpression(~b).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLIncrement, r, ctxInfo) { |
| 1187 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1188 | Var a(kInt_Type, "a"), b(kBool_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1189 | Expression e1 = ++a; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1190 | EXPECT_EQUAL(e1, "++a"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1191 | |
| 1192 | Expression e2 = a++; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1193 | EXPECT_EQUAL(e2, "a++"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1194 | |
| 1195 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1196 | ExpectError error(r, "'++' cannot operate on 'bool'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1197 | DSLExpression(++b).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1201 | ExpectError error(r, "'++' cannot operate on 'bool'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1202 | DSLExpression(b++).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1206 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1207 | DSLExpression(++(a + 1)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1211 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1212 | DSLExpression((a + 1)++).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLDecrement, r, ctxInfo) { |
| 1217 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1218 | Var a(kInt_Type, "a"), b(kBool_Type, "b"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1219 | Expression e1 = --a; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1220 | EXPECT_EQUAL(e1, "--a"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1221 | |
| 1222 | Expression e2 = a--; |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1223 | EXPECT_EQUAL(e2, "a--"); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1224 | |
| 1225 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1226 | ExpectError error(r, "'--' cannot operate on 'bool'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1227 | DSLExpression(--b).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1231 | ExpectError error(r, "'--' cannot operate on 'bool'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1232 | DSLExpression(b--).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1236 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1237 | DSLExpression(--(a + 1)).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1241 | ExpectError error(r, "cannot assign to this expression"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1242 | DSLExpression((a + 1)--).release(); |
Ethan Nicholas | 92969f2 | 2021-01-13 10:38:59 -0500 | [diff] [blame] | 1243 | } |
| 1244 | } |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1245 | |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 1246 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLCall, r, ctxInfo) { |
| 1247 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 1248 | { |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1249 | DSLExpression sqrt(DSLWriter::IRGenerator().convertIdentifier(/*offset=*/-1, "sqrt")); |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 1250 | SkTArray<DSLWrapper<DSLExpression>> args; |
John Stiles | 443fa19 | 2021-05-24 23:46:46 -0400 | [diff] [blame] | 1251 | args.emplace_back(16); |
| 1252 | EXPECT_EQUAL(sqrt(std::move(args)), "4.0"); // sqrt(16) gets optimized to 4 |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | { |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1256 | DSLExpression pow(DSLWriter::IRGenerator().convertIdentifier(/*offset=*/-1, "pow")); |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 1257 | DSLVar a(kFloat_Type, "a"); |
| 1258 | DSLVar b(kFloat_Type, "b"); |
| 1259 | SkTArray<DSLWrapper<DSLExpression>> args; |
| 1260 | args.emplace_back(a); |
| 1261 | args.emplace_back(b); |
| 1262 | EXPECT_EQUAL(pow(std::move(args)), "pow(a, b)"); |
| 1263 | } |
| 1264 | } |
| 1265 | |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1266 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBlock, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1267 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 1268 | EXPECT_EQUAL(Block(), "{ }"); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1269 | Var a(kInt_Type, "a", 1), b(kInt_Type, "b", 2); |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 1270 | EXPECT_EQUAL(Block(Declare(a), Declare(b), a = b), "{ int a = 1; int b = 2; (a = b); }"); |
Ethan Nicholas | db2326b | 2021-04-19 10:55:18 -0400 | [diff] [blame] | 1271 | |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 1272 | EXPECT_EQUAL((If(a > 0, --a), ++b), "if ((a > 0)) --a; ++b;"); |
| 1273 | |
| 1274 | SkTArray<DSLStatement> statements; |
| 1275 | statements.push_back(a = 0); |
| 1276 | statements.push_back(++a); |
| 1277 | EXPECT_EQUAL(Block(std::move(statements)), "{ (a = 0); ++a; }"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1278 | } |
| 1279 | |
Ethan Nicholas | daceb79 | 2021-02-05 14:22:32 -0500 | [diff] [blame] | 1280 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBreak, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1281 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1282 | Var i(kInt_Type, "i", 0); |
| 1283 | DSLFunction(kVoid_Type, "success").define( |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1284 | For(Declare(i), i < 10, ++i, Block( |
Ethan Nicholas | daceb79 | 2021-02-05 14:22:32 -0500 | [diff] [blame] | 1285 | If(i > 5, Break()) |
| 1286 | )) |
| 1287 | ); |
| 1288 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1289 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], |
| 1290 | "void success() { for (int i = 0; (i < 10); ++i) { if ((i > 5)) break; } }"); |
Ethan Nicholas | daceb79 | 2021-02-05 14:22:32 -0500 | [diff] [blame] | 1291 | |
| 1292 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1293 | ExpectError error(r, "break statement must be inside a loop or switch"); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1294 | DSLFunction(kVoid_Type, "fail").define( |
Ethan Nicholas | daceb79 | 2021-02-05 14:22:32 -0500 | [diff] [blame] | 1295 | Break() |
| 1296 | ); |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLContinue, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1301 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1302 | Var i(kInt_Type, "i", 0); |
| 1303 | DSLFunction(kVoid_Type, "success").define( |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1304 | For(Declare(i), i < 10, ++i, Block( |
Ethan Nicholas | daceb79 | 2021-02-05 14:22:32 -0500 | [diff] [blame] | 1305 | If(i < 5, Continue()) |
| 1306 | )) |
| 1307 | ); |
| 1308 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1309 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], |
| 1310 | "void success() { for (int i = 0; (i < 10); ++i) { if ((i < 5)) continue; } }"); |
Ethan Nicholas | daceb79 | 2021-02-05 14:22:32 -0500 | [diff] [blame] | 1311 | |
| 1312 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1313 | ExpectError error(r, "continue statement must be inside a loop"); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1314 | DSLFunction(kVoid_Type, "fail").define( |
Ethan Nicholas | daceb79 | 2021-02-05 14:22:32 -0500 | [diff] [blame] | 1315 | Continue() |
| 1316 | ); |
| 1317 | } |
| 1318 | } |
| 1319 | |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1320 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLDeclare, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1321 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | da72978 | 2021-07-19 12:55:52 -0400 | [diff] [blame] | 1322 | { |
| 1323 | Var a(kHalf4_Type, "a"), b(kHalf4_Type, "b", Half4(1)); |
| 1324 | EXPECT_EQUAL(Declare(a), "half4 a;"); |
| 1325 | EXPECT_EQUAL(Declare(b), "half4 b = half4(1.0);"); |
| 1326 | } |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1327 | |
| 1328 | { |
Ethan Nicholas | da72978 | 2021-07-19 12:55:52 -0400 | [diff] [blame] | 1329 | DSLWriter::Reset(); |
| 1330 | SkTArray<Var> vars; |
| 1331 | vars.push_back(Var(kBool_Type, "a", true)); |
| 1332 | vars.push_back(Var(kFloat_Type, "b")); |
| 1333 | EXPECT_EQUAL(Declare(vars), "bool a = true; float b;"); |
| 1334 | } |
| 1335 | |
| 1336 | { |
| 1337 | DSLWriter::Reset(); |
| 1338 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().empty()); |
| 1339 | GlobalVar a(kHalf4_Type, "a"), b(kHalf4_Type, "b", Half4(1)); |
| 1340 | Declare(a); |
| 1341 | Declare(b); |
| 1342 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 2); |
| 1343 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], "half4 a;"); |
| 1344 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[1], "half4 b = half4(1.0);"); |
| 1345 | } |
| 1346 | |
| 1347 | { |
| 1348 | DSLWriter::Reset(); |
| 1349 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().empty()); |
| 1350 | SkTArray<GlobalVar> vars; |
| 1351 | vars.push_back(GlobalVar(kHalf4_Type, "a")); |
| 1352 | vars.push_back(GlobalVar(kHalf4_Type, "b", Half4(1))); |
| 1353 | Declare(vars); |
| 1354 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 2); |
| 1355 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], "half4 a;"); |
| 1356 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[1], "half4 b = half4(1.0);"); |
| 1357 | } |
| 1358 | |
| 1359 | { |
| 1360 | DSLWriter::Reset(); |
| 1361 | Var a(kHalf4_Type, "a", 1); |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1362 | ExpectError error(r, "expected 'half4', but found 'int'"); |
Ethan Nicholas | da72978 | 2021-07-19 12:55:52 -0400 | [diff] [blame] | 1363 | Declare(a).release(); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | { |
Ethan Nicholas | da72978 | 2021-07-19 12:55:52 -0400 | [diff] [blame] | 1367 | DSLWriter::Reset(); |
| 1368 | Var a(kInt_Type, "a"); |
| 1369 | Declare(a).release(); |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1370 | ExpectError error(r, "variable has already been declared"); |
Ethan Nicholas | da72978 | 2021-07-19 12:55:52 -0400 | [diff] [blame] | 1371 | Declare(a).release(); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1372 | } |
Ethan Nicholas | e9c2c5a | 2021-04-30 13:14:24 -0400 | [diff] [blame] | 1373 | |
| 1374 | { |
Ethan Nicholas | da72978 | 2021-07-19 12:55:52 -0400 | [diff] [blame] | 1375 | DSLWriter::Reset(); |
| 1376 | Var a(kUniform_Modifier, kInt_Type, "a"); |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1377 | ExpectError error(r, "'uniform' is not permitted here"); |
Ethan Nicholas | da72978 | 2021-07-19 12:55:52 -0400 | [diff] [blame] | 1378 | Declare(a).release(); |
Ethan Nicholas | e9c2c5a | 2021-04-30 13:14:24 -0400 | [diff] [blame] | 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLDeclareGlobal, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1383 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1384 | DSLGlobalVar x(kInt_Type, "x", 0); |
| 1385 | Declare(x); |
| 1386 | DSLGlobalVar y(kUniform_Modifier, kFloat2_Type, "y"); |
| 1387 | Declare(y); |
Ethan Nicholas | e9c2c5a | 2021-04-30 13:14:24 -0400 | [diff] [blame] | 1388 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 2); |
| 1389 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], "int x = 0;"); |
| 1390 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[1], "uniform float2 y;"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1391 | } |
| 1392 | |
Ethan Nicholas | daceb79 | 2021-02-05 14:22:32 -0500 | [diff] [blame] | 1393 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLDiscard, r, ctxInfo) { |
| 1394 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
John Stiles | 443fa19 | 2021-05-24 23:46:46 -0400 | [diff] [blame] | 1395 | Var x(kFloat_Type, "x", 1); |
| 1396 | EXPECT_EQUAL(If(Sqrt(x) > 0, Discard()), "if ((sqrt(x) > 0.0)) discard;"); |
Ethan Nicholas | daceb79 | 2021-02-05 14:22:32 -0500 | [diff] [blame] | 1397 | } |
| 1398 | |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1399 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLDo, r, ctxInfo) { |
| 1400 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 1401 | Statement x = Do(Block(), true); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1402 | EXPECT_EQUAL(x, "do {} while (true);"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1403 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1404 | Var a(kFloat_Type, "a"), b(kFloat_Type, "b"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1405 | Statement y = Do(Block(a++, --b), a != b); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1406 | EXPECT_EQUAL(y, "do { a++; --b; } while ((a != b));"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1407 | |
| 1408 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1409 | ExpectError error(r, "expected 'bool', but found 'int'"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1410 | Do(Block(), 7).release(); |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLFor, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1415 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
John Stiles | 8676ebe | 2021-04-20 15:30:41 -0400 | [diff] [blame] | 1416 | EXPECT_EQUAL(For(Statement(), Expression(), Expression(), Block()), |
| 1417 | "for (;;) {}"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1418 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1419 | Var i(kInt_Type, "i", 0); |
John Stiles | 8676ebe | 2021-04-20 15:30:41 -0400 | [diff] [blame] | 1420 | EXPECT_EQUAL(For(Declare(i), i < 10, ++i, i += 5), |
| 1421 | "for (int i = 0; (i < 10); ++i) (i += 5);"); |
| 1422 | |
| 1423 | Var j(kInt_Type, "j", 0); |
| 1424 | Var k(kInt_Type, "k", 10); |
| 1425 | EXPECT_EQUAL(For((Declare(j), Declare(k)), j < k, ++j, Block()), R"( |
| 1426 | { |
| 1427 | int j = 0; |
| 1428 | int k = 10; |
| 1429 | for (; (j < k); ++j) {} |
| 1430 | } |
| 1431 | )"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1432 | |
| 1433 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1434 | ExpectError error(r, "expected 'bool', but found 'int'"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1435 | For(i = 0, i + 10, ++i, i += 5).release(); |
| 1436 | } |
Ethan Nicholas | a0f7654 | 2021-04-16 16:02:18 -0400 | [diff] [blame] | 1437 | |
| 1438 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1439 | ExpectError error(r, "invalid for loop initializer"); |
Ethan Nicholas | a0f7654 | 2021-04-16 16:02:18 -0400 | [diff] [blame] | 1440 | For(If(i == 0, i = 1), i < 10, ++i, i += 5).release(); |
| 1441 | } |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1442 | } |
| 1443 | |
Ethan Nicholas | e2c0504 | 2021-02-03 10:27:22 -0500 | [diff] [blame] | 1444 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLFunction, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1445 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1446 | Parameter coords(kFloat2_Type, "coords"); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1447 | DSLFunction(kVoid_Type, "main", coords).define( |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1448 | sk_FragColor() = Half4(coords, 0, 1) |
| 1449 | ); |
| 1450 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1451 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], |
Ethan Nicholas | 371f6e1 | 2021-05-04 14:30:02 -0400 | [diff] [blame] | 1452 | "void main(float2 coords) { (sk_FragColor = half4(half2(coords), 0.0, 1.0)); }"); |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1453 | |
Ethan Nicholas | 63f75fc | 2021-02-23 12:05:49 -0500 | [diff] [blame] | 1454 | { |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1455 | DSLWriter::Reset(); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1456 | DSLParameter x(kFloat_Type, "x"); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1457 | DSLFunction sqr(kFloat_Type, "sqr", x); |
Ethan Nicholas | 63f75fc | 2021-02-23 12:05:49 -0500 | [diff] [blame] | 1458 | sqr.define( |
| 1459 | Return(x * x) |
| 1460 | ); |
| 1461 | EXPECT_EQUAL(sqr(sk_FragCoord().x()), "sqr(sk_FragCoord.x)"); |
| 1462 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1); |
| 1463 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], "float sqr(float x) { return (x * x); }"); |
| 1464 | } |
| 1465 | |
| 1466 | { |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1467 | DSLWriter::Reset(); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1468 | DSLParameter x(kFloat2_Type, "x"); |
| 1469 | DSLParameter y(kFloat2_Type, "y"); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1470 | DSLFunction dot(kFloat2_Type, "dot", x, y); |
Ethan Nicholas | 63f75fc | 2021-02-23 12:05:49 -0500 | [diff] [blame] | 1471 | dot.define( |
| 1472 | Return(x * x + y * y) |
| 1473 | ); |
| 1474 | EXPECT_EQUAL(dot(Float2(1.0f, 2.0f), Float2(3.0f, 4.0f)), |
| 1475 | "dot(float2(1.0, 2.0), float2(3.0, 4.0))"); |
| 1476 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1); |
| 1477 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], |
| 1478 | "float2 dot(float2 x, float2 y) { return ((x * x) + (y * y)); }"); |
| 1479 | } |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1480 | |
| 1481 | { |
Ethan Nicholas | 80f6235 | 2021-04-09 12:25:03 -0400 | [diff] [blame] | 1482 | DSLWriter::Reset(); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1483 | DSLParameter x(kFloat_Type, "x"); |
| 1484 | DSLParameter y(kFloat_Type, "y"); |
Ethan Nicholas | 80f6235 | 2021-04-09 12:25:03 -0400 | [diff] [blame] | 1485 | DSLFunction pair(kFloat2_Type, "pair", x, y); |
| 1486 | pair.define( |
| 1487 | Return(Float2(x, y)) |
| 1488 | ); |
| 1489 | Var varArg1(kFloat_Type, "varArg1"); |
| 1490 | Var varArg2(kFloat_Type, "varArg2"); |
| 1491 | DSLWriter::MarkDeclared(varArg1); |
| 1492 | DSLWriter::MarkDeclared(varArg2); |
| 1493 | EXPECT_EQUAL(pair(varArg1, varArg2), "pair(varArg1, varArg2)"); |
| 1494 | } |
| 1495 | |
| 1496 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1497 | ExpectError error(r, "expected 'float', but found 'bool'"); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1498 | DSLWriter::Reset(); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1499 | DSLFunction(kFloat_Type, "broken").define( |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1500 | Return(true) |
| 1501 | ); |
| 1502 | } |
| 1503 | |
| 1504 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1505 | ExpectError error(r, "expected function to return 'float'"); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1506 | DSLWriter::Reset(); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1507 | DSLFunction(kFloat_Type, "broken").define( |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1508 | Return() |
| 1509 | ); |
| 1510 | } |
| 1511 | |
| 1512 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1513 | ExpectError error(r, "function 'broken' can exit without returning a value"); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1514 | DSLWriter::Reset(); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1515 | Var x(kFloat_Type, "x", 0); |
| 1516 | DSLFunction(kFloat_Type, "broken").define( |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1517 | Declare(x), |
John Stiles | b3dcbb1 | 2021-03-04 16:00:20 -0500 | [diff] [blame] | 1518 | If(x == 1, Return(x)) |
| 1519 | ); |
| 1520 | } |
| 1521 | |
| 1522 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1523 | ExpectError error(r, "may not return a value from a void function"); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1524 | DSLWriter::Reset(); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1525 | DSLFunction(kVoid_Type, "broken").define( |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1526 | Return(0) |
| 1527 | ); |
| 1528 | } |
| 1529 | |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1530 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1531 | ExpectError error(r, "function 'broken' can exit without returning a value"); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1532 | DSLWriter::Reset(); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1533 | DSLFunction(kFloat_Type, "broken").define( |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1534 | ); |
| 1535 | } |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1536 | |
| 1537 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1538 | ExpectError error(r, "parameter has already been used in another function"); |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1539 | DSLWriter::Reset(); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1540 | DSLParameter p(kFloat_Type); |
| 1541 | DSLFunction(kVoid_Type, "ok", p).define( |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1542 | ); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1543 | DSLFunction(kVoid_Type, "broken", p).define( |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1544 | ); |
| 1545 | } |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1546 | } |
| 1547 | |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1548 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLIf, r, ctxInfo) { |
| 1549 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1550 | Var a(kFloat_Type, "a"), b(kFloat_Type, "b"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1551 | Statement x = If(a > b, a -= b); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1552 | EXPECT_EQUAL(x, "if ((a > b)) (a -= b);"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1553 | |
| 1554 | Statement y = If(a > b, a -= b, b -= a); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1555 | EXPECT_EQUAL(y, "if ((a > b)) (a -= b); else (b -= a);"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1556 | |
Ethan Nicholas | 8a6537d | 2021-04-30 12:44:00 -0400 | [diff] [blame] | 1557 | Statement z = StaticIf(a > b, a -= b, b -= a); |
| 1558 | EXPECT_EQUAL(z, "@if ((a > b)) (a -= b); else (b -= a);"); |
| 1559 | |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1560 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1561 | ExpectError error(r, "expected 'bool', but found 'float'"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1562 | If(a + b, a -= b).release(); |
| 1563 | } |
| 1564 | } |
| 1565 | |
Ethan Nicholas | e6ed3c2 | 2021-07-08 10:38:43 -0400 | [diff] [blame] | 1566 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLInterfaceBlock, r, ctxInfo) { |
| 1567 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1568 | DSLGlobalVar intf = InterfaceBlock(kUniform_Modifier, "InterfaceBlock1", |
| 1569 | { Field(kFloat_Type, "a"), Field(kInt_Type, "b") }); |
Ethan Nicholas | e6ed3c2 | 2021-07-08 10:38:43 -0400 | [diff] [blame] | 1570 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1); |
| 1571 | EXPECT_EQUAL(*DSLWriter::ProgramElements().back(), |
| 1572 | "uniform InterfaceBlock1 { float a; int b; };"); |
| 1573 | EXPECT_EQUAL(intf.field("a"), "InterfaceBlock1.a"); |
| 1574 | |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1575 | DSLGlobalVar intf2 = InterfaceBlock(kUniform_Modifier, "InterfaceBlock2", |
| 1576 | { Field(kFloat2_Type, "x"), Field(kHalf2x2_Type, "y") }, |
Ethan Nicholas | e6ed3c2 | 2021-07-08 10:38:43 -0400 | [diff] [blame] | 1577 | "blockVar"); |
| 1578 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 2); |
| 1579 | EXPECT_EQUAL(*DSLWriter::ProgramElements().back(), |
| 1580 | "uniform InterfaceBlock2 { float2 x; half2x2 y; } blockVar;"); |
| 1581 | EXPECT_EQUAL(intf2.field("x"), "blockVar.x"); |
| 1582 | |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1583 | DSLGlobalVar intf3 = InterfaceBlock(kUniform_Modifier, "InterfaceBlock3", |
| 1584 | { Field(kFloat_Type, "z") },"arrayVar", 4); |
Ethan Nicholas | e6ed3c2 | 2021-07-08 10:38:43 -0400 | [diff] [blame] | 1585 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 3); |
| 1586 | EXPECT_EQUAL(*DSLWriter::ProgramElements().back(), |
| 1587 | "uniform InterfaceBlock3 { float z; } arrayVar[4];"); |
| 1588 | EXPECT_EQUAL(intf3[1].field("z"), "arrayVar[1].z"); |
| 1589 | } |
| 1590 | |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1591 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLReturn, r, ctxInfo) { |
| 1592 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 1593 | |
| 1594 | Statement x = Return(); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1595 | EXPECT_EQUAL(x, "return;"); |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1596 | |
| 1597 | Statement y = Return(true); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1598 | EXPECT_EQUAL(y, "return true;"); |
Ethan Nicholas | 1ff7609 | 2021-01-28 10:02:43 -0500 | [diff] [blame] | 1599 | } |
| 1600 | |
Ethan Nicholas | fa648a1 | 2021-02-17 12:13:20 -0500 | [diff] [blame] | 1601 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLSelect, r, ctxInfo) { |
| 1602 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1603 | Var a(kInt_Type, "a"); |
Ethan Nicholas | fa648a1 | 2021-02-17 12:13:20 -0500 | [diff] [blame] | 1604 | Expression x = Select(a > 0, 1, -1); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1605 | EXPECT_EQUAL(x, "((a > 0) ? 1 : -1)"); |
Ethan Nicholas | fa648a1 | 2021-02-17 12:13:20 -0500 | [diff] [blame] | 1606 | |
| 1607 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1608 | ExpectError error(r, "expected 'bool', but found 'int'"); |
Ethan Nicholas | 549c6b8 | 2021-06-25 12:31:44 -0400 | [diff] [blame] | 1609 | Select(a, 1, -1).release(); |
Ethan Nicholas | fa648a1 | 2021-02-17 12:13:20 -0500 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1613 | ExpectError error(r, "ternary operator result mismatch: 'float2', 'float3'"); |
Ethan Nicholas | 549c6b8 | 2021-06-25 12:31:44 -0400 | [diff] [blame] | 1614 | Select(a > 0, Float2(1), Float3(1)).release(); |
Ethan Nicholas | fa648a1 | 2021-02-17 12:13:20 -0500 | [diff] [blame] | 1615 | } |
| 1616 | } |
| 1617 | |
Ethan Nicholas | cfefec0 | 2021-02-09 15:22:57 -0500 | [diff] [blame] | 1618 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLSwitch, r, ctxInfo) { |
| 1619 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 1620 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1621 | Var a(kFloat_Type, "a"), b(kInt_Type, "b"); |
Ethan Nicholas | cfefec0 | 2021-02-09 15:22:57 -0500 | [diff] [blame] | 1622 | |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 1623 | SkTArray<DSLStatement> caseStatements; |
| 1624 | caseStatements.push_back(a = 1); |
| 1625 | caseStatements.push_back(Continue()); |
John Stiles | f3a28db | 2021-03-10 23:00:47 -0500 | [diff] [blame] | 1626 | Statement x = Switch(b, |
Ethan Nicholas | cfefec0 | 2021-02-09 15:22:57 -0500 | [diff] [blame] | 1627 | Case(0, a = 0, Break()), |
Ethan Nicholas | 722cb67 | 2021-05-06 10:47:06 -0400 | [diff] [blame] | 1628 | Case(1, std::move(caseStatements)), |
John Stiles | e1d1b08 | 2021-02-23 13:44:36 -0500 | [diff] [blame] | 1629 | Case(2, a = 2 /*Fallthrough*/), |
Ethan Nicholas | cfefec0 | 2021-02-09 15:22:57 -0500 | [diff] [blame] | 1630 | Default(Discard()) |
| 1631 | ); |
John Stiles | e1d1b08 | 2021-02-23 13:44:36 -0500 | [diff] [blame] | 1632 | EXPECT_EQUAL(x, R"( |
John Stiles | f3a28db | 2021-03-10 23:00:47 -0500 | [diff] [blame] | 1633 | switch (b) { |
John Stiles | e1d1b08 | 2021-02-23 13:44:36 -0500 | [diff] [blame] | 1634 | case 0: (a = 0.0); break; |
| 1635 | case 1: (a = 1.0); continue; |
| 1636 | case 2: (a = 2.0); |
| 1637 | default: discard; |
| 1638 | } |
| 1639 | )"); |
Ethan Nicholas | cfefec0 | 2021-02-09 15:22:57 -0500 | [diff] [blame] | 1640 | |
Ethan Nicholas | 8a6537d | 2021-04-30 12:44:00 -0400 | [diff] [blame] | 1641 | Statement y = StaticSwitch(b, |
| 1642 | Case(0, a = 0, Break()), |
| 1643 | Case(1, a = 1, Continue()), |
| 1644 | Case(2, a = 2 /*Fallthrough*/), |
| 1645 | Default(Discard()) |
| 1646 | ); |
| 1647 | EXPECT_EQUAL(y, R"( |
| 1648 | @switch (b) { |
| 1649 | case 0: (a = 0.0); break; |
| 1650 | case 1: (a = 1.0); continue; |
| 1651 | case 2: (a = 2.0); |
| 1652 | default: discard; |
| 1653 | } |
| 1654 | )"); |
| 1655 | |
John Stiles | 642cde2 | 2021-02-23 14:57:01 -0500 | [diff] [blame] | 1656 | EXPECT_EQUAL(Switch(b), |
| 1657 | "switch (b) {}"); |
| 1658 | |
| 1659 | EXPECT_EQUAL(Switch(b, Default(), Case(0), Case(1)), |
| 1660 | "switch (b) { default: case 0: case 1: }"); |
Ethan Nicholas | cfefec0 | 2021-02-09 15:22:57 -0500 | [diff] [blame] | 1661 | |
| 1662 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1663 | ExpectError error(r, "duplicate case value '0'"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1664 | DSLStatement(Switch(0, Case(0), Case(0))).release(); |
Ethan Nicholas | cfefec0 | 2021-02-09 15:22:57 -0500 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1668 | ExpectError error(r, "duplicate default case"); |
Ethan Nicholas | 34c7e11 | 2021-02-25 20:50:32 -0500 | [diff] [blame] | 1669 | DSLStatement(Switch(0, Default(a = 0), Default(a = 1))).release(); |
John Stiles | e1d1b08 | 2021-02-23 13:44:36 -0500 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1673 | ExpectError error(r, "case value must be a constant integer"); |
John Stiles | 628777c | 2021-08-04 22:07:41 -0400 | [diff] [blame] | 1674 | Var c(kInt_Type); |
| 1675 | DSLStatement(Switch(0, Case(c))).release(); |
Ethan Nicholas | cfefec0 | 2021-02-09 15:22:57 -0500 | [diff] [blame] | 1676 | } |
Ethan Nicholas | cfefec0 | 2021-02-09 15:22:57 -0500 | [diff] [blame] | 1677 | } |
| 1678 | |
Ethan Nicholas | 68c77d4 | 2021-01-26 14:31:29 -0500 | [diff] [blame] | 1679 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLSwizzle, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1680 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1681 | Var a(kFloat4_Type, "a"); |
Ethan Nicholas | 68c77d4 | 2021-01-26 14:31:29 -0500 | [diff] [blame] | 1682 | |
John Stiles | f04e09c | 2021-03-05 13:13:14 -0500 | [diff] [blame] | 1683 | EXPECT_EQUAL(a.x(), |
| 1684 | "a.x"); |
| 1685 | EXPECT_EQUAL(a.y(), |
| 1686 | "a.y"); |
| 1687 | EXPECT_EQUAL(a.z(), |
| 1688 | "a.z"); |
| 1689 | EXPECT_EQUAL(a.w(), |
| 1690 | "a.w"); |
| 1691 | EXPECT_EQUAL(a.r(), |
| 1692 | "a.x"); |
| 1693 | EXPECT_EQUAL(a.g(), |
| 1694 | "a.y"); |
| 1695 | EXPECT_EQUAL(a.b(), |
| 1696 | "a.z"); |
| 1697 | EXPECT_EQUAL(a.a(), |
| 1698 | "a.w"); |
| 1699 | EXPECT_EQUAL(Swizzle(a, R), |
| 1700 | "a.x"); |
| 1701 | EXPECT_EQUAL(Swizzle(a, ZERO, G), |
| 1702 | "float2(0.0, a.y)"); |
| 1703 | EXPECT_EQUAL(Swizzle(a, B, G, G), |
| 1704 | "a.zyy"); |
| 1705 | EXPECT_EQUAL(Swizzle(a, R, G, B, ONE), |
| 1706 | "float4(a.xyz, 1.0)"); |
| 1707 | EXPECT_EQUAL(Swizzle(a, B, G, R, ONE).r(), |
| 1708 | "a.z"); |
Ethan Nicholas | 68c77d4 | 2021-01-26 14:31:29 -0500 | [diff] [blame] | 1709 | } |
| 1710 | |
John Stiles | 08771b0 | 2021-04-26 09:35:10 -0400 | [diff] [blame] | 1711 | |
| 1712 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLVarSwap, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1713 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
John Stiles | 08771b0 | 2021-04-26 09:35:10 -0400 | [diff] [blame] | 1714 | |
| 1715 | // We should be able to convert `a` into a proper var by swapping it, even from within a scope. |
| 1716 | Var a; |
| 1717 | if (true) |
| 1718 | { |
| 1719 | Var(kInt_Type, "a").swap(a); |
| 1720 | } |
| 1721 | |
| 1722 | EXPECT_EQUAL(Statement(Block(Declare(a), a = 123)), |
| 1723 | "{ int a; (a = 123); }"); |
| 1724 | } |
| 1725 | |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1726 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLWhile, r, ctxInfo) { |
| 1727 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 1728 | Statement x = While(true, Block()); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1729 | EXPECT_EQUAL(x, "for (; true;) {}"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1730 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1731 | Var a(kFloat_Type, "a"), b(kFloat_Type, "b"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1732 | Statement y = While(a != b, Block(a++, --b)); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1733 | EXPECT_EQUAL(y, "for (; (a != b);) { a++; --b; }"); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1734 | |
| 1735 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1736 | ExpectError error(r, "expected 'bool', but found 'int'"); |
Ethan Nicholas | 549c6b8 | 2021-06-25 12:31:44 -0400 | [diff] [blame] | 1737 | While(7, Block()).release(); |
Ethan Nicholas | d6b6f3e | 2021-01-22 15:18:25 -0500 | [diff] [blame] | 1738 | } |
| 1739 | } |
Ethan Nicholas | 04be339 | 2021-01-26 10:07:01 -0500 | [diff] [blame] | 1740 | |
| 1741 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLIndex, r, ctxInfo) { |
| 1742 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1743 | Var a(Array(kInt_Type, 5), "a"), b(kInt_Type, "b"); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1744 | |
| 1745 | EXPECT_EQUAL(a[0], "a[0]"); |
| 1746 | EXPECT_EQUAL(a[b], "a[b]"); |
Ethan Nicholas | 04be339 | 2021-01-26 10:07:01 -0500 | [diff] [blame] | 1747 | |
| 1748 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1749 | ExpectError error(r, "expected 'int', but found 'bool'"); |
Ethan Nicholas | 549c6b8 | 2021-06-25 12:31:44 -0400 | [diff] [blame] | 1750 | a[true].release(); |
Ethan Nicholas | 04be339 | 2021-01-26 10:07:01 -0500 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1754 | ExpectError error(r, "expected array, but found 'int'"); |
Ethan Nicholas | 549c6b8 | 2021-06-25 12:31:44 -0400 | [diff] [blame] | 1755 | b[0].release(); |
Ethan Nicholas | 04be339 | 2021-01-26 10:07:01 -0500 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1759 | ExpectError error(r, "index -1 out of range for 'int[5]'"); |
Ethan Nicholas | 549c6b8 | 2021-06-25 12:31:44 -0400 | [diff] [blame] | 1760 | a[-1].release(); |
Ethan Nicholas | 04be339 | 2021-01-26 10:07:01 -0500 | [diff] [blame] | 1761 | } |
| 1762 | } |
Ethan Nicholas | 30e93d5 | 2021-01-26 12:00:25 -0500 | [diff] [blame] | 1763 | |
| 1764 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBuiltins, r, ctxInfo) { |
| 1765 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 1766 | // There is a Fract type on Mac which can conflict with our Fract builtin |
| 1767 | using SkSL::dsl::Fract; |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1768 | Var a(kHalf4_Type, "a"), b(kHalf4_Type, "b"), c(kHalf4_Type, "c"); |
| 1769 | Var h3(kHalf3_Type, "h3"); |
| 1770 | Var b4(kBool4_Type, "b4"); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1771 | EXPECT_EQUAL(Abs(a), "abs(a)"); |
| 1772 | EXPECT_EQUAL(All(b4), "all(b4)"); |
| 1773 | EXPECT_EQUAL(Any(b4), "any(b4)"); |
John Stiles | e3fa745 | 2021-04-26 09:36:07 -0400 | [diff] [blame] | 1774 | EXPECT_EQUAL(Atan(a), "atan(a)"); |
| 1775 | EXPECT_EQUAL(Atan(a, b), "atan(a, b)"); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1776 | EXPECT_EQUAL(Ceil(a), "ceil(a)"); |
| 1777 | EXPECT_EQUAL(Clamp(a, 0, 1), "clamp(a, 0.0, 1.0)"); |
| 1778 | EXPECT_EQUAL(Cos(a), "cos(a)"); |
| 1779 | EXPECT_EQUAL(Cross(h3, h3), "cross(h3, h3)"); |
| 1780 | EXPECT_EQUAL(Degrees(a), "degrees(a)"); |
| 1781 | EXPECT_EQUAL(Distance(a, b), "distance(a, b)"); |
| 1782 | EXPECT_EQUAL(Dot(a, b), "dot(a, b)"); |
| 1783 | EXPECT_EQUAL(Equal(a, b), "equal(a, b)"); |
| 1784 | EXPECT_EQUAL(Exp(a), "exp(a)"); |
| 1785 | EXPECT_EQUAL(Exp2(a), "exp2(a)"); |
| 1786 | EXPECT_EQUAL(Faceforward(a, b, c), "faceforward(a, b, c)"); |
| 1787 | EXPECT_EQUAL(Floor(a), "floor(a)"); |
| 1788 | EXPECT_EQUAL(Fract(a), "fract(a)"); |
| 1789 | EXPECT_EQUAL(GreaterThan(a, b), "greaterThan(a, b)"); |
| 1790 | EXPECT_EQUAL(GreaterThanEqual(a, b), "greaterThanEqual(a, b)"); |
| 1791 | EXPECT_EQUAL(Inversesqrt(a), "inversesqrt(a)"); |
| 1792 | EXPECT_EQUAL(LessThan(a, b), "lessThan(a, b)"); |
| 1793 | EXPECT_EQUAL(LessThanEqual(a, b), "lessThanEqual(a, b)"); |
| 1794 | EXPECT_EQUAL(Length(a), "length(a)"); |
| 1795 | EXPECT_EQUAL(Log(a), "log(a)"); |
| 1796 | EXPECT_EQUAL(Log2(a), "log2(a)"); |
| 1797 | EXPECT_EQUAL(Max(a, b), "max(a, b)"); |
| 1798 | EXPECT_EQUAL(Min(a, b), "min(a, b)"); |
| 1799 | EXPECT_EQUAL(Mix(a, b, c), "mix(a, b, c)"); |
| 1800 | EXPECT_EQUAL(Mod(a, b), "mod(a, b)"); |
| 1801 | EXPECT_EQUAL(Normalize(a), "normalize(a)"); |
| 1802 | EXPECT_EQUAL(NotEqual(a, b), "notEqual(a, b)"); |
| 1803 | EXPECT_EQUAL(Pow(a, b), "pow(a, b)"); |
| 1804 | EXPECT_EQUAL(Radians(a), "radians(a)"); |
| 1805 | EXPECT_EQUAL(Reflect(a, b), "reflect(a, b)"); |
| 1806 | EXPECT_EQUAL(Refract(a, b, 1), "refract(a, b, 1.0)"); |
| 1807 | EXPECT_EQUAL(Saturate(a), "saturate(a)"); |
| 1808 | EXPECT_EQUAL(Sign(a), "sign(a)"); |
| 1809 | EXPECT_EQUAL(Sin(a), "sin(a)"); |
| 1810 | EXPECT_EQUAL(Smoothstep(a, b, c), "smoothstep(a, b, c)"); |
| 1811 | EXPECT_EQUAL(Sqrt(a), "sqrt(a)"); |
| 1812 | EXPECT_EQUAL(Step(a, b), "step(a, b)"); |
| 1813 | EXPECT_EQUAL(Tan(a), "tan(a)"); |
| 1814 | EXPECT_EQUAL(Unpremul(a), "unpremul(a)"); |
Ethan Nicholas | 30e93d5 | 2021-01-26 12:00:25 -0500 | [diff] [blame] | 1815 | |
| 1816 | // these calls all go through the normal channels, so it ought to be sufficient to prove that |
| 1817 | // one of them reports errors correctly |
| 1818 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1819 | ExpectError error(r, "no match for ceil(bool)"); |
Ethan Nicholas | 30e93d5 | 2021-01-26 12:00:25 -0500 | [diff] [blame] | 1820 | Ceil(a == b).release(); |
| 1821 | } |
| 1822 | } |
Ethan Nicholas | d6b26e5 | 2021-01-27 07:53:46 -0500 | [diff] [blame] | 1823 | |
| 1824 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLModifiers, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1825 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | d6b26e5 | 2021-01-27 07:53:46 -0500 | [diff] [blame] | 1826 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1827 | Var v1(kConst_Modifier, kInt_Type, "v1", 0); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1828 | Statement d1 = Declare(v1); |
Ethan Nicholas | bd97400 | 2021-02-22 16:20:06 -0500 | [diff] [blame] | 1829 | EXPECT_EQUAL(d1, "const int v1 = 0;"); |
Ethan Nicholas | d6b26e5 | 2021-01-27 07:53:46 -0500 | [diff] [blame] | 1830 | |
| 1831 | // Most modifiers require an appropriate context to be legal. We can't yet give them that |
| 1832 | // context, so we can't as yet Declare() variables with these modifiers. |
| 1833 | // TODO: better tests when able |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1834 | Var v2(kIn_Modifier, kInt_Type, "v2"); |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1835 | REPORTER_ASSERT(r, v2.modifiers().flags() == SkSL::Modifiers::kIn_Flag); |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1836 | DSLWriter::MarkDeclared(v2); |
Ethan Nicholas | d6b26e5 | 2021-01-27 07:53:46 -0500 | [diff] [blame] | 1837 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1838 | Var v3(kOut_Modifier, kInt_Type, "v3"); |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1839 | REPORTER_ASSERT(r, v3.modifiers().flags() == SkSL::Modifiers::kOut_Flag); |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1840 | DSLWriter::MarkDeclared(v3); |
Ethan Nicholas | d6b26e5 | 2021-01-27 07:53:46 -0500 | [diff] [blame] | 1841 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1842 | Var v4(kFlat_Modifier, kInt_Type, "v4"); |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1843 | REPORTER_ASSERT(r, v4.modifiers().flags() == SkSL::Modifiers::kFlat_Flag); |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1844 | DSLWriter::MarkDeclared(v4); |
Ethan Nicholas | d6b26e5 | 2021-01-27 07:53:46 -0500 | [diff] [blame] | 1845 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1846 | Var v5(kNoPerspective_Modifier, kInt_Type, "v5"); |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1847 | REPORTER_ASSERT(r, v5.modifiers().flags() == SkSL::Modifiers::kNoPerspective_Flag); |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1848 | DSLWriter::MarkDeclared(v5); |
Ethan Nicholas | d6b26e5 | 2021-01-27 07:53:46 -0500 | [diff] [blame] | 1849 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1850 | Var v6(kIn_Modifier | kOut_Modifier, kInt_Type, "v6"); |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1851 | REPORTER_ASSERT(r, v6.modifiers().flags() == (SkSL::Modifiers::kIn_Flag | |
| 1852 | SkSL::Modifiers::kOut_Flag)); |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1853 | DSLWriter::MarkDeclared(v6); |
Ethan Nicholas | 11a15b1 | 2021-02-11 15:56:27 -0500 | [diff] [blame] | 1854 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1855 | Var v7(kInOut_Modifier, kInt_Type, "v7"); |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1856 | REPORTER_ASSERT(r, v7.modifiers().flags() == (SkSL::Modifiers::kIn_Flag | |
| 1857 | SkSL::Modifiers::kOut_Flag)); |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1858 | DSLWriter::MarkDeclared(v7); |
Ethan Nicholas | d6b26e5 | 2021-01-27 07:53:46 -0500 | [diff] [blame] | 1859 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1860 | Var v8(kUniform_Modifier, kInt_Type, "v8"); |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1861 | REPORTER_ASSERT(r, v8.modifiers().flags() == SkSL::Modifiers::kUniform_Flag); |
Ethan Nicholas | e9c2c5a | 2021-04-30 13:14:24 -0400 | [diff] [blame] | 1862 | DSLWriter::MarkDeclared(v8); |
Ethan Nicholas | 961d944 | 2021-03-16 16:37:29 -0400 | [diff] [blame] | 1863 | // Uniforms do not need to be explicitly declared |
Ethan Nicholas | d6b26e5 | 2021-01-27 07:53:46 -0500 | [diff] [blame] | 1864 | } |
Ethan Nicholas | bf79dff | 2021-02-11 15:18:31 -0500 | [diff] [blame] | 1865 | |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1866 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLLayout, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1867 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1868 | Var v1(DSLModifiers(DSLLayout().location(1).set(2).binding(3).offset(4).index(5).builtin(6) |
| 1869 | .inputAttachmentIndex(7), |
| 1870 | kConst_Modifier), kInt_Type, "v1", 0); |
| 1871 | EXPECT_EQUAL(Declare(v1), "layout (location = 1, offset = 4, binding = 3, index = 5, set = 2, " |
| 1872 | "builtin = 6, input_attachment_index = 7) const int v1 = 0;"); |
| 1873 | |
| 1874 | Var v2(DSLLayout().originUpperLeft(), kFloat2_Type, "v2"); |
| 1875 | EXPECT_EQUAL(Declare(v2), "layout (origin_upper_left) float2 v2;"); |
| 1876 | |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1877 | Var v4(DSLLayout().pushConstant(), kBool_Type, "v4"); |
| 1878 | EXPECT_EQUAL(Declare(v4), "layout (push_constant) bool v4;"); |
| 1879 | |
| 1880 | Var v5(DSLLayout().blendSupportAllEquations(), kHalf4_Type, "v5"); |
| 1881 | EXPECT_EQUAL(Declare(v5), "layout (blend_support_all_equations) half4 v5;"); |
| 1882 | |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1883 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1884 | ExpectError error(r, "'srgb_unpremul' is only permitted in runtime effects"); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 1885 | DSLGlobalVar v(DSLModifiers(DSLLayout().srgbUnpremul(), kUniform_Modifier), kHalf4_Type, |
| 1886 | "v"); |
| 1887 | Declare(v); |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 1888 | } |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1889 | |
| 1890 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1891 | ExpectError error(r, "layout qualifier 'location' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1892 | DSLLayout().location(1).location(2); |
| 1893 | } |
| 1894 | |
| 1895 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1896 | ExpectError error(r, "layout qualifier 'set' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1897 | DSLLayout().set(1).set(2); |
| 1898 | } |
| 1899 | |
| 1900 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1901 | ExpectError error(r, "layout qualifier 'binding' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1902 | DSLLayout().binding(1).binding(2); |
| 1903 | } |
| 1904 | |
| 1905 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1906 | ExpectError error(r, "layout qualifier 'offset' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1907 | DSLLayout().offset(1).offset(2); |
| 1908 | } |
| 1909 | |
| 1910 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1911 | ExpectError error(r, "layout qualifier 'index' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1912 | DSLLayout().index(1).index(2); |
| 1913 | } |
| 1914 | |
| 1915 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1916 | ExpectError error(r, "layout qualifier 'builtin' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1917 | DSLLayout().builtin(1).builtin(2); |
| 1918 | } |
| 1919 | |
| 1920 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1921 | ExpectError error(r, "layout qualifier 'input_attachment_index' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1922 | DSLLayout().inputAttachmentIndex(1).inputAttachmentIndex(2); |
| 1923 | } |
| 1924 | |
| 1925 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1926 | ExpectError error(r, "layout qualifier 'origin_upper_left' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1927 | DSLLayout().originUpperLeft().originUpperLeft(); |
| 1928 | } |
| 1929 | |
| 1930 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1931 | ExpectError error(r, "layout qualifier 'push_constant' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1932 | DSLLayout().pushConstant().pushConstant(); |
| 1933 | } |
| 1934 | |
| 1935 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1936 | ExpectError error(r, "layout qualifier 'blend_support_all_equations' appears more than " |
| 1937 | "once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1938 | DSLLayout().blendSupportAllEquations().blendSupportAllEquations(); |
| 1939 | } |
| 1940 | |
| 1941 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1942 | ExpectError error(r, "layout qualifier 'srgb_unpremul' appears more than once"); |
Ethan Nicholas | b22fcaf | 2021-05-10 16:17:22 -0400 | [diff] [blame] | 1943 | DSLLayout().srgbUnpremul().srgbUnpremul(); |
| 1944 | } |
| 1945 | } |
| 1946 | |
Ethan Nicholas | 624a529 | 2021-04-16 14:54:43 -0400 | [diff] [blame] | 1947 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLSampleShader, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1948 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), default_settings(), |
Brian Osman | 552fcb9 | 2021-04-28 17:41:57 -0400 | [diff] [blame] | 1949 | SkSL::ProgramKind::kRuntimeShader); |
Brian Osman | f8a5504 | 2021-08-23 16:24:18 -0400 | [diff] [blame] | 1950 | DSLGlobalVar shader(kUniform_Modifier, kShader_Type, "child"); |
Brian Osman | cbfa34a | 2021-09-02 09:26:27 -0400 | [diff] [blame^] | 1951 | EXPECT_EQUAL(Sample(shader, Float2(0, 0)), "child.eval(float2(0.0, 0.0))"); |
Ethan Nicholas | 624a529 | 2021-04-16 14:54:43 -0400 | [diff] [blame] | 1952 | |
| 1953 | { |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 1954 | ExpectError error(r, "no match for sample(shader, half4)"); |
Ethan Nicholas | 624a529 | 2021-04-16 14:54:43 -0400 | [diff] [blame] | 1955 | Sample(shader, Half4(1)).release(); |
| 1956 | } |
| 1957 | } |
| 1958 | |
Ethan Nicholas | bf79dff | 2021-02-11 15:18:31 -0500 | [diff] [blame] | 1959 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLStruct, r, ctxInfo) { |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 1960 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | bf79dff | 2021-02-11 15:18:31 -0500 | [diff] [blame] | 1961 | |
| 1962 | DSLType simpleStruct = Struct("SimpleStruct", |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1963 | Field(kFloat_Type, "x"), |
| 1964 | Field(kBool_Type, "b"), |
| 1965 | Field(Array(kFloat_Type, 3), "a") |
Ethan Nicholas | bf79dff | 2021-02-11 15:18:31 -0500 | [diff] [blame] | 1966 | ); |
| 1967 | DSLVar result(simpleStruct, "result"); |
| 1968 | DSLFunction(simpleStruct, "returnStruct").define( |
| 1969 | Declare(result), |
| 1970 | result.field("x") = 123, |
| 1971 | result.field("b") = result.field("x") > 0, |
| 1972 | result.field("a")[0] = result.field("x"), |
| 1973 | Return(result) |
| 1974 | ); |
| 1975 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 2); |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1976 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], |
| 1977 | "struct SimpleStruct { float x; bool b; float[3] a; };"); |
| 1978 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[1], |
| 1979 | "SimpleStruct returnStruct() { SimpleStruct result; (result.x = 123.0);" |
| 1980 | "(result.b = (result.x > 0.0)); (result.a[0] = result.x); return result; }"); |
Ethan Nicholas | bf79dff | 2021-02-11 15:18:31 -0500 | [diff] [blame] | 1981 | |
Ethan Nicholas | bf79dff | 2021-02-11 15:18:31 -0500 | [diff] [blame] | 1982 | Struct("NestedStruct", |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 1983 | Field(kInt_Type, "x"), |
Ethan Nicholas | bf79dff | 2021-02-11 15:18:31 -0500 | [diff] [blame] | 1984 | Field(simpleStruct, "simple") |
| 1985 | ); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 1986 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 3); |
| 1987 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[2], |
John Stiles | b4d7b58 | 2021-02-19 09:56:31 -0500 | [diff] [blame] | 1988 | "struct NestedStruct { int x; SimpleStruct simple; };"); |
Ethan Nicholas | bf79dff | 2021-02-11 15:18:31 -0500 | [diff] [blame] | 1989 | } |
Ethan Nicholas | a1a0b92 | 2021-05-04 12:22:02 -0400 | [diff] [blame] | 1990 | |
| 1991 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLWrapper, r, ctxInfo) { |
| 1992 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu()); |
| 1993 | std::vector<Wrapper<DSLExpression>> exprs; |
| 1994 | exprs.push_back(DSLExpression(1)); |
| 1995 | exprs.emplace_back(2.0); |
| 1996 | EXPECT_EQUAL(std::move(*exprs[0]), "1"); |
| 1997 | EXPECT_EQUAL(std::move(*exprs[1]), "2.0"); |
| 1998 | |
| 1999 | std::vector<Wrapper<DSLVar>> vars; |
| 2000 | vars.emplace_back(DSLVar(kInt_Type, "x")); |
Ethan Nicholas | b4f8b7a | 2021-06-23 10:27:09 -0400 | [diff] [blame] | 2001 | REPORTER_ASSERT(r, DSLWriter::Var(*vars[0])->name() == "x"); |
Ethan Nicholas | a1a0b92 | 2021-05-04 12:22:02 -0400 | [diff] [blame] | 2002 | } |
Ethan Nicholas | ebc9fad | 2021-07-09 15:35:23 -0400 | [diff] [blame] | 2003 | |
| 2004 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLRTAdjust, r, ctxInfo) { |
Ethan Nicholas | 494eb3e | 2021-08-27 19:17:01 -0400 | [diff] [blame] | 2005 | { |
| 2006 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(), |
| 2007 | SkSL::ProgramKind::kVertex); |
| 2008 | DSLGlobalVar rtAdjust(kUniform_Modifier, kFloat4_Type, "sk_RTAdjust"); |
| 2009 | Declare(rtAdjust); |
| 2010 | DSLFunction(kVoid_Type, "main").define( |
| 2011 | sk_Position() = Half4(0) |
| 2012 | ); |
| 2013 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 2); |
| 2014 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[1], |
| 2015 | "void main() {" |
| 2016 | "(sk_PerVertex.sk_Position = float4(0.0));" |
| 2017 | "(sk_PerVertex.sk_Position = float4(((sk_PerVertex.sk_Position.xy * sk_RTAdjust.xz) + " |
| 2018 | "(sk_PerVertex.sk_Position.ww * sk_RTAdjust.yw)), 0.0, sk_PerVertex.sk_Position.w));" |
| 2019 | "}"); |
| 2020 | } |
| 2021 | |
| 2022 | { |
| 2023 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(), |
| 2024 | SkSL::ProgramKind::kVertex); |
| 2025 | REPORTER_ASSERT(r, !DSLWriter::IRGenerator().haveRTAdjustInterfaceBlock()); |
| 2026 | |
| 2027 | DSLGlobalVar intf = InterfaceBlock(kUniform_Modifier, "uniforms", |
| 2028 | { Field(kInt_Type, "unused"), |
| 2029 | Field(kFloat4_Type, "sk_RTAdjust") }); |
| 2030 | REPORTER_ASSERT(r, DSLWriter::IRGenerator().haveRTAdjustInterfaceBlock()); |
| 2031 | REPORTER_ASSERT(r, DSLWriter::IRGenerator().getRTAdjustFieldIndex() == 1); |
| 2032 | } |
| 2033 | |
| 2034 | { |
| 2035 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(), |
| 2036 | SkSL::ProgramKind::kVertex); |
| 2037 | ExpectError error(r, "sk_RTAdjust must have type 'float4'"); |
| 2038 | InterfaceBlock(kUniform_Modifier, "uniforms", |
| 2039 | { Field(kInt_Type, "unused"), Field(kHalf4_Type, "sk_RTAdjust") }); |
| 2040 | } |
| 2041 | |
| 2042 | { |
| 2043 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(), |
| 2044 | SkSL::ProgramKind::kVertex); |
| 2045 | ExpectError error(r, "symbol 'sk_RTAdjust' was already defined"); |
| 2046 | InterfaceBlock(kUniform_Modifier, "uniforms1", |
| 2047 | { Field(kInt_Type, "unused1"), Field(kFloat4_Type, "sk_RTAdjust") }); |
| 2048 | InterfaceBlock(kUniform_Modifier, "uniforms2", |
| 2049 | { Field(kInt_Type, "unused2"), Field(kFloat4_Type, "sk_RTAdjust") }); |
| 2050 | } |
Ethan Nicholas | ebc9fad | 2021-07-09 15:35:23 -0400 | [diff] [blame] | 2051 | } |
Ethan Nicholas | 292a09d | 2021-07-14 09:52:16 -0400 | [diff] [blame] | 2052 | |
| 2053 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLInlining, r, ctxInfo) { |
| 2054 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 2055 | DSLParameter x(kFloat_Type, "x"); |
Ethan Nicholas | 292a09d | 2021-07-14 09:52:16 -0400 | [diff] [blame] | 2056 | DSLFunction sqr(kFloat_Type, "sqr", x); |
| 2057 | sqr.define( |
| 2058 | Return(x * x) |
| 2059 | ); |
| 2060 | DSLFunction(kVoid_Type, "main").define( |
| 2061 | sk_FragColor() = (sqr(2), Half4(sqr(3))) |
| 2062 | ); |
Ethan Nicholas | b18c1e2 | 2021-07-16 09:53:53 -0400 | [diff] [blame] | 2063 | const char* source = "source test"; |
| 2064 | std::unique_ptr<SkSL::Program> program = ReleaseProgram(std::make_unique<SkSL::String>(source)); |
Ethan Nicholas | 292a09d | 2021-07-14 09:52:16 -0400 | [diff] [blame] | 2065 | EXPECT_EQUAL(*program, |
| 2066 | "layout(location = 0, index = 0, builtin = 10001) out half4 sk_FragColor;" |
| 2067 | "layout(builtin = 17)in bool sk_Clockwise;" |
| 2068 | "void main() {" |
| 2069 | "/* inlined: sqr */;" |
| 2070 | "/* inlined: sqr */;" |
| 2071 | "(sk_FragColor = (4.0 , half4(half(9.0))));" |
| 2072 | "}"); |
Ethan Nicholas | b18c1e2 | 2021-07-16 09:53:53 -0400 | [diff] [blame] | 2073 | REPORTER_ASSERT(r, *program->fSource == source); |
Ethan Nicholas | 292a09d | 2021-07-14 09:52:16 -0400 | [diff] [blame] | 2074 | } |
Ethan Nicholas | 459777a | 2021-07-16 11:16:27 -0400 | [diff] [blame] | 2075 | |
| 2076 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLReleaseUnused, r, ctxInfo) { |
| 2077 | SkSL::ProgramSettings settings = default_settings(); |
| 2078 | settings.fAssertDSLObjectsReleased = false; |
| 2079 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), settings); |
| 2080 | If(Sqrt(1) > 0, Discard()); |
| 2081 | // Ensure that we can safely destroy statements and expressions despite being unused while |
| 2082 | // settings.fAssertDSLObjectsReleased is disabled. |
| 2083 | } |
Ethan Nicholas | 57709e1 | 2021-08-10 15:02:51 -0400 | [diff] [blame] | 2084 | |
| 2085 | DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLPrototypes, r, ctxInfo) { |
| 2086 | AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared()); |
| 2087 | { |
| 2088 | DSLParameter x(kFloat_Type, "x"); |
| 2089 | DSLFunction sqr(kFloat_Type, "sqr", x); |
| 2090 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1); |
| 2091 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], "float sqr(float x);"); |
| 2092 | sqr.define( |
| 2093 | Return(x * x) |
| 2094 | ); |
| 2095 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1); |
| 2096 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], "float sqr(float x) { return (x * x); }"); |
| 2097 | } |
| 2098 | |
| 2099 | { |
| 2100 | DSLWriter::Reset(); |
| 2101 | DSLParameter x(kFloat_Type, "x"); |
| 2102 | DSLFunction sqr(kFloat_Type, "sqr", x); |
| 2103 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1); |
| 2104 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], "float sqr(float x);"); |
| 2105 | DSLFunction(kVoid_Type, "main").define(sqr(5)); |
| 2106 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 2); |
| 2107 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], "float sqr(float x);"); |
| 2108 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[1], "void main() { sqr(5.0); }"); |
| 2109 | sqr.define( |
| 2110 | Return(x * x) |
| 2111 | ); |
| 2112 | REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 3); |
| 2113 | EXPECT_EQUAL(*DSLWriter::ProgramElements()[2], "float sqr(float x) { return (x * x); }"); |
| 2114 | |
| 2115 | const char* source = "source test"; |
| 2116 | std::unique_ptr<SkSL::Program> p = ReleaseProgram(std::make_unique<SkSL::String>(source)); |
| 2117 | EXPECT_EQUAL(*p, |
| 2118 | "layout (builtin = 17) in bool sk_Clockwise;" |
| 2119 | "float sqr(float x);" |
| 2120 | "void main() {" |
| 2121 | "/* inlined: sqr */;" |
| 2122 | "25.0;" |
| 2123 | "}"); |
| 2124 | } |
| 2125 | } |