yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaimplement dot products for 1 vectors (#8599)b4023f715

master
1.2 KiB32 linesraw
1//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type
2//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -output-using-type
3//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type
4//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl -output-using-type
5//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda -output-using-type
6//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-wgsl -output-using-type
7
8// Test for dot product with 1-element vectors (float and int)
9
10// CHECK: 8
11
12//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
13RWStructuredBuffer<int> outputBuffer;
14
15[numthreads(1, 1, 1)]
16void computeMain()
17{
18    // Float dot product with 1-element vectors
19    vector<float, 1> floatVec1 = vector<float, 1>(2.0);
20    vector<float, 1> floatVec2 = vector<float, 1>(2.0);
21    float floatDot = dot(floatVec1, floatVec2); // 2.0 * 2.0 = 4.0
22    
23    // Int dot product with 1-element vectors
24    vector<int, 1> intVec1 = vector<int, 1>(2);
25    vector<int, 1> intVec2 = vector<int, 1>(2);
26    int intDot = dot(intVec1, intVec2); // 2 * 2 = 4
27    
28    // Add them together and convert to int
29    int result = int(floatDot) + intDot; // 4 + 4 = 8
30    
31    outputBuffer[0] = result;
32}