webgpu-native / webgpu-headers

**NOT STABLE YET!** See README.
https://webgpu-native.github.io/webgpu-headers/
BSD 3-Clause "New" or "Revised" License
391 stars 45 forks source link

Proposal: remove Undefined from VertexStepMode and binding type enums #424

Open kainino0x opened 1 week ago

kainino0x commented 1 week ago

After @beaufortfrancois started implementing VertexBufferNotUsed/BindingNotUsed in Dawn I am reconsidering that we should have Undefined values for these enums at all. There is not really any value in them, since:

See also PR #364; issues #234, #242

kainino0x commented 1 week ago
  • In languages that have defaults

Technically we do have "defaults" in C, in the form of the INIT structs. We could set the defaults in there but we still do not need Undefined to exist to be able to do that. Unless we think these structs will get reused in a different context with different defaults (seems vanishingly unlikely).

eliemichel commented 6 days ago

I very much approve this! Even in a pure C use case, I can see no use of the Undefined value whereever there is a NotUsed one, since in JS the semantics is the same (right?).

kainino0x commented 6 days ago

I very much approve this! Even in a pure C use case, I can see no use of the Undefined value whereever there is a NotUsed one, since in JS the semantics is the same (right?).

They don't map to the same JS:

kainino0x commented 6 days ago

Technically we do have "defaults" in C, in the form of the INIT structs. We could set the defaults in there but we still do not need Undefined to exist to be able to do that. Unless we think these structs will get reused in a different context with different defaults (seems vanishingly unlikely).

To write that out, regardless of which way we go on removing Undefined, we could change the INIT macros from:

WGPU_BIND_GROUP_LAYOUT_ENTRY_INIT { ... /*.buffer=*/WGPU_BUFFER_BINDING_LAYOUT_INIT ... };
WGPU_BUFFER_BINDING_LAYOUT_INIT { ... /*.type=*/WGPUBufferBindingType_BindingNotUsed ... };

to

WGPU_BIND_GROUP_LAYOUT_ENTRY_INIT {
    ... /*.buffer=*/_wgpu_MAKE_INIT_STRUCT(WGPUBufferBindingLayout, {
      ... /*.type=*/WGPUBufferBindingType_BindingNotUsed ...
    }) ...
  };
WGPU_BUFFER_BINDING_LAYOUT_INIT { ... /*.type=*/WGPUBufferBindingType_Uniform ... };

so you can write: { .buffer=WGPU_BUFFER_BINDING_LAYOUT_INIT } and have it do what { buffer: {} } does in JS.

kainino0x commented 6 days ago

In #427 I did think of one small reason we might keep Undefined:

  • Maybe INIT macros should prefer Undefined over trivial defaults e.g. /*.dimension=*/WGPUTextureDimension_2D in case the JS API changes them from trivial (WebIDL) defaults to non-trivial defaults (non-breakingly, but in such a way that they depend on the values of other new members or something). (I am not sure if we ever discussed this before. I know we said that we should implement all of WebIDL's trivial defaulting in webgpu.h implementations though.)

That last line above would instead be:

WGPU_BUFFER_BINDING_LAYOUT_INIT { ... /*.type=*/WGPUBufferBindingType_Undefined ... };

but the effect would be the same.

kainino0x commented 4 days ago

Nov 21 meeting:

kainino0x commented 4 days ago

Ugh I forgot we should discuss the whole initialization thing I was talking about before I land this, will leave it on the agenda for now.