Comments (10)
Jay, is there an estimate for this one?
from slang.
This is probably an easy one but I don't have much confidence.
I put 3 days for now.
from slang.
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.
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.
Jay, is this issue still blocking you?
from slang.
Yes it blocks my UE task.
I will start working on this tomorrow.
from slang.
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.
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.
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.
Fix is merged.
Closing the issue.
from slang.
Related Issues (20)
- Fix CTS tests failures.
- Breakdown the runtime cost of Slang backend passes.
- constexpr doesn't work as expected when used on a function HOT 3
- Design documentation for DXIL linking of shader-modules
- Pointer example on User Guide doesn't work HOT 5
- Incorrect inlining of generic initializers HOT 1
- Throw an error when using `[[vk::binding]]` on global shader parameters
- Wrong matrix operations in Metal? HOT 6
- How to import modules :) HOT 1
- support for opengl HOT 4
- Investigate why the compiler warning level 4 is not working as expected HOT 2
- Shader reflection API issues HOT 2
- Update documentation for compilation API with profile information for new targets.
- Print warning when unsigned and signed integer types used for binary operators HOT 1
- Refactor of obfuscateModuleLocs
- typealias with interface does not work as expected HOT 4
- `Sampler2D` crashes the compiler when targeting host HOT 3
- OpenGL glsl target spits out *Index instead of *Id HOT 4
- Host code gets not properly excluded when building gpu target
- Add support for RWStructuredBuffer with 64bit index HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slang.