skia2/src/sksl/SkSLVMGenerator.h
Brian Osman e89d8ea20b Update particle system to use skvm, rather than ByteCode
This was the last remaining user of ByteCode. The skvm solution
is faster, and lets us delete the ByteCode system.

Testing on 15 instances of sinusoidal_emitter (90k particles):
  - ByteCode                     ~9   ms
  - ByteCode (older, optimized): ~5.5 ms
  - skvm                         ~2.1 ms

Change-Id: Ia2e5c9ab2d36c97e59af28a6f989bf212889e439
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356919
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2021-01-21 23:07:29 +00:00

83 lines
2.5 KiB
C++

/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_VMGENERATOR
#define SKSL_VMGENERATOR
#include "src/core/SkSpan.h"
#include "src/core/SkVM.h"
#include "src/sksl/SkSLString.h"
#include "src/sksl/ir/SkSLType.h"
#include <functional>
namespace SkSL {
class FunctionDefinition;
struct Program;
using SampleChildFn = std::function<skvm::Color(int, skvm::Coord)>;
// TODO: Have a generic entry point, supporting SkSpan<skvm::Val> for parameters and return values.
// That would be useful for interpreter use cases like SkParticleEffect.
// Convert 'function' to skvm instructions in 'builder', for use by shaders and color filters
skvm::Color ProgramToSkVM(const Program& program,
const FunctionDefinition& function,
skvm::Builder* builder,
SkSpan<skvm::Val> uniforms,
skvm::Coord device,
skvm::Coord local,
SampleChildFn sampleChild);
struct SkVMSignature {
size_t fParameterSlots = 0;
size_t fReturnSlots = 0;
};
/*
* Converts 'function' to skvm instructions in 'builder'. Always adds one arg per value in the
* parameter list, then one per value in the return type. For example:
*
* float2 fn(float2 a, float b) { ... }
*
* ... is mapped so that it can be called as:
*
* p.eval(N, &a.x, &a.y, &b, &return.x, &return.y);
*
* The number of parameter and return slots (pointers) is placed in 'outSignature', if provided.
* If the program declares any uniforms, 'uniforms' should contain the IDs of each individual value
* (eg, one ID per component of a vector).
*/
bool ProgramToSkVM(const Program& program,
const FunctionDefinition& function,
skvm::Builder* b,
SkSpan<skvm::Val> uniforms,
SkVMSignature* outSignature = nullptr);
const FunctionDefinition* Program_GetFunction(const Program& program, const char* function);
struct UniformInfo {
struct Uniform {
String fName;
Type::NumberKind fKind;
int fColumns;
int fRows;
int fSlot;
};
std::vector<Uniform> fUniforms;
int fUniformSlotCount = 0;
};
std::unique_ptr<UniformInfo> Program_GetUniformInfo(const Program& program);
bool testingOnly_ProgramToSkVMShader(const Program& program, skvm::Builder* builder);
} // namespace SkSL
#endif