From 5e398c2b5eef4f200a2b9a0d73840aae062db4fe Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Fri, 8 Mar 2019 11:50:35 -0500 Subject: [PATCH] change load/store_rgba to have src and dst variants somewhat motivated by future mixer stages Bug: skia: Change-Id: Icd41ec9311f0da966164451324d28e7b3dfb3213 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/199280 Reviewed-by: Mike Klein Reviewed-by: Florin Malita Commit-Queue: Mike Reed Commit-Queue: Mike Klein --- src/core/SkColorFilter.cpp | 13 ++++++------- src/core/SkRasterPipeline.h | 2 +- src/opts/SkRasterPipeline_opts.h | 26 ++++++++++++++++++++++---- src/shaders/SkComposeShader.cpp | 21 +++++++++------------ 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp index a5bfab12bf..5631647cec 100644 --- a/src/core/SkColorFilter.cpp +++ b/src/core/SkColorFilter.cpp @@ -308,18 +308,17 @@ public: }; auto state = alloc->make(); - p->append(SkRasterPipeline::store_rgba, state->orig_rgba); + p->append(SkRasterPipeline::store_src, state->orig_rgba); if (!fCF1) { fCF0->appendStages(p, dst, alloc, shaderIsOpaque); p->append(SkRasterPipeline::move_src_dst); - p->append(SkRasterPipeline::load_rgba, state->orig_rgba); + p->append(SkRasterPipeline::load_src, state->orig_rgba); } else { - fCF1->appendStages(p, dst, alloc, shaderIsOpaque); - p->append(SkRasterPipeline::store_rgba, state->filtered_rgba); - p->append(SkRasterPipeline::load_rgba, state->orig_rgba); fCF0->appendStages(p, dst, alloc, shaderIsOpaque); - p->append(SkRasterPipeline::move_src_dst); - p->append(SkRasterPipeline::load_rgba, state->filtered_rgba); + p->append(SkRasterPipeline::store_src, state->filtered_rgba); + p->append(SkRasterPipeline::load_src, state->orig_rgba); + fCF1->appendStages(p, dst, alloc, shaderIsOpaque); + p->append(SkRasterPipeline::load_dst, state->filtered_rgba); } float* storage = alloc->make(fWeight); p->append(SkRasterPipeline::lerp_1_float, storage); diff --git a/src/core/SkRasterPipeline.h b/src/core/SkRasterPipeline.h index 74e915f8b0..eae7e995d5 100644 --- a/src/core/SkRasterPipeline.h +++ b/src/core/SkRasterPipeline.h @@ -52,7 +52,7 @@ M(alpha_to_gray) M(alpha_to_gray_dst) M(luminance_to_alpha) \ M(bilerp_clamp_8888) \ M(store_u16_be) \ - M(load_rgba) M(store_rgba) \ + M(load_src) M(store_src) M(load_dst) M(store_dst) \ M(scale_u8) M(scale_565) M(scale_1_float) \ M( lerp_u8) M( lerp_565) M( lerp_1_float) \ M(dstatop) M(dstin) M(dstout) M(dstover) \ diff --git a/src/opts/SkRasterPipeline_opts.h b/src/opts/SkRasterPipeline_opts.h index 2abc0b5914..64d062266b 100644 --- a/src/opts/SkRasterPipeline_opts.h +++ b/src/opts/SkRasterPipeline_opts.h @@ -1066,7 +1066,7 @@ STAGE(white_color, Ctx::None) { } // load registers r,g,b,a from context (mirrors store_rgba) -STAGE(load_rgba, const float* ptr) { +STAGE(load_src, const float* ptr) { r = unaligned_load(ptr + 0*N); g = unaligned_load(ptr + 1*N); b = unaligned_load(ptr + 2*N); @@ -1074,13 +1074,29 @@ STAGE(load_rgba, const float* ptr) { } // store registers r,g,b,a into context (mirrors load_rgba) -STAGE(store_rgba, float* ptr) { +STAGE(store_src, float* ptr) { unaligned_store(ptr + 0*N, r); unaligned_store(ptr + 1*N, g); unaligned_store(ptr + 2*N, b); unaligned_store(ptr + 3*N, a); } +// load registers dr,dg,db,da from context (mirrors store_dst) +STAGE(load_dst, const float* ptr) { + dr = unaligned_load(ptr + 0*N); + dg = unaligned_load(ptr + 1*N); + db = unaligned_load(ptr + 2*N); + da = unaligned_load(ptr + 3*N); +} + +// store registers dr,dg,db,da into context (mirrors load_dst) +STAGE(store_dst, float* ptr) { + unaligned_store(ptr + 0*N, dr); + unaligned_store(ptr + 1*N, dg); + unaligned_store(ptr + 2*N, db); + unaligned_store(ptr + 3*N, da); +} + // Most blend modes apply the same logic to each channel. #define BLEND_MODE(name) \ SI F name##_channel(F s, F d, F sa, F da); \ @@ -3344,8 +3360,10 @@ STAGE_GP(bilerp_clamp_8888, const SkRasterPipeline_GatherCtx* ctx) { // If a pipeline uses these stages, it'll boot it out of lowp into highp. #define NOT_IMPLEMENTED(st) static void (*st)(void) = nullptr; NOT_IMPLEMENTED(callback) - NOT_IMPLEMENTED(load_rgba) - NOT_IMPLEMENTED(store_rgba) + NOT_IMPLEMENTED(load_src) + NOT_IMPLEMENTED(store_src) + NOT_IMPLEMENTED(load_dst) + NOT_IMPLEMENTED(store_dst) NOT_IMPLEMENTED(unbounded_set_rgb) NOT_IMPLEMENTED(unbounded_uniform_color) NOT_IMPLEMENTED(unpremul) diff --git a/src/shaders/SkComposeShader.cpp b/src/shaders/SkComposeShader.cpp index 2dee742d80..da3abc0b2f 100644 --- a/src/shaders/SkComposeShader.cpp +++ b/src/shaders/SkComposeShader.cpp @@ -85,21 +85,18 @@ bool SkComposeShader::onAppendStages(const StageRec& rec) const { }; auto storage = rec.fAlloc->make(); - if (!as_SB(fSrc)->appendStages(rec)) { - return false; - } - // This outputs r,g,b,a, which we'll need later when we apply the mode, but we save it off now - // since fShaderB will overwrite them. - rec.fPipeline->append(SkRasterPipeline::store_rgba, storage->fRGBA); - if (!as_SB(fDst)->appendStages(rec)) { return false; } - // We now have our logical 'dst' in r,g,b,a, but we need it in dr,dg,db,da for the mode/lerp - // so we have to shuttle them. If we had a stage the would load_into_dst, then we could - // reverse the two shader invocations, and avoid this move... - rec.fPipeline->append(SkRasterPipeline::move_src_dst); - rec.fPipeline->append(SkRasterPipeline::load_rgba, storage->fRGBA); + // This outputs r,g,b,a, which we'll need later when we apply the mode, so we save it off now + rec.fPipeline->append(SkRasterPipeline::store_src, storage->fRGBA); + + if (!as_SB(fSrc)->appendStages(rec)) { + return false; + } + // r,g,b,a now have the right input for the next step (lerp and/or mode), but we need to + // reload dr,dg,db,da from memory, since we stashed that from our fDst invocation earlier. + rec.fPipeline->append(SkRasterPipeline::load_dst, storage->fRGBA); if (!this->isJustLerp()) { SkBlendMode_AppendStages(fMode, rec.fPipeline);