Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
SkSL::RP::Program Class Reference

#include <SkSLRasterPipelineBuilder.h>

Classes

class  Dumper
 

Public Member Functions

 Program (skia_private::TArray< Instruction > instrs, int numValueSlots, int numUniformSlots, int numImmutableSlots, int numLabels, DebugTracePriv *debugTrace)
 
 ~Program ()
 
bool appendStages (SkRasterPipeline *pipeline, SkArenaAlloc *alloc, Callbacks *callbacks, SkSpan< const float > uniforms) const
 
void dump (SkWStream *out, bool writeInstructionCount=false) const
 
int numUniforms () const
 

Friends

class Dumper
 

Detailed Description

Definition at line 152 of file SkSLRasterPipelineBuilder.h.

Constructor & Destructor Documentation

◆ Program()

SkSL::RP::Program::Program ( skia_private::TArray< Instruction instrs,
int  numValueSlots,
int  numUniformSlots,
int  numImmutableSlots,
int  numLabels,
DebugTracePriv debugTrace 
)

Definition at line 1390 of file SkSLRasterPipelineBuilder.cpp.

1396 : fInstructions(std::move(instrs))
1397 , fNumValueSlots(numValueSlots)
1398 , fNumUniformSlots(numUniformSlots)
1399 , fNumImmutableSlots(numImmutableSlots)
1400 , fNumLabels(numLabels)
1401 , fDebugTrace(debugTrace) {
1402 this->optimize();
1403
1404 fTempStackMaxDepths = this->tempStackMaxDepths();
1405
1406 fNumTempStackSlots = 0;
1407 for (const int depth : fTempStackMaxDepths) {
1408 fNumTempStackSlots += depth;
1409 }
1410
1411 if (fDebugTrace) {
1412 fTraceHook = SkSL::Tracer::Make(&fDebugTrace->fTraceInfo);
1413 }
1414}
std::vector< TraceInfo > fTraceInfo
static std::unique_ptr< Tracer > Make(std::vector< TraceInfo > *traceInfo)

◆ ~Program()

SkSL::RP::Program::~Program ( )
default

Member Function Documentation

◆ appendStages()

bool SkSL::RP::Program::appendStages ( SkRasterPipeline pipeline,
SkArenaAlloc alloc,
RP::Callbacks callbacks,
SkSpan< const float >  uniforms 
) const

Definition at line 1652 of file SkSLRasterPipelineBuilder.cpp.

1655 {
1656#if defined(SKSL_STANDALONE)
1657 return false;
1658#else
1659 // Convert our Instruction list to an array of ProgramOps.
1660 TArray<Stage> stages;
1661 SlotData slotData = this->allocateSlotData(alloc);
1662 this->makeStages(&stages, alloc, uniforms, slotData);
1663
1664 // Allocate buffers for branch targets and labels; these are needed to convert labels into
1665 // actual offsets into the pipeline and fix up branches.
1667 branchContexts.reserve_exact(fNumLabels);
1668 TArray<int> labelOffsets;
1669 labelOffsets.push_back_n(fNumLabels, -1);
1670 TArray<int> branchGoesToLabel;
1671 branchGoesToLabel.reserve_exact(fNumLabels);
1672
1673 auto resetBasePointer = [&]() {
1674 // Whenever we hand off control to another shader, we have to assume that it might overwrite
1675 // the base pointer (if it uses SkSL, it will!), so we reset it on return.
1676 pipeline->append(SkRasterPipelineOp::set_base_pointer, slotData.values.data());
1677 };
1678
1679 resetBasePointer();
1680
1681 for (const Stage& stage : stages) {
1682 switch (stage.op) {
1683 case ProgramOp::stack_rewind:
1684 pipeline->appendStackRewind();
1685 break;
1686
1687 case ProgramOp::invoke_shader:
1688 if (!callbacks || !callbacks->appendShader(sk_bit_cast<intptr_t>(stage.ctx))) {
1689 return false;
1690 }
1691 resetBasePointer();
1692 break;
1693
1694 case ProgramOp::invoke_color_filter:
1695 if (!callbacks || !callbacks->appendColorFilter(sk_bit_cast<intptr_t>(stage.ctx))) {
1696 return false;
1697 }
1698 resetBasePointer();
1699 break;
1700
1701 case ProgramOp::invoke_blender:
1702 if (!callbacks || !callbacks->appendBlender(sk_bit_cast<intptr_t>(stage.ctx))) {
1703 return false;
1704 }
1705 resetBasePointer();
1706 break;
1707
1708 case ProgramOp::invoke_to_linear_srgb:
1709 if (!callbacks) {
1710 return false;
1711 }
1712 callbacks->toLinearSrgb(stage.ctx);
1713 // A ColorSpaceXform shouldn't ever alter the base pointer, so we don't need to call
1714 // resetBasePointer here.
1715 break;
1716
1717 case ProgramOp::invoke_from_linear_srgb:
1718 if (!callbacks) {
1719 return false;
1720 }
1721 callbacks->fromLinearSrgb(stage.ctx);
1722 // A ColorSpaceXform shouldn't ever alter the base pointer, so we don't need to call
1723 // resetBasePointer here.
1724 break;
1725
1726 case ProgramOp::label: {
1727 // Remember the absolute pipeline position of this label.
1728 int labelID = sk_bit_cast<intptr_t>(stage.ctx);
1729 SkASSERT(labelID >= 0 && labelID < fNumLabels);
1730 labelOffsets[labelID] = pipeline->getNumStages();
1731 break;
1732 }
1733 case ProgramOp::jump:
1734 case ProgramOp::branch_if_all_lanes_active:
1735 case ProgramOp::branch_if_any_lanes_active:
1736 case ProgramOp::branch_if_no_lanes_active:
1737 case ProgramOp::branch_if_no_active_lanes_eq: {
1738 // The branch context contain a valid label ID at this point.
1739 auto* branchCtx = static_cast<SkRasterPipeline_BranchCtx*>(stage.ctx);
1740 int labelID = branchCtx->offset;
1741 SkASSERT(labelID >= 0 && labelID < fNumLabels);
1742
1743 // Replace the label ID in the branch context with the absolute pipeline position.
1744 // We will go back over the branch targets at the end and fix them up.
1745 branchCtx->offset = pipeline->getNumStages();
1746
1747 SkASSERT(branchContexts.size() == branchGoesToLabel.size());
1748 branchContexts.push_back(branchCtx);
1749 branchGoesToLabel.push_back(labelID);
1750 [[fallthrough]];
1751 }
1752 default:
1753 // Append a regular op to the program.
1754 SkASSERT((int)stage.op < kNumRasterPipelineHighpOps);
1755 pipeline->append((SkRasterPipelineOp)stage.op, stage.ctx);
1756 break;
1757 }
1758 }
1759
1760 // Now that we have assembled the program and know the pipeline positions of each label and
1761 // branch, fix up every branch target.
1762 SkASSERT(branchContexts.size() == branchGoesToLabel.size());
1763 for (int index = 0; index < branchContexts.size(); ++index) {
1764 int branchFromIdx = branchContexts[index]->offset;
1765 int branchToIdx = labelOffsets[branchGoesToLabel[index]];
1766 branchContexts[index]->offset = branchToIdx - branchFromIdx;
1767 }
1768
1769 return true;
1770#endif
1771}
#define SkASSERT(cond)
Definition SkAssert.h:116
static constexpr int kNumRasterPipelineHighpOps
int getNumStages() const
void append(SkRasterPipelineOp, void *=nullptr)
T * push_back_n(int n)
Definition SkTArray.h:262
int size() const
Definition SkTArray.h:416
void reserve_exact(int n)
Definition SkTArray.h:176

◆ dump()

void SkSL::RP::Program::dump ( SkWStream out,
bool  writeInstructionCount = false 
) const

Definition at line 3771 of file SkSLRasterPipelineBuilder.cpp.

3771 {
3772 Dumper(*this).dump(out, writeInstructionCount);
3773}

◆ numUniforms()

int SkSL::RP::Program::numUniforms ( ) const
inline

Definition at line 169 of file SkSLRasterPipelineBuilder.h.

169{ return fNumUniformSlots; }

Friends And Related Symbol Documentation

◆ Dumper

friend class Dumper
friend

Definition at line 281 of file SkSLRasterPipelineBuilder.h.


The documentation for this class was generated from the following files: