KhronosGroup / KhronosGroup/SYCL-Docs

Are vec swizzles from vec<T, N> to vec<T, N+n> allowed?

Open
#521 3 comments 0 reactions 0 assignees View on GitHub
clarification
Dominant language
JavaScript
Stars
158
Forks
80
Avg merge
7d 6h
Merged PRs (30d)
5

Description

It recently was reported by a user that swizzling to a larger `vec` size currently does not work in AdaptiveCpp, while it seems to work in DPC++.
Here is an example of the code in question:

```c++
#define SYCL_SIMPLE_SWIZZLES
#include

int main(int argc, char* argv[]) {
sycl::float2 p0 {1.0f, 2.0f};
sycl::float3 p1 = p0.xyx(); // Error occurs here
return 0;
}
```

The specification says:
> Where XYZW_SWIZZLE is all permutations with repetition, of any subset with length greater than 1, of x, y for NumElements == 2, x, y, z for NumElements == 3 and x, y, z, w for NumElements == 4. For example a four element vec provides permutations including xzyw, xyyy and xz.

The way I read it, the 3-component `xyx` in the example is not a permutation of any subset of `(x,y)` (since `NumElements == 2`) and thus would not be allowed. I'm not sure if the exact mathematical definition of "permutation with repetition" allows more freedom here, but in that case it should perhaps be made more obvious. The current situation is already that AdaptiveCpp and DPC++ implement this differently.

This is the opposite case of https://github.com/KhronosGroup/SYCL-Docs/issues/29

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the quoted XYZW_SWIZZLE specification wording and the float2-to-float3 `xyx()` example. Compare the opposite case in SYCL-Docs issue 29 and the reported AdaptiveCpp and DPC++ behavior. Done means resolving the interpretation and making the specification or its wording unambiguous about larger-vector swizzles.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.