slang
slang copied to clipboard
Const SPIRV Pointer
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);
}
}
We currently don't support const T*
syntax.
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.
We will add support for const pointers in Q2.
Updating to Q3 given resourcing constraints.