yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
1.6 KiB66 linesraw
1// Test use of unrelated generics in a dynamically dispatched generic function can be specialized.
2
3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0 -output-using-type
4//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx11 -profile sm_5_0 -output-using-type
5//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute  -output-using-type
6//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
7
8interface IValueGetter
9{
10    float get();
11}
12
13struct MyWrapper<T:IValueGetter>
14{
15    T getter;
16    float getVal()
17    {
18        return getter.get();
19    }
20}
21
22interface IFoo
23{
24    int getIntVal(int x);
25}
26
27[anyValueSize(16)]
28interface IInterface
29{
30    float callGetter<T:IFoo>(T foo);
31}
32
33struct Impl : IInterface
34{
35    int data;
36    struct GetterImpl : IValueGetter { float val; float get(){return val;} }
37    float callGetter<T:IFoo>(T foo)
38    {
39        // We should be able to specialize `wrapper` even if it is
40        // used in this dynamically dispatched method.
41        MyWrapper<GetterImpl> wrapper;
42        wrapper.getter.val = 2.0f;
43        return wrapper.getVal() * foo.getIntVal(1);
44    }
45};
46
47struct IdentityFoo : IFoo { int getIntVal(int x) { return x; } }
48
49float test()
50{
51    IInterface obj = createDynamicObject<IInterface, uint4>(3, uint4(1,2,3,4));
52    IdentityFoo foo;
53    // Call via dynamic dispatch
54    return obj.callGetter(foo);
55}
56
57//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer
58RWStructuredBuffer<float> gOutputBuffer;
59
60//TEST_INPUT: type_conformance Impl:IInterface = 3
61
62[numthreads(1, 1, 1)]
63void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
64{
65    gOutputBuffer[0] = test();
66}