slang icon indicating copy to clipboard operation
slang copied to clipboard

Const SPIRV Pointer

Open Ipotrick opened this issue 1 year ago • 3 comments

I encounter an internal compiler error when trying to annotate the pointee of a pointer as const. I believe const pointers should be supported, just for the static type checking. Compile error:

internal error 99999: unexpected condition encountered in Slang compiler: unknown type modifier in semantic checking
    const TestStruct * ptr = (const TestStruct *)(test[0]);
                              ^~~~~

Repro (modified test sample, should be easy to slot in):

struct TestStruct
{
    uint index;
};

[[vk::binding(2, 0)]] StructuredBuffer<uint64_t> test;

struct PP
{
    int data;
    int data2;
}
struct Data
{
    int data;
    PP* pNext;
};

void funcThatTakesPointer(PP* p)
{
    p.data = 2;
}
int* funcThatReturnsPointer(PP* p)
{
    return &p.data;
}

// CHECK: OpEntryPoint

[[vk::binding(0, 0)]] StructuredBuffer<Data> buffer;
[[vk::binding(1, 0)]] RWStructuredBuffer<int> output;
[shader("compute")]
[numthreads(8, 8, 1)]
void main(int id : SV_DispatchThreadID)
{
    const TestStruct * ptr = (const TestStruct *)(test[0]);
    output[0] = buffer[ptr.index].pNext.data;
    let pData = &(buffer[0].pNext.data);
    // CHECK: OpPtrAccessChain
    int* pData1 = pData + 1;
    *pData1 = 3;
    *(int2*)pData = int2(1, 2);
    pData1[-1] = 2;
    buffer[0].pNext[1] = {5};
    // CHECK: OpConvertPtrToU
    // CHECK: OpINotEqual
    if (pData1)
    {
        *(funcThatReturnsPointer(buffer[0].pNext)) = 4;
    }
    if (pData1 > pData)
    {
        funcThatTakesPointer(buffer[0].pNext);
    }
}

Ipotrick avatar Feb 26 '24 23:02 Ipotrick

We currently don't support const T* syntax.

csyonghe avatar Feb 27 '24 00:02 csyonghe

Eventually we will, but the focus for now is to unblock users from accessing the hardware features available in SPIRV. We will revisit const pointer support later in the year or in the next year. Closing for now because we can't allocate our resources on it in our current milestone.

csyonghe avatar Feb 27 '24 00:02 csyonghe

We will add support for const pointers in Q2.

csyonghe avatar Feb 29 '24 07:02 csyonghe

Updating to Q3 given resourcing constraints.

bmillsNV avatar May 16 '24 19:05 bmillsNV