slang

Making it easier to work with shaders


TODO

Expression Type Conversions

Grammar:

'(' type-expr ')') base-expr

A cast expression converts a value (base-expr) to the desired type (type-expr). This is also known as an explicit type conversion. See Expression Type Conversions for details.

(int) 1.0f

A cast expression can perform both built-in type conversions and invoke any single-argument initializers of the target type.

As a compatibility feature for older code, Slang supports using a cast where the base expression is an integer literal zero and the target type is a user-defined structure type:

MyStruct s = (MyStruct) 0;

The semantics of such a cast are equivalent to initialization from an empty initializer list:

MyStruct s = {};

cases:

  • cast to void. But see also https://github.com/shader-slang/slang/issues/11315
  • passing a void value to return statement is allowed for void-typed functions