Repository: shader-slang/slang
File: source/slang/slang-ir-glsl-legalize.cpp (C++)

Code before:
};

struct GLSLSystemValueInfo
{
    // The name of the built-in GLSL variable
    char const* name;

    // The name of an outer array that wraps
    // the variable, in the case of a GS input
    char const* outerArrayName;

    // The required type of the built-in variable
    IRType* requiredType;

    // If the built in GLSL variable is an array, holds the index into the array.
    // If < 0, then there is no array indexing
    Index arrayIndex;

    // The kind of the system value that requires special treatment.
    GLSLSystemValueKind kind = GLSLSystemValueKind::General;

    // The target builtin name.
    IRTargetBuiltinVarName targetVarName = IRTargetBuiltinVarName::Unknown;
};

// Helper function to create member-level debug info for entry point struct parameters
void createMemberDebugInfo(
    IRBuilder* builder,
    IRStructType* structType,
    ScalarizedVal globalValue,
    IRDebugVar* parentDebugVar)
{
    // Only handle tuple values (struct members)
    if (globalValue.flavor != ScalarizedVal::Flavor::tuple)
        return;

    auto tupleVal = as<ScalarizedTupleValImpl>(globalValue.impl);
    if (!tupleVal)
        return;

    // Get debug location from the parent debug variable
    IRInst* debugSource = nullptr;
    IRInst* debugLine = nullptr;
    IRInst* debugCol = nullptr;

    // Try to find debug location information from the parent function
    if (auto parentFunc = getParentFunc(parentDebugVar))
    {
        if (auto funcDebugLoc = parentFunc->findDecoration<IRDebugLocationDecoration>())
        {
            debugSource = funcDebugLoc->getSource();

Review comment (bug):
can you explain why we need this? Doesn't every entrypoint parameter already have a debug var after ir lowering?

Code after:
};

struct GLSLSystemValueInfo
{
    // The name of the built-in GLSL variable
    char const* name;

    // The name of an outer array that wraps
    // the variable, in the case of a GS input
    char const* outerArrayName;

    // The required type of the built-in variable
    IRType* requiredType;

    // If the built in GLSL variable is an array, holds the index into the array.
    // If < 0, then there is no array indexing
    Index arrayIndex;

    // The kind of the system value that requires special treatment.
    GLSLSystemValueKind kind = GLSLSystemValueKind::General;

    // The target builtin name.
    IRTargetBuiltinVarName targetVarName = IRTargetBuiltinVarName::Unknown;
};

static void leafAddressesImpl(List<IRInst*>& ret, const ScalarizedVal& v)
{
    switch (v.flavor)
    {
    case ScalarizedVal::Flavor::none:
    case ScalarizedVal::Flavor::value:
        break;

    case ScalarizedVal::Flavor::address:
        {
            ret.add(v.irValue);
        }
        break;
    case ScalarizedVal::Flavor::tuple:
        {
            auto tupleVal = as<ScalarizedTupleValImpl>(v.impl);
            for (auto e : tupleVal->elements)
            {
                leafAddressesImpl(ret, e.val);
            }
        }
        break;
    case ScalarizedVal::Flavor::typeAdapter:
        {
            auto typeAdapterVal = as<ScalarizedTypeAdapterValImpl>(v.impl);
            leafAddressesImpl(ret, typeAdapterVal->val);