summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-user-type-hint.cpp
blob: 100794d4a22ee6a0ffe2628c29fe4491b7f98d05 (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
37
#include "slang-ir-user-type-hint.h"

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

namespace Slang
{

void addUserTypeHintDecorations(IRModule* module)
{
    for (auto globalInst : module->getGlobalInsts())
    {
        auto inst = as<IRGlobalParam>(globalInst);
        if (!inst)
            continue;
        if (inst->getDataType())
        {
            // Preserve the original type name as a decoration before we do any type lowering.
            // This is needed to implement -fspv-reflect, which allows the compiler to output the
            // original user-friendly type name of each shader parameter as a SPIRV decoration.
            //
            StringBuilder sb;
            getTypeNameHint(sb, inst->getDataType());
            if (sb.getLength())
            {
                IRBuilder builder(inst);
                builder.addDecoration(
                    inst,
                    kIROp_UserTypeNameDecoration,
                    builder.getStringValue(sb.produceString().getUnownedSlice()));
            }
        }
    }
}

} // namespace Slang