blob: 577721d029d18458eca4a1b119a6d12df97a9daa [file] [log] [blame]
Brian Osman0a442b72020-12-02 11:12:51 -05001/*
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
8#ifndef SKSL_VMGENERATOR
9#define SKSL_VMGENERATOR
10
11#include "src/core/SkSpan.h"
12#include "src/core/SkVM.h"
13
14#include <functional>
15
16namespace SkSL {
17
18class FunctionDefinition;
19struct Program;
20
21using SampleChildFn = std::function<skvm::Color(int, skvm::Coord)>;
22
23// TODO: Have a generic entry point, supporting SkSpan<skvm::Val> for parameters and return values.
24// That would be useful for interpreter use cases like SkParticleEffect.
25
26// Convert 'function' to skvm instructions in 'builder', for use by shaders and color filters
27skvm::Color ProgramToSkVM(const Program& program,
28 const FunctionDefinition& function,
29 skvm::Builder* builder,
30 SkSpan<skvm::Val> uniforms,
31 skvm::Coord device,
32 skvm::Coord local,
33 SampleChildFn sampleChild);
34
Brian Osmanf4a77732020-12-28 09:03:00 -050035struct SkVMSignature {
36 size_t fParameterSlots = 0;
37 size_t fReturnSlots = 0;
38};
39
40/*
41 * Converts 'function' to skvm instructions in 'builder'. Always adds one arg for uniforms, then
42 * one per value in the parameter list, and finally one per value in the return type. For example:
43 *
44 * uniform float u; uniform float v;
45 * float2 fn(float2 a, float b) { ... }
46 *
47 * ... is mapped so that it can be called as:
48 *
49 * p.eval(N, uniforms, &a.x, &a.y, &b, &return.x, &return.y);
50 *
51 * The number of parameter and return slots (pointers) is placed in 'outSignature', if provided.
52 */
53bool ProgramToSkVM(const Program& program,
54 const FunctionDefinition& function,
55 skvm::Builder* b,
56 SkVMSignature* outSignature = nullptr);
57
Brian Osman5933d4c2021-01-05 13:02:20 -050058const FunctionDefinition* Program_GetFunction(const Program& program, const char* function);
59
Brian Osman47726a12020-12-17 16:02:08 -050060bool testingOnly_ProgramToSkVMShader(const Program& program, skvm::Builder* builder);
61
Brian Osman0a442b72020-12-02 11:12:51 -050062} // namespace SkSL
63
64#endif