void SkRasterPipeline::reset() { // We intentionally leave the alloc alone here; we don't own it.
fRewindCtx = nullptr;
fStages = nullptr;
fTailPointer = nullptr;
fNumStages = 0;
fMemoryCtxInfos.clear();
}
void SkRasterPipeline::append(SkRasterPipelineOp op, void* ctx) {
SkASSERT(op != Op::uniform_color); // Please use appendConstantColor().
SkASSERT(op != Op::unbounded_uniform_color); // Please use appendConstantColor().
SkASSERT(op != Op::set_rgb); // Please use appendSetRGB().
SkASSERT(op != Op::unbounded_set_rgb); // Please use appendSetRGB().
SkASSERT(op != Op::parametric); // Please use appendTransferFunction().
SkASSERT(op != Op::gamma_); // Please use appendTransferFunction().
SkASSERT(op != Op::PQish); // Please use appendTransferFunction().
SkASSERT(op != Op::HLGish); // Please use appendTransferFunction().
SkASSERT(op != Op::HLGinvish); // Please use appendTransferFunction().
SkASSERT(op != Op::stack_checkpoint); // Please use appendStackRewind().
SkASSERT(op != Op::stack_rewind); // Please use appendStackRewind().
this->uncheckedAppend(op, ctx);
}
uint8_t* SkRasterPipeline::tailPointer() { if (!fTailPointer) { // All ops in the pipeline that use the tail value share the same value.
fTailPointer = fAlloc->make<uint8_t>(0xFF);
} return fTailPointer;
}
void SkRasterPipeline::extend(const SkRasterPipeline& src) { if (src.empty()) { return;
} // Create a rewind context if `src` has one already, but we don't. If we _do_ already have one, // we need to keep it, since we already have rewind ops that reference it. Either way, we need // to rewrite all the rewind ops to point to _our_ rewind context; we only get that checkpoint. if (src.fRewindCtx && !fRewindCtx) {
fRewindCtx = fAlloc->make<SkRasterPipeline_RewindCtx>();
} auto stages = fAlloc->makeArrayDefault<StageList>(src.fNumStages);
int n = src.fNumStages; const StageList* st = src.fStages; while (n --> 1) {
stages[n] = *st;
stages[n].prev = &stages[n-1];
// We make sure that all ops use _our_ stack context and tail pointer. switch (stages[n].stage) { case Op::stack_rewind: {
stages[n].ctx = fRewindCtx; break;
} case Op::init_lane_masks: { auto* ctx = (SkRasterPipeline_InitLaneMasksCtx*)stages[n].ctx;
ctx->tail = this->tailPointer(); break;
} case Op::branch_if_all_lanes_active: { auto* ctx = (SkRasterPipeline_BranchIfAllLanesActiveCtx*)stages[n].ctx;
ctx->tail = this->tailPointer(); break;
} default: break;
}
st = st->prev;
}
stages[0] = *st;
stages[0].prev = fStages;
// uniform_color requires colors in range and can go lowp, // while unbounded_uniform_color supports out-of-range colors too but not lowp. if (0 <= rgba[0] && rgba[0] <= rgba[3] &&
0 <= rgba[1] && rgba[1] <= rgba[3] &&
0 <= rgba[2] && rgba[2] <= rgba[3]) { // To make loads more direct, we store 8-bit values in 16-bit slots.
color = color * 255.0f + 0.5f;
ctx->rgba[0] = (uint16_t)color[0];
ctx->rgba[1] = (uint16_t)color[1];
ctx->rgba[2] = (uint16_t)color[2];
ctx->rgba[3] = (uint16_t)color[3];
this->uncheckedAppend(Op::uniform_color, ctx);
} else {
this->uncheckedAppend(Op::unbounded_uniform_color, ctx);
}
}
}
case kAlpha_8_SkColorType: this->append(Op::load_a8, ctx); break; case kA16_unorm_SkColorType: this->append(Op::load_a16, ctx); break; case kA16_float_SkColorType: this->append(Op::load_af16, ctx); break; case kRGB_565_SkColorType: this->append(Op::load_565, ctx); break; case kARGB_4444_SkColorType: this->append(Op::load_4444, ctx); break; case kR8G8_unorm_SkColorType: this->append(Op::load_rg88, ctx); break; case kR16G16_unorm_SkColorType: this->append(Op::load_rg1616, ctx); break; case kR16G16_float_SkColorType: this->append(Op::load_rgf16, ctx); break; case kRGBA_8888_SkColorType: this->append(Op::load_8888, ctx); break; case kRGBA_1010102_SkColorType: this->append(Op::load_1010102, ctx); break; case kR16G16B16A16_unorm_SkColorType:this->append(Op::load_16161616,ctx); break; case kRGBA_F16Norm_SkColorType: case kRGBA_F16_SkColorType: this->append(Op::load_f16, ctx); break; case kRGBA_F32_SkColorType: this->append(Op::load_f32, ctx); break; case kRGBA_10x6_SkColorType: this->append(Op::load_10x6, ctx); break;
case kGray_8_SkColorType: this->append(Op::load_a8, ctx);
this->append(Op::alpha_to_gray); break;
case kR8_unorm_SkColorType: this->append(Op::load_a8, ctx);
this->append(Op::alpha_to_red); break;
case kRGB_888x_SkColorType: this->append(Op::load_8888, ctx);
this->append(Op::force_opaque); break;
case kBGRA_1010102_SkColorType: this->append(Op::load_1010102, ctx);
this->append(Op::swap_rb); break;
case kRGB_101010x_SkColorType: this->append(Op::load_1010102, ctx);
this->append(Op::force_opaque); break;
case kBGR_101010x_SkColorType: this->append(Op::load_1010102, ctx);
this->append(Op::force_opaque);
this->append(Op::swap_rb); break;
case kBGRA_10101010_XR_SkColorType: this->append(Op::load_10101010_xr, ctx);
this->append(Op::swap_rb); break;
case kBGR_101010x_XR_SkColorType: this->append(Op::load_1010102_xr, ctx);
this->append(Op::force_opaque);
this->append(Op::swap_rb); break; case kRGB_F16F16F16x_SkColorType: this->append(Op::load_f16, ctx);
this->append(Op::force_opaque); break;
case kBGRA_8888_SkColorType: this->append(Op::load_8888, ctx);
this->append(Op::swap_rb); break;
case kSRGBA_8888_SkColorType:
this->append(Op::load_8888, ctx);
this->appendTransferFunction(*skcms_sRGB_TransferFunction()); break;
}
}
case kAlpha_8_SkColorType: this->append(Op::load_a8_dst, ctx); break; case kA16_unorm_SkColorType: this->append(Op::load_a16_dst, ctx); break; case kA16_float_SkColorType: this->append(Op::load_af16_dst, ctx); break; case kRGB_565_SkColorType: this->append(Op::load_565_dst, ctx); break; case kARGB_4444_SkColorType: this->append(Op::load_4444_dst, ctx); break; case kR8G8_unorm_SkColorType: this->append(Op::load_rg88_dst, ctx); break; case kR16G16_unorm_SkColorType: this->append(Op::load_rg1616_dst, ctx); break; case kR16G16_float_SkColorType: this->append(Op::load_rgf16_dst, ctx); break; case kRGBA_8888_SkColorType: this->append(Op::load_8888_dst, ctx); break; case kRGBA_1010102_SkColorType: this->append(Op::load_1010102_dst, ctx); break; case kR16G16B16A16_unorm_SkColorType: this->append(Op::load_16161616_dst,ctx); break; case kRGBA_F16Norm_SkColorType: case kRGBA_F16_SkColorType: this->append(Op::load_f16_dst, ctx); break; case kRGBA_F32_SkColorType: this->append(Op::load_f32_dst, ctx); break; case kRGBA_10x6_SkColorType: this->append(Op::load_10x6_dst, ctx); break;
case kGray_8_SkColorType: this->append(Op::load_a8_dst, ctx);
this->append(Op::alpha_to_gray_dst); break;
case kR8_unorm_SkColorType: this->append(Op::load_a8_dst, ctx);
this->append(Op::alpha_to_red_dst); break;
case kRGB_888x_SkColorType: this->append(Op::load_8888_dst, ctx);
this->append(Op::force_opaque_dst); break;
case kBGRA_1010102_SkColorType: this->append(Op::load_1010102_dst, ctx);
this->append(Op::swap_rb_dst); break;
case kRGB_101010x_SkColorType: this->append(Op::load_1010102_dst, ctx);
this->append(Op::force_opaque_dst); break;
case kBGR_101010x_SkColorType: this->append(Op::load_1010102_dst, ctx);
this->append(Op::force_opaque_dst);
this->append(Op::swap_rb_dst); break;
case kBGR_101010x_XR_SkColorType: this->append(Op::load_1010102_xr_dst, ctx);
this->append(Op::force_opaque_dst);
this->append(Op::swap_rb_dst); break;
case kBGRA_10101010_XR_SkColorType: this->append(Op::load_10101010_xr_dst, ctx);
this->append(Op::swap_rb_dst); break; case kRGB_F16F16F16x_SkColorType: this->append(Op::load_f16_dst, ctx);
this->append(Op::force_opaque_dst); break;
case kBGRA_8888_SkColorType: this->append(Op::load_8888_dst, ctx);
this->append(Op::swap_rb_dst); break;
case kSRGBA_8888_SkColorType: // TODO: We could remove the double-swap if we had _dst versions of all the TF stages
this->append(Op::load_8888_dst, ctx);
this->append(Op::swap_src_dst);
this->appendTransferFunction(*skcms_sRGB_TransferFunction());
this->append(Op::swap_src_dst); break;
}
}
case kAlpha_8_SkColorType: this->append(Op::store_a8, ctx); break; case kR8_unorm_SkColorType: this->append(Op::store_r8, ctx); break; case kA16_unorm_SkColorType: this->append(Op::store_a16, ctx); break; case kA16_float_SkColorType: this->append(Op::store_af16, ctx); break; case kRGB_565_SkColorType: this->append(Op::store_565, ctx); break; case kARGB_4444_SkColorType: this->append(Op::store_4444, ctx); break; case kR8G8_unorm_SkColorType: this->append(Op::store_rg88, ctx); break; case kR16G16_unorm_SkColorType: this->append(Op::store_rg1616, ctx); break; case kR16G16_float_SkColorType: this->append(Op::store_rgf16, ctx); break; case kRGBA_8888_SkColorType: this->append(Op::store_8888, ctx); break; case kRGBA_1010102_SkColorType: this->append(Op::store_1010102, ctx); break; case kR16G16B16A16_unorm_SkColorType: this->append(Op::store_16161616,ctx); break; case kRGBA_F16Norm_SkColorType: case kRGBA_F16_SkColorType: this->append(Op::store_f16, ctx); break; case kRGBA_F32_SkColorType: this->append(Op::store_f32, ctx); break; case kRGBA_10x6_SkColorType: this->append(Op::store_10x6, ctx); break;
case kRGB_888x_SkColorType: this->append(Op::force_opaque);
this->append(Op::store_8888, ctx); break;
case kBGRA_1010102_SkColorType: this->append(Op::swap_rb);
this->append(Op::store_1010102, ctx); break;
case kRGB_101010x_SkColorType: this->append(Op::force_opaque);
this->append(Op::store_1010102, ctx); break;
case kBGR_101010x_SkColorType: this->append(Op::force_opaque);
this->append(Op::swap_rb);
this->append(Op::store_1010102, ctx); break;
case kBGR_101010x_XR_SkColorType: this->append(Op::force_opaque);
this->append(Op::swap_rb);
this->append(Op::store_1010102_xr, ctx); break; case kRGB_F16F16F16x_SkColorType: this->append(Op::force_opaque);
this->append(Op::store_f16, ctx); break;
case kBGRA_10101010_XR_SkColorType: this->append(Op::swap_rb);
this->append(Op::store_10101010_xr, ctx); break;
case kGray_8_SkColorType: this->append(Op::bt709_luminance_or_luma_to_alpha);
this->append(Op::store_a8, ctx); break;
case kBGRA_8888_SkColorType: this->append(Op::swap_rb);
this->append(Op::store_8888, ctx); break;
case kSRGBA_8888_SkColorType:
this->appendTransferFunction(*skcms_sRGB_Inverse_TransferFunction());
this->append(Op::store_8888, ctx); break;
}
}
// GPUs clamp all color channels to the limits of the format just before the blend step. To match // that auto-clamp, the RP blitter uses this helper immediately before appending blending stages. void SkRasterPipeline::appendClampIfNormalized(const SkImageInfo& info) { if (SkColorTypeIsNormalized(info.colorType())) {
this->uncheckedAppend(Op::clamp_01, nullptr);
}
}
bool SkRasterPipeline::buildLowpPipeline(SkRasterPipelineStage* ip) const { if (gForceHighPrecisionRasterPipeline || fRewindCtx) { returnfalse;
} // Stages are stored backwards in fStages; to compensate, we assemble the pipeline in reverse // here, back to front.
prepend_to_pipeline(ip, SkOpts::just_return_lowp, /*ctx=*/nullptr); for (const StageList* st = fStages; st; st = st->prev) { int opIndex = (int)st->stage; if (opIndex >= kNumRasterPipelineLowpOps || !SkOpts::ops_lowp[opIndex]) { // This program contains a stage that doesn't exist in lowp. returnfalse;
}
prepend_to_pipeline(ip, SkOpts::ops_lowp[opIndex], st->ctx);
} returntrue;
}
void SkRasterPipeline::buildHighpPipeline(SkRasterPipelineStage* ip) const { // We assemble the pipeline in reverse, since the stage list is stored backwards.
prepend_to_pipeline(ip, SkOpts::just_return_highp, /*ctx=*/nullptr); for (const StageList* st = fStages; st; st = st->prev) { int opIndex = (int)st->stage;
prepend_to_pipeline(ip, SkOpts::ops_highp[opIndex], st->ctx);
}
// stack_checkpoint and stack_rewind are only implemented in highp. We only need these stages // when generating long (or looping) pipelines from SkSL. The other stages used by the SkSL // Raster Pipeline generator will only have highp implementations, because we can't execute SkSL // code without floating point. if (fRewindCtx) { constint rewindIndex = (int)Op::stack_checkpoint;
prepend_to_pipeline(ip, SkOpts::ops_highp[rewindIndex], fRewindCtx);
}
}
SkRasterPipeline::StartPipelineFn SkRasterPipeline::buildPipeline(SkRasterPipelineStage* ip) const { // We try to build a lowp pipeline first; if that fails, we fall back to a highp float pipeline. if (this->buildLowpPipeline(ip)) { return SkOpts::start_pipeline_lowp;
}
int SkRasterPipeline::stagesNeeded() const { // Add 1 to budget for a `just_return` stage at the end. int stages = fNumStages + 1;
// If we have any stack_rewind stages, we will need to inject a stack_checkpoint stage. if (fRewindCtx) {
stages += 1;
} return stages;
}
void SkRasterPipeline::run(size_t x, size_t y, size_t w, size_t h) const { if (this->empty()) { return;
}
int stagesNeeded = this->stagesNeeded();
// Best to not use fAlloc here... we can't bound how often run() will be called.
AutoSTMalloc<32, SkRasterPipelineStage> program(stagesNeeded);
int numMemoryCtxs = fMemoryCtxInfos.size();
AutoSTMalloc<2, SkRasterPipeline_MemoryCtxPatch> patches(numMemoryCtxs); for (int i = 0; i < numMemoryCtxs; ++i) {
patches[i].info = fMemoryCtxInfos[i];
patches[i].backup = nullptr;
memset(patches[i].scratch, 0, sizeof(patches[i].scratch));
}
auto start_pipeline = this->buildPipeline(program.get() + stagesNeeded);
start_pipeline(x, y, x + w, y + h, program.get(),
SkSpan{patches.data(), numMemoryCtxs},
fTailPointer);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.