diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-12-21 16:16:23 -0800 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-12-21 16:16:23 -0800 |
| commit | 00490154ef0762839556b5884ba9b7523b265a1c (patch) | |
| tree | 239e42c6e9fd2907afe52974cccda41555bde2ba /tests/compute | |
| parent | 6f681279d99e72e717bb2b91763b80e570ae725b (diff) | |
Support generic `struct` types during IR-based emit
Fixes #318
Most of the required support was actually in place, so this is just a bunch of fixes:
- Detect when we are in "full IR" mode, so that we can always emit `struct` declarations with their mangled named (which will produce different names for different specializations, since we emit decl-refs)
- Carefully exclude builtin types from this for now. We'll need a more complete solution for mapping HLSL/Slang builtin types to their GLSL equivalents soon.
- Skip emitting types referenced by generic IR functions, since they might not be usable.
- Also fix things up so that we emit types used in the initializer for any global variables.
- Fix bug in generic specialization where we specialize the same function more than once, with different type arguments. We were crashing on a `Dictionary::Add` call where the key already exists from a previous specialization attempt.
- Fix name-mangling logic so that when outputting a possibly-specialized generic it looks for the outer-most `GenericSubstitution` rather than just the first one in the list. This is to handle the way that we insert other substitutions willy-nilly in places where they realistically don't belong. :(
All of these changes together allow us to pass a slightly modified (more advanced) version of the test case posted to #318.
Diffstat (limited to 'tests/compute')
| -rw-r--r-- | tests/compute/generic-struct.slang | 37 | ||||
| -rw-r--r-- | tests/compute/generic-struct.slang.expected.txt | 4 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/compute/generic-struct.slang b/tests/compute/generic-struct.slang new file mode 100644 index 000000000..fd56ae0e9 --- /dev/null +++ b/tests/compute/generic-struct.slang @@ -0,0 +1,37 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +// Check that user code can declare and use a generic +// `struct` type. + +RWStructuredBuffer<int> outputBuffer; + +__generic<T> +struct GenStruct +{ + T x; + T y; +}; + +__generic<T> +T test(T val) +{ + GenStruct<T> gs; + gs.x = val; + gs.y = val; + return gs.x; +} + + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + + float outVal = 0; + + outVal += test<uint>(tid); + outVal += test<float>(tid * 16.0f); + + outputBuffer[tid] = int(outVal); +}
\ No newline at end of file diff --git a/tests/compute/generic-struct.slang.expected.txt b/tests/compute/generic-struct.slang.expected.txt new file mode 100644 index 000000000..d4cb1cc00 --- /dev/null +++ b/tests/compute/generic-struct.slang.expected.txt @@ -0,0 +1,4 @@ +0 +11 +22 +33 |
