#include "src/sksl/codegen/SkSLRasterPipelineBuilder.h"
#include <cstdint>
#include <optional>
#include "include/core/SkStream.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTFitsIn.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkArenaAlloc.h"
#include "src/base/SkSafeMath.h"
#include "src/core/SkOpts.h"
#include "src/core/SkRasterPipelineContextUtils.h"
#include "src/core/SkRasterPipelineOpContexts.h"
#include "src/core/SkRasterPipelineOpList.h"
#include "src/core/SkTHash.h"
#include "src/sksl/SkSLPosition.h"
#include "src/sksl/SkSLString.h"
#include "src/sksl/tracing/SkSLDebugTracePriv.h"
#include "src/sksl/tracing/SkSLTraceHook.h"
#if !defined(SKSL_STANDALONE)
#include "src/core/SkRasterPipeline.h"
#endif
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>
usingnamespaceskia_private;
namespace SkSL::RP {
#define ALL_SINGLE_SLOT_UNARY_OP_CASES …
#define ALL_MULTI_SLOT_UNARY_OP_CASES …
#define ALL_N_WAY_BINARY_OP_CASES …
#define ALL_MULTI_SLOT_BINARY_OP_CASES …
#define ALL_IMMEDIATE_BINARY_OP_CASES …
#define ALL_IMMEDIATE_MULTI_SLOT_BINARY_OP_CASES …
#define ALL_N_WAY_TERNARY_OP_CASES …
#define ALL_MULTI_SLOT_TERNARY_OP_CASES …
static bool is_immediate_op(BuilderOp op) { … }
static bool is_multi_slot_immediate_op(BuilderOp op) { … }
static BuilderOp convert_n_way_op_to_immediate(BuilderOp op, int slots, int32_t* constantValue) { … }
void Builder::appendInstruction(BuilderOp op, SlotList slots,
int immA, int immB, int immC, int immD) { … }
Instruction* Builder::lastInstruction(int fromBack) { … }
Instruction* Builder::lastInstructionOnAnyStack(int fromBack) { … }
void Builder::unary_op(BuilderOp op, int32_t slots) { … }
void Builder::binary_op(BuilderOp op, int32_t slots) { … }
void Builder::ternary_op(BuilderOp op, int32_t slots) { … }
void Builder::dot_floats(int32_t slots) { … }
void Builder::refract_floats() { … }
void Builder::inverse_matrix(int32_t n) { … }
void Builder::pad_stack(int32_t count) { … }
bool Builder::simplifyImmediateUnmaskedOp() { … }
void Builder::discard_stack(int32_t count, int stackID) { … }
void Builder::label(int labelID) { … }
void Builder::jump(int labelID) { … }
void Builder::branch_if_any_lanes_active(int labelID) { … }
void Builder::branch_if_all_lanes_active(int labelID) { … }
void Builder::branch_if_no_lanes_active(int labelID) { … }
void Builder::branch_if_no_active_lanes_on_stack_top_equal(int value, int labelID) { … }
void Builder::push_slots_or_immutable(SlotRange src, BuilderOp op) { … }
void Builder::push_slots_or_immutable_indirect(SlotRange fixedRange,
int dynamicStackID,
SlotRange limitRange,
BuilderOp op) { … }
void Builder::push_uniform(SlotRange src) { … }
void Builder::push_uniform_indirect(SlotRange fixedRange,
int dynamicStackID,
SlotRange limitRange) { … }
void Builder::trace_var_indirect(int traceMaskStackID,
SlotRange fixedRange,
int dynamicStackID,
SlotRange limitRange) { … }
void Builder::push_constant_i(int32_t val, int count) { … }
void Builder::push_duplicates(int count) { … }
void Builder::push_clone(int numSlots, int offsetFromStackTop) { … }
void Builder::push_clone_from_stack(SlotRange range, int otherStackID, int offsetFromStackTop) { … }
void Builder::push_clone_indirect_from_stack(SlotRange fixedOffset,
int dynamicStackID,
int otherStackID,
int offsetFromStackTop) { … }
void Builder::pop_slots(SlotRange dst) { … }
void Builder::simplifyPopSlotsUnmasked(SlotRange* dst) { … }
void Builder::pop_slots_unmasked(SlotRange dst) { … }
void Builder::exchange_src() { … }
void Builder::pop_src_rgba() { … }
void Builder::copy_stack_to_slots(SlotRange dst, int offsetFromStackTop) { … }
void Builder::copy_stack_to_slots_indirect(SlotRange fixedRange,
int dynamicStackID,
SlotRange limitRange) { … }
static bool slot_ranges_overlap(SlotRange x, SlotRange y) { … }
void Builder::copy_constant(Slot slot, int constantValue) { … }
void Builder::copy_slots_unmasked(SlotRange dst, SlotRange src) { … }
void Builder::copy_immutable_unmasked(SlotRange dst, SlotRange src) { … }
void Builder::copy_uniform_to_slots_unmasked(SlotRange dst, SlotRange src) { … }
void Builder::copy_stack_to_slots_unmasked(SlotRange dst, int offsetFromStackTop) { … }
void Builder::pop_return_mask() { … }
void Builder::push_condition_mask() { … }
void Builder::merge_condition_mask() { … }
void Builder::zero_slots_unmasked(SlotRange dst) { … }
static int pack_nybbles(SkSpan<const int8_t> components) { … }
template <typename T>
static void unpack_nybbles_to_offsets(uint32_t components, SkSpan<T> offsets) { … }
static int max_packed_nybble(uint32_t components, size_t numComponents) { … }
void Builder::swizzle_copy_stack_to_slots(SlotRange dst,
SkSpan<const int8_t> components,
int offsetFromStackTop) { … }
void Builder::swizzle_copy_stack_to_slots_indirect(SlotRange fixedRange,
int dynamicStackID,
SlotRange limitRange,
SkSpan<const int8_t> components,
int offsetFromStackTop) { … }
void Builder::swizzle(int consumedSlots, SkSpan<const int8_t> components) { … }
void Builder::transpose(int columns, int rows) { … }
void Builder::diagonal_matrix(int columns, int rows) { … }
void Builder::matrix_resize(int origColumns, int origRows, int newColumns, int newRows) { … }
void Builder::matrix_multiply(int leftColumns, int leftRows, int rightColumns, int rightRows) { … }
std::unique_ptr<Program> Builder::finish(int numValueSlots,
int numUniformSlots,
int numImmutableSlots,
DebugTracePriv* debugTrace) { … }
static int stack_usage(const Instruction& inst) { … }
Program::StackDepths Program::tempStackMaxDepths() const { … }
Program::Program(TArray<Instruction> instrs,
int numValueSlots,
int numUniformSlots,
int numImmutableSlots,
int numLabels,
DebugTracePriv* debugTrace)
: … { … }
Program::~Program() = default;
static bool immutable_data_is_splattable(int32_t* immutablePtr, int numSlots) { … }
void Program::appendCopy(TArray<Stage>* pipeline,
SkArenaAlloc* alloc,
std::byte* basePtr,
ProgramOp baseStage,
SkRPOffset dst, int dstStride,
SkRPOffset src, int srcStride,
int numSlots) const { … }
void Program::appendCopySlotsUnmasked(TArray<Stage>* pipeline,
SkArenaAlloc* alloc,
SkRPOffset dst,
SkRPOffset src,
int numSlots) const { … }
void Program::appendCopyImmutableUnmasked(TArray<Stage>* pipeline,
SkArenaAlloc* alloc,
std::byte* basePtr,
SkRPOffset dst,
SkRPOffset src,
int numSlots) const { … }
void Program::appendCopySlotsMasked(TArray<Stage>* pipeline,
SkArenaAlloc* alloc,
SkRPOffset dst,
SkRPOffset src,
int numSlots) const { … }
void Program::appendSingleSlotUnaryOp(TArray<Stage>* pipeline, ProgramOp stage,
float* dst, int numSlots) const { … }
void Program::appendMultiSlotUnaryOp(TArray<Stage>* pipeline, ProgramOp baseStage,
float* dst, int numSlots) const { … }
void Program::appendImmediateBinaryOp(TArray<Stage>* pipeline, SkArenaAlloc* alloc,
ProgramOp baseStage,
SkRPOffset dst, int32_t value, int numSlots) const { … }
void Program::appendAdjacentNWayBinaryOp(TArray<Stage>* pipeline, SkArenaAlloc* alloc,
ProgramOp stage,
SkRPOffset dst, SkRPOffset src, int numSlots) const { … }
void Program::appendAdjacentMultiSlotBinaryOp(TArray<Stage>* pipeline, SkArenaAlloc* alloc,
ProgramOp baseStage, std::byte* basePtr,
SkRPOffset dst, SkRPOffset src, int numSlots) const { … }
void Program::appendAdjacentNWayTernaryOp(TArray<Stage>* pipeline, SkArenaAlloc* alloc,
ProgramOp stage, std::byte* basePtr, SkRPOffset dst,
SkRPOffset src0, SkRPOffset src1, int numSlots) const { … }
void Program::appendAdjacentMultiSlotTernaryOp(TArray<Stage>* pipeline, SkArenaAlloc* alloc,
ProgramOp baseStage, std::byte* basePtr,
SkRPOffset dst, SkRPOffset src0, SkRPOffset src1,
int numSlots) const { … }
void Program::appendStackRewindForNonTailcallers(TArray<Stage>* pipeline) const { … }
void Program::appendStackRewind(TArray<Stage>* pipeline) const { … }
void Builder::invoke_shader(int childIdx) { … }
void Builder::invoke_color_filter(int childIdx) { … }
void Builder::invoke_blender(int childIdx) { … }
void Builder::invoke_to_linear_srgb() { … }
void Builder::invoke_from_linear_srgb() { … }
static void* context_bit_pun(intptr_t val) { … }
std::optional<Program::SlotData> Program::allocateSlotData(SkArenaAlloc* alloc) const { … }
bool Program::appendStages(SkRasterPipeline* pipeline,
SkArenaAlloc* alloc,
RP::Callbacks* callbacks,
SkSpan<const float> uniforms) const { … }
void Program::makeStages(TArray<Stage>* pipeline,
SkArenaAlloc* alloc,
SkSpan<const float> uniforms,
const SlotData& slots) const { … }
class Program::Dumper { … };
void Program::Dumper::dump(SkWStream* out, bool writeInstructionCount) { … }
void Program::dump(SkWStream* out, bool writeInstructionCount) const { … }
}