Open kainino0x opened 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).
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?).
I very much approve this! Even in a pure C use case, I can see no use of the
Undefined
value whereever there is aNotUsed
one, since in JS the semantics is the same (right?).
They don't map to the same JS:
{ .buffer={ .type=BindingNotUsed } }
↔ JS { buffer: undefined }
{ .buffer={ .type=Undefined } }
↔ JS { buffer: { type: undefined } }
{ .buffer={ .type=Uniform } }
↔ JS { buffer: { type: "uniform" } }
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 needUndefined
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.
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.
Nov 21 meeting:
VertexBufferNotUsed
/BindingNotUsed
that Undefined
is just… not useful in C. Remove? And in the INIT
structs, should we set the defaults to NotUsed
or to the real default?Undefined
[]
as a hole?)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.
After @beaufortfrancois started implementing
VertexBufferNotUsed
/BindingNotUsed
in Dawn I am reconsidering that we should haveUndefined
values for these enums at all. There is not really any value in them, since:Vertex
orUniform
/Float
/Filtering
/WriteOnly
undefined
toWGPUVertexStepMode_Undefined
/etc.WGPUBindGroupLayoutEntry.buffer.type
default toBindingNotUsed
but haveWGPUBufferBindingLayout.type
default toUniform
. Or just use algebraic data types, or whatever.See also PR #364; issues #234, #242