yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
9ec6b9168
master
1// property-in-interface.slang 2 3//TEST(compute):COMPARE_COMPUTE: -shaderobj -vk 4 5// Test that interfaces can include property declarations. 6 7interface ICell 8{ 9 property value : int { get; set; } 10} 11 12struct MyCell : ICell 13{ 14 var _data : int; 15 16 property value : int { get { return _data; } set(newValue) { _data = newValue; } } 17} 18 19struct YourCell : ICell 20{ 21 int value; 22 23 int getValue() { return value; } 24 25 [mutating] void setValue(int v) { value = v; } 26} 27 28int helper<C : ICell>(C cell) 29{ 30 cell.value = cell.value + 1; 31 return cell.value; 32} 33 34int test(int value) 35{ 36 MyCell myCell = { value+1 }; 37 YourCell yourCell = { value }; 38 39 // Note: fetching `value` directly from `YourCell` 40 // to confirm that member lookup is prioritizing 41 // the concrete `YourCell::value` member of the inherited 42 // abstract member `ICell::value`. 43 // 44 int f = (yourCell.value + yourCell.getValue()) / 2; 45 return helper(myCell)*16 + helper(yourCell) + f; 46} 47 48//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):out,name=outputBuffer 49RWStructuredBuffer<int> outputBuffer; 50 51[numthreads(4, 1, 1)] 52void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 53{ 54 uint tid = dispatchThreadID.x; 55 int inVal = outputBuffer[tid]; 56 int outVal = test(inVal); 57 outputBuffer[tid] = outVal; 58}