Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
 

Detailed Description

Definition at line 3097 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 3099 of file SkSLSPIRVCodeGenerator.cpp.

3101 : fGen(gen)
3102 , fVecPointer(vecPointer)
3103 , fComponents(components)
3104 , fBaseType(&baseType)
3105 , fSwizzleType(&swizzleType)
3106 , 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 3108 of file SkSLSPIRVCodeGenerator.cpp.

3108 {
3109 ComponentArray updatedSwizzle;
3110 for (int8_t component : components) {
3111 if (component < 0 || component >= fComponents.size()) {
3112 SkDEBUGFAILF("swizzle accessed nonexistent component %d", (int)component);
3113 return false;
3114 }
3115 updatedSwizzle.push_back(fComponents[component]);
3116 }
3117 fComponents = updatedSwizzle;
3118 fSwizzleType = &newType;
3119 return true;
3120 }
#define SkDEBUGFAILF(fmt,...)
Definition SkAssert.h:119
int size() const
Definition SkTArray.h:416
skia_private::STArray< 4, int8_t > ComponentArray
Definition SkSLDefines.h:24

◆ load()

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

Implements SkSL::SPIRVCodeGenerator::LValue.

Definition at line 3126 of file SkSLSPIRVCodeGenerator.cpp.

3126 {
3127 SpvId base = fGen.nextId(fBaseType);
3128 fGen.writeInstruction(SpvOpLoad, fGen.getType(*fBaseType), base, fVecPointer, out);
3129 SpvId result = fGen.nextId(fBaseType);
3130 fGen.writeOpCode(SpvOpVectorShuffle, 5 + (int32_t) fComponents.size(), out);
3131 fGen.writeWord(fGen.getType(*fSwizzleType), out);
3132 fGen.writeWord(result, out);
3133 fGen.writeWord(base, out);
3134 fGen.writeWord(base, out);
3135 for (int component : fComponents) {
3136 fGen.writeWord(component, out);
3137 }
3138 return result;
3139 }
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 3122 of file SkSLSPIRVCodeGenerator.cpp.

3122 {
3123 return fStorageClass;
3124 }

◆ store()

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

Implements SkSL::SPIRVCodeGenerator::LValue.

Definition at line 3141 of file SkSLSPIRVCodeGenerator.cpp.

3141 {
3142 // use OpVectorShuffle to mix and match the vector components. We effectively create
3143 // a virtual vector out of the concatenation of the left and right vectors, and then
3144 // select components from this virtual vector to make the result vector. For
3145 // instance, given:
3146 // float3L = ...;
3147 // float3R = ...;
3148 // L.xz = R.xy;
3149 // we end up with the virtual vector (L.x, L.y, L.z, R.x, R.y, R.z). Then we want
3150 // our result vector to look like (R.x, L.y, R.y), so we need to select indices
3151 // (3, 1, 4).
3152 SpvId base = fGen.nextId(fBaseType);
3153 fGen.writeInstruction(SpvOpLoad, fGen.getType(*fBaseType), base, fVecPointer, out);
3154 SpvId shuffle = fGen.nextId(fBaseType);
3155 fGen.writeOpCode(SpvOpVectorShuffle, 5 + fBaseType->columns(), out);
3156 fGen.writeWord(fGen.getType(*fBaseType), out);
3157 fGen.writeWord(shuffle, out);
3158 fGen.writeWord(base, out);
3159 fGen.writeWord(value, out);
3160 for (int i = 0; i < fBaseType->columns(); i++) {
3161 // current offset into the virtual vector, defaults to pulling the unmodified
3162 // value from the left side
3163 int offset = i;
3164 // check to see if we are writing this component
3165 for (int j = 0; j < fComponents.size(); j++) {
3166 if (fComponents[j] == i) {
3167 // we're writing to this component, so adjust the offset to pull from
3168 // the correct component of the right side instead of preserving the
3169 // value from the left
3170 offset = (int) (j + fBaseType->columns());
3171 break;
3172 }
3173 }
3174 fGen.writeWord(offset, out);
3175 }
3176 fGen.writeOpStore(fStorageClass, fVecPointer, shuffle, out);
3177 }
Type::kYUV Type::kRGBA() int(0.7 *637)
virtual int columns() const
Definition SkSLType.h:429
SI Vec< sizeof...(Ix), T > shuffle(const Vec< N, T > &)
Definition SkVx.h:667
Point offset

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