add per-program control over JIT

We have a global flag controlling whether skvm::Programs JIT,
and this adds a per-Program flag to skvm::Builder::done().

Use it for single-color color filtering, and add a unit test.

Change-Id: I3a87761c8c6b818111d03c97b31f8b30d9f2c194
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367856
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2021-02-08 10:24:52 -06:00
parent 6d7357c143
commit c7c1f9c148
4 changed files with 22 additions and 7 deletions

View File

@ -119,7 +119,9 @@ SkColor4f SkColorFilter::filterColor4f(const SkColor4f& origSrcColor, SkColorSpa
b.store({skvm::PixelFormat::FLOAT, 32,32,32,32, 0,32,64,96},
b.varying<SkColor4f>(), unpremul(filtered));
b.done().eval(1, uni.buf.data(), &color); // tell SkVM to skip JIT?
const bool allow_jit = false; // We're only filtering one color, no point JITing.
b.done("filterColor4f", allow_jit).eval(1, uni.buf.data(), &color);
return color;
}

View File

@ -515,14 +515,14 @@ namespace skvm {
return finalize (std::move(program));
}
Program Builder::done(const char* debug_name) const {
Program Builder::done(const char* debug_name, bool allow_jit) const {
char buf[64] = "skvm-jit-";
if (!debug_name) {
*SkStrAppendU32(buf+9, this->hash()) = '\0';
debug_name = buf;
}
return {this->optimize(), fStrides, debug_name};
return {this->optimize(), fStrides, debug_name, allow_jit};
}
uint64_t Builder::hash() const {
@ -2878,9 +2878,9 @@ namespace skvm {
Program::Program(const std::vector<OptimizedInstruction>& instructions,
const std::vector<int>& strides,
const char* debug_name) : Program() {
const char* debug_name, bool allow_jit) : Program() {
fImpl->strides = strides;
if (gSkVMAllowJIT) {
if (gSkVMAllowJIT && allow_jit) {
#if 1 && defined(SKVM_LLVM)
this->setupLLVM(instructions, debug_name);
#elif 1 && defined(SKVM_JIT)

View File

@ -583,7 +583,7 @@ namespace skvm {
Builder();
explicit Builder(Features);
Program done(const char* debug_name = nullptr) const;
Program done(const char* debug_name = nullptr, bool allow_jit=true) const;
// Mostly for debugging, tests, etc.
std::vector<Instruction> program() const { return fProgram; }
@ -951,7 +951,7 @@ namespace skvm {
public:
Program(const std::vector<OptimizedInstruction>& instructions,
const std::vector<int>& strides,
const char* debug_name);
const char* debug_name, bool allow_jit);
Program();
~Program();

View File

@ -94,6 +94,19 @@ DEF_TEST(SkVM_memcpy, r) {
});
}
DEF_TEST(SkVM_allow_jit, r) {
skvm::Builder b;
{
auto src = b.varying<int>(),
dst = b.varying<int>();
b.store32(dst, b.load32(src));
}
if (b.done("", /*allow_jit=*/true).hasJIT()) {
REPORTER_ASSERT(r, !b.done("", false).hasJIT());
}
}
DEF_TEST(SkVM_LoopCounts, r) {
// Make sure we cover all the exact N we want.