Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkSL::SwizzleLValue Class Reference
Inheritance diagram for SkSL::SwizzleLValue:
SkSL::SPIRVCodeGenerator::LValue

Public Member Functions

 SwizzleLValue (SPIRVCodeGenerator &gen, SpvId vecPointer, const ComponentArray &components, const Type &baseType, const Type &swizzleType, SpvStorageClass_ storageClass)
 
bool applySwizzle (const ComponentArray &components, const Type &newType) override
 
SpvStorageClass storageClass () const override
 
SpvId load (OutputStream &out) override
 
void store (SpvId value, OutputStream &out) override
 
- Public Member Functions inherited from SkSL::SPIRVCodeGenerator::LValue
virtual ~LValue ()
 
virtual SpvId getPointer ()
 
virtual bool isMemoryObjectPointer () const
 
virtual bool applySwizzle (const ComponentArray &components, const Type &newType)
 
virtual SpvStorageClass storageClass () const =0
 
virtual SpvId load (OutputStream &out)=0
 
virtual void store (SpvId value, OutputStream &out)=0
 

Detailed Description

Definition at line 3121 of file SkSLSPIRVCodeGenerator.cpp.

Constructor & Destructor Documentation

◆ SwizzleLValue()

SkSL::SwizzleLValue::SwizzleLValue ( SPIRVCodeGenerator gen,
SpvId  vecPointer,
const ComponentArray components,
const Type baseType,
const Type swizzleType,
SpvStorageClass_  storageClass 
)
inline

Definition at line 3123 of file SkSLSPIRVCodeGenerator.cpp.

3125 : fGen(gen)
3126 , fVecPointer(vecPointer)
3127 , fComponents(components)
3128 , fBaseType(&baseType)
3129 , fSwizzleType(&swizzleType)
3130 , fStorageClass(storageClass) {}
SpvStorageClass storageClass() const override
Definition: gen.py:1

Member Function Documentation

◆ applySwizzle()

bool SkSL::SwizzleLValue::applySwizzle ( const ComponentArray components,
const Type newType 
)
inlineoverridevirtual

Reimplemented from SkSL::SPIRVCodeGenerator::LValue.

Definition at line 3132 of file SkSLSPIRVCodeGenerator.cpp.

3132 {
3133 ComponentArray updatedSwizzle;
3134 for (int8_t component : components) {
3135 if (component < 0 || component >= fComponents.size()) {
3136 SkDEBUGFAILF("swizzle accessed nonexistent component %d", (int)component);
3137 return false;
3138 }
3139 updatedSwizzle.push_back(fComponents[component]);
3140 }
3141 fComponents = updatedSwizzle;
3142 fSwizzleType = &newType;
3143 return true;
3144 }
#define SkDEBUGFAILF(fmt,...)
Definition: SkAssert.h:119
skia_private::FixedArray< 4, int8_t > ComponentArray
Definition: SkSLSwizzle.h:46

◆ load()

SpvId SkSL::SwizzleLValue::load ( OutputStream out)
inlineoverridevirtual

Implements SkSL::SPIRVCodeGenerator::LValue.

Definition at line 3150 of file SkSLSPIRVCodeGenerator.cpp.

3150 {
3151 SpvId base = fGen.nextId(fBaseType);
3152 fGen.writeInstruction(SpvOpLoad, fGen.getType(*fBaseType), base, fVecPointer, out);
3153 SpvId result = fGen.nextId(fBaseType);
3154 fGen.writeOpCode(SpvOpVectorShuffle, 5 + (int32_t) fComponents.size(), out);
3155 fGen.writeWord(fGen.getType(*fSwizzleType), out);
3156 fGen.writeWord(result, out);
3157 fGen.writeWord(base, out);
3158 fGen.writeWord(base, out);
3159 for (int component : fComponents) {
3160 fGen.writeWord(component, out);
3161 }
3162 return result;
3163 }
GAsyncResult * result
unsigned int SpvId
Definition: spirv.h:51
@ SpvOpLoad
Definition: spirv.h:628
@ SpvOpVectorShuffle
Definition: spirv.h:645

◆ storageClass()

SpvStorageClass SkSL::SwizzleLValue::storageClass ( ) const
inlineoverridevirtual

Implements SkSL::SPIRVCodeGenerator::LValue.

Definition at line 3146 of file SkSLSPIRVCodeGenerator.cpp.

3146 {
3147 return fStorageClass;
3148 }

◆ store()

void SkSL::SwizzleLValue::store ( SpvId  value,
OutputStream out 
)
inlineoverridevirtual

Implements SkSL::SPIRVCodeGenerator::LValue.

Definition at line 3165 of file SkSLSPIRVCodeGenerator.cpp.

3165 {
3166 // use OpVectorShuffle to mix and match the vector components. We effectively create
3167 // a virtual vector out of the concatenation of the left and right vectors, and then
3168 // select components from this virtual vector to make the result vector. For
3169 // instance, given:
3170 // float3L = ...;
3171 // float3R = ...;
3172 // L.xz = R.xy;
3173 // we end up with the virtual vector (L.x, L.y, L.z, R.x, R.y, R.z). Then we want
3174 // our result vector to look like (R.x, L.y, R.y), so we need to select indices
3175 // (3, 1, 4).
3176 SpvId base = fGen.nextId(fBaseType);
3177 fGen.writeInstruction(SpvOpLoad, fGen.getType(*fBaseType), base, fVecPointer, out);
3178 SpvId shuffle = fGen.nextId(fBaseType);
3179 fGen.writeOpCode(SpvOpVectorShuffle, 5 + fBaseType->columns(), out);
3180 fGen.writeWord(fGen.getType(*fBaseType), out);
3181 fGen.writeWord(shuffle, out);
3182 fGen.writeWord(base, out);
3183 fGen.writeWord(value, out);
3184 for (int i = 0; i < fBaseType->columns(); i++) {
3185 // current offset into the virtual vector, defaults to pulling the unmodified
3186 // value from the left side
3187 int offset = i;
3188 // check to see if we are writing this component
3189 for (int j = 0; j < fComponents.size(); j++) {
3190 if (fComponents[j] == i) {
3191 // we're writing to this component, so adjust the offset to pull from
3192 // the correct component of the right side instead of preserving the
3193 // value from the left
3194 offset = (int) (j + fBaseType->columns());
3195 break;
3196 }
3197 }
3198 fGen.writeWord(offset, out);
3199 }
3200 fGen.writeOpStore(fStorageClass, fVecPointer, shuffle, out);
3201 }
virtual int columns() const
Definition: SkSLType.h:429
uint8_t value
SI Vec< sizeof...(Ix), T > shuffle(const Vec< N, T > &)
Definition: SkVx.h:667
SeparatedVector2 offset

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