Skip to content

Add 0/1 swizzle syntax #732

@dneto0

Description

@dneto0

From https://twitter.com/FreyaHolmer/status/1255107846129299456

okay I swear to god, the amount of time I spend doing this:

float3( v.xy, 0 )
float3( v.x, 0, v.y )
float4( v, 0 )
float4( v, 1 )

like, if only we had swizzle operators for 0 and 1, imagine if we could just

v.xy0
v.x0y
v.xyz0
v.xyz1

So, the idea is to permit 0 and 1 as elements of a swizzle syntax, where they indicate not positions in the source vector, but rather constants 0 and 1 (of the right scalar type).

At LLVM or SPIR-V level, there's no disadvantage, as a general swizzle to construct a vector use the "shuffle" operation, and in this case the second operand to the shuffle would be a 0-1 vector rather than a dummy (unused) vector.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions