Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[meta] Advanced compute support #1154

Closed
6 of 8 tasks
dragostis opened this issue Jul 30, 2021 · 3 comments
Closed
6 of 8 tasks

[meta] Advanced compute support #1154

dragostis opened this issue Jul 30, 2021 · 3 comments
Labels
area: middle Intermediate representation help wanted Extra attention is needed kind: feature New feature or request lang: WGSL WebGPU shading language

Comments

@dragostis
Copy link

dragostis commented Jul 30, 2021

I wanted to have a checklist of some more advanced features that would enable complex compute use cases in one place so it's easier to keep up with naga's development. Feel free to add/edit/remove as appropriate.

Features:

@kvark kvark changed the title Advanced compute support [meta] Advanced compute support Aug 1, 2021
@kvark kvark added area: middle Intermediate representation help wanted Extra attention is needed kind: feature New feature or request lang: WGSL WebGPU shading language labels Aug 1, 2021
@dragostis
Copy link
Author

dragostis commented Aug 20, 2021

For pointer support, I'm adding a few edge cases that seem interesting:

Broken, p cannot be indexed by non-constant:

fn array_read_from_pointer(p: ptr<workgroup, array<u32, 32>>, i: u32) -> u32 {
    return *p[i];
    // This works instead: return *(p[i]);
}

Works:

fn array_write_from_pointer(p: ptr<function, array<u32, 32>>, i: u32) -> u32 {
    p[i] = 42u;
}

Broken, runtime arrays seem to have a type that can't be passed into functions:

fn runtime_array_read_from_pointer(p: ptr<storage, array<u32>>, i: u32) -> u32 {
    return p[i];
}

Broken, runtime arrays seem to have a type that can't be passed into functions:

fn runtime_array_write_from_pointer(p: ptr<storage, array<u32>, read_write>, i: u32) {
    p[i] = 42u;
}

Works:

struct Foo {
    bar: u32;
};

fn struct_field_read_from_pointer(p: ptr<function, Foo>) -> u32 {
    return *p.bar;
}

Works:

struct Foo {
    bar: u32;
};

fn struct_field_write_from_pointer(p: ptr<function, Foo>) {
    p.bar = 42u;
}

@teoxoy
Copy link
Member

teoxoy commented May 1, 2022

For pointer support, I'm adding a few edge cases that seem interesting:

Broken, p cannot be indexed by non-constant:

fn array_read_from_pointer(p: ptr<workgroup, array<u32, 32>>, i: u32) -> u32 {
    return *p[i];
    // This works instead: return *(p[i]);
}

This now errors with:

error: the value indexed by a `[]` subscripting expression must not be a pointer
   ┌─ test.wgsl:69:1369return *p[i];
   │             ^ expression is a pointer

and

error: the value indexed by a `[]` subscripting expression must not be a pointer
   ┌─ test.wgsl:69:1469return *(p[i]);
   │              ^ expression is a pointer

Looking at the relevant grammar section in the WGSL spec this is intended and return (*p)[i]; should be used instead.

Works:

fn array_write_from_pointer(p: ptr<function, array<u32, 32>>, i: u32) -> u32 {
    p[i] = 42u;
}

This now errors with:

error: the value indexed by a `[]` subscripting expression must not be a pointer
   ┌─ test.wgsl:67:7367fn array_write_from_pointer2(p: ptr<function, array<u32, 32>>, i: u32) {
   │ ╭────────────────────────────────────────────────────────────────────────^
68 │ │     p[i] = 42u;
   │ ╰─────^ expression is a pointer

According to the relevant grammar section in the WGSL spec *p[i] = 42u; should work but it doesn't ((*p)[i] = 42u; works however).

Broken, runtime arrays seem to have a type that can't be passed into functions:

fn runtime_array_read_from_pointer(p: ptr<storage, array<u32>>, i: u32) -> u32 {
    return p[i];
}

Broken, runtime arrays seem to have a type that can't be passed into functions:

fn runtime_array_write_from_pointer(p: ptr<storage, array<u32>, read_write>, i: u32) {
    p[i] = 42u;
}

Both of these are intended to not work according to the spec and they will fail with the following error:

error: 
  ┌─ test.wgsl:1:11 │ ╭ fn runtime_array_read_from_pointer(p: ptr<storage, array<u32>>, i: u32) -> u32 {
  │                                         ^^^^^^^^^^^^^^^^^^^^^^^^ naga::Type [3]
2 │ │     return (*p)[i];
3 │ │ }
  │ ╰─^ naga::Function [1]

Function [1] 'runtime_array_read_from_pointer' is invalid: 
        Argument 'p' at index 0 is a pointer of space Storage { access: LOAD }, which can't be passed into functions.

Works:

struct Foo {
    bar: u32;
};

fn struct_field_read_from_pointer(p: ptr<function, Foo>) -> u32 {
    return *p.bar;
}

This one errors again and should be return (*p).bar;.

Works:

struct Foo {
    bar: u32;
};

fn struct_field_write_from_pointer(p: ptr<function, Foo>) {
    p.bar = 42u;
}

This one errors again and should be *p.bar = 42u; (however this again doesn't work but should).

Conclusion

Everything related to pointers besides the assignment works as intended. I opened gfx-rs/wgpu#4383 to tackle the assignment issue.

@teoxoy
Copy link
Member

teoxoy commented Nov 21, 2022

Will close this, let's track the last 2 items in their own issues

@teoxoy teoxoy closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: middle Intermediate representation help wanted Extra attention is needed kind: feature New feature or request lang: WGSL WebGPU shading language
Projects
None yet
Development

No branches or pull requests

3 participants