GithubHelp home page GithubHelp logo

Comments (10)

swoods-nv avatar swoods-nv commented on July 27, 2024

Jay, is there an estimate for this one?

from slang.

jkwak-work avatar jkwak-work commented on July 27, 2024

This is probably an easy one but I don't have much confidence.
I put 3 days for now.

from slang.

csyonghe avatar csyonghe commented on July 27, 2024

The issue is usually because we failed to identify the two specializations are the same thing.

In IR, we usually deduplicate specialize insts. When we specialize the Reduce function, we want to make sure we didn't create duplicated specialized structs. To trace this down, you can set a breakpoint after specialization pass, and inspect the IR for duplicate struct types. Find the duplicate struct type with the bigger UID, and try to track down why it gets created. There is a lookup process before creating the specialized struct type to see if a specialization is already created. Check why that lookup failed to determine the case.

from slang.

csyonghe avatar csyonghe commented on July 27, 2024

Set a breakpoint on the call to specializeModule in slang-emit.cpp:424 and start from there.
Then specializeGeneric will be called on everything that needs specialization, this include the generic functions and the generic struct type. Try to set a break point in this function when we are trying to specialize a struct type, and see why the lookup failed in slang-ir-specialize.cpp:238.

from slang.

swoods-nv avatar swoods-nv commented on July 27, 2024

Jay, is this issue still blocking you?

from slang.

jkwak-work avatar jkwak-work commented on July 27, 2024

Yes it blocks my UE task.
I will start working on this tomorrow.

from slang.

jkwak-work avatar jkwak-work commented on July 27, 2024

I am having some trouble reproducing the issue.
When I target "HLSL", it is easy to reproduce.
But when I use gfx with slang-test, both dxc and fxc don't print the error and everything works fine.
I am little puzzled.
The bug might be in the code where HLSL gets emitted.

from slang.

jkwak-work avatar jkwak-work commented on July 27, 2024

It appears that the issue stems from the fact that the duplication detecting logic uses hash values.
And the hash values are calculated from the memory pointer values rather than the values the pointers point to.

HashCode IRSimpleSpecializationKey::getHashCode() const
{
    auto valCount = vals.getCount();
    HashCode hash = Slang::getHashCode(valCount);
    for( Index ii = 0; ii < valCount; ++ii )
    {
        hash = combineHash(hash, Slang::getHashCode(vals[ii])); // <== This generates a hash value from memory pointer values; not the value kIROp_IntLit represents.
    }
    return hash;
}

When this happens, the following is where the issue happens.

    IRInst* specializeGeneric(
        IRGeneric* genericVal,
        IRSpecialize* specializeInst)
    {
        // First, we want to see if an existing specialization
        // has already been made. To do that we will construct a key
        // for lookup in the generic specialization context.
        //
        // Our key will consist of the identity of the generic
        // being specialized, and each of the argument values
        // being pased to it. In our hypothetical example of
        // `specialize(g, a, b, c)` the key will then be
        // the array `[g, a, b, c]`.
        //
        Key key;
        key.vals.add(specializeInst->getBase());
        UInt argCount = specializeInst->getArgCount();
        for (UInt ii = 0; ii < argCount; ++ii)
        {
            key.vals.add(specializeInst->getArg(ii));
        }

        {
            // We use our generated key to look for an
            // existing specialization that has been registered.
            // If one is found, our work is done.
            //
            IRInst* specializedVal = nullptr;
            if (genericSpecializations.tryGetValue(key, specializedVal)) // <== This didn't properly work
                return specializedVal;
        }

from slang.

jkwak-work avatar jkwak-work commented on July 27, 2024

I found another problem regarding this issue.
When I wrap the generic argument, which is a compile-time constant, with "int", it becomes not-compile-time constant.

tests/bugs/gh-3935.slang(14): error 39999: expression does not evaluate to a compile-time constant
MyStruct<int(ArraySize / 2)> Reduce(MyStruct<ArraySize> o)

Note that the error message above shows "int(ArraySize /2)".
It compiles fine when I just did "MyStruct<ArraySize / 2> Reduce..."

from slang.

jkwak-work avatar jkwak-work commented on July 27, 2024

Fix is merged.
Closing the issue.

from slang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.