shader-slang / slang

Making it easier to work with shaders
MIT License
1.78k stars 159 forks source link

Improve documentation and error message to clarify user defined data structures: `struct` vs `class` #4448

Closed chaoticbob closed 4 hours ago

chaoticbob commented 1 week ago

It appears that Slang does not support a class data structure? I couldn't find an example of a class in the tests. When I try to compile the shader below, I get this error:

(0): error 99999: Slang compilation aborted due to an exception of class Slang::InternalError: unimplemented: Unhandled global inst in spirv-emit:
[export(%1)]
[nameHint(%2)]
class %S        : %3
{
        field(%a, %4)
}

CMD:

slangc.exe -target spirv -lang slang -D__spirv__ -emit-spirv-directly -profile vs_6_0 -entry main shader.hlsl

If class isn't supported and the user is meant to use struct, can we document this instead of leaving it as an exercise for the the user?

Shader

class S {  
  float a;
};

float4 main() : SV_TARGET {
    S s;

    return (float4)s.a;
}
csyonghe commented 1 week ago

class is reserved for further cpu/host side logic, and represents a reference counted, heap allocated object. It is invalid to use classes for gpu code.