summaryrefslogtreecommitdiffstats
path: root/tests/metal/pointer-literals.slang
blob: 4752cf1d781fb89d96cf5f8880e5cf50686b929f (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
//TEST:SIMPLE(filecheck=METAL): -target metal -stage compute -entry computeMain
//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage compute -entry computeMain
//TEST(compute, metal):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-metal -compute -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -emit-spirv-directly -compute -output-using-type

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

//METAL: {{\[\[}}kernel{{\]\]}} void computeMain
//METALLIB: define void @computeMain

// Test that pointer literals are handled correctly in Metal.

[numthreads(1,1,1)]
void computeMain()
{
    // Test pointer literals in some contexts that might generate kIROp_PtrLit.

    // Test 1: Basic pointer literal assignment
    void* ptr1 = nullptr;
    outputBuffer[0] = (ptr1 == nullptr) ? 1 : 0;
    // BUF: 1
    
    // Test 2: Pointer literal in struct
    struct TestStruct
    {
        void* ptr;
        int value;
    };

    TestStruct test = { nullptr, 42 };
    outputBuffer[1] = (test.ptr == nullptr) ? 1 : 0;
    // BUF: 1
}