summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/properties/property-in-interface.slang
blob: 2ef0506240f6246ac7338be65043ae36c85aa233 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// property-in-interface.slang

//TEST(compute):COMPARE_COMPUTE: -shaderobj -vk

// Test that interfaces can include property declarations.

interface ICell
{
    property value : int { get; set; }
}

struct MyCell : ICell
{
    var _data : int;

    property value : int { get { return _data; } set(newValue) { _data = newValue; } }
}

struct YourCell : ICell
{
    int value;

    int getValue() { return value; }

    [mutating] void setValue(int v) { value = v; }
}

int helper<C : ICell>(C cell)
{
    cell.value = cell.value + 1;
    return cell.value;
}

int test(int value)
{
    MyCell myCell = { value+1 };
    YourCell yourCell = { value };

    // Note: fetching `value` directly from `YourCell`
    // to confirm that member lookup is prioritizing
    // the concrete `YourCell::value` member of the inherited
    // abstract member `ICell::value`.
    //
    int f = (yourCell.value + yourCell.getValue()) / 2;
    return helper(myCell)*16 + helper(yourCell) + f;
}

//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    uint tid = dispatchThreadID.x;
    int inVal = outputBuffer[tid];
    int outVal = test(inVal);
    outputBuffer[tid] = outVal;
}