2 * Copyright 2020 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SKSL_VMGENERATOR
9 #define SKSL_VMGENERATOR
11 #include "src/core/SkVM.h"
12 #include "src/sksl/ir/SkSLType.h"
18 template <typename T> class SkSpan;
22 class FunctionDefinition;
28 virtual ~SkVMCallbacks() = default;
30 virtual skvm::Color sampleShader(int index, skvm::Coord coord) = 0;
31 virtual skvm::Color sampleColorFilter(int index, skvm::Color color) = 0;
32 virtual skvm::Color sampleBlender(int index, skvm::Color src, skvm::Color dst) = 0;
34 virtual skvm::Color toLinearSrgb(skvm::Color color) = 0;
35 virtual skvm::Color fromLinearSrgb(skvm::Color color) = 0;
38 // Convert 'function' to skvm instructions in 'builder', for use by blends, shaders, & color filters
39 skvm::Color ProgramToSkVM(const Program& program,
40 const FunctionDefinition& function,
41 skvm::Builder* builder,
42 SkVMDebugTrace* debugTrace,
43 SkSpan<skvm::Val> uniforms,
46 skvm::Color inputColor,
47 skvm::Color destColor,
48 SkVMCallbacks* callbacks);
50 struct SkVMSignature {
51 size_t fParameterSlots = 0;
52 size_t fReturnSlots = 0;
56 * Converts 'function' to skvm instructions in 'builder'. Always adds one arg per value in the
57 * parameter list, then one per value in the return type. For example:
59 * float2 fn(float2 a, float b) { ... }
61 * ... is mapped so that it can be called as:
63 * p.eval(N, &a.x, &a.y, &b, &return.x, &return.y);
65 * The number of parameter and return slots (pointers) is placed in 'outSignature', if provided.
66 * If the program declares any uniforms, 'uniforms' should contain the IDs of each individual value
67 * (eg, one ID per component of a vector).
69 bool ProgramToSkVM(const Program& program,
70 const FunctionDefinition& function,
72 SkVMDebugTrace* debugTrace,
73 SkSpan<skvm::Val> uniforms,
74 SkVMSignature* outSignature = nullptr);
76 const FunctionDefinition* Program_GetFunction(const Program& program, const char* function);
81 Type::NumberKind fKind;
86 std::vector<Uniform> fUniforms;
87 int fUniformSlotCount = 0;
90 std::unique_ptr<UniformInfo> Program_GetUniformInfo(const Program& program);
92 bool testingOnly_ProgramToSkVMShader(const Program& program,
93 skvm::Builder* builder,
94 SkVMDebugTrace* debugTrace);