void StructureHLSL::storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking) { Std140PaddingHelper padHelper = getPaddingHelper(); const TFieldList &fields = structure.fields(); for (unsigned int i = 0; i < fields.size(); i++) { padHelper.prePadding(*fields[i]->type()); } // Add remaining element index to the global map, for use with nested structs in standard layouts const TString &structName = QualifiedStructNameString(structure, useHLSLRowMajorPacking, true); mStd140StructElementIndexes[structName] = padHelper.elementIndex(); }
TString StructureHLSL::define(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing, Std140PaddingHelper *padHelper) { const TFieldList &fields = structure.fields(); const bool isNameless = (structure.name() == ""); const TString &structName = QualifiedStructNameString(structure, useHLSLRowMajorPacking, useStd140Packing); const TString declareString = (isNameless ? "struct" : "struct " + structName); TString string; string += declareString + "\n" "{\n"; for (unsigned int i = 0; i < fields.size(); i++) { const TField &field = *fields[i]; const TType &fieldType = *field.type(); const TStructure *fieldStruct = fieldType.getStruct(); const TString &fieldTypeString = fieldStruct ? QualifiedStructNameString(*fieldStruct, useHLSLRowMajorPacking, useStd140Packing) : TypeString(fieldType); if (padHelper) { string += padHelper->prePaddingString(fieldType); } string += " " + fieldTypeString + " " + DecorateField(field.name(), structure) + ArrayString(fieldType) + ";\n"; if (padHelper) { string += padHelper->postPaddingString(fieldType, useHLSLRowMajorPacking); } } // Nameless structs do not finish with a semicolon and newline, to leave room for an instance variable string += (isNameless ? "} " : "};\n"); return string; }
TIntermTyped *CreateZeroNode(const TType &type) { TType constType(type); constType.setQualifier(EvqConst); if (!type.isArray() && type.getBasicType() != EbtStruct) { size_t size = constType.getObjectSize(); TConstantUnion *u = new TConstantUnion[size]; for (size_t i = 0; i < size; ++i) { switch (type.getBasicType()) { case EbtFloat: u[i].setFConst(0.0f); break; case EbtInt: u[i].setIConst(0); break; case EbtUInt: u[i].setUConst(0u); break; case EbtBool: u[i].setBConst(false); break; default: // CreateZeroNode is called by ParseContext that keeps parsing even when an // error occurs, so it is possible for CreateZeroNode to be called with // non-basic types. This happens only on error condition but CreateZeroNode // needs to return a value with the correct type to continue the typecheck. // That's why we handle non-basic type by setting whatever value, we just need // the type to be right. u[i].setIConst(42); break; } } TIntermConstantUnion *node = new TIntermConstantUnion(u, constType); return node; } if (type.getBasicType() == EbtVoid) { // Void array. This happens only on error condition, similarly to the case above. We don't // have a constructor operator for void, so this needs special handling. We'll end up with a // value without the array type, but that should not be a problem. while (constType.isArray()) { constType.toArrayElementType(); } return CreateZeroNode(constType); } TIntermSequence *arguments = new TIntermSequence(); if (type.isArray()) { TType elementType(type); elementType.toArrayElementType(); size_t arraySize = type.getOutermostArraySize(); for (size_t i = 0; i < arraySize; ++i) { arguments->push_back(CreateZeroNode(elementType)); } } else { ASSERT(type.getBasicType() == EbtStruct); TStructure *structure = type.getStruct(); for (const auto &field : structure->fields()) { arguments->push_back(CreateZeroNode(*field->type())); } } return TIntermAggregate::CreateConstructor(constType, arguments); }