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

Wgsl alias does not work when using from module #79

Open
Swoorup opened this issue Feb 26, 2024 · 5 comments
Open

Wgsl alias does not work when using from module #79

Swoorup opened this issue Feb 26, 2024 · 5 comments

Comments

@Swoorup
Copy link

Swoorup commented Feb 26, 2024

It appears that you can't use wgsl alias from a composable module. It works when using you are using from the make module file though.

composer
  .add_composable_module(ComposableModuleDescriptor {
      source: "alias Vec2 = vec2<f32>;",
      file_path: "valid.wgsl",
      as_name: Some("valid".to_owned()),
      ..Default::default()
  })
  .unwrap();

let module = composer
    .make_naga_module(NagaModuleDescriptor {
        source: r#"
      #import valid::Vec2;

      @group(0) @binding(1) var<uniform> position: Vec2;
    "#,
        file_path: "",
        ..Default::default()
    })
    .map_err(|err| println!("{}", err.emit_to_string(&composer)))
    .unwrap();

Here you get the error:

error: Composable module identifiers must not require substitution according to naga writeback rules: `Vec2`
  ┌─ valid.wgsl:1:1
  │
1 │ 
  │ ^ Composable module identifiers must not require substitution according to naga writeback rules: `Vec2`
@robtfm
Copy link
Collaborator

robtfm commented Feb 26, 2024

i haven't used aliases at all, so i wouldn't t expect this to work without some changes.

that said, this error is due to the '2' on the end. if you call it VecTwo you might get it to work, or at least get another error. we do some translations to allow most items (not struct members, and apparently not aliases) to end in numbers, and probably need to handle aliases explicitly as well in the same way.

but i suspect there will be more changes required to support aliases, maybe for internal use in a module and almost certainly for importing them into another module.

i'm not sure importing them would ever work, since i'm not sure languages other than wgsl have alias support.

@Swoorup
Copy link
Author

Swoorup commented Feb 26, 2024

Ugh, you are right. I renamed Vec2 to Vivek and I got

error: unknown type: 'Vivek'
  ┌─ :4:53
  │
4 │           @group(0) @binding(1) var<uniform> valid: Vivek;
  │                                                     ^^^^^ unknown type
  │
  = unknown type: 'Vivek'

@Swoorup
Copy link
Author

Swoorup commented Feb 26, 2024

but i suspect there will be more changes required to support aliases, maybe for internal use in a module and almost certainly for importing them into another module.

i'm not sure importing them would ever work, since i'm not sure languages other than wgsl have alias support.

I'd mostly like to use then as semi- new types for things like alias worldpoint = vec2<f32> rather, structs have stricter requirements (16 bytes alignment).

For other languages I suppose, we just output the types they alias?

@robtfm
Copy link
Collaborator

robtfm commented Feb 26, 2024

do type aliases in wgsl give you type safety? the docs are unclear but i suspect not. and if not i guess you could just include the aliases everywhere you want to use them...

@Swoorup
Copy link
Author

Swoorup commented Feb 26, 2024

It doesn't. But its better than nothing. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants