Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Functions | Variables
runtimeintrinsics.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkData.h"
#include "include/core/SkFont.h"
#include "include/core/SkPaint.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkImageFilters.h"
#include "include/effects/SkRuntimeEffect.h"
#include "src/base/SkRandom.h"
#include "src/core/SkRuntimeEffectPriv.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Macros

#define SKSL_MATRIX_SELECTORS
 

Functions

static void next_column (SkCanvas *canvas)
 
static void next_row (SkCanvas *canvas)
 
static constexpr int columns_to_width (int columns)
 
static constexpr int rows_to_height (int rows)
 
static void draw_label (SkCanvas *canvas, const char *label)
 
static SkBitmap draw_shader (SkCanvas *canvas, sk_sp< SkShader > shader, bool allowRasterFallback=true)
 
static SkString make_unary_sksl_1d (const char *fn, bool requireES3)
 
static void plot (SkCanvas *canvas, const char *fn, float xMin, float xMax, float yMin, float yMax, const char *label=nullptr, bool requireES3=false)
 
static void plot_es3 (SkCanvas *canvas, const char *fn, float xMin, float xMax, float yMin, float yMax, const char *label=nullptr)
 
 DEF_SIMPLE_GM (runtime_intrinsics_trig, canvas, columns_to_width(3), rows_to_height(5))
 
 DEF_SIMPLE_GPU_GM_CAN_FAIL (runtime_intrinsics_trig_es3, ctx, canvas, errorMsg, columns_to_width(3), rows_to_height(2))
 
 DEF_SIMPLE_GM (runtime_intrinsics_exponential, canvas, columns_to_width(2), rows_to_height(5))
 
 DEF_SIMPLE_GM (runtime_intrinsics_common, canvas, columns_to_width(6), rows_to_height(7))
 
 DEF_SIMPLE_GPU_GM_CAN_FAIL (runtime_intrinsics_common_es3, ctx, canvas, errorMsg, columns_to_width(6), rows_to_height(5))
 
 DEF_SIMPLE_GM (runtime_intrinsics_geometric, canvas, columns_to_width(4), rows_to_height(5))
 
static SkString make_matrix_comp_mult_sksl (int dim)
 
template<int N>
static void plot_matrix_comp_mult (SkCanvas *canvas, std::array< float, N *N > mtx1, std::array< float, N *N > mtx2, const char *label)
 
static SkString make_matrix_inverse_sksl (int dim)
 
template<int N>
static void plot_matrix_inverse (SkCanvas *canvas, std::array< float, N *N > mtx, const char *label)
 
 DEF_SIMPLE_GM (runtime_intrinsics_matrix, canvas, columns_to_width(3), rows_to_height(2))
 
static SkString make_bvec_sksl (const char *type, const char *fn)
 
template<typename T = float>
static void plot_bvec (SkCanvas *canvas, const char *fn, const char *label)
 
 DEF_SIMPLE_GM (runtime_intrinsics_relational, canvas, columns_to_width(4), rows_to_height(6))
 

Variables

static constexpr int kBoxSize = 100
 
static constexpr int kPadding = 5
 
static constexpr int kLabelHeight = 15
 

Macro Definition Documentation

◆ SKSL_MATRIX_SELECTORS

#define SKSL_MATRIX_SELECTORS
Value:
"inline float2 sel2(float x) {" \
" return float2(" \
" x < 0.5 ? 1 : 0," \
" x >= 0.5 ? 1 : 0);" \
"}" \
"inline float3 sel3(float x) {" \
" return float3(" \
" x < 0.33 ? 1 : 0," \
" x >= 0.33 && x < 0.66 ? 1 : 0," \
" x >= 0.66 ? 1 : 0);" \
"}" \
"inline float4 sel4(float x) {" \
" return float4(" \
" x < 0.25 ? 1 : 0," \
" x >= 0.25 && x < 0.5 ? 1 : 0," \
" x >= 0.5 && x < 0.75 ? 1 : 0," \
" x >= 0.75 ? 1 : 0);" \
"}"

Definition at line 411 of file runtimeintrinsics.cpp.

412 {" \
413 " return float2(" \
414 " x < 0.5 ? 1 : 0," \
415 " x >= 0.5 ? 1 : 0);" \
416 "}" \
417 "inline float3 sel3(float x) {" \
418 " return float3(" \
419 " x < 0.33 ? 1 : 0," \
420 " x >= 0.33 && x < 0.66 ? 1 : 0," \
421 " x >= 0.66 ? 1 : 0);" \
422 "}" \
423 "inline float4 sel4(float x) {" \
424 " return float4(" \
425 " x < 0.25 ? 1 : 0," \
426 " x >= 0.25 && x < 0.5 ? 1 : 0," \
427 " x >= 0.5 && x < 0.75 ? 1 : 0," \
428 " x >= 0.75 ? 1 : 0);" \
429 "}"
skvx::float4 float4
skvx::float2 float2
double x

Function Documentation

◆ columns_to_width()

static constexpr int columns_to_width ( int  columns)
staticconstexpr

Definition at line 42 of file runtimeintrinsics.cpp.

42 {
43 return (kPadding + kBoxSize) * columns + kPadding;
44}
static constexpr int kPadding
static constexpr int kBoxSize

◆ DEF_SIMPLE_GM() [1/6]

DEF_SIMPLE_GM ( runtime_intrinsics_common  ,
canvas  ,
columns_to_width(6)  ,
rows_to_height(7)   
)

Definition at line 262 of file runtimeintrinsics.cpp.

265 {
266 canvas->translate(kPadding, kPadding);
267 canvas->save();
268
269 plot(canvas, "abs(x)", -10.0f, 10.0f, 0.0f, 10.0f);
270 plot(canvas, "sign(x)", -1.0f, 1.0f, -1.5f, 1.5f);
271 next_row(canvas);
272
273 plot(canvas, "floor(x)", -3.0f, 3.0f, -4.0f, 4.0f);
274 plot(canvas, "ceil(x)", -3.0f, 3.0f, -4.0f, 4.0f);
275 plot(canvas, "fract(x)", -3.0f, 3.0f, 0.0f, 1.0f);
276 plot(canvas, "mod(x, 2)", -4.0f, 4.0f, -2.0f, 2.0f, "mod(scalar)");
277 plot(canvas, "mod(p, -2).x", -4.0f, 4.0f, -2.0f, 2.0f, "mod(mixed)" );
278 plot(canvas, "mod(p, v2).x", -4.0f, 4.0f, -2.0f, 2.0f, "mod(vector)");
279 next_row(canvas);
280
281 plot(canvas, "min(x, 1)", 0.0f, 2.0f, 0.0f, 2.0f, "min(scalar)");
282 plot(canvas, "min(p, 1).x", 0.0f, 2.0f, 0.0f, 2.0f, "min(mixed)" );
283 plot(canvas, "min(p, v1).x", 0.0f, 2.0f, 0.0f, 2.0f, "min(vector)");
284 plot(canvas, "max(x, 1)", 0.0f, 2.0f, 0.0f, 2.0f, "max(scalar)");
285 plot(canvas, "max(p, 1).x", 0.0f, 2.0f, 0.0f, 2.0f, "max(mixed)" );
286 plot(canvas, "max(p, v1).x", 0.0f, 2.0f, 0.0f, 2.0f, "max(vector)");
287 next_row(canvas);
288
289 plot(canvas, "clamp(x, 1, 2)", 0.0f, 3.0f, 0.0f, 3.0f, "clamp(scalar)");
290 plot(canvas, "clamp(p, 1, 2).x", 0.0f, 3.0f, 0.0f, 3.0f, "clamp(mixed)" );
291 plot(canvas, "clamp(p, v1, v2).x", 0.0f, 3.0f, 0.0f, 3.0f, "clamp(vector)");
292 plot(canvas, "saturate(x)", -1.0f, 2.0f, -0.5f, 1.5f);
293 next_row(canvas);
294
295 plot(canvas, "mix(1, 2, x)", -1.0f, 2.0f, 0.0f, 3.0f, "mix(scalar)");
296 plot(canvas, "mix(v1, v2, x).x", -1.0f, 2.0f, 0.0f, 3.0f, "mix(mixed)" );
297 plot(canvas, "mix(v1, v2, p).x", -1.0f, 2.0f, 0.0f, 3.0f, "mix(vector)");
298 next_row(canvas);
299
300 plot(canvas, "step(1, x)", 0.0f, 2.0f, -0.5f, 1.5f, "step(scalar)");
301 plot(canvas, "step(1, p).x", 0.0f, 2.0f, -0.5f, 1.5f, "step(mixed)" );
302 plot(canvas, "step(v1, p).x", 0.0f, 2.0f, -0.5f, 1.5f, "step(vector)");
303 plot(canvas, "smoothstep(1, 2, x)", 0.5f, 2.5f, -0.5f, 1.5f, "smooth(scalar)");
304 plot(canvas, "smoothstep(1, 2, p).x", 0.5f, 2.5f, -0.5f, 1.5f, "smooth(mixed)" );
305 plot(canvas, "smoothstep(v1, v2, p).x", 0.5f, 2.5f, -0.5f, 1.5f, "smooth(vector)");
306 next_row(canvas);
307
308 plot(canvas, "floor(p).x", -3.0f, 3.0f, -4.0f, 4.0f);
309 plot(canvas, "ceil(p).x", -3.0f, 3.0f, -4.0f, 4.0f);
310 plot(canvas, "floor(p).y", -3.0f, 3.0f, -4.0f, 4.0f);
311 plot(canvas, "ceil(p).y", -3.0f, 3.0f, -4.0f, 4.0f);
312 next_row(canvas);
313}
static void next_row(SkCanvas *canvas)
static void plot(SkCanvas *canvas, const char *fn, float xMin, float xMax, float yMin, float yMax, const char *label=nullptr, bool requireES3=false)

◆ DEF_SIMPLE_GM() [2/6]

DEF_SIMPLE_GM ( runtime_intrinsics_exponential  ,
canvas  ,
columns_to_width(2)  ,
rows_to_height(5)   
)

Definition at line 233 of file runtimeintrinsics.cpp.

236 {
237 canvas->translate(kPadding, kPadding);
238 canvas->save();
239
240 plot(canvas, "pow(x, 3)", 0.0f, 8.0f, 0.0f, 500.0f);
241 plot(canvas, "pow(x, -3)", 0.0f, 4.0f, 0.0f, 10.0f);
242 next_row(canvas);
243
244 plot(canvas, "pow(0.9, x)", -10.0f, 10.0f, 0.0f, 3.0f);
245 plot(canvas, "pow(1.1, x)", -10.0f, 10.0f, 0.0f, 3.0f);
246 next_row(canvas);
247
248 plot(canvas, "exp(x)", -1.0f, 7.0f, 0.0f, 1000.0f);
249 plot(canvas, "log(x)", 0.0f, 2.5f, -4.0f, 1.0f);
250 next_row(canvas);
251
252 plot(canvas, "exp2(x)", -1.0f, 7.0f, 0.0f, 130.0f);
253 plot(canvas, "log2(x)", 0.0f, 4.0f, -4.0f, 2.0f);
254 next_row(canvas);
255
256 plot(canvas, "sqrt(x)", 0.0f, 25.0f, 0.0f, 5.0f);
257 plot(canvas, "inversesqrt(x)", 0.0f, 25.0f, 0.2f, 4.0f);
258 next_row(canvas);
259}

◆ DEF_SIMPLE_GM() [3/6]

DEF_SIMPLE_GM ( runtime_intrinsics_geometric  ,
canvas  ,
columns_to_width(4)  ,
rows_to_height(5)   
)

Definition at line 376 of file runtimeintrinsics.cpp.

379 {
380 canvas->translate(kPadding, kPadding);
381 canvas->save();
382
383 plot(canvas, "length(x)", -1.0f, 1.0f, -0.5f, 1.5f);
384 plot(canvas, "length(p)", 0.0f, 1.0f, 0.5f, 1.5f);
385 plot(canvas, "distance(x, 0)", -1.0f, 1.0f, -0.5f, 1.5f);
386 plot(canvas, "distance(p, v1)", 0.0f, 1.0f, 0.5f, 1.5f);
387 next_row(canvas);
388
389 plot(canvas, "dot(x, 2)", -1.0f, 1.0f, -2.5f, 2.5f);
390 plot(canvas, "dot(p, p.y1)", -1.0f, 1.0f, -2.5f, 0.5f);
391 next_row(canvas);
392
393 plot(canvas, "cross(p.xy1, p.y1x).x", 0.0f, 1.0f, -1.0f, 1.0f);
394 plot(canvas, "cross(p.xy1, p.y1x).y", 0.0f, 1.0f, -1.0f, 1.0f);
395 plot(canvas, "cross(p.xy1, p.y1x).z", 0.0f, 1.0f, -1.0f, 1.0f);
396 next_row(canvas);
397
398 plot(canvas, "normalize(x)", -2.0f, 2.0f, -1.5f, 1.5f);
399 plot(canvas, "normalize(p).x", 0.0f, 2.0f, 0.0f, 1.0f);
400 plot(canvas, "normalize(p).y", 0.0f, 2.0f, 0.0f, 1.0f);
401 plot(canvas, "faceforward(v1, p.x0, v1.x0).x", -1.0f, 1.0f, -1.5f, 1.5f, "faceforward");
402 next_row(canvas);
403
404 plot(canvas, "reflect(p.x1, v1.0x).x", -1.0f, 1.0f, -1.0f, 1.0f, "reflect(horiz)");
405 plot(canvas, "reflect(p.x1, normalize(v1)).y", -1.0f, 1.0f, -1.0f, 1.0f, "reflect(diag)" );
406 plot(canvas, "refract(v1.x0, v1.0x, x).x", 0.0f, 1.0f, -1.0f, 1.0f, "refract().x");
407 plot(canvas, "refract(v1.x0, v1.0x, x).y", 0.0f, 1.0f, -1.0f, 1.0f, "refract().y");
408 next_row(canvas);
409}

◆ DEF_SIMPLE_GM() [4/6]

DEF_SIMPLE_GM ( runtime_intrinsics_matrix  ,
canvas  ,
columns_to_width(3)  ,
rows_to_height(2)   
)

Definition at line 510 of file runtimeintrinsics.cpp.

513 {
514 canvas->translate(kPadding, kPadding);
515 canvas->save();
516
517 // Random pairs of matrices where the elements of matrixCompMult(m1, m2) lie in [0, 1]
518 plot_matrix_comp_mult<2>(canvas,
519 {1.00f, 0.0f, 2.0f, 0.5f},
520 {0.75f, 2.0f, 0.2f, 1.2f},
521 "compMult(2x2)");
522
523 plot_matrix_comp_mult<3>(canvas,
524 {1.00f, 0.0f, 2.0f, 0.5f, -1.0f, -2.0f, -0.5f, 4.00f, 0.25f},
525 {0.75f, 2.0f, 0.2f, 1.2f, -0.8f, -0.1f, -1.8f, 0.25f, 2.00f},
526 "compMult(3x3)");
527
528 plot_matrix_comp_mult<4>(canvas,
529 {1.00f, 0.0f, 2.0f, 0.5f, -1.0f, -2.0f, -0.5f, 4.00f, 0.25f, 0.05f,
530 10.00f, -0.66f, -1.0f, -0.5f, 0.5f, 0.66f},
531 {0.75f, 2.0f, 0.2f, 1.2f, -0.8f, -0.1f, -1.8f, 0.25f, 2.00f, 2.00f,
532 0.03f, -1.00f, -1.0f, -0.5f, 1.7f, 0.66f},
533 "compMult(4x4)");
534 next_row(canvas);
535
536 // Random, invertible matrices where the elements of inverse(m) lie in [-1, 1]
537 plot_matrix_inverse<2>(canvas,
538 { 1.20f, 0.68f,
539 -0.27f, -1.55f},
540 "inverse(2x2)");
541
542 plot_matrix_inverse<3>(canvas,
543 {-1.13f, -2.96f, -0.14f,
544 1.45f, -1.88f, -1.02f,
545 -2.54f, -2.58f, -1.17f},
546 "inverse(3x3)");
547
548 plot_matrix_inverse<4>(canvas,
549 {-1.51f, -3.95f, -0.19f, 1.93f,
550 -2.51f, -1.35f, -3.39f, -3.45f,
551 -1.56f, 1.61f, -0.22f, -1.08f,
552 -2.81f, -2.14f, -0.09f, 3.00f},
553 "inverse(4x4)");
554 next_row(canvas);
555}

◆ DEF_SIMPLE_GM() [5/6]

DEF_SIMPLE_GM ( runtime_intrinsics_relational  ,
canvas  ,
columns_to_width(4)  ,
rows_to_height(6)   
)

Definition at line 597 of file runtimeintrinsics.cpp.

600 {
601 canvas->translate(kPadding, kPadding);
602 canvas->save();
603
604 plot_bvec<float>(canvas, "lessThan(p, v1)", "lessThan");
605 plot_bvec<int> (canvas, "lessThan(int2(p), v1)", "lessThan(int)");
606 plot_bvec<float>(canvas, "lessThanEqual(p, v1)", "lessThanEqual");
607 plot_bvec<int> (canvas, "lessThanEqual(int2(p), v1)", "lessThanEqual(int)");
608 next_row(canvas);
609
610 plot_bvec<float>(canvas, "greaterThan(p, v1)", "greaterThan");
611 plot_bvec<int> (canvas, "greaterThan(int2(p), v1)", "greaterThan(int)");
612 plot_bvec<float>(canvas, "greaterThanEqual(p, v1)", "greaterThanEqual");
613 plot_bvec<int> (canvas, "greaterThanEqual(int2(p), v1)", "greaterThanEqual(int)");
614 next_row(canvas);
615
616 plot_bvec<float>(canvas, "equal(p, v1)", "equal");
617 plot_bvec<int> (canvas, "equal(int2(p), v1)", "equal(int)");
618 plot_bvec<float>(canvas, "notEqual(p, v1)", "notEqual");
619 plot_bvec<int> (canvas, "notEqual(int2(p), v1)", "notEqual(int)");
620 next_row(canvas);
621
622 plot_bvec(canvas, "equal( lessThanEqual(p, v1), greaterThanEqual(p, v1))", "equal(bvec)");
623 plot_bvec(canvas, "notEqual(lessThanEqual(p, v1), greaterThanEqual(p, v1))", "notequal(bvec)");
624 next_row(canvas);
625
626 plot_bvec(canvas, "not(notEqual(p, v1))", "not(notEqual)");
627 plot_bvec(canvas, "not(equal(p, v1))", "not(equal)");
628 next_row(canvas);
629
630 plot_bvec(canvas, "bool2(any(equal(p, v1)))", "any(equal)");
631 plot_bvec(canvas, "bool2(all(equal(p, v1)))", "all(equal)");
632 next_row(canvas);
633}
static void plot_bvec(SkCanvas *canvas, const char *fn, const char *label)

◆ DEF_SIMPLE_GM() [6/6]

DEF_SIMPLE_GM ( runtime_intrinsics_trig  ,
canvas  ,
columns_to_width(3)  ,
rows_to_height(5)   
)

Definition at line 172 of file runtimeintrinsics.cpp.

175 {
176 const float kPI = SK_FloatPI, kTwoPI = 2 * SK_FloatPI, kPIOverTwo = SK_FloatPI / 2;
177
178 canvas->translate(kPadding, kPadding);
179 canvas->save();
180
181 plot(canvas, "radians(x)", 0.0f, 360.0f, 0.0f, kTwoPI);
182 plot(canvas, "degrees(x)", 0.0f, kTwoPI, 0.0f, 360.0f);
183 next_row(canvas);
184
185 plot(canvas, "sin(x)", 0.0f, kTwoPI, -1.0f, 1.0f);
186 plot(canvas, "cos(x)", 0.0f, kTwoPI, -1.0f, 1.0f);
187 plot(canvas, "tan(x)", 0.0f, kPI, -10.0f, 10.0f);
188 next_row(canvas);
189
190 plot(canvas, "asin(x)", -1.0f, 1.0f, -kPIOverTwo, kPIOverTwo);
191 plot(canvas, "acos(x)", -1.0f, 1.0f, 0.0f, kPI);
192 plot(canvas, "atan(x)", -10.0f, 10.0f, -kPIOverTwo, kPIOverTwo);
193 next_row(canvas);
194
195 plot(canvas, "atan(0.1, x)", -1.0f, 1.0f, 0.0f, kPI);
196 plot(canvas, "atan(-0.1, x)", -1.0f, 1.0f, -kPI, 0.0f);
197 next_row(canvas);
198
199 plot(canvas, "atan(x, 0.1)", -1.0f, 1.0f, -kPIOverTwo, kPIOverTwo);
200 plot(canvas, "atan(x, -0.1)", -1.0f, 1.0f, -kPI, kPI);
201 next_row(canvas);
202}
constexpr float SK_FloatPI

◆ DEF_SIMPLE_GPU_GM_CAN_FAIL() [1/2]

DEF_SIMPLE_GPU_GM_CAN_FAIL ( runtime_intrinsics_common_es3  ,
ctx  ,
canvas  ,
errorMsg  ,
columns_to_width(6)  ,
rows_to_height(5)   
)

Definition at line 316 of file runtimeintrinsics.cpp.

319 {
320 if (ctx->priv().caps()->shaderCaps()->supportedSkSLVerion() < SkSL::Version::k300) {
321 *errorMsg = "SkSL 300 is not supported.";
323 }
324
325 canvas->translate(kPadding, kPadding);
326 canvas->save();
327
328 plot_es3(canvas, "floatBitsToInt(x)", -2, 2, -2'000'000'000, 2'000'000'000,
329 "floatBitsToInt(s)");
330 plot_es3(canvas, "floatBitsToInt(p).x", -2, 2, -2'000'000'000, 2'000'000'000,
331 "floatBitsToInt(v)");
332 plot_es3(canvas, "floatBitsToUint(x)", -2, 2, 0, 4'000'000'000,
333 "floatBitsToUint(s)");
334 plot_es3(canvas, "floatBitsToUint(p).x", -2, 2, 0, 4'000'000'000,
335 "floatBitsToUint(v)");
336 next_row(canvas);
337
338 plot_es3(canvas, "intBitsToFloat(xi)", -2'000'000'000, 2'000'000'000, -2, 2,
339 "intBitsToFloat(s)");
340 plot_es3(canvas, "intBitsToFloat(pi).x", -2'000'000'000, 2'000'000'000, -2, 2,
341 "intBitsToFloat(v)");
342 plot_es3(canvas, "uintBitsToFloat(uint(xi))", 0, 4'000'000'000, -2, 2,
343 "uintBitsToFloat(s)");
344 plot_es3(canvas, "uintBitsToFloat(uint2(pi)).x", 0, 4'000'000'000, -2, 2,
345 "uintBitsToFloat(v)");
346 next_row(canvas);
347
348 plot_es3(canvas, "trunc(x)", -2, 2, -3, 3);
349 plot_es3(canvas, "trunc(p).x", -2, 2, -3, 3);
350 plot_es3(canvas, "round(x)", -2, 2, -3, 3);
351 plot_es3(canvas, "round(p).x", -2, 2, -3, 3);
352 plot_es3(canvas, "roundEven(x)", -2, 2, -3, 3);
353 plot_es3(canvas, "roundEven(p).x", -2, 2, -3, 3);
354 next_row(canvas);
355
356 plot_es3(canvas, "min(xi, 1)", -2, 5, -3, 5, "min(int-scalar)");
357 plot_es3(canvas, "min(pi, 1).x", -2, 5, -3, 5, "min(int-mixed)" );
358 plot_es3(canvas, "min(pi, int2(1)).x", -2, 5, -3, 5, "min(int-vector)");
359 plot_es3(canvas, "max(xi, 1)", -2, 5, -3, 5, "max(int-scalar)");
360 plot_es3(canvas, "max(pi, 1).x", -2, 5, -3, 5, "max(int-mixed)" );
361 plot_es3(canvas, "max(pi, int2(1)).x", -2, 5, -3, 5, "max(int-vector)");
362 next_row(canvas);
363
364 plot_es3(canvas, "clamp(xi, 1, 3)", -1, 5, -1, 5, "clamp(int-scalar)");
365 plot_es3(canvas, "clamp(pi, 1, 3).x", -1, 5, -1, 5, "clamp(int-mixed)" );
366 plot_es3(canvas, "clamp(pi, int2(1), int2(3)).x", -1, 5, -1, 5, "clamp(int-vector)");
367 plot_es3(canvas, "mix(p.x, p.y, (x>0) )", -1, 2, 0, 3, "mix(scalar, bool)");
368 plot_es3(canvas, "mix(p.yx, p, (x>0).xx).x", -1, 2, 0, 3, "mix(vector, bool)");
369 next_row(canvas);
370
372}
static void plot_es3(SkCanvas *canvas, const char *fn, float xMin, float xMax, float yMin, float yMax, const char *label=nullptr)

◆ DEF_SIMPLE_GPU_GM_CAN_FAIL() [2/2]

DEF_SIMPLE_GPU_GM_CAN_FAIL ( runtime_intrinsics_trig_es3  ,
ctx  ,
canvas  ,
errorMsg  ,
columns_to_width(3)  ,
rows_to_height(2)   
)

Definition at line 205 of file runtimeintrinsics.cpp.

208 {
209 if (ctx->priv().caps()->shaderCaps()->supportedSkSLVerion() < SkSL::Version::k300) {
210 *errorMsg = "SkSL 300 is not supported.";
212 }
213
214 canvas->translate(kPadding, kPadding);
215 canvas->save();
216
217 plot_es3(canvas, "sinh(x)", -2.0f, 2.0f, -4.0f, 4.0f);
218 plot_es3(canvas, "cosh(x)", -2.0f, 2.0f, 0.0f, 4.0f);
219 plot_es3(canvas, "tanh(x)", -2.0f, 2.0f, -1.0f, 1.0f);
220 next_row(canvas);
221
222 if (ctx->priv().caps()->shaderCaps()->fInverseHyperbolicSupport) {
223 plot_es3(canvas, "asinh(x)", -2.0f, 2.0f, -2.0f, 2.0f);
224 plot_es3(canvas, "acosh(x)", 0.0f, 5.0f, 0.0f, 3.0f);
225 plot_es3(canvas, "atanh(x)", -1.0f, 1.0f, -4.0f, 4.0f);
226 }
227 next_row(canvas);
228
230}

◆ draw_label()

static void draw_label ( SkCanvas canvas,
const char *  label 
)
static

Definition at line 50 of file runtimeintrinsics.cpp.

50 {
54 font.measureText(label, strlen(label), SkTextEncoding::kUTF8, &bounds);
55
56 canvas->drawSimpleText(label, strlen(label), SkTextEncoding::kUTF8,
57 (kBoxSize - bounds.width()) * 0.5f,
58 (kLabelHeight + bounds.height()) * 0.5f, font, p);
59 canvas->translate(0, kLabelHeight);
60}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
constexpr SkColor4f kBlack
Definition SkColor.h:435
Optional< SkRect > bounds
Definition SkRecords.h:189
SkFont DefaultPortableFont()
font
Font Metadata and Metrics.
static constexpr int kLabelHeight

◆ draw_shader()

static SkBitmap draw_shader ( SkCanvas canvas,
sk_sp< SkShader shader,
bool  allowRasterFallback = true 
)
static

Definition at line 62 of file runtimeintrinsics.cpp.

63 {
65 paint.setShader(std::move(shader));
66
69 auto surface = canvas->makeSurface(info);
70 if (allowRasterFallback && !surface) {
72 }
73
74 if (surface) {
75 surface->getCanvas()->clear(SK_ColorWHITE);
76 surface->getCanvas()->scale(kBoxSize, kBoxSize);
77 surface->getCanvas()->drawRect({0, 0, 1, 1}, paint);
78
79 bitmap.allocPixels(info);
80 surface->readPixels(bitmap, 0, 0);
81
82 canvas->drawImage(bitmap.asImage(), 0, 0);
83 }
84 return bitmap;
85}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)

◆ make_bvec_sksl()

static SkString make_bvec_sksl ( const char *  type,
const char *  fn 
)
static

Definition at line 560 of file runtimeintrinsics.cpp.

560 {
561 // We use negative floats, to ensure that the integer variants are working with the correct
562 // interpretation of the data.
563 return SkStringPrintf(
564 "uniform %s2 v1;"
565 "half4 main(float2 p) {"
566 " p.x = p.x < 0.33 ? -3.0 : (p.x < 0.66 ? -2.0 : -1.0);"
567 " p.y = p.y < 0.33 ? -3.0 : (p.y < 0.66 ? -2.0 : -1.0);"
568 " bool2 cmp = %s;"
569 " return half4(cmp.x ? 1.0 : 0.0, cmp.y ? 1.0 : 0.0, 0, 1);"
570 "}",
571 type, fn);
572}
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287

◆ make_matrix_comp_mult_sksl()

static SkString make_matrix_comp_mult_sksl ( int  dim)
static

Definition at line 432 of file runtimeintrinsics.cpp.

432 {
433 return SkStringPrintf(
434 "uniform float%dx%d m1;" // dim, dim
435 "uniform float%dx%d m2;" // dim, dim
437 "half4 main(float2 p) {"
438 " float%d colSel = sel%d(p.x);" // dim, dim
439 " float%d rowSel = sel%d(p.y);" // dim, dim
440 " float%d col = matrixCompMult(m1, m2) * colSel;" // dim
441 " float v = dot(col, rowSel);"
442 " return v.xxx1;"
443 "}", dim, dim, dim, dim, dim, dim, dim, dim, dim);
444}
#define SKSL_MATRIX_SELECTORS

◆ make_matrix_inverse_sksl()

static SkString make_matrix_inverse_sksl ( int  dim)
static

Definition at line 472 of file runtimeintrinsics.cpp.

472 {
473 return SkStringPrintf(
474 "uniform float scale; uniform float bias;"
475 "uniform float%dx%d m;" // dim, dim
477 "half4 main(float2 p) {"
478 " float%d colSel = sel%d(p.x);" // dim, dim
479 " float%d rowSel = sel%d(p.y);" // dim, dim
480 " float%d col = inverse(m) * colSel;" // dim
481 " float v = dot(col, rowSel) * scale + bias;"
482 " return v.xxx1;"
483 "}", dim, dim, dim, dim, dim, dim, dim);
484}

◆ make_unary_sksl_1d()

static SkString make_unary_sksl_1d ( const char *  fn,
bool  requireES3 
)
static

Definition at line 99 of file runtimeintrinsics.cpp.

99 {
100 return SkStringPrintf(
101 "#version %s\n"
102 "uniform float xScale; uniform float xBias;"
103 "uniform float yScale; uniform float yBias;"
104 "half4 main(float2 p) {"
105 " const float2 v1 = float2(1);"
106 " const float2 v2 = float2(2);"
107 " p = float2(p.x, 1 - p.x) * xScale + xBias;"
108 " float x = p.x;"
109 " int2 pi = int2(floor(p));"
110 " int xi = pi.x;"
111 " float y = float(%s) * yScale + yBias;"
112 " return y.xxx1;"
113 "}",
114 requireES3 ? "300" : "100", fn);
115}

◆ next_column()

static void next_column ( SkCanvas canvas)
static

Definition at line 32 of file runtimeintrinsics.cpp.

32 {
33 canvas->translate(kBoxSize + kPadding, 0);
34}

◆ next_row()

static void next_row ( SkCanvas canvas)
static

Definition at line 36 of file runtimeintrinsics.cpp.

36 {
37 canvas->restore();
39 canvas->save();
40}
void restore()
Definition SkCanvas.cpp:465
int save()
Definition SkCanvas.cpp:451

◆ plot()

static void plot ( SkCanvas canvas,
const char *  fn,
float  xMin,
float  xMax,
float  yMin,
float  yMax,
const char *  label = nullptr,
bool  requireES3 = false 
)
static

Definition at line 118 of file runtimeintrinsics.cpp.

125 {
126 canvas->save();
127
128 draw_label(canvas, label ? label : fn);
129
130 auto [effect, error] = SkRuntimeEffect::MakeForShader(make_unary_sksl_1d(fn, requireES3));
131 if (!effect) {
132 SkDebugf("Error: %s\n", error.c_str());
133 return;
134 }
135
137 builder.uniform("xScale") = xMax - xMin;
138 builder.uniform("xBias") = xMin;
139 builder.uniform("yScale") = 1.0f / (yMax - yMin);
140 builder.uniform("yBias") = -yMin / (yMax - yMin);
141
143 draw_shader(canvas, builder.makeShader(), /*allowRasterFallback=*/!requireES3);
144 if (!bitmap.empty()) {
145 // Plot.
146 SkPaint plotPaint({ 0.0f, 0.5f, 0.0f, 1.0f });
147 SkPoint pts[kBoxSize];
148 for (int x = 0; x < kBoxSize; ++x) {
149 SkColor c = bitmap.getColor(x, 0);
150 SkScalar y = (1 - (SkColorGetR(c) / 255.0f)) * kBoxSize;
151 pts[x].set(x + 0.5f, y);
152 }
153 plotPaint.setAntiAlias(true);
154 canvas->drawPoints(SkCanvas::kPolygon_PointMode, kBoxSize, pts, plotPaint);
155 }
156
157 canvas->restore();
158 next_column(canvas);
159}
#define SkColorGetR(color)
Definition SkColor.h:65
uint32_t SkColor
Definition SkColor.h:37
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
@ kPolygon_PointMode
draw the array of points as a open polygon
Definition SkCanvas.h:1243
static Result MakeForShader(SkString sksl, const Options &)
float SkScalar
Definition extension.cpp:12
const uint8_t uint32_t uint32_t GError ** error
double y
static SkString make_unary_sksl_1d(const char *fn, bool requireES3)
static SkBitmap draw_shader(SkCanvas *canvas, sk_sp< SkShader > shader, bool allowRasterFallback=true)
static void draw_label(SkCanvas *canvas, const char *label)
static void next_column(SkCanvas *canvas)

◆ plot_bvec()

template<typename T = float>
static void plot_bvec ( SkCanvas canvas,
const char *  fn,
const char *  label 
)
static

Definition at line 575 of file runtimeintrinsics.cpp.

575 {
576 canvas->save();
577
578 draw_label(canvas, label);
579
580 const char* type = std::is_integral<T>::value ? "int" : "float";
582 if (!effect) {
583 SkDebugf("Error: %s\n", error.c_str());
584 return;
585 }
586
587 T uniformData[2] = { -2, -2 };
588 sk_sp<SkData> uniforms = SkData::MakeWithCopy(uniformData, sizeof(uniformData));
589
590 draw_shader(canvas, effect->makeShader(uniforms, /*children=*/{}));
591
592 canvas->restore();
593 next_column(canvas);
594}
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition SkData.cpp:111
#define T
static SkString make_bvec_sksl(const char *type, const char *fn)

◆ plot_es3()

static void plot_es3 ( SkCanvas canvas,
const char *  fn,
float  xMin,
float  xMax,
float  yMin,
float  yMax,
const char *  label = nullptr 
)
static

Definition at line 161 of file runtimeintrinsics.cpp.

167 {
168 plot(canvas, fn, xMin, xMax, yMin, yMax, label, /*requireES3=*/true);
169}

◆ plot_matrix_comp_mult()

template<int N>
static void plot_matrix_comp_mult ( SkCanvas canvas,
std::array< float, N *N mtx1,
std::array< float, N *N mtx2,
const char *  label 
)
static

Definition at line 447 of file runtimeintrinsics.cpp.

450 {
451 canvas->save();
452
453 draw_label(canvas, label);
454
456 if (!effect) {
457 SkDebugf("Error: %s\n", error.c_str());
458 return;
459 }
460
462 builder.uniform("m1") = mtx1;
463 builder.uniform("m2") = mtx2;
464
465 draw_shader(canvas, builder.makeShader());
466
467 canvas->restore();
468 next_column(canvas);
469}
#define N
Definition beziers.cpp:19
static SkString make_matrix_comp_mult_sksl(int dim)

◆ plot_matrix_inverse()

template<int N>
static void plot_matrix_inverse ( SkCanvas canvas,
std::array< float, N *N mtx,
const char *  label 
)
static

Definition at line 487 of file runtimeintrinsics.cpp.

487 {
488 canvas->save();
489
490 draw_label(canvas, label);
491
493 if (!effect) {
494 SkDebugf("Error: %s\n", error.c_str());
495 return;
496 }
497
499 builder.uniform("scale") = 0.5f;
500 builder.uniform("bias") = 0.5f;
501 builder.uniform("m") = mtx;
502
503 draw_shader(canvas, builder.makeShader());
504
505 canvas->restore();
506 next_column(canvas);
507}
static SkString make_matrix_inverse_sksl(int dim)

◆ rows_to_height()

static constexpr int rows_to_height ( int  rows)
staticconstexpr

Definition at line 46 of file runtimeintrinsics.cpp.

46 {
47 return (kPadding + kLabelHeight + kBoxSize) * rows + kPadding;
48}

Variable Documentation

◆ kBoxSize

constexpr int kBoxSize = 100
staticconstexpr

Definition at line 28 of file runtimeintrinsics.cpp.

◆ kLabelHeight

constexpr int kLabelHeight = 15
staticconstexpr

Definition at line 30 of file runtimeintrinsics.cpp.

◆ kPadding

constexpr int kPadding = 5
staticconstexpr

Definition at line 29 of file runtimeintrinsics.cpp.