summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-legalize-mesh-outputs.cpp
blob: 52826c064a0a2a055ce8a766297086d393a29ef7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "slang-ir-legalize-mesh-outputs.h"

#include "slang-ir-clone.h"
#include "slang-ir-insts.h"
#include "slang-ir.h"

namespace Slang
{

void legalizeMeshOutputTypes(IRModule* module)
{
    IRBuilder builder(module);

    for (auto inst : module->getGlobalInsts())
    {
        if (auto meshOutput = as<IRMeshOutputType>(inst))
        {
            auto elemType = meshOutput->getElementType();
            auto maxCount = meshOutput->getMaxElementCount();
            auto arrayType = builder.getArrayType(elemType, maxCount);
            IROp decorationOp =
                as<IRVerticesType>(meshOutput)  ? kIROp_VerticesDecoration
                : as<IRIndicesType>(meshOutput) ? kIROp_IndicesDecoration
                : as<IRPrimitivesType>(meshOutput)
                    ? kIROp_PrimitivesDecoration
                    : (SLANG_UNREACHABLE("Missing case for IRMeshOutputType"), IROp(0));
            // Ensure that all params are marked up as vertices/indices/primitives
            traverseUsers<IRParam>(
                meshOutput,
                [&](IRParam* i) { builder.addMeshOutputDecoration(decorationOp, i, maxCount); });
            meshOutput->replaceUsesWith(arrayType);
        }
    }
}

} // namespace Slang