Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkSL::RP::SlotManager Class Reference

Public Member Functions

 SlotManager (std::vector< SlotDebugInfo > *i)
 
void addSlotDebugInfoForGroup (const std::string &varName, const Type &type, Position pos, int *groupIndex, bool isFunctionReturnValue)
 
void addSlotDebugInfo (const std::string &varName, const Type &type, Position pos, bool isFunctionReturnValue)
 
SlotRange createSlots (std::string name, const Type &type, Position pos, bool isFunctionReturnValue)
 
std::optional< SlotRangemapVariableToSlots (const Variable &v, SlotRange range)
 
void unmapVariableSlots (const Variable &v)
 
SlotRange getVariableSlots (const Variable &v)
 
SlotRange getFunctionSlots (const IRNode &callSite, const FunctionDeclaration &f)
 
int slotCount () const
 

Detailed Description

Definition at line 95 of file SkSLRasterPipelineCodeGenerator.cpp.

Constructor & Destructor Documentation

◆ SlotManager()

SkSL::RP::SlotManager::SlotManager ( std::vector< SlotDebugInfo > *  i)
inline

Definition at line 97 of file SkSLRasterPipelineCodeGenerator.cpp.

97: fSlotDebugInfo(i) {}

Member Function Documentation

◆ addSlotDebugInfo()

void SkSL::RP::SlotManager::addSlotDebugInfo ( const std::string &  varName,
const Type type,
Position  pos,
bool  isFunctionReturnValue 
)

Definition at line 1160 of file SkSLRasterPipelineCodeGenerator.cpp.

1163 {
1164 int groupIndex = 0;
1165 this->addSlotDebugInfoForGroup(varName, type, pos, &groupIndex, isFunctionReturnValue);
1166 SkASSERT((size_t)groupIndex == type.slotCount());
1167}
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
GLenum type
void addSlotDebugInfoForGroup(const std::string &varName, const Type &type, Position pos, int *groupIndex, bool isFunctionReturnValue)

◆ addSlotDebugInfoForGroup()

void SkSL::RP::SlotManager::addSlotDebugInfoForGroup ( const std::string &  varName,
const Type type,
Position  pos,
int groupIndex,
bool  isFunctionReturnValue 
)

Used by createSlots to add this variable to SlotDebugInfo inside the DebugTrace.

Definition at line 1109 of file SkSLRasterPipelineCodeGenerator.cpp.

1113 {
1114 SkASSERT(fSlotDebugInfo);
1115 switch (type.typeKind()) {
1117 int nslots = type.columns();
1118 const Type& elemType = type.componentType();
1119 for (int slot = 0; slot < nslots; ++slot) {
1120 this->addSlotDebugInfoForGroup(varName + "[" + std::to_string(slot) + "]", elemType,
1121 pos, groupIndex, isFunctionReturnValue);
1122 }
1123 break;
1124 }
1126 for (const Field& field : type.fields()) {
1127 this->addSlotDebugInfoForGroup(varName + "." + std::string(field.fName),
1128 *field.fType, pos, groupIndex,
1129 isFunctionReturnValue);
1130 }
1131 break;
1132 }
1133 default:
1134 SkASSERTF(0, "unsupported slot type %d", (int)type.typeKind());
1135 [[fallthrough]];
1136
1140 Type::NumberKind numberKind = type.componentType().numberKind();
1141 int nslots = type.slotCount();
1142
1143 for (int slot = 0; slot < nslots; ++slot) {
1144 SlotDebugInfo slotInfo;
1145 slotInfo.name = varName;
1146 slotInfo.columns = type.columns();
1147 slotInfo.rows = type.rows();
1148 slotInfo.componentIndex = slot;
1149 slotInfo.groupIndex = (*groupIndex)++;
1150 slotInfo.numberKind = numberKind;
1151 slotInfo.pos = pos;
1152 slotInfo.fnReturnValue = isFunctionReturnValue ? 1 : -1;
1153 fSlotDebugInfo->push_back(std::move(slotInfo));
1154 }
1155 break;
1156 }
1157 }
1158}
#define SkASSERTF(cond, fmt,...)
Definition: SkAssert.h:117
static SkString to_string(int n)
Definition: nanobench.cpp:119

◆ createSlots()

SlotRange SkSL::RP::SlotManager::createSlots ( std::string  name,
const Type type,
Position  pos,
bool  isFunctionReturnValue 
)

Creates slots associated with an SkSL variable or return value.

Definition at line 1169 of file SkSLRasterPipelineCodeGenerator.cpp.

1172 {
1173 size_t nslots = type.slotCount();
1174 if (nslots == 0) {
1175 return {};
1176 }
1177 if (fSlotDebugInfo) {
1178 // Our debug slot-info table should have the same length as the actual slot table.
1179 SkASSERT(fSlotDebugInfo->size() == (size_t)fSlotCount);
1180
1181 // Append slot names and types to our debug slot-info table.
1182 fSlotDebugInfo->reserve(fSlotCount + nslots);
1183 this->addSlotDebugInfo(name, type, pos, isFunctionReturnValue);
1184
1185 // Confirm that we added the expected number of slots.
1186 SkASSERT(fSlotDebugInfo->size() == (size_t)(fSlotCount + nslots));
1187 }
1188
1189 SlotRange result = {fSlotCount, (int)nslots};
1190 fSlotCount += nslots;
1191 return result;
1192}
void addSlotDebugInfo(const std::string &varName, const Type &type, Position pos, bool isFunctionReturnValue)
GAsyncResult * result
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ getFunctionSlots()

SlotRange SkSL::RP::SlotManager::getFunctionSlots ( const IRNode callSite,
const FunctionDeclaration f 
)

Looks up the slots associated with an SkSL function's return value; creates the range if necessary. Note that recursion is never supported, so we don't need to maintain return values in a stack; we can just statically allocate one slot per function call-site.

Definition at line 1220 of file SkSLRasterPipelineCodeGenerator.cpp.

1220 {
1221 SlotRange* entry = fSlotMap.find(&callSite);
1222 if (entry != nullptr) {
1223 return *entry;
1224 }
1225 SlotRange range = this->createSlots("[" + std::string(f.name()) + "].result",
1226 f.returnType(),
1227 f.fPosition,
1228 /*isFunctionReturnValue=*/true);
1229 fSlotMap.set(&callSite, range);
1230 return range;
1231}
SlotRange createSlots(std::string name, const Type &type, Position pos, bool isFunctionReturnValue)

◆ getVariableSlots()

SlotRange SkSL::RP::SlotManager::getVariableSlots ( const Variable v)

Looks up the slots associated with an SkSL variable; creates the slot if necessary.

Definition at line 1207 of file SkSLRasterPipelineCodeGenerator.cpp.

1207 {
1208 SlotRange* entry = fSlotMap.find(&v);
1209 if (entry != nullptr) {
1210 return *entry;
1211 }
1212 SlotRange range = this->createSlots(std::string(v.name()),
1213 v.type(),
1214 v.fPosition,
1215 /*isFunctionReturnValue=*/false);
1216 this->mapVariableToSlots(v, range);
1217 return range;
1218}
std::optional< SlotRange > mapVariableToSlots(const Variable &v, SlotRange range)

◆ mapVariableToSlots()

std::optional< SlotRange > SkSL::RP::SlotManager::mapVariableToSlots ( const Variable v,
SlotRange  range 
)

Associates previously-created slots with an SkSL variable; this can allow multiple variables to share overlapping ranges. If the variable was already associated with a slot range, returns the previously associated range.

Definition at line 1194 of file SkSLRasterPipelineCodeGenerator.cpp.

1194 {
1195 SkASSERT(v.type().slotCount() == SkToSizeT(range.count));
1196 const SlotRange* existingEntry = fSlotMap.find(&v);
1197 std::optional<SlotRange> originalRange = existingEntry ? std::optional(*existingEntry)
1198 : std::nullopt;
1199 fSlotMap.set(&v, range);
1200 return originalRange;
1201}
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31
Definition: ref_ptr.h:256

◆ slotCount()

int SkSL::RP::SlotManager::slotCount ( ) const
inline

Returns the total number of slots consumed.

Definition at line 140 of file SkSLRasterPipelineCodeGenerator.cpp.

140{ return fSlotCount; }

◆ unmapVariableSlots()

void SkSL::RP::SlotManager::unmapVariableSlots ( const Variable v)

Deletes the existing mapping between a variable and its slots; a future call to getVariableSlots will see this as a brand new variable and associate new slots.

Definition at line 1203 of file SkSLRasterPipelineCodeGenerator.cpp.

1203 {
1204 fSlotMap.remove(&v);
1205}

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