diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-02-09 11:26:04 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-09 11:26:04 -0500 |
| commit | 160111a0e27c9325ddfc49a53fbb82d3c6f06c90 (patch) | |
| tree | f71557856792e01bd4f55ad3013b16946bc866b6 /tests/experiments/generic/enum-int-flags-2.slang | |
| parent | d06a78d935b2743494d47ed5cd3f36e38ac9c5ac (diff) | |
Generic experiments (#2119)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Small fixes.
Added compiler crash with generic defined in a function.
Added enum-flags test that works (by limiting backing type to int), and using __EnumType constraint.
* Add comment about crash.
* Disable crashing test.
Diffstat (limited to 'tests/experiments/generic/enum-int-flags-2.slang')
| -rw-r--r-- | tests/experiments/generic/enum-int-flags-2.slang | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/experiments/generic/enum-int-flags-2.slang b/tests/experiments/generic/enum-int-flags-2.slang new file mode 100644 index 000000000..c5283fb7e --- /dev/null +++ b/tests/experiments/generic/enum-int-flags-2.slang @@ -0,0 +1,45 @@ +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj + +/* A test to use generics to treat an enum as a set. +Here we simplify previous example, by not allowing the backing type be +a specialization parameter (and just use int). + +Moreover here E is constrained to __EnumType. + +Works +*/ + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer<float> outputBuffer; + +enum Enum +{ + A = 0x1, + B = 0x2, + C = 0x4, +}; + +__generic<E : __EnumType> +struct Flags +{ + [mutating] void set(E e) { value |= (int)e; } + bool isSet(E e) { return (((int)e) & value) != 0; } + int value = 0; +}; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int index = dispatchThreadID.x; + + Flags<Enum> flags; + + if (index & 1) + { + flags.set(Enum::A); + } + bool isASet = flags.isSet(Enum::A); + + outputBuffer[index] = isASet ? 2 : 1; +} + |
