예제 #1
0
void CollectVariables::visitVariable(const TIntermSymbol *variable,
                                     std::vector<InterfaceBlock> *infoList) const
{
    InterfaceBlock interfaceBlock;
    const TInterfaceBlock *blockType = variable->getType().getInterfaceBlock();
    ASSERT(blockType);

    interfaceBlock.name = blockType->name().c_str();
    interfaceBlock.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str();
    interfaceBlock.instanceName = (blockType->hasInstanceName() ? blockType->instanceName().c_str() : "");
    interfaceBlock.arraySize = variable->getArraySize();
    interfaceBlock.isRowMajorLayout = (blockType->matrixPacking() == EmpRowMajor);
    interfaceBlock.layout = GetBlockLayoutType(blockType->blockStorage());

    // Gather field information
    const TFieldList &fieldList = blockType->fields();

    for (size_t fieldIndex = 0; fieldIndex < fieldList.size(); ++fieldIndex)
    {
        const TField &field = *fieldList[fieldIndex];
        const TString &fullFieldName = InterfaceBlockFieldName(*blockType, field);
        const TType &fieldType = *field.type();

        GetVariableTraverser traverser(mSymbolTable);
        traverser.traverse(fieldType, fullFieldName, &interfaceBlock.fields);

        interfaceBlock.fields.back().isRowMajorLayout = (fieldType.getLayoutQualifier().matrixPacking == EmpRowMajor);
    }

    infoList->push_back(interfaceBlock);
}
예제 #2
0
TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks)
{
    TString interfaceBlocks;

    for (ReferencedSymbols::const_iterator interfaceBlockIt = referencedInterfaceBlocks.begin();
         interfaceBlockIt != referencedInterfaceBlocks.end(); interfaceBlockIt++)
    {
        const TType &nodeType = interfaceBlockIt->second->getType();
        const TInterfaceBlock &interfaceBlock = *nodeType.getInterfaceBlock();
        const TFieldList &fieldList = interfaceBlock.fields();

        unsigned int arraySize = static_cast<unsigned int>(interfaceBlock.arraySize());
        InterfaceBlock activeBlock(interfaceBlock.name().c_str(), arraySize, mInterfaceBlockRegister);
        for (unsigned int typeIndex = 0; typeIndex < fieldList.size(); typeIndex++)
        {
            const TField &field = *fieldList[typeIndex];
            const TString &fullFieldName = InterfaceBlockFieldName(interfaceBlock, field);

            bool isRowMajor = (field.type()->getLayoutQualifier().matrixPacking == EmpRowMajor);
            GetInterfaceBlockFieldTraverser traverser(&activeBlock.fields, isRowMajor);
            traverser.traverse(*field.type(), fullFieldName);
        }

        mInterfaceBlockRegisterMap[activeBlock.name] = mInterfaceBlockRegister;
        mInterfaceBlockRegister += std::max(1u, arraySize);

        BlockLayoutType blockLayoutType = GetBlockLayoutType(interfaceBlock.blockStorage());
        SetBlockLayout(&activeBlock, blockLayoutType);

        if (interfaceBlock.matrixPacking() == EmpRowMajor)
        {
            activeBlock.isRowMajorLayout = true;
        }

        mActiveInterfaceBlocks.push_back(activeBlock);

        if (interfaceBlock.hasInstanceName())
        {
            interfaceBlocks += interfaceBlockStructString(interfaceBlock);
        }

        if (arraySize > 0)
        {
            for (unsigned int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++)
            {
                interfaceBlocks += interfaceBlockString(interfaceBlock, activeBlock.registerIndex + arrayIndex, arrayIndex);
            }
        }
        else
        {
            interfaceBlocks += interfaceBlockString(interfaceBlock, activeBlock.registerIndex, GL_INVALID_INDEX);
        }
    }

    return (interfaceBlocks.empty() ? "" : ("// Interface Blocks\n\n" + interfaceBlocks));
}