Skip to content

Removing ptr and adding ref #1334

@dj2

Description

@dj2

I'd like to propose we remove the ptr type from WGSL. I've found this type to be especially confusing because we also have things like var which is a pointer to some bit of member, but it's different from ptr.

In the place of ptr I propose we add a ref keyword which is used similar to var.

fn main() -> void {
  var a : i32 = 2;
  ref b : i32 = a;   // Take a reference to a

  const c : ptr<function, i32> = a;  // current ptr syntax
}
var <private> a : i32 = 2;
fn main() -> void {
  ref b : i32 = a;   // b inherits the `private` storage class from a
  ref<private> c : i32 = a;  // Even if provided, the storage class must match.

  const b : ptr<private, i32> = a;  // current ptr syntax
}

When using a ref as a parameter to a function, the storage class is required.

fn b(ref<private> a : i32) -> i32 {
  return a;
}

fn b(a : ptr<private, i32>) -> i32 {}  // Current ptr syntax

var<private> z : i32 = 2;
fn main() -> void {
  ref y : i32 = z;
  var c : i32 = b(y);
}

Using ref is more concise, and provides a clearer idea of what you're getting. It functions the same as var in that we will auto-dereference to do the load/store as needed.

Metadata

Metadata

Assignees

Labels

wgslWebGPU Shading Language Issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions